1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011, 2012 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Library General Public
22 * License as published by the Free Software Foundation; either
23 * version 2 of the License, or (at your option) any later version.
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Library General Public License for more details.
30 * You should have received a copy of the GNU Library General Public
31 * License along with this library; if not, write to the
32 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
33 * Boston, MA 02111-1307, USA.
38 #include "ui/gui/pspp-sheet-private.h"
42 #include <gdk/gdkkeysyms.h>
45 #include "ui/gui/psppire-marshal.h"
46 #include "ui/gui/pspp-sheet-selection.h"
48 #define P_(STRING) STRING
49 #define GTK_PARAM_READABLE G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
50 #define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
52 /* Many keyboard shortcuts for Mac are the same as for X
53 * except they use Command key instead of Control (e.g. Cut,
54 * Copy, Paste). This symbol is for those simple cases. */
55 #ifndef GDK_WINDOWING_QUARTZ
56 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_CONTROL_MASK
58 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_META_MASK
61 #define PSPP_SHEET_VIEW_PRIORITY_VALIDATE (GDK_PRIORITY_REDRAW + 5)
62 #define PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC (PSPP_SHEET_VIEW_PRIORITY_VALIDATE + 2)
63 #define PSPP_SHEET_VIEW_TIME_MS_PER_IDLE 30
64 #define SCROLL_EDGE_SIZE 15
65 #define EXPANDER_EXTRA_PADDING 4
66 #define PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT 5000
68 /* The "background" areas of all rows/cells add up to cover the entire tree.
69 * The background includes all inter-row and inter-cell spacing.
70 * The "cell" areas are the cell_area passed in to gtk_cell_renderer_render(),
71 * i.e. just the cells, no spacing.
74 #define BACKGROUND_HEIGHT(tree_view) (tree_view->priv->fixed_height)
75 #define CELL_HEIGHT(tree_view, separator) ((BACKGROUND_HEIGHT (tree_view)) - (separator))
77 /* Translate from bin_window coordinates to rbtree (tree coordinates) and
80 #define TREE_WINDOW_Y_TO_RBTREE_Y(tree_view,y) ((y) + tree_view->priv->dy)
81 #define RBTREE_Y_TO_TREE_WINDOW_Y(tree_view,y) ((y) - tree_view->priv->dy)
83 /* This is in bin_window coordinates */
84 #define BACKGROUND_FIRST_PIXEL(tree_view,node) (RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, pspp_sheet_view_node_find_offset (tree_view, (node))))
85 #define CELL_FIRST_PIXEL(tree_view,node,separator) (BACKGROUND_FIRST_PIXEL (tree_view,node) + separator/2)
87 #define ROW_HEIGHT(tree_view) \
88 ((tree_view->priv->fixed_height > 0) ? (tree_view->priv->fixed_height) : (tree_view)->priv->expander_size)
91 typedef struct _PsppSheetViewChild PsppSheetViewChild;
92 struct _PsppSheetViewChild
102 typedef struct _TreeViewDragInfo TreeViewDragInfo;
103 struct _TreeViewDragInfo
105 GdkModifierType start_button_mask;
106 GtkTargetList *_unused_source_target_list;
107 GdkDragAction source_actions;
109 GtkTargetList *_unused_dest_target_list;
111 guint source_set : 1;
127 START_INTERACTIVE_SEARCH,
137 PROP_HEADERS_VISIBLE,
138 PROP_HEADERS_CLICKABLE,
143 PROP_HOVER_SELECTION,
145 PROP_ENABLE_GRID_LINES,
149 PROP_FIXED_HEIGHT_SET
153 static void pspp_sheet_view_finalize (GObject *object);
154 static void pspp_sheet_view_set_property (GObject *object,
158 static void pspp_sheet_view_get_property (GObject *object,
163 static void pspp_sheet_view_dispose (GObject *object);
165 /* gtkwidget signals */
166 static void pspp_sheet_view_realize (GtkWidget *widget);
167 static void pspp_sheet_view_unrealize (GtkWidget *widget);
168 static void pspp_sheet_view_map (GtkWidget *widget);
169 static void pspp_sheet_view_size_request (GtkWidget *widget,
170 GtkRequisition *requisition);
171 static void pspp_sheet_view_size_allocate (GtkWidget *widget,
172 GtkAllocation *allocation);
173 static gboolean pspp_sheet_view_expose (GtkWidget *widget,
174 GdkEventExpose *event);
175 static gboolean pspp_sheet_view_key_press (GtkWidget *widget,
177 static gboolean pspp_sheet_view_key_release (GtkWidget *widget,
179 static gboolean pspp_sheet_view_motion (GtkWidget *widget,
180 GdkEventMotion *event);
181 static gboolean pspp_sheet_view_enter_notify (GtkWidget *widget,
182 GdkEventCrossing *event);
183 static gboolean pspp_sheet_view_leave_notify (GtkWidget *widget,
184 GdkEventCrossing *event);
185 static gboolean pspp_sheet_view_button_press (GtkWidget *widget,
186 GdkEventButton *event);
187 static gboolean pspp_sheet_view_button_release (GtkWidget *widget,
188 GdkEventButton *event);
189 static gboolean pspp_sheet_view_grab_broken (GtkWidget *widget,
190 GdkEventGrabBroken *event);
192 static void pspp_sheet_view_set_focus_child (GtkContainer *container,
194 static gint pspp_sheet_view_focus_out (GtkWidget *widget,
195 GdkEventFocus *event);
196 static gint pspp_sheet_view_focus (GtkWidget *widget,
197 GtkDirectionType direction);
198 static void pspp_sheet_view_grab_focus (GtkWidget *widget);
199 static void pspp_sheet_view_style_set (GtkWidget *widget,
200 GtkStyle *previous_style);
201 static void pspp_sheet_view_grab_notify (GtkWidget *widget,
202 gboolean was_grabbed);
203 static void pspp_sheet_view_state_changed (GtkWidget *widget,
204 GtkStateType previous_state);
206 /* container signals */
207 static void pspp_sheet_view_remove (GtkContainer *container,
209 static void pspp_sheet_view_forall (GtkContainer *container,
210 gboolean include_internals,
211 GtkCallback callback,
212 gpointer callback_data);
214 /* Source side drag signals */
215 static void pspp_sheet_view_drag_begin (GtkWidget *widget,
216 GdkDragContext *context);
217 static void pspp_sheet_view_drag_end (GtkWidget *widget,
218 GdkDragContext *context);
219 static void pspp_sheet_view_drag_data_get (GtkWidget *widget,
220 GdkDragContext *context,
221 GtkSelectionData *selection_data,
224 static void pspp_sheet_view_drag_data_delete (GtkWidget *widget,
225 GdkDragContext *context);
227 /* Target side drag signals */
228 static void pspp_sheet_view_drag_leave (GtkWidget *widget,
229 GdkDragContext *context,
231 static gboolean pspp_sheet_view_drag_motion (GtkWidget *widget,
232 GdkDragContext *context,
236 static gboolean pspp_sheet_view_drag_drop (GtkWidget *widget,
237 GdkDragContext *context,
241 static void pspp_sheet_view_drag_data_received (GtkWidget *widget,
242 GdkDragContext *context,
245 GtkSelectionData *selection_data,
249 /* tree_model signals */
250 static void pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
252 GtkAdjustment *vadj);
253 static gboolean pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
254 GtkMovementStep step,
256 static gboolean pspp_sheet_view_real_select_all (PsppSheetView *tree_view);
257 static gboolean pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view);
258 static gboolean pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
259 gboolean start_editing);
260 static gboolean pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view);
261 static void pspp_sheet_view_row_changed (GtkTreeModel *model,
265 static void pspp_sheet_view_row_inserted (GtkTreeModel *model,
269 static void pspp_sheet_view_row_deleted (GtkTreeModel *model,
272 static void pspp_sheet_view_rows_reordered (GtkTreeModel *model,
278 /* Incremental reflow */
279 static gint validate_row (PsppSheetView *tree_view,
283 static void validate_visible_area (PsppSheetView *tree_view);
284 static gboolean validate_rows_handler (PsppSheetView *tree_view);
285 static gboolean presize_handler_callback (gpointer data);
286 static void install_presize_handler (PsppSheetView *tree_view);
287 static void install_scroll_sync_handler (PsppSheetView *tree_view);
288 static void pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
291 static void pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view);
292 static void pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view);
293 static void invalidate_empty_focus (PsppSheetView *tree_view);
295 /* Internal functions */
296 static void pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
299 gboolean add_shifted_binding,
300 GtkMovementStep step,
302 static void pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
304 const GdkRectangle *clip_rect);
305 static gint pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
308 static void pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
309 PsppSheetView *tree_view);
310 static void pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
312 static void pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
313 PsppSheetViewColumn *column,
314 gboolean focus_to_cell);
315 static gboolean pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
316 GdkEventMotion *event);
317 static void pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view);
318 static void pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
320 static void pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
322 static void pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
324 static void pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
326 static void pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
328 gboolean clear_and_select,
329 gboolean clamp_node);
330 static gboolean pspp_sheet_view_has_special_cell (PsppSheetView *tree_view);
331 static void pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view);
332 static void update_prelight (PsppSheetView *tree_view,
335 static void initialize_fixed_height_mode (PsppSheetView *tree_view);
337 /* interactive search */
338 static void pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view);
339 static void pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
340 PsppSheetView *tree_view);
341 static void pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
342 GtkWidget *search_dialog,
344 static void pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
347 static void pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
348 PsppSheetView *tree_view);
349 static void pspp_sheet_view_search_activate (GtkEntry *entry,
350 PsppSheetView *tree_view);
351 static gboolean pspp_sheet_view_real_search_enable_popdown(gpointer data);
352 static void pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
354 static gboolean pspp_sheet_view_search_delete_event (GtkWidget *widget,
356 PsppSheetView *tree_view);
357 static gboolean pspp_sheet_view_search_button_press_event (GtkWidget *widget,
358 GdkEventButton *event,
359 PsppSheetView *tree_view);
360 static gboolean pspp_sheet_view_search_scroll_event (GtkWidget *entry,
361 GdkEventScroll *event,
362 PsppSheetView *tree_view);
363 static gboolean pspp_sheet_view_search_key_press_event (GtkWidget *entry,
365 PsppSheetView *tree_view);
366 static gboolean pspp_sheet_view_search_move (GtkWidget *window,
367 PsppSheetView *tree_view,
369 static gboolean pspp_sheet_view_search_equal_func (GtkTreeModel *model,
373 gpointer search_data);
374 static gboolean pspp_sheet_view_search_iter (GtkTreeModel *model,
375 PsppSheetSelection *selection,
380 static void pspp_sheet_view_search_init (GtkWidget *entry,
381 PsppSheetView *tree_view);
382 static void pspp_sheet_view_put (PsppSheetView *tree_view,
383 GtkWidget *child_widget,
388 static gboolean pspp_sheet_view_start_editing (PsppSheetView *tree_view,
389 GtkTreePath *cursor_path);
390 static gboolean pspp_sheet_view_editable_button_press_event (GtkWidget *,
393 static void pspp_sheet_view_editable_clicked (GtkButton *, PsppSheetView *);
394 static void pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
395 PsppSheetViewColumn *column,
397 GtkCellEditable *cell_editable,
398 GdkRectangle *cell_area,
401 static gboolean pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
402 gboolean keybinding);
403 static gboolean pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view);
404 static PsppSheetViewColumn *pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
405 PsppSheetViewColumn *column,
408 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
409 PsppSheetViewColumn *column,
410 const GdkRectangle *background_area,
411 gboolean subtract_focus_rect,
412 GdkRectangle *cell_area);
413 static gint pspp_sheet_view_find_offset (PsppSheetView *tree_view,
418 static void pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
422 static void pspp_sheet_view_buildable_init (GtkBuildableIface *iface);
425 static gboolean scroll_row_timeout (gpointer data);
426 static void add_scroll_timeout (PsppSheetView *tree_view);
427 static void remove_scroll_timeout (PsppSheetView *tree_view);
429 static guint tree_view_signals [LAST_SIGNAL] = { 0 };
431 static GtkBindingSet *edit_bindings;
438 G_DEFINE_TYPE_WITH_CODE (PsppSheetView, pspp_sheet_view, GTK_TYPE_CONTAINER,
439 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
440 pspp_sheet_view_buildable_init))
443 pspp_sheet_view_class_init (PsppSheetViewClass *class)
445 GObjectClass *o_class;
446 GtkWidgetClass *widget_class;
447 GtkContainerClass *container_class;
448 GtkBindingSet *binding_set[2];
451 binding_set[0] = gtk_binding_set_by_class (class);
453 binding_set[1] = gtk_binding_set_new ("PsppSheetViewEditing");
454 edit_bindings = binding_set[1];
456 o_class = (GObjectClass *) class;
457 widget_class = (GtkWidgetClass *) class;
458 container_class = (GtkContainerClass *) class;
460 /* GObject signals */
461 o_class->set_property = pspp_sheet_view_set_property;
462 o_class->get_property = pspp_sheet_view_get_property;
463 o_class->finalize = pspp_sheet_view_finalize;
464 o_class->dispose = pspp_sheet_view_dispose;
466 /* GtkWidget signals */
467 widget_class->map = pspp_sheet_view_map;
468 widget_class->realize = pspp_sheet_view_realize;
469 widget_class->unrealize = pspp_sheet_view_unrealize;
470 widget_class->size_request = pspp_sheet_view_size_request;
471 widget_class->size_allocate = pspp_sheet_view_size_allocate;
472 widget_class->button_press_event = pspp_sheet_view_button_press;
473 widget_class->button_release_event = pspp_sheet_view_button_release;
474 widget_class->grab_broken_event = pspp_sheet_view_grab_broken;
475 /*widget_class->configure_event = pspp_sheet_view_configure;*/
476 widget_class->motion_notify_event = pspp_sheet_view_motion;
477 widget_class->expose_event = pspp_sheet_view_expose;
478 widget_class->key_press_event = pspp_sheet_view_key_press;
479 widget_class->key_release_event = pspp_sheet_view_key_release;
480 widget_class->enter_notify_event = pspp_sheet_view_enter_notify;
481 widget_class->leave_notify_event = pspp_sheet_view_leave_notify;
482 widget_class->focus_out_event = pspp_sheet_view_focus_out;
483 widget_class->drag_begin = pspp_sheet_view_drag_begin;
484 widget_class->drag_end = pspp_sheet_view_drag_end;
485 widget_class->drag_data_get = pspp_sheet_view_drag_data_get;
486 widget_class->drag_data_delete = pspp_sheet_view_drag_data_delete;
487 widget_class->drag_leave = pspp_sheet_view_drag_leave;
488 widget_class->drag_motion = pspp_sheet_view_drag_motion;
489 widget_class->drag_drop = pspp_sheet_view_drag_drop;
490 widget_class->drag_data_received = pspp_sheet_view_drag_data_received;
491 widget_class->focus = pspp_sheet_view_focus;
492 widget_class->grab_focus = pspp_sheet_view_grab_focus;
493 widget_class->style_set = pspp_sheet_view_style_set;
494 widget_class->grab_notify = pspp_sheet_view_grab_notify;
495 widget_class->state_changed = pspp_sheet_view_state_changed;
497 /* GtkContainer signals */
498 container_class->remove = pspp_sheet_view_remove;
499 container_class->forall = pspp_sheet_view_forall;
500 container_class->set_focus_child = pspp_sheet_view_set_focus_child;
502 class->set_scroll_adjustments = pspp_sheet_view_set_adjustments;
503 class->move_cursor = pspp_sheet_view_real_move_cursor;
504 class->select_all = pspp_sheet_view_real_select_all;
505 class->unselect_all = pspp_sheet_view_real_unselect_all;
506 class->select_cursor_row = pspp_sheet_view_real_select_cursor_row;
507 class->toggle_cursor_row = pspp_sheet_view_real_toggle_cursor_row;
508 class->start_interactive_search = pspp_sheet_view_start_interactive_search;
512 g_object_class_install_property (o_class,
514 g_param_spec_object ("model",
515 P_("TreeView Model"),
516 P_("The model for the tree view"),
518 GTK_PARAM_READWRITE));
520 g_object_class_install_property (o_class,
522 g_param_spec_object ("hadjustment",
523 P_("Horizontal Adjustment"),
524 P_("Horizontal Adjustment for the widget"),
526 GTK_PARAM_READWRITE));
528 g_object_class_install_property (o_class,
530 g_param_spec_object ("vadjustment",
531 P_("Vertical Adjustment"),
532 P_("Vertical Adjustment for the widget"),
534 GTK_PARAM_READWRITE));
536 g_object_class_install_property (o_class,
537 PROP_HEADERS_VISIBLE,
538 g_param_spec_boolean ("headers-visible",
539 P_("Headers Visible"),
540 P_("Show the column header buttons"),
542 GTK_PARAM_READWRITE));
544 g_object_class_install_property (o_class,
545 PROP_HEADERS_CLICKABLE,
546 g_param_spec_boolean ("headers-clickable",
547 P_("Headers Clickable"),
548 P_("Column headers respond to click events"),
550 GTK_PARAM_READWRITE));
552 g_object_class_install_property (o_class,
554 g_param_spec_boolean ("reorderable",
556 P_("View is reorderable"),
558 GTK_PARAM_READWRITE));
560 g_object_class_install_property (o_class,
562 g_param_spec_boolean ("rules-hint",
564 P_("Set a hint to the theme engine to draw rows in alternating colors"),
566 GTK_PARAM_READWRITE));
568 g_object_class_install_property (o_class,
570 g_param_spec_boolean ("enable-search",
572 P_("View allows user to search through columns interactively"),
574 GTK_PARAM_READWRITE));
576 g_object_class_install_property (o_class,
578 g_param_spec_int ("search-column",
580 P_("Model column to search through during interactive search"),
584 GTK_PARAM_READWRITE));
587 * PsppSheetView:hover-selection:
589 * Enables of disables the hover selection mode of @tree_view.
590 * Hover selection makes the selected row follow the pointer.
591 * Currently, this works only for the selection modes
592 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
594 * This mode is primarily intended for treeviews in popups, e.g.
595 * in #GtkComboBox or #GtkEntryCompletion.
599 g_object_class_install_property (o_class,
600 PROP_HOVER_SELECTION,
601 g_param_spec_boolean ("hover-selection",
602 P_("Hover Selection"),
603 P_("Whether the selection should follow the pointer"),
605 GTK_PARAM_READWRITE));
607 g_object_class_install_property (o_class,
609 g_param_spec_boolean ("rubber-banding",
610 P_("Rubber Banding"),
611 P_("Whether to enable selection of multiple items by dragging the mouse pointer"),
613 GTK_PARAM_READWRITE));
615 g_object_class_install_property (o_class,
616 PROP_ENABLE_GRID_LINES,
617 g_param_spec_enum ("enable-grid-lines",
618 P_("Enable Grid Lines"),
619 P_("Whether grid lines should be drawn in the tree view"),
620 PSPP_TYPE_SHEET_VIEW_GRID_LINES,
621 PSPP_SHEET_VIEW_GRID_LINES_NONE,
622 GTK_PARAM_READWRITE));
624 g_object_class_install_property (o_class,
626 g_param_spec_int ("tooltip-column",
627 P_("Tooltip Column"),
628 P_("The column in the model containing the tooltip texts for the rows"),
632 GTK_PARAM_READWRITE));
634 g_object_class_install_property (o_class,
636 g_param_spec_enum ("special-cells",
638 P_("Whether rows have special cells."),
639 PSPP_TYPE_SHEET_VIEW_SPECIAL_CELLS,
640 PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT,
641 GTK_PARAM_READWRITE));
643 g_object_class_install_property (o_class,
645 g_param_spec_int ("fixed-height",
647 P_("Height of a single row. Normally the height of a row is determined automatically. Writing this property sets fixed-height-set to true, preventing this property's value from changing."),
651 GTK_PARAM_READWRITE));
653 g_object_class_install_property (o_class,
654 PROP_FIXED_HEIGHT_SET,
655 g_param_spec_boolean ("fixed-height-set",
656 P_("Fixed Height Set"),
657 P_("Whether fixed-height was set externally."),
659 GTK_PARAM_READWRITE));
661 /* Style properties */
662 #define _TREE_VIEW_EXPANDER_SIZE 12
663 #define _TREE_VIEW_VERTICAL_SEPARATOR 2
664 #define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
666 gtk_widget_class_install_style_property (widget_class,
667 g_param_spec_int ("expander-size",
669 P_("Size of the expander arrow"),
672 _TREE_VIEW_EXPANDER_SIZE,
673 GTK_PARAM_READABLE));
675 gtk_widget_class_install_style_property (widget_class,
676 g_param_spec_int ("vertical-separator",
677 P_("Vertical Separator Width"),
678 P_("Vertical space between cells. Must be an even number"),
681 _TREE_VIEW_VERTICAL_SEPARATOR,
682 GTK_PARAM_READABLE));
684 gtk_widget_class_install_style_property (widget_class,
685 g_param_spec_int ("horizontal-separator",
686 P_("Horizontal Separator Width"),
687 P_("Horizontal space between cells. Must be an even number"),
690 _TREE_VIEW_HORIZONTAL_SEPARATOR,
691 GTK_PARAM_READABLE));
693 gtk_widget_class_install_style_property (widget_class,
694 g_param_spec_boolean ("allow-rules",
696 P_("Allow drawing of alternating color rows"),
698 GTK_PARAM_READABLE));
700 gtk_widget_class_install_style_property (widget_class,
701 g_param_spec_boxed ("even-row-color",
702 P_("Even Row Color"),
703 P_("Color to use for even rows"),
705 GTK_PARAM_READABLE));
707 gtk_widget_class_install_style_property (widget_class,
708 g_param_spec_boxed ("odd-row-color",
710 P_("Color to use for odd rows"),
712 GTK_PARAM_READABLE));
714 gtk_widget_class_install_style_property (widget_class,
715 g_param_spec_boolean ("row-ending-details",
716 P_("Row Ending details"),
717 P_("Enable extended row background theming"),
719 GTK_PARAM_READABLE));
721 gtk_widget_class_install_style_property (widget_class,
722 g_param_spec_int ("grid-line-width",
723 P_("Grid line width"),
724 P_("Width, in pixels, of the tree view grid lines"),
726 GTK_PARAM_READABLE));
728 gtk_widget_class_install_style_property (widget_class,
729 g_param_spec_int ("tree-line-width",
730 P_("Tree line width"),
731 P_("Width, in pixels, of the tree view lines"),
733 GTK_PARAM_READABLE));
735 gtk_widget_class_install_style_property (widget_class,
736 g_param_spec_string ("tree-line-pattern",
737 P_("Tree line pattern"),
738 P_("Dash pattern used to draw the tree view lines"),
740 GTK_PARAM_READABLE));
744 * PsppSheetView::set-scroll-adjustments
745 * @horizontal: the horizontal #GtkAdjustment
746 * @vertical: the vertical #GtkAdjustment
748 * Set the scroll adjustments for the tree view. Usually scrolled containers
749 * like #GtkScrolledWindow will emit this signal to connect two instances
750 * of #GtkScrollbar to the scroll directions of the #PsppSheetView.
752 widget_class->set_scroll_adjustments_signal =
753 g_signal_new ("set-scroll-adjustments",
754 G_TYPE_FROM_CLASS (o_class),
755 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
756 G_STRUCT_OFFSET (PsppSheetViewClass, set_scroll_adjustments),
758 psppire_marshal_VOID__OBJECT_OBJECT,
761 GTK_TYPE_ADJUSTMENT);
764 * PsppSheetView::row-activated:
765 * @tree_view: the object on which the signal is emitted
766 * @path: the #GtkTreePath for the activated row
767 * @column: the #PsppSheetViewColumn in which the activation occurred
769 * The "row-activated" signal is emitted when the method
770 * pspp_sheet_view_row_activated() is called or the user double clicks
771 * a treeview row. It is also emitted when a non-editable row is
772 * selected and one of the keys: Space, Shift+Space, Return or
775 * For selection handling refer to the <link linkend="TreeWidget">tree
776 * widget conceptual overview</link> as well as #PsppSheetSelection.
778 tree_view_signals[ROW_ACTIVATED] =
779 g_signal_new ("row-activated",
780 G_TYPE_FROM_CLASS (o_class),
781 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
782 G_STRUCT_OFFSET (PsppSheetViewClass, row_activated),
784 psppire_marshal_VOID__BOXED_OBJECT,
787 PSPP_TYPE_SHEET_VIEW_COLUMN);
790 * PsppSheetView::columns-changed:
791 * @tree_view: the object on which the signal is emitted
793 * The number of columns of the treeview has changed.
795 tree_view_signals[COLUMNS_CHANGED] =
796 g_signal_new ("columns-changed",
797 G_TYPE_FROM_CLASS (o_class),
799 G_STRUCT_OFFSET (PsppSheetViewClass, columns_changed),
801 g_cclosure_marshal_VOID__VOID,
805 * PsppSheetView::cursor-changed:
806 * @tree_view: the object on which the signal is emitted
808 * The position of the cursor (focused cell) has changed.
810 tree_view_signals[CURSOR_CHANGED] =
811 g_signal_new ("cursor-changed",
812 G_TYPE_FROM_CLASS (o_class),
814 G_STRUCT_OFFSET (PsppSheetViewClass, cursor_changed),
816 g_cclosure_marshal_VOID__VOID,
819 tree_view_signals[MOVE_CURSOR] =
820 g_signal_new ("move-cursor",
821 G_TYPE_FROM_CLASS (o_class),
822 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
823 G_STRUCT_OFFSET (PsppSheetViewClass, move_cursor),
825 psppire_marshal_BOOLEAN__ENUM_INT,
827 GTK_TYPE_MOVEMENT_STEP,
830 tree_view_signals[SELECT_ALL] =
831 g_signal_new ("select-all",
832 G_TYPE_FROM_CLASS (o_class),
833 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
834 G_STRUCT_OFFSET (PsppSheetViewClass, select_all),
836 psppire_marshal_BOOLEAN__VOID,
839 tree_view_signals[UNSELECT_ALL] =
840 g_signal_new ("unselect-all",
841 G_TYPE_FROM_CLASS (o_class),
842 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
843 G_STRUCT_OFFSET (PsppSheetViewClass, unselect_all),
845 psppire_marshal_BOOLEAN__VOID,
848 tree_view_signals[SELECT_CURSOR_ROW] =
849 g_signal_new ("select-cursor-row",
850 G_TYPE_FROM_CLASS (o_class),
851 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
852 G_STRUCT_OFFSET (PsppSheetViewClass, select_cursor_row),
854 psppire_marshal_BOOLEAN__BOOLEAN,
858 tree_view_signals[TOGGLE_CURSOR_ROW] =
859 g_signal_new ("toggle-cursor-row",
860 G_TYPE_FROM_CLASS (o_class),
861 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
862 G_STRUCT_OFFSET (PsppSheetViewClass, toggle_cursor_row),
864 psppire_marshal_BOOLEAN__VOID,
867 tree_view_signals[START_INTERACTIVE_SEARCH] =
868 g_signal_new ("start-interactive-search",
869 G_TYPE_FROM_CLASS (o_class),
870 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
871 G_STRUCT_OFFSET (PsppSheetViewClass, start_interactive_search),
873 psppire_marshal_BOOLEAN__VOID,
877 for (i = 0; i < 2; i++)
879 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Up, 0, TRUE,
880 GTK_MOVEMENT_DISPLAY_LINES, -1);
881 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Up, 0, TRUE,
882 GTK_MOVEMENT_DISPLAY_LINES, -1);
884 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Down, 0, TRUE,
885 GTK_MOVEMENT_DISPLAY_LINES, 1);
886 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Down, 0, TRUE,
887 GTK_MOVEMENT_DISPLAY_LINES, 1);
889 pspp_sheet_view_add_move_binding (binding_set[i], GDK_p, GDK_CONTROL_MASK, FALSE,
890 GTK_MOVEMENT_DISPLAY_LINES, -1);
892 pspp_sheet_view_add_move_binding (binding_set[i], GDK_n, GDK_CONTROL_MASK, FALSE,
893 GTK_MOVEMENT_DISPLAY_LINES, 1);
895 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Home, 0, TRUE,
896 GTK_MOVEMENT_BUFFER_ENDS, -1);
897 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Home, 0, TRUE,
898 GTK_MOVEMENT_BUFFER_ENDS, -1);
900 pspp_sheet_view_add_move_binding (binding_set[i], GDK_End, 0, TRUE,
901 GTK_MOVEMENT_BUFFER_ENDS, 1);
902 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_End, 0, TRUE,
903 GTK_MOVEMENT_BUFFER_ENDS, 1);
905 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Up, 0, TRUE,
906 GTK_MOVEMENT_PAGES, -1);
907 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Up, 0, TRUE,
908 GTK_MOVEMENT_PAGES, -1);
910 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Down, 0, TRUE,
911 GTK_MOVEMENT_PAGES, 1);
912 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Down, 0, TRUE,
913 GTK_MOVEMENT_PAGES, 1);
916 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, 0, "move-cursor", 2,
917 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
920 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, 0, "move-cursor", 2,
921 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
924 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, 0, "move-cursor", 2,
925 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
928 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, 0, "move-cursor", 2,
929 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
932 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, GDK_CONTROL_MASK,
934 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
937 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, GDK_CONTROL_MASK,
939 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
942 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, GDK_CONTROL_MASK,
944 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
947 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, GDK_CONTROL_MASK,
949 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
952 gtk_binding_entry_add_signal (binding_set[i], GDK_f, GDK_CONTROL_MASK, "start-interactive-search", 0);
954 gtk_binding_entry_add_signal (binding_set[i], GDK_F, GDK_CONTROL_MASK, "start-interactive-search", 0);
957 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
958 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
960 gtk_binding_entry_add_signal (binding_set[0], GDK_a, GDK_CONTROL_MASK, "select-all", 0);
961 gtk_binding_entry_add_signal (binding_set[0], GDK_slash, GDK_CONTROL_MASK, "select-all", 0);
963 gtk_binding_entry_add_signal (binding_set[0], GDK_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0);
964 gtk_binding_entry_add_signal (binding_set[0], GDK_backslash, GDK_CONTROL_MASK, "unselect-all", 0);
966 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_SHIFT_MASK, "select-cursor-row", 1,
967 G_TYPE_BOOLEAN, TRUE);
968 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", 1,
969 G_TYPE_BOOLEAN, TRUE);
971 gtk_binding_entry_add_signal (binding_set[0], GDK_space, 0, "select-cursor-row", 1,
972 G_TYPE_BOOLEAN, TRUE);
973 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, 0, "select-cursor-row", 1,
974 G_TYPE_BOOLEAN, TRUE);
975 gtk_binding_entry_add_signal (binding_set[0], GDK_Return, 0, "select-cursor-row", 1,
976 G_TYPE_BOOLEAN, TRUE);
977 gtk_binding_entry_add_signal (binding_set[0], GDK_ISO_Enter, 0, "select-cursor-row", 1,
978 G_TYPE_BOOLEAN, TRUE);
979 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Enter, 0, "select-cursor-row", 1,
980 G_TYPE_BOOLEAN, TRUE);
982 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, 0, "select-cursor-parent", 0);
983 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", 0);
985 g_type_class_add_private (o_class, sizeof (PsppSheetViewPrivate));
989 pspp_sheet_view_buildable_init (GtkBuildableIface *iface)
991 iface->add_child = pspp_sheet_view_buildable_add_child;
995 pspp_sheet_view_init (PsppSheetView *tree_view)
997 tree_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (tree_view, PSPP_TYPE_SHEET_VIEW, PsppSheetViewPrivate);
999 gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
1000 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (tree_view), FALSE);
1002 tree_view->priv->flags = PSPP_SHEET_VIEW_DRAW_KEYFOCUS
1003 | PSPP_SHEET_VIEW_HEADERS_VISIBLE;
1005 /* We need some padding */
1006 tree_view->priv->selected = range_tower_create ();
1007 tree_view->priv->dy = 0;
1008 tree_view->priv->cursor_offset = 0;
1009 tree_view->priv->n_columns = 0;
1010 tree_view->priv->header_height = 1;
1011 tree_view->priv->x_drag = 0;
1012 tree_view->priv->drag_pos = -1;
1013 tree_view->priv->header_has_focus = FALSE;
1014 tree_view->priv->pressed_button = -1;
1015 tree_view->priv->press_start_x = -1;
1016 tree_view->priv->press_start_y = -1;
1017 tree_view->priv->reorderable = FALSE;
1018 tree_view->priv->presize_handler_timer = 0;
1019 tree_view->priv->scroll_sync_timer = 0;
1020 tree_view->priv->fixed_height = -1;
1021 tree_view->priv->fixed_height_set = FALSE;
1022 pspp_sheet_view_set_adjustments (tree_view, NULL, NULL);
1023 tree_view->priv->selection = _pspp_sheet_selection_new_with_tree_view (tree_view);
1024 tree_view->priv->enable_search = TRUE;
1025 tree_view->priv->search_column = -1;
1026 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
1027 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
1028 tree_view->priv->search_custom_entry_set = FALSE;
1029 tree_view->priv->typeselect_flush_timeout = 0;
1030 tree_view->priv->init_hadjust_value = TRUE;
1031 tree_view->priv->width = 0;
1033 tree_view->priv->hover_selection = FALSE;
1035 tree_view->priv->rubber_banding_enable = FALSE;
1037 tree_view->priv->grid_lines = PSPP_SHEET_VIEW_GRID_LINES_NONE;
1039 tree_view->priv->tooltip_column = -1;
1041 tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT;
1043 tree_view->priv->post_validation_flag = FALSE;
1045 tree_view->priv->last_button_x = -1;
1046 tree_view->priv->last_button_y = -1;
1048 tree_view->priv->event_last_x = -10000;
1049 tree_view->priv->event_last_y = -10000;
1051 tree_view->priv->prelight_node = -1;
1052 tree_view->priv->rubber_band_start_node = -1;
1053 tree_view->priv->rubber_band_end_node = -1;
1055 tree_view->priv->anchor_column = NULL;
1057 tree_view->priv->button_style = NULL;
1059 tree_view->dispose_has_run = FALSE;
1068 pspp_sheet_view_set_property (GObject *object,
1070 const GValue *value,
1073 PsppSheetView *tree_view;
1075 tree_view = PSPP_SHEET_VIEW (object);
1080 pspp_sheet_view_set_model (tree_view, g_value_get_object (value));
1082 case PROP_HADJUSTMENT:
1083 pspp_sheet_view_set_hadjustment (tree_view, g_value_get_object (value));
1085 case PROP_VADJUSTMENT:
1086 pspp_sheet_view_set_vadjustment (tree_view, g_value_get_object (value));
1088 case PROP_HEADERS_VISIBLE:
1089 pspp_sheet_view_set_headers_visible (tree_view, g_value_get_boolean (value));
1091 case PROP_HEADERS_CLICKABLE:
1092 pspp_sheet_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
1094 case PROP_REORDERABLE:
1095 pspp_sheet_view_set_reorderable (tree_view, g_value_get_boolean (value));
1097 case PROP_RULES_HINT:
1098 pspp_sheet_view_set_rules_hint (tree_view, g_value_get_boolean (value));
1100 case PROP_ENABLE_SEARCH:
1101 pspp_sheet_view_set_enable_search (tree_view, g_value_get_boolean (value));
1103 case PROP_SEARCH_COLUMN:
1104 pspp_sheet_view_set_search_column (tree_view, g_value_get_int (value));
1106 case PROP_HOVER_SELECTION:
1107 tree_view->priv->hover_selection = g_value_get_boolean (value);
1109 case PROP_RUBBER_BANDING:
1110 tree_view->priv->rubber_banding_enable = g_value_get_boolean (value);
1112 case PROP_ENABLE_GRID_LINES:
1113 pspp_sheet_view_set_grid_lines (tree_view, g_value_get_enum (value));
1115 case PROP_TOOLTIP_COLUMN:
1116 pspp_sheet_view_set_tooltip_column (tree_view, g_value_get_int (value));
1118 case PROP_SPECIAL_CELLS:
1119 pspp_sheet_view_set_special_cells (tree_view, g_value_get_enum (value));
1121 case PROP_FIXED_HEIGHT:
1122 pspp_sheet_view_set_fixed_height (tree_view, g_value_get_int (value));
1124 case PROP_FIXED_HEIGHT_SET:
1125 if (g_value_get_boolean (value))
1127 if (!tree_view->priv->fixed_height_set
1128 && tree_view->priv->fixed_height >= 0)
1130 tree_view->priv->fixed_height_set = true;
1131 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1136 if (tree_view->priv->fixed_height_set)
1138 tree_view->priv->fixed_height_set = false;
1139 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1140 install_presize_handler (tree_view);
1145 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1151 pspp_sheet_view_get_property (GObject *object,
1156 PsppSheetView *tree_view;
1158 tree_view = PSPP_SHEET_VIEW (object);
1163 g_value_set_object (value, tree_view->priv->model);
1165 case PROP_HADJUSTMENT:
1166 g_value_set_object (value, tree_view->priv->hadjustment);
1168 case PROP_VADJUSTMENT:
1169 g_value_set_object (value, tree_view->priv->vadjustment);
1171 case PROP_HEADERS_VISIBLE:
1172 g_value_set_boolean (value, pspp_sheet_view_get_headers_visible (tree_view));
1174 case PROP_HEADERS_CLICKABLE:
1175 g_value_set_boolean (value, pspp_sheet_view_get_headers_clickable (tree_view));
1177 case PROP_REORDERABLE:
1178 g_value_set_boolean (value, tree_view->priv->reorderable);
1180 case PROP_RULES_HINT:
1181 g_value_set_boolean (value, tree_view->priv->has_rules);
1183 case PROP_ENABLE_SEARCH:
1184 g_value_set_boolean (value, tree_view->priv->enable_search);
1186 case PROP_SEARCH_COLUMN:
1187 g_value_set_int (value, tree_view->priv->search_column);
1189 case PROP_HOVER_SELECTION:
1190 g_value_set_boolean (value, tree_view->priv->hover_selection);
1192 case PROP_RUBBER_BANDING:
1193 g_value_set_boolean (value, tree_view->priv->rubber_banding_enable);
1195 case PROP_ENABLE_GRID_LINES:
1196 g_value_set_enum (value, tree_view->priv->grid_lines);
1198 case PROP_TOOLTIP_COLUMN:
1199 g_value_set_int (value, tree_view->priv->tooltip_column);
1201 case PROP_SPECIAL_CELLS:
1202 g_value_set_enum (value, tree_view->priv->special_cells);
1204 case PROP_FIXED_HEIGHT:
1205 g_value_set_int (value, pspp_sheet_view_get_fixed_height (tree_view));
1207 case PROP_FIXED_HEIGHT_SET:
1208 g_value_set_boolean (value, tree_view->priv->fixed_height_set);
1211 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1217 pspp_sheet_view_dispose (GObject *object)
1219 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1221 if (tree_view->dispose_has_run)
1224 tree_view->dispose_has_run = TRUE;
1226 if (tree_view->priv->selection != NULL)
1228 _pspp_sheet_selection_set_tree_view (tree_view->priv->selection, NULL);
1229 g_object_unref (tree_view->priv->selection);
1230 tree_view->priv->selection = NULL;
1233 if (tree_view->priv->hadjustment)
1235 g_object_unref (tree_view->priv->hadjustment);
1236 tree_view->priv->hadjustment = NULL;
1238 if (tree_view->priv->vadjustment)
1240 g_object_unref (tree_view->priv->vadjustment);
1241 tree_view->priv->vadjustment = NULL;
1244 if (tree_view->priv->button_style)
1246 g_object_unref (tree_view->priv->button_style);
1247 tree_view->priv->button_style = NULL;
1251 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->dispose (object);
1257 pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
1258 GtkBuilder *builder,
1262 pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), PSPP_SHEET_VIEW_COLUMN (child));
1266 pspp_sheet_view_finalize (GObject *object)
1268 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1270 pspp_sheet_view_stop_editing (tree_view, TRUE);
1272 if (tree_view->priv->selected != NULL)
1274 range_tower_destroy (tree_view->priv->selected);
1275 tree_view->priv->selected = NULL;
1279 tree_view->priv->prelight_node = -1;
1282 if (tree_view->priv->scroll_to_path != NULL)
1284 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1285 tree_view->priv->scroll_to_path = NULL;
1288 if (tree_view->priv->drag_dest_row != NULL)
1290 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
1291 tree_view->priv->drag_dest_row = NULL;
1294 if (tree_view->priv->top_row != NULL)
1296 gtk_tree_row_reference_free (tree_view->priv->top_row);
1297 tree_view->priv->top_row = NULL;
1300 if (tree_view->priv->column_drop_func_data &&
1301 tree_view->priv->column_drop_func_data_destroy)
1303 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
1304 tree_view->priv->column_drop_func_data = NULL;
1307 if (tree_view->priv->destroy_count_destroy &&
1308 tree_view->priv->destroy_count_data)
1310 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
1311 tree_view->priv->destroy_count_data = NULL;
1314 gtk_tree_row_reference_free (tree_view->priv->cursor);
1315 tree_view->priv->cursor = NULL;
1317 gtk_tree_row_reference_free (tree_view->priv->anchor);
1318 tree_view->priv->anchor = NULL;
1320 /* destroy interactive search dialog */
1321 if (tree_view->priv->search_window)
1323 gtk_widget_destroy (tree_view->priv->search_window);
1324 tree_view->priv->search_window = NULL;
1325 tree_view->priv->search_entry = NULL;
1326 if (tree_view->priv->typeselect_flush_timeout)
1328 g_source_remove (tree_view->priv->typeselect_flush_timeout);
1329 tree_view->priv->typeselect_flush_timeout = 0;
1333 if (tree_view->priv->search_destroy && tree_view->priv->search_user_data)
1335 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
1336 tree_view->priv->search_user_data = NULL;
1339 if (tree_view->priv->search_position_destroy && tree_view->priv->search_position_user_data)
1341 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
1342 tree_view->priv->search_position_user_data = NULL;
1345 pspp_sheet_view_set_model (tree_view, NULL);
1348 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->finalize (object);
1353 /* GtkWidget Methods
1356 /* GtkWidget::map helper */
1358 pspp_sheet_view_map_buttons (PsppSheetView *tree_view)
1362 g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (tree_view)));
1364 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
1366 PsppSheetViewColumn *column;
1368 for (list = tree_view->priv->columns; list; list = list->next)
1370 column = list->data;
1371 if (column->button != NULL &&
1372 gtk_widget_get_visible (column->button) &&
1373 !gtk_widget_get_mapped (column->button))
1374 gtk_widget_map (column->button);
1376 for (list = tree_view->priv->columns; list; list = list->next)
1378 column = list->data;
1379 if (column->visible == FALSE || column->window == NULL)
1381 if (column->resizable)
1383 gdk_window_raise (column->window);
1384 gdk_window_show (column->window);
1387 gdk_window_hide (column->window);
1389 gdk_window_show (tree_view->priv->header_window);
1394 pspp_sheet_view_map (GtkWidget *widget)
1396 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1399 gtk_widget_set_mapped (widget, TRUE);
1401 tmp_list = tree_view->priv->children;
1404 PsppSheetViewChild *child = tmp_list->data;
1405 tmp_list = tmp_list->next;
1407 if (gtk_widget_get_visible (child->widget))
1409 if (!gtk_widget_get_mapped (child->widget))
1410 gtk_widget_map (child->widget);
1413 gdk_window_show (tree_view->priv->bin_window);
1415 pspp_sheet_view_map_buttons (tree_view);
1417 gdk_window_show (widget->window);
1421 pspp_sheet_view_realize (GtkWidget *widget)
1424 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1426 GdkWindowAttr attributes;
1427 gint attributes_mask;
1429 gtk_widget_set_realized (widget, TRUE);
1431 /* Make the main, clipping window */
1432 attributes.window_type = GDK_WINDOW_CHILD;
1433 attributes.x = widget->allocation.x;
1434 attributes.y = widget->allocation.y;
1435 attributes.width = widget->allocation.width;
1436 attributes.height = widget->allocation.height;
1437 attributes.wclass = GDK_INPUT_OUTPUT;
1438 attributes.visual = gtk_widget_get_visual (widget);
1439 attributes.colormap = gtk_widget_get_colormap (widget);
1440 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1442 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1444 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1445 &attributes, attributes_mask);
1446 gdk_window_set_user_data (widget->window, widget);
1448 /* Make the window for the tree */
1450 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1451 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1452 attributes.height = widget->allocation.height;
1453 attributes.event_mask = (GDK_EXPOSURE_MASK |
1455 GDK_POINTER_MOTION_MASK |
1456 GDK_ENTER_NOTIFY_MASK |
1457 GDK_LEAVE_NOTIFY_MASK |
1458 GDK_BUTTON_PRESS_MASK |
1459 GDK_BUTTON_RELEASE_MASK |
1460 gtk_widget_get_events (widget));
1462 tree_view->priv->bin_window = gdk_window_new (widget->window,
1463 &attributes, attributes_mask);
1464 gdk_window_set_user_data (tree_view->priv->bin_window, widget);
1466 /* Make the column header window */
1469 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1470 attributes.height = tree_view->priv->header_height;
1471 attributes.event_mask = (GDK_EXPOSURE_MASK |
1473 GDK_BUTTON_PRESS_MASK |
1474 GDK_BUTTON_RELEASE_MASK |
1475 GDK_KEY_PRESS_MASK |
1476 GDK_KEY_RELEASE_MASK |
1477 gtk_widget_get_events (widget));
1479 tree_view->priv->header_window = gdk_window_new (widget->window,
1480 &attributes, attributes_mask);
1481 gdk_window_set_user_data (tree_view->priv->header_window, widget);
1483 /* Add them all up. */
1484 widget->style = gtk_style_attach (widget->style, widget->window);
1485 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1486 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
1487 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
1489 tmp_list = tree_view->priv->children;
1492 PsppSheetViewChild *child = tmp_list->data;
1493 tmp_list = tmp_list->next;
1495 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1498 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1499 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1501 /* Need to call those here, since they create GCs */
1502 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1504 install_presize_handler (tree_view);
1506 for (i = 0; i < 5; ++i)
1508 tree_view->priv->grid_line_gc[i] = gdk_gc_new (widget->window);
1509 gdk_gc_copy (tree_view->priv->grid_line_gc[i], widget->style->text_aa_gc[i]);
1514 pspp_sheet_view_unrealize (GtkWidget *widget)
1517 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1518 PsppSheetViewPrivate *priv = tree_view->priv;
1521 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1523 if (priv->scroll_timeout != 0)
1525 g_source_remove (priv->scroll_timeout);
1526 priv->scroll_timeout = 0;
1529 if (priv->open_dest_timeout != 0)
1531 g_source_remove (priv->open_dest_timeout);
1532 priv->open_dest_timeout = 0;
1535 if (priv->presize_handler_timer != 0)
1537 g_source_remove (priv->presize_handler_timer);
1538 priv->presize_handler_timer = 0;
1541 if (priv->validate_rows_timer != 0)
1543 g_source_remove (priv->validate_rows_timer);
1544 priv->validate_rows_timer = 0;
1547 if (priv->scroll_sync_timer != 0)
1549 g_source_remove (priv->scroll_sync_timer);
1550 priv->scroll_sync_timer = 0;
1553 if (priv->typeselect_flush_timeout)
1555 g_source_remove (priv->typeselect_flush_timeout);
1556 priv->typeselect_flush_timeout = 0;
1559 for (list = priv->columns; list; list = list->next)
1560 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1562 gdk_window_set_user_data (priv->bin_window, NULL);
1563 gdk_window_destroy (priv->bin_window);
1564 priv->bin_window = NULL;
1566 gdk_window_set_user_data (priv->header_window, NULL);
1567 gdk_window_destroy (priv->header_window);
1568 priv->header_window = NULL;
1570 if (priv->drag_window)
1572 gdk_window_set_user_data (priv->drag_window, NULL);
1573 gdk_window_destroy (priv->drag_window);
1574 priv->drag_window = NULL;
1577 if (priv->drag_highlight_window)
1579 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1580 gdk_window_destroy (priv->drag_highlight_window);
1581 priv->drag_highlight_window = NULL;
1584 for (x = 0 ; x < 5 ; ++x)
1585 g_object_unref (priv->grid_line_gc[x]);
1587 if (tree_view->priv->columns != NULL)
1589 list = tree_view->priv->columns;
1592 PsppSheetViewColumn *column;
1593 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1595 pspp_sheet_view_remove_column (tree_view, column);
1597 tree_view->priv->columns = NULL;
1601 /* GtkWidget::size_request helper */
1603 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1607 tree_view->priv->header_height = 0;
1609 if (tree_view->priv->model)
1611 for (list = tree_view->priv->columns; list; list = list->next)
1613 GtkRequisition requisition;
1614 PsppSheetViewColumn *column = list->data;
1616 pspp_sheet_view_column_size_request (column, &requisition);
1617 column->button_request = requisition.width;
1618 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1624 /* Called only by ::size_request */
1626 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1629 PsppSheetViewColumn *column;
1632 if (tree_view->priv->model == NULL)
1634 tree_view->priv->width = 0;
1635 tree_view->priv->prev_width = 0;
1636 tree_view->priv->height = 0;
1640 tree_view->priv->prev_width = tree_view->priv->width;
1641 tree_view->priv->width = 0;
1643 /* keep this in sync with size_allocate below */
1644 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1646 gint real_requested_width = 0;
1647 column = list->data;
1648 if (!column->visible)
1651 if (column->use_resized_width)
1653 real_requested_width = column->resized_width;
1657 real_requested_width = column->fixed_width;
1660 if (column->min_width != -1)
1661 real_requested_width = MAX (real_requested_width, column->min_width);
1662 if (column->max_width != -1)
1663 real_requested_width = MIN (real_requested_width, column->max_width);
1665 tree_view->priv->width += real_requested_width;
1668 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1672 pspp_sheet_view_size_request (GtkWidget *widget,
1673 GtkRequisition *requisition)
1675 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1678 /* we validate some rows initially just to make sure we have some size.
1679 * In practice, with a lot of static lists, this should get a good width.
1681 initialize_fixed_height_mode (tree_view);
1682 pspp_sheet_view_size_request_columns (tree_view);
1683 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1685 requisition->width = tree_view->priv->width;
1686 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1688 tmp_list = tree_view->priv->children;
1692 PsppSheetViewChild *child = tmp_list->data;
1693 GtkRequisition child_requisition;
1695 tmp_list = tmp_list->next;
1697 if (gtk_widget_get_visible (child->widget))
1698 gtk_widget_size_request (child->widget, &child_requisition);
1703 invalidate_column (PsppSheetView *tree_view,
1704 PsppSheetViewColumn *column)
1706 gint column_offset = 0;
1708 GtkWidget *widget = GTK_WIDGET (tree_view);
1711 if (!gtk_widget_get_realized (widget))
1714 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1715 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1717 list = (rtl ? list->prev : list->next))
1719 PsppSheetViewColumn *tmpcolumn = list->data;
1720 if (tmpcolumn == column)
1722 GdkRectangle invalid_rect;
1724 invalid_rect.x = column_offset;
1726 invalid_rect.width = column->width;
1727 invalid_rect.height = widget->allocation.height;
1729 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
1733 column_offset += tmpcolumn->width;
1738 invalidate_last_column (PsppSheetView *tree_view)
1743 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1745 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1747 last_column = (rtl ? last_column->next : last_column->prev))
1749 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1751 invalidate_column (tree_view, last_column->data);
1758 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1759 PsppSheetViewColumn *column)
1761 gint real_requested_width;
1763 if (column->use_resized_width)
1765 real_requested_width = column->resized_width;
1769 real_requested_width = column->fixed_width;
1772 if (column->min_width != -1)
1773 real_requested_width = MAX (real_requested_width, column->min_width);
1774 if (column->max_width != -1)
1775 real_requested_width = MIN (real_requested_width, column->max_width);
1777 return real_requested_width;
1781 span_intersects (int a0, int a_width,
1782 int b0, int b_width)
1784 int a1 = a0 + a_width;
1785 int b1 = b0 + b_width;
1786 return (a0 >= b0 && a0 < b1) || (b0 >= a0 && b0 < a1);
1789 /* GtkWidget::size_allocate helper */
1791 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1792 gboolean *width_changed)
1794 PsppSheetView *tree_view;
1795 GList *list, *first_column, *last_column;
1796 PsppSheetViewColumn *column;
1797 GtkAllocation allocation;
1799 gint extra, extra_per_column;
1800 gint full_requested_width = 0;
1801 gint number_of_expand_columns = 0;
1802 gboolean column_changed = FALSE;
1805 tree_view = PSPP_SHEET_VIEW (widget);
1807 for (last_column = g_list_last (tree_view->priv->columns);
1808 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1809 last_column = last_column->prev)
1811 if (last_column == NULL)
1814 for (first_column = g_list_first (tree_view->priv->columns);
1815 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1816 first_column = first_column->next)
1820 allocation.height = tree_view->priv->header_height;
1822 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1824 /* find out how many extra space and expandable columns we have */
1825 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1827 column = (PsppSheetViewColumn *)list->data;
1829 if (!column->visible)
1832 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1835 number_of_expand_columns++;
1838 extra = MAX (widget->allocation.width - full_requested_width, 0);
1839 if (number_of_expand_columns > 0)
1840 extra_per_column = extra/number_of_expand_columns;
1842 extra_per_column = 0;
1844 for (list = (rtl ? last_column : first_column);
1845 list != (rtl ? first_column->prev : last_column->next);
1846 list = (rtl ? list->prev : list->next))
1848 gint real_requested_width = 0;
1851 column = list->data;
1852 old_width = column->width;
1854 if (!column->visible)
1857 /* We need to handle the dragged button specially.
1859 if (column == tree_view->priv->drag_column)
1861 GtkAllocation drag_allocation;
1862 gdk_drawable_get_size (tree_view->priv->drag_window,
1863 &(drag_allocation.width),
1864 &(drag_allocation.height));
1865 drag_allocation.x = 0;
1866 drag_allocation.y = 0;
1867 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1869 width += drag_allocation.width;
1873 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1875 allocation.x = width;
1876 column->width = real_requested_width;
1880 if (number_of_expand_columns == 1)
1882 /* We add the remander to the last column as
1884 column->width += extra;
1888 column->width += extra_per_column;
1889 extra -= extra_per_column;
1890 number_of_expand_columns --;
1894 if (column->width != old_width)
1895 g_object_notify (G_OBJECT (column), "width");
1897 allocation.width = column->width;
1898 width += column->width;
1900 if (column->width > old_width)
1901 column_changed = TRUE;
1903 pspp_sheet_view_column_size_allocate (column, &allocation);
1905 if (span_intersects (allocation.x, allocation.width,
1906 tree_view->priv->hadjustment->value,
1907 widget->allocation.width)
1908 && gtk_widget_get_realized (widget))
1909 pspp_sheet_view_column_set_need_button (column, TRUE);
1912 gdk_window_move_resize (column->window,
1913 allocation.x + (rtl ? 0 : allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1915 TREE_VIEW_DRAG_WIDTH, allocation.height);
1918 /* We change the width here. The user might have been resizing columns,
1919 * so the total width of the tree view changes.
1921 tree_view->priv->width = width;
1923 *width_changed = TRUE;
1926 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
1931 pspp_sheet_view_size_allocate (GtkWidget *widget,
1932 GtkAllocation *allocation)
1934 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1936 gboolean width_changed = FALSE;
1937 gint old_width = widget->allocation.width;
1939 if (allocation->width != widget->allocation.width)
1940 width_changed = TRUE;
1942 widget->allocation = *allocation;
1944 tmp_list = tree_view->priv->children;
1948 GtkAllocation allocation;
1950 PsppSheetViewChild *child = tmp_list->data;
1951 tmp_list = tmp_list->next;
1953 /* totally ignore our child's requisition */
1954 allocation.x = child->x;
1955 allocation.y = child->y;
1956 allocation.width = child->width;
1957 allocation.height = child->height;
1958 gtk_widget_size_allocate (child->widget, &allocation);
1961 /* We size-allocate the columns first because the width of the
1962 * tree view (used in updating the adjustments below) might change.
1964 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
1966 tree_view->priv->hadjustment->page_size = allocation->width;
1967 tree_view->priv->hadjustment->page_increment = allocation->width * 0.9;
1968 tree_view->priv->hadjustment->step_increment = allocation->width * 0.1;
1969 tree_view->priv->hadjustment->lower = 0;
1970 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->page_size, tree_view->priv->width);
1972 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
1974 if (allocation->width < tree_view->priv->width)
1976 if (tree_view->priv->init_hadjust_value)
1978 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
1979 tree_view->priv->init_hadjust_value = FALSE;
1981 else if (allocation->width != old_width)
1983 tree_view->priv->hadjustment->value = CLAMP (tree_view->priv->hadjustment->value - allocation->width + old_width, 0, tree_view->priv->width - allocation->width);
1986 tree_view->priv->hadjustment->value = CLAMP (tree_view->priv->width - (tree_view->priv->prev_width - tree_view->priv->hadjustment->value), 0, tree_view->priv->width - allocation->width);
1990 tree_view->priv->hadjustment->value = 0;
1991 tree_view->priv->init_hadjust_value = TRUE;
1995 if (tree_view->priv->hadjustment->value + allocation->width > tree_view->priv->width)
1996 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
1998 gtk_adjustment_changed (tree_view->priv->hadjustment);
2000 tree_view->priv->vadjustment->page_size = allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view);
2001 tree_view->priv->vadjustment->step_increment = tree_view->priv->vadjustment->page_size * 0.1;
2002 tree_view->priv->vadjustment->page_increment = tree_view->priv->vadjustment->page_size * 0.9;
2003 tree_view->priv->vadjustment->lower = 0;
2004 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->page_size, tree_view->priv->height);
2006 gtk_adjustment_changed (tree_view->priv->vadjustment);
2008 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
2009 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
2010 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
2011 else if (tree_view->priv->vadjustment->value + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
2012 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
2013 tree_view->priv->height - tree_view->priv->vadjustment->page_size);
2014 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
2015 pspp_sheet_view_top_row_to_dy (tree_view);
2017 pspp_sheet_view_dy_to_top_row (tree_view);
2019 if (gtk_widget_get_realized (widget))
2021 gdk_window_move_resize (widget->window,
2022 allocation->x, allocation->y,
2023 allocation->width, allocation->height);
2024 gdk_window_move_resize (tree_view->priv->header_window,
2025 - (gint) tree_view->priv->hadjustment->value,
2027 MAX (tree_view->priv->width, allocation->width),
2028 tree_view->priv->header_height);
2029 gdk_window_move_resize (tree_view->priv->bin_window,
2030 - (gint) tree_view->priv->hadjustment->value,
2031 TREE_VIEW_HEADER_HEIGHT (tree_view),
2032 MAX (tree_view->priv->width, allocation->width),
2033 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2036 if (tree_view->priv->row_count == 0)
2037 invalidate_empty_focus (tree_view);
2039 if (gtk_widget_get_realized (widget))
2041 gboolean has_expand_column = FALSE;
2042 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2044 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2046 has_expand_column = TRUE;
2051 /* This little hack only works if we have an LTR locale, and no column has the */
2054 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2055 ! has_expand_column)
2056 invalidate_last_column (tree_view);
2058 gtk_widget_queue_draw (widget);
2063 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2065 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2067 GtkWidget *widget = GTK_WIDGET (tree_view);
2069 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2070 gtk_widget_grab_focus (widget);
2071 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2075 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2078 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2082 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2085 range_tower_set1 (tree_view->priv->selected, node, 1);
2089 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2092 range_tower_set0 (tree_view->priv->selected, node, 1);
2096 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2099 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2103 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2106 return node > 0 ? node - 1 : -1;
2110 all_columns_selected (PsppSheetView *tree_view)
2114 for (list = tree_view->priv->columns; list; list = list->next)
2116 PsppSheetViewColumn *column = list->data;
2117 if (column->selectable && !column->selected)
2125 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2127 PsppSheetViewColumn *column,
2128 GdkEventButton *event)
2130 PsppSheetSelection *selection;
2131 PsppSheetSelectionMode mode;
2133 gboolean update_anchor;
2137 g_return_val_if_fail (tree_view != NULL, FALSE);
2138 g_return_val_if_fail (column != NULL, FALSE);
2140 selection = tree_view->priv->selection;
2141 mode = pspp_sheet_selection_get_mode (selection);
2142 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2145 if (!column->row_head)
2150 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2151 if (event->type != GDK_BUTTON_PRESS
2152 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2158 path = gtk_tree_path_new_from_indices (node, -1);
2161 pspp_sheet_selection_unselect_all (selection);
2162 pspp_sheet_selection_select_path (selection, path);
2163 pspp_sheet_selection_select_all_columns (selection);
2164 update_anchor = TRUE;
2167 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2169 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2170 || !all_columns_selected (tree_view))
2172 pspp_sheet_selection_unselect_all (selection);
2173 pspp_sheet_selection_select_path (selection, path);
2174 pspp_sheet_selection_select_all_columns (selection);
2175 update_anchor = TRUE;
2179 update_anchor = handled = FALSE;
2181 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2182 && modifiers == GDK_CONTROL_MASK)
2184 if (!all_columns_selected (tree_view))
2186 pspp_sheet_selection_unselect_all (selection);
2187 pspp_sheet_selection_select_all_columns (selection);
2190 if (pspp_sheet_selection_path_is_selected (selection, path))
2191 pspp_sheet_selection_unselect_path (selection, path);
2193 pspp_sheet_selection_select_path (selection, path);
2194 update_anchor = TRUE;
2197 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2198 && modifiers == GDK_SHIFT_MASK)
2200 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2201 GtkTreePath *anchor_path;
2203 if (all_columns_selected (tree_view)
2204 && gtk_tree_row_reference_valid (anchor))
2206 update_anchor = FALSE;
2207 anchor_path = gtk_tree_row_reference_get_path (anchor);
2211 update_anchor = TRUE;
2212 anchor_path = gtk_tree_path_copy (path);
2215 pspp_sheet_selection_unselect_all (selection);
2216 pspp_sheet_selection_select_range (selection, anchor_path, path);
2217 pspp_sheet_selection_select_all_columns (selection);
2219 gtk_tree_path_free (anchor_path);
2224 update_anchor = handled = FALSE;
2228 if (tree_view->priv->anchor)
2229 gtk_tree_row_reference_free (tree_view->priv->anchor);
2230 tree_view->priv->anchor =
2231 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2232 tree_view->priv->model,
2236 gtk_tree_path_free (path);
2241 find_click (PsppSheetView *tree_view,
2244 PsppSheetViewColumn **column,
2245 GdkRectangle *background_area,
2246 GdkRectangle *cell_area)
2253 /* find the node that was clicked */
2254 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2257 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2262 background_area->y = y_offset + y;
2263 background_area->height = ROW_HEIGHT (tree_view);
2264 background_area->x = 0;
2266 /* Let the column have a chance at selecting it. */
2267 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2268 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2269 list; list = (rtl ? list->prev : list->next))
2271 PsppSheetViewColumn *candidate = list->data;
2273 if (!candidate->visible)
2276 background_area->width = candidate->width;
2277 if ((background_area->x > x) ||
2278 (background_area->x + background_area->width <= x))
2280 background_area->x += background_area->width;
2284 /* we found the focus column */
2286 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2288 *column = candidate;
2296 pspp_sheet_view_button_press (GtkWidget *widget,
2297 GdkEventButton *event)
2299 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2301 PsppSheetViewColumn *column = NULL;
2303 GdkRectangle background_area;
2304 GdkRectangle cell_area;
2307 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2308 pspp_sheet_view_stop_editing (tree_view, FALSE);
2311 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2312 * we're done handling the button press.
2315 if (event->window == tree_view->priv->bin_window)
2320 gint pre_val, aft_val;
2321 PsppSheetViewColumn *column = NULL;
2322 GtkCellRenderer *focus_cell = NULL;
2323 gboolean row_double_click = FALSE;
2324 gboolean node_selected;
2327 if (tree_view->priv->row_count == 0)
2329 grab_focus_and_unset_draw_keyfocus (tree_view);
2333 if (!find_click (tree_view, event->x, event->y, &node, &column,
2334 &background_area, &cell_area))
2336 grab_focus_and_unset_draw_keyfocus (tree_view);
2340 tree_view->priv->focus_column = column;
2342 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2346 node_selected = pspp_sheet_view_node_is_selected (tree_view, node);
2347 pre_val = tree_view->priv->vadjustment->value;
2349 path = _pspp_sheet_view_find_path (tree_view, node);
2351 /* we only handle selection modifications on the first button press
2353 if (event->type == GDK_BUTTON_PRESS)
2355 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2356 tree_view->priv->ctrl_pressed = TRUE;
2357 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2358 tree_view->priv->shift_pressed = TRUE;
2360 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2362 pspp_sheet_view_column_focus_cell (column, focus_cell);
2364 if (event->state & GDK_CONTROL_MASK)
2366 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
2367 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2369 else if (event->state & GDK_SHIFT_MASK)
2371 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
2372 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE);
2376 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
2379 if (tree_view->priv->anchor_column == NULL ||
2380 !(event->state & GDK_SHIFT_MASK))
2381 tree_view->priv->anchor_column = column;
2382 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2383 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2384 tree_view->priv->anchor_column,
2387 tree_view->priv->ctrl_pressed = FALSE;
2388 tree_view->priv->shift_pressed = FALSE;
2391 /* the treeview may have been scrolled because of _set_cursor,
2395 aft_val = tree_view->priv->vadjustment->value;
2396 dval = pre_val - aft_val;
2398 cell_area.y += dval;
2399 background_area.y += dval;
2401 /* Save press to possibly begin a drag
2403 if (!tree_view->priv->in_grab &&
2404 tree_view->priv->pressed_button < 0)
2406 tree_view->priv->pressed_button = event->button;
2407 tree_view->priv->press_start_x = event->x;
2408 tree_view->priv->press_start_y = event->y;
2409 tree_view->priv->press_start_node = node;
2411 if (tree_view->priv->rubber_banding_enable
2413 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2414 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2416 tree_view->priv->press_start_y += tree_view->priv->dy;
2417 tree_view->priv->rubber_band_x = event->x;
2418 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2419 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2421 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2422 tree_view->priv->rubber_band_ctrl = TRUE;
2423 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2424 tree_view->priv->rubber_band_shift = TRUE;
2429 /* Test if a double click happened on the same row. */
2430 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2432 int double_click_time, double_click_distance;
2434 g_object_get (gtk_settings_get_for_screen (
2435 gtk_widget_get_screen (widget)),
2436 "gtk-double-click-time", &double_click_time,
2437 "gtk-double-click-distance", &double_click_distance,
2440 /* Same conditions as _gdk_event_button_generate */
2441 if (tree_view->priv->last_button_x != -1 &&
2442 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2443 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2444 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2446 /* We do no longer compare paths of this row and the
2447 * row clicked previously. We use the double click
2448 * distance to decide whether this is a valid click,
2449 * allowing the mouse to slightly move over another row.
2451 row_double_click = TRUE;
2453 tree_view->priv->last_button_time = 0;
2454 tree_view->priv->last_button_x = -1;
2455 tree_view->priv->last_button_y = -1;
2459 tree_view->priv->last_button_time = event->time;
2460 tree_view->priv->last_button_x = event->x;
2461 tree_view->priv->last_button_y = event->y;
2465 if (row_double_click)
2467 gtk_grab_remove (widget);
2468 pspp_sheet_view_row_activated (tree_view, path, column);
2470 if (tree_view->priv->pressed_button == event->button)
2471 tree_view->priv->pressed_button = -1;
2474 gtk_tree_path_free (path);
2476 /* If we activated the row through a double click we don't want to grab
2477 * focus back, as moving focus to another widget is pretty common.
2479 if (!row_double_click)
2480 grab_focus_and_unset_draw_keyfocus (tree_view);
2485 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2487 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2489 column = list->data;
2490 if (event->window == column->window &&
2491 column->resizable &&
2496 if (gdk_pointer_grab (column->window, FALSE,
2497 GDK_POINTER_MOTION_HINT_MASK |
2498 GDK_BUTTON1_MOTION_MASK |
2499 GDK_BUTTON_RELEASE_MASK,
2500 NULL, NULL, event->time))
2503 gtk_grab_add (widget);
2504 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2505 column->resized_width = column->width;
2507 /* block attached dnd signal handler */
2508 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2510 g_signal_handlers_block_matched (widget,
2511 G_SIGNAL_MATCH_DATA,
2515 tree_view->priv->drag_pos = i;
2516 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2518 if (!gtk_widget_has_focus (widget))
2519 gtk_widget_grab_focus (widget);
2527 /* GtkWidget::button_release_event helper */
2529 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2530 GdkEventButton *event)
2532 PsppSheetView *tree_view;
2536 tree_view = PSPP_SHEET_VIEW (widget);
2538 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2539 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2540 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2542 /* Move the button back */
2543 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2545 g_object_ref (tree_view->priv->drag_column->button);
2546 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2547 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2548 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2549 g_object_unref (tree_view->priv->drag_column->button);
2550 gtk_widget_queue_resize (widget);
2551 if (tree_view->priv->drag_column->resizable)
2553 gdk_window_raise (tree_view->priv->drag_column->window);
2554 gdk_window_show (tree_view->priv->drag_column->window);
2557 gdk_window_hide (tree_view->priv->drag_column->window);
2559 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2563 if (tree_view->priv->cur_reorder &&
2564 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2565 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2566 tree_view->priv->cur_reorder->right_column);
2570 if (tree_view->priv->cur_reorder &&
2571 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2572 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2573 tree_view->priv->cur_reorder->left_column);
2575 tree_view->priv->drag_column = NULL;
2576 gdk_window_hide (tree_view->priv->drag_window);
2578 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2579 g_slice_free (PsppSheetViewColumnReorder, l->data);
2580 g_list_free (tree_view->priv->column_drag_info);
2581 tree_view->priv->column_drag_info = NULL;
2582 tree_view->priv->cur_reorder = NULL;
2584 if (tree_view->priv->drag_highlight_window)
2585 gdk_window_hide (tree_view->priv->drag_highlight_window);
2587 /* Reset our flags */
2588 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2589 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2594 /* GtkWidget::button_release_event helper */
2596 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2597 GdkEventButton *event)
2599 PsppSheetView *tree_view;
2602 tree_view = PSPP_SHEET_VIEW (widget);
2604 tree_view->priv->drag_pos = -1;
2606 /* unblock attached dnd signal handler */
2607 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2609 g_signal_handlers_unblock_matched (widget,
2610 G_SIGNAL_MATCH_DATA,
2614 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2615 gtk_grab_remove (widget);
2616 gdk_display_pointer_ungrab (gdk_drawable_get_display (event->window),
2622 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2623 GdkEventButton *event)
2625 GtkCellEditable *cell_editable;
2630 PsppSheetViewColumn *column;
2631 GdkRectangle background_area;
2632 GdkRectangle cell_area;
2638 if (event->window != tree_view->priv->bin_window)
2641 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2645 /* decide if we edit */
2646 path = _pspp_sheet_view_find_path (tree_view, node);
2647 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2648 if (event->button != 1 || modifiers)
2651 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2652 pspp_sheet_view_column_cell_set_cell_data (column,
2653 tree_view->priv->model,
2656 if (!pspp_sheet_view_column_get_quick_edit (column)
2657 && _pspp_sheet_view_column_has_editable_cell (column))
2660 flags = 0; /* FIXME: get the right flags */
2661 path_string = gtk_tree_path_to_string (path);
2663 if (!_pspp_sheet_view_column_cell_event (column,
2671 if (cell_editable == NULL)
2674 pspp_sheet_view_real_set_cursor (tree_view, path,
2676 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2679 _pspp_sheet_view_column_get_neighbor_sizes (
2680 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2683 area.width -= right + left;
2685 pspp_sheet_view_real_start_editing (tree_view,
2692 g_free (path_string);
2693 gtk_tree_path_free (path);
2698 pspp_sheet_view_button_release (GtkWidget *widget,
2699 GdkEventButton *event)
2701 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2703 pspp_sheet_view_stop_editing (tree_view, FALSE);
2704 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2705 && pspp_sheet_view_button_release_edit (tree_view, event))
2707 if (tree_view->priv->pressed_button == event->button)
2708 tree_view->priv->pressed_button = -1;
2710 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2714 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2715 return pspp_sheet_view_button_release_drag_column (widget, event);
2717 if (tree_view->priv->rubber_band_status)
2718 pspp_sheet_view_stop_rubber_band (tree_view);
2720 if (tree_view->priv->pressed_button == event->button)
2721 tree_view->priv->pressed_button = -1;
2723 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2724 return pspp_sheet_view_button_release_column_resize (widget, event);
2730 pspp_sheet_view_grab_broken (GtkWidget *widget,
2731 GdkEventGrabBroken *event)
2733 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2735 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2736 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2738 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2739 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2744 /* GtkWidget::motion_event function set.
2748 do_prelight (PsppSheetView *tree_view,
2750 /* these are in bin_window coords */
2754 int prev_node = tree_view->priv->prelight_node;
2756 if (prev_node != node)
2758 tree_view->priv->prelight_node = node;
2761 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2764 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2769 prelight_or_select (PsppSheetView *tree_view,
2771 /* these are in bin_window coords */
2775 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2777 if (tree_view->priv->hover_selection &&
2778 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2779 !(tree_view->priv->edited_column &&
2780 tree_view->priv->edited_column->editable_widget))
2784 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2788 path = _pspp_sheet_view_find_path (tree_view, node);
2789 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2790 if (pspp_sheet_view_node_is_selected (tree_view, node))
2792 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2793 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE);
2795 gtk_tree_path_free (path);
2799 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2800 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2803 do_prelight (tree_view, node, x, y);
2807 ensure_unprelighted (PsppSheetView *tree_view)
2809 do_prelight (tree_view,
2811 -1000, -1000); /* coords not possibly over an arrow */
2813 g_assert (tree_view->priv->prelight_node < 0);
2817 update_prelight (PsppSheetView *tree_view,
2824 if (tree_view->priv->row_count == 0)
2829 ensure_unprelighted (tree_view);
2833 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2837 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2840 prelight_or_select (tree_view, node, x, y);
2846 /* Our motion arrow is either a box (in the case of the original spot)
2847 * or an arrow. It is expander_size wide.
2870 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2872 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2873 GtkWidget *widget = GTK_WIDGET (tree_view);
2874 GdkBitmap *mask = NULL;
2879 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2880 GdkWindowAttr attributes;
2881 guint attributes_mask;
2884 reorder->left_column == tree_view->priv->drag_column ||
2885 reorder->right_column == tree_view->priv->drag_column)
2886 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2887 else if (reorder->left_column || reorder->right_column)
2889 GdkRectangle visible_rect;
2890 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2891 if (reorder->left_column)
2892 x = reorder->left_column->allocation.x + reorder->left_column->allocation.width;
2894 x = reorder->right_column->allocation.x;
2896 if (x < visible_rect.x)
2897 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2898 else if (x > visible_rect.x + visible_rect.width)
2899 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2901 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2904 /* We want to draw the rectangle over the initial location. */
2905 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2910 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2912 if (tree_view->priv->drag_highlight_window)
2914 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2916 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2919 attributes.window_type = GDK_WINDOW_CHILD;
2920 attributes.wclass = GDK_INPUT_OUTPUT;
2921 attributes.x = tree_view->priv->drag_column_x;
2923 width = attributes.width = tree_view->priv->drag_column->allocation.width;
2924 height = attributes.height = tree_view->priv->drag_column->allocation.height;
2925 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2926 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2927 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2928 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2929 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
2930 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2932 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2933 gc = gdk_gc_new (mask);
2935 gdk_gc_set_foreground (gc, &col);
2936 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2938 gdk_gc_set_foreground(gc, &col);
2939 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
2940 g_object_unref (gc);
2942 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
2944 if (mask) g_object_unref (mask);
2945 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2948 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
2954 width = tree_view->priv->expander_size;
2956 /* Get x, y, width, height of arrow */
2957 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
2958 if (reorder->left_column)
2960 x += reorder->left_column->allocation.x + reorder->left_column->allocation.width - width/2;
2961 height = reorder->left_column->allocation.height;
2965 x += reorder->right_column->allocation.x - width/2;
2966 height = reorder->right_column->allocation.height;
2968 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
2969 height += tree_view->priv->expander_size;
2971 /* Create the new window */
2972 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
2974 if (tree_view->priv->drag_highlight_window)
2976 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2978 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2981 attributes.window_type = GDK_WINDOW_TEMP;
2982 attributes.wclass = GDK_INPUT_OUTPUT;
2983 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2984 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2985 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2986 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2989 attributes.width = width;
2990 attributes.height = height;
2991 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
2992 &attributes, attributes_mask);
2993 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2995 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2996 gc = gdk_gc_new (mask);
2998 gdk_gc_set_foreground (gc, &col);
2999 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3001 /* Draw the 2 arrows as per above */
3003 gdk_gc_set_foreground (gc, &col);
3004 for (i = 0; i < width; i ++)
3006 if (i == (width/2 - 1))
3008 gdk_draw_line (mask, gc, i, j, i, height - j);
3009 if (i < (width/2 - 1))
3014 g_object_unref (gc);
3015 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3017 if (mask) g_object_unref (mask);
3020 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
3021 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3023 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
3024 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3030 width = tree_view->priv->expander_size;
3032 /* Get x, y, width, height of arrow */
3033 width = width/2; /* remember, the arrow only takes half the available width */
3034 gdk_window_get_origin (widget->window, &x, &y);
3035 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3036 x += widget->allocation.width - width;
3038 if (reorder->left_column)
3039 height = reorder->left_column->allocation.height;
3041 height = reorder->right_column->allocation.height;
3043 y -= tree_view->priv->expander_size;
3044 height += 2*tree_view->priv->expander_size;
3046 /* Create the new window */
3047 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
3048 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3050 if (tree_view->priv->drag_highlight_window)
3052 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3054 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3057 attributes.window_type = GDK_WINDOW_TEMP;
3058 attributes.wclass = GDK_INPUT_OUTPUT;
3059 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3060 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3061 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3062 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3065 attributes.width = width;
3066 attributes.height = height;
3067 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3068 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3070 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3071 gc = gdk_gc_new (mask);
3073 gdk_gc_set_foreground (gc, &col);
3074 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3076 /* Draw the 2 arrows as per above */
3078 gdk_gc_set_foreground (gc, &col);
3079 j = tree_view->priv->expander_size;
3080 for (i = 0; i < width; i ++)
3083 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3087 gdk_draw_line (mask, gc, k, j, k, height - j);
3088 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3089 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3092 g_object_unref (gc);
3093 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3095 if (mask) g_object_unref (mask);
3098 tree_view->priv->drag_column_window_state = arrow_type;
3099 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3103 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3104 gdk_window_hide (tree_view->priv->drag_highlight_window);
3108 gdk_window_show (tree_view->priv->drag_highlight_window);
3109 gdk_window_raise (tree_view->priv->drag_highlight_window);
3113 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3114 GdkEventMotion *event)
3118 PsppSheetViewColumn *column;
3119 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3121 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3123 if (event->is_hint || event->window != widget->window)
3124 gtk_widget_get_pointer (widget, &x, NULL);
3128 if (tree_view->priv->hadjustment)
3129 x += tree_view->priv->hadjustment->value;
3131 new_width = pspp_sheet_view_new_column_width (tree_view,
3132 tree_view->priv->drag_pos, &x);
3133 if (x != tree_view->priv->x_drag &&
3134 (new_width != column->fixed_width))
3136 column->use_resized_width = TRUE;
3137 column->resized_width = new_width;
3140 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3142 gtk_widget_queue_resize (widget);
3150 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3152 PsppSheetViewColumnReorder *reorder = NULL;
3156 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3157 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3159 reorder = (PsppSheetViewColumnReorder *) list->data;
3160 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3165 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3168 tree_view->priv->cur_reorder = reorder;
3169 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3173 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3175 GdkRectangle visible_rect;
3180 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3181 y += tree_view->priv->dy;
3183 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3185 /* see if we are near the edge. */
3186 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3189 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3194 value = CLAMP (tree_view->priv->vadjustment->value + offset, 0.0,
3195 tree_view->priv->vadjustment->upper - tree_view->priv->vadjustment->page_size);
3196 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3200 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3202 GdkRectangle visible_rect;
3207 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3209 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3211 /* See if we are near the edge. */
3212 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3215 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3221 value = CLAMP (tree_view->priv->hadjustment->value + offset,
3222 0.0, tree_view->priv->hadjustment->upper - tree_view->priv->hadjustment->page_size);
3223 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3230 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3231 GdkEventMotion *event)
3233 PsppSheetView *tree_view = (PsppSheetView *) widget;
3234 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3238 if ((column == NULL) ||
3239 (event->window != tree_view->priv->drag_window))
3242 /* Handle moving the header */
3243 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3244 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3245 MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width) - column->allocation.width);
3246 gdk_window_move (tree_view->priv->drag_window, x, y);
3248 /* autoscroll, if needed */
3249 pspp_sheet_view_horizontal_autoscroll (tree_view);
3250 /* Update the current reorder position and arrow; */
3251 pspp_sheet_view_update_current_reorder (tree_view);
3257 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3259 remove_scroll_timeout (tree_view);
3260 gtk_grab_remove (GTK_WIDGET (tree_view));
3262 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3264 GtkTreePath *tmp_path;
3266 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3268 /* The anchor path should be set to the start path */
3269 tmp_path = _pspp_sheet_view_find_path (tree_view,
3270 tree_view->priv->rubber_band_start_node);
3272 if (tree_view->priv->anchor)
3273 gtk_tree_row_reference_free (tree_view->priv->anchor);
3275 tree_view->priv->anchor =
3276 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3277 tree_view->priv->model,
3280 gtk_tree_path_free (tmp_path);
3282 /* ... and the cursor to the end path */
3283 tmp_path = _pspp_sheet_view_find_path (tree_view,
3284 tree_view->priv->rubber_band_end_node);
3285 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE);
3286 gtk_tree_path_free (tmp_path);
3288 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3291 /* Clear status variables */
3292 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3293 tree_view->priv->rubber_band_shift = 0;
3294 tree_view->priv->rubber_band_ctrl = 0;
3296 tree_view->priv->rubber_band_start_node = -1;
3297 tree_view->priv->rubber_band_end_node = -1;
3301 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3305 gboolean skip_start,
3308 if (start_node == end_node)
3311 /* We skip the first node and jump inside the loop */
3317 /* Small optimization by assuming insensitive nodes are never
3322 if (tree_view->priv->rubber_band_shift)
3323 pspp_sheet_view_node_select (tree_view, start_node);
3324 else if (tree_view->priv->rubber_band_ctrl)
3326 /* Toggle the selection state */
3327 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3328 pspp_sheet_view_node_unselect (tree_view, start_node);
3330 pspp_sheet_view_node_select (tree_view, start_node);
3333 pspp_sheet_view_node_select (tree_view, start_node);
3337 /* Mirror the above */
3338 if (tree_view->priv->rubber_band_shift)
3339 pspp_sheet_view_node_unselect (tree_view, start_node);
3340 else if (tree_view->priv->rubber_band_ctrl)
3342 /* Toggle the selection state */
3343 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3344 pspp_sheet_view_node_unselect (tree_view, start_node);
3346 pspp_sheet_view_node_select (tree_view, start_node);
3349 pspp_sheet_view_node_unselect (tree_view, start_node);
3352 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3354 if (start_node == end_node)
3359 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3362 /* Ran out of tree */
3365 if (skip_end && start_node == end_node)
3372 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3375 return node * tree_view->priv->fixed_height;
3379 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3383 int fixed_height = tree_view->priv->fixed_height;
3384 if (fixed_height <= 0
3386 || height >= tree_view->priv->row_count * fixed_height)
3393 *new_node = height / fixed_height;
3394 return height % fixed_height;
3399 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3404 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3405 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3407 /* Handle the start area first */
3408 if (tree_view->priv->rubber_band_start_node < 0)
3410 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3417 else if (start_node < tree_view->priv->rubber_band_start_node)
3419 /* New node is above the old one; selection became bigger */
3420 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3422 tree_view->priv->rubber_band_start_node,
3427 else if (start_node > tree_view->priv->rubber_band_start_node)
3429 /* New node is below the old one; selection became smaller */
3430 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3431 tree_view->priv->rubber_band_start_node,
3438 tree_view->priv->rubber_band_start_node = start_node;
3440 /* Next, handle the end area */
3441 if (tree_view->priv->rubber_band_end_node < 0)
3443 /* In the event this happens, start_node was also -1; this case is
3447 else if (end_node < 0)
3449 /* Find the last node in the tree */
3450 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3453 /* Selection reached end of the tree */
3454 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3455 tree_view->priv->rubber_band_end_node,
3461 else if (end_node > tree_view->priv->rubber_band_end_node)
3463 /* New node is below the old one; selection became bigger */
3464 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3465 tree_view->priv->rubber_band_end_node,
3471 else if (end_node < tree_view->priv->rubber_band_end_node)
3473 /* New node is above the old one; selection became smaller */
3474 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3476 tree_view->priv->rubber_band_end_node,
3482 tree_view->priv->rubber_band_end_node = end_node;
3486 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3489 GdkRectangle old_area;
3490 GdkRectangle new_area;
3491 GdkRectangle common;
3492 GdkRegion *invalid_region;
3493 PsppSheetViewColumn *column;
3495 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3496 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3497 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3498 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3500 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3503 y = MAX (y, 0) + tree_view->priv->dy;
3505 new_area.x = MIN (tree_view->priv->press_start_x, x);
3506 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3507 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3508 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3510 invalid_region = gdk_region_rectangle (&old_area);
3511 gdk_region_union_with_rect (invalid_region, &new_area);
3513 gdk_rectangle_intersect (&old_area, &new_area, &common);
3514 if (common.width > 2 && common.height > 2)
3516 GdkRegion *common_region;
3518 /* make sure the border is invalidated */
3524 common_region = gdk_region_rectangle (&common);
3526 gdk_region_subtract (invalid_region, common_region);
3527 gdk_region_destroy (common_region);
3530 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3532 gdk_region_destroy (invalid_region);
3534 tree_view->priv->rubber_band_x = x;
3535 tree_view->priv->rubber_band_y = y;
3536 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3538 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3539 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3540 tree_view->priv->anchor_column,
3543 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3545 pspp_sheet_view_update_rubber_band_selection (tree_view);
3549 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3554 GdkRectangle rubber_rect;
3557 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3558 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3559 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3560 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3562 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3565 cr = gdk_cairo_create (tree_view->priv->bin_window);
3566 cairo_set_line_width (cr, 1.0);
3568 cairo_set_source_rgba (cr,
3569 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3570 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3571 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.,
3574 gdk_cairo_rectangle (cr, &rect);
3578 cairo_set_source_rgb (cr,
3579 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3580 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3581 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.);
3583 cairo_rectangle (cr,
3584 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3585 rubber_rect.width - 1, rubber_rect.height - 1);
3592 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3593 GdkEventMotion *event)
3595 PsppSheetView *tree_view;
3599 tree_view = (PsppSheetView *) widget;
3601 if (tree_view->priv->row_count == 0)
3604 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3606 GdkRectangle background_area, cell_area;
3607 PsppSheetViewColumn *column;
3609 if (find_click (tree_view, event->x, event->y, &node, &column,
3610 &background_area, &cell_area)
3611 && tree_view->priv->focus_column == column
3612 && tree_view->priv->press_start_node == node)
3615 gtk_grab_add (GTK_WIDGET (tree_view));
3616 pspp_sheet_view_update_rubber_band (tree_view);
3618 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3620 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3622 pspp_sheet_view_update_rubber_band (tree_view);
3624 add_scroll_timeout (tree_view);
3627 /* only check for an initiated drag when a button is pressed */
3628 if (tree_view->priv->pressed_button >= 0
3629 && !tree_view->priv->rubber_band_status)
3630 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3632 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3636 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3638 tree_view->priv->event_last_x = event->x;
3639 tree_view->priv->event_last_y = event->y;
3641 prelight_or_select (tree_view, node, event->x, event->y);
3647 pspp_sheet_view_motion (GtkWidget *widget,
3648 GdkEventMotion *event)
3650 PsppSheetView *tree_view;
3652 tree_view = (PsppSheetView *) widget;
3654 /* Resizing a column */
3655 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3656 return pspp_sheet_view_motion_resize_column (widget, event);
3659 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3660 return pspp_sheet_view_motion_drag_column (widget, event);
3662 /* Sanity check it */
3663 if (event->window == tree_view->priv->bin_window)
3664 return pspp_sheet_view_motion_bin_window (widget, event);
3669 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3670 * the tree is empty.
3673 invalidate_empty_focus (PsppSheetView *tree_view)
3677 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3682 gdk_drawable_get_size (tree_view->priv->bin_window, &area.width, &area.height);
3683 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3686 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3690 draw_empty_focus (PsppSheetView *tree_view, GdkRectangle *clip_area)
3692 GtkWidget *widget = GTK_WIDGET (tree_view);
3695 if (!gtk_widget_has_focus (widget))
3698 gdk_drawable_get_size (tree_view->priv->bin_window, &w, &h);
3704 gtk_paint_focus (gtk_widget_get_style (widget),
3705 tree_view->priv->bin_window,
3706 gtk_widget_get_state (widget),
3714 pspp_sheet_view_draw_grid_lines (PsppSheetView *tree_view,
3715 GdkEventExpose *event,
3716 gint n_visible_columns,
3720 GList *list = tree_view->priv->columns;
3725 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3726 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3729 gdk_drawable_get_size (event->window, NULL, &height);
3731 /* Only draw the lines for visible rows and columns */
3732 for (list = tree_view->priv->columns; list; list = list->next, i++)
3734 PsppSheetViewColumn *column = list->data;
3736 /* We don't want a line for the last column */
3737 if (i == n_visible_columns - 1)
3740 if (! column->visible)
3743 current_x += column->width;
3745 if (current_x - 1 >= event->area.x
3746 && current_x - 1 < event->area.x + event->area.width)
3747 gdk_draw_line (event->window,
3748 tree_view->priv->grid_line_gc[GTK_WIDGET(tree_view)->state],
3749 current_x - 1, min_y,
3750 current_x - 1, max_y - min_y);
3754 /* Warning: Very scary function.
3755 * Modify at your own risk
3757 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3758 * FIXME: It's not...
3761 pspp_sheet_view_bin_expose (GtkWidget *widget,
3762 GdkEventExpose *event)
3764 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3769 int drag_highlight = -1;
3772 gint y_offset, cell_offset;
3775 GdkRectangle background_area;
3776 GdkRectangle cell_area;
3778 gint bin_window_width;
3779 gint bin_window_height;
3780 GtkTreePath *cursor_path;
3781 GtkTreePath *drag_dest_path;
3782 GList *first_column, *last_column;
3783 gint vertical_separator;
3784 gint horizontal_separator;
3785 gint focus_line_width;
3786 gboolean allow_rules;
3787 gboolean has_special_cell;
3789 gint n_visible_columns;
3790 gint grid_line_width;
3791 gboolean row_ending_details;
3792 gboolean draw_vgrid_lines, draw_hgrid_lines;
3795 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3797 gtk_widget_style_get (widget,
3798 "horizontal-separator", &horizontal_separator,
3799 "vertical-separator", &vertical_separator,
3800 "allow-rules", &allow_rules,
3801 "focus-line-width", &focus_line_width,
3802 "row-ending-details", &row_ending_details,
3805 if (tree_view->priv->row_count == 0)
3807 draw_empty_focus (tree_view, &event->area);
3811 /* clip event->area to the visible area */
3812 if (event->area.height < 0)
3815 validate_visible_area (tree_view);
3817 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, event->area.y);
3821 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3822 gdk_drawable_get_size (tree_view->priv->bin_window,
3823 &bin_window_width, &bin_window_height);
3825 if (tree_view->priv->height < bin_window_height)
3827 gtk_paint_flat_box (widget->style,
3834 0, tree_view->priv->height,
3836 bin_window_height - tree_view->priv->height);
3842 /* find the path for the node */
3843 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3844 gtk_tree_model_get_iter (tree_view->priv->model,
3847 depth = gtk_tree_path_get_depth (path);
3848 gtk_tree_path_free (path);
3851 drag_dest_path = NULL;
3853 if (tree_view->priv->cursor)
3854 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3857 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3859 if (tree_view->priv->drag_dest_row)
3860 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3863 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3867 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3868 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3870 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3871 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3873 if (draw_vgrid_lines || draw_hgrid_lines)
3874 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3876 n_visible_columns = 0;
3877 for (list = tree_view->priv->columns; list; list = list->next)
3879 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3881 n_visible_columns ++;
3884 /* Find the last column */
3885 for (last_column = g_list_last (tree_view->priv->columns);
3886 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
3887 last_column = last_column->prev)
3891 for (first_column = g_list_first (tree_view->priv->columns);
3892 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
3893 first_column = first_column->next)
3896 /* Actually process the expose event. To do this, we want to
3897 * start at the first node of the event, and walk the tree in
3898 * order, drawing each successive node.
3905 gboolean is_first = FALSE;
3906 gboolean is_last = FALSE;
3907 gboolean done = FALSE;
3910 max_height = ROW_HEIGHT (tree_view);
3914 background_area.y = y_offset + event->area.y;
3915 background_area.height = max_height;
3916 max_y = background_area.y + max_height;
3920 if (node == tree_view->priv->prelight_node)
3921 flags |= GTK_CELL_RENDERER_PRELIT;
3923 selected = pspp_sheet_view_node_is_selected (tree_view, node);
3927 if (tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
3929 /* we *need* to set cell data on all cells before the call
3930 * to _has_special_cell, else _has_special_cell() does not
3931 * return a correct value.
3933 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3935 list = (rtl ? list->prev : list->next))
3937 PsppSheetViewColumn *column = list->data;
3938 pspp_sheet_view_column_cell_set_cell_data (column,
3939 tree_view->priv->model,
3943 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
3946 has_special_cell = tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
3948 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3950 list = (rtl ? list->prev : list->next))
3952 PsppSheetViewColumn *column = list->data;
3953 const gchar *detail = NULL;
3954 gboolean selected_column;
3957 if (!column->visible)
3960 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
3961 selected_column = column->selected && column->selectable;
3963 selected_column = TRUE;
3965 if (cell_offset > event->area.x + event->area.width ||
3966 cell_offset + column->width < event->area.x)
3968 cell_offset += column->width;
3972 if (selected && selected_column)
3973 flags |= GTK_CELL_RENDERER_SELECTED;
3975 flags &= ~GTK_CELL_RENDERER_SELECTED;
3977 if (column->show_sort_indicator)
3978 flags |= GTK_CELL_RENDERER_SORTED;
3980 flags &= ~GTK_CELL_RENDERER_SORTED;
3983 flags |= GTK_CELL_RENDERER_FOCUSED;
3985 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3987 background_area.x = cell_offset;
3988 background_area.width = column->width;
3990 cell_area = background_area;
3991 cell_area.y += vertical_separator / 2;
3992 cell_area.x += horizontal_separator / 2;
3993 cell_area.height -= vertical_separator;
3994 cell_area.width -= horizontal_separator;
3996 if (draw_vgrid_lines)
3998 if (list == first_column)
4000 cell_area.width -= grid_line_width / 2;
4002 else if (list == last_column)
4004 cell_area.x += grid_line_width / 2;
4005 cell_area.width -= grid_line_width / 2;
4009 cell_area.x += grid_line_width / 2;
4010 cell_area.width -= grid_line_width;
4014 if (draw_hgrid_lines)
4016 cell_area.y += grid_line_width / 2;
4017 cell_area.height -= grid_line_width;
4020 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
4022 cell_offset += column->width;
4026 pspp_sheet_view_column_cell_set_cell_data (column,
4027 tree_view->priv->model,
4030 /* Select the detail for drawing the cell. relevant
4031 * factors are parity, sortedness, and whether to
4034 if (allow_rules && tree_view->priv->has_rules)
4036 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4037 n_visible_columns >= 3)
4040 detail = "cell_odd_ruled_sorted";
4042 detail = "cell_even_ruled_sorted";
4047 detail = "cell_odd_ruled";
4049 detail = "cell_even_ruled";
4054 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4055 n_visible_columns >= 3)
4058 detail = "cell_odd_sorted";
4060 detail = "cell_even_sorted";
4065 detail = "cell_odd";
4067 detail = "cell_even";
4073 if (widget->state == GTK_STATE_INSENSITIVE)
4074 state = GTK_STATE_INSENSITIVE;
4075 else if (flags & GTK_CELL_RENDERER_SELECTED)
4076 state = GTK_STATE_SELECTED;
4078 state = GTK_STATE_NORMAL;
4080 /* Draw background */
4081 if (row_ending_details)
4083 char new_detail[128];
4085 is_first = (rtl ? !list->next : !list->prev);
4086 is_last = (rtl ? !list->prev : !list->next);
4088 /* (I don't like the snprintfs either, but couldn't find a
4091 if (is_first && is_last)
4092 g_snprintf (new_detail, 127, "%s", detail);
4094 g_snprintf (new_detail, 127, "%s_start", detail);
4096 g_snprintf (new_detail, 127, "%s_end", detail);
4098 g_snprintf (new_detail, 128, "%s_middle", detail);
4100 gtk_paint_flat_box (widget->style,
4109 background_area.width,
4110 background_area.height);
4114 gtk_paint_flat_box (widget->style,
4123 background_area.width,
4124 background_area.height);
4127 if (draw_hgrid_lines)
4129 if (background_area.y > 0)
4130 gdk_draw_line (event->window,
4131 tree_view->priv->grid_line_gc[widget->state],
4132 background_area.x, background_area.y,
4133 background_area.x + background_area.width,
4136 if (y_offset + max_height >= event->area.height)
4137 gdk_draw_line (event->window,
4138 tree_view->priv->grid_line_gc[widget->state],
4139 background_area.x, background_area.y + max_height,
4140 background_area.x + background_area.width,
4141 background_area.y + max_height);
4144 _pspp_sheet_view_column_cell_render (column,
4151 if (node == cursor && has_special_cell &&
4152 ((column == tree_view->priv->focus_column &&
4153 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4154 gtk_widget_has_focus (widget)) ||
4155 (column == tree_view->priv->edited_column)))
4157 _pspp_sheet_view_column_cell_draw_focus (column,
4165 cell_offset += column->width;
4168 if (cell_offset < event->area.x)
4170 gtk_paint_flat_box (widget->style,
4179 event->area.x - cell_offset,
4180 background_area.height);
4183 if (node == drag_highlight)
4185 /* Draw indicator for the drop
4187 gint highlight_y = -1;
4191 switch (tree_view->priv->drag_dest_pos)
4193 case PSPP_SHEET_VIEW_DROP_BEFORE:
4194 highlight_y = background_area.y - 1;
4195 if (highlight_y < 0)
4199 case PSPP_SHEET_VIEW_DROP_AFTER:
4200 highlight_y = background_area.y + background_area.height - 1;
4203 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4204 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4205 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4209 gdk_drawable_get_size (tree_view->priv->bin_window,
4212 if (row_ending_details)
4213 gtk_paint_focus (widget->style,
4214 tree_view->priv->bin_window,
4215 gtk_widget_get_state (widget),
4219 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4220 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4221 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4222 - focus_line_width / 2,
4223 width, ROW_HEIGHT (tree_view)
4224 - focus_line_width + 1);
4226 gtk_paint_focus (widget->style,
4227 tree_view->priv->bin_window,
4228 gtk_widget_get_state (widget),
4231 "treeview-drop-indicator",
4232 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4233 - focus_line_width / 2,
4234 width, ROW_HEIGHT (tree_view)
4235 - focus_line_width + 1);
4239 if (highlight_y >= 0)
4241 gdk_draw_line (event->window,
4242 widget->style->fg_gc[gtk_widget_get_state (widget)],
4245 rtl ? 0 : bin_window_width,
4250 /* draw the big row-spanning focus rectangle, if needed */
4251 if (!has_special_cell && node == cursor &&
4252 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4253 gtk_widget_has_focus (widget))
4255 gint tmp_y, tmp_height;
4257 GtkStateType focus_rect_state;
4260 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4261 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4262 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4265 gdk_drawable_get_size (tree_view->priv->bin_window,
4268 if (draw_hgrid_lines)
4270 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4271 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4275 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4276 tmp_height = ROW_HEIGHT (tree_view);
4279 if (row_ending_details)
4280 gtk_paint_focus (widget->style,
4281 tree_view->priv->bin_window,
4286 ? (is_last ? "treeview" : "treeview-left" )
4287 : (is_last ? "treeview-right" : "treeview-middle" )),
4291 gtk_paint_focus (widget->style,
4292 tree_view->priv->bin_window,
4301 y_offset += max_height;
4305 node = pspp_sheet_view_node_next (tree_view, node);
4308 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4312 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4319 while (y_offset < event->area.height);
4322 pspp_sheet_view_draw_grid_lines (tree_view, event, n_visible_columns,
4325 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4327 GdkRectangle *rectangles;
4330 gdk_region_get_rectangles (event->region,
4334 while (n_rectangles--)
4335 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4337 g_free (rectangles);
4341 gtk_tree_path_free (cursor_path);
4344 gtk_tree_path_free (drag_dest_path);
4350 pspp_sheet_view_expose (GtkWidget *widget,
4351 GdkEventExpose *event)
4353 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4355 if (event->window == tree_view->priv->bin_window)
4360 retval = pspp_sheet_view_bin_expose (widget, event);
4362 /* We can't just chain up to Container::expose as it will try to send the
4363 * event to the headers, so we handle propagating it to our children
4364 * (eg. widgets being edited) ourselves.
4366 tmp_list = tree_view->priv->children;
4369 PsppSheetViewChild *child = tmp_list->data;
4370 tmp_list = tmp_list->next;
4372 gtk_container_propagate_expose (GTK_CONTAINER (tree_view), child->widget, event);
4378 else if (event->window == tree_view->priv->header_window)
4380 gint n_visible_columns;
4383 gtk_paint_flat_box (widget->style,
4393 event->area.height);
4395 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4397 PsppSheetViewColumn *column = list->data;
4399 if (column == tree_view->priv->drag_column || !column->visible)
4402 if (span_intersects (column->allocation.x, column->allocation.width,
4403 event->area.x, event->area.width)
4404 && column->button != NULL)
4405 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4406 column->button, event);
4409 n_visible_columns = 0;
4410 for (list = tree_view->priv->columns; list; list = list->next)
4412 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4414 n_visible_columns ++;
4416 pspp_sheet_view_draw_grid_lines (tree_view,
4420 event->area.height);
4422 else if (event->window == tree_view->priv->drag_window)
4424 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4425 tree_view->priv->drag_column->button,
4439 /* returns 0x1 when no column has been found -- yes it's hackish */
4440 static PsppSheetViewColumn *
4441 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4442 PsppSheetViewColumn *column,
4445 PsppSheetViewColumn *left_column = NULL;
4446 PsppSheetViewColumn *cur_column = NULL;
4449 if (!column->reorderable)
4450 return (PsppSheetViewColumn *)0x1;
4452 switch (drop_position)
4455 /* find first column where we can drop */
4456 tmp_list = tree_view->priv->columns;
4457 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4458 return (PsppSheetViewColumn *)0x1;
4462 g_assert (tmp_list);
4464 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4465 tmp_list = tmp_list->next;
4467 if (left_column && left_column->visible == FALSE)
4470 if (!tree_view->priv->column_drop_func)
4473 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4475 left_column = cur_column;
4482 if (!tree_view->priv->column_drop_func)
4485 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4488 return (PsppSheetViewColumn *)0x1;
4492 /* find first column after column where we can drop */
4493 tmp_list = tree_view->priv->columns;
4495 for (; tmp_list; tmp_list = tmp_list->next)
4496 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4499 if (!tmp_list || !tmp_list->next)
4500 return (PsppSheetViewColumn *)0x1;
4502 tmp_list = tmp_list->next;
4503 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4504 tmp_list = tmp_list->next;
4508 g_assert (tmp_list);
4510 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4511 tmp_list = tmp_list->next;
4513 if (left_column && left_column->visible == FALSE)
4515 left_column = cur_column;
4517 tmp_list = tmp_list->next;
4521 if (!tree_view->priv->column_drop_func)
4524 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4526 left_column = cur_column;
4533 if (!tree_view->priv->column_drop_func)
4536 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4539 return (PsppSheetViewColumn *)0x1;
4543 /* find first column before column where we can drop */
4544 tmp_list = tree_view->priv->columns;
4546 for (; tmp_list; tmp_list = tmp_list->next)
4547 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4550 if (!tmp_list || !tmp_list->prev)
4551 return (PsppSheetViewColumn *)0x1;
4553 tmp_list = tmp_list->prev;
4554 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4555 tmp_list = tmp_list->prev;
4559 g_assert (tmp_list);
4561 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4563 if (left_column && !left_column->visible)
4565 /*if (!tmp_list->prev)
4566 return (PsppSheetViewColumn *)0x1;
4569 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4570 tmp_list = tmp_list->prev->prev;
4573 cur_column = left_column;
4575 tmp_list = tmp_list->prev;
4579 if (!tree_view->priv->column_drop_func)
4582 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4585 cur_column = left_column;
4586 tmp_list = tmp_list->prev;
4589 if (!tree_view->priv->column_drop_func)
4592 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4595 return (PsppSheetViewColumn *)0x1;
4599 /* same as DROP_HOME case, but doing it backwards */
4600 tmp_list = g_list_last (tree_view->priv->columns);
4603 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4604 return (PsppSheetViewColumn *)0x1;
4608 g_assert (tmp_list);
4610 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4612 if (left_column && !left_column->visible)
4614 cur_column = left_column;
4615 tmp_list = tmp_list->prev;
4618 if (!tree_view->priv->column_drop_func)
4621 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4624 cur_column = left_column;
4625 tmp_list = tmp_list->prev;
4628 if (!tree_view->priv->column_drop_func)
4631 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4634 return (PsppSheetViewColumn *)0x1;
4638 return (PsppSheetViewColumn *)0x1;
4642 pspp_sheet_view_key_press (GtkWidget *widget,
4645 PsppSheetView *tree_view = (PsppSheetView *) widget;
4647 if (tree_view->priv->rubber_band_status)
4649 if (event->keyval == GDK_Escape)
4650 pspp_sheet_view_stop_rubber_band (tree_view);
4655 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4657 if (event->keyval == GDK_Escape)
4659 tree_view->priv->cur_reorder = NULL;
4660 pspp_sheet_view_button_release_drag_column (widget, NULL);
4665 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4667 GList *focus_column;
4670 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4672 for (focus_column = tree_view->priv->columns;
4674 focus_column = focus_column->next)
4676 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4678 if (column->button && gtk_widget_has_focus (column->button))
4683 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4684 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4685 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4687 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4689 if (!column->resizable)
4691 gtk_widget_error_bell (widget);
4695 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4696 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4698 gint old_width = column->resized_width;
4700 column->resized_width = MAX (column->resized_width,
4702 column->resized_width -= 2;
4703 if (column->resized_width < 0)
4704 column->resized_width = 0;
4706 if (column->min_width == -1)
4707 column->resized_width = MAX (column->button_request,
4708 column->resized_width);
4710 column->resized_width = MAX (column->min_width,
4711 column->resized_width);
4713 if (column->max_width != -1)
4714 column->resized_width = MIN (column->resized_width,
4717 column->use_resized_width = TRUE;
4719 if (column->resized_width != old_width)
4720 gtk_widget_queue_resize (widget);
4722 gtk_widget_error_bell (widget);
4724 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4725 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4727 gint old_width = column->resized_width;
4729 column->resized_width = MAX (column->resized_width,
4731 column->resized_width += 2;
4733 if (column->max_width != -1)
4734 column->resized_width = MIN (column->resized_width,
4737 column->use_resized_width = TRUE;
4739 if (column->resized_width != old_width)
4740 gtk_widget_queue_resize (widget);
4742 gtk_widget_error_bell (widget);
4749 (event->state & GDK_MOD1_MASK) &&
4750 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4751 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4752 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4753 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4755 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4757 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4758 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4760 PsppSheetViewColumn *col;
4761 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4762 if (col != (PsppSheetViewColumn *)0x1)
4763 pspp_sheet_view_move_column_after (tree_view, column, col);
4765 gtk_widget_error_bell (widget);
4767 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4768 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4770 PsppSheetViewColumn *col;
4771 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4772 if (col != (PsppSheetViewColumn *)0x1)
4773 pspp_sheet_view_move_column_after (tree_view, column, col);
4775 gtk_widget_error_bell (widget);
4777 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4779 PsppSheetViewColumn *col;
4780 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4781 if (col != (PsppSheetViewColumn *)0x1)
4782 pspp_sheet_view_move_column_after (tree_view, column, col);
4784 gtk_widget_error_bell (widget);
4786 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4788 PsppSheetViewColumn *col;
4789 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4790 if (col != (PsppSheetViewColumn *)0x1)
4791 pspp_sheet_view_move_column_after (tree_view, column, col);
4793 gtk_widget_error_bell (widget);
4800 /* Chain up to the parent class. It handles the keybindings. */
4801 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4804 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4806 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4810 /* We pass the event to the search_entry. If its text changes, then we start
4811 * the typeahead find capabilities. */
4812 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4813 && tree_view->priv->enable_search
4814 && !tree_view->priv->search_custom_entry_set)
4816 GdkEvent *new_event;
4818 const char *new_text;
4821 gboolean text_modified;
4822 gulong popup_menu_id;
4824 pspp_sheet_view_ensure_interactive_directory (tree_view);
4826 /* Make a copy of the current text */
4827 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4828 new_event = gdk_event_copy ((GdkEvent *) event);
4829 g_object_unref (((GdkEventKey *) new_event)->window);
4830 ((GdkEventKey *) new_event)->window = g_object_ref (tree_view->priv->search_window->window);
4831 gtk_widget_realize (tree_view->priv->search_window);
4833 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4834 "popup-menu", G_CALLBACK (gtk_true),
4837 /* Move the entry off screen */
4838 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4839 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4840 gdk_screen_get_width (screen) + 1,
4841 gdk_screen_get_height (screen) + 1);
4842 gtk_widget_show (tree_view->priv->search_window);
4844 /* Send the event to the window. If the preedit_changed signal is emitted
4845 * during this event, we will set priv->imcontext_changed */
4846 tree_view->priv->imcontext_changed = FALSE;
4847 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4848 gdk_event_free (new_event);
4849 gtk_widget_hide (tree_view->priv->search_window);
4851 g_signal_handler_disconnect (tree_view->priv->search_entry,
4854 /* We check to make sure that the entry tried to handle the text, and that
4855 * the text has changed.
4857 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4858 text_modified = strcmp (old_text, new_text) != 0;
4860 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4861 (retval && text_modified)) /* ...or the text was modified */
4863 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4865 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4870 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
4880 pspp_sheet_view_key_release (GtkWidget *widget,
4883 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4885 if (tree_view->priv->rubber_band_status)
4888 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
4891 /* FIXME Is this function necessary? Can I get an enter_notify event
4892 * w/o either an expose event or a mouse motion event?
4895 pspp_sheet_view_enter_notify (GtkWidget *widget,
4896 GdkEventCrossing *event)
4898 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4902 /* Sanity check it */
4903 if (event->window != tree_view->priv->bin_window)
4906 if (tree_view->priv->row_count == 0)
4909 if (event->mode == GDK_CROSSING_GRAB ||
4910 event->mode == GDK_CROSSING_GTK_GRAB ||
4911 event->mode == GDK_CROSSING_GTK_UNGRAB ||
4912 event->mode == GDK_CROSSING_STATE_CHANGED)
4915 /* find the node internally */
4916 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
4919 pspp_sheet_view_find_offset (tree_view, new_y, &node);
4921 tree_view->priv->event_last_x = event->x;
4922 tree_view->priv->event_last_y = event->y;
4924 prelight_or_select (tree_view, node, event->x, event->y);
4930 pspp_sheet_view_leave_notify (GtkWidget *widget,
4931 GdkEventCrossing *event)
4933 PsppSheetView *tree_view;
4935 if (event->mode == GDK_CROSSING_GRAB)
4938 tree_view = PSPP_SHEET_VIEW (widget);
4940 if (tree_view->priv->prelight_node >= 0)
4941 _pspp_sheet_view_queue_draw_node (tree_view,
4942 tree_view->priv->prelight_node,
4945 tree_view->priv->event_last_x = -10000;
4946 tree_view->priv->event_last_y = -10000;
4948 prelight_or_select (tree_view,
4950 -1000, -1000); /* coords not possibly over an arrow */
4957 pspp_sheet_view_focus_out (GtkWidget *widget,
4958 GdkEventFocus *event)
4960 PsppSheetView *tree_view;
4962 tree_view = PSPP_SHEET_VIEW (widget);
4964 gtk_widget_queue_draw (widget);
4966 /* destroy interactive search dialog */
4967 if (tree_view->priv->search_window)
4968 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
4974 /* Incremental Reflow
4978 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
4983 y = pspp_sheet_view_node_find_offset (tree_view, node)
4984 - tree_view->priv->vadjustment->value
4985 + TREE_VIEW_HEADER_HEIGHT (tree_view);
4987 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
4989 GTK_WIDGET (tree_view)->allocation.width,
4990 tree_view->priv->fixed_height);
4994 node_is_visible (PsppSheetView *tree_view,
5000 y = pspp_sheet_view_node_find_offset (tree_view, node);
5001 height = ROW_HEIGHT (tree_view);
5003 if (y >= tree_view->priv->vadjustment->value &&
5004 y + height <= (tree_view->priv->vadjustment->value
5005 + tree_view->priv->vadjustment->page_size))
5011 /* Returns the row height. */
5013 validate_row (PsppSheetView *tree_view,
5018 PsppSheetViewColumn *column;
5019 GList *list, *first_column, *last_column;
5021 gint horizontal_separator;
5022 gint vertical_separator;
5023 gint focus_line_width;
5024 gboolean retval = FALSE;
5025 gboolean draw_vgrid_lines, draw_hgrid_lines;
5027 gint grid_line_width;
5028 gboolean wide_separators;
5029 gint separator_height;
5031 gtk_widget_style_get (GTK_WIDGET (tree_view),
5032 "focus-padding", &focus_pad,
5033 "focus-line-width", &focus_line_width,
5034 "horizontal-separator", &horizontal_separator,
5035 "vertical-separator", &vertical_separator,
5036 "grid-line-width", &grid_line_width,
5037 "wide-separators", &wide_separators,
5038 "separator-height", &separator_height,
5042 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5043 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5045 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5046 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5048 for (last_column = g_list_last (tree_view->priv->columns);
5049 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5050 last_column = last_column->prev)
5053 for (first_column = g_list_first (tree_view->priv->columns);
5054 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5055 first_column = first_column->next)
5058 for (list = tree_view->priv->columns; list; list = list->next)
5063 column = list->data;
5065 if (! column->visible)
5068 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5069 pspp_sheet_view_column_cell_get_size (column,
5071 &tmp_width, &tmp_height);
5073 tmp_height += vertical_separator;
5074 height = MAX (height, tmp_height);
5076 tmp_width = tmp_width + horizontal_separator;
5078 if (draw_vgrid_lines)
5080 if (list->data == first_column || list->data == last_column)
5081 tmp_width += grid_line_width / 2.0;
5083 tmp_width += grid_line_width;
5086 if (tmp_width > column->requested_width)
5089 column->requested_width = tmp_width;
5093 if (draw_hgrid_lines)
5094 height += grid_line_width;
5096 tree_view->priv->post_validation_flag = TRUE;
5102 validate_visible_area (PsppSheetView *tree_view)
5104 GtkTreePath *path = NULL;
5105 GtkTreePath *above_path = NULL;
5108 gboolean size_changed = FALSE;
5110 gint area_above = 0;
5111 gint area_below = 0;
5113 if (tree_view->priv->row_count == 0)
5116 if (tree_view->priv->scroll_to_path == NULL)
5119 total_height = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5121 if (total_height == 0)
5124 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5127 /* we are going to scroll, and will update dy */
5128 _pspp_sheet_view_find_node (tree_view, path, &node);
5129 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5131 if (tree_view->priv->scroll_to_use_align)
5133 gint height = ROW_HEIGHT (tree_view);
5134 area_above = (total_height - height) *
5135 tree_view->priv->scroll_to_row_align;
5136 area_below = total_height - area_above - height;
5137 area_above = MAX (area_above, 0);
5138 area_below = MAX (area_below, 0);
5143 * 1) row not visible
5147 gint height = ROW_HEIGHT (tree_view);
5149 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5151 if (dy >= tree_view->priv->vadjustment->value &&
5152 dy + height <= (tree_view->priv->vadjustment->value
5153 + tree_view->priv->vadjustment->page_size))
5155 /* row visible: keep the row at the same position */
5156 area_above = dy - tree_view->priv->vadjustment->value;
5157 area_below = (tree_view->priv->vadjustment->value +
5158 tree_view->priv->vadjustment->page_size)
5163 /* row not visible */
5165 && dy + height <= tree_view->priv->vadjustment->page_size)
5167 /* row at the beginning -- fixed */
5169 area_below = tree_view->priv->vadjustment->page_size
5170 - area_above - height;
5172 else if (dy >= (tree_view->priv->vadjustment->upper -
5173 tree_view->priv->vadjustment->page_size))
5175 /* row at the end -- fixed */
5176 area_above = dy - (tree_view->priv->vadjustment->upper -
5177 tree_view->priv->vadjustment->page_size);
5178 area_below = tree_view->priv->vadjustment->page_size -
5179 area_above - height;
5183 area_above = tree_view->priv->vadjustment->page_size - height;
5189 /* row somewhere in the middle, bring it to the top
5193 area_below = total_height - height;
5199 /* the scroll to isn't valid; ignore it.
5202 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5203 tree_view->priv->scroll_to_path = NULL;
5207 above_path = gtk_tree_path_copy (path);
5209 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5210 * backwards is much slower then forward, as there is no iter_prev function.
5211 * We go forwards first in case we run out of tree. Then we go backwards to
5214 while (node >= 0 && area_below > 0)
5216 gboolean done = FALSE;
5219 node = pspp_sheet_view_node_next (tree_view, node);
5222 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5224 gtk_tree_path_next (path);
5227 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5237 area_below -= ROW_HEIGHT (tree_view);
5239 gtk_tree_path_free (path);
5241 /* If we ran out of tree, and have extra area_below left, we need to add it
5244 area_above += area_below;
5246 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5248 /* We walk backwards */
5249 while (area_above > 0)
5251 node = pspp_sheet_view_node_prev (tree_view, node);
5253 /* Always find the new path in the tree. We cannot just assume
5254 * a gtk_tree_path_prev() is enough here, as there might be children
5255 * in between this node and the previous sibling node. If this
5256 * appears to be a performance hotspot in profiles, we can look into
5257 * intrigate logic for keeping path, node and iter in sync like
5258 * we do for forward walks. (Which will be hard because of the lacking
5265 gtk_tree_path_free (above_path);
5266 above_path = _pspp_sheet_view_find_path (tree_view, node);
5268 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5270 area_above -= ROW_HEIGHT (tree_view);
5273 /* set the dy here to scroll to the path,
5274 * and sync the top row accordingly
5276 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5277 pspp_sheet_view_top_row_to_dy (tree_view);
5279 /* update width/height and queue a resize */
5282 GtkRequisition requisition;
5284 /* We temporarily guess a size, under the assumption that it will be the
5285 * same when we get our next size_allocate. If we don't do this, we'll be
5286 * in an inconsistent state if we call top_row_to_dy. */
5288 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5289 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5290 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5291 gtk_adjustment_changed (tree_view->priv->hadjustment);
5292 gtk_adjustment_changed (tree_view->priv->vadjustment);
5293 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5296 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5297 tree_view->priv->scroll_to_path = NULL;
5300 gtk_tree_path_free (above_path);
5302 if (tree_view->priv->scroll_to_column)
5304 tree_view->priv->scroll_to_column = NULL;
5306 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5310 initialize_fixed_height_mode (PsppSheetView *tree_view)
5312 if (!tree_view->priv->row_count)
5315 if (tree_view->priv->fixed_height_set)
5318 if (tree_view->priv->fixed_height < 0)
5325 path = _pspp_sheet_view_find_path (tree_view, node);
5326 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5328 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5330 gtk_tree_path_free (path);
5332 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5336 /* Our strategy for finding nodes to validate is a little convoluted. We find
5337 * the left-most uninvalidated node. We then try walking right, validating
5338 * nodes. Once we find a valid node, we repeat the previous process of finding
5339 * the first invalid node.
5343 validate_rows_handler (PsppSheetView *tree_view)
5345 initialize_fixed_height_mode (tree_view);
5346 if (tree_view->priv->validate_rows_timer)
5348 g_source_remove (tree_view->priv->validate_rows_timer);
5349 tree_view->priv->validate_rows_timer = 0;
5356 do_presize_handler (PsppSheetView *tree_view)
5358 GtkRequisition requisition;
5360 validate_visible_area (tree_view);
5361 tree_view->priv->presize_handler_timer = 0;
5363 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5366 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5368 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5369 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5370 gtk_adjustment_changed (tree_view->priv->hadjustment);
5371 gtk_adjustment_changed (tree_view->priv->vadjustment);
5372 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5378 presize_handler_callback (gpointer data)
5380 do_presize_handler (PSPP_SHEET_VIEW (data));
5386 install_presize_handler (PsppSheetView *tree_view)
5388 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5391 if (! tree_view->priv->presize_handler_timer)
5393 tree_view->priv->presize_handler_timer =
5394 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5396 if (! tree_view->priv->validate_rows_timer)
5398 tree_view->priv->validate_rows_timer =
5399 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5404 scroll_sync_handler (PsppSheetView *tree_view)
5406 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
5407 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5408 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5409 pspp_sheet_view_top_row_to_dy (tree_view);
5411 pspp_sheet_view_dy_to_top_row (tree_view);
5413 tree_view->priv->scroll_sync_timer = 0;
5419 install_scroll_sync_handler (PsppSheetView *tree_view)
5421 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5424 if (!tree_view->priv->scroll_sync_timer)
5426 tree_view->priv->scroll_sync_timer =
5427 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5432 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5436 gtk_tree_row_reference_free (tree_view->priv->top_row);
5440 tree_view->priv->top_row = NULL;
5441 tree_view->priv->top_row_dy = 0;
5445 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5446 tree_view->priv->top_row_dy = offset;
5450 /* Always call this iff dy is in the visible range. If the tree is empty, then
5451 * it's set to be NULL, and top_row_dy is 0;
5454 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5460 if (tree_view->priv->row_count == 0)
5462 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5466 offset = pspp_sheet_view_find_offset (tree_view,
5467 tree_view->priv->dy,
5472 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5476 path = _pspp_sheet_view_find_path (tree_view, node);
5477 pspp_sheet_view_set_top_row (tree_view, path, offset);
5478 gtk_tree_path_free (path);
5484 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5490 /* Avoid recursive calls */
5491 if (tree_view->priv->in_top_row_to_dy)
5494 if (tree_view->priv->top_row)
5495 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5502 _pspp_sheet_view_find_node (tree_view, path, &node);
5505 gtk_tree_path_free (path);
5509 /* keep dy and set new toprow */
5510 gtk_tree_row_reference_free (tree_view->priv->top_row);
5511 tree_view->priv->top_row = NULL;
5512 tree_view->priv->top_row_dy = 0;
5513 /* DO NOT install the idle handler */
5514 pspp_sheet_view_dy_to_top_row (tree_view);
5518 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5520 /* new top row -- do NOT install the idle handler */
5521 pspp_sheet_view_dy_to_top_row (tree_view);
5525 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5526 new_dy += tree_view->priv->top_row_dy;
5528 if (new_dy + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
5529 new_dy = tree_view->priv->height - tree_view->priv->vadjustment->page_size;
5531 new_dy = MAX (0, new_dy);
5533 tree_view->priv->in_top_row_to_dy = TRUE;
5534 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5535 tree_view->priv->in_top_row_to_dy = FALSE;
5540 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5542 install_presize_handler (tree_view);
5548 set_source_row (GdkDragContext *context,
5549 GtkTreeModel *model,
5550 GtkTreePath *source_row)
5552 g_object_set_data_full (G_OBJECT (context),
5553 "gtk-tree-view-source-row",
5554 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5555 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5559 get_source_row (GdkDragContext *context)
5561 GtkTreeRowReference *ref =
5562 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5565 return gtk_tree_row_reference_get_path (ref);
5572 GtkTreeRowReference *dest_row;
5573 guint path_down_mode : 1;
5574 guint empty_view_drop : 1;
5575 guint drop_append_mode : 1;
5580 dest_row_free (gpointer data)
5582 DestRow *dr = (DestRow *)data;
5584 gtk_tree_row_reference_free (dr->dest_row);
5585 g_slice_free (DestRow, dr);
5589 set_dest_row (GdkDragContext *context,
5590 GtkTreeModel *model,
5591 GtkTreePath *dest_row,
5592 gboolean path_down_mode,
5593 gboolean empty_view_drop,
5594 gboolean drop_append_mode)
5600 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5605 dr = g_slice_new (DestRow);
5607 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5608 dr->path_down_mode = path_down_mode != FALSE;
5609 dr->empty_view_drop = empty_view_drop != FALSE;
5610 dr->drop_append_mode = drop_append_mode != FALSE;
5612 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5613 dr, (GDestroyNotify) dest_row_free);
5617 get_dest_row (GdkDragContext *context,
5618 gboolean *path_down_mode)
5621 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5625 GtkTreePath *path = NULL;
5628 *path_down_mode = dr->path_down_mode;
5631 path = gtk_tree_row_reference_get_path (dr->dest_row);
5632 else if (dr->empty_view_drop)
5633 path = gtk_tree_path_new_from_indices (0, -1);
5637 if (path && dr->drop_append_mode)
5638 gtk_tree_path_next (path);
5646 /* Get/set whether drag_motion requested the drag data and
5647 * drag_data_received should thus not actually insert the data,
5648 * since the data doesn't result from a drop.
5651 set_status_pending (GdkDragContext *context,
5652 GdkDragAction suggested_action)
5654 g_object_set_data (G_OBJECT (context),
5655 "gtk-tree-view-status-pending",
5656 GINT_TO_POINTER (suggested_action));
5659 static GdkDragAction
5660 get_status_pending (GdkDragContext *context)
5662 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5663 "gtk-tree-view-status-pending"));
5666 static TreeViewDragInfo*
5667 get_info (PsppSheetView *tree_view)
5669 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5673 destroy_info (TreeViewDragInfo *di)
5675 g_slice_free (TreeViewDragInfo, di);
5678 static TreeViewDragInfo*
5679 ensure_info (PsppSheetView *tree_view)
5681 TreeViewDragInfo *di;
5683 di = get_info (tree_view);
5687 di = g_slice_new0 (TreeViewDragInfo);
5689 g_object_set_data_full (G_OBJECT (tree_view),
5690 "gtk-tree-view-drag-info",
5692 (GDestroyNotify) destroy_info);
5699 remove_info (PsppSheetView *tree_view)
5701 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5706 drag_scan_timeout (gpointer data)
5708 PsppSheetView *tree_view;
5710 GdkModifierType state;
5711 GtkTreePath *path = NULL;
5712 PsppSheetViewColumn *column = NULL;
5713 GdkRectangle visible_rect;
5715 GDK_THREADS_ENTER ();
5717 tree_view = PSPP_SHEET_VIEW (data);
5719 gdk_window_get_pointer (tree_view->priv->bin_window,
5722 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5724 /* See if we are near the edge. */
5725 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5726 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5727 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5728 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5730 pspp_sheet_view_get_path_at_pos (tree_view,
5731 tree_view->priv->bin_window,
5740 pspp_sheet_view_scroll_to_cell (tree_view,
5746 gtk_tree_path_free (path);
5750 GDK_THREADS_LEAVE ();
5757 add_scroll_timeout (PsppSheetView *tree_view)
5759 if (tree_view->priv->scroll_timeout == 0)
5761 tree_view->priv->scroll_timeout =
5762 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5767 remove_scroll_timeout (PsppSheetView *tree_view)
5769 if (tree_view->priv->scroll_timeout != 0)
5771 g_source_remove (tree_view->priv->scroll_timeout);
5772 tree_view->priv->scroll_timeout = 0;
5777 check_model_dnd (GtkTreeModel *model,
5778 GType required_iface,
5779 const gchar *signal)
5781 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5783 g_warning ("You must override the default '%s' handler "
5784 "on PsppSheetView when using models that don't support "
5785 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5786 "is to connect to '%s' and call "
5787 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5788 "the default handler from running. Look at the source code "
5789 "for the default handler in gtktreeview.c to get an idea what "
5790 "your handler should do. (gtktreeview.c is in the GTK source "
5791 "code.) If you're using GTK from a language other than C, "
5792 "there may be a more natural way to override default handlers, e.g. via derivation.",
5793 signal, g_type_name (required_iface), signal);
5801 scroll_row_timeout (gpointer data)
5803 PsppSheetView *tree_view = data;
5805 pspp_sheet_view_horizontal_autoscroll (tree_view);
5806 pspp_sheet_view_vertical_autoscroll (tree_view);
5808 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5809 pspp_sheet_view_update_rubber_band (tree_view);
5814 /* Returns TRUE if event should not be propagated to parent widgets */
5816 set_destination_row (PsppSheetView *tree_view,
5817 GdkDragContext *context,
5818 /* coordinates relative to the widget */
5821 GdkDragAction *suggested_action,
5824 GtkTreePath *path = NULL;
5825 PsppSheetViewDropPosition pos;
5826 PsppSheetViewDropPosition old_pos;
5827 TreeViewDragInfo *di;
5829 GtkTreePath *old_dest_path = NULL;
5830 gboolean can_drop = FALSE;
5832 *suggested_action = 0;
5835 widget = GTK_WIDGET (tree_view);
5837 di = get_info (tree_view);
5839 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5841 /* someone unset us as a drag dest, note that if
5842 * we return FALSE drag_leave isn't called
5845 pspp_sheet_view_set_drag_dest_row (tree_view,
5847 PSPP_SHEET_VIEW_DROP_BEFORE);
5849 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5851 return FALSE; /* no longer a drop site */
5854 *target = gtk_drag_dest_find_target (widget, context,
5855 gtk_drag_dest_get_target_list (widget));
5856 if (*target == GDK_NONE)
5861 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5867 GtkTreeModel *model;
5869 /* the row got dropped on empty space, let's setup a special case
5873 gtk_tree_path_free (path);
5875 model = pspp_sheet_view_get_model (tree_view);
5877 n_children = gtk_tree_model_iter_n_children (model, NULL);
5880 pos = PSPP_SHEET_VIEW_DROP_AFTER;
5881 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5885 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
5886 path = gtk_tree_path_new_from_indices (0, -1);
5896 /* If we left the current row's "open" zone, unset the timeout for
5899 pspp_sheet_view_get_drag_dest_row (tree_view,
5904 gtk_tree_path_free (old_dest_path);
5906 if (TRUE /* FIXME if the location droppable predicate */)
5914 GtkWidget *source_widget;
5916 *suggested_action = context->suggested_action;
5917 source_widget = gtk_drag_get_source_widget (context);
5919 if (source_widget == widget)
5921 /* Default to MOVE, unless the user has
5922 * pressed ctrl or shift to affect available actions
5924 if ((context->actions & GDK_ACTION_MOVE) != 0)
5925 *suggested_action = GDK_ACTION_MOVE;
5928 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5933 /* can't drop here */
5934 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5936 PSPP_SHEET_VIEW_DROP_BEFORE);
5940 gtk_tree_path_free (path);
5946 get_logical_dest_row (PsppSheetView *tree_view,
5947 gboolean *path_down_mode,
5948 gboolean *drop_append_mode)
5950 /* adjust path to point to the row the drop goes in front of */
5951 GtkTreePath *path = NULL;
5952 PsppSheetViewDropPosition pos;
5954 g_return_val_if_fail (path_down_mode != NULL, NULL);
5955 g_return_val_if_fail (drop_append_mode != NULL, NULL);
5957 *path_down_mode = FALSE;
5958 *drop_append_mode = 0;
5960 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
5965 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
5967 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
5968 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
5969 *path_down_mode = TRUE;
5973 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
5975 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
5977 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5978 !gtk_tree_model_iter_next (model, &iter))
5979 *drop_append_mode = 1;
5982 *drop_append_mode = 0;
5983 gtk_tree_path_next (path);
5991 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
5992 GdkEventMotion *event)
5994 GtkWidget *widget = GTK_WIDGET (tree_view);
5995 GdkDragContext *context;
5996 TreeViewDragInfo *di;
5997 GtkTreePath *path = NULL;
5999 gint cell_x, cell_y;
6000 GtkTreeModel *model;
6001 gboolean retval = FALSE;
6003 di = get_info (tree_view);
6005 if (di == NULL || !di->source_set)
6008 if (tree_view->priv->pressed_button < 0)
6011 if (!gtk_drag_check_threshold (widget,
6012 tree_view->priv->press_start_x,
6013 tree_view->priv->press_start_y,
6014 event->x, event->y))
6017 model = pspp_sheet_view_get_model (tree_view);
6022 button = tree_view->priv->pressed_button;
6023 tree_view->priv->pressed_button = -1;
6025 pspp_sheet_view_get_path_at_pos (tree_view,
6026 tree_view->priv->press_start_x,
6027 tree_view->priv->press_start_y,
6036 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6037 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6041 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6044 /* Now we can begin the drag */
6048 context = gtk_drag_begin (widget,
6049 gtk_drag_source_get_target_list (widget),
6054 set_source_row (context, model, path);
6058 gtk_tree_path_free (path);
6065 pspp_sheet_view_drag_begin (GtkWidget *widget,
6066 GdkDragContext *context)
6068 PsppSheetView *tree_view;
6069 GtkTreePath *path = NULL;
6070 gint cell_x, cell_y;
6072 TreeViewDragInfo *di;
6074 tree_view = PSPP_SHEET_VIEW (widget);
6076 /* if the user uses a custom DND source impl, we don't set the icon here */
6077 di = get_info (tree_view);
6079 if (di == NULL || !di->source_set)
6082 pspp_sheet_view_get_path_at_pos (tree_view,
6083 tree_view->priv->press_start_x,
6084 tree_view->priv->press_start_y,
6090 g_return_if_fail (path != NULL);
6092 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6095 gtk_drag_set_icon_pixmap (context,
6096 gdk_drawable_get_colormap (row_pix),
6099 /* the + 1 is for the black border in the icon */
6100 tree_view->priv->press_start_x + 1,
6103 g_object_unref (row_pix);
6104 gtk_tree_path_free (path);
6108 pspp_sheet_view_drag_end (GtkWidget *widget,
6109 GdkDragContext *context)
6114 /* Default signal implementations for the drag signals */
6116 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6117 GdkDragContext *context,
6118 GtkSelectionData *selection_data,
6122 PsppSheetView *tree_view;
6123 GtkTreeModel *model;
6124 TreeViewDragInfo *di;
6125 GtkTreePath *source_row;
6127 tree_view = PSPP_SHEET_VIEW (widget);
6129 model = pspp_sheet_view_get_model (tree_view);
6134 di = get_info (PSPP_SHEET_VIEW (widget));
6139 source_row = get_source_row (context);
6141 if (source_row == NULL)
6144 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6145 * any model; for DragSource models there are some other targets
6149 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6150 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6155 /* If drag_data_get does nothing, try providing row data. */
6156 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6158 gtk_tree_set_row_drag_data (selection_data,
6164 gtk_tree_path_free (source_row);
6169 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6170 GdkDragContext *context)
6172 TreeViewDragInfo *di;
6173 GtkTreeModel *model;
6174 PsppSheetView *tree_view;
6175 GtkTreePath *source_row;
6177 tree_view = PSPP_SHEET_VIEW (widget);
6178 model = pspp_sheet_view_get_model (tree_view);
6180 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6183 di = get_info (tree_view);
6188 source_row = get_source_row (context);
6190 if (source_row == NULL)
6193 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6196 gtk_tree_path_free (source_row);
6198 set_source_row (context, NULL, NULL);
6202 pspp_sheet_view_drag_leave (GtkWidget *widget,
6203 GdkDragContext *context,
6206 /* unset any highlight row */
6207 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6209 PSPP_SHEET_VIEW_DROP_BEFORE);
6211 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6216 pspp_sheet_view_drag_motion (GtkWidget *widget,
6217 GdkDragContext *context,
6218 /* coordinates relative to the widget */
6224 GtkTreePath *path = NULL;
6225 PsppSheetViewDropPosition pos;
6226 PsppSheetView *tree_view;
6227 GdkDragAction suggested_action = 0;
6230 tree_view = PSPP_SHEET_VIEW (widget);
6232 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6235 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6237 /* we only know this *after* set_desination_row */
6238 empty = tree_view->priv->empty_view_drop;
6240 if (path == NULL && !empty)
6242 /* Can't drop here. */
6243 gdk_drag_status (context, 0, time);
6247 if (tree_view->priv->open_dest_timeout == 0 &&
6248 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6249 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6255 add_scroll_timeout (tree_view);
6258 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6260 /* Request data so we can use the source row when
6261 * determining whether to accept the drop
6263 set_status_pending (context, suggested_action);
6264 gtk_drag_get_data (widget, context, target, time);
6268 set_status_pending (context, 0);
6269 gdk_drag_status (context, suggested_action, time);
6274 gtk_tree_path_free (path);
6281 pspp_sheet_view_drag_drop (GtkWidget *widget,
6282 GdkDragContext *context,
6283 /* coordinates relative to the widget */
6288 PsppSheetView *tree_view;
6290 GdkDragAction suggested_action = 0;
6291 GdkAtom target = GDK_NONE;
6292 TreeViewDragInfo *di;
6293 GtkTreeModel *model;
6294 gboolean path_down_mode;
6295 gboolean drop_append_mode;
6297 tree_view = PSPP_SHEET_VIEW (widget);
6299 model = pspp_sheet_view_get_model (tree_view);
6301 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6303 di = get_info (tree_view);
6308 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6311 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6314 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6316 if (target != GDK_NONE && path != NULL)
6318 /* in case a motion had requested drag data, change things so we
6319 * treat drag data receives as a drop.
6321 set_status_pending (context, 0);
6322 set_dest_row (context, model, path,
6323 path_down_mode, tree_view->priv->empty_view_drop,
6328 gtk_tree_path_free (path);
6330 /* Unset this thing */
6331 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6333 PSPP_SHEET_VIEW_DROP_BEFORE);
6335 if (target != GDK_NONE)
6337 gtk_drag_get_data (widget, context, target, time);
6345 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6346 GdkDragContext *context,
6347 /* coordinates relative to the widget */
6350 GtkSelectionData *selection_data,
6355 TreeViewDragInfo *di;
6356 gboolean accepted = FALSE;
6357 GtkTreeModel *model;
6358 PsppSheetView *tree_view;
6359 GtkTreePath *dest_row;
6360 GdkDragAction suggested_action;
6361 gboolean path_down_mode;
6362 gboolean drop_append_mode;
6364 tree_view = PSPP_SHEET_VIEW (widget);
6366 model = pspp_sheet_view_get_model (tree_view);
6368 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6371 di = get_info (tree_view);
6376 suggested_action = get_status_pending (context);
6378 if (suggested_action)
6380 /* We are getting this data due to a request in drag_motion,
6381 * rather than due to a request in drag_drop, so we are just
6382 * supposed to call drag_status, not actually paste in the
6385 path = get_logical_dest_row (tree_view, &path_down_mode,
6389 suggested_action = 0;
6390 else if (path_down_mode)
6391 gtk_tree_path_down (path);
6393 if (suggested_action)
6395 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6401 path_down_mode = FALSE;
6402 gtk_tree_path_up (path);
6404 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6407 suggested_action = 0;
6410 suggested_action = 0;
6414 gdk_drag_status (context, suggested_action, time);
6417 gtk_tree_path_free (path);
6419 /* If you can't drop, remove user drop indicator until the next motion */
6420 if (suggested_action == 0)
6421 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6423 PSPP_SHEET_VIEW_DROP_BEFORE);
6428 dest_row = get_dest_row (context, &path_down_mode);
6430 if (dest_row == NULL)
6433 if (selection_data->length >= 0)
6437 gtk_tree_path_down (dest_row);
6438 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6439 dest_row, selection_data))
6440 gtk_tree_path_up (dest_row);
6444 if (selection_data->length >= 0)
6446 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6452 gtk_drag_finish (context,
6454 (context->action == GDK_ACTION_MOVE),
6457 if (gtk_tree_path_get_depth (dest_row) == 1
6458 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6460 /* special special case drag to "0", scroll to first item */
6461 if (!tree_view->priv->scroll_to_path)
6462 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6465 gtk_tree_path_free (dest_row);
6468 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6473 /* GtkContainer Methods
6478 pspp_sheet_view_remove (GtkContainer *container,
6481 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6482 PsppSheetViewChild *child = NULL;
6485 tmp_list = tree_view->priv->children;
6488 child = tmp_list->data;
6489 if (child->widget == widget)
6491 gtk_widget_unparent (widget);
6493 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6494 g_list_free_1 (tmp_list);
6495 g_slice_free (PsppSheetViewChild, child);
6499 tmp_list = tmp_list->next;
6502 tmp_list = tree_view->priv->columns;
6506 PsppSheetViewColumn *column;
6507 column = tmp_list->data;
6508 if (column->button == widget)
6510 gtk_widget_unparent (widget);
6513 tmp_list = tmp_list->next;
6518 pspp_sheet_view_forall (GtkContainer *container,
6519 gboolean include_internals,
6520 GtkCallback callback,
6521 gpointer callback_data)
6523 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6524 PsppSheetViewChild *child = NULL;
6525 PsppSheetViewColumn *column;
6528 tmp_list = tree_view->priv->children;
6531 child = tmp_list->data;
6532 tmp_list = tmp_list->next;
6534 (* callback) (child->widget, callback_data);
6536 if (include_internals == FALSE)
6539 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6541 column = tmp_list->data;
6544 (* callback) (column->button, callback_data);
6548 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6549 * cells. If so we draw one big row-spanning focus rectangle.
6552 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6556 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6557 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6559 for (list = tree_view->priv->columns; list; list = list->next)
6561 if (!((PsppSheetViewColumn *)list->data)->visible)
6563 if (_pspp_sheet_view_column_count_special_cells (list->data))
6571 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6572 PsppSheetViewColumn *focus_column,
6573 gboolean clamp_column_visible)
6575 g_return_if_fail (focus_column != NULL);
6577 tree_view->priv->focus_column = focus_column;
6578 if (!focus_column->button)
6580 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6581 g_return_if_fail (focus_column->button != NULL);
6584 if (GTK_CONTAINER (tree_view)->focus_child != focus_column->button)
6585 gtk_widget_grab_focus (focus_column->button);
6587 if (clamp_column_visible)
6588 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6591 /* Returns TRUE if the focus is within the headers, after the focus operation is
6595 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6596 GtkDirectionType dir,
6597 gboolean clamp_column_visible)
6599 GtkWidget *focus_child;
6600 PsppSheetViewColumn *focus_column;
6601 GList *last_column, *first_column;
6605 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6608 focus_child = GTK_CONTAINER (tree_view)->focus_child;
6610 first_column = tree_view->priv->columns;
6611 while (first_column)
6613 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6615 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6617 first_column = first_column->next;
6620 /* No headers are visible, or are focusable. We can't focus in or out.
6622 if (first_column == NULL)
6625 last_column = g_list_last (tree_view->priv->columns);
6628 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6630 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6632 last_column = last_column->prev;
6636 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6640 case GTK_DIR_TAB_BACKWARD:
6641 case GTK_DIR_TAB_FORWARD:
6644 if (focus_child == NULL)
6646 if (tree_view->priv->focus_column != NULL &&
6647 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6648 focus_column = tree_view->priv->focus_column;
6650 focus_column = first_column->data;
6651 pspp_sheet_view_focus_column (tree_view, focus_column,
6652 clamp_column_visible);
6659 if (focus_child == NULL)
6661 if (tree_view->priv->focus_column != NULL)
6662 focus_column = tree_view->priv->focus_column;
6663 else if (dir == GTK_DIR_LEFT)
6664 focus_column = last_column->data;
6666 focus_column = first_column->data;
6667 pspp_sheet_view_focus_column (tree_view, focus_column,
6668 clamp_column_visible);
6672 if (gtk_widget_child_focus (focus_child, dir))
6674 /* The focus moves inside the button. */
6675 /* This is probably a great example of bad UI */
6676 if (clamp_column_visible)
6677 pspp_sheet_view_clamp_column_visible (tree_view,
6678 tree_view->priv->focus_column,
6683 /* We need to move the focus among the row of buttons. */
6684 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6685 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6688 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6689 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6691 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6697 PsppSheetViewColumn *column;
6699 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6700 tmp_list = tmp_list->next;
6702 tmp_list = tmp_list->prev;
6704 if (tmp_list == NULL)
6706 g_warning ("Internal button not found");
6709 column = tmp_list->data;
6710 if (column->button &&
6712 pspp_sheet_view_column_can_focus (column))
6714 pspp_sheet_view_focus_column (tree_view, column,
6715 clamp_column_visible);
6722 g_assert_not_reached ();
6729 /* This function returns in 'path' the first focusable path, if the given path
6730 * is already focusable, it's the returned one.
6734 search_first_focusable_path (PsppSheetView *tree_view,
6736 gboolean search_forward,
6739 /* XXX this function is trivial given that the sheetview doesn't support
6743 if (!path || !*path)
6746 _pspp_sheet_view_find_node (tree_view, *path, &node);
6754 return (*path != NULL);
6758 pspp_sheet_view_focus (GtkWidget *widget,
6759 GtkDirectionType direction)
6761 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6762 GtkContainer *container = GTK_CONTAINER (widget);
6763 GtkWidget *focus_child;
6765 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6768 focus_child = container->focus_child;
6770 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6771 /* Case 1. Headers currently have focus. */
6778 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6780 case GTK_DIR_TAB_BACKWARD:
6783 case GTK_DIR_TAB_FORWARD:
6785 gtk_widget_grab_focus (widget);
6788 g_assert_not_reached ();
6793 /* Case 2. We don't have focus at all. */
6794 if (!gtk_widget_has_focus (widget))
6796 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6797 gtk_widget_grab_focus (widget);
6801 /* Case 3. We have focus already. */
6802 if (direction == GTK_DIR_TAB_BACKWARD)
6803 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6804 else if (direction == GTK_DIR_TAB_FORWARD)
6807 /* Other directions caught by the keybindings */
6808 gtk_widget_grab_focus (widget);
6813 pspp_sheet_view_grab_focus (GtkWidget *widget)
6815 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6817 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6821 pspp_sheet_view_style_set (GtkWidget *widget,
6822 GtkStyle *previous_style)
6824 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6826 PsppSheetViewColumn *column;
6828 if (gtk_widget_get_realized (widget))
6831 PsppSheetViewPrivate *priv = PSPP_SHEET_VIEW (widget)->priv;
6833 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
6834 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
6835 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
6836 for (i = 0; i < 5 ; ++i)
6838 g_object_unref (priv->grid_line_gc[i]);
6839 priv->grid_line_gc[i] = gdk_gc_new (widget->window);
6840 gdk_gc_copy (priv->grid_line_gc[i], widget->style->text_aa_gc[i]);
6843 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6846 gtk_widget_style_get (widget,
6847 "expander-size", &tree_view->priv->expander_size,
6849 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6851 for (list = tree_view->priv->columns; list; list = list->next)
6853 column = list->data;
6854 _pspp_sheet_view_column_cell_set_dirty (column);
6857 tree_view->priv->fixed_height = -1;
6859 /* Invalidate cached button style. */
6860 if (tree_view->priv->button_style)
6862 g_object_unref (tree_view->priv->button_style);
6863 tree_view->priv->button_style = NULL;
6866 gtk_widget_queue_resize (widget);
6871 pspp_sheet_view_set_focus_child (GtkContainer *container,
6874 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6877 for (list = tree_view->priv->columns; list; list = list->next)
6879 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6881 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6886 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6890 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6891 GtkAdjustment *hadj,
6892 GtkAdjustment *vadj)
6894 gboolean need_adjust = FALSE;
6896 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6899 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6901 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6903 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
6905 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6907 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
6909 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
6910 pspp_sheet_view_adjustment_changed,
6912 g_object_unref (tree_view->priv->hadjustment);
6915 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
6917 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
6918 pspp_sheet_view_adjustment_changed,
6920 g_object_unref (tree_view->priv->vadjustment);
6923 if (tree_view->priv->hadjustment != hadj)
6925 tree_view->priv->hadjustment = hadj;
6926 g_object_ref_sink (tree_view->priv->hadjustment);
6928 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
6929 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6934 if (tree_view->priv->vadjustment != vadj)
6936 tree_view->priv->vadjustment = vadj;
6937 g_object_ref_sink (tree_view->priv->vadjustment);
6939 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
6940 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6946 pspp_sheet_view_adjustment_changed (NULL, tree_view);
6951 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
6952 GtkMovementStep step,
6955 GdkModifierType state;
6957 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
6958 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
6959 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
6960 step == GTK_MOVEMENT_DISPLAY_LINES ||
6961 step == GTK_MOVEMENT_PAGES ||
6962 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
6964 if (tree_view->priv->row_count == 0)
6966 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
6969 pspp_sheet_view_stop_editing (tree_view, FALSE);
6970 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
6971 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
6973 if (gtk_get_current_event_state (&state))
6975 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
6976 tree_view->priv->ctrl_pressed = TRUE;
6977 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
6978 tree_view->priv->shift_pressed = TRUE;
6980 /* else we assume not pressed */
6984 /* currently we make no distinction. When we go bi-di, we need to */
6985 case GTK_MOVEMENT_LOGICAL_POSITIONS:
6986 case GTK_MOVEMENT_VISUAL_POSITIONS:
6987 pspp_sheet_view_move_cursor_left_right (tree_view, count);
6989 case GTK_MOVEMENT_DISPLAY_LINES:
6990 pspp_sheet_view_move_cursor_up_down (tree_view, count);
6992 case GTK_MOVEMENT_PAGES:
6993 pspp_sheet_view_move_cursor_page_up_down (tree_view, count);
6995 case GTK_MOVEMENT_BUFFER_ENDS:
6996 pspp_sheet_view_move_cursor_start_end (tree_view, count);
6999 g_assert_not_reached ();
7002 tree_view->priv->ctrl_pressed = FALSE;
7003 tree_view->priv->shift_pressed = FALSE;
7009 pspp_sheet_view_put (PsppSheetView *tree_view,
7010 GtkWidget *child_widget,
7011 /* in bin_window coordinates */
7017 PsppSheetViewChild *child;
7019 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7020 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7022 child = g_slice_new (PsppSheetViewChild);
7024 child->widget = child_widget;
7027 child->width = width;
7028 child->height = height;
7030 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7032 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7033 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7035 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7039 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7041 /* in tree coordinates */
7047 PsppSheetViewChild *child = NULL;
7049 GdkRectangle allocation;
7051 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7052 g_return_if_fail (GTK_IS_WIDGET (widget));
7054 for (list = tree_view->priv->children; list; list = list->next)
7056 if (((PsppSheetViewChild *)list->data)->widget == widget)
7065 allocation.x = child->x = x;
7066 allocation.y = child->y = y;
7067 allocation.width = child->width = width;
7068 allocation.height = child->height = height;
7070 if (gtk_widget_get_realized (widget))
7071 gtk_widget_size_allocate (widget, &allocation);
7075 /* TreeModel Callbacks
7079 pspp_sheet_view_row_changed (GtkTreeModel *model,
7084 PsppSheetView *tree_view = (PsppSheetView *)data;
7086 gboolean free_path = FALSE;
7087 GtkTreePath *cursor_path;
7089 g_return_if_fail (path != NULL || iter != NULL);
7091 if (tree_view->priv->cursor != NULL)
7092 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7096 if (tree_view->priv->edited_column &&
7097 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7098 pspp_sheet_view_stop_editing (tree_view, TRUE);
7100 if (cursor_path != NULL)
7101 gtk_tree_path_free (cursor_path);
7105 path = gtk_tree_model_get_path (model, iter);
7108 else if (iter == NULL)
7109 gtk_tree_model_get_iter (model, iter, path);
7111 _pspp_sheet_view_find_node (tree_view,
7117 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7118 pspp_sheet_view_node_queue_redraw (tree_view, node);
7122 gtk_tree_path_free (path);
7126 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7131 PsppSheetView *tree_view = (PsppSheetView *) data;
7134 gint height = tree_view->priv->fixed_height;
7135 gboolean free_path = FALSE;
7136 gboolean node_visible = TRUE;
7138 g_return_if_fail (path != NULL || iter != NULL);
7142 path = gtk_tree_model_get_path (model, iter);
7145 else if (iter == NULL)
7146 gtk_tree_model_get_iter (model, iter, path);
7148 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7150 /* Update all row-references */
7151 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7152 indices = gtk_tree_path_get_indices (path);
7153 tmpnode = indices[0];
7155 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7159 if (node_visible && node_is_visible (tree_view, tmpnode))
7160 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7162 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7165 install_presize_handler (tree_view);
7167 gtk_tree_path_free (path);
7171 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7175 PsppSheetView *tree_view = (PsppSheetView *)data;
7178 g_return_if_fail (path != NULL);
7180 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7182 _pspp_sheet_view_find_node (tree_view, path, &node);
7187 range_tower_delete (tree_view->priv->selected, node, 1);
7189 /* Ensure we don't have a dangling pointer to a dead node */
7190 ensure_unprelighted (tree_view);
7192 /* Cancel editting if we've started */
7193 pspp_sheet_view_stop_editing (tree_view, TRUE);
7195 if (tree_view->priv->destroy_count_func)
7197 gint child_count = 0;
7198 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7201 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7203 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7205 gtk_tree_row_reference_free (tree_view->priv->top_row);
7206 tree_view->priv->top_row = NULL;
7209 install_scroll_sync_handler (tree_view);
7211 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7214 if (helper_data.changed)
7215 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7220 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7221 GtkTreePath *parent,
7226 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7229 /* XXX need to adjust selection */
7230 len = gtk_tree_model_iter_n_children (model, iter);
7235 gtk_tree_row_reference_reordered (G_OBJECT (data),
7240 if (gtk_tree_path_get_depth (parent) != 0)
7243 if (tree_view->priv->edited_column)
7244 pspp_sheet_view_stop_editing (tree_view, TRUE);
7246 /* we need to be unprelighted */
7247 ensure_unprelighted (tree_view);
7249 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7251 pspp_sheet_view_dy_to_top_row (tree_view);
7255 /* Internal tree functions
7260 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7261 PsppSheetViewColumn *column,
7265 PsppSheetViewColumn *tmp_column = NULL;
7276 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7279 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7281 list = (rtl ? list->prev : list->next))
7283 tmp_column = list->data;
7285 if (tmp_column == column)
7288 if (tmp_column->visible)
7289 total_width += tmp_column->width;
7292 if (tmp_column != column)
7294 g_warning (G_STRLOC": passed-in column isn't in the tree");
7303 if (column->visible)
7304 *x2 = total_width + column->width;
7306 *x2 = total_width; /* width of 0 */
7310 /* Make sure the node is visible vertically */
7312 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7315 gint node_dy, height;
7316 GtkTreePath *path = NULL;
7318 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7321 /* just return if the node is visible, avoiding a costly expose */
7322 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7323 height = ROW_HEIGHT (tree_view);
7324 if (node_dy >= tree_view->priv->vadjustment->value
7325 && node_dy + height <= (tree_view->priv->vadjustment->value
7326 + tree_view->priv->vadjustment->page_size))
7329 path = _pspp_sheet_view_find_path (tree_view, node);
7332 /* We process updates because we want to clear old selected items when we scroll.
7333 * if this is removed, we get a "selection streak" at the bottom. */
7334 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7335 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7336 gtk_tree_path_free (path);
7341 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7342 PsppSheetViewColumn *column,
7343 gboolean focus_to_cell)
7350 x = column->allocation.x;
7351 width = column->allocation.width;
7353 if (width > tree_view->priv->hadjustment->page_size)
7355 /* The column is larger than the horizontal page size. If the
7356 * column has cells which can be focussed individually, then we make
7357 * sure the cell which gets focus is fully visible (if even the
7358 * focus cell is bigger than the page size, we make sure the
7359 * left-hand side of the cell is visible).
7361 * If the column does not have those so-called special cells, we
7362 * make sure the left-hand side of the column is visible.
7365 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7367 GtkTreePath *cursor_path;
7368 GdkRectangle background_area, cell_area, focus_area;
7370 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7372 pspp_sheet_view_get_cell_area (tree_view,
7373 cursor_path, column, &cell_area);
7374 pspp_sheet_view_get_background_area (tree_view,
7375 cursor_path, column,
7378 gtk_tree_path_free (cursor_path);
7380 _pspp_sheet_view_column_get_focus_area (column,
7386 width = focus_area.width;
7388 if (width < tree_view->priv->hadjustment->page_size)
7390 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7391 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7392 x + width - tree_view->priv->hadjustment->page_size);
7393 else if (tree_view->priv->hadjustment->value > x)
7394 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7398 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7400 tree_view->priv->hadjustment->lower,
7401 tree_view->priv->hadjustment->upper
7402 - tree_view->priv->hadjustment->page_size));
7406 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7407 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7408 x + width - tree_view->priv->hadjustment->page_size);
7409 else if (tree_view->priv->hadjustment->value > x)
7410 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7415 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7420 path = gtk_tree_path_new ();
7422 gtk_tree_path_append_index (path, node);
7427 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7431 gint *indices = gtk_tree_path_get_indices (path);
7432 gint depth = gtk_tree_path_get_depth (path);
7435 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7441 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7444 gboolean add_shifted_binding,
7445 GtkMovementStep step,
7449 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7454 if (add_shifted_binding)
7455 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7460 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7463 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7468 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7475 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7476 PsppSheetViewColumn *column)
7478 PsppSheetViewColumn *left_column;
7479 PsppSheetViewColumn *cur_column = NULL;
7480 PsppSheetViewColumnReorder *reorder;
7485 /* We want to precalculate the motion list such that we know what column slots
7489 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7491 /* First, identify all possible drop spots */
7493 tmp_list = g_list_last (tree_view->priv->columns);
7495 tmp_list = g_list_first (tree_view->priv->columns);
7499 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7500 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7502 if (cur_column->visible == FALSE)
7505 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7506 if (left_column != column && cur_column != column &&
7507 tree_view->priv->column_drop_func &&
7508 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7510 left_column = cur_column;
7513 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7514 reorder->left_column = left_column;
7515 left_column = reorder->right_column = cur_column;
7517 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7520 /* Add the last one */
7521 if (tree_view->priv->column_drop_func == NULL ||
7522 ((left_column != column) &&
7523 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7525 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7526 reorder->left_column = left_column;
7527 reorder->right_column = NULL;
7528 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7531 /* We quickly check to see if it even makes sense to reorder columns. */
7532 /* If there is nothing that can be moved, then we return */
7534 if (tree_view->priv->column_drag_info == NULL)
7537 /* We know there are always 2 slots possbile, as you can always return column. */
7538 /* If that's all there is, return */
7539 if (tree_view->priv->column_drag_info->next == NULL ||
7540 (tree_view->priv->column_drag_info->next->next == NULL &&
7541 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7542 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7544 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7545 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7546 g_list_free (tree_view->priv->column_drag_info);
7547 tree_view->priv->column_drag_info = NULL;
7550 /* We fill in the ranges for the columns, now that we've isolated them */
7551 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7553 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7555 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7557 reorder->left_align = left;
7558 if (tmp_list->next != NULL)
7560 g_assert (tmp_list->next->data);
7561 left = reorder->right_align = (reorder->right_column->allocation.x +
7562 reorder->right_column->allocation.width +
7563 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7569 gdk_drawable_get_size (tree_view->priv->header_window, &width, NULL);
7570 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7576 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7577 PsppSheetViewColumn *column)
7579 GdkEvent *send_event;
7580 GtkAllocation allocation;
7581 gint x, y, width, height;
7582 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7583 GdkDisplay *display = gdk_screen_get_display (screen);
7585 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7586 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7587 g_return_if_fail (column->button);
7589 pspp_sheet_view_set_column_drag_info (tree_view, column);
7591 if (tree_view->priv->column_drag_info == NULL)
7594 if (tree_view->priv->drag_window == NULL)
7596 GdkWindowAttr attributes;
7597 guint attributes_mask;
7599 attributes.window_type = GDK_WINDOW_CHILD;
7600 attributes.wclass = GDK_INPUT_OUTPUT;
7601 attributes.x = column->allocation.x;
7603 attributes.width = column->allocation.width;
7604 attributes.height = column->allocation.height;
7605 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7606 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
7607 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7608 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
7610 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7613 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7616 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7617 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7619 gtk_grab_remove (column->button);
7621 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7622 send_event->crossing.send_event = TRUE;
7623 send_event->crossing.window = g_object_ref (GTK_BUTTON (column->button)->event_window);
7624 send_event->crossing.subwindow = NULL;
7625 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7626 send_event->crossing.time = GDK_CURRENT_TIME;
7628 gtk_propagate_event (column->button, send_event);
7629 gdk_event_free (send_event);
7631 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7632 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7633 send_event->button.send_event = TRUE;
7634 send_event->button.time = GDK_CURRENT_TIME;
7635 send_event->button.x = -1;
7636 send_event->button.y = -1;
7637 send_event->button.axes = NULL;
7638 send_event->button.state = 0;
7639 send_event->button.button = 1;
7640 send_event->button.device = gdk_display_get_core_pointer (display);
7641 send_event->button.x_root = 0;
7642 send_event->button.y_root = 0;
7644 gtk_propagate_event (column->button, send_event);
7645 gdk_event_free (send_event);
7647 /* Kids, don't try this at home */
7648 g_object_ref (column->button);
7649 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7650 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7651 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7652 g_object_unref (column->button);
7654 tree_view->priv->drag_column_x = column->allocation.x;
7655 allocation = column->allocation;
7657 gtk_widget_size_allocate (column->button, &allocation);
7658 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7660 tree_view->priv->drag_column = column;
7661 gdk_window_show (tree_view->priv->drag_window);
7663 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7664 gdk_drawable_get_size (tree_view->priv->header_window, &width, &height);
7666 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7667 while (gtk_events_pending ())
7668 gtk_main_iteration ();
7670 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7671 gdk_pointer_grab (tree_view->priv->drag_window,
7673 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7674 NULL, NULL, GDK_CURRENT_TIME);
7675 gdk_keyboard_grab (tree_view->priv->drag_window,
7681 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7683 const GdkRectangle *clip_rect)
7687 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7691 rect.width = MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width);
7693 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7694 rect.height = ROW_HEIGHT (tree_view);
7698 GdkRectangle new_rect;
7700 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7702 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7706 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7711 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7713 const GdkRectangle *clip_rect)
7717 _pspp_sheet_view_find_node (tree_view, path, &node);
7720 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7724 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7727 GtkTreePath *cursor_path;
7729 if ((tree_view->priv->row_count == 0) ||
7730 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7734 if (tree_view->priv->cursor)
7735 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7737 if (cursor_path == NULL)
7739 /* There's no cursor. Move the cursor to the first selected row, if any
7740 * are selected, otherwise to the first row in the sheetview.
7742 GList *selected_rows;
7743 GtkTreeModel *model;
7744 PsppSheetSelection *selection;
7746 selection = pspp_sheet_view_get_selection (tree_view);
7747 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7751 /* XXX we could avoid doing O(n) work to get this result */
7752 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7753 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7754 g_list_free (selected_rows);
7758 cursor_path = gtk_tree_path_new_first ();
7759 search_first_focusable_path (tree_view, &cursor_path,
7763 gtk_tree_row_reference_free (tree_view->priv->cursor);
7764 tree_view->priv->cursor = NULL;
7768 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7769 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7770 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE);
7772 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
7778 /* Now find a column for the cursor. */
7779 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7781 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7782 gtk_tree_path_free (cursor_path);
7784 if (tree_view->priv->focus_column == NULL)
7787 for (list = tree_view->priv->columns; list; list = list->next)
7789 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7791 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7792 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7793 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7803 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7806 gint selection_count;
7807 int cursor_node = -1;
7808 int new_cursor_node = -1;
7809 GtkTreePath *cursor_path = NULL;
7810 gboolean grab_focus = TRUE;
7812 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7816 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7817 /* FIXME: we lost the cursor; should we get the first? */
7820 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7821 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7823 if (cursor_node < 0)
7824 /* FIXME: we lost the cursor; should we get the first? */
7827 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7829 if (selection_count == 0
7830 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7831 && !tree_view->priv->ctrl_pressed)
7833 /* Don't move the cursor, but just select the current node */
7834 new_cursor_node = cursor_node;
7839 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7841 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7844 gtk_tree_path_free (cursor_path);
7846 if (new_cursor_node)
7848 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7850 search_first_focusable_path (tree_view, &cursor_path,
7855 gtk_tree_path_free (cursor_path);
7859 * If the list has only one item and multi-selection is set then select
7860 * the row (if not yet selected).
7862 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7863 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7864 new_cursor_node < 0)
7867 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7869 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7871 if (new_cursor_node < 0
7872 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7874 new_cursor_node = cursor_node;
7878 new_cursor_node = -1;
7882 if (new_cursor_node >= 0)
7884 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7885 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE);
7886 gtk_tree_path_free (cursor_path);
7890 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7892 if (!tree_view->priv->shift_pressed)
7894 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7896 GTK_DIR_UP : GTK_DIR_DOWN))
7898 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
7901 gtk_widget_child_focus (toplevel,
7903 GTK_DIR_TAB_BACKWARD :
7904 GTK_DIR_TAB_FORWARD);
7911 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7916 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7920 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
7923 int cursor_node = -1;
7924 GtkTreePath *old_cursor_path = NULL;
7925 GtkTreePath *cursor_path = NULL;
7926 int start_cursor_node = -1;
7929 gint vertical_separator;
7931 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7934 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
7935 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7937 /* This is sorta weird. Focus in should give us a cursor */
7940 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
7941 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
7943 if (cursor_node < 0)
7945 /* FIXME: we lost the cursor. Should we try to get one? */
7946 gtk_tree_path_free (old_cursor_path);
7950 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7951 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
7952 y += tree_view->priv->cursor_offset;
7953 y += count * (int)tree_view->priv->vadjustment->page_increment;
7954 y = CLAMP (y, (gint)tree_view->priv->vadjustment->lower, (gint)tree_view->priv->vadjustment->upper - vertical_separator);
7956 if (y >= tree_view->priv->height)
7957 y = tree_view->priv->height - 1;
7959 tree_view->priv->cursor_offset =
7960 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
7962 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
7964 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7965 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
7968 y -= tree_view->priv->cursor_offset;
7969 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7971 start_cursor_node = cursor_node;
7973 if (! search_first_focusable_path (tree_view, &cursor_path,
7977 /* It looks like we reached the end of the view without finding
7978 * a focusable row. We will step backwards to find the last
7981 cursor_node = start_cursor_node;
7982 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7984 search_first_focusable_path (tree_view, &cursor_path,
7993 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7995 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
7998 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
7999 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8000 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8002 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
8003 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8005 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8008 gtk_tree_path_free (old_cursor_path);
8009 gtk_tree_path_free (cursor_path);
8013 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
8016 int cursor_node = -1;
8017 GtkTreePath *cursor_path = NULL;
8018 PsppSheetViewColumn *column;
8021 gboolean found_column = FALSE;
8024 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8026 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8029 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8030 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8034 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8035 if (cursor_node < 0)
8037 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8039 gtk_tree_path_free (cursor_path);
8042 gtk_tree_path_free (cursor_path);
8044 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8045 if (tree_view->priv->focus_column)
8047 for (; list; list = (rtl ? list->prev : list->next))
8049 if (list->data == tree_view->priv->focus_column)
8056 gboolean left, right;
8058 column = list->data;
8059 if (column->visible == FALSE || column->row_head)
8062 pspp_sheet_view_column_cell_set_cell_data (column,
8063 tree_view->priv->model,
8068 right = list->prev ? TRUE : FALSE;
8069 left = list->next ? TRUE : FALSE;
8073 left = list->prev ? TRUE : FALSE;
8074 right = list->next ? TRUE : FALSE;
8077 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8079 tree_view->priv->focus_column = column;
8080 found_column = TRUE;
8085 list = rtl ? list->prev : list->next;
8087 list = rtl ? list->next : list->prev;
8092 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8093 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8094 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8098 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8101 pspp_sheet_view_clamp_column_visible (tree_view,
8102 tree_view->priv->focus_column, TRUE);
8106 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8111 GtkTreePath *old_path;
8113 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8116 g_return_if_fail (tree_view->priv->row_count > 0);
8118 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8122 /* Now go forward to find the first focusable row. */
8123 path = _pspp_sheet_view_find_path (tree_view, 0);
8124 search_first_focusable_path (tree_view, &path,
8125 TRUE, &cursor_node);
8129 /* Now go backwards to find last focusable row. */
8130 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8131 search_first_focusable_path (tree_view, &path,
8132 FALSE, &cursor_node);
8138 if (gtk_tree_path_compare (old_path, path))
8140 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
8141 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8145 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8149 gtk_tree_path_free (old_path);
8150 gtk_tree_path_free (path);
8154 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8156 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8159 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8160 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8163 pspp_sheet_selection_select_all (tree_view->priv->selection);
8169 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8171 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8174 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8175 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8178 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8184 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8185 gboolean start_editing)
8188 int cursor_node = -1;
8189 GtkTreePath *cursor_path = NULL;
8190 GtkTreeSelectMode mode = 0;
8192 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8195 if (tree_view->priv->cursor)
8196 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8198 if (cursor_path == NULL)
8201 _pspp_sheet_view_find_node (tree_view, cursor_path,
8204 if (cursor_node < 0)
8206 gtk_tree_path_free (cursor_path);
8210 if (!tree_view->priv->shift_pressed && start_editing &&
8211 tree_view->priv->focus_column)
8213 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8215 gtk_tree_path_free (cursor_path);
8220 if (tree_view->priv->ctrl_pressed)
8221 mode |= GTK_TREE_SELECT_MODE_TOGGLE;
8222 if (tree_view->priv->shift_pressed)
8223 mode |= GTK_TREE_SELECT_MODE_EXTEND;
8225 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8231 /* We bail out if the original (tree, node) don't exist anymore after
8232 * handling the selection-changed callback. We do return TRUE because
8233 * the key press has been handled at this point.
8235 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8237 if (cursor_node != new_node)
8240 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8242 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8243 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8245 if (!tree_view->priv->shift_pressed)
8246 pspp_sheet_view_row_activated (tree_view, cursor_path,
8247 tree_view->priv->focus_column);
8249 gtk_tree_path_free (cursor_path);
8255 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8258 int cursor_node = -1;
8259 GtkTreePath *cursor_path = NULL;
8261 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8265 if (tree_view->priv->cursor)
8266 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8268 if (cursor_path == NULL)
8271 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8272 if (cursor_node < 0)
8274 gtk_tree_path_free (cursor_path);
8278 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8281 GTK_TREE_SELECT_MODE_TOGGLE,
8284 /* We bail out if the original (tree, node) don't exist anymore after
8285 * handling the selection-changed callback. We do return TRUE because
8286 * the key press has been handled at this point.
8288 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8290 if (cursor_node != new_node)
8293 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8295 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8296 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8297 gtk_tree_path_free (cursor_path);
8303 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8305 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8306 tree_view->priv->typeselect_flush_timeout = 0;
8311 /* Cut and paste from gtkwindow.c */
8313 send_focus_change (GtkWidget *widget,
8316 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8318 g_object_ref (widget);
8321 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
8323 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
8325 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8326 fevent->focus_change.window = g_object_ref (widget->window);
8327 fevent->focus_change.in = in;
8329 gtk_widget_event (widget, fevent);
8331 g_object_notify (G_OBJECT (widget), "has-focus");
8333 g_object_unref (widget);
8334 gdk_event_free (fevent);
8338 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8340 GtkWidget *frame, *vbox, *toplevel;
8343 if (tree_view->priv->search_custom_entry_set)
8346 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8347 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8349 if (tree_view->priv->search_window != NULL)
8351 if (GTK_WINDOW (toplevel)->group)
8352 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8353 GTK_WINDOW (tree_view->priv->search_window));
8354 else if (GTK_WINDOW (tree_view->priv->search_window)->group)
8355 gtk_window_group_remove_window (GTK_WINDOW (tree_view->priv->search_window)->group,
8356 GTK_WINDOW (tree_view->priv->search_window));
8357 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8361 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8362 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8364 if (GTK_WINDOW (toplevel)->group)
8365 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8366 GTK_WINDOW (tree_view->priv->search_window));
8368 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8369 GDK_WINDOW_TYPE_HINT_UTILITY);
8370 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8371 g_signal_connect (tree_view->priv->search_window, "delete-event",
8372 G_CALLBACK (pspp_sheet_view_search_delete_event),
8374 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8375 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8377 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8378 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8380 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8381 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8384 frame = gtk_frame_new (NULL);
8385 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8386 gtk_widget_show (frame);
8387 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8389 vbox = gtk_vbox_new (FALSE, 0);
8390 gtk_widget_show (vbox);
8391 gtk_container_add (GTK_CONTAINER (frame), vbox);
8392 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8395 tree_view->priv->search_entry = gtk_entry_new ();
8396 gtk_widget_show (tree_view->priv->search_entry);
8397 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8398 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8400 g_signal_connect (tree_view->priv->search_entry,
8401 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8403 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8405 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8407 gtk_container_add (GTK_CONTAINER (vbox),
8408 tree_view->priv->search_entry);
8410 gtk_widget_realize (tree_view->priv->search_entry);
8413 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8414 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8417 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8418 gboolean keybinding)
8420 /* We only start interactive search if we have focus or the columns
8421 * have focus. If one of our children have focus, we don't want to
8425 gboolean found_focus = FALSE;
8426 GtkWidgetClass *entry_parent_class;
8428 if (!tree_view->priv->enable_search && !keybinding)
8431 if (tree_view->priv->search_custom_entry_set)
8434 if (tree_view->priv->search_window != NULL &&
8435 gtk_widget_get_visible (tree_view->priv->search_window))
8438 for (list = tree_view->priv->columns; list; list = list->next)
8440 PsppSheetViewColumn *column;
8442 column = list->data;
8443 if (! column->visible)
8446 if (column->button && gtk_widget_has_focus (column->button))
8453 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8459 if (tree_view->priv->search_column < 0)
8462 pspp_sheet_view_ensure_interactive_directory (tree_view);
8465 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8468 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8469 gtk_widget_show (tree_view->priv->search_window);
8470 if (tree_view->priv->search_entry_changed_id == 0)
8472 tree_view->priv->search_entry_changed_id =
8473 g_signal_connect (tree_view->priv->search_entry, "changed",
8474 G_CALLBACK (pspp_sheet_view_search_init),
8478 tree_view->priv->typeselect_flush_timeout =
8479 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8480 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8483 /* Grab focus will select all the text. We don't want that to happen, so we
8484 * call the parent instance and bypass the selection change. This is probably
8485 * really non-kosher. */
8486 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8487 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8489 /* send focus-in event */
8490 send_focus_change (tree_view->priv->search_entry, TRUE);
8492 /* search first matching iter */
8493 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8499 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8501 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8504 /* this function returns the new width of the column being resized given
8505 * the column and x position of the cursor; the x cursor position is passed
8506 * in as a pointer and automagicly corrected if it's beyond min/max limits
8509 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8513 PsppSheetViewColumn *column;
8517 /* first translate the x position from widget->window
8518 * to clist->clist_window
8520 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8521 column = g_list_nth (tree_view->priv->columns, i)->data;
8522 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8524 /* Clamp down the value */
8525 if (column->min_width == -1)
8526 width = MAX (column->button_request, width);
8528 width = MAX (column->min_width, width);
8529 if (column->max_width != -1)
8530 width = MIN (width, column->max_width);
8532 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8538 /* FIXME this adjust_allocation is a big cut-and-paste from
8539 * GtkCList, needs to be some "official" way to do this
8549 /* The window to which widget->window is relative */
8550 #define ALLOCATION_WINDOW(widget) \
8551 (!gtk_widget_get_has_window (widget) ? \
8552 (widget)->window : \
8553 gdk_window_get_parent ((widget)->window))
8556 adjust_allocation_recurse (GtkWidget *widget,
8559 ScrollData *scroll_data = data;
8561 /* Need to really size allocate instead of just poking
8562 * into widget->allocation if the widget is not realized.
8563 * FIXME someone figure out why this was.
8565 if (!gtk_widget_get_realized (widget))
8567 if (gtk_widget_get_visible (widget))
8569 GdkRectangle tmp_rectangle = widget->allocation;
8570 tmp_rectangle.x += scroll_data->dx;
8571 tmp_rectangle.y += scroll_data->dy;
8573 gtk_widget_size_allocate (widget, &tmp_rectangle);
8578 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8580 widget->allocation.x += scroll_data->dx;
8581 widget->allocation.y += scroll_data->dy;
8583 if (GTK_IS_CONTAINER (widget))
8584 gtk_container_forall (GTK_CONTAINER (widget),
8585 adjust_allocation_recurse,
8592 adjust_allocation (GtkWidget *widget,
8596 ScrollData scroll_data;
8598 if (gtk_widget_get_realized (widget))
8599 scroll_data.window = ALLOCATION_WINDOW (widget);
8601 scroll_data.window = NULL;
8603 scroll_data.dx = dx;
8604 scroll_data.dy = dy;
8606 adjust_allocation_recurse (widget, &scroll_data);
8610 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8614 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8615 PsppSheetView *tree_view)
8617 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8622 gdk_window_move (tree_view->priv->bin_window,
8623 - tree_view->priv->hadjustment->value,
8624 TREE_VIEW_HEADER_HEIGHT (tree_view));
8625 gdk_window_move (tree_view->priv->header_window,
8626 - tree_view->priv->hadjustment->value,
8628 dy = tree_view->priv->dy - (int) tree_view->priv->vadjustment->value;
8631 update_prelight (tree_view,
8632 tree_view->priv->event_last_x,
8633 tree_view->priv->event_last_y - dy);
8635 if (tree_view->priv->edited_column &&
8636 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8640 PsppSheetViewChild *child = NULL;
8642 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8643 adjust_allocation (widget, 0, dy);
8645 for (list = tree_view->priv->children; list; list = list->next)
8647 child = (PsppSheetViewChild *)list->data;
8648 if (child->widget == widget)
8656 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8658 if (tree_view->priv->dy != (int) tree_view->priv->vadjustment->value)
8660 /* update our dy and top_row */
8661 tree_view->priv->dy = (int) tree_view->priv->vadjustment->value;
8663 if (!tree_view->priv->in_top_row_to_dy)
8664 pspp_sheet_view_dy_to_top_row (tree_view);
8667 for (list = tree_view->priv->columns; list; list = list->next)
8669 PsppSheetViewColumn *column = list->data;
8670 GtkAllocation *allocation = &column->allocation;
8672 if (span_intersects (allocation->x, allocation->width,
8673 tree_view->priv->hadjustment->value,
8674 GTK_WIDGET (tree_view)->allocation.width))
8676 pspp_sheet_view_column_set_need_button (column, TRUE);
8677 if (!column->button)
8678 pspp_sheet_view_column_update_button (column);
8690 * pspp_sheet_view_new:
8692 * Creates a new #PsppSheetView widget.
8694 * Return value: A newly created #PsppSheetView widget.
8697 pspp_sheet_view_new (void)
8699 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8703 * pspp_sheet_view_new_with_model:
8704 * @model: the model.
8706 * Creates a new #PsppSheetView widget with the model initialized to @model.
8708 * Return value: A newly created #PsppSheetView widget.
8711 pspp_sheet_view_new_with_model (GtkTreeModel *model)
8713 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
8720 * pspp_sheet_view_get_model:
8721 * @tree_view: a #PsppSheetView
8723 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
8726 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
8729 pspp_sheet_view_get_model (PsppSheetView *tree_view)
8731 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8733 return tree_view->priv->model;
8737 * pspp_sheet_view_set_model:
8738 * @tree_view: A #GtkTreeNode.
8739 * @model: (allow-none): The model.
8741 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
8742 * set, it will remove it before setting the new model. If @model is %NULL,
8743 * then it will unset the old model.
8746 pspp_sheet_view_set_model (PsppSheetView *tree_view,
8747 GtkTreeModel *model)
8749 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8750 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
8752 if (model == tree_view->priv->model)
8755 if (tree_view->priv->scroll_to_path)
8757 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8758 tree_view->priv->scroll_to_path = NULL;
8761 if (tree_view->priv->model)
8763 GList *tmplist = tree_view->priv->columns;
8765 if (tree_view->priv->selected)
8766 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
8767 pspp_sheet_view_stop_editing (tree_view, TRUE);
8769 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8770 pspp_sheet_view_row_changed,
8772 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8773 pspp_sheet_view_row_inserted,
8775 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8776 pspp_sheet_view_row_deleted,
8778 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8779 pspp_sheet_view_rows_reordered,
8782 for (; tmplist; tmplist = tmplist->next)
8783 _pspp_sheet_view_column_unset_model (tmplist->data,
8784 tree_view->priv->model);
8786 tree_view->priv->prelight_node = -1;
8788 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
8789 tree_view->priv->drag_dest_row = NULL;
8790 gtk_tree_row_reference_free (tree_view->priv->cursor);
8791 tree_view->priv->cursor = NULL;
8792 gtk_tree_row_reference_free (tree_view->priv->anchor);
8793 tree_view->priv->anchor = NULL;
8794 gtk_tree_row_reference_free (tree_view->priv->top_row);
8795 tree_view->priv->top_row = NULL;
8796 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8797 tree_view->priv->scroll_to_path = NULL;
8799 tree_view->priv->scroll_to_column = NULL;
8801 g_object_unref (tree_view->priv->model);
8803 tree_view->priv->search_column = -1;
8804 tree_view->priv->fixed_height = -1;
8805 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
8806 tree_view->priv->last_button_x = -1;
8807 tree_view->priv->last_button_y = -1;
8810 tree_view->priv->model = model;
8812 if (tree_view->priv->model)
8815 GtkTreeModelFlags flags;
8817 if (tree_view->priv->search_column == -1)
8819 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
8821 GType type = gtk_tree_model_get_column_type (model, i);
8823 if (g_value_type_transformable (type, G_TYPE_STRING))
8825 tree_view->priv->search_column = i;
8831 g_object_ref (tree_view->priv->model);
8832 g_signal_connect (tree_view->priv->model,
8834 G_CALLBACK (pspp_sheet_view_row_changed),
8836 g_signal_connect (tree_view->priv->model,
8838 G_CALLBACK (pspp_sheet_view_row_inserted),
8840 g_signal_connect (tree_view->priv->model,
8842 G_CALLBACK (pspp_sheet_view_row_deleted),
8844 g_signal_connect (tree_view->priv->model,
8846 G_CALLBACK (pspp_sheet_view_rows_reordered),
8849 flags = gtk_tree_model_get_flags (tree_view->priv->model);
8851 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
8853 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
8854 install_presize_handler (tree_view);
8857 g_object_notify (G_OBJECT (tree_view), "model");
8859 if (tree_view->priv->selection)
8860 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
8862 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8863 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
8867 * pspp_sheet_view_get_selection:
8868 * @tree_view: A #PsppSheetView.
8870 * Gets the #PsppSheetSelection associated with @tree_view.
8872 * Return value: A #PsppSheetSelection object.
8874 PsppSheetSelection *
8875 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
8877 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8879 return tree_view->priv->selection;
8883 * pspp_sheet_view_get_hadjustment:
8884 * @tree_view: A #PsppSheetView
8886 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
8888 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8892 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
8894 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8896 if (tree_view->priv->hadjustment == NULL)
8897 pspp_sheet_view_set_hadjustment (tree_view, NULL);
8899 return tree_view->priv->hadjustment;
8903 * pspp_sheet_view_set_hadjustment:
8904 * @tree_view: A #PsppSheetView
8905 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8907 * Sets the #GtkAdjustment for the current horizontal aspect.
8910 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
8911 GtkAdjustment *adjustment)
8913 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8915 pspp_sheet_view_set_adjustments (tree_view,
8917 tree_view->priv->vadjustment);
8919 g_object_notify (G_OBJECT (tree_view), "hadjustment");
8923 * pspp_sheet_view_get_vadjustment:
8924 * @tree_view: A #PsppSheetView
8926 * Gets the #GtkAdjustment currently being used for the vertical aspect.
8928 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8932 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
8934 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8936 if (tree_view->priv->vadjustment == NULL)
8937 pspp_sheet_view_set_vadjustment (tree_view, NULL);
8939 return tree_view->priv->vadjustment;
8943 * pspp_sheet_view_set_vadjustment:
8944 * @tree_view: A #PsppSheetView
8945 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8947 * Sets the #GtkAdjustment for the current vertical aspect.
8950 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
8951 GtkAdjustment *adjustment)
8953 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8955 pspp_sheet_view_set_adjustments (tree_view,
8956 tree_view->priv->hadjustment,
8959 g_object_notify (G_OBJECT (tree_view), "vadjustment");
8962 /* Column and header operations */
8965 * pspp_sheet_view_get_headers_visible:
8966 * @tree_view: A #PsppSheetView.
8968 * Returns %TRUE if the headers on the @tree_view are visible.
8970 * Return value: Whether the headers are visible or not.
8973 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
8975 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
8977 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8981 * pspp_sheet_view_set_headers_visible:
8982 * @tree_view: A #PsppSheetView.
8983 * @headers_visible: %TRUE if the headers are visible
8985 * Sets the visibility state of the headers.
8988 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
8989 gboolean headers_visible)
8993 PsppSheetViewColumn *column;
8995 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8997 headers_visible = !! headers_visible;
8999 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
9002 if (headers_visible)
9003 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9005 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9007 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9009 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
9010 if (headers_visible)
9012 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));
9014 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9015 pspp_sheet_view_map_buttons (tree_view);
9019 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9021 for (list = tree_view->priv->columns; list; list = list->next)
9023 column = list->data;
9025 gtk_widget_unmap (column->button);
9027 gdk_window_hide (tree_view->priv->header_window);
9031 tree_view->priv->vadjustment->page_size = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
9032 tree_view->priv->vadjustment->page_increment = (GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2;
9033 tree_view->priv->vadjustment->lower = 0;
9034 tree_view->priv->vadjustment->upper = tree_view->priv->height;
9035 gtk_adjustment_changed (tree_view->priv->vadjustment);
9037 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9039 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9043 * pspp_sheet_view_columns_autosize:
9044 * @tree_view: A #PsppSheetView.
9046 * Resizes all columns to their optimal width. Only works after the
9047 * treeview has been realized.
9050 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9052 gboolean dirty = FALSE;
9054 PsppSheetViewColumn *column;
9056 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9058 for (list = tree_view->priv->columns; list; list = list->next)
9060 column = list->data;
9061 _pspp_sheet_view_column_cell_set_dirty (column);
9066 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9070 * pspp_sheet_view_set_headers_clickable:
9071 * @tree_view: A #PsppSheetView.
9072 * @setting: %TRUE if the columns are clickable.
9074 * Allow the column title buttons to be clicked.
9077 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9082 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9084 for (list = tree_view->priv->columns; list; list = list->next)
9085 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9087 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9092 * pspp_sheet_view_get_headers_clickable:
9093 * @tree_view: A #PsppSheetView.
9095 * Returns whether all header columns are clickable.
9097 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9102 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9106 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9108 for (list = tree_view->priv->columns; list; list = list->next)
9109 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9116 * pspp_sheet_view_set_rules_hint
9117 * @tree_view: a #PsppSheetView
9118 * @setting: %TRUE if the tree requires reading across rows
9120 * This function tells GTK+ that the user interface for your
9121 * application requires users to read across tree rows and associate
9122 * cells with one another. By default, GTK+ will then render the tree
9123 * with alternating row colors. Do <emphasis>not</emphasis> use it
9124 * just because you prefer the appearance of the ruled tree; that's a
9125 * question for the theme. Some themes will draw tree rows in
9126 * alternating colors even when rules are turned off, and users who
9127 * prefer that appearance all the time can choose those themes. You
9128 * should call this function only as a <emphasis>semantic</emphasis>
9129 * hint to the theme engine that your tree makes alternating colors
9130 * useful from a functional standpoint (since it has lots of columns,
9135 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9138 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9140 setting = setting != FALSE;
9142 if (tree_view->priv->has_rules != setting)
9144 tree_view->priv->has_rules = setting;
9145 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9148 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9152 * pspp_sheet_view_get_rules_hint
9153 * @tree_view: a #PsppSheetView
9155 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9157 * Return value: %TRUE if rules are useful for the user of this tree
9160 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9162 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9164 return tree_view->priv->has_rules;
9167 /* Public Column functions
9171 * pspp_sheet_view_append_column:
9172 * @tree_view: A #PsppSheetView.
9173 * @column: The #PsppSheetViewColumn to add.
9175 * Appends @column to the list of columns.
9177 * Return value: The number of columns in @tree_view after appending.
9180 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9181 PsppSheetViewColumn *column)
9183 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9184 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9185 g_return_val_if_fail (column->tree_view == NULL, -1);
9187 return pspp_sheet_view_insert_column (tree_view, column, -1);
9192 * pspp_sheet_view_remove_column:
9193 * @tree_view: A #PsppSheetView.
9194 * @column: The #PsppSheetViewColumn to remove.
9196 * Removes @column from @tree_view.
9198 * Return value: The number of columns in @tree_view after removing.
9201 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9202 PsppSheetViewColumn *column)
9204 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9205 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9206 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9208 if (tree_view->priv->focus_column == column)
9209 tree_view->priv->focus_column = NULL;
9211 if (tree_view->priv->edited_column == column)
9213 pspp_sheet_view_stop_editing (tree_view, TRUE);
9215 /* no need to, but just to be sure ... */
9216 tree_view->priv->edited_column = NULL;
9219 _pspp_sheet_view_column_unset_tree_view (column);
9221 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9222 tree_view->priv->n_columns--;
9224 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9228 _pspp_sheet_view_column_unrealize_button (column);
9229 for (list = tree_view->priv->columns; list; list = list->next)
9231 PsppSheetViewColumn *tmp_column;
9233 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9234 if (tmp_column->visible)
9235 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9238 if (tree_view->priv->n_columns == 0 &&
9239 pspp_sheet_view_get_headers_visible (tree_view) &&
9240 tree_view->priv->header_window)
9241 gdk_window_hide (tree_view->priv->header_window);
9243 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9246 g_object_unref (column);
9247 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9249 return tree_view->priv->n_columns;
9253 * pspp_sheet_view_insert_column:
9254 * @tree_view: A #PsppSheetView.
9255 * @column: The #PsppSheetViewColumn to be inserted.
9256 * @position: The position to insert @column in.
9258 * This inserts the @column into the @tree_view at @position. If @position is
9259 * -1, then the column is inserted at the end.
9261 * Return value: The number of columns in @tree_view after insertion.
9264 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9265 PsppSheetViewColumn *column,
9268 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9269 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9270 g_return_val_if_fail (column->tree_view == NULL, -1);
9272 g_object_ref_sink (column);
9274 if (tree_view->priv->n_columns == 0 &&
9275 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9276 pspp_sheet_view_get_headers_visible (tree_view))
9278 gdk_window_show (tree_view->priv->header_window);
9281 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9283 tree_view->priv->n_columns++;
9285 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9287 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9291 _pspp_sheet_view_column_realize_button (column);
9293 for (list = tree_view->priv->columns; list; list = list->next)
9295 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9296 if (column->visible)
9297 _pspp_sheet_view_column_cell_set_dirty (column);
9299 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9302 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9304 return tree_view->priv->n_columns;
9308 * pspp_sheet_view_insert_column_with_attributes:
9309 * @tree_view: A #PsppSheetView
9310 * @position: The position to insert the new column in.
9311 * @title: The title to set the header to.
9312 * @cell: The #GtkCellRenderer.
9313 * @Varargs: A %NULL-terminated list of attributes.
9315 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9316 * @position. If @position is -1, then the newly created column is inserted at
9317 * the end. The column is initialized with the attributes given.
9319 * Return value: The number of columns in @tree_view after insertion.
9322 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9325 GtkCellRenderer *cell,
9328 PsppSheetViewColumn *column;
9333 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9335 column = pspp_sheet_view_column_new ();
9336 pspp_sheet_view_column_set_title (column, title);
9337 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9339 va_start (args, cell);
9341 attribute = va_arg (args, gchar *);
9343 while (attribute != NULL)
9345 column_id = va_arg (args, gint);
9346 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9347 attribute = va_arg (args, gchar *);
9352 pspp_sheet_view_insert_column (tree_view, column, position);
9354 return tree_view->priv->n_columns;
9358 * pspp_sheet_view_insert_column_with_data_func:
9359 * @tree_view: a #PsppSheetView
9360 * @position: Position to insert, -1 for append
9361 * @title: column title
9362 * @cell: cell renderer for column
9363 * @func: function to set attributes of cell renderer
9364 * @data: data for @func
9365 * @dnotify: destroy notifier for @data
9367 * Convenience function that inserts a new column into the #PsppSheetView
9368 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9369 * attributes (normally using data from the model). See also
9370 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9372 * Return value: number of columns in the tree view post-insert
9375 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9378 GtkCellRenderer *cell,
9379 PsppSheetCellDataFunc func,
9381 GDestroyNotify dnotify)
9383 PsppSheetViewColumn *column;
9385 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9387 column = pspp_sheet_view_column_new ();
9388 pspp_sheet_view_column_set_title (column, title);
9389 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9390 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9392 pspp_sheet_view_insert_column (tree_view, column, position);
9394 return tree_view->priv->n_columns;
9398 * pspp_sheet_view_get_column:
9399 * @tree_view: A #PsppSheetView.
9400 * @n: The position of the column, counting from 0.
9402 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9404 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9407 PsppSheetViewColumn *
9408 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9411 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9413 if (n < 0 || n >= tree_view->priv->n_columns)
9416 if (tree_view->priv->columns == NULL)
9419 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9423 * pspp_sheet_view_get_columns:
9424 * @tree_view: A #PsppSheetView
9426 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9427 * The returned list must be freed with g_list_free ().
9429 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9432 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9434 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9436 return g_list_copy (tree_view->priv->columns);
9440 * pspp_sheet_view_move_column_after:
9441 * @tree_view: A #PsppSheetView
9442 * @column: The #PsppSheetViewColumn to be moved.
9443 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9445 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9446 * @column is placed in the first position.
9449 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9450 PsppSheetViewColumn *column,
9451 PsppSheetViewColumn *base_column)
9453 GList *column_list_el, *base_el = NULL;
9455 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9457 column_list_el = g_list_find (tree_view->priv->columns, column);
9458 g_return_if_fail (column_list_el != NULL);
9462 base_el = g_list_find (tree_view->priv->columns, base_column);
9463 g_return_if_fail (base_el != NULL);
9466 if (column_list_el->prev == base_el)
9469 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9470 if (base_el == NULL)
9472 column_list_el->prev = NULL;
9473 column_list_el->next = tree_view->priv->columns;
9474 if (column_list_el->next)
9475 column_list_el->next->prev = column_list_el;
9476 tree_view->priv->columns = column_list_el;
9480 column_list_el->prev = base_el;
9481 column_list_el->next = base_el->next;
9482 if (column_list_el->next)
9483 column_list_el->next->prev = column_list_el;
9484 base_el->next = column_list_el;
9487 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9489 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9490 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9493 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9497 * pspp_sheet_view_set_column_drag_function:
9498 * @tree_view: A #PsppSheetView.
9499 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9500 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9501 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9503 * Sets a user function for determining where a column may be dropped when
9504 * dragged. This function is called on every column pair in turn at the
9505 * beginning of a column drag to determine where a drop can take place. The
9506 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9507 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9508 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9509 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9510 * @tree_view reverts to the default behavior of allowing all columns to be
9511 * dropped everywhere.
9514 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9515 PsppSheetViewColumnDropFunc func,
9517 GDestroyNotify destroy)
9519 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9521 if (tree_view->priv->column_drop_func_data_destroy)
9522 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9524 tree_view->priv->column_drop_func = func;
9525 tree_view->priv->column_drop_func_data = user_data;
9526 tree_view->priv->column_drop_func_data_destroy = destroy;
9530 * pspp_sheet_view_scroll_to_point:
9531 * @tree_view: a #PsppSheetView
9532 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9533 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9535 * Scrolls the tree view such that the top-left corner of the visible
9536 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9537 * in tree coordinates. The @tree_view must be realized before
9538 * this function is called. If it isn't, you probably want to be
9539 * using pspp_sheet_view_scroll_to_cell().
9541 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9544 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9548 GtkAdjustment *hadj;
9549 GtkAdjustment *vadj;
9551 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9552 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9554 hadj = tree_view->priv->hadjustment;
9555 vadj = tree_view->priv->vadjustment;
9558 gtk_adjustment_set_value (hadj, CLAMP (tree_x, hadj->lower, hadj->upper - hadj->page_size));
9560 gtk_adjustment_set_value (vadj, CLAMP (tree_y, vadj->lower, vadj->upper - vadj->page_size));
9564 * pspp_sheet_view_scroll_to_cell:
9565 * @tree_view: A #PsppSheetView.
9566 * @path: (allow-none): The path of the row to move to, or %NULL.
9567 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9568 * @use_align: whether to use alignment arguments, or %FALSE.
9569 * @row_align: The vertical alignment of the row specified by @path.
9570 * @col_align: The horizontal alignment of the column specified by @column.
9572 * Moves the alignments of @tree_view to the position specified by @column and
9573 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9574 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9575 * or @path need to be non-%NULL. @row_align determines where the row is
9576 * placed, and @col_align determines where @column is placed. Both are expected
9577 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9578 * right/bottom alignment, 0.5 means center.
9580 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9581 * tree does the minimum amount of work to scroll the cell onto the screen.
9582 * This means that the cell will be scrolled to the edge closest to its current
9583 * position. If the cell is currently visible on the screen, nothing is done.
9585 * This function only works if the model is set, and @path is a valid row on the
9586 * model. If the model changes before the @tree_view is realized, the centered
9587 * path will be modified to reflect this change.
9590 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9592 PsppSheetViewColumn *column,
9597 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9598 g_return_if_fail (tree_view->priv->model != NULL);
9599 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9600 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9601 g_return_if_fail (path != NULL || column != NULL);
9604 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9605 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9607 row_align = CLAMP (row_align, 0.0, 1.0);
9608 col_align = CLAMP (col_align, 0.0, 1.0);
9611 /* Note: Despite the benefits that come from having one code path for the
9612 * scrolling code, we short-circuit validate_visible_area's immplementation as
9613 * it is much slower than just going to the point.
9615 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9616 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9617 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9619 if (tree_view->priv->scroll_to_path)
9620 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9622 tree_view->priv->scroll_to_path = NULL;
9623 tree_view->priv->scroll_to_column = NULL;
9626 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9628 tree_view->priv->scroll_to_column = column;
9629 tree_view->priv->scroll_to_use_align = use_align;
9630 tree_view->priv->scroll_to_row_align = row_align;
9631 tree_view->priv->scroll_to_col_align = col_align;
9633 install_presize_handler (tree_view);
9637 GdkRectangle cell_rect;
9638 GdkRectangle vis_rect;
9639 gint dest_x, dest_y;
9641 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9642 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9644 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9646 dest_x = vis_rect.x;
9647 dest_y = vis_rect.y;
9653 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9657 if (cell_rect.x < vis_rect.x)
9658 dest_x = cell_rect.x;
9659 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9660 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9668 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9669 dest_y = MAX (dest_y, 0);
9673 if (cell_rect.y < vis_rect.y)
9674 dest_y = cell_rect.y;
9675 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9676 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9680 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9685 * pspp_sheet_view_row_activated:
9686 * @tree_view: A #PsppSheetView
9687 * @path: The #GtkTreePath to be activated.
9688 * @column: The #PsppSheetViewColumn to be activated.
9690 * Activates the cell determined by @path and @column.
9693 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9695 PsppSheetViewColumn *column)
9697 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9699 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
9704 * pspp_sheet_view_get_reorderable:
9705 * @tree_view: a #PsppSheetView
9707 * Retrieves whether the user can reorder the tree via drag-and-drop. See
9708 * pspp_sheet_view_set_reorderable().
9710 * Return value: %TRUE if the tree can be reordered.
9713 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
9715 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9717 return tree_view->priv->reorderable;
9721 * pspp_sheet_view_set_reorderable:
9722 * @tree_view: A #PsppSheetView.
9723 * @reorderable: %TRUE, if the tree can be reordered.
9725 * This function is a convenience function to allow you to reorder
9726 * models that support the #GtkDragSourceIface and the
9727 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
9728 * these. If @reorderable is %TRUE, then the user can reorder the
9729 * model by dragging and dropping rows. The developer can listen to
9730 * these changes by connecting to the model's row_inserted and
9731 * row_deleted signals. The reordering is implemented by setting up
9732 * the tree view as a drag source and destination. Therefore, drag and
9733 * drop can not be used in a reorderable view for any other purpose.
9735 * This function does not give you any degree of control over the order -- any
9736 * reordering is allowed. If more control is needed, you should probably
9737 * handle drag and drop manually.
9740 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
9741 gboolean reorderable)
9743 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9745 reorderable = reorderable != FALSE;
9747 if (tree_view->priv->reorderable == reorderable)
9752 const GtkTargetEntry row_targets[] = {
9753 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
9756 pspp_sheet_view_enable_model_drag_source (tree_view,
9759 G_N_ELEMENTS (row_targets),
9761 pspp_sheet_view_enable_model_drag_dest (tree_view,
9763 G_N_ELEMENTS (row_targets),
9768 pspp_sheet_view_unset_rows_drag_source (tree_view);
9769 pspp_sheet_view_unset_rows_drag_dest (tree_view);
9772 tree_view->priv->reorderable = reorderable;
9774 g_object_notify (G_OBJECT (tree_view), "reorderable");
9777 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
9778 is pressed, other rows will be unselected.
9780 If CLAMP_NODE is true, then the sheetview will scroll to make the row
9783 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
9785 gboolean clear_and_select,
9786 gboolean clamp_node)
9790 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9792 GtkTreePath *cursor_path;
9793 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9794 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
9795 gtk_tree_path_free (cursor_path);
9798 gtk_tree_row_reference_free (tree_view->priv->cursor);
9799 tree_view->priv->cursor = NULL;
9801 _pspp_sheet_view_find_node (tree_view, path, &node);
9802 tree_view->priv->cursor =
9803 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
9804 tree_view->priv->model,
9807 if (tree_view->priv->row_count > 0)
9811 if (clear_and_select && !tree_view->priv->ctrl_pressed)
9813 GtkTreeSelectMode mode = 0;
9815 if (tree_view->priv->ctrl_pressed)
9816 mode |= GTK_TREE_SELECT_MODE_TOGGLE;
9817 if (tree_view->priv->shift_pressed)
9818 mode |= GTK_TREE_SELECT_MODE_EXTEND;
9820 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
9825 /* We have to re-find tree and node here again, somebody might have
9826 * cleared the node or the whole tree in the PsppSheetSelection::changed
9827 * callback. If the nodes differ we bail out here.
9829 _pspp_sheet_view_find_node (tree_view, path, &new_node);
9831 if (node != new_node)
9836 pspp_sheet_view_clamp_node_visible (tree_view, node);
9837 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
9841 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
9845 * pspp_sheet_view_get_cursor:
9846 * @tree_view: A #PsppSheetView
9847 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
9848 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
9850 * Fills in @path and @focus_column with the current path and focus column. If
9851 * the cursor isn't currently set, then *@path will be %NULL. If no column
9852 * currently has focus, then *@focus_column will be %NULL.
9854 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
9855 * you are done with it.
9858 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
9860 PsppSheetViewColumn **focus_column)
9862 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9866 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9867 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9874 *focus_column = tree_view->priv->focus_column;
9879 * pspp_sheet_view_set_cursor:
9880 * @tree_view: A #PsppSheetView
9881 * @path: A #GtkTreePath
9882 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9883 * @start_editing: %TRUE if the specified cell should start being edited.
9885 * Sets the current keyboard focus to be at @path, and selects it. This is
9886 * useful when you want to focus the user's attention on a particular row. If
9887 * @focus_column is not %NULL, then focus is given to the column specified by
9888 * it. Additionally, if @focus_column is specified, and @start_editing is
9889 * %TRUE, then editing should be started in the specified cell.
9890 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
9891 * in order to give keyboard focus to the widget. Please note that editing
9892 * can only happen when the widget is realized.
9894 * If @path is invalid for @model, the current cursor (if any) will be unset
9895 * and the function will return without failing.
9898 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
9900 PsppSheetViewColumn *focus_column,
9901 gboolean start_editing)
9903 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
9904 NULL, start_editing);
9908 * pspp_sheet_view_set_cursor_on_cell:
9909 * @tree_view: A #PsppSheetView
9910 * @path: A #GtkTreePath
9911 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9912 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
9913 * @start_editing: %TRUE if the specified cell should start being edited.
9915 * Sets the current keyboard focus to be at @path, and selects it. This is
9916 * useful when you want to focus the user's attention on a particular row. If
9917 * @focus_column is not %NULL, then focus is given to the column specified by
9918 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
9919 * contains 2 or more editable or activatable cells, then focus is given to
9920 * the cell specified by @focus_cell. Additionally, if @focus_column is
9921 * specified, and @start_editing is %TRUE, then editing should be started in
9922 * the specified cell. This function is often followed by
9923 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
9924 * widget. Please note that editing can only happen when the widget is
9927 * If @path is invalid for @model, the current cursor (if any) will be unset
9928 * and the function will return without failing.
9933 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
9935 PsppSheetViewColumn *focus_column,
9936 GtkCellRenderer *focus_cell,
9937 gboolean start_editing)
9939 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9940 g_return_if_fail (path != NULL);
9941 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
9943 if (!tree_view->priv->model)
9948 g_return_if_fail (focus_column);
9949 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
9952 /* cancel the current editing, if it exists */
9953 if (tree_view->priv->edited_column &&
9954 tree_view->priv->edited_column->editable_widget)
9955 pspp_sheet_view_stop_editing (tree_view, TRUE);
9957 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
9959 if (focus_column && focus_column->visible)
9962 gboolean column_in_tree = FALSE;
9964 for (list = tree_view->priv->columns; list; list = list->next)
9965 if (list->data == focus_column)
9967 column_in_tree = TRUE;
9970 g_return_if_fail (column_in_tree);
9971 tree_view->priv->focus_column = focus_column;
9973 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
9975 pspp_sheet_view_start_editing (tree_view, path);
9977 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
9978 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
9984 * pspp_sheet_view_get_bin_window:
9985 * @tree_view: A #PsppSheetView
9987 * Returns the window that @tree_view renders to. This is used primarily to
9988 * compare to <literal>event->window</literal> to confirm that the event on
9989 * @tree_view is on the right window.
9991 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
9994 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
9996 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9998 return tree_view->priv->bin_window;
10002 * pspp_sheet_view_get_path_at_pos:
10003 * @tree_view: A #PsppSheetView.
10004 * @x: The x position to be identified (relative to bin_window).
10005 * @y: The y position to be identified (relative to bin_window).
10006 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
10007 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
10008 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
10009 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
10011 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10012 * (please see pspp_sheet_view_get_bin_window()).
10013 * That is, @x and @y are relative to an events coordinates. @x and @y must
10014 * come from an event on the @tree_view only where <literal>event->window ==
10015 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10016 * things like popup menus. If @path is non-%NULL, then it will be filled
10017 * with the #GtkTreePath at that point. This path should be freed with
10018 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10019 * with the column at that point. @cell_x and @cell_y return the coordinates
10020 * relative to the cell background (i.e. the @background_area passed to
10021 * gtk_cell_renderer_render()). This function is only meaningful if
10022 * @tree_view is realized. Therefore this function will always return %FALSE
10023 * if @tree_view is not realized or does not have a model.
10025 * For converting widget coordinates (eg. the ones you get from
10026 * GtkWidget::query-tooltip), please see
10027 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10029 * Return value: %TRUE if a row exists at that coordinate.
10032 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10035 GtkTreePath **path,
10036 PsppSheetViewColumn **column,
10043 g_return_val_if_fail (tree_view != NULL, FALSE);
10050 if (tree_view->priv->bin_window == NULL)
10053 if (tree_view->priv->row_count == 0)
10056 if (x > tree_view->priv->hadjustment->upper)
10059 if (x < 0 || y < 0)
10062 if (column || cell_x)
10064 PsppSheetViewColumn *tmp_column;
10065 PsppSheetViewColumn *last_column = NULL;
10067 gint remaining_x = x;
10068 gboolean found = FALSE;
10071 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10072 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10074 list = (rtl ? list->prev : list->next))
10076 tmp_column = list->data;
10078 if (tmp_column->visible == FALSE)
10081 last_column = tmp_column;
10082 if (remaining_x <= tmp_column->width)
10087 *column = tmp_column;
10090 *cell_x = remaining_x;
10094 remaining_x -= tmp_column->width;
10097 /* If found is FALSE and there is a last_column, then it the remainder
10098 * space is in that area
10105 *column = last_column;
10108 *cell_x = last_column->width + remaining_x;
10117 y_offset = pspp_sheet_view_find_offset (tree_view,
10118 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10125 *cell_y = y_offset;
10128 *path = _pspp_sheet_view_find_path (tree_view, node);
10133 /* Computes 'cell_area' from 'background_area', which must be the background
10134 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10135 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10136 the cell area as passed to _pspp_sheet_view_column_cell_render().
10138 'column' is required to properly adjust 'cell_area->x' and
10139 'cell_area->width'. It may be set to NULL if these values are not of
10140 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10143 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10144 PsppSheetViewColumn *column,
10145 const GdkRectangle *background_area,
10146 gboolean subtract_focus_rect,
10147 GdkRectangle *cell_area)
10149 gint vertical_separator;
10150 gint horizontal_separator;
10152 *cell_area = *background_area;
10154 gtk_widget_style_get (GTK_WIDGET (tree_view),
10155 "vertical-separator", &vertical_separator,
10156 "horizontal-separator", &horizontal_separator,
10158 cell_area->x += horizontal_separator / 2;
10159 cell_area->y += vertical_separator / 2;
10160 cell_area->width -= horizontal_separator;
10161 cell_area->height -= vertical_separator;
10163 if (subtract_focus_rect)
10165 int focus_line_width;
10167 gtk_widget_style_get (GTK_WIDGET (tree_view),
10168 "focus-line-width", &focus_line_width,
10170 cell_area->x += focus_line_width;
10171 cell_area->y += focus_line_width;
10172 cell_area->width -= 2 * focus_line_width;
10173 cell_area->height -= 2 * focus_line_width;
10176 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10178 gint grid_line_width;
10179 gtk_widget_style_get (GTK_WIDGET (tree_view),
10180 "grid-line-width", &grid_line_width,
10183 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10184 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10187 PsppSheetViewColumn *first_column, *last_column;
10190 /* Find the last visible column. */
10191 last_column = NULL;
10192 for (list = g_list_last (tree_view->priv->columns);
10196 PsppSheetViewColumn *c = list->data;
10204 /* Find the first visible column. */
10205 first_column = NULL;
10206 for (list = g_list_first (tree_view->priv->columns);
10210 PsppSheetViewColumn *c = list->data;
10218 if (column == first_column)
10220 cell_area->width -= grid_line_width / 2;
10222 else if (column == last_column)
10224 cell_area->x += grid_line_width / 2;
10225 cell_area->width -= grid_line_width / 2;
10229 cell_area->x += grid_line_width / 2;
10230 cell_area->width -= grid_line_width;
10234 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10235 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10237 cell_area->y += grid_line_width / 2;
10238 cell_area->height -= grid_line_width;
10242 if (column == NULL)
10245 cell_area->width = 0;
10250 * pspp_sheet_view_get_cell_area:
10251 * @tree_view: a #PsppSheetView
10252 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10253 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10254 * @rect: rectangle to fill with cell rect
10256 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10257 * row specified by @path and the column specified by @column. If @path is
10258 * %NULL, or points to a path not currently displayed, the @y and @height fields
10259 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10260 * fields will be filled with 0. The sum of all cell rects does not cover the
10261 * entire tree; there are extra pixels in between rows, for example. The
10262 * returned rectangle is equivalent to the @cell_area passed to
10263 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10267 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10269 PsppSheetViewColumn *column,
10270 GdkRectangle *rect)
10272 GdkRectangle background_area;
10274 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10275 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10276 g_return_if_fail (rect != NULL);
10277 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10278 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10280 pspp_sheet_view_get_background_area (tree_view, path, column,
10282 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10287 * pspp_sheet_view_get_background_area:
10288 * @tree_view: a #PsppSheetView
10289 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10290 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10291 * @rect: rectangle to fill with cell background rect
10293 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10294 * row specified by @path and the column specified by @column. If @path is
10295 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10296 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10297 * fields will be filled with 0. The returned rectangle is equivalent to the
10298 * @background_area passed to gtk_cell_renderer_render(). These background
10299 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10300 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10301 * itself, excluding surrounding borders.
10305 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10307 PsppSheetViewColumn *column,
10308 GdkRectangle *rect)
10312 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10313 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10314 g_return_if_fail (rect != NULL);
10323 /* Get vertical coords */
10325 _pspp_sheet_view_find_node (tree_view, path, &node);
10329 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10331 rect->height = ROW_HEIGHT (tree_view);
10338 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10339 rect->width = x2 - rect->x;
10344 * pspp_sheet_view_get_visible_rect:
10345 * @tree_view: a #PsppSheetView
10346 * @visible_rect: rectangle to fill
10348 * Fills @visible_rect with the currently-visible region of the
10349 * buffer, in tree coordinates. Convert to bin_window coordinates with
10350 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10351 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10352 * scrollable area of the tree.
10355 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10356 GdkRectangle *visible_rect)
10360 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10362 widget = GTK_WIDGET (tree_view);
10366 visible_rect->x = tree_view->priv->hadjustment->value;
10367 visible_rect->y = tree_view->priv->vadjustment->value;
10368 visible_rect->width = widget->allocation.width;
10369 visible_rect->height = widget->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10374 * pspp_sheet_view_widget_to_tree_coords:
10375 * @tree_view: a #PsppSheetView
10376 * @wx: X coordinate relative to bin_window
10377 * @wy: Y coordinate relative to bin_window
10378 * @tx: return location for tree X coordinate
10379 * @ty: return location for tree Y coordinate
10381 * Converts bin_window coordinates to coordinates for the
10382 * tree (the full scrollable area of the tree).
10384 * Deprecated: 2.12: Due to historial reasons the name of this function is
10385 * incorrect. For converting coordinates relative to the widget to
10386 * bin_window coordinates, please see
10387 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10391 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10397 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10400 *tx = wx + tree_view->priv->hadjustment->value;
10402 *ty = wy + tree_view->priv->dy;
10406 * pspp_sheet_view_tree_to_widget_coords:
10407 * @tree_view: a #PsppSheetView
10408 * @tx: tree X coordinate
10409 * @ty: tree Y coordinate
10410 * @wx: return location for X coordinate relative to bin_window
10411 * @wy: return location for Y coordinate relative to bin_window
10413 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10414 * to bin_window coordinates.
10416 * Deprecated: 2.12: Due to historial reasons the name of this function is
10417 * incorrect. For converting bin_window coordinates to coordinates relative
10418 * to bin_window, please see
10419 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10423 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10429 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10432 *wx = tx - tree_view->priv->hadjustment->value;
10434 *wy = ty - tree_view->priv->dy;
10439 * pspp_sheet_view_convert_widget_to_tree_coords:
10440 * @tree_view: a #PsppSheetView
10441 * @wx: X coordinate relative to the widget
10442 * @wy: Y coordinate relative to the widget
10443 * @tx: return location for tree X coordinate
10444 * @ty: return location for tree Y coordinate
10446 * Converts widget coordinates to coordinates for the
10447 * tree (the full scrollable area of the tree).
10452 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10460 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10462 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10465 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10471 * pspp_sheet_view_convert_tree_to_widget_coords:
10472 * @tree_view: a #PsppSheetView
10473 * @tx: X coordinate relative to the tree
10474 * @ty: Y coordinate relative to the tree
10475 * @wx: return location for widget X coordinate
10476 * @wy: return location for widget Y coordinate
10478 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10479 * to widget coordinates.
10484 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10492 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10494 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10497 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10503 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10504 * @tree_view: a #PsppSheetView
10505 * @wx: X coordinate relative to the widget
10506 * @wy: Y coordinate relative to the widget
10507 * @bx: return location for bin_window X coordinate
10508 * @by: return location for bin_window Y coordinate
10510 * Converts widget coordinates to coordinates for the bin_window
10511 * (see pspp_sheet_view_get_bin_window()).
10516 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10522 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10525 *bx = wx + tree_view->priv->hadjustment->value;
10527 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10531 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10532 * @tree_view: a #PsppSheetView
10533 * @bx: bin_window X coordinate
10534 * @by: bin_window Y coordinate
10535 * @wx: return location for widget X coordinate
10536 * @wy: return location for widget Y coordinate
10538 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10539 * to widget relative coordinates.
10544 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10550 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10553 *wx = bx - tree_view->priv->hadjustment->value;
10555 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10559 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10560 * @tree_view: a #PsppSheetView
10561 * @tx: tree X coordinate
10562 * @ty: tree Y coordinate
10563 * @bx: return location for X coordinate relative to bin_window
10564 * @by: return location for Y coordinate relative to bin_window
10566 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10567 * to bin_window coordinates.
10572 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10578 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10583 *by = ty - tree_view->priv->dy;
10587 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10588 * @tree_view: a #PsppSheetView
10589 * @bx: X coordinate relative to bin_window
10590 * @by: Y coordinate relative to bin_window
10591 * @tx: return location for tree X coordinate
10592 * @ty: return location for tree Y coordinate
10594 * Converts bin_window coordinates to coordinates for the
10595 * tree (the full scrollable area of the tree).
10600 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10606 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10611 *ty = by + tree_view->priv->dy;
10617 * pspp_sheet_view_get_visible_range:
10618 * @tree_view: A #PsppSheetView
10619 * @start_path: (allow-none): Return location for start of region, or %NULL.
10620 * @end_path: (allow-none): Return location for end of region, or %NULL.
10622 * Sets @start_path and @end_path to be the first and last visible path.
10623 * Note that there may be invisible paths in between.
10625 * The paths should be freed with gtk_tree_path_free() after use.
10627 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10632 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10633 GtkTreePath **start_path,
10634 GtkTreePath **end_path)
10639 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10641 if (!tree_view->priv->row_count)
10648 pspp_sheet_view_find_offset (tree_view,
10649 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10652 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10661 if (tree_view->priv->height < tree_view->priv->vadjustment->page_size)
10662 y = tree_view->priv->height - 1;
10664 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, tree_view->priv->vadjustment->page_size) - 1;
10666 pspp_sheet_view_find_offset (tree_view, y, &node);
10668 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10677 unset_reorderable (PsppSheetView *tree_view)
10679 if (tree_view->priv->reorderable)
10681 tree_view->priv->reorderable = FALSE;
10682 g_object_notify (G_OBJECT (tree_view), "reorderable");
10687 * pspp_sheet_view_enable_model_drag_source:
10688 * @tree_view: a #PsppSheetView
10689 * @start_button_mask: Mask of allowed buttons to start drag
10690 * @targets: the table of targets that the drag will support
10691 * @n_targets: the number of items in @targets
10692 * @actions: the bitmask of possible actions for a drag from this
10695 * Turns @tree_view into a drag source for automatic DND. Calling this
10696 * method sets #PsppSheetView:reorderable to %FALSE.
10699 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10700 GdkModifierType start_button_mask,
10701 const GtkTargetEntry *targets,
10703 GdkDragAction actions)
10705 TreeViewDragInfo *di;
10707 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10709 gtk_drag_source_set (GTK_WIDGET (tree_view),
10715 di = ensure_info (tree_view);
10717 di->start_button_mask = start_button_mask;
10718 di->source_actions = actions;
10719 di->source_set = TRUE;
10721 unset_reorderable (tree_view);
10725 * pspp_sheet_view_enable_model_drag_dest:
10726 * @tree_view: a #PsppSheetView
10727 * @targets: the table of targets that the drag will support
10728 * @n_targets: the number of items in @targets
10729 * @actions: the bitmask of possible actions for a drag from this
10732 * Turns @tree_view into a drop destination for automatic DND. Calling
10733 * this method sets #PsppSheetView:reorderable to %FALSE.
10736 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
10737 const GtkTargetEntry *targets,
10739 GdkDragAction actions)
10741 TreeViewDragInfo *di;
10743 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10745 gtk_drag_dest_set (GTK_WIDGET (tree_view),
10751 di = ensure_info (tree_view);
10752 di->dest_set = TRUE;
10754 unset_reorderable (tree_view);
10758 * pspp_sheet_view_unset_rows_drag_source:
10759 * @tree_view: a #PsppSheetView
10761 * Undoes the effect of
10762 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
10763 * #PsppSheetView:reorderable to %FALSE.
10766 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
10768 TreeViewDragInfo *di;
10770 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10772 di = get_info (tree_view);
10776 if (di->source_set)
10778 gtk_drag_source_unset (GTK_WIDGET (tree_view));
10779 di->source_set = FALSE;
10782 if (!di->dest_set && !di->source_set)
10783 remove_info (tree_view);
10786 unset_reorderable (tree_view);
10790 * pspp_sheet_view_unset_rows_drag_dest:
10791 * @tree_view: a #PsppSheetView
10793 * Undoes the effect of
10794 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
10795 * #PsppSheetView:reorderable to %FALSE.
10798 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
10800 TreeViewDragInfo *di;
10802 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10804 di = get_info (tree_view);
10810 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
10811 di->dest_set = FALSE;
10814 if (!di->dest_set && !di->source_set)
10815 remove_info (tree_view);
10818 unset_reorderable (tree_view);
10822 * pspp_sheet_view_set_drag_dest_row:
10823 * @tree_view: a #PsppSheetView
10824 * @path: (allow-none): The path of the row to highlight, or %NULL.
10825 * @pos: Specifies whether to drop before, after or into the row
10827 * Sets the row that is highlighted for feedback.
10830 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
10832 PsppSheetViewDropPosition pos)
10834 GtkTreePath *current_dest;
10836 /* Note; this function is exported to allow a custom DND
10837 * implementation, so it can't touch TreeViewDragInfo
10840 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10842 current_dest = NULL;
10844 if (tree_view->priv->drag_dest_row)
10846 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10847 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
10850 /* special case a drop on an empty model */
10851 tree_view->priv->empty_view_drop = 0;
10853 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
10854 && gtk_tree_path_get_depth (path) == 1
10855 && gtk_tree_path_get_indices (path)[0] == 0)
10859 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
10863 tree_view->priv->empty_view_drop = 1;
10866 tree_view->priv->drag_dest_pos = pos;
10870 tree_view->priv->drag_dest_row =
10871 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
10872 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
10875 tree_view->priv->drag_dest_row = NULL;
10879 int node, new_node;
10881 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
10882 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10886 new_node = pspp_sheet_view_node_next (tree_view, node);
10888 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
10890 new_node = pspp_sheet_view_node_prev (tree_view, node);
10892 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
10894 gtk_tree_path_free (current_dest);
10899 * pspp_sheet_view_get_drag_dest_row:
10900 * @tree_view: a #PsppSheetView
10901 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
10902 * @pos: (allow-none): Return location for the drop position, or %NULL
10904 * Gets information about the row that is highlighted for feedback.
10907 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
10908 GtkTreePath **path,
10909 PsppSheetViewDropPosition *pos)
10911 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10915 if (tree_view->priv->drag_dest_row)
10916 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10919 if (tree_view->priv->empty_view_drop)
10920 *path = gtk_tree_path_new_from_indices (0, -1);
10927 *pos = tree_view->priv->drag_dest_pos;
10931 * pspp_sheet_view_get_dest_row_at_pos:
10932 * @tree_view: a #PsppSheetView
10933 * @drag_x: the position to determine the destination row for
10934 * @drag_y: the position to determine the destination row for
10935 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
10936 * @pos: (allow-none): Return location for the drop position, or %NULL
10938 * Determines the destination row for a given position. @drag_x and
10939 * @drag_y are expected to be in widget coordinates. This function is only
10940 * meaningful if @tree_view is realized. Therefore this function will always
10941 * return %FALSE if @tree_view is not realized or does not have a model.
10943 * Return value: whether there is a row at the given position, %TRUE if this
10944 * is indeed the case.
10947 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
10950 GtkTreePath **path,
10951 PsppSheetViewDropPosition *pos)
10955 gdouble offset_into_row;
10958 PsppSheetViewColumn *column = NULL;
10959 GtkTreePath *tmp_path = NULL;
10961 /* Note; this function is exported to allow a custom DND
10962 * implementation, so it can't touch TreeViewDragInfo
10965 g_return_val_if_fail (tree_view != NULL, FALSE);
10966 g_return_val_if_fail (drag_x >= 0, FALSE);
10967 g_return_val_if_fail (drag_y >= 0, FALSE);
10972 if (tree_view->priv->bin_window == NULL)
10975 if (tree_view->priv->row_count == 0)
10978 /* If in the top third of a row, we drop before that row; if
10979 * in the bottom third, drop after that row; if in the middle,
10980 * and the row has children, drop into the row.
10982 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
10985 if (!pspp_sheet_view_get_path_at_pos (tree_view,
10994 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
10997 offset_into_row = cell_y;
11002 gtk_tree_path_free (tmp_path);
11006 third = cell.height / 3.0;
11010 if (offset_into_row < third)
11012 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11014 else if (offset_into_row < (cell.height / 2.0))
11016 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11018 else if (offset_into_row < third * 2.0)
11020 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11024 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11033 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11035 * pspp_sheet_view_create_row_drag_icon:
11036 * @tree_view: a #PsppSheetView
11037 * @path: a #GtkTreePath in @tree_view
11039 * Creates a #GdkPixmap representation of the row at @path.
11040 * This image is used for a drag icon.
11042 * Return value: a newly-allocated pixmap of the drag icon.
11045 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11052 GdkRectangle background_area;
11053 GdkRectangle expose_area;
11056 /* start drawing inside the black outline */
11058 GdkDrawable *drawable;
11059 gint bin_window_width;
11062 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11063 g_return_val_if_fail (path != NULL, NULL);
11065 widget = GTK_WIDGET (tree_view);
11067 if (!gtk_widget_get_realized (widget))
11070 depth = gtk_tree_path_get_depth (path);
11072 _pspp_sheet_view_find_node (tree_view,
11079 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11086 background_area.y = y;
11087 background_area.height = ROW_HEIGHT (tree_view);
11089 gdk_drawable_get_size (tree_view->priv->bin_window,
11090 &bin_window_width, NULL);
11092 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11093 bin_window_width + 2,
11094 background_area.height + 2,
11099 expose_area.width = bin_window_width + 2;
11100 expose_area.height = background_area.height + 2;
11102 gdk_draw_rectangle (drawable,
11103 widget->style->base_gc [gtk_widget_get_state (widget)],
11106 bin_window_width + 2,
11107 background_area.height + 2);
11109 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11111 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11113 list = (rtl ? list->prev : list->next))
11115 PsppSheetViewColumn *column = list->data;
11116 GdkRectangle cell_area;
11117 gint vertical_separator;
11119 if (!column->visible)
11122 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11124 background_area.x = cell_offset;
11125 background_area.width = column->width;
11127 gtk_widget_style_get (widget,
11128 "vertical-separator", &vertical_separator,
11131 cell_area = background_area;
11133 cell_area.y += vertical_separator / 2;
11134 cell_area.height -= vertical_separator;
11136 if (pspp_sheet_view_column_cell_is_visible (column))
11137 _pspp_sheet_view_column_cell_render (column,
11143 cell_offset += column->width;
11146 gdk_draw_rectangle (drawable,
11147 widget->style->black_gc,
11150 bin_window_width + 1,
11151 background_area.height + 1);
11158 * pspp_sheet_view_set_destroy_count_func:
11159 * @tree_view: A #PsppSheetView
11160 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11161 * @data: (allow-none): User data to be passed to @func, or %NULL
11162 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11164 * This function should almost never be used. It is meant for private use by
11165 * ATK for determining the number of visible children that are removed when a row is deleted.
11168 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11169 PsppSheetDestroyCountFunc func,
11171 GDestroyNotify destroy)
11173 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11175 if (tree_view->priv->destroy_count_destroy)
11176 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11178 tree_view->priv->destroy_count_func = func;
11179 tree_view->priv->destroy_count_data = data;
11180 tree_view->priv->destroy_count_destroy = destroy;
11185 * Interactive search
11189 * pspp_sheet_view_set_enable_search:
11190 * @tree_view: A #PsppSheetView
11191 * @enable_search: %TRUE, if the user can search interactively
11193 * If @enable_search is set, then the user can type in text to search through
11194 * the tree interactively (this is sometimes called "typeahead find").
11196 * Note that even if this is %FALSE, the user can still initiate a search
11197 * using the "start-interactive-search" key binding.
11200 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11201 gboolean enable_search)
11203 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11205 enable_search = !!enable_search;
11207 if (tree_view->priv->enable_search != enable_search)
11209 tree_view->priv->enable_search = enable_search;
11210 g_object_notify (G_OBJECT (tree_view), "enable-search");
11215 * pspp_sheet_view_get_enable_search:
11216 * @tree_view: A #PsppSheetView
11218 * Returns whether or not the tree allows to start interactive searching
11219 * by typing in text.
11221 * Return value: whether or not to let the user search interactively
11224 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11226 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11228 return tree_view->priv->enable_search;
11233 * pspp_sheet_view_get_search_column:
11234 * @tree_view: A #PsppSheetView
11236 * Gets the column searched on by the interactive search code.
11238 * Return value: the column the interactive search code searches in.
11241 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11243 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11245 return (tree_view->priv->search_column);
11249 * pspp_sheet_view_set_search_column:
11250 * @tree_view: A #PsppSheetView
11251 * @column: the column of the model to search in, or -1 to disable searching
11253 * Sets @column as the column where the interactive search code should
11254 * search in for the current model.
11256 * If the search column is set, users can use the "start-interactive-search"
11257 * key binding to bring up search popup. The enable-search property controls
11258 * whether simply typing text will also start an interactive search.
11260 * Note that @column refers to a column of the current model. The search
11261 * column is reset to -1 when the model is changed.
11264 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11267 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11268 g_return_if_fail (column >= -1);
11270 if (tree_view->priv->search_column == column)
11273 tree_view->priv->search_column = column;
11274 g_object_notify (G_OBJECT (tree_view), "search-column");
11278 * pspp_sheet_view_get_search_equal_func:
11279 * @tree_view: A #PsppSheetView
11281 * Returns the compare function currently in use.
11283 * Return value: the currently used compare function for the search code.
11286 PsppSheetViewSearchEqualFunc
11287 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11289 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11291 return tree_view->priv->search_equal_func;
11295 * pspp_sheet_view_set_search_equal_func:
11296 * @tree_view: A #PsppSheetView
11297 * @search_equal_func: the compare function to use during the search
11298 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11299 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11301 * Sets the compare function for the interactive search capabilities; note
11302 * that somewhat like strcmp() returning 0 for equality
11303 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11306 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11307 PsppSheetViewSearchEqualFunc search_equal_func,
11308 gpointer search_user_data,
11309 GDestroyNotify search_destroy)
11311 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11312 g_return_if_fail (search_equal_func != NULL);
11314 if (tree_view->priv->search_destroy)
11315 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11317 tree_view->priv->search_equal_func = search_equal_func;
11318 tree_view->priv->search_user_data = search_user_data;
11319 tree_view->priv->search_destroy = search_destroy;
11320 if (tree_view->priv->search_equal_func == NULL)
11321 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11325 * pspp_sheet_view_get_search_entry:
11326 * @tree_view: A #PsppSheetView
11328 * Returns the #GtkEntry which is currently in use as interactive search
11329 * entry for @tree_view. In case the built-in entry is being used, %NULL
11330 * will be returned.
11332 * Return value: the entry currently in use as search entry.
11337 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11339 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11341 if (tree_view->priv->search_custom_entry_set)
11342 return GTK_ENTRY (tree_view->priv->search_entry);
11348 * pspp_sheet_view_set_search_entry:
11349 * @tree_view: A #PsppSheetView
11350 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11352 * Sets the entry which the interactive search code will use for this
11353 * @tree_view. This is useful when you want to provide a search entry
11354 * in our interface at all time at a fixed position. Passing %NULL for
11355 * @entry will make the interactive search code use the built-in popup
11361 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11364 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11365 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11367 if (tree_view->priv->search_custom_entry_set)
11369 if (tree_view->priv->search_entry_changed_id)
11371 g_signal_handler_disconnect (tree_view->priv->search_entry,
11372 tree_view->priv->search_entry_changed_id);
11373 tree_view->priv->search_entry_changed_id = 0;
11375 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11376 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11379 g_object_unref (tree_view->priv->search_entry);
11381 else if (tree_view->priv->search_window)
11383 gtk_widget_destroy (tree_view->priv->search_window);
11385 tree_view->priv->search_window = NULL;
11390 tree_view->priv->search_entry = g_object_ref (entry);
11391 tree_view->priv->search_custom_entry_set = TRUE;
11393 if (tree_view->priv->search_entry_changed_id == 0)
11395 tree_view->priv->search_entry_changed_id =
11396 g_signal_connect (tree_view->priv->search_entry, "changed",
11397 G_CALLBACK (pspp_sheet_view_search_init),
11401 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11402 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11405 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11409 tree_view->priv->search_entry = NULL;
11410 tree_view->priv->search_custom_entry_set = FALSE;
11415 * pspp_sheet_view_set_search_position_func:
11416 * @tree_view: A #PsppSheetView
11417 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11418 * to use the default search position function
11419 * @data: (allow-none): user data to pass to @func, or %NULL
11420 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11422 * Sets the function to use when positioning the search dialog.
11427 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11428 PsppSheetViewSearchPositionFunc func,
11429 gpointer user_data,
11430 GDestroyNotify destroy)
11432 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11434 if (tree_view->priv->search_position_destroy)
11435 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11437 tree_view->priv->search_position_func = func;
11438 tree_view->priv->search_position_user_data = user_data;
11439 tree_view->priv->search_position_destroy = destroy;
11440 if (tree_view->priv->search_position_func == NULL)
11441 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11445 * pspp_sheet_view_get_search_position_func:
11446 * @tree_view: A #PsppSheetView
11448 * Returns the positioning function currently in use.
11450 * Return value: the currently used function for positioning the search dialog.
11454 PsppSheetViewSearchPositionFunc
11455 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11457 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11459 return tree_view->priv->search_position_func;
11464 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11465 PsppSheetView *tree_view)
11467 if (tree_view->priv->disable_popdown)
11470 if (tree_view->priv->search_entry_changed_id)
11472 g_signal_handler_disconnect (tree_view->priv->search_entry,
11473 tree_view->priv->search_entry_changed_id);
11474 tree_view->priv->search_entry_changed_id = 0;
11476 if (tree_view->priv->typeselect_flush_timeout)
11478 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11479 tree_view->priv->typeselect_flush_timeout = 0;
11482 if (gtk_widget_get_visible (search_dialog))
11484 /* send focus-in event */
11485 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11486 gtk_widget_hide (search_dialog);
11487 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11488 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11493 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11494 GtkWidget *search_dialog,
11495 gpointer user_data)
11498 gint tree_x, tree_y;
11499 gint tree_width, tree_height;
11500 GdkWindow *tree_window = GTK_WIDGET (tree_view)->window;
11501 GdkScreen *screen = gdk_drawable_get_screen (tree_window);
11502 GtkRequisition requisition;
11504 GdkRectangle monitor;
11506 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11507 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11509 gtk_widget_realize (search_dialog);
11511 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11512 gdk_drawable_get_size (tree_window,
11515 gtk_widget_size_request (search_dialog, &requisition);
11517 if (tree_x + tree_width > gdk_screen_get_width (screen))
11518 x = gdk_screen_get_width (screen) - requisition.width;
11519 else if (tree_x + tree_width - requisition.width < 0)
11522 x = tree_x + tree_width - requisition.width;
11524 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11525 y = gdk_screen_get_height (screen) - requisition.height;
11526 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11529 y = tree_y + tree_height;
11531 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11535 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11539 PsppSheetView *tree_view = (PsppSheetView *)data;
11541 tree_view->priv->disable_popdown = 1;
11542 g_signal_connect (menu, "hide",
11543 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11546 /* Because we're visible but offscreen, we just set a flag in the preedit
11550 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11551 PsppSheetView *tree_view)
11553 tree_view->priv->imcontext_changed = 1;
11554 if (tree_view->priv->typeselect_flush_timeout)
11556 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11557 tree_view->priv->typeselect_flush_timeout =
11558 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11559 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11566 pspp_sheet_view_search_activate (GtkEntry *entry,
11567 PsppSheetView *tree_view)
11572 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11575 /* If we have a row selected and it's the cursor row, we activate
11577 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11579 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11581 _pspp_sheet_view_find_node (tree_view, path, &node);
11583 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11584 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11586 gtk_tree_path_free (path);
11591 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11593 PsppSheetView *tree_view = (PsppSheetView *)data;
11595 tree_view->priv->disable_popdown = 0;
11601 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11604 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11608 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11609 GdkEventAny *event,
11610 PsppSheetView *tree_view)
11612 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11614 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11620 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11621 GdkEventButton *event,
11622 PsppSheetView *tree_view)
11624 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11626 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11628 if (event->window == tree_view->priv->bin_window)
11629 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11635 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11636 GdkEventScroll *event,
11637 PsppSheetView *tree_view)
11639 gboolean retval = FALSE;
11641 if (event->direction == GDK_SCROLL_UP)
11643 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11646 else if (event->direction == GDK_SCROLL_DOWN)
11648 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11652 /* renew the flush timeout */
11653 if (retval && tree_view->priv->typeselect_flush_timeout
11654 && !tree_view->priv->search_custom_entry_set)
11656 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11657 tree_view->priv->typeselect_flush_timeout =
11658 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11659 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11667 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11668 GdkEventKey *event,
11669 PsppSheetView *tree_view)
11671 gboolean retval = FALSE;
11673 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11674 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11676 /* close window and cancel the search */
11677 if (!tree_view->priv->search_custom_entry_set
11678 && (event->keyval == GDK_Escape ||
11679 event->keyval == GDK_Tab ||
11680 event->keyval == GDK_KP_Tab ||
11681 event->keyval == GDK_ISO_Left_Tab))
11683 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11687 /* select previous matching iter */
11688 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11690 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11691 gtk_widget_error_bell (widget);
11696 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11697 && (event->keyval == GDK_g || event->keyval == GDK_G))
11699 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11700 gtk_widget_error_bell (widget);
11705 /* select next matching iter */
11706 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
11708 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11709 gtk_widget_error_bell (widget);
11714 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
11715 && (event->keyval == GDK_g || event->keyval == GDK_G))
11717 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11718 gtk_widget_error_bell (widget);
11723 /* renew the flush timeout */
11724 if (retval && tree_view->priv->typeselect_flush_timeout
11725 && !tree_view->priv->search_custom_entry_set)
11727 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11728 tree_view->priv->typeselect_flush_timeout =
11729 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11730 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11737 /* this function returns FALSE if there is a search string but
11738 * nothing was found, and TRUE otherwise.
11741 pspp_sheet_view_search_move (GtkWidget *window,
11742 PsppSheetView *tree_view,
11750 GtkTreeModel *model;
11751 PsppSheetSelection *selection;
11753 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
11755 g_return_val_if_fail (text != NULL, FALSE);
11757 len = strlen (text);
11759 if (up && tree_view->priv->selected_iter == 1)
11760 return strlen (text) < 1;
11762 len = strlen (text);
11767 model = pspp_sheet_view_get_model (tree_view);
11768 selection = pspp_sheet_view_get_selection (tree_view);
11771 pspp_sheet_selection_unselect_all (selection);
11772 if (!gtk_tree_model_get_iter_first (model, &iter))
11775 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
11776 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
11781 tree_view->priv->selected_iter += up?(-1):(1);
11786 /* return to old iter */
11788 gtk_tree_model_get_iter_first (model, &iter);
11789 pspp_sheet_view_search_iter (model, selection,
11791 &count, tree_view->priv->selected_iter);
11797 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
11801 gpointer search_data)
11803 gboolean retval = TRUE;
11805 gchar *normalized_string;
11806 gchar *normalized_key;
11807 gchar *case_normalized_string = NULL;
11808 gchar *case_normalized_key = NULL;
11809 GValue value = {0,};
11810 GValue transformed = {0,};
11812 gtk_tree_model_get_value (model, iter, column, &value);
11814 g_value_init (&transformed, G_TYPE_STRING);
11816 if (!g_value_transform (&value, &transformed))
11818 g_value_unset (&value);
11822 g_value_unset (&value);
11824 str = g_value_get_string (&transformed);
11827 g_value_unset (&transformed);
11831 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
11832 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
11834 if (normalized_string && normalized_key)
11836 case_normalized_string = g_utf8_casefold (normalized_string, -1);
11837 case_normalized_key = g_utf8_casefold (normalized_key, -1);
11839 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
11843 g_value_unset (&transformed);
11844 g_free (normalized_key);
11845 g_free (normalized_string);
11846 g_free (case_normalized_key);
11847 g_free (case_normalized_string);
11853 pspp_sheet_view_search_iter (GtkTreeModel *model,
11854 PsppSheetSelection *selection,
11863 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
11865 path = gtk_tree_model_get_path (model, iter);
11866 _pspp_sheet_view_find_node (tree_view, path, &node);
11870 gboolean done = FALSE;
11872 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
11877 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
11879 pspp_sheet_selection_select_iter (selection, iter);
11880 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
11883 gtk_tree_path_free (path);
11892 node = pspp_sheet_view_node_next (tree_view, node);
11898 has_next = gtk_tree_model_iter_next (model, iter);
11901 gtk_tree_path_next (path);
11904 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
11909 gtk_tree_path_free (path);
11911 /* we've run out of tree, done with this func */
11923 pspp_sheet_view_search_init (GtkWidget *entry,
11924 PsppSheetView *tree_view)
11930 GtkTreeModel *model;
11931 PsppSheetSelection *selection;
11933 g_return_if_fail (GTK_IS_ENTRY (entry));
11934 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11936 text = gtk_entry_get_text (GTK_ENTRY (entry));
11938 model = pspp_sheet_view_get_model (tree_view);
11939 selection = pspp_sheet_view_get_selection (tree_view);
11942 pspp_sheet_selection_unselect_all (selection);
11943 if (tree_view->priv->typeselect_flush_timeout
11944 && !tree_view->priv->search_custom_entry_set)
11946 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11947 tree_view->priv->typeselect_flush_timeout =
11948 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11949 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11956 if (!gtk_tree_model_get_iter_first (model, &iter))
11959 ret = pspp_sheet_view_search_iter (model, selection,
11964 tree_view->priv->selected_iter = 1;
11968 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
11969 PsppSheetView *tree_view)
11971 if (tree_view->priv->edited_column == NULL)
11974 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
11975 tree_view->priv->edited_column = NULL;
11977 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
11978 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
11980 g_signal_handlers_disconnect_by_func (cell_editable,
11981 pspp_sheet_view_remove_widget,
11983 g_signal_handlers_disconnect_by_func (cell_editable,
11984 pspp_sheet_view_editable_button_press_event,
11986 g_signal_handlers_disconnect_by_func (cell_editable,
11987 pspp_sheet_view_editable_clicked,
11990 gtk_container_remove (GTK_CONTAINER (tree_view),
11991 GTK_WIDGET (cell_editable));
11993 /* FIXME should only redraw a single node */
11994 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
11998 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
11999 GtkTreePath *cursor_path)
12002 GdkRectangle background_area;
12003 GdkRectangle cell_area;
12004 GtkCellEditable *editable_widget = NULL;
12005 gchar *path_string;
12006 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
12007 gint retval = FALSE;
12010 g_assert (tree_view->priv->focus_column);
12012 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12015 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12016 if (cursor_node < 0)
12019 path_string = gtk_tree_path_to_string (cursor_path);
12020 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12022 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12023 tree_view->priv->model,
12025 pspp_sheet_view_get_background_area (tree_view,
12027 tree_view->priv->focus_column,
12029 pspp_sheet_view_get_cell_area (tree_view,
12031 tree_view->priv->focus_column,
12034 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12043 if (editable_widget != NULL)
12047 GtkCellRenderer *cell;
12050 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12052 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12055 area.width -= right + left;
12057 pspp_sheet_view_real_start_editing (tree_view,
12058 tree_view->priv->focus_column,
12067 g_free (path_string);
12072 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12073 GdkEventButton *event,
12074 PsppSheetView *sheet_view)
12078 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12079 "pspp-sheet-view-node"));
12080 return pspp_sheet_view_row_head_clicked (sheet_view,
12082 sheet_view->priv->edited_column,
12087 pspp_sheet_view_editable_clicked (GtkButton *button,
12088 PsppSheetView *sheet_view)
12090 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12095 is_all_selected (GtkWidget *widget)
12097 GtkEntryBuffer *buffer;
12098 gint start_pos, end_pos;
12100 if (!GTK_IS_ENTRY (widget))
12103 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12104 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12105 &start_pos, &end_pos)
12107 && end_pos == gtk_entry_buffer_get_length (buffer));
12111 is_at_left (GtkWidget *widget)
12113 return (GTK_IS_ENTRY (widget)
12114 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12118 is_at_right (GtkWidget *widget)
12120 GtkEntryBuffer *buffer;
12123 if (!GTK_IS_ENTRY (widget))
12126 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12127 length = gtk_entry_buffer_get_length (buffer);
12128 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12132 pspp_sheet_view_event (GtkWidget *widget,
12133 GdkEventKey *event,
12134 PsppSheetView *tree_view)
12136 PsppSheetViewColumn *column;
12144 /* Intercept only key press events.
12145 It would make sense to use "key-press-event" instead of "event", but
12146 GtkEntry attaches its own signal handler to "key-press-event" that runs
12147 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12149 if (event->type != GDK_KEY_PRESS)
12152 if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12154 /* Pass through most keys that include modifiers. */
12155 if ((event->keyval == GDK_Tab || event->keyval == GDK_ISO_Left_Tab)
12156 && !(event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK)))
12158 /* Special case for Shift-Tab. */
12164 keyval = event->keyval;
12165 state = event->state & ~(GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK);
12167 switch (event->keyval)
12169 case GDK_Left: case GDK_KP_Left:
12170 if (!is_all_selected (widget) && !is_at_left (widget))
12174 case GDK_Right: case GDK_KP_Right:
12175 if (!is_all_selected (widget) && !is_at_right (widget))
12179 case GDK_Up: case GDK_KP_Up:
12180 case GDK_Down: case GDK_KP_Down:
12183 case GDK_Page_Up: case GDK_KP_Page_Up:
12184 case GDK_Page_Down: case GDK_KP_Page_Down:
12196 case GDK_ISO_Left_Tab:
12197 keyval = event->state & GDK_SHIFT_MASK ? GDK_Left : GDK_Right;
12204 row = tree_view->priv->edited_row;
12205 column = tree_view->priv->edited_column;
12206 path = gtk_tree_path_new_from_indices (row, -1);
12208 pspp_sheet_view_stop_editing (tree_view, cancel);
12209 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12211 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12212 gtk_tree_path_free (path);
12214 handled = gtk_binding_set_activate (edit_bindings, keyval, state,
12215 GTK_OBJECT (tree_view));
12217 g_signal_stop_emission_by_name (widget, "event");
12219 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12220 pspp_sheet_view_start_editing (tree_view, path);
12221 gtk_tree_path_free (path);
12227 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12230 PsppSheetView *sheet_view = data;
12232 g_signal_connect (widget, "event",
12233 G_CALLBACK (pspp_sheet_view_event),
12236 if (GTK_IS_CONTAINER (widget))
12237 gtk_container_foreach (GTK_CONTAINER (widget),
12238 pspp_sheet_view_override_cell_keypresses,
12243 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12244 PsppSheetViewColumn *column,
12246 GtkCellEditable *cell_editable,
12247 GdkRectangle *cell_area,
12251 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12252 gint pre_val = tree_view->priv->vadjustment->value;
12253 GtkRequisition requisition;
12256 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12258 tree_view->priv->edited_column = column;
12259 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12261 row = gtk_tree_path_get_indices (path)[0];
12262 tree_view->priv->edited_row = row;
12263 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
12264 cell_area->y += pre_val - (int)tree_view->priv->vadjustment->value;
12266 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12267 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12268 tree_view->priv->anchor_column = column;
12270 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12272 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12274 if (requisition.height < cell_area->height)
12276 gint diff = cell_area->height - requisition.height;
12277 pspp_sheet_view_put (tree_view,
12278 GTK_WIDGET (cell_editable),
12279 cell_area->x, cell_area->y + diff/2,
12280 cell_area->width, requisition.height);
12284 pspp_sheet_view_put (tree_view,
12285 GTK_WIDGET (cell_editable),
12286 cell_area->x, cell_area->y,
12287 cell_area->width, cell_area->height);
12290 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12291 (GdkEvent *)event);
12293 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12294 g_signal_connect (cell_editable, "remove-widget",
12295 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12296 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12297 GTK_IS_BUTTON (cell_editable))
12299 g_signal_connect (cell_editable, "button-press-event",
12300 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12302 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12303 GINT_TO_POINTER (row));
12304 g_signal_connect (cell_editable, "clicked",
12305 G_CALLBACK (pspp_sheet_view_editable_clicked),
12309 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12314 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12315 gboolean cancel_editing)
12317 PsppSheetViewColumn *column;
12318 GtkCellRenderer *cell;
12320 if (tree_view->priv->edited_column == NULL)
12324 * This is very evil. We need to do this, because
12325 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12326 * later on. If pspp_sheet_view_row_changed notices
12327 * tree_view->priv->edited_column != NULL, it'll call
12328 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12330 * Please read that again if you intend to modify anything here.
12333 column = tree_view->priv->edited_column;
12334 tree_view->priv->edited_column = NULL;
12336 cell = _pspp_sheet_view_column_get_edited_cell (column);
12337 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12339 if (!cancel_editing)
12340 gtk_cell_editable_editing_done (column->editable_widget);
12342 tree_view->priv->edited_column = column;
12344 gtk_cell_editable_remove_widget (column->editable_widget);
12349 * pspp_sheet_view_set_hover_selection:
12350 * @tree_view: a #PsppSheetView
12351 * @hover: %TRUE to enable hover selection mode
12353 * Enables of disables the hover selection mode of @tree_view.
12354 * Hover selection makes the selected row follow the pointer.
12355 * Currently, this works only for the selection modes
12356 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12361 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12364 hover = hover != FALSE;
12366 if (hover != tree_view->priv->hover_selection)
12368 tree_view->priv->hover_selection = hover;
12370 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12375 * pspp_sheet_view_get_hover_selection:
12376 * @tree_view: a #PsppSheetView
12378 * Returns whether hover selection mode is turned on for @tree_view.
12380 * Return value: %TRUE if @tree_view is in hover selection mode
12385 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12387 return tree_view->priv->hover_selection;
12391 * pspp_sheet_view_set_rubber_banding:
12392 * @tree_view: a #PsppSheetView
12393 * @enable: %TRUE to enable rubber banding
12395 * Enables or disables rubber banding in @tree_view. If the selection mode is
12396 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12397 * banding will allow the user to select multiple rows by dragging the mouse.
12402 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12405 enable = enable != FALSE;
12407 if (enable != tree_view->priv->rubber_banding_enable)
12409 tree_view->priv->rubber_banding_enable = enable;
12411 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12416 * pspp_sheet_view_get_rubber_banding:
12417 * @tree_view: a #PsppSheetView
12419 * Returns whether rubber banding is turned on for @tree_view. If the
12420 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12421 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12422 * select multiple rows by dragging the mouse.
12424 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12429 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12431 return tree_view->priv->rubber_banding_enable;
12435 * pspp_sheet_view_is_rubber_banding_active:
12436 * @tree_view: a #PsppSheetView
12438 * Returns whether a rubber banding operation is currently being done
12441 * Return value: %TRUE if a rubber banding operation is currently being
12442 * done in @tree_view.
12447 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12449 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12451 if (tree_view->priv->rubber_banding_enable
12452 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12459 pspp_sheet_view_grab_notify (GtkWidget *widget,
12460 gboolean was_grabbed)
12462 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12464 tree_view->priv->in_grab = !was_grabbed;
12468 tree_view->priv->pressed_button = -1;
12470 if (tree_view->priv->rubber_band_status)
12471 pspp_sheet_view_stop_rubber_band (tree_view);
12476 pspp_sheet_view_state_changed (GtkWidget *widget,
12477 GtkStateType previous_state)
12479 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12481 if (gtk_widget_get_realized (widget))
12483 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
12484 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
12487 gtk_widget_queue_draw (widget);
12491 * pspp_sheet_view_get_grid_lines:
12492 * @tree_view: a #PsppSheetView
12494 * Returns which grid lines are enabled in @tree_view.
12496 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12501 PsppSheetViewGridLines
12502 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12504 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12506 return tree_view->priv->grid_lines;
12510 * pspp_sheet_view_set_grid_lines:
12511 * @tree_view: a #PsppSheetView
12512 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12515 * Sets which grid lines to draw in @tree_view.
12520 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12521 PsppSheetViewGridLines grid_lines)
12523 PsppSheetViewPrivate *priv;
12525 PsppSheetViewGridLines old_grid_lines;
12527 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12529 priv = tree_view->priv;
12530 widget = GTK_WIDGET (tree_view);
12532 old_grid_lines = priv->grid_lines;
12533 priv->grid_lines = grid_lines;
12535 if (old_grid_lines != grid_lines)
12537 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12539 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12544 * pspp_sheet_view_get_special_cells:
12545 * @tree_view: a #PsppSheetView
12547 * Returns which grid lines are enabled in @tree_view.
12549 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12550 * the sheet view contain special cells.
12552 PsppSheetViewSpecialCells
12553 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12555 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12557 return tree_view->priv->special_cells;
12561 * pspp_sheet_view_set_special_cells:
12562 * @tree_view: a #PsppSheetView
12563 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12564 * the sheet view contain special cells.
12566 * Sets whether rows in the sheet view contain special cells, controlling the
12567 * rendering of row selections.
12570 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12571 PsppSheetViewSpecialCells special_cells)
12573 PsppSheetViewPrivate *priv;
12576 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12578 priv = tree_view->priv;
12579 widget = GTK_WIDGET (tree_view);
12581 if (priv->special_cells != special_cells)
12583 priv->special_cells = special_cells;
12584 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12585 g_object_notify (G_OBJECT (tree_view), "special-cells");
12590 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12592 /* XXX (re)calculate fixed_height if necessary */
12593 return tree_view->priv->fixed_height;
12597 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12600 g_return_if_fail (fixed_height > 0);
12602 if (tree_view->priv->fixed_height != fixed_height)
12604 tree_view->priv->fixed_height = fixed_height;
12605 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12607 if (!tree_view->priv->fixed_height_set)
12609 tree_view->priv->fixed_height_set = TRUE;
12610 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12615 * pspp_sheet_view_set_tooltip_row:
12616 * @tree_view: a #PsppSheetView
12617 * @tooltip: a #GtkTooltip
12618 * @path: a #GtkTreePath
12620 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12621 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12622 * See also gtk_tooltip_set_tip_area().
12627 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12628 GtkTooltip *tooltip,
12631 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12632 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12634 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12638 * pspp_sheet_view_set_tooltip_cell:
12639 * @tree_view: a #PsppSheetView
12640 * @tooltip: a #GtkTooltip
12641 * @path: (allow-none): a #GtkTreePath or %NULL
12642 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12643 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12645 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12646 * in common. For example if @path is %NULL and @column is set, the tip
12647 * area will be set to the full area covered by @column. See also
12648 * gtk_tooltip_set_tip_area().
12650 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12655 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12656 GtkTooltip *tooltip,
12658 PsppSheetViewColumn *column,
12659 GtkCellRenderer *cell)
12663 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12664 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12665 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12666 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12668 /* Determine x values. */
12669 if (column && cell)
12674 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12675 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12677 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12680 rect.width = width;
12686 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
12687 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12690 rect.width = tmp.width;
12695 rect.width = GTK_WIDGET (tree_view)->allocation.width;
12698 /* Determine y values. */
12703 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
12704 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12707 rect.height = tmp.height;
12712 rect.height = tree_view->priv->vadjustment->page_size;
12715 gtk_tooltip_set_tip_area (tooltip, &rect);
12719 * pspp_sheet_view_get_tooltip_context:
12720 * @tree_view: a #PsppSheetView
12721 * @x: the x coordinate (relative to widget coordinates)
12722 * @y: the y coordinate (relative to widget coordinates)
12723 * @keyboard_tip: whether this is a keyboard tooltip or not
12724 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
12725 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
12726 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
12728 * This function is supposed to be used in a #GtkWidget::query-tooltip
12729 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
12730 * which are received in the signal handler, should be passed to this
12731 * function without modification.
12733 * The return value indicates whether there is a tree view row at the given
12734 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
12735 * tooltips the row returned will be the cursor row. When %TRUE, then any of
12736 * @model, @path and @iter which have been provided will be set to point to
12737 * that row and the corresponding model. @x and @y will always be converted
12738 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
12740 * Return value: whether or not the given tooltip context points to a row.
12745 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
12748 gboolean keyboard_tip,
12749 GtkTreeModel **model,
12750 GtkTreePath **path,
12753 GtkTreePath *tmppath = NULL;
12755 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12756 g_return_val_if_fail (x != NULL, FALSE);
12757 g_return_val_if_fail (y != NULL, FALSE);
12761 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
12768 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
12771 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
12772 &tmppath, NULL, NULL, NULL))
12777 *model = pspp_sheet_view_get_model (tree_view);
12780 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
12786 gtk_tree_path_free (tmppath);
12792 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
12795 gboolean keyboard_tip,
12796 GtkTooltip *tooltip,
12799 GValue value = { 0, };
12800 GValue transformed = { 0, };
12803 GtkTreeModel *model;
12804 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12806 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
12809 &model, &path, &iter))
12812 gtk_tree_model_get_value (model, &iter,
12813 tree_view->priv->tooltip_column, &value);
12815 g_value_init (&transformed, G_TYPE_STRING);
12817 if (!g_value_transform (&value, &transformed))
12819 g_value_unset (&value);
12820 gtk_tree_path_free (path);
12825 g_value_unset (&value);
12827 if (!g_value_get_string (&transformed))
12829 g_value_unset (&transformed);
12830 gtk_tree_path_free (path);
12835 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
12836 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
12838 gtk_tree_path_free (path);
12839 g_value_unset (&transformed);
12845 * pspp_sheet_view_set_tooltip_column:
12846 * @tree_view: a #PsppSheetView
12847 * @column: an integer, which is a valid column number for @tree_view's model
12849 * If you only plan to have simple (text-only) tooltips on full rows, you
12850 * can use this function to have #PsppSheetView handle these automatically
12851 * for you. @column should be set to the column in @tree_view's model
12852 * containing the tooltip texts, or -1 to disable this feature.
12854 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
12855 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
12857 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
12858 * so &, <, etc have to be escaped in the text.
12863 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
12866 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12868 if (column == tree_view->priv->tooltip_column)
12873 g_signal_handlers_disconnect_by_func (tree_view,
12874 pspp_sheet_view_set_tooltip_query_cb,
12876 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
12880 if (tree_view->priv->tooltip_column == -1)
12882 g_signal_connect (tree_view, "query-tooltip",
12883 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
12884 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
12888 tree_view->priv->tooltip_column = column;
12889 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
12893 * pspp_sheet_view_get_tooltip_column:
12894 * @tree_view: a #PsppSheetView
12896 * Returns the column of @tree_view's model which is being used for
12897 * displaying tooltips on @tree_view's rows.
12899 * Return value: the index of the tooltip column that is currently being
12900 * used, or -1 if this is disabled.
12905 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
12907 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12909 return tree_view->priv->tooltip_column;
12913 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
12914 GValue *return_accu,
12915 const GValue *handler_return,
12918 gboolean continue_emission;
12919 gboolean signal_handled;
12921 signal_handled = g_value_get_boolean (handler_return);
12922 g_value_set_boolean (return_accu, signal_handled);
12923 continue_emission = !signal_handled;
12925 return continue_emission;
12929 pspp_sheet_view_grid_lines_get_type (void)
12931 static GType etype = 0;
12932 if (G_UNLIKELY(etype == 0)) {
12933 static const GEnumValue values[] = {
12934 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
12935 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
12936 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
12937 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
12940 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
12946 pspp_sheet_view_special_cells_get_type (void)
12948 static GType etype = 0;
12949 if (G_UNLIKELY(etype == 0)) {
12950 static const GEnumValue values[] = {
12951 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
12952 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
12953 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
12956 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);