1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011, 2012, 2013 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Library General Public
22 * License as published by the Free Software Foundation; either
23 * version 2 of the License, or (at your option) any later version.
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Library General Public License for more details.
30 * You should have received a copy of the GNU Library General Public
31 * License along with this library; if not, write to the
32 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
33 * Boston, MA 02111-1307, USA.
38 #include "ui/gui/pspp-sheet-private.h"
42 #include <gdk/gdkkeysyms.h>
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 PsppSheetSelectMode mode);
261 static gboolean pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view);
262 static void pspp_sheet_view_row_changed (GtkTreeModel *model,
266 static void pspp_sheet_view_row_inserted (GtkTreeModel *model,
270 static void pspp_sheet_view_row_deleted (GtkTreeModel *model,
273 static void pspp_sheet_view_rows_reordered (GtkTreeModel *model,
279 /* Incremental reflow */
280 static gint validate_row (PsppSheetView *tree_view,
284 static void validate_visible_area (PsppSheetView *tree_view);
285 static gboolean validate_rows_handler (PsppSheetView *tree_view);
286 static gboolean presize_handler_callback (gpointer data);
287 static void install_presize_handler (PsppSheetView *tree_view);
288 static void install_scroll_sync_handler (PsppSheetView *tree_view);
289 static void pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
292 static void pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view);
293 static void pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view);
294 static void invalidate_empty_focus (PsppSheetView *tree_view);
296 /* Internal functions */
297 static void pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
300 gboolean add_shifted_binding,
301 GtkMovementStep step,
303 static void pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
305 const GdkRectangle *clip_rect);
306 static gint pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
309 static void pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
310 PsppSheetView *tree_view);
311 static void pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
313 static void pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
314 PsppSheetViewColumn *column,
315 gboolean focus_to_cell);
316 static gboolean pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
317 GdkEventMotion *event);
318 static void pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view);
319 static gboolean pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
321 PsppSheetSelectMode mode);
322 static void pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
324 PsppSheetSelectMode mode);
325 static void pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
327 PsppSheetSelectMode mode);
328 static void pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
330 PsppSheetSelectMode mode);
331 static void pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
333 static void pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
335 PsppSheetSelectMode mode);
336 static void pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
338 gboolean clear_and_select,
340 PsppSheetSelectMode mode);
341 static gboolean pspp_sheet_view_has_special_cell (PsppSheetView *tree_view);
342 static void pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view);
343 static void update_prelight (PsppSheetView *tree_view,
346 static void initialize_fixed_height_mode (PsppSheetView *tree_view);
348 /* interactive search */
349 static void pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view);
350 static void pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
351 PsppSheetView *tree_view);
352 static void pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
353 GtkWidget *search_dialog,
355 static void pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
358 static void pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
359 PsppSheetView *tree_view);
360 static void pspp_sheet_view_search_activate (GtkEntry *entry,
361 PsppSheetView *tree_view);
362 static gboolean pspp_sheet_view_real_search_enable_popdown(gpointer data);
363 static void pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
365 static gboolean pspp_sheet_view_search_delete_event (GtkWidget *widget,
367 PsppSheetView *tree_view);
368 static gboolean pspp_sheet_view_search_button_press_event (GtkWidget *widget,
369 GdkEventButton *event,
370 PsppSheetView *tree_view);
371 static gboolean pspp_sheet_view_search_scroll_event (GtkWidget *entry,
372 GdkEventScroll *event,
373 PsppSheetView *tree_view);
374 static gboolean pspp_sheet_view_search_key_press_event (GtkWidget *entry,
376 PsppSheetView *tree_view);
377 static gboolean pspp_sheet_view_search_move (GtkWidget *window,
378 PsppSheetView *tree_view,
380 static gboolean pspp_sheet_view_search_equal_func (GtkTreeModel *model,
384 gpointer search_data);
385 static gboolean pspp_sheet_view_search_iter (GtkTreeModel *model,
386 PsppSheetSelection *selection,
391 static void pspp_sheet_view_search_init (GtkWidget *entry,
392 PsppSheetView *tree_view);
393 static void pspp_sheet_view_put (PsppSheetView *tree_view,
394 GtkWidget *child_widget,
399 static gboolean pspp_sheet_view_start_editing (PsppSheetView *tree_view,
400 GtkTreePath *cursor_path);
401 static gboolean pspp_sheet_view_editable_button_press_event (GtkWidget *,
404 static void pspp_sheet_view_editable_clicked (GtkButton *, PsppSheetView *);
405 static void pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
406 PsppSheetViewColumn *column,
408 GtkCellEditable *cell_editable,
409 GdkRectangle *cell_area,
412 static gboolean pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
413 gboolean keybinding);
414 static gboolean pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view);
415 static PsppSheetViewColumn *pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
416 PsppSheetViewColumn *column,
419 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
420 PsppSheetViewColumn *column,
421 const GdkRectangle *background_area,
422 gboolean subtract_focus_rect,
423 GdkRectangle *cell_area);
424 static gint pspp_sheet_view_find_offset (PsppSheetView *tree_view,
429 static void pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
433 static void pspp_sheet_view_buildable_init (GtkBuildableIface *iface);
436 static gboolean scroll_row_timeout (gpointer data);
437 static void add_scroll_timeout (PsppSheetView *tree_view);
438 static void remove_scroll_timeout (PsppSheetView *tree_view);
440 static guint tree_view_signals [LAST_SIGNAL] = { 0 };
442 static GtkBindingSet *edit_bindings;
449 G_DEFINE_TYPE_WITH_CODE (PsppSheetView, pspp_sheet_view, GTK_TYPE_CONTAINER,
450 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
451 pspp_sheet_view_buildable_init))
454 pspp_sheet_view_class_init (PsppSheetViewClass *class)
456 GObjectClass *o_class;
457 GtkWidgetClass *widget_class;
458 GtkContainerClass *container_class;
459 GtkBindingSet *binding_set[2];
462 binding_set[0] = gtk_binding_set_by_class (class);
464 binding_set[1] = gtk_binding_set_new ("PsppSheetViewEditing");
465 edit_bindings = binding_set[1];
467 o_class = (GObjectClass *) class;
468 widget_class = (GtkWidgetClass *) class;
469 container_class = (GtkContainerClass *) class;
471 /* GObject signals */
472 o_class->set_property = pspp_sheet_view_set_property;
473 o_class->get_property = pspp_sheet_view_get_property;
474 o_class->finalize = pspp_sheet_view_finalize;
475 o_class->dispose = pspp_sheet_view_dispose;
477 /* GtkWidget signals */
478 widget_class->map = pspp_sheet_view_map;
479 widget_class->realize = pspp_sheet_view_realize;
480 widget_class->unrealize = pspp_sheet_view_unrealize;
481 widget_class->size_request = pspp_sheet_view_size_request;
482 widget_class->size_allocate = pspp_sheet_view_size_allocate;
483 widget_class->button_press_event = pspp_sheet_view_button_press;
484 widget_class->button_release_event = pspp_sheet_view_button_release;
485 widget_class->grab_broken_event = pspp_sheet_view_grab_broken;
486 /*widget_class->configure_event = pspp_sheet_view_configure;*/
487 widget_class->motion_notify_event = pspp_sheet_view_motion;
488 widget_class->expose_event = pspp_sheet_view_expose;
489 widget_class->key_press_event = pspp_sheet_view_key_press;
490 widget_class->key_release_event = pspp_sheet_view_key_release;
491 widget_class->enter_notify_event = pspp_sheet_view_enter_notify;
492 widget_class->leave_notify_event = pspp_sheet_view_leave_notify;
493 widget_class->focus_out_event = pspp_sheet_view_focus_out;
494 widget_class->drag_begin = pspp_sheet_view_drag_begin;
495 widget_class->drag_end = pspp_sheet_view_drag_end;
496 widget_class->drag_data_get = pspp_sheet_view_drag_data_get;
497 widget_class->drag_data_delete = pspp_sheet_view_drag_data_delete;
498 widget_class->drag_leave = pspp_sheet_view_drag_leave;
499 widget_class->drag_motion = pspp_sheet_view_drag_motion;
500 widget_class->drag_drop = pspp_sheet_view_drag_drop;
501 widget_class->drag_data_received = pspp_sheet_view_drag_data_received;
502 widget_class->focus = pspp_sheet_view_focus;
503 widget_class->grab_focus = pspp_sheet_view_grab_focus;
504 widget_class->style_set = pspp_sheet_view_style_set;
505 widget_class->grab_notify = pspp_sheet_view_grab_notify;
506 widget_class->state_changed = pspp_sheet_view_state_changed;
508 /* GtkContainer signals */
509 container_class->remove = pspp_sheet_view_remove;
510 container_class->forall = pspp_sheet_view_forall;
511 container_class->set_focus_child = pspp_sheet_view_set_focus_child;
513 class->set_scroll_adjustments = pspp_sheet_view_set_adjustments;
514 class->move_cursor = pspp_sheet_view_real_move_cursor;
515 class->select_all = pspp_sheet_view_real_select_all;
516 class->unselect_all = pspp_sheet_view_real_unselect_all;
517 class->select_cursor_row = pspp_sheet_view_real_select_cursor_row;
518 class->toggle_cursor_row = pspp_sheet_view_real_toggle_cursor_row;
519 class->start_interactive_search = pspp_sheet_view_start_interactive_search;
523 g_object_class_install_property (o_class,
525 g_param_spec_object ("model",
526 P_("TreeView Model"),
527 P_("The model for the tree view"),
529 GTK_PARAM_READWRITE));
531 g_object_class_install_property (o_class,
533 g_param_spec_object ("hadjustment",
534 P_("Horizontal Adjustment"),
535 P_("Horizontal Adjustment for the widget"),
537 GTK_PARAM_READWRITE));
539 g_object_class_install_property (o_class,
541 g_param_spec_object ("vadjustment",
542 P_("Vertical Adjustment"),
543 P_("Vertical Adjustment for the widget"),
545 GTK_PARAM_READWRITE));
547 g_object_class_install_property (o_class,
548 PROP_HEADERS_VISIBLE,
549 g_param_spec_boolean ("headers-visible",
550 P_("Headers Visible"),
551 P_("Show the column header buttons"),
553 GTK_PARAM_READWRITE));
555 g_object_class_install_property (o_class,
556 PROP_HEADERS_CLICKABLE,
557 g_param_spec_boolean ("headers-clickable",
558 P_("Headers Clickable"),
559 P_("Column headers respond to click events"),
561 GTK_PARAM_READWRITE));
563 g_object_class_install_property (o_class,
565 g_param_spec_boolean ("reorderable",
567 P_("View is reorderable"),
569 GTK_PARAM_READWRITE));
571 g_object_class_install_property (o_class,
573 g_param_spec_boolean ("rules-hint",
575 P_("Set a hint to the theme engine to draw rows in alternating colors"),
577 GTK_PARAM_READWRITE));
579 g_object_class_install_property (o_class,
581 g_param_spec_boolean ("enable-search",
583 P_("View allows user to search through columns interactively"),
585 GTK_PARAM_READWRITE));
587 g_object_class_install_property (o_class,
589 g_param_spec_int ("search-column",
591 P_("Model column to search through during interactive search"),
595 GTK_PARAM_READWRITE));
598 * PsppSheetView:hover-selection:
600 * Enables of disables the hover selection mode of @tree_view.
601 * Hover selection makes the selected row follow the pointer.
602 * Currently, this works only for the selection modes
603 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
605 * This mode is primarily intended for treeviews in popups, e.g.
606 * in #GtkComboBox or #GtkEntryCompletion.
610 g_object_class_install_property (o_class,
611 PROP_HOVER_SELECTION,
612 g_param_spec_boolean ("hover-selection",
613 P_("Hover Selection"),
614 P_("Whether the selection should follow the pointer"),
616 GTK_PARAM_READWRITE));
618 g_object_class_install_property (o_class,
620 g_param_spec_boolean ("rubber-banding",
621 P_("Rubber Banding"),
622 P_("Whether to enable selection of multiple items by dragging the mouse pointer"),
624 GTK_PARAM_READWRITE));
626 g_object_class_install_property (o_class,
627 PROP_ENABLE_GRID_LINES,
628 g_param_spec_enum ("enable-grid-lines",
629 P_("Enable Grid Lines"),
630 P_("Whether grid lines should be drawn in the tree view"),
631 PSPP_TYPE_SHEET_VIEW_GRID_LINES,
632 PSPP_SHEET_VIEW_GRID_LINES_NONE,
633 GTK_PARAM_READWRITE));
635 g_object_class_install_property (o_class,
637 g_param_spec_int ("tooltip-column",
638 P_("Tooltip Column"),
639 P_("The column in the model containing the tooltip texts for the rows"),
643 GTK_PARAM_READWRITE));
645 g_object_class_install_property (o_class,
647 g_param_spec_enum ("special-cells",
649 P_("Whether rows have special cells."),
650 PSPP_TYPE_SHEET_VIEW_SPECIAL_CELLS,
651 PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT,
652 GTK_PARAM_READWRITE));
654 g_object_class_install_property (o_class,
656 g_param_spec_int ("fixed-height",
658 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."),
662 GTK_PARAM_READWRITE));
664 g_object_class_install_property (o_class,
665 PROP_FIXED_HEIGHT_SET,
666 g_param_spec_boolean ("fixed-height-set",
667 P_("Fixed Height Set"),
668 P_("Whether fixed-height was set externally."),
670 GTK_PARAM_READWRITE));
672 /* Style properties */
673 #define _TREE_VIEW_EXPANDER_SIZE 12
674 #define _TREE_VIEW_VERTICAL_SEPARATOR 2
675 #define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
677 gtk_widget_class_install_style_property (widget_class,
678 g_param_spec_int ("expander-size",
680 P_("Size of the expander arrow"),
683 _TREE_VIEW_EXPANDER_SIZE,
684 GTK_PARAM_READABLE));
686 gtk_widget_class_install_style_property (widget_class,
687 g_param_spec_int ("vertical-separator",
688 P_("Vertical Separator Width"),
689 P_("Vertical space between cells. Must be an even number"),
692 _TREE_VIEW_VERTICAL_SEPARATOR,
693 GTK_PARAM_READABLE));
695 gtk_widget_class_install_style_property (widget_class,
696 g_param_spec_int ("horizontal-separator",
697 P_("Horizontal Separator Width"),
698 P_("Horizontal space between cells. Must be an even number"),
701 _TREE_VIEW_HORIZONTAL_SEPARATOR,
702 GTK_PARAM_READABLE));
704 gtk_widget_class_install_style_property (widget_class,
705 g_param_spec_boolean ("allow-rules",
707 P_("Allow drawing of alternating color rows"),
709 GTK_PARAM_READABLE));
711 gtk_widget_class_install_style_property (widget_class,
712 g_param_spec_boxed ("even-row-color",
713 P_("Even Row Color"),
714 P_("Color to use for even rows"),
716 GTK_PARAM_READABLE));
718 gtk_widget_class_install_style_property (widget_class,
719 g_param_spec_boxed ("odd-row-color",
721 P_("Color to use for odd rows"),
723 GTK_PARAM_READABLE));
725 gtk_widget_class_install_style_property (widget_class,
726 g_param_spec_boolean ("row-ending-details",
727 P_("Row Ending details"),
728 P_("Enable extended row background theming"),
730 GTK_PARAM_READABLE));
732 gtk_widget_class_install_style_property (widget_class,
733 g_param_spec_int ("grid-line-width",
734 P_("Grid line width"),
735 P_("Width, in pixels, of the tree view grid lines"),
737 GTK_PARAM_READABLE));
739 gtk_widget_class_install_style_property (widget_class,
740 g_param_spec_int ("tree-line-width",
741 P_("Tree line width"),
742 P_("Width, in pixels, of the tree view lines"),
744 GTK_PARAM_READABLE));
746 gtk_widget_class_install_style_property (widget_class,
747 g_param_spec_string ("tree-line-pattern",
748 P_("Tree line pattern"),
749 P_("Dash pattern used to draw the tree view lines"),
751 GTK_PARAM_READABLE));
755 * PsppSheetView::set-scroll-adjustments
756 * @horizontal: the horizontal #GtkAdjustment
757 * @vertical: the vertical #GtkAdjustment
759 * Set the scroll adjustments for the tree view. Usually scrolled containers
760 * like #GtkScrolledWindow will emit this signal to connect two instances
761 * of #GtkScrollbar to the scroll directions of the #PsppSheetView.
763 widget_class->set_scroll_adjustments_signal =
764 g_signal_new ("set-scroll-adjustments",
765 G_TYPE_FROM_CLASS (o_class),
766 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
767 G_STRUCT_OFFSET (PsppSheetViewClass, set_scroll_adjustments),
769 psppire_marshal_VOID__OBJECT_OBJECT,
772 GTK_TYPE_ADJUSTMENT);
775 * PsppSheetView::row-activated:
776 * @tree_view: the object on which the signal is emitted
777 * @path: the #GtkTreePath for the activated row
778 * @column: the #PsppSheetViewColumn in which the activation occurred
780 * The "row-activated" signal is emitted when the method
781 * pspp_sheet_view_row_activated() is called or the user double clicks
782 * a treeview row. It is also emitted when a non-editable row is
783 * selected and one of the keys: Space, Shift+Space, Return or
786 * For selection handling refer to the <link linkend="TreeWidget">tree
787 * widget conceptual overview</link> as well as #PsppSheetSelection.
789 tree_view_signals[ROW_ACTIVATED] =
790 g_signal_new ("row-activated",
791 G_TYPE_FROM_CLASS (o_class),
792 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
793 G_STRUCT_OFFSET (PsppSheetViewClass, row_activated),
795 psppire_marshal_VOID__BOXED_OBJECT,
798 PSPP_TYPE_SHEET_VIEW_COLUMN);
801 * PsppSheetView::columns-changed:
802 * @tree_view: the object on which the signal is emitted
804 * The number of columns of the treeview has changed.
806 tree_view_signals[COLUMNS_CHANGED] =
807 g_signal_new ("columns-changed",
808 G_TYPE_FROM_CLASS (o_class),
810 G_STRUCT_OFFSET (PsppSheetViewClass, columns_changed),
812 g_cclosure_marshal_VOID__VOID,
816 * PsppSheetView::cursor-changed:
817 * @tree_view: the object on which the signal is emitted
819 * The position of the cursor (focused cell) has changed.
821 tree_view_signals[CURSOR_CHANGED] =
822 g_signal_new ("cursor-changed",
823 G_TYPE_FROM_CLASS (o_class),
825 G_STRUCT_OFFSET (PsppSheetViewClass, cursor_changed),
827 g_cclosure_marshal_VOID__VOID,
830 tree_view_signals[MOVE_CURSOR] =
831 g_signal_new ("move-cursor",
832 G_TYPE_FROM_CLASS (o_class),
833 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
834 G_STRUCT_OFFSET (PsppSheetViewClass, move_cursor),
836 psppire_marshal_BOOLEAN__ENUM_INT,
838 GTK_TYPE_MOVEMENT_STEP,
841 tree_view_signals[SELECT_ALL] =
842 g_signal_new ("select-all",
843 G_TYPE_FROM_CLASS (o_class),
844 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
845 G_STRUCT_OFFSET (PsppSheetViewClass, select_all),
847 psppire_marshal_BOOLEAN__VOID,
850 tree_view_signals[UNSELECT_ALL] =
851 g_signal_new ("unselect-all",
852 G_TYPE_FROM_CLASS (o_class),
853 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
854 G_STRUCT_OFFSET (PsppSheetViewClass, unselect_all),
856 psppire_marshal_BOOLEAN__VOID,
859 tree_view_signals[SELECT_CURSOR_ROW] =
860 g_signal_new ("select-cursor-row",
861 G_TYPE_FROM_CLASS (o_class),
862 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
863 G_STRUCT_OFFSET (PsppSheetViewClass, select_cursor_row),
865 psppire_marshal_BOOLEAN__BOOLEAN,
867 G_TYPE_BOOLEAN, G_TYPE_INT);
869 tree_view_signals[TOGGLE_CURSOR_ROW] =
870 g_signal_new ("toggle-cursor-row",
871 G_TYPE_FROM_CLASS (o_class),
872 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
873 G_STRUCT_OFFSET (PsppSheetViewClass, toggle_cursor_row),
875 psppire_marshal_BOOLEAN__VOID,
878 tree_view_signals[START_INTERACTIVE_SEARCH] =
879 g_signal_new ("start-interactive-search",
880 G_TYPE_FROM_CLASS (o_class),
881 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
882 G_STRUCT_OFFSET (PsppSheetViewClass, start_interactive_search),
884 psppire_marshal_BOOLEAN__VOID,
888 for (i = 0; i < 2; i++)
890 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Up, 0, TRUE,
891 GTK_MOVEMENT_DISPLAY_LINES, -1);
892 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Up, 0, TRUE,
893 GTK_MOVEMENT_DISPLAY_LINES, -1);
895 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Down, 0, TRUE,
896 GTK_MOVEMENT_DISPLAY_LINES, 1);
897 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Down, 0, TRUE,
898 GTK_MOVEMENT_DISPLAY_LINES, 1);
900 pspp_sheet_view_add_move_binding (binding_set[i], GDK_p, GDK_CONTROL_MASK, FALSE,
901 GTK_MOVEMENT_DISPLAY_LINES, -1);
903 pspp_sheet_view_add_move_binding (binding_set[i], GDK_n, GDK_CONTROL_MASK, FALSE,
904 GTK_MOVEMENT_DISPLAY_LINES, 1);
906 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Home, 0, TRUE,
907 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
908 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Home, 0, TRUE,
909 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
911 pspp_sheet_view_add_move_binding (binding_set[i], GDK_End, 0, TRUE,
912 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
913 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_End, 0, TRUE,
914 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
916 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Up, 0, TRUE,
917 GTK_MOVEMENT_PAGES, -1);
918 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Up, 0, TRUE,
919 GTK_MOVEMENT_PAGES, -1);
921 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Down, 0, TRUE,
922 GTK_MOVEMENT_PAGES, 1);
923 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Down, 0, TRUE,
924 GTK_MOVEMENT_PAGES, 1);
927 gtk_binding_entry_add_signal (binding_set[i], GDK_Up, GDK_CONTROL_MASK, "move-cursor", 2,
928 G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
931 gtk_binding_entry_add_signal (binding_set[i], GDK_Down, GDK_CONTROL_MASK, "move-cursor", 2,
932 G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
935 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, 0, "move-cursor", 2,
936 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
939 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, 0, "move-cursor", 2,
940 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
943 gtk_binding_entry_add_signal (binding_set[i], GDK_Tab, 0, "move-cursor", 2,
944 G_TYPE_ENUM, GTK_MOVEMENT_LOGICAL_POSITIONS,
947 gtk_binding_entry_add_signal (binding_set[i], GDK_Tab, GDK_SHIFT_MASK, "move-cursor", 2,
948 G_TYPE_ENUM, GTK_MOVEMENT_LOGICAL_POSITIONS,
951 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, 0, "move-cursor", 2,
952 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
955 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, 0, "move-cursor", 2,
956 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
959 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, GDK_CONTROL_MASK,
961 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
964 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, GDK_CONTROL_MASK,
966 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
969 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, GDK_CONTROL_MASK,
971 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
974 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, GDK_CONTROL_MASK,
976 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
979 gtk_binding_entry_add_signal (binding_set[i], GDK_f, GDK_CONTROL_MASK, "start-interactive-search", 0);
981 gtk_binding_entry_add_signal (binding_set[i], GDK_F, GDK_CONTROL_MASK, "start-interactive-search", 0);
984 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
985 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
987 gtk_binding_entry_add_signal (binding_set[0], GDK_a, GDK_CONTROL_MASK, "select-all", 0);
988 gtk_binding_entry_add_signal (binding_set[0], GDK_slash, GDK_CONTROL_MASK, "select-all", 0);
990 gtk_binding_entry_add_signal (binding_set[0], GDK_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0);
991 gtk_binding_entry_add_signal (binding_set[0], GDK_backslash, GDK_CONTROL_MASK, "unselect-all", 0);
993 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_SHIFT_MASK, "select-cursor-row", 1,
994 G_TYPE_BOOLEAN, TRUE,
995 G_TYPE_INT, PSPP_SHEET_SELECT_MODE_EXTEND);
996 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", 1,
997 G_TYPE_BOOLEAN, TRUE,
998 G_TYPE_INT, PSPP_SHEET_SELECT_MODE_EXTEND);
1000 gtk_binding_entry_add_signal (binding_set[0], GDK_space, 0, "select-cursor-row", 1,
1001 G_TYPE_BOOLEAN, TRUE,
1003 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, 0, "select-cursor-row", 1,
1004 G_TYPE_BOOLEAN, TRUE,
1006 gtk_binding_entry_add_signal (binding_set[0], GDK_Return, 0, "select-cursor-row", 1,
1007 G_TYPE_BOOLEAN, TRUE,
1009 gtk_binding_entry_add_signal (binding_set[0], GDK_ISO_Enter, 0, "select-cursor-row", 1,
1010 G_TYPE_BOOLEAN, TRUE,
1012 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Enter, 0, "select-cursor-row", 1,
1013 G_TYPE_BOOLEAN, TRUE,
1016 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, 0, "select-cursor-parent", 0);
1017 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", 0);
1019 g_type_class_add_private (o_class, sizeof (PsppSheetViewPrivate));
1023 pspp_sheet_view_buildable_init (GtkBuildableIface *iface)
1025 iface->add_child = pspp_sheet_view_buildable_add_child;
1029 pspp_sheet_view_init (PsppSheetView *tree_view)
1031 tree_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (tree_view, PSPP_TYPE_SHEET_VIEW, PsppSheetViewPrivate);
1033 gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
1034 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (tree_view), FALSE);
1036 tree_view->priv->flags = PSPP_SHEET_VIEW_DRAW_KEYFOCUS
1037 | PSPP_SHEET_VIEW_HEADERS_VISIBLE;
1039 /* We need some padding */
1040 tree_view->priv->selected = range_tower_create ();
1041 tree_view->priv->dy = 0;
1042 tree_view->priv->cursor_offset = 0;
1043 tree_view->priv->n_columns = 0;
1044 tree_view->priv->header_height = 1;
1045 tree_view->priv->x_drag = 0;
1046 tree_view->priv->drag_pos = -1;
1047 tree_view->priv->header_has_focus = FALSE;
1048 tree_view->priv->pressed_button = -1;
1049 tree_view->priv->press_start_x = -1;
1050 tree_view->priv->press_start_y = -1;
1051 tree_view->priv->reorderable = FALSE;
1052 tree_view->priv->presize_handler_timer = 0;
1053 tree_view->priv->scroll_sync_timer = 0;
1054 tree_view->priv->fixed_height = -1;
1055 tree_view->priv->fixed_height_set = FALSE;
1056 pspp_sheet_view_set_adjustments (tree_view, NULL, NULL);
1057 tree_view->priv->selection = _pspp_sheet_selection_new_with_tree_view (tree_view);
1058 tree_view->priv->enable_search = TRUE;
1059 tree_view->priv->search_column = -1;
1060 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
1061 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
1062 tree_view->priv->search_custom_entry_set = FALSE;
1063 tree_view->priv->typeselect_flush_timeout = 0;
1064 tree_view->priv->init_hadjust_value = TRUE;
1065 tree_view->priv->width = 0;
1067 tree_view->priv->hover_selection = FALSE;
1069 tree_view->priv->rubber_banding_enable = FALSE;
1071 tree_view->priv->grid_lines = PSPP_SHEET_VIEW_GRID_LINES_NONE;
1073 tree_view->priv->tooltip_column = -1;
1075 tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT;
1077 tree_view->priv->post_validation_flag = FALSE;
1079 tree_view->priv->last_button_x = -1;
1080 tree_view->priv->last_button_y = -1;
1082 tree_view->priv->event_last_x = -10000;
1083 tree_view->priv->event_last_y = -10000;
1085 tree_view->priv->prelight_node = -1;
1086 tree_view->priv->rubber_band_start_node = -1;
1087 tree_view->priv->rubber_band_end_node = -1;
1089 tree_view->priv->anchor_column = NULL;
1091 tree_view->priv->button_style = NULL;
1093 tree_view->dispose_has_run = FALSE;
1102 pspp_sheet_view_set_property (GObject *object,
1104 const GValue *value,
1107 PsppSheetView *tree_view;
1109 tree_view = PSPP_SHEET_VIEW (object);
1114 pspp_sheet_view_set_model (tree_view, g_value_get_object (value));
1116 case PROP_HADJUSTMENT:
1117 pspp_sheet_view_set_hadjustment (tree_view, g_value_get_object (value));
1119 case PROP_VADJUSTMENT:
1120 pspp_sheet_view_set_vadjustment (tree_view, g_value_get_object (value));
1122 case PROP_HEADERS_VISIBLE:
1123 pspp_sheet_view_set_headers_visible (tree_view, g_value_get_boolean (value));
1125 case PROP_HEADERS_CLICKABLE:
1126 pspp_sheet_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
1128 case PROP_REORDERABLE:
1129 pspp_sheet_view_set_reorderable (tree_view, g_value_get_boolean (value));
1131 case PROP_RULES_HINT:
1132 pspp_sheet_view_set_rules_hint (tree_view, g_value_get_boolean (value));
1134 case PROP_ENABLE_SEARCH:
1135 pspp_sheet_view_set_enable_search (tree_view, g_value_get_boolean (value));
1137 case PROP_SEARCH_COLUMN:
1138 pspp_sheet_view_set_search_column (tree_view, g_value_get_int (value));
1140 case PROP_HOVER_SELECTION:
1141 tree_view->priv->hover_selection = g_value_get_boolean (value);
1143 case PROP_RUBBER_BANDING:
1144 tree_view->priv->rubber_banding_enable = g_value_get_boolean (value);
1146 case PROP_ENABLE_GRID_LINES:
1147 pspp_sheet_view_set_grid_lines (tree_view, g_value_get_enum (value));
1149 case PROP_TOOLTIP_COLUMN:
1150 pspp_sheet_view_set_tooltip_column (tree_view, g_value_get_int (value));
1152 case PROP_SPECIAL_CELLS:
1153 pspp_sheet_view_set_special_cells (tree_view, g_value_get_enum (value));
1155 case PROP_FIXED_HEIGHT:
1156 pspp_sheet_view_set_fixed_height (tree_view, g_value_get_int (value));
1158 case PROP_FIXED_HEIGHT_SET:
1159 if (g_value_get_boolean (value))
1161 if (!tree_view->priv->fixed_height_set
1162 && tree_view->priv->fixed_height >= 0)
1164 tree_view->priv->fixed_height_set = true;
1165 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1170 if (tree_view->priv->fixed_height_set)
1172 tree_view->priv->fixed_height_set = false;
1173 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1174 install_presize_handler (tree_view);
1179 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1185 pspp_sheet_view_get_property (GObject *object,
1190 PsppSheetView *tree_view;
1192 tree_view = PSPP_SHEET_VIEW (object);
1197 g_value_set_object (value, tree_view->priv->model);
1199 case PROP_HADJUSTMENT:
1200 g_value_set_object (value, tree_view->priv->hadjustment);
1202 case PROP_VADJUSTMENT:
1203 g_value_set_object (value, tree_view->priv->vadjustment);
1205 case PROP_HEADERS_VISIBLE:
1206 g_value_set_boolean (value, pspp_sheet_view_get_headers_visible (tree_view));
1208 case PROP_HEADERS_CLICKABLE:
1209 g_value_set_boolean (value, pspp_sheet_view_get_headers_clickable (tree_view));
1211 case PROP_REORDERABLE:
1212 g_value_set_boolean (value, tree_view->priv->reorderable);
1214 case PROP_RULES_HINT:
1215 g_value_set_boolean (value, tree_view->priv->has_rules);
1217 case PROP_ENABLE_SEARCH:
1218 g_value_set_boolean (value, tree_view->priv->enable_search);
1220 case PROP_SEARCH_COLUMN:
1221 g_value_set_int (value, tree_view->priv->search_column);
1223 case PROP_HOVER_SELECTION:
1224 g_value_set_boolean (value, tree_view->priv->hover_selection);
1226 case PROP_RUBBER_BANDING:
1227 g_value_set_boolean (value, tree_view->priv->rubber_banding_enable);
1229 case PROP_ENABLE_GRID_LINES:
1230 g_value_set_enum (value, tree_view->priv->grid_lines);
1232 case PROP_TOOLTIP_COLUMN:
1233 g_value_set_int (value, tree_view->priv->tooltip_column);
1235 case PROP_SPECIAL_CELLS:
1236 g_value_set_enum (value, tree_view->priv->special_cells);
1238 case PROP_FIXED_HEIGHT:
1239 g_value_set_int (value, pspp_sheet_view_get_fixed_height (tree_view));
1241 case PROP_FIXED_HEIGHT_SET:
1242 g_value_set_boolean (value, tree_view->priv->fixed_height_set);
1245 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1251 pspp_sheet_view_dispose (GObject *object)
1253 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1255 if (tree_view->dispose_has_run)
1258 tree_view->dispose_has_run = TRUE;
1260 if (tree_view->priv->selection != NULL)
1262 _pspp_sheet_selection_set_tree_view (tree_view->priv->selection, NULL);
1263 g_object_unref (tree_view->priv->selection);
1264 tree_view->priv->selection = NULL;
1267 if (tree_view->priv->hadjustment)
1269 g_object_unref (tree_view->priv->hadjustment);
1270 tree_view->priv->hadjustment = NULL;
1272 if (tree_view->priv->vadjustment)
1274 g_object_unref (tree_view->priv->vadjustment);
1275 tree_view->priv->vadjustment = NULL;
1278 if (tree_view->priv->button_style)
1280 g_object_unref (tree_view->priv->button_style);
1281 tree_view->priv->button_style = NULL;
1285 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->dispose (object);
1291 pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
1292 GtkBuilder *builder,
1296 pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), PSPP_SHEET_VIEW_COLUMN (child));
1300 pspp_sheet_view_finalize (GObject *object)
1302 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1304 pspp_sheet_view_stop_editing (tree_view, TRUE);
1306 if (tree_view->priv->selected != NULL)
1308 range_tower_destroy (tree_view->priv->selected);
1309 tree_view->priv->selected = NULL;
1313 tree_view->priv->prelight_node = -1;
1316 if (tree_view->priv->scroll_to_path != NULL)
1318 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1319 tree_view->priv->scroll_to_path = NULL;
1322 if (tree_view->priv->drag_dest_row != NULL)
1324 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
1325 tree_view->priv->drag_dest_row = NULL;
1328 if (tree_view->priv->top_row != NULL)
1330 gtk_tree_row_reference_free (tree_view->priv->top_row);
1331 tree_view->priv->top_row = NULL;
1334 if (tree_view->priv->column_drop_func_data &&
1335 tree_view->priv->column_drop_func_data_destroy)
1337 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
1338 tree_view->priv->column_drop_func_data = NULL;
1341 if (tree_view->priv->destroy_count_destroy &&
1342 tree_view->priv->destroy_count_data)
1344 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
1345 tree_view->priv->destroy_count_data = NULL;
1348 gtk_tree_row_reference_free (tree_view->priv->cursor);
1349 tree_view->priv->cursor = NULL;
1351 gtk_tree_row_reference_free (tree_view->priv->anchor);
1352 tree_view->priv->anchor = NULL;
1354 /* destroy interactive search dialog */
1355 if (tree_view->priv->search_window)
1357 gtk_widget_destroy (tree_view->priv->search_window);
1358 tree_view->priv->search_window = NULL;
1359 tree_view->priv->search_entry = NULL;
1360 if (tree_view->priv->typeselect_flush_timeout)
1362 g_source_remove (tree_view->priv->typeselect_flush_timeout);
1363 tree_view->priv->typeselect_flush_timeout = 0;
1367 if (tree_view->priv->search_destroy && tree_view->priv->search_user_data)
1369 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
1370 tree_view->priv->search_user_data = NULL;
1373 if (tree_view->priv->search_position_destroy && tree_view->priv->search_position_user_data)
1375 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
1376 tree_view->priv->search_position_user_data = NULL;
1379 pspp_sheet_view_set_model (tree_view, NULL);
1382 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->finalize (object);
1387 /* GtkWidget Methods
1390 /* GtkWidget::map helper */
1392 pspp_sheet_view_map_buttons (PsppSheetView *tree_view)
1396 g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (tree_view)));
1398 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
1400 PsppSheetViewColumn *column;
1402 for (list = tree_view->priv->columns; list; list = list->next)
1404 column = list->data;
1405 if (column->button != NULL &&
1406 gtk_widget_get_visible (column->button) &&
1407 !gtk_widget_get_mapped (column->button))
1408 gtk_widget_map (column->button);
1410 for (list = tree_view->priv->columns; list; list = list->next)
1412 column = list->data;
1413 if (column->visible == FALSE || column->window == NULL)
1415 if (column->resizable)
1417 gdk_window_raise (column->window);
1418 gdk_window_show (column->window);
1421 gdk_window_hide (column->window);
1423 gdk_window_show (tree_view->priv->header_window);
1428 pspp_sheet_view_map (GtkWidget *widget)
1430 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1433 gtk_widget_set_mapped (widget, TRUE);
1435 tmp_list = tree_view->priv->children;
1438 PsppSheetViewChild *child = tmp_list->data;
1439 tmp_list = tmp_list->next;
1441 if (gtk_widget_get_visible (child->widget))
1443 if (!gtk_widget_get_mapped (child->widget))
1444 gtk_widget_map (child->widget);
1447 gdk_window_show (tree_view->priv->bin_window);
1449 pspp_sheet_view_map_buttons (tree_view);
1451 gdk_window_show (gtk_widget_get_window (widget));
1455 pspp_sheet_view_realize (GtkWidget *widget)
1457 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1459 GdkWindowAttr attributes;
1460 gint attributes_mask;
1462 gtk_widget_set_realized (widget, TRUE);
1464 /* Make the main, clipping window */
1465 attributes.window_type = GDK_WINDOW_CHILD;
1466 attributes.x = widget->allocation.x;
1467 attributes.y = widget->allocation.y;
1468 attributes.width = widget->allocation.width;
1469 attributes.height = widget->allocation.height;
1470 attributes.wclass = GDK_INPUT_OUTPUT;
1471 attributes.visual = gtk_widget_get_visual (widget);
1472 attributes.colormap = gtk_widget_get_colormap (widget);
1473 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1475 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1477 gtk_widget_set_window (widget,
1478 gdk_window_new (gtk_widget_get_parent_window (widget),
1479 &attributes, attributes_mask));
1480 gdk_window_set_user_data (gtk_widget_get_window (widget), widget);
1482 /* Make the window for the tree */
1484 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1485 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1486 attributes.height = widget->allocation.height;
1487 attributes.event_mask = (GDK_EXPOSURE_MASK |
1489 GDK_POINTER_MOTION_MASK |
1490 GDK_ENTER_NOTIFY_MASK |
1491 GDK_LEAVE_NOTIFY_MASK |
1492 GDK_BUTTON_PRESS_MASK |
1493 GDK_BUTTON_RELEASE_MASK |
1494 gtk_widget_get_events (widget));
1496 tree_view->priv->bin_window = gdk_window_new (gtk_widget_get_window (widget),
1497 &attributes, attributes_mask);
1498 gdk_window_set_user_data (tree_view->priv->bin_window, widget);
1500 /* Make the column header window */
1503 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1504 attributes.height = tree_view->priv->header_height;
1505 attributes.event_mask = (GDK_EXPOSURE_MASK |
1507 GDK_BUTTON_PRESS_MASK |
1508 GDK_BUTTON_RELEASE_MASK |
1509 GDK_KEY_PRESS_MASK |
1510 GDK_KEY_RELEASE_MASK |
1511 gtk_widget_get_events (widget));
1513 tree_view->priv->header_window = gdk_window_new (gtk_widget_get_window (widget),
1514 &attributes, attributes_mask);
1515 gdk_window_set_user_data (tree_view->priv->header_window, widget);
1517 /* Add them all up. */
1518 widget->style = gtk_style_attach (widget->style, gtk_widget_get_window (widget));
1519 gdk_window_set_back_pixmap (gtk_widget_get_window (widget), NULL, FALSE);
1520 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
1521 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
1523 tmp_list = tree_view->priv->children;
1526 PsppSheetViewChild *child = tmp_list->data;
1527 tmp_list = tmp_list->next;
1529 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1532 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1533 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1535 /* Need to call those here, since they create GCs */
1536 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1538 install_presize_handler (tree_view);
1542 pspp_sheet_view_unrealize (GtkWidget *widget)
1544 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1545 PsppSheetViewPrivate *priv = tree_view->priv;
1548 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1550 if (priv->scroll_timeout != 0)
1552 g_source_remove (priv->scroll_timeout);
1553 priv->scroll_timeout = 0;
1556 if (priv->open_dest_timeout != 0)
1558 g_source_remove (priv->open_dest_timeout);
1559 priv->open_dest_timeout = 0;
1562 if (priv->presize_handler_timer != 0)
1564 g_source_remove (priv->presize_handler_timer);
1565 priv->presize_handler_timer = 0;
1568 if (priv->validate_rows_timer != 0)
1570 g_source_remove (priv->validate_rows_timer);
1571 priv->validate_rows_timer = 0;
1574 if (priv->scroll_sync_timer != 0)
1576 g_source_remove (priv->scroll_sync_timer);
1577 priv->scroll_sync_timer = 0;
1580 if (priv->typeselect_flush_timeout)
1582 g_source_remove (priv->typeselect_flush_timeout);
1583 priv->typeselect_flush_timeout = 0;
1586 for (list = priv->columns; list; list = list->next)
1587 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1589 gdk_window_set_user_data (priv->bin_window, NULL);
1590 gdk_window_destroy (priv->bin_window);
1591 priv->bin_window = NULL;
1593 gdk_window_set_user_data (priv->header_window, NULL);
1594 gdk_window_destroy (priv->header_window);
1595 priv->header_window = NULL;
1597 if (priv->drag_window)
1599 gdk_window_set_user_data (priv->drag_window, NULL);
1600 gdk_window_destroy (priv->drag_window);
1601 priv->drag_window = NULL;
1604 if (priv->drag_highlight_window)
1606 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1607 gdk_window_destroy (priv->drag_highlight_window);
1608 priv->drag_highlight_window = NULL;
1611 if (tree_view->priv->columns != NULL)
1613 list = tree_view->priv->columns;
1616 PsppSheetViewColumn *column;
1617 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1619 pspp_sheet_view_remove_column (tree_view, column);
1621 tree_view->priv->columns = NULL;
1625 /* GtkWidget::size_request helper */
1627 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1631 tree_view->priv->header_height = 0;
1633 if (tree_view->priv->model)
1635 for (list = tree_view->priv->columns; list; list = list->next)
1637 GtkRequisition requisition;
1638 PsppSheetViewColumn *column = list->data;
1640 pspp_sheet_view_column_size_request (column, &requisition);
1641 column->button_request = requisition.width;
1642 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1648 /* Called only by ::size_request */
1650 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1653 PsppSheetViewColumn *column;
1656 if (tree_view->priv->model == NULL)
1658 tree_view->priv->width = 0;
1659 tree_view->priv->prev_width = 0;
1660 tree_view->priv->height = 0;
1664 tree_view->priv->prev_width = tree_view->priv->width;
1665 tree_view->priv->width = 0;
1667 /* keep this in sync with size_allocate below */
1668 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1670 gint real_requested_width = 0;
1671 column = list->data;
1672 if (!column->visible)
1675 if (column->use_resized_width)
1677 real_requested_width = column->resized_width;
1681 real_requested_width = column->fixed_width;
1684 if (column->min_width != -1)
1685 real_requested_width = MAX (real_requested_width, column->min_width);
1686 if (column->max_width != -1)
1687 real_requested_width = MIN (real_requested_width, column->max_width);
1689 tree_view->priv->width += real_requested_width;
1692 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1696 pspp_sheet_view_size_request (GtkWidget *widget,
1697 GtkRequisition *requisition)
1699 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1702 /* we validate some rows initially just to make sure we have some size.
1703 * In practice, with a lot of static lists, this should get a good width.
1705 initialize_fixed_height_mode (tree_view);
1706 pspp_sheet_view_size_request_columns (tree_view);
1707 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1709 requisition->width = tree_view->priv->width;
1710 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1712 tmp_list = tree_view->priv->children;
1716 PsppSheetViewChild *child = tmp_list->data;
1717 GtkRequisition child_requisition;
1719 tmp_list = tmp_list->next;
1721 if (gtk_widget_get_visible (child->widget))
1722 gtk_widget_size_request (child->widget, &child_requisition);
1727 invalidate_column (PsppSheetView *tree_view,
1728 PsppSheetViewColumn *column)
1730 gint column_offset = 0;
1732 GtkWidget *widget = GTK_WIDGET (tree_view);
1735 if (!gtk_widget_get_realized (widget))
1738 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1739 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1741 list = (rtl ? list->prev : list->next))
1743 PsppSheetViewColumn *tmpcolumn = list->data;
1744 if (tmpcolumn == column)
1746 GdkRectangle invalid_rect;
1748 invalid_rect.x = column_offset;
1750 invalid_rect.width = column->width;
1751 invalid_rect.height = widget->allocation.height;
1753 gdk_window_invalidate_rect (gtk_widget_get_window (widget), &invalid_rect, TRUE);
1757 column_offset += tmpcolumn->width;
1762 invalidate_last_column (PsppSheetView *tree_view)
1767 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1769 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1771 last_column = (rtl ? last_column->next : last_column->prev))
1773 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1775 invalidate_column (tree_view, last_column->data);
1782 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1783 PsppSheetViewColumn *column)
1785 gint real_requested_width;
1787 if (column->use_resized_width)
1789 real_requested_width = column->resized_width;
1793 real_requested_width = column->fixed_width;
1796 if (column->min_width != -1)
1797 real_requested_width = MAX (real_requested_width, column->min_width);
1798 if (column->max_width != -1)
1799 real_requested_width = MIN (real_requested_width, column->max_width);
1801 return real_requested_width;
1805 span_intersects (int a0, int a_width,
1806 int b0, int b_width)
1808 int a1 = a0 + a_width;
1809 int b1 = b0 + b_width;
1810 return (a0 >= b0 && a0 < b1) || (b0 >= a0 && b0 < a1);
1813 /* GtkWidget::size_allocate helper */
1815 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1816 gboolean *width_changed)
1818 PsppSheetView *tree_view;
1819 GList *list, *first_column, *last_column;
1820 PsppSheetViewColumn *column;
1821 GtkAllocation allocation;
1823 gint extra, extra_per_column;
1824 gint full_requested_width = 0;
1825 gint number_of_expand_columns = 0;
1826 gboolean column_changed = FALSE;
1829 tree_view = PSPP_SHEET_VIEW (widget);
1831 for (last_column = g_list_last (tree_view->priv->columns);
1832 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1833 last_column = last_column->prev)
1835 if (last_column == NULL)
1838 for (first_column = g_list_first (tree_view->priv->columns);
1839 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1840 first_column = first_column->next)
1844 allocation.height = tree_view->priv->header_height;
1846 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1848 /* find out how many extra space and expandable columns we have */
1849 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1851 column = (PsppSheetViewColumn *)list->data;
1853 if (!column->visible)
1856 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1859 number_of_expand_columns++;
1862 extra = MAX (widget->allocation.width - full_requested_width, 0);
1863 if (number_of_expand_columns > 0)
1864 extra_per_column = extra/number_of_expand_columns;
1866 extra_per_column = 0;
1868 for (list = (rtl ? last_column : first_column);
1869 list != (rtl ? first_column->prev : last_column->next);
1870 list = (rtl ? list->prev : list->next))
1872 gint real_requested_width = 0;
1875 column = list->data;
1876 old_width = column->width;
1878 if (!column->visible)
1881 /* We need to handle the dragged button specially.
1883 if (column == tree_view->priv->drag_column)
1885 GtkAllocation drag_allocation;
1886 drag_allocation.width = gdk_window_get_width (tree_view->priv->drag_window);
1887 drag_allocation.height = gdk_window_get_height (tree_view->priv->drag_window);
1888 drag_allocation.x = 0;
1889 drag_allocation.y = 0;
1890 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1892 width += drag_allocation.width;
1896 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1898 allocation.x = width;
1899 column->width = real_requested_width;
1903 if (number_of_expand_columns == 1)
1905 /* We add the remander to the last column as
1907 column->width += extra;
1911 column->width += extra_per_column;
1912 extra -= extra_per_column;
1913 number_of_expand_columns --;
1917 if (column->width != old_width)
1918 g_object_notify (G_OBJECT (column), "width");
1920 allocation.width = column->width;
1921 width += column->width;
1923 if (column->width > old_width)
1924 column_changed = TRUE;
1926 pspp_sheet_view_column_size_allocate (column, &allocation);
1928 if (span_intersects (allocation.x, allocation.width,
1929 tree_view->priv->hadjustment->value,
1930 widget->allocation.width)
1931 && gtk_widget_get_realized (widget))
1932 pspp_sheet_view_column_set_need_button (column, TRUE);
1935 gdk_window_move_resize (column->window,
1936 allocation.x + (rtl ? 0 : allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1938 TREE_VIEW_DRAG_WIDTH, allocation.height);
1941 /* We change the width here. The user might have been resizing columns,
1942 * so the total width of the tree view changes.
1944 tree_view->priv->width = width;
1946 *width_changed = TRUE;
1949 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
1954 pspp_sheet_view_size_allocate (GtkWidget *widget,
1955 GtkAllocation *allocation)
1957 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1959 gboolean width_changed = FALSE;
1960 gint old_width = widget->allocation.width;
1962 if (allocation->width != widget->allocation.width)
1963 width_changed = TRUE;
1965 widget->allocation = *allocation;
1967 tmp_list = tree_view->priv->children;
1971 GtkAllocation allocation;
1973 PsppSheetViewChild *child = tmp_list->data;
1974 tmp_list = tmp_list->next;
1976 /* totally ignore our child's requisition */
1977 allocation.x = child->x;
1978 allocation.y = child->y;
1979 allocation.width = child->width;
1980 allocation.height = child->height;
1981 gtk_widget_size_allocate (child->widget, &allocation);
1984 /* We size-allocate the columns first because the width of the
1985 * tree view (used in updating the adjustments below) might change.
1987 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
1989 tree_view->priv->hadjustment->page_size = allocation->width;
1990 tree_view->priv->hadjustment->page_increment = allocation->width * 0.9;
1991 tree_view->priv->hadjustment->step_increment = allocation->width * 0.1;
1992 tree_view->priv->hadjustment->lower = 0;
1993 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->page_size, tree_view->priv->width);
1995 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
1997 if (allocation->width < tree_view->priv->width)
1999 if (tree_view->priv->init_hadjust_value)
2001 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
2002 tree_view->priv->init_hadjust_value = FALSE;
2004 else if (allocation->width != old_width)
2006 tree_view->priv->hadjustment->value = CLAMP (tree_view->priv->hadjustment->value - allocation->width + old_width, 0, tree_view->priv->width - allocation->width);
2009 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);
2013 tree_view->priv->hadjustment->value = 0;
2014 tree_view->priv->init_hadjust_value = TRUE;
2018 if (tree_view->priv->hadjustment->value + allocation->width > tree_view->priv->width)
2019 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
2021 gtk_adjustment_changed (tree_view->priv->hadjustment);
2023 tree_view->priv->vadjustment->page_size = allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view);
2024 tree_view->priv->vadjustment->step_increment = tree_view->priv->vadjustment->page_size * 0.1;
2025 tree_view->priv->vadjustment->page_increment = tree_view->priv->vadjustment->page_size * 0.9;
2026 tree_view->priv->vadjustment->lower = 0;
2027 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->page_size, tree_view->priv->height);
2029 gtk_adjustment_changed (tree_view->priv->vadjustment);
2031 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
2032 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
2033 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
2034 else if (tree_view->priv->vadjustment->value + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
2035 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
2036 tree_view->priv->height - tree_view->priv->vadjustment->page_size);
2037 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
2038 pspp_sheet_view_top_row_to_dy (tree_view);
2040 pspp_sheet_view_dy_to_top_row (tree_view);
2042 if (gtk_widget_get_realized (widget))
2044 gdk_window_move_resize (gtk_widget_get_window (widget),
2045 allocation->x, allocation->y,
2046 allocation->width, allocation->height);
2047 gdk_window_move_resize (tree_view->priv->header_window,
2048 - (gint) tree_view->priv->hadjustment->value,
2050 MAX (tree_view->priv->width, allocation->width),
2051 tree_view->priv->header_height);
2052 gdk_window_move_resize (tree_view->priv->bin_window,
2053 - (gint) tree_view->priv->hadjustment->value,
2054 TREE_VIEW_HEADER_HEIGHT (tree_view),
2055 MAX (tree_view->priv->width, allocation->width),
2056 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2059 if (tree_view->priv->row_count == 0)
2060 invalidate_empty_focus (tree_view);
2062 if (gtk_widget_get_realized (widget))
2064 gboolean has_expand_column = FALSE;
2065 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2067 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2069 has_expand_column = TRUE;
2074 /* This little hack only works if we have an LTR locale, and no column has the */
2077 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2078 ! has_expand_column)
2079 invalidate_last_column (tree_view);
2081 gtk_widget_queue_draw (widget);
2086 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2088 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2090 GtkWidget *widget = GTK_WIDGET (tree_view);
2092 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2093 gtk_widget_grab_focus (widget);
2094 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2098 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2101 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2105 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2108 range_tower_set1 (tree_view->priv->selected, node, 1);
2112 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2115 range_tower_set0 (tree_view->priv->selected, node, 1);
2119 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2122 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2126 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2129 return node > 0 ? node - 1 : -1;
2133 all_columns_selected (PsppSheetView *tree_view)
2137 for (list = tree_view->priv->columns; list; list = list->next)
2139 PsppSheetViewColumn *column = list->data;
2140 if (column->selectable && !column->selected)
2148 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2150 PsppSheetViewColumn *column,
2151 GdkEventButton *event)
2153 PsppSheetSelection *selection;
2154 PsppSheetSelectionMode mode;
2156 gboolean update_anchor;
2160 g_return_val_if_fail (tree_view != NULL, FALSE);
2161 g_return_val_if_fail (column != NULL, FALSE);
2163 selection = tree_view->priv->selection;
2164 mode = pspp_sheet_selection_get_mode (selection);
2165 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2168 if (!column->row_head)
2173 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2174 if (event->type != GDK_BUTTON_PRESS
2175 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2181 path = gtk_tree_path_new_from_indices (node, -1);
2184 pspp_sheet_selection_unselect_all (selection);
2185 pspp_sheet_selection_select_path (selection, path);
2186 pspp_sheet_selection_select_all_columns (selection);
2187 update_anchor = TRUE;
2190 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2192 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2193 || !all_columns_selected (tree_view))
2195 pspp_sheet_selection_unselect_all (selection);
2196 pspp_sheet_selection_select_path (selection, path);
2197 pspp_sheet_selection_select_all_columns (selection);
2198 update_anchor = TRUE;
2202 update_anchor = handled = FALSE;
2204 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2205 && modifiers == GDK_CONTROL_MASK)
2207 if (!all_columns_selected (tree_view))
2209 pspp_sheet_selection_unselect_all (selection);
2210 pspp_sheet_selection_select_all_columns (selection);
2213 if (pspp_sheet_selection_path_is_selected (selection, path))
2214 pspp_sheet_selection_unselect_path (selection, path);
2216 pspp_sheet_selection_select_path (selection, path);
2217 update_anchor = TRUE;
2220 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2221 && modifiers == GDK_SHIFT_MASK)
2223 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2224 GtkTreePath *anchor_path;
2226 if (all_columns_selected (tree_view)
2227 && gtk_tree_row_reference_valid (anchor))
2229 update_anchor = FALSE;
2230 anchor_path = gtk_tree_row_reference_get_path (anchor);
2234 update_anchor = TRUE;
2235 anchor_path = gtk_tree_path_copy (path);
2238 pspp_sheet_selection_unselect_all (selection);
2239 pspp_sheet_selection_select_range (selection, anchor_path, path);
2240 pspp_sheet_selection_select_all_columns (selection);
2242 gtk_tree_path_free (anchor_path);
2247 update_anchor = handled = FALSE;
2251 if (tree_view->priv->anchor)
2252 gtk_tree_row_reference_free (tree_view->priv->anchor);
2253 tree_view->priv->anchor =
2254 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2255 tree_view->priv->model,
2259 gtk_tree_path_free (path);
2264 find_click (PsppSheetView *tree_view,
2267 PsppSheetViewColumn **column,
2268 GdkRectangle *background_area,
2269 GdkRectangle *cell_area)
2276 /* find the node that was clicked */
2277 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2280 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2285 background_area->y = y_offset + y;
2286 background_area->height = ROW_HEIGHT (tree_view);
2287 background_area->x = 0;
2289 /* Let the column have a chance at selecting it. */
2290 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2291 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2292 list; list = (rtl ? list->prev : list->next))
2294 PsppSheetViewColumn *candidate = list->data;
2296 if (!candidate->visible)
2299 background_area->width = candidate->width;
2300 if ((background_area->x > x) ||
2301 (background_area->x + background_area->width <= x))
2303 background_area->x += background_area->width;
2307 /* we found the focus column */
2309 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2311 *column = candidate;
2319 pspp_sheet_view_button_press (GtkWidget *widget,
2320 GdkEventButton *event)
2322 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2324 PsppSheetViewColumn *column = NULL;
2326 GdkRectangle background_area;
2327 GdkRectangle cell_area;
2330 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2331 pspp_sheet_view_stop_editing (tree_view, FALSE);
2334 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2335 * we're done handling the button press.
2338 if (event->window == tree_view->priv->bin_window)
2343 gint pre_val, aft_val;
2344 PsppSheetViewColumn *column = NULL;
2345 GtkCellRenderer *focus_cell = NULL;
2346 gboolean row_double_click = FALSE;
2349 if (tree_view->priv->row_count == 0)
2351 grab_focus_and_unset_draw_keyfocus (tree_view);
2355 if (!find_click (tree_view, event->x, event->y, &node, &column,
2356 &background_area, &cell_area))
2358 grab_focus_and_unset_draw_keyfocus (tree_view);
2362 tree_view->priv->focus_column = column;
2364 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2368 pre_val = tree_view->priv->vadjustment->value;
2370 path = _pspp_sheet_view_find_path (tree_view, node);
2372 /* we only handle selection modifications on the first button press
2374 if (event->type == GDK_BUTTON_PRESS)
2376 PsppSheetSelectionMode mode = 0;
2378 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2379 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
2380 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2381 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
2383 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2385 pspp_sheet_view_column_focus_cell (column, focus_cell);
2387 if (event->state & GDK_CONTROL_MASK)
2389 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, mode);
2390 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2392 else if (event->state & GDK_SHIFT_MASK)
2394 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
2395 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE, mode);
2399 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
2402 if (tree_view->priv->anchor_column == NULL ||
2403 !(event->state & GDK_SHIFT_MASK))
2404 tree_view->priv->anchor_column = column;
2405 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2406 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2407 tree_view->priv->anchor_column,
2411 /* the treeview may have been scrolled because of _set_cursor,
2415 aft_val = tree_view->priv->vadjustment->value;
2416 dval = pre_val - aft_val;
2418 cell_area.y += dval;
2419 background_area.y += dval;
2421 /* Save press to possibly begin a drag
2423 if (!tree_view->priv->in_grab &&
2424 tree_view->priv->pressed_button < 0)
2426 tree_view->priv->pressed_button = event->button;
2427 tree_view->priv->press_start_x = event->x;
2428 tree_view->priv->press_start_y = event->y;
2429 tree_view->priv->press_start_node = node;
2431 if (tree_view->priv->rubber_banding_enable
2432 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2433 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2435 tree_view->priv->press_start_y += tree_view->priv->dy;
2436 tree_view->priv->rubber_band_x = event->x;
2437 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2438 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2440 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2441 tree_view->priv->rubber_band_ctrl = TRUE;
2442 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2443 tree_view->priv->rubber_band_shift = TRUE;
2448 /* Test if a double click happened on the same row. */
2449 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2451 int double_click_time, double_click_distance;
2453 g_object_get (gtk_settings_get_for_screen (
2454 gtk_widget_get_screen (widget)),
2455 "gtk-double-click-time", &double_click_time,
2456 "gtk-double-click-distance", &double_click_distance,
2459 /* Same conditions as _gdk_event_button_generate */
2460 if (tree_view->priv->last_button_x != -1 &&
2461 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2462 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2463 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2465 /* We do no longer compare paths of this row and the
2466 * row clicked previously. We use the double click
2467 * distance to decide whether this is a valid click,
2468 * allowing the mouse to slightly move over another row.
2470 row_double_click = TRUE;
2472 tree_view->priv->last_button_time = 0;
2473 tree_view->priv->last_button_x = -1;
2474 tree_view->priv->last_button_y = -1;
2478 tree_view->priv->last_button_time = event->time;
2479 tree_view->priv->last_button_x = event->x;
2480 tree_view->priv->last_button_y = event->y;
2484 if (row_double_click)
2486 gtk_grab_remove (widget);
2487 pspp_sheet_view_row_activated (tree_view, path, column);
2489 if (tree_view->priv->pressed_button == event->button)
2490 tree_view->priv->pressed_button = -1;
2493 gtk_tree_path_free (path);
2495 /* If we activated the row through a double click we don't want to grab
2496 * focus back, as moving focus to another widget is pretty common.
2498 if (!row_double_click)
2499 grab_focus_and_unset_draw_keyfocus (tree_view);
2504 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2506 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2508 column = list->data;
2509 if (event->window == column->window &&
2510 column->resizable &&
2515 if (gdk_pointer_grab (column->window, FALSE,
2516 GDK_POINTER_MOTION_HINT_MASK |
2517 GDK_BUTTON1_MOTION_MASK |
2518 GDK_BUTTON_RELEASE_MASK,
2519 NULL, NULL, event->time))
2522 gtk_grab_add (widget);
2523 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2524 column->resized_width = column->width;
2526 /* block attached dnd signal handler */
2527 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2529 g_signal_handlers_block_matched (widget,
2530 G_SIGNAL_MATCH_DATA,
2534 tree_view->priv->drag_pos = i;
2535 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2537 if (!gtk_widget_has_focus (widget))
2538 gtk_widget_grab_focus (widget);
2546 /* GtkWidget::button_release_event helper */
2548 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2549 GdkEventButton *event)
2551 PsppSheetView *tree_view;
2555 tree_view = PSPP_SHEET_VIEW (widget);
2557 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2558 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2559 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2561 /* Move the button back */
2562 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2564 g_object_ref (tree_view->priv->drag_column->button);
2565 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2566 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2567 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2568 g_object_unref (tree_view->priv->drag_column->button);
2569 gtk_widget_queue_resize (widget);
2570 if (tree_view->priv->drag_column->resizable)
2572 gdk_window_raise (tree_view->priv->drag_column->window);
2573 gdk_window_show (tree_view->priv->drag_column->window);
2576 gdk_window_hide (tree_view->priv->drag_column->window);
2578 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2582 if (tree_view->priv->cur_reorder &&
2583 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2584 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2585 tree_view->priv->cur_reorder->right_column);
2589 if (tree_view->priv->cur_reorder &&
2590 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2591 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2592 tree_view->priv->cur_reorder->left_column);
2594 tree_view->priv->drag_column = NULL;
2595 gdk_window_hide (tree_view->priv->drag_window);
2597 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2598 g_slice_free (PsppSheetViewColumnReorder, l->data);
2599 g_list_free (tree_view->priv->column_drag_info);
2600 tree_view->priv->column_drag_info = NULL;
2601 tree_view->priv->cur_reorder = NULL;
2603 if (tree_view->priv->drag_highlight_window)
2604 gdk_window_hide (tree_view->priv->drag_highlight_window);
2606 /* Reset our flags */
2607 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2608 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2613 /* GtkWidget::button_release_event helper */
2615 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2616 GdkEventButton *event)
2618 PsppSheetView *tree_view;
2621 tree_view = PSPP_SHEET_VIEW (widget);
2623 tree_view->priv->drag_pos = -1;
2625 /* unblock attached dnd signal handler */
2626 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2628 g_signal_handlers_unblock_matched (widget,
2629 G_SIGNAL_MATCH_DATA,
2633 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2634 gtk_grab_remove (widget);
2635 gdk_display_pointer_ungrab (gdk_window_get_display (event->window),
2641 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2642 GdkEventButton *event)
2644 GtkCellEditable *cell_editable;
2649 PsppSheetViewColumn *column;
2650 GdkRectangle background_area;
2651 GdkRectangle cell_area;
2657 if (event->window != tree_view->priv->bin_window)
2660 /* Ignore a released button, if that button wasn't depressed */
2661 if (tree_view->priv->pressed_button != event->button)
2664 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2668 /* decide if we edit */
2669 path = _pspp_sheet_view_find_path (tree_view, node);
2670 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2671 if (event->button != 1 || modifiers)
2674 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2675 pspp_sheet_view_column_cell_set_cell_data (column,
2676 tree_view->priv->model,
2679 if (!pspp_sheet_view_column_get_quick_edit (column)
2680 && _pspp_sheet_view_column_has_editable_cell (column))
2683 flags = 0; /* FIXME: get the right flags */
2684 path_string = gtk_tree_path_to_string (path);
2686 if (!_pspp_sheet_view_column_cell_event (column,
2694 if (cell_editable == NULL)
2697 pspp_sheet_view_real_set_cursor (tree_view, path,
2698 TRUE, TRUE, 0); /* XXX mode? */
2699 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2702 _pspp_sheet_view_column_get_neighbor_sizes (
2703 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2706 area.width -= right + left;
2708 pspp_sheet_view_real_start_editing (tree_view,
2715 g_free (path_string);
2716 gtk_tree_path_free (path);
2721 pspp_sheet_view_button_release (GtkWidget *widget,
2722 GdkEventButton *event)
2724 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2726 pspp_sheet_view_stop_editing (tree_view, FALSE);
2727 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2728 && pspp_sheet_view_button_release_edit (tree_view, event))
2730 if (tree_view->priv->pressed_button == event->button)
2731 tree_view->priv->pressed_button = -1;
2733 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2737 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2738 return pspp_sheet_view_button_release_drag_column (widget, event);
2740 if (tree_view->priv->rubber_band_status)
2741 pspp_sheet_view_stop_rubber_band (tree_view);
2743 if (tree_view->priv->pressed_button == event->button)
2744 tree_view->priv->pressed_button = -1;
2746 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2747 return pspp_sheet_view_button_release_column_resize (widget, event);
2753 pspp_sheet_view_grab_broken (GtkWidget *widget,
2754 GdkEventGrabBroken *event)
2756 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2758 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2759 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2761 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2762 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2767 /* GtkWidget::motion_event function set.
2771 do_prelight (PsppSheetView *tree_view,
2773 /* these are in bin_window coords */
2777 int prev_node = tree_view->priv->prelight_node;
2779 if (prev_node != node)
2781 tree_view->priv->prelight_node = node;
2784 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2787 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2792 prelight_or_select (PsppSheetView *tree_view,
2794 /* these are in bin_window coords */
2798 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2800 if (tree_view->priv->hover_selection &&
2801 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2802 !(tree_view->priv->edited_column &&
2803 tree_view->priv->edited_column->editable_widget))
2807 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2811 path = _pspp_sheet_view_find_path (tree_view, node);
2812 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2813 if (pspp_sheet_view_node_is_selected (tree_view, node))
2815 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2816 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE, 0); /* XXX mode? */
2818 gtk_tree_path_free (path);
2822 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2823 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2826 do_prelight (tree_view, node, x, y);
2830 ensure_unprelighted (PsppSheetView *tree_view)
2832 do_prelight (tree_view,
2834 -1000, -1000); /* coords not possibly over an arrow */
2836 g_assert (tree_view->priv->prelight_node < 0);
2840 update_prelight (PsppSheetView *tree_view,
2847 if (tree_view->priv->row_count == 0)
2852 ensure_unprelighted (tree_view);
2856 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2860 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2863 prelight_or_select (tree_view, node, x, y);
2869 /* Our motion arrow is either a box (in the case of the original spot)
2870 * or an arrow. It is expander_size wide.
2893 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2896 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2897 GtkWidget *widget = GTK_WIDGET (tree_view);
2898 GdkBitmap *mask = NULL;
2903 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2904 GdkWindowAttr attributes;
2905 guint attributes_mask;
2908 reorder->left_column == tree_view->priv->drag_column ||
2909 reorder->right_column == tree_view->priv->drag_column)
2910 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2911 else if (reorder->left_column || reorder->right_column)
2913 GdkRectangle visible_rect;
2914 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2915 if (reorder->left_column)
2916 x = reorder->left_column->allocation.x + reorder->left_column->allocation.width;
2918 x = reorder->right_column->allocation.x;
2920 if (x < visible_rect.x)
2921 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2922 else if (x > visible_rect.x + visible_rect.width)
2923 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2925 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2928 /* We want to draw the rectangle over the initial location. */
2929 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2934 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2936 if (tree_view->priv->drag_highlight_window)
2938 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2940 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2943 attributes.window_type = GDK_WINDOW_CHILD;
2944 attributes.wclass = GDK_INPUT_OUTPUT;
2945 attributes.x = tree_view->priv->drag_column_x;
2947 width = attributes.width = tree_view->priv->drag_column->allocation.width;
2948 height = attributes.height = tree_view->priv->drag_column->allocation.height;
2949 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2950 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2951 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2952 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2953 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
2954 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2956 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2957 gc = gdk_gc_new (mask);
2959 gdk_gc_set_foreground (gc, &col);
2960 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2962 gdk_gc_set_foreground(gc, &col);
2963 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
2964 g_object_unref (gc);
2966 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
2968 if (mask) g_object_unref (mask);
2969 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2972 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
2978 width = tree_view->priv->expander_size;
2980 /* Get x, y, width, height of arrow */
2981 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
2982 if (reorder->left_column)
2984 x += reorder->left_column->allocation.x + reorder->left_column->allocation.width - width/2;
2985 height = reorder->left_column->allocation.height;
2989 x += reorder->right_column->allocation.x - width/2;
2990 height = reorder->right_column->allocation.height;
2992 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
2993 height += tree_view->priv->expander_size;
2995 /* Create the new window */
2996 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
2998 if (tree_view->priv->drag_highlight_window)
3000 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3002 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3005 attributes.window_type = GDK_WINDOW_TEMP;
3006 attributes.wclass = GDK_INPUT_OUTPUT;
3007 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3008 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3009 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3010 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3013 attributes.width = width;
3014 attributes.height = height;
3015 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
3016 &attributes, attributes_mask);
3017 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3019 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3020 gc = gdk_gc_new (mask);
3022 gdk_gc_set_foreground (gc, &col);
3023 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3025 /* Draw the 2 arrows as per above */
3027 gdk_gc_set_foreground (gc, &col);
3028 for (i = 0; i < width; i ++)
3030 if (i == (width/2 - 1))
3032 gdk_draw_line (mask, gc, i, j, i, height - j);
3033 if (i < (width/2 - 1))
3038 g_object_unref (gc);
3039 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3041 if (mask) g_object_unref (mask);
3044 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
3045 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3047 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
3048 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3054 width = tree_view->priv->expander_size;
3056 /* Get x, y, width, height of arrow */
3057 width = width/2; /* remember, the arrow only takes half the available width */
3058 gdk_window_get_origin (gtk_widget_get_window (widget), &x, &y);
3059 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3060 x += widget->allocation.width - width;
3062 if (reorder->left_column)
3063 height = reorder->left_column->allocation.height;
3065 height = reorder->right_column->allocation.height;
3067 y -= tree_view->priv->expander_size;
3068 height += 2*tree_view->priv->expander_size;
3070 /* Create the new window */
3071 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
3072 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3074 if (tree_view->priv->drag_highlight_window)
3076 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3078 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3081 attributes.window_type = GDK_WINDOW_TEMP;
3082 attributes.wclass = GDK_INPUT_OUTPUT;
3083 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3084 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3085 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3086 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3089 attributes.width = width;
3090 attributes.height = height;
3091 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3092 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3094 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3095 gc = gdk_gc_new (mask);
3097 gdk_gc_set_foreground (gc, &col);
3098 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3100 /* Draw the 2 arrows as per above */
3102 gdk_gc_set_foreground (gc, &col);
3103 j = tree_view->priv->expander_size;
3104 for (i = 0; i < width; i ++)
3107 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3111 gdk_draw_line (mask, gc, k, j, k, height - j);
3112 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3113 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3116 g_object_unref (gc);
3117 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3119 if (mask) g_object_unref (mask);
3122 tree_view->priv->drag_column_window_state = arrow_type;
3123 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3127 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3128 gdk_window_hide (tree_view->priv->drag_highlight_window);
3132 gdk_window_show (tree_view->priv->drag_highlight_window);
3133 gdk_window_raise (tree_view->priv->drag_highlight_window);
3138 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3139 GdkEventMotion *event)
3143 PsppSheetViewColumn *column;
3144 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3146 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3148 if (event->is_hint || event->window != gtk_widget_get_window (widget))
3149 gtk_widget_get_pointer (widget, &x, NULL);
3153 if (tree_view->priv->hadjustment)
3154 x += tree_view->priv->hadjustment->value;
3156 new_width = pspp_sheet_view_new_column_width (tree_view,
3157 tree_view->priv->drag_pos, &x);
3158 if (x != tree_view->priv->x_drag &&
3159 (new_width != column->fixed_width))
3161 column->use_resized_width = TRUE;
3162 column->resized_width = new_width;
3165 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3167 gtk_widget_queue_resize (widget);
3175 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3177 PsppSheetViewColumnReorder *reorder = NULL;
3181 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3182 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3184 reorder = (PsppSheetViewColumnReorder *) list->data;
3185 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3190 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3193 tree_view->priv->cur_reorder = reorder;
3194 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3198 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3200 GdkRectangle visible_rect;
3205 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3206 y += tree_view->priv->dy;
3208 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3210 /* see if we are near the edge. */
3211 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3214 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3219 value = CLAMP (tree_view->priv->vadjustment->value + offset, 0.0,
3220 tree_view->priv->vadjustment->upper - tree_view->priv->vadjustment->page_size);
3221 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3225 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3227 GdkRectangle visible_rect;
3232 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3234 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3236 /* See if we are near the edge. */
3237 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3240 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3246 value = CLAMP (tree_view->priv->hadjustment->value + offset,
3247 0.0, tree_view->priv->hadjustment->upper - tree_view->priv->hadjustment->page_size);
3248 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3255 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3256 GdkEventMotion *event)
3258 PsppSheetView *tree_view = (PsppSheetView *) widget;
3259 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3263 if ((column == NULL) ||
3264 (event->window != tree_view->priv->drag_window))
3267 /* Handle moving the header */
3268 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3269 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3270 MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width) - column->allocation.width);
3271 gdk_window_move (tree_view->priv->drag_window, x, y);
3273 /* autoscroll, if needed */
3274 pspp_sheet_view_horizontal_autoscroll (tree_view);
3275 /* Update the current reorder position and arrow; */
3276 pspp_sheet_view_update_current_reorder (tree_view);
3282 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3284 remove_scroll_timeout (tree_view);
3285 gtk_grab_remove (GTK_WIDGET (tree_view));
3287 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3289 GtkTreePath *tmp_path;
3291 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3293 /* The anchor path should be set to the start path */
3294 tmp_path = _pspp_sheet_view_find_path (tree_view,
3295 tree_view->priv->rubber_band_start_node);
3297 if (tree_view->priv->anchor)
3298 gtk_tree_row_reference_free (tree_view->priv->anchor);
3300 tree_view->priv->anchor =
3301 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3302 tree_view->priv->model,
3305 gtk_tree_path_free (tmp_path);
3307 /* ... and the cursor to the end path */
3308 tmp_path = _pspp_sheet_view_find_path (tree_view,
3309 tree_view->priv->rubber_band_end_node);
3310 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE, 0); /* XXX mode? */
3311 gtk_tree_path_free (tmp_path);
3313 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3316 /* Clear status variables */
3317 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3318 tree_view->priv->rubber_band_shift = 0;
3319 tree_view->priv->rubber_band_ctrl = 0;
3321 tree_view->priv->rubber_band_start_node = -1;
3322 tree_view->priv->rubber_band_end_node = -1;
3326 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3330 gboolean skip_start,
3333 if (start_node == end_node)
3336 /* We skip the first node and jump inside the loop */
3342 /* Small optimization by assuming insensitive nodes are never
3347 if (tree_view->priv->rubber_band_shift)
3348 pspp_sheet_view_node_select (tree_view, start_node);
3349 else if (tree_view->priv->rubber_band_ctrl)
3351 /* Toggle the selection state */
3352 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3353 pspp_sheet_view_node_unselect (tree_view, start_node);
3355 pspp_sheet_view_node_select (tree_view, start_node);
3358 pspp_sheet_view_node_select (tree_view, start_node);
3362 /* Mirror the above */
3363 if (tree_view->priv->rubber_band_shift)
3364 pspp_sheet_view_node_unselect (tree_view, start_node);
3365 else if (tree_view->priv->rubber_band_ctrl)
3367 /* Toggle the selection state */
3368 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3369 pspp_sheet_view_node_unselect (tree_view, start_node);
3371 pspp_sheet_view_node_select (tree_view, start_node);
3374 pspp_sheet_view_node_unselect (tree_view, start_node);
3377 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3379 if (start_node == end_node)
3384 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3387 /* Ran out of tree */
3390 if (skip_end && start_node == end_node)
3397 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3400 return node * tree_view->priv->fixed_height;
3404 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3408 int fixed_height = tree_view->priv->fixed_height;
3409 if (fixed_height <= 0
3411 || height >= tree_view->priv->row_count * fixed_height)
3418 *new_node = height / fixed_height;
3419 return height % fixed_height;
3424 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3429 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3430 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3432 /* Handle the start area first */
3433 if (tree_view->priv->rubber_band_start_node < 0)
3435 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3442 else if (start_node < tree_view->priv->rubber_band_start_node)
3444 /* New node is above the old one; selection became bigger */
3445 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3447 tree_view->priv->rubber_band_start_node,
3452 else if (start_node > tree_view->priv->rubber_band_start_node)
3454 /* New node is below the old one; selection became smaller */
3455 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3456 tree_view->priv->rubber_band_start_node,
3463 tree_view->priv->rubber_band_start_node = start_node;
3465 /* Next, handle the end area */
3466 if (tree_view->priv->rubber_band_end_node < 0)
3468 /* In the event this happens, start_node was also -1; this case is
3472 else if (end_node < 0)
3474 /* Find the last node in the tree */
3475 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3478 /* Selection reached end of the tree */
3479 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3480 tree_view->priv->rubber_band_end_node,
3486 else if (end_node > tree_view->priv->rubber_band_end_node)
3488 /* New node is below the old one; selection became bigger */
3489 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3490 tree_view->priv->rubber_band_end_node,
3496 else if (end_node < tree_view->priv->rubber_band_end_node)
3498 /* New node is above the old one; selection became smaller */
3499 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3501 tree_view->priv->rubber_band_end_node,
3507 tree_view->priv->rubber_band_end_node = end_node;
3511 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3514 GdkRectangle old_area;
3515 GdkRectangle new_area;
3516 GdkRectangle common;
3517 GdkRegion *invalid_region;
3518 PsppSheetViewColumn *column;
3520 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3521 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3522 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3523 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3525 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3528 y = MAX (y, 0) + tree_view->priv->dy;
3530 new_area.x = MIN (tree_view->priv->press_start_x, x);
3531 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3532 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3533 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3535 invalid_region = gdk_region_rectangle (&old_area);
3536 gdk_region_union_with_rect (invalid_region, &new_area);
3538 gdk_rectangle_intersect (&old_area, &new_area, &common);
3539 if (common.width > 2 && common.height > 2)
3541 GdkRegion *common_region;
3543 /* make sure the border is invalidated */
3549 common_region = gdk_region_rectangle (&common);
3551 gdk_region_subtract (invalid_region, common_region);
3552 gdk_region_destroy (common_region);
3555 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3557 gdk_region_destroy (invalid_region);
3559 tree_view->priv->rubber_band_x = x;
3560 tree_view->priv->rubber_band_y = y;
3561 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3563 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3564 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3565 tree_view->priv->anchor_column,
3568 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3570 pspp_sheet_view_update_rubber_band_selection (tree_view);
3574 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3579 GdkRectangle rubber_rect;
3582 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3583 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3584 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3585 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3587 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3590 cr = gdk_cairo_create (tree_view->priv->bin_window);
3591 cairo_set_line_width (cr, 1.0);
3593 cairo_set_source_rgba (cr,
3594 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3595 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3596 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.,
3599 gdk_cairo_rectangle (cr, &rect);
3603 cairo_set_source_rgb (cr,
3604 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3605 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3606 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.);
3608 cairo_rectangle (cr,
3609 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3610 rubber_rect.width - 1, rubber_rect.height - 1);
3617 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3618 GdkEventMotion *event)
3620 PsppSheetView *tree_view;
3624 tree_view = (PsppSheetView *) widget;
3626 if (tree_view->priv->row_count == 0)
3629 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3631 GdkRectangle background_area, cell_area;
3632 PsppSheetViewColumn *column;
3634 if (find_click (tree_view, event->x, event->y, &node, &column,
3635 &background_area, &cell_area)
3636 && tree_view->priv->focus_column == column
3637 && tree_view->priv->press_start_node == node)
3640 gtk_grab_add (GTK_WIDGET (tree_view));
3641 pspp_sheet_view_update_rubber_band (tree_view);
3643 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3645 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3647 pspp_sheet_view_update_rubber_band (tree_view);
3649 add_scroll_timeout (tree_view);
3652 /* only check for an initiated drag when a button is pressed */
3653 if (tree_view->priv->pressed_button >= 0
3654 && !tree_view->priv->rubber_band_status)
3655 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3657 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3661 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3663 tree_view->priv->event_last_x = event->x;
3664 tree_view->priv->event_last_y = event->y;
3666 prelight_or_select (tree_view, node, event->x, event->y);
3672 pspp_sheet_view_motion (GtkWidget *widget,
3673 GdkEventMotion *event)
3675 PsppSheetView *tree_view;
3677 tree_view = (PsppSheetView *) widget;
3679 /* Resizing a column */
3680 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3681 return pspp_sheet_view_motion_resize_column (widget, event);
3684 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3685 return pspp_sheet_view_motion_drag_column (widget, event);
3687 /* Sanity check it */
3688 if (event->window == tree_view->priv->bin_window)
3689 return pspp_sheet_view_motion_bin_window (widget, event);
3694 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3695 * the tree is empty.
3698 invalidate_empty_focus (PsppSheetView *tree_view)
3702 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3707 area.width = gdk_window_get_width (tree_view->priv->bin_window);
3708 area.height = gdk_window_get_height (tree_view->priv->bin_window);
3709 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3712 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3716 draw_empty_focus (PsppSheetView *tree_view, GdkRectangle *clip_area)
3718 GtkWidget *widget = GTK_WIDGET (tree_view);
3721 if (!gtk_widget_has_focus (widget))
3724 w = gdk_window_get_width (tree_view->priv->bin_window);
3725 h = gdk_window_get_height (tree_view->priv->bin_window);
3731 gtk_paint_focus (gtk_widget_get_style (widget),
3732 tree_view->priv->bin_window,
3733 gtk_widget_get_state (widget),
3741 pspp_sheet_view_draw_vertical_grid_lines (PsppSheetView *tree_view,
3742 GdkEventExpose *event,
3743 gint n_visible_columns,
3747 GList *list = tree_view->priv->columns;
3751 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3752 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3755 /* Only draw the lines for visible rows and columns */
3756 for (list = tree_view->priv->columns; list; list = list->next, i++)
3758 PsppSheetViewColumn *column = list->data;
3760 /* We don't want a line for the last column */
3761 if (i == n_visible_columns - 1)
3764 if (! column->visible)
3767 current_x += column->width;
3769 if (current_x - 1 >= event->area.x
3770 && current_x - 1 < event->area.x + event->area.width)
3773 gdk_draw_line (event->window,
3774 tree_view->priv->grid_line_gc[GTK_WIDGET(tree_view)->state],
3775 current_x - 1, min_y,
3776 current_x - 1, max_y - min_y);
3779 cairo_t *cr = gdk_cairo_create (event->window);
3780 cairo_set_line_width (cr, 1.0);
3781 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
3782 cairo_move_to (cr, current_x - 0.5, min_y);
3783 cairo_line_to (cr, current_x - 0.5 , max_y - min_y);
3792 /* Warning: Very scary function.
3793 * Modify at your own risk
3795 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3796 * FIXME: It's not...
3799 pspp_sheet_view_bin_expose (GtkWidget *widget,
3800 GdkEventExpose *event)
3802 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3807 int drag_highlight = -1;
3810 gint y_offset, cell_offset;
3812 GdkRectangle background_area;
3813 GdkRectangle cell_area;
3815 gint bin_window_width;
3816 gint bin_window_height;
3817 GtkTreePath *cursor_path;
3818 GtkTreePath *drag_dest_path;
3819 GList *first_column, *last_column;
3820 gint vertical_separator;
3821 gint horizontal_separator;
3822 gint focus_line_width;
3823 gboolean allow_rules;
3824 gboolean has_special_cell;
3826 gint n_visible_columns;
3827 gint grid_line_width;
3828 gboolean row_ending_details;
3829 gboolean draw_vgrid_lines, draw_hgrid_lines;
3832 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3834 gtk_widget_style_get (widget,
3835 "horizontal-separator", &horizontal_separator,
3836 "vertical-separator", &vertical_separator,
3837 "allow-rules", &allow_rules,
3838 "focus-line-width", &focus_line_width,
3839 "row-ending-details", &row_ending_details,
3842 if (tree_view->priv->row_count == 0)
3844 draw_empty_focus (tree_view, &event->area);
3848 /* clip event->area to the visible area */
3849 if (event->area.height < 0.5)
3852 validate_visible_area (tree_view);
3854 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, event->area.y);
3858 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3860 gdk_window_get_width (tree_view->priv->bin_window);
3863 gdk_window_get_height (tree_view->priv->bin_window);
3866 if (tree_view->priv->height < bin_window_height)
3868 gtk_paint_flat_box (widget->style,
3875 0, tree_view->priv->height,
3877 bin_window_height - tree_view->priv->height);
3883 /* find the path for the node */
3884 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3885 gtk_tree_model_get_iter (tree_view->priv->model,
3888 gtk_tree_path_free (path);
3891 drag_dest_path = NULL;
3893 if (tree_view->priv->cursor)
3894 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3897 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3899 if (tree_view->priv->drag_dest_row)
3900 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3903 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3907 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3908 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3910 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3911 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3913 if (draw_vgrid_lines || draw_hgrid_lines)
3914 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3916 n_visible_columns = 0;
3917 for (list = tree_view->priv->columns; list; list = list->next)
3919 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3921 n_visible_columns ++;
3924 /* Find the last column */
3925 for (last_column = g_list_last (tree_view->priv->columns);
3926 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
3927 last_column = last_column->prev)
3931 for (first_column = g_list_first (tree_view->priv->columns);
3932 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
3933 first_column = first_column->next)
3936 /* Actually process the expose event. To do this, we want to
3937 * start at the first node of the event, and walk the tree in
3938 * order, drawing each successive node.
3945 gboolean is_first = FALSE;
3946 gboolean is_last = FALSE;
3947 gboolean done = FALSE;
3950 max_height = ROW_HEIGHT (tree_view);
3954 background_area.y = y_offset + event->area.y;
3955 background_area.height = max_height;
3956 max_y = background_area.y + max_height;
3960 if (node == tree_view->priv->prelight_node)
3961 flags |= GTK_CELL_RENDERER_PRELIT;
3963 selected = pspp_sheet_view_node_is_selected (tree_view, node);
3967 if (tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
3969 /* we *need* to set cell data on all cells before the call
3970 * to _has_special_cell, else _has_special_cell() does not
3971 * return a correct value.
3973 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3975 list = (rtl ? list->prev : list->next))
3977 PsppSheetViewColumn *column = list->data;
3978 pspp_sheet_view_column_cell_set_cell_data (column,
3979 tree_view->priv->model,
3983 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
3986 has_special_cell = tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
3988 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3990 list = (rtl ? list->prev : list->next))
3992 PsppSheetViewColumn *column = list->data;
3993 const gchar *detail = NULL;
3994 gboolean selected_column;
3997 if (!column->visible)
4000 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
4001 selected_column = column->selected && column->selectable;
4003 selected_column = TRUE;
4005 if (cell_offset > event->area.x + event->area.width ||
4006 cell_offset + column->width < event->area.x)
4008 cell_offset += column->width;
4012 if (selected && selected_column)
4013 flags |= GTK_CELL_RENDERER_SELECTED;
4015 flags &= ~GTK_CELL_RENDERER_SELECTED;
4017 if (column->show_sort_indicator)
4018 flags |= GTK_CELL_RENDERER_SORTED;
4020 flags &= ~GTK_CELL_RENDERER_SORTED;
4023 flags |= GTK_CELL_RENDERER_FOCUSED;
4025 flags &= ~GTK_CELL_RENDERER_FOCUSED;
4027 background_area.x = cell_offset;
4028 background_area.width = column->width;
4030 cell_area = background_area;
4031 cell_area.y += vertical_separator / 2;
4032 cell_area.x += horizontal_separator / 2;
4033 cell_area.height -= vertical_separator;
4034 cell_area.width -= horizontal_separator;
4036 if (draw_vgrid_lines)
4038 if (list == first_column)
4040 cell_area.width -= grid_line_width / 2;
4042 else if (list == last_column)
4044 cell_area.x += grid_line_width / 2;
4045 cell_area.width -= grid_line_width / 2;
4049 cell_area.x += grid_line_width / 2;
4050 cell_area.width -= grid_line_width;
4054 if (draw_hgrid_lines)
4056 cell_area.y += grid_line_width / 2;
4057 cell_area.height -= grid_line_width;
4060 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
4062 cell_offset += column->width;
4066 pspp_sheet_view_column_cell_set_cell_data (column,
4067 tree_view->priv->model,
4070 /* Select the detail for drawing the cell. relevant
4071 * factors are parity, sortedness, and whether to
4074 if (allow_rules && tree_view->priv->has_rules)
4076 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4077 n_visible_columns >= 3)
4080 detail = "cell_odd_ruled_sorted";
4082 detail = "cell_even_ruled_sorted";
4087 detail = "cell_odd_ruled";
4089 detail = "cell_even_ruled";
4094 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4095 n_visible_columns >= 3)
4098 detail = "cell_odd_sorted";
4100 detail = "cell_even_sorted";
4105 detail = "cell_odd";
4107 detail = "cell_even";
4113 if (widget->state == GTK_STATE_INSENSITIVE)
4114 state = GTK_STATE_INSENSITIVE;
4115 else if (flags & GTK_CELL_RENDERER_SELECTED)
4116 state = GTK_STATE_SELECTED;
4118 state = GTK_STATE_NORMAL;
4120 /* Draw background */
4121 if (row_ending_details)
4123 char new_detail[128];
4125 is_first = (rtl ? !list->next : !list->prev);
4126 is_last = (rtl ? !list->prev : !list->next);
4128 /* (I don't like the snprintfs either, but couldn't find a
4131 if (is_first && is_last)
4132 g_snprintf (new_detail, 127, "%s", detail);
4134 g_snprintf (new_detail, 127, "%s_start", detail);
4136 g_snprintf (new_detail, 127, "%s_end", detail);
4138 g_snprintf (new_detail, 128, "%s_middle", detail);
4140 gtk_paint_flat_box (widget->style,
4149 background_area.width,
4150 background_area.height);
4154 gtk_paint_flat_box (widget->style,
4163 background_area.width,
4164 background_area.height);
4167 if (draw_hgrid_lines)
4169 cairo_t *cr = gdk_cairo_create (event->window);
4170 cairo_set_line_width (cr, 1.0);
4171 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
4173 if (background_area.y >= 0)
4176 gdk_draw_line (event->window,
4177 tree_view->priv->grid_line_gc[widget->state],
4178 background_area.x, background_area.y,
4179 background_area.x + background_area.width,
4182 cairo_move_to (cr, background_area.x, background_area.y - 0.5);
4183 cairo_line_to (cr, background_area.x + background_area.width,
4184 background_area.y - 0.5);
4188 if (y_offset + max_height >= event->area.height - 0.5)
4191 gdk_draw_line (event->window,
4192 tree_view->priv->grid_line_gc[widget->state],
4193 background_area.x, background_area.y + max_height,
4194 background_area.x + background_area.width,
4195 background_area.y + max_height);
4198 cairo_move_to (cr, background_area.x, background_area.y + max_height - 0.5);
4199 cairo_line_to (cr, background_area.x + background_area.width,
4200 background_area.y + max_height - 0.5);
4207 _pspp_sheet_view_column_cell_render (column,
4214 if (node == cursor && has_special_cell &&
4215 ((column == tree_view->priv->focus_column &&
4216 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4217 gtk_widget_has_focus (widget)) ||
4218 (column == tree_view->priv->edited_column)))
4220 _pspp_sheet_view_column_cell_draw_focus (column,
4228 cell_offset += column->width;
4231 if (cell_offset < event->area.x)
4233 gtk_paint_flat_box (widget->style,
4242 event->area.x - cell_offset,
4243 background_area.height);
4246 if (node == drag_highlight)
4248 /* Draw indicator for the drop
4250 gint highlight_y = -1;
4254 switch (tree_view->priv->drag_dest_pos)
4256 case PSPP_SHEET_VIEW_DROP_BEFORE:
4257 highlight_y = background_area.y - 1;
4258 if (highlight_y < 0)
4262 case PSPP_SHEET_VIEW_DROP_AFTER:
4263 highlight_y = background_area.y + background_area.height - 1;
4266 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4267 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4268 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4272 width = gdk_window_get_width (tree_view->priv->bin_window);
4274 if (row_ending_details)
4275 gtk_paint_focus (widget->style,
4276 tree_view->priv->bin_window,
4277 gtk_widget_get_state (widget),
4281 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4282 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4283 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4284 - focus_line_width / 2,
4285 width, ROW_HEIGHT (tree_view)
4286 - focus_line_width + 1);
4288 gtk_paint_focus (widget->style,
4289 tree_view->priv->bin_window,
4290 gtk_widget_get_state (widget),
4293 "treeview-drop-indicator",
4294 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4295 - focus_line_width / 2,
4296 width, ROW_HEIGHT (tree_view)
4297 - focus_line_width + 1);
4302 if (highlight_y >= 0)
4304 gdk_draw_line (event->window,
4305 widget->style->fg_gc[gtk_widget_get_state (widget)],
4308 rtl ? 0 : bin_window_width,
4314 /* draw the big row-spanning focus rectangle, if needed */
4315 if (!has_special_cell && node == cursor &&
4316 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4317 gtk_widget_has_focus (widget))
4319 gint tmp_y, tmp_height;
4321 GtkStateType focus_rect_state;
4324 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4325 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4326 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4329 width = gdk_window_get_width (tree_view->priv->bin_window);
4331 if (draw_hgrid_lines)
4333 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4334 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4338 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4339 tmp_height = ROW_HEIGHT (tree_view);
4342 if (row_ending_details)
4343 gtk_paint_focus (widget->style,
4344 tree_view->priv->bin_window,
4349 ? (is_last ? "treeview" : "treeview-left" )
4350 : (is_last ? "treeview-right" : "treeview-middle" )),
4354 gtk_paint_focus (widget->style,
4355 tree_view->priv->bin_window,
4364 y_offset += max_height;
4368 node = pspp_sheet_view_node_next (tree_view, node);
4371 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4375 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4382 while (y_offset < event->area.height);
4385 pspp_sheet_view_draw_vertical_grid_lines (tree_view, event, n_visible_columns,
4388 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4390 GdkRectangle *rectangles;
4393 gdk_region_get_rectangles (event->region,
4397 while (n_rectangles--)
4398 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4400 g_free (rectangles);
4404 gtk_tree_path_free (cursor_path);
4407 gtk_tree_path_free (drag_dest_path);
4413 pspp_sheet_view_expose (GtkWidget *widget,
4414 GdkEventExpose *event)
4416 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4418 if (event->window == tree_view->priv->bin_window)
4423 retval = pspp_sheet_view_bin_expose (widget, event);
4425 /* We can't just chain up to Container::expose as it will try to send the
4426 * event to the headers, so we handle propagating it to our children
4427 * (eg. widgets being edited) ourselves.
4429 tmp_list = tree_view->priv->children;
4432 PsppSheetViewChild *child = tmp_list->data;
4433 tmp_list = tmp_list->next;
4435 gtk_container_propagate_expose (GTK_CONTAINER (tree_view), child->widget, event);
4441 else if (event->window == tree_view->priv->header_window)
4443 gint n_visible_columns;
4446 gtk_paint_flat_box (widget->style,
4456 event->area.height);
4458 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4460 PsppSheetViewColumn *column = list->data;
4462 if (column == tree_view->priv->drag_column || !column->visible)
4465 if (span_intersects (column->allocation.x, column->allocation.width,
4466 event->area.x, event->area.width)
4467 && column->button != NULL)
4468 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4469 column->button, event);
4472 n_visible_columns = 0;
4473 for (list = tree_view->priv->columns; list; list = list->next)
4475 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4477 n_visible_columns ++;
4479 pspp_sheet_view_draw_vertical_grid_lines (tree_view,
4483 event->area.height);
4485 else if (event->window == tree_view->priv->drag_window)
4487 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4488 tree_view->priv->drag_column->button,
4502 /* returns 0x1 when no column has been found -- yes it's hackish */
4503 static PsppSheetViewColumn *
4504 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4505 PsppSheetViewColumn *column,
4508 PsppSheetViewColumn *left_column = NULL;
4509 PsppSheetViewColumn *cur_column = NULL;
4512 if (!column->reorderable)
4513 return (PsppSheetViewColumn *)0x1;
4515 switch (drop_position)
4518 /* find first column where we can drop */
4519 tmp_list = tree_view->priv->columns;
4520 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4521 return (PsppSheetViewColumn *)0x1;
4525 g_assert (tmp_list);
4527 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4528 tmp_list = tmp_list->next;
4530 if (left_column && left_column->visible == FALSE)
4533 if (!tree_view->priv->column_drop_func)
4536 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4538 left_column = cur_column;
4545 if (!tree_view->priv->column_drop_func)
4548 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4551 return (PsppSheetViewColumn *)0x1;
4555 /* find first column after column where we can drop */
4556 tmp_list = tree_view->priv->columns;
4558 for (; tmp_list; tmp_list = tmp_list->next)
4559 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4562 if (!tmp_list || !tmp_list->next)
4563 return (PsppSheetViewColumn *)0x1;
4565 tmp_list = tmp_list->next;
4566 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4567 tmp_list = tmp_list->next;
4571 g_assert (tmp_list);
4573 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4574 tmp_list = tmp_list->next;
4576 if (left_column && left_column->visible == FALSE)
4578 left_column = cur_column;
4580 tmp_list = tmp_list->next;
4584 if (!tree_view->priv->column_drop_func)
4587 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4589 left_column = cur_column;
4596 if (!tree_view->priv->column_drop_func)
4599 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4602 return (PsppSheetViewColumn *)0x1;
4606 /* find first column before column where we can drop */
4607 tmp_list = tree_view->priv->columns;
4609 for (; tmp_list; tmp_list = tmp_list->next)
4610 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4613 if (!tmp_list || !tmp_list->prev)
4614 return (PsppSheetViewColumn *)0x1;
4616 tmp_list = tmp_list->prev;
4617 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4618 tmp_list = tmp_list->prev;
4622 g_assert (tmp_list);
4624 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4626 if (left_column && !left_column->visible)
4628 /*if (!tmp_list->prev)
4629 return (PsppSheetViewColumn *)0x1;
4632 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4633 tmp_list = tmp_list->prev->prev;
4636 cur_column = left_column;
4638 tmp_list = tmp_list->prev;
4642 if (!tree_view->priv->column_drop_func)
4645 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4648 cur_column = left_column;
4649 tmp_list = tmp_list->prev;
4652 if (!tree_view->priv->column_drop_func)
4655 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4658 return (PsppSheetViewColumn *)0x1;
4662 /* same as DROP_HOME case, but doing it backwards */
4663 tmp_list = g_list_last (tree_view->priv->columns);
4666 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4667 return (PsppSheetViewColumn *)0x1;
4671 g_assert (tmp_list);
4673 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4675 if (left_column && !left_column->visible)
4677 cur_column = left_column;
4678 tmp_list = tmp_list->prev;
4681 if (!tree_view->priv->column_drop_func)
4684 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4687 cur_column = left_column;
4688 tmp_list = tmp_list->prev;
4691 if (!tree_view->priv->column_drop_func)
4694 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4697 return (PsppSheetViewColumn *)0x1;
4701 return (PsppSheetViewColumn *)0x1;
4705 pspp_sheet_view_key_press (GtkWidget *widget,
4708 PsppSheetView *tree_view = (PsppSheetView *) widget;
4710 if (tree_view->priv->rubber_band_status)
4712 if (event->keyval == GDK_Escape)
4713 pspp_sheet_view_stop_rubber_band (tree_view);
4718 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4720 if (event->keyval == GDK_Escape)
4722 tree_view->priv->cur_reorder = NULL;
4723 pspp_sheet_view_button_release_drag_column (widget, NULL);
4728 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4730 GList *focus_column;
4733 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4735 for (focus_column = tree_view->priv->columns;
4737 focus_column = focus_column->next)
4739 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4741 if (column->button && gtk_widget_has_focus (column->button))
4746 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4747 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4748 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4750 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4752 if (!column->resizable)
4754 gtk_widget_error_bell (widget);
4758 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4759 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4761 gint old_width = column->resized_width;
4763 column->resized_width = MAX (column->resized_width,
4765 column->resized_width -= 2;
4766 if (column->resized_width < 0)
4767 column->resized_width = 0;
4769 if (column->min_width == -1)
4770 column->resized_width = MAX (column->button_request,
4771 column->resized_width);
4773 column->resized_width = MAX (column->min_width,
4774 column->resized_width);
4776 if (column->max_width != -1)
4777 column->resized_width = MIN (column->resized_width,
4780 column->use_resized_width = TRUE;
4782 if (column->resized_width != old_width)
4783 gtk_widget_queue_resize (widget);
4785 gtk_widget_error_bell (widget);
4787 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4788 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4790 gint old_width = column->resized_width;
4792 column->resized_width = MAX (column->resized_width,
4794 column->resized_width += 2;
4796 if (column->max_width != -1)
4797 column->resized_width = MIN (column->resized_width,
4800 column->use_resized_width = TRUE;
4802 if (column->resized_width != old_width)
4803 gtk_widget_queue_resize (widget);
4805 gtk_widget_error_bell (widget);
4812 (event->state & GDK_MOD1_MASK) &&
4813 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4814 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4815 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4816 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4818 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4820 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4821 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4823 PsppSheetViewColumn *col;
4824 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4825 if (col != (PsppSheetViewColumn *)0x1)
4826 pspp_sheet_view_move_column_after (tree_view, column, col);
4828 gtk_widget_error_bell (widget);
4830 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4831 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4833 PsppSheetViewColumn *col;
4834 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4835 if (col != (PsppSheetViewColumn *)0x1)
4836 pspp_sheet_view_move_column_after (tree_view, column, col);
4838 gtk_widget_error_bell (widget);
4840 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4842 PsppSheetViewColumn *col;
4843 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4844 if (col != (PsppSheetViewColumn *)0x1)
4845 pspp_sheet_view_move_column_after (tree_view, column, col);
4847 gtk_widget_error_bell (widget);
4849 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4851 PsppSheetViewColumn *col;
4852 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4853 if (col != (PsppSheetViewColumn *)0x1)
4854 pspp_sheet_view_move_column_after (tree_view, column, col);
4856 gtk_widget_error_bell (widget);
4863 /* Chain up to the parent class. It handles the keybindings. */
4864 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4867 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4869 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4873 /* We pass the event to the search_entry. If its text changes, then we start
4874 * the typeahead find capabilities. */
4875 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4876 && tree_view->priv->enable_search
4877 && !tree_view->priv->search_custom_entry_set)
4879 GdkEvent *new_event;
4881 const char *new_text;
4884 gboolean text_modified;
4885 gulong popup_menu_id;
4887 pspp_sheet_view_ensure_interactive_directory (tree_view);
4889 /* Make a copy of the current text */
4890 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4891 new_event = gdk_event_copy ((GdkEvent *) event);
4892 g_object_unref (((GdkEventKey *) new_event)->window);
4893 ((GdkEventKey *) new_event)->window = g_object_ref (tree_view->priv->search_window->window);
4894 gtk_widget_realize (tree_view->priv->search_window);
4896 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4897 "popup-menu", G_CALLBACK (gtk_true),
4900 /* Move the entry off screen */
4901 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4902 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4903 gdk_screen_get_width (screen) + 1,
4904 gdk_screen_get_height (screen) + 1);
4905 gtk_widget_show (tree_view->priv->search_window);
4907 /* Send the event to the window. If the preedit_changed signal is emitted
4908 * during this event, we will set priv->imcontext_changed */
4909 tree_view->priv->imcontext_changed = FALSE;
4910 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4911 gdk_event_free (new_event);
4912 gtk_widget_hide (tree_view->priv->search_window);
4914 g_signal_handler_disconnect (tree_view->priv->search_entry,
4917 /* We check to make sure that the entry tried to handle the text, and that
4918 * the text has changed.
4920 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4921 text_modified = strcmp (old_text, new_text) != 0;
4923 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4924 (retval && text_modified)) /* ...or the text was modified */
4926 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4928 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4933 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
4943 pspp_sheet_view_key_release (GtkWidget *widget,
4946 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4948 if (tree_view->priv->rubber_band_status)
4951 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
4954 /* FIXME Is this function necessary? Can I get an enter_notify event
4955 * w/o either an expose event or a mouse motion event?
4958 pspp_sheet_view_enter_notify (GtkWidget *widget,
4959 GdkEventCrossing *event)
4961 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4965 /* Sanity check it */
4966 if (event->window != tree_view->priv->bin_window)
4969 if (tree_view->priv->row_count == 0)
4972 if (event->mode == GDK_CROSSING_GRAB ||
4973 event->mode == GDK_CROSSING_GTK_GRAB ||
4974 event->mode == GDK_CROSSING_GTK_UNGRAB ||
4975 event->mode == GDK_CROSSING_STATE_CHANGED)
4978 /* find the node internally */
4979 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
4982 pspp_sheet_view_find_offset (tree_view, new_y, &node);
4984 tree_view->priv->event_last_x = event->x;
4985 tree_view->priv->event_last_y = event->y;
4987 prelight_or_select (tree_view, node, event->x, event->y);
4993 pspp_sheet_view_leave_notify (GtkWidget *widget,
4994 GdkEventCrossing *event)
4996 PsppSheetView *tree_view;
4998 if (event->mode == GDK_CROSSING_GRAB)
5001 tree_view = PSPP_SHEET_VIEW (widget);
5003 if (tree_view->priv->prelight_node >= 0)
5004 _pspp_sheet_view_queue_draw_node (tree_view,
5005 tree_view->priv->prelight_node,
5008 tree_view->priv->event_last_x = -10000;
5009 tree_view->priv->event_last_y = -10000;
5011 prelight_or_select (tree_view,
5013 -1000, -1000); /* coords not possibly over an arrow */
5020 pspp_sheet_view_focus_out (GtkWidget *widget,
5021 GdkEventFocus *event)
5023 PsppSheetView *tree_view;
5025 tree_view = PSPP_SHEET_VIEW (widget);
5027 gtk_widget_queue_draw (widget);
5029 /* destroy interactive search dialog */
5030 if (tree_view->priv->search_window)
5031 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
5037 /* Incremental Reflow
5041 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
5046 y = pspp_sheet_view_node_find_offset (tree_view, node)
5047 - tree_view->priv->vadjustment->value
5048 + TREE_VIEW_HEADER_HEIGHT (tree_view);
5050 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
5052 GTK_WIDGET (tree_view)->allocation.width,
5053 tree_view->priv->fixed_height);
5057 node_is_visible (PsppSheetView *tree_view,
5063 y = pspp_sheet_view_node_find_offset (tree_view, node);
5064 height = ROW_HEIGHT (tree_view);
5066 if (y >= tree_view->priv->vadjustment->value &&
5067 y + height <= (tree_view->priv->vadjustment->value
5068 + tree_view->priv->vadjustment->page_size))
5074 /* Returns the row height. */
5076 validate_row (PsppSheetView *tree_view,
5081 PsppSheetViewColumn *column;
5082 GList *list, *first_column, *last_column;
5084 gint horizontal_separator;
5085 gint vertical_separator;
5086 gint focus_line_width;
5087 gboolean draw_vgrid_lines, draw_hgrid_lines;
5089 gint grid_line_width;
5090 gboolean wide_separators;
5091 gint separator_height;
5093 gtk_widget_style_get (GTK_WIDGET (tree_view),
5094 "focus-padding", &focus_pad,
5095 "focus-line-width", &focus_line_width,
5096 "horizontal-separator", &horizontal_separator,
5097 "vertical-separator", &vertical_separator,
5098 "grid-line-width", &grid_line_width,
5099 "wide-separators", &wide_separators,
5100 "separator-height", &separator_height,
5104 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5105 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5107 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5108 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5110 for (last_column = g_list_last (tree_view->priv->columns);
5111 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5112 last_column = last_column->prev)
5115 for (first_column = g_list_first (tree_view->priv->columns);
5116 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5117 first_column = first_column->next)
5120 for (list = tree_view->priv->columns; list; list = list->next)
5125 column = list->data;
5127 if (! column->visible)
5130 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5131 pspp_sheet_view_column_cell_get_size (column,
5133 &tmp_width, &tmp_height);
5135 tmp_height += vertical_separator;
5136 height = MAX (height, tmp_height);
5138 tmp_width = tmp_width + horizontal_separator;
5140 if (draw_vgrid_lines)
5142 if (list->data == first_column || list->data == last_column)
5143 tmp_width += grid_line_width / 2.0;
5145 tmp_width += grid_line_width;
5148 if (tmp_width > column->requested_width)
5149 column->requested_width = tmp_width;
5152 if (draw_hgrid_lines)
5153 height += grid_line_width;
5155 tree_view->priv->post_validation_flag = TRUE;
5161 validate_visible_area (PsppSheetView *tree_view)
5163 GtkTreePath *path = NULL;
5164 GtkTreePath *above_path = NULL;
5167 gboolean size_changed = FALSE;
5169 gint area_above = 0;
5170 gint area_below = 0;
5172 if (tree_view->priv->row_count == 0)
5175 if (tree_view->priv->scroll_to_path == NULL)
5178 total_height = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5180 if (total_height == 0)
5183 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5186 /* we are going to scroll, and will update dy */
5187 _pspp_sheet_view_find_node (tree_view, path, &node);
5188 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5190 if (tree_view->priv->scroll_to_use_align)
5192 gint height = ROW_HEIGHT (tree_view);
5193 area_above = (total_height - height) *
5194 tree_view->priv->scroll_to_row_align;
5195 area_below = total_height - area_above - height;
5196 area_above = MAX (area_above, 0);
5197 area_below = MAX (area_below, 0);
5202 * 1) row not visible
5206 gint height = ROW_HEIGHT (tree_view);
5208 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5210 if (dy >= tree_view->priv->vadjustment->value &&
5211 dy + height <= (tree_view->priv->vadjustment->value
5212 + tree_view->priv->vadjustment->page_size))
5214 /* row visible: keep the row at the same position */
5215 area_above = dy - tree_view->priv->vadjustment->value;
5216 area_below = (tree_view->priv->vadjustment->value +
5217 tree_view->priv->vadjustment->page_size)
5222 /* row not visible */
5224 && dy + height <= tree_view->priv->vadjustment->page_size)
5226 /* row at the beginning -- fixed */
5228 area_below = tree_view->priv->vadjustment->page_size
5229 - area_above - height;
5231 else if (dy >= (tree_view->priv->vadjustment->upper -
5232 tree_view->priv->vadjustment->page_size))
5234 /* row at the end -- fixed */
5235 area_above = dy - (tree_view->priv->vadjustment->upper -
5236 tree_view->priv->vadjustment->page_size);
5237 area_below = tree_view->priv->vadjustment->page_size -
5238 area_above - height;
5242 area_above = tree_view->priv->vadjustment->page_size - height;
5248 /* row somewhere in the middle, bring it to the top
5252 area_below = total_height - height;
5258 /* the scroll to isn't valid; ignore it.
5261 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5262 tree_view->priv->scroll_to_path = NULL;
5266 above_path = gtk_tree_path_copy (path);
5268 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5269 * backwards is much slower then forward, as there is no iter_prev function.
5270 * We go forwards first in case we run out of tree. Then we go backwards to
5273 while (node >= 0 && area_below > 0)
5275 gboolean done = FALSE;
5278 node = pspp_sheet_view_node_next (tree_view, node);
5281 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5283 gtk_tree_path_next (path);
5286 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5296 area_below -= ROW_HEIGHT (tree_view);
5298 gtk_tree_path_free (path);
5300 /* If we ran out of tree, and have extra area_below left, we need to add it
5303 area_above += area_below;
5305 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5307 /* We walk backwards */
5308 while (area_above > 0)
5310 node = pspp_sheet_view_node_prev (tree_view, node);
5312 /* Always find the new path in the tree. We cannot just assume
5313 * a gtk_tree_path_prev() is enough here, as there might be children
5314 * in between this node and the previous sibling node. If this
5315 * appears to be a performance hotspot in profiles, we can look into
5316 * intrigate logic for keeping path, node and iter in sync like
5317 * we do for forward walks. (Which will be hard because of the lacking
5324 gtk_tree_path_free (above_path);
5325 above_path = _pspp_sheet_view_find_path (tree_view, node);
5327 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5329 area_above -= ROW_HEIGHT (tree_view);
5332 /* set the dy here to scroll to the path,
5333 * and sync the top row accordingly
5335 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5336 pspp_sheet_view_top_row_to_dy (tree_view);
5338 /* update width/height and queue a resize */
5341 GtkRequisition requisition;
5343 /* We temporarily guess a size, under the assumption that it will be the
5344 * same when we get our next size_allocate. If we don't do this, we'll be
5345 * in an inconsistent state if we call top_row_to_dy. */
5347 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5348 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5349 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5350 gtk_adjustment_changed (tree_view->priv->hadjustment);
5351 gtk_adjustment_changed (tree_view->priv->vadjustment);
5352 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5355 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5356 tree_view->priv->scroll_to_path = NULL;
5359 gtk_tree_path_free (above_path);
5361 if (tree_view->priv->scroll_to_column)
5363 tree_view->priv->scroll_to_column = NULL;
5365 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5369 initialize_fixed_height_mode (PsppSheetView *tree_view)
5371 if (!tree_view->priv->row_count)
5374 if (tree_view->priv->fixed_height_set)
5377 if (tree_view->priv->fixed_height < 0)
5384 path = _pspp_sheet_view_find_path (tree_view, node);
5385 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5387 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5389 gtk_tree_path_free (path);
5391 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5395 /* Our strategy for finding nodes to validate is a little convoluted. We find
5396 * the left-most uninvalidated node. We then try walking right, validating
5397 * nodes. Once we find a valid node, we repeat the previous process of finding
5398 * the first invalid node.
5402 validate_rows_handler (PsppSheetView *tree_view)
5404 initialize_fixed_height_mode (tree_view);
5405 if (tree_view->priv->validate_rows_timer)
5407 g_source_remove (tree_view->priv->validate_rows_timer);
5408 tree_view->priv->validate_rows_timer = 0;
5415 do_presize_handler (PsppSheetView *tree_view)
5417 GtkRequisition requisition;
5419 validate_visible_area (tree_view);
5420 tree_view->priv->presize_handler_timer = 0;
5422 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5425 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5427 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5428 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5429 gtk_adjustment_changed (tree_view->priv->hadjustment);
5430 gtk_adjustment_changed (tree_view->priv->vadjustment);
5431 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5437 presize_handler_callback (gpointer data)
5439 do_presize_handler (PSPP_SHEET_VIEW (data));
5445 install_presize_handler (PsppSheetView *tree_view)
5447 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5450 if (! tree_view->priv->presize_handler_timer)
5452 tree_view->priv->presize_handler_timer =
5453 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5455 if (! tree_view->priv->validate_rows_timer)
5457 tree_view->priv->validate_rows_timer =
5458 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5463 scroll_sync_handler (PsppSheetView *tree_view)
5465 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
5466 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5467 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5468 pspp_sheet_view_top_row_to_dy (tree_view);
5470 pspp_sheet_view_dy_to_top_row (tree_view);
5472 tree_view->priv->scroll_sync_timer = 0;
5478 install_scroll_sync_handler (PsppSheetView *tree_view)
5480 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5483 if (!tree_view->priv->scroll_sync_timer)
5485 tree_view->priv->scroll_sync_timer =
5486 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5491 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5495 gtk_tree_row_reference_free (tree_view->priv->top_row);
5499 tree_view->priv->top_row = NULL;
5500 tree_view->priv->top_row_dy = 0;
5504 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5505 tree_view->priv->top_row_dy = offset;
5509 /* Always call this iff dy is in the visible range. If the tree is empty, then
5510 * it's set to be NULL, and top_row_dy is 0;
5513 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5519 if (tree_view->priv->row_count == 0)
5521 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5525 offset = pspp_sheet_view_find_offset (tree_view,
5526 tree_view->priv->dy,
5531 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5535 path = _pspp_sheet_view_find_path (tree_view, node);
5536 pspp_sheet_view_set_top_row (tree_view, path, offset);
5537 gtk_tree_path_free (path);
5543 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5549 /* Avoid recursive calls */
5550 if (tree_view->priv->in_top_row_to_dy)
5553 if (tree_view->priv->top_row)
5554 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5561 _pspp_sheet_view_find_node (tree_view, path, &node);
5564 gtk_tree_path_free (path);
5568 /* keep dy and set new toprow */
5569 gtk_tree_row_reference_free (tree_view->priv->top_row);
5570 tree_view->priv->top_row = NULL;
5571 tree_view->priv->top_row_dy = 0;
5572 /* DO NOT install the idle handler */
5573 pspp_sheet_view_dy_to_top_row (tree_view);
5577 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5579 /* new top row -- do NOT install the idle handler */
5580 pspp_sheet_view_dy_to_top_row (tree_view);
5584 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5585 new_dy += tree_view->priv->top_row_dy;
5587 if (new_dy + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
5588 new_dy = tree_view->priv->height - tree_view->priv->vadjustment->page_size;
5590 new_dy = MAX (0, new_dy);
5592 tree_view->priv->in_top_row_to_dy = TRUE;
5593 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5594 tree_view->priv->in_top_row_to_dy = FALSE;
5599 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5601 install_presize_handler (tree_view);
5607 set_source_row (GdkDragContext *context,
5608 GtkTreeModel *model,
5609 GtkTreePath *source_row)
5611 g_object_set_data_full (G_OBJECT (context),
5612 "gtk-tree-view-source-row",
5613 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5614 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5618 get_source_row (GdkDragContext *context)
5620 GtkTreeRowReference *ref =
5621 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5624 return gtk_tree_row_reference_get_path (ref);
5631 GtkTreeRowReference *dest_row;
5632 guint path_down_mode : 1;
5633 guint empty_view_drop : 1;
5634 guint drop_append_mode : 1;
5639 dest_row_free (gpointer data)
5641 DestRow *dr = (DestRow *)data;
5643 gtk_tree_row_reference_free (dr->dest_row);
5644 g_slice_free (DestRow, dr);
5648 set_dest_row (GdkDragContext *context,
5649 GtkTreeModel *model,
5650 GtkTreePath *dest_row,
5651 gboolean path_down_mode,
5652 gboolean empty_view_drop,
5653 gboolean drop_append_mode)
5659 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5664 dr = g_slice_new (DestRow);
5666 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5667 dr->path_down_mode = path_down_mode != FALSE;
5668 dr->empty_view_drop = empty_view_drop != FALSE;
5669 dr->drop_append_mode = drop_append_mode != FALSE;
5671 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5672 dr, (GDestroyNotify) dest_row_free);
5676 get_dest_row (GdkDragContext *context,
5677 gboolean *path_down_mode)
5680 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5684 GtkTreePath *path = NULL;
5687 *path_down_mode = dr->path_down_mode;
5690 path = gtk_tree_row_reference_get_path (dr->dest_row);
5691 else if (dr->empty_view_drop)
5692 path = gtk_tree_path_new_from_indices (0, -1);
5696 if (path && dr->drop_append_mode)
5697 gtk_tree_path_next (path);
5705 /* Get/set whether drag_motion requested the drag data and
5706 * drag_data_received should thus not actually insert the data,
5707 * since the data doesn't result from a drop.
5710 set_status_pending (GdkDragContext *context,
5711 GdkDragAction suggested_action)
5713 g_object_set_data (G_OBJECT (context),
5714 "gtk-tree-view-status-pending",
5715 GINT_TO_POINTER (suggested_action));
5718 static GdkDragAction
5719 get_status_pending (GdkDragContext *context)
5721 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5722 "gtk-tree-view-status-pending"));
5725 static TreeViewDragInfo*
5726 get_info (PsppSheetView *tree_view)
5728 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5732 destroy_info (TreeViewDragInfo *di)
5734 g_slice_free (TreeViewDragInfo, di);
5737 static TreeViewDragInfo*
5738 ensure_info (PsppSheetView *tree_view)
5740 TreeViewDragInfo *di;
5742 di = get_info (tree_view);
5746 di = g_slice_new0 (TreeViewDragInfo);
5748 g_object_set_data_full (G_OBJECT (tree_view),
5749 "gtk-tree-view-drag-info",
5751 (GDestroyNotify) destroy_info);
5758 remove_info (PsppSheetView *tree_view)
5760 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5765 drag_scan_timeout (gpointer data)
5767 PsppSheetView *tree_view;
5769 GdkModifierType state;
5770 GtkTreePath *path = NULL;
5771 PsppSheetViewColumn *column = NULL;
5772 GdkRectangle visible_rect;
5774 GDK_THREADS_ENTER ();
5776 tree_view = PSPP_SHEET_VIEW (data);
5778 gdk_window_get_pointer (tree_view->priv->bin_window,
5781 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5783 /* See if we are near the edge. */
5784 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5785 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5786 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5787 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5789 pspp_sheet_view_get_path_at_pos (tree_view,
5790 tree_view->priv->bin_window,
5799 pspp_sheet_view_scroll_to_cell (tree_view,
5805 gtk_tree_path_free (path);
5809 GDK_THREADS_LEAVE ();
5816 add_scroll_timeout (PsppSheetView *tree_view)
5818 if (tree_view->priv->scroll_timeout == 0)
5820 tree_view->priv->scroll_timeout =
5821 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5826 remove_scroll_timeout (PsppSheetView *tree_view)
5828 if (tree_view->priv->scroll_timeout != 0)
5830 g_source_remove (tree_view->priv->scroll_timeout);
5831 tree_view->priv->scroll_timeout = 0;
5836 check_model_dnd (GtkTreeModel *model,
5837 GType required_iface,
5838 const gchar *signal)
5840 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5842 g_warning ("You must override the default '%s' handler "
5843 "on PsppSheetView when using models that don't support "
5844 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5845 "is to connect to '%s' and call "
5846 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5847 "the default handler from running. Look at the source code "
5848 "for the default handler in gtktreeview.c to get an idea what "
5849 "your handler should do. (gtktreeview.c is in the GTK source "
5850 "code.) If you're using GTK from a language other than C, "
5851 "there may be a more natural way to override default handlers, e.g. via derivation.",
5852 signal, g_type_name (required_iface), signal);
5860 scroll_row_timeout (gpointer data)
5862 PsppSheetView *tree_view = data;
5864 pspp_sheet_view_horizontal_autoscroll (tree_view);
5865 pspp_sheet_view_vertical_autoscroll (tree_view);
5867 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5868 pspp_sheet_view_update_rubber_band (tree_view);
5873 /* Returns TRUE if event should not be propagated to parent widgets */
5875 set_destination_row (PsppSheetView *tree_view,
5876 GdkDragContext *context,
5877 /* coordinates relative to the widget */
5880 GdkDragAction *suggested_action,
5883 GtkTreePath *path = NULL;
5884 PsppSheetViewDropPosition pos;
5885 PsppSheetViewDropPosition old_pos;
5886 TreeViewDragInfo *di;
5888 GtkTreePath *old_dest_path = NULL;
5889 gboolean can_drop = FALSE;
5891 *suggested_action = 0;
5894 widget = GTK_WIDGET (tree_view);
5896 di = get_info (tree_view);
5898 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5900 /* someone unset us as a drag dest, note that if
5901 * we return FALSE drag_leave isn't called
5904 pspp_sheet_view_set_drag_dest_row (tree_view,
5906 PSPP_SHEET_VIEW_DROP_BEFORE);
5908 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5910 return FALSE; /* no longer a drop site */
5913 *target = gtk_drag_dest_find_target (widget, context,
5914 gtk_drag_dest_get_target_list (widget));
5915 if (*target == GDK_NONE)
5920 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5926 GtkTreeModel *model;
5928 /* the row got dropped on empty space, let's setup a special case
5932 gtk_tree_path_free (path);
5934 model = pspp_sheet_view_get_model (tree_view);
5936 n_children = gtk_tree_model_iter_n_children (model, NULL);
5939 pos = PSPP_SHEET_VIEW_DROP_AFTER;
5940 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5944 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
5945 path = gtk_tree_path_new_from_indices (0, -1);
5955 /* If we left the current row's "open" zone, unset the timeout for
5958 pspp_sheet_view_get_drag_dest_row (tree_view,
5963 gtk_tree_path_free (old_dest_path);
5965 if (TRUE /* FIXME if the location droppable predicate */)
5973 GtkWidget *source_widget;
5975 *suggested_action = context->suggested_action;
5976 source_widget = gtk_drag_get_source_widget (context);
5978 if (source_widget == widget)
5980 /* Default to MOVE, unless the user has
5981 * pressed ctrl or shift to affect available actions
5983 if ((context->actions & GDK_ACTION_MOVE) != 0)
5984 *suggested_action = GDK_ACTION_MOVE;
5987 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5992 /* can't drop here */
5993 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5995 PSPP_SHEET_VIEW_DROP_BEFORE);
5999 gtk_tree_path_free (path);
6005 get_logical_dest_row (PsppSheetView *tree_view,
6006 gboolean *path_down_mode,
6007 gboolean *drop_append_mode)
6009 /* adjust path to point to the row the drop goes in front of */
6010 GtkTreePath *path = NULL;
6011 PsppSheetViewDropPosition pos;
6013 g_return_val_if_fail (path_down_mode != NULL, NULL);
6014 g_return_val_if_fail (drop_append_mode != NULL, NULL);
6016 *path_down_mode = FALSE;
6017 *drop_append_mode = 0;
6019 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6024 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
6026 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
6027 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
6028 *path_down_mode = TRUE;
6032 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
6034 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
6036 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6037 !gtk_tree_model_iter_next (model, &iter))
6038 *drop_append_mode = 1;
6041 *drop_append_mode = 0;
6042 gtk_tree_path_next (path);
6050 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
6051 GdkEventMotion *event)
6053 GtkWidget *widget = GTK_WIDGET (tree_view);
6054 GdkDragContext *context;
6055 TreeViewDragInfo *di;
6056 GtkTreePath *path = NULL;
6058 gint cell_x, cell_y;
6059 GtkTreeModel *model;
6060 gboolean retval = FALSE;
6062 di = get_info (tree_view);
6064 if (di == NULL || !di->source_set)
6067 if (tree_view->priv->pressed_button < 0)
6070 if (!gtk_drag_check_threshold (widget,
6071 tree_view->priv->press_start_x,
6072 tree_view->priv->press_start_y,
6073 event->x, event->y))
6076 model = pspp_sheet_view_get_model (tree_view);
6081 button = tree_view->priv->pressed_button;
6082 tree_view->priv->pressed_button = -1;
6084 pspp_sheet_view_get_path_at_pos (tree_view,
6085 tree_view->priv->press_start_x,
6086 tree_view->priv->press_start_y,
6095 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6096 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6100 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6103 /* Now we can begin the drag */
6107 context = gtk_drag_begin (widget,
6108 gtk_drag_source_get_target_list (widget),
6113 set_source_row (context, model, path);
6117 gtk_tree_path_free (path);
6124 pspp_sheet_view_drag_begin (GtkWidget *widget,
6125 GdkDragContext *context)
6127 PsppSheetView *tree_view;
6128 GtkTreePath *path = NULL;
6129 gint cell_x, cell_y;
6131 TreeViewDragInfo *di;
6133 tree_view = PSPP_SHEET_VIEW (widget);
6135 /* if the user uses a custom DND source impl, we don't set the icon here */
6136 di = get_info (tree_view);
6138 if (di == NULL || !di->source_set)
6141 pspp_sheet_view_get_path_at_pos (tree_view,
6142 tree_view->priv->press_start_x,
6143 tree_view->priv->press_start_y,
6149 g_return_if_fail (path != NULL);
6151 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6154 gtk_drag_set_icon_pixmap (context,
6155 gdk_drawable_get_colormap (row_pix),
6158 /* the + 1 is for the black border in the icon */
6159 tree_view->priv->press_start_x + 1,
6162 g_object_unref (row_pix);
6163 gtk_tree_path_free (path);
6167 pspp_sheet_view_drag_end (GtkWidget *widget,
6168 GdkDragContext *context)
6173 /* Default signal implementations for the drag signals */
6175 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6176 GdkDragContext *context,
6177 GtkSelectionData *selection_data,
6181 PsppSheetView *tree_view;
6182 GtkTreeModel *model;
6183 TreeViewDragInfo *di;
6184 GtkTreePath *source_row;
6186 tree_view = PSPP_SHEET_VIEW (widget);
6188 model = pspp_sheet_view_get_model (tree_view);
6193 di = get_info (PSPP_SHEET_VIEW (widget));
6198 source_row = get_source_row (context);
6200 if (source_row == NULL)
6203 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6204 * any model; for DragSource models there are some other targets
6208 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6209 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6214 /* If drag_data_get does nothing, try providing row data. */
6215 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6217 gtk_tree_set_row_drag_data (selection_data,
6223 gtk_tree_path_free (source_row);
6228 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6229 GdkDragContext *context)
6231 TreeViewDragInfo *di;
6232 GtkTreeModel *model;
6233 PsppSheetView *tree_view;
6234 GtkTreePath *source_row;
6236 tree_view = PSPP_SHEET_VIEW (widget);
6237 model = pspp_sheet_view_get_model (tree_view);
6239 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6242 di = get_info (tree_view);
6247 source_row = get_source_row (context);
6249 if (source_row == NULL)
6252 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6255 gtk_tree_path_free (source_row);
6257 set_source_row (context, NULL, NULL);
6261 pspp_sheet_view_drag_leave (GtkWidget *widget,
6262 GdkDragContext *context,
6265 /* unset any highlight row */
6266 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6268 PSPP_SHEET_VIEW_DROP_BEFORE);
6270 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6275 pspp_sheet_view_drag_motion (GtkWidget *widget,
6276 GdkDragContext *context,
6277 /* coordinates relative to the widget */
6283 GtkTreePath *path = NULL;
6284 PsppSheetViewDropPosition pos;
6285 PsppSheetView *tree_view;
6286 GdkDragAction suggested_action = 0;
6289 tree_view = PSPP_SHEET_VIEW (widget);
6291 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6294 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6296 /* we only know this *after* set_desination_row */
6297 empty = tree_view->priv->empty_view_drop;
6299 if (path == NULL && !empty)
6301 /* Can't drop here. */
6302 gdk_drag_status (context, 0, time);
6306 if (tree_view->priv->open_dest_timeout == 0 &&
6307 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6308 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6314 add_scroll_timeout (tree_view);
6317 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6319 /* Request data so we can use the source row when
6320 * determining whether to accept the drop
6322 set_status_pending (context, suggested_action);
6323 gtk_drag_get_data (widget, context, target, time);
6327 set_status_pending (context, 0);
6328 gdk_drag_status (context, suggested_action, time);
6333 gtk_tree_path_free (path);
6340 pspp_sheet_view_drag_drop (GtkWidget *widget,
6341 GdkDragContext *context,
6342 /* coordinates relative to the widget */
6347 PsppSheetView *tree_view;
6349 GdkDragAction suggested_action = 0;
6350 GdkAtom target = GDK_NONE;
6351 TreeViewDragInfo *di;
6352 GtkTreeModel *model;
6353 gboolean path_down_mode;
6354 gboolean drop_append_mode;
6356 tree_view = PSPP_SHEET_VIEW (widget);
6358 model = pspp_sheet_view_get_model (tree_view);
6360 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6362 di = get_info (tree_view);
6367 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6370 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6373 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6375 if (target != GDK_NONE && path != NULL)
6377 /* in case a motion had requested drag data, change things so we
6378 * treat drag data receives as a drop.
6380 set_status_pending (context, 0);
6381 set_dest_row (context, model, path,
6382 path_down_mode, tree_view->priv->empty_view_drop,
6387 gtk_tree_path_free (path);
6389 /* Unset this thing */
6390 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6392 PSPP_SHEET_VIEW_DROP_BEFORE);
6394 if (target != GDK_NONE)
6396 gtk_drag_get_data (widget, context, target, time);
6404 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6405 GdkDragContext *context,
6406 /* coordinates relative to the widget */
6409 GtkSelectionData *selection_data,
6414 TreeViewDragInfo *di;
6415 gboolean accepted = FALSE;
6416 GtkTreeModel *model;
6417 PsppSheetView *tree_view;
6418 GtkTreePath *dest_row;
6419 GdkDragAction suggested_action;
6420 gboolean path_down_mode;
6421 gboolean drop_append_mode;
6423 tree_view = PSPP_SHEET_VIEW (widget);
6425 model = pspp_sheet_view_get_model (tree_view);
6427 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6430 di = get_info (tree_view);
6435 suggested_action = get_status_pending (context);
6437 if (suggested_action)
6439 /* We are getting this data due to a request in drag_motion,
6440 * rather than due to a request in drag_drop, so we are just
6441 * supposed to call drag_status, not actually paste in the
6444 path = get_logical_dest_row (tree_view, &path_down_mode,
6448 suggested_action = 0;
6449 else if (path_down_mode)
6450 gtk_tree_path_down (path);
6452 if (suggested_action)
6454 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6460 path_down_mode = FALSE;
6461 gtk_tree_path_up (path);
6463 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6466 suggested_action = 0;
6469 suggested_action = 0;
6473 gdk_drag_status (context, suggested_action, time);
6476 gtk_tree_path_free (path);
6478 /* If you can't drop, remove user drop indicator until the next motion */
6479 if (suggested_action == 0)
6480 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6482 PSPP_SHEET_VIEW_DROP_BEFORE);
6487 dest_row = get_dest_row (context, &path_down_mode);
6489 if (dest_row == NULL)
6492 if (selection_data->length >= 0)
6496 gtk_tree_path_down (dest_row);
6497 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6498 dest_row, selection_data))
6499 gtk_tree_path_up (dest_row);
6503 if (selection_data->length >= 0)
6505 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6511 gtk_drag_finish (context,
6513 (context->action == GDK_ACTION_MOVE),
6516 if (gtk_tree_path_get_depth (dest_row) == 1
6517 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6519 /* special special case drag to "0", scroll to first item */
6520 if (!tree_view->priv->scroll_to_path)
6521 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6524 gtk_tree_path_free (dest_row);
6527 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6532 /* GtkContainer Methods
6537 pspp_sheet_view_remove (GtkContainer *container,
6540 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6541 PsppSheetViewChild *child = NULL;
6544 tmp_list = tree_view->priv->children;
6547 child = tmp_list->data;
6548 if (child->widget == widget)
6550 gtk_widget_unparent (widget);
6552 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6553 g_list_free_1 (tmp_list);
6554 g_slice_free (PsppSheetViewChild, child);
6558 tmp_list = tmp_list->next;
6561 tmp_list = tree_view->priv->columns;
6565 PsppSheetViewColumn *column;
6566 column = tmp_list->data;
6567 if (column->button == widget)
6569 gtk_widget_unparent (widget);
6572 tmp_list = tmp_list->next;
6577 pspp_sheet_view_forall (GtkContainer *container,
6578 gboolean include_internals,
6579 GtkCallback callback,
6580 gpointer callback_data)
6582 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6583 PsppSheetViewChild *child = NULL;
6584 PsppSheetViewColumn *column;
6587 tmp_list = tree_view->priv->children;
6590 child = tmp_list->data;
6591 tmp_list = tmp_list->next;
6593 (* callback) (child->widget, callback_data);
6595 if (include_internals == FALSE)
6598 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6600 column = tmp_list->data;
6603 (* callback) (column->button, callback_data);
6607 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6608 * cells. If so we draw one big row-spanning focus rectangle.
6611 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6615 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6616 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6618 for (list = tree_view->priv->columns; list; list = list->next)
6620 if (!((PsppSheetViewColumn *)list->data)->visible)
6622 if (_pspp_sheet_view_column_count_special_cells (list->data))
6630 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6631 PsppSheetViewColumn *focus_column,
6632 gboolean clamp_column_visible)
6634 g_return_if_fail (focus_column != NULL);
6636 tree_view->priv->focus_column = focus_column;
6637 if (!focus_column->button)
6639 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6640 // g_return_if_fail (focus_column->button != NULL);
6641 if (focus_column->button == NULL)
6645 if (GTK_CONTAINER (tree_view)->focus_child != focus_column->button)
6646 gtk_widget_grab_focus (focus_column->button);
6648 if (clamp_column_visible)
6649 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6652 /* Returns TRUE if the focus is within the headers, after the focus operation is
6656 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6657 GtkDirectionType dir,
6658 gboolean clamp_column_visible)
6660 GtkWidget *focus_child;
6661 PsppSheetViewColumn *focus_column;
6662 GList *last_column, *first_column;
6666 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6669 focus_child = GTK_CONTAINER (tree_view)->focus_child;
6671 first_column = tree_view->priv->columns;
6672 while (first_column)
6674 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6676 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6678 first_column = first_column->next;
6681 /* No headers are visible, or are focusable. We can't focus in or out.
6683 if (first_column == NULL)
6686 last_column = g_list_last (tree_view->priv->columns);
6689 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6691 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6693 last_column = last_column->prev;
6697 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6701 case GTK_DIR_TAB_BACKWARD:
6702 case GTK_DIR_TAB_FORWARD:
6705 if (focus_child == NULL)
6707 if (tree_view->priv->focus_column != NULL &&
6708 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6709 focus_column = tree_view->priv->focus_column;
6711 focus_column = first_column->data;
6712 pspp_sheet_view_focus_column (tree_view, focus_column,
6713 clamp_column_visible);
6720 if (focus_child == NULL)
6722 if (tree_view->priv->focus_column != NULL)
6723 focus_column = tree_view->priv->focus_column;
6724 else if (dir == GTK_DIR_LEFT)
6725 focus_column = last_column->data;
6727 focus_column = first_column->data;
6728 pspp_sheet_view_focus_column (tree_view, focus_column,
6729 clamp_column_visible);
6733 if (gtk_widget_child_focus (focus_child, dir))
6735 /* The focus moves inside the button. */
6736 /* This is probably a great example of bad UI */
6737 if (clamp_column_visible)
6738 pspp_sheet_view_clamp_column_visible (tree_view,
6739 tree_view->priv->focus_column,
6744 /* We need to move the focus among the row of buttons. */
6745 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6746 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6749 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6750 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6752 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6758 PsppSheetViewColumn *column;
6760 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6761 tmp_list = tmp_list->next;
6763 tmp_list = tmp_list->prev;
6765 if (tmp_list == NULL)
6767 g_warning ("Internal button not found");
6770 column = tmp_list->data;
6771 if (column->visible &&
6772 pspp_sheet_view_column_can_focus (column))
6774 pspp_sheet_view_column_set_need_button (column, TRUE);
6777 pspp_sheet_view_focus_column (tree_view, column,
6778 clamp_column_visible);
6786 g_assert_not_reached ();
6793 /* This function returns in 'path' the first focusable path, if the given path
6794 * is already focusable, it's the returned one.
6798 search_first_focusable_path (PsppSheetView *tree_view,
6800 gboolean search_forward,
6803 /* XXX this function is trivial given that the sheetview doesn't support
6807 if (!path || !*path)
6810 _pspp_sheet_view_find_node (tree_view, *path, &node);
6818 return (*path != NULL);
6822 pspp_sheet_view_focus (GtkWidget *widget,
6823 GtkDirectionType direction)
6825 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6826 GtkContainer *container = GTK_CONTAINER (widget);
6827 GtkWidget *focus_child;
6829 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6832 focus_child = container->focus_child;
6834 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6835 /* Case 1. Headers currently have focus. */
6842 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6844 case GTK_DIR_TAB_BACKWARD:
6847 case GTK_DIR_TAB_FORWARD:
6849 gtk_widget_grab_focus (widget);
6852 g_assert_not_reached ();
6857 /* Case 2. We don't have focus at all. */
6858 if (!gtk_widget_has_focus (widget))
6860 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6861 gtk_widget_grab_focus (widget);
6865 /* Case 3. We have focus already. */
6866 if (direction == GTK_DIR_TAB_BACKWARD)
6867 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6868 else if (direction == GTK_DIR_TAB_FORWARD)
6871 /* Other directions caught by the keybindings */
6872 gtk_widget_grab_focus (widget);
6877 pspp_sheet_view_grab_focus (GtkWidget *widget)
6879 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6881 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6885 pspp_sheet_view_style_set (GtkWidget *widget,
6886 GtkStyle *previous_style)
6888 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6890 PsppSheetViewColumn *column;
6892 if (gtk_widget_get_realized (widget))
6894 gdk_window_set_back_pixmap (gtk_widget_get_window (widget), NULL, FALSE);
6895 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
6896 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
6897 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6900 gtk_widget_style_get (widget,
6901 "expander-size", &tree_view->priv->expander_size,
6903 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6905 for (list = tree_view->priv->columns; list; list = list->next)
6907 column = list->data;
6908 _pspp_sheet_view_column_cell_set_dirty (column);
6911 tree_view->priv->fixed_height = -1;
6913 /* Invalidate cached button style. */
6914 if (tree_view->priv->button_style)
6916 g_object_unref (tree_view->priv->button_style);
6917 tree_view->priv->button_style = NULL;
6920 gtk_widget_queue_resize (widget);
6925 pspp_sheet_view_set_focus_child (GtkContainer *container,
6928 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6931 for (list = tree_view->priv->columns; list; list = list->next)
6933 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6935 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6940 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6944 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6945 GtkAdjustment *hadj,
6946 GtkAdjustment *vadj)
6948 gboolean need_adjust = FALSE;
6950 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6953 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6955 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6957 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
6959 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6961 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
6963 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
6964 pspp_sheet_view_adjustment_changed,
6966 g_object_unref (tree_view->priv->hadjustment);
6969 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
6971 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
6972 pspp_sheet_view_adjustment_changed,
6974 g_object_unref (tree_view->priv->vadjustment);
6977 if (tree_view->priv->hadjustment != hadj)
6979 tree_view->priv->hadjustment = hadj;
6980 g_object_ref_sink (tree_view->priv->hadjustment);
6982 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
6983 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6988 if (tree_view->priv->vadjustment != vadj)
6990 tree_view->priv->vadjustment = vadj;
6991 g_object_ref_sink (tree_view->priv->vadjustment);
6993 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
6994 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7000 pspp_sheet_view_adjustment_changed (NULL, tree_view);
7005 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
7006 GtkMovementStep step,
7009 PsppSheetSelectMode mode;
7010 GdkModifierType state;
7012 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
7013 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
7014 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
7015 step == GTK_MOVEMENT_DISPLAY_LINES ||
7016 step == GTK_MOVEMENT_PAGES ||
7017 step == GTK_MOVEMENT_BUFFER_ENDS ||
7018 step == GTK_MOVEMENT_DISPLAY_LINE_ENDS, FALSE);
7020 if (tree_view->priv->row_count == 0)
7022 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7025 pspp_sheet_view_stop_editing (tree_view, FALSE);
7026 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7027 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7030 if (gtk_get_current_event_state (&state))
7032 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7033 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
7034 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
7035 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
7037 /* else we assume not pressed */
7041 case GTK_MOVEMENT_LOGICAL_POSITIONS:
7042 pspp_sheet_view_move_cursor_tab (tree_view, count);
7044 case GTK_MOVEMENT_VISUAL_POSITIONS:
7045 pspp_sheet_view_move_cursor_left_right (tree_view, count, mode);
7047 case GTK_MOVEMENT_DISPLAY_LINES:
7048 pspp_sheet_view_move_cursor_up_down (tree_view, count, mode);
7050 case GTK_MOVEMENT_PAGES:
7051 pspp_sheet_view_move_cursor_page_up_down (tree_view, count, mode);
7053 case GTK_MOVEMENT_BUFFER_ENDS:
7054 pspp_sheet_view_move_cursor_start_end (tree_view, count, mode);
7056 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
7057 pspp_sheet_view_move_cursor_line_start_end (tree_view, count, mode);
7060 g_assert_not_reached ();
7067 pspp_sheet_view_put (PsppSheetView *tree_view,
7068 GtkWidget *child_widget,
7069 /* in bin_window coordinates */
7075 PsppSheetViewChild *child;
7077 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7078 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7080 child = g_slice_new (PsppSheetViewChild);
7082 child->widget = child_widget;
7085 child->width = width;
7086 child->height = height;
7088 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7090 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7091 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7093 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7097 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7099 /* in tree coordinates */
7105 PsppSheetViewChild *child = NULL;
7107 GdkRectangle allocation;
7109 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7110 g_return_if_fail (GTK_IS_WIDGET (widget));
7112 for (list = tree_view->priv->children; list; list = list->next)
7114 if (((PsppSheetViewChild *)list->data)->widget == widget)
7123 allocation.x = child->x = x;
7124 allocation.y = child->y = y;
7125 allocation.width = child->width = width;
7126 allocation.height = child->height = height;
7128 if (gtk_widget_get_realized (widget))
7129 gtk_widget_size_allocate (widget, &allocation);
7133 /* TreeModel Callbacks
7137 pspp_sheet_view_row_changed (GtkTreeModel *model,
7142 PsppSheetView *tree_view = (PsppSheetView *)data;
7144 gboolean free_path = FALSE;
7145 GtkTreePath *cursor_path;
7147 g_return_if_fail (path != NULL || iter != NULL);
7149 if (tree_view->priv->cursor != NULL)
7150 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7154 if (tree_view->priv->edited_column &&
7155 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7156 pspp_sheet_view_stop_editing (tree_view, TRUE);
7158 if (cursor_path != NULL)
7159 gtk_tree_path_free (cursor_path);
7163 path = gtk_tree_model_get_path (model, iter);
7166 else if (iter == NULL)
7167 gtk_tree_model_get_iter (model, iter, path);
7169 _pspp_sheet_view_find_node (tree_view,
7175 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7176 pspp_sheet_view_node_queue_redraw (tree_view, node);
7180 gtk_tree_path_free (path);
7184 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7189 PsppSheetView *tree_view = (PsppSheetView *) data;
7192 gint height = tree_view->priv->fixed_height;
7193 gboolean free_path = FALSE;
7194 gboolean node_visible = TRUE;
7196 g_return_if_fail (path != NULL || iter != NULL);
7200 path = gtk_tree_model_get_path (model, iter);
7203 else if (iter == NULL)
7204 gtk_tree_model_get_iter (model, iter, path);
7206 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7208 /* Update all row-references */
7209 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7210 indices = gtk_tree_path_get_indices (path);
7211 tmpnode = indices[0];
7213 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7217 if (node_visible && node_is_visible (tree_view, tmpnode))
7218 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7220 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7223 install_presize_handler (tree_view);
7225 gtk_tree_path_free (path);
7229 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7233 PsppSheetView *tree_view = (PsppSheetView *)data;
7236 g_return_if_fail (path != NULL);
7238 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7240 _pspp_sheet_view_find_node (tree_view, path, &node);
7245 range_tower_delete (tree_view->priv->selected, node, 1);
7247 /* Ensure we don't have a dangling pointer to a dead node */
7248 ensure_unprelighted (tree_view);
7250 /* Cancel editting if we've started */
7251 pspp_sheet_view_stop_editing (tree_view, TRUE);
7253 if (tree_view->priv->destroy_count_func)
7255 gint child_count = 0;
7256 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7259 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7261 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7263 gtk_tree_row_reference_free (tree_view->priv->top_row);
7264 tree_view->priv->top_row = NULL;
7267 install_scroll_sync_handler (tree_view);
7269 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7272 if (helper_data.changed)
7273 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7278 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7279 GtkTreePath *parent,
7284 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7287 /* XXX need to adjust selection */
7288 len = gtk_tree_model_iter_n_children (model, iter);
7293 gtk_tree_row_reference_reordered (G_OBJECT (data),
7298 if (gtk_tree_path_get_depth (parent) != 0)
7301 if (tree_view->priv->edited_column)
7302 pspp_sheet_view_stop_editing (tree_view, TRUE);
7304 /* we need to be unprelighted */
7305 ensure_unprelighted (tree_view);
7307 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7309 pspp_sheet_view_dy_to_top_row (tree_view);
7313 /* Internal tree functions
7318 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7319 PsppSheetViewColumn *column,
7323 PsppSheetViewColumn *tmp_column = NULL;
7334 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7337 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7339 list = (rtl ? list->prev : list->next))
7341 tmp_column = list->data;
7343 if (tmp_column == column)
7346 if (tmp_column->visible)
7347 total_width += tmp_column->width;
7350 if (tmp_column != column)
7352 g_warning (G_STRLOC": passed-in column isn't in the tree");
7361 if (column->visible)
7362 *x2 = total_width + column->width;
7364 *x2 = total_width; /* width of 0 */
7368 /* Make sure the node is visible vertically */
7370 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7373 gint node_dy, height;
7374 GtkTreePath *path = NULL;
7376 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7379 /* just return if the node is visible, avoiding a costly expose */
7380 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7381 height = ROW_HEIGHT (tree_view);
7382 if (node_dy >= tree_view->priv->vadjustment->value
7383 && node_dy + height <= (tree_view->priv->vadjustment->value
7384 + tree_view->priv->vadjustment->page_size))
7387 path = _pspp_sheet_view_find_path (tree_view, node);
7390 /* We process updates because we want to clear old selected items when we scroll.
7391 * if this is removed, we get a "selection streak" at the bottom. */
7392 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7393 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7394 gtk_tree_path_free (path);
7399 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7400 PsppSheetViewColumn *column,
7401 gboolean focus_to_cell)
7408 x = column->allocation.x;
7409 width = column->allocation.width;
7411 if (width > tree_view->priv->hadjustment->page_size)
7413 /* The column is larger than the horizontal page size. If the
7414 * column has cells which can be focussed individually, then we make
7415 * sure the cell which gets focus is fully visible (if even the
7416 * focus cell is bigger than the page size, we make sure the
7417 * left-hand side of the cell is visible).
7419 * If the column does not have those so-called special cells, we
7420 * make sure the left-hand side of the column is visible.
7423 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7425 GtkTreePath *cursor_path;
7426 GdkRectangle background_area, cell_area, focus_area;
7428 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7430 pspp_sheet_view_get_cell_area (tree_view,
7431 cursor_path, column, &cell_area);
7432 pspp_sheet_view_get_background_area (tree_view,
7433 cursor_path, column,
7436 gtk_tree_path_free (cursor_path);
7438 _pspp_sheet_view_column_get_focus_area (column,
7444 width = focus_area.width;
7446 if (width < tree_view->priv->hadjustment->page_size)
7448 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7449 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7450 x + width - tree_view->priv->hadjustment->page_size);
7451 else if (tree_view->priv->hadjustment->value > x)
7452 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7456 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7458 tree_view->priv->hadjustment->lower,
7459 tree_view->priv->hadjustment->upper
7460 - tree_view->priv->hadjustment->page_size));
7464 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7465 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7466 x + width - tree_view->priv->hadjustment->page_size);
7467 else if (tree_view->priv->hadjustment->value > x)
7468 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7473 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7478 path = gtk_tree_path_new ();
7480 gtk_tree_path_append_index (path, node);
7485 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7489 gint *indices = gtk_tree_path_get_indices (path);
7490 gint depth = gtk_tree_path_get_depth (path);
7493 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7499 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7502 gboolean add_shifted_binding,
7503 GtkMovementStep step,
7507 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7512 if (add_shifted_binding)
7513 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7518 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7521 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7526 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7533 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7534 PsppSheetViewColumn *column)
7536 PsppSheetViewColumn *left_column;
7537 PsppSheetViewColumn *cur_column = NULL;
7538 PsppSheetViewColumnReorder *reorder;
7543 /* We want to precalculate the motion list such that we know what column slots
7547 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7549 /* First, identify all possible drop spots */
7551 tmp_list = g_list_last (tree_view->priv->columns);
7553 tmp_list = g_list_first (tree_view->priv->columns);
7557 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7558 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7560 if (cur_column->visible == FALSE)
7563 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7564 if (left_column != column && cur_column != column &&
7565 tree_view->priv->column_drop_func &&
7566 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7568 left_column = cur_column;
7571 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7572 reorder->left_column = left_column;
7573 left_column = reorder->right_column = cur_column;
7575 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7578 /* Add the last one */
7579 if (tree_view->priv->column_drop_func == NULL ||
7580 ((left_column != column) &&
7581 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7583 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7584 reorder->left_column = left_column;
7585 reorder->right_column = NULL;
7586 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7589 /* We quickly check to see if it even makes sense to reorder columns. */
7590 /* If there is nothing that can be moved, then we return */
7592 if (tree_view->priv->column_drag_info == NULL)
7595 /* We know there are always 2 slots possbile, as you can always return column. */
7596 /* If that's all there is, return */
7597 if (tree_view->priv->column_drag_info->next == NULL ||
7598 (tree_view->priv->column_drag_info->next->next == NULL &&
7599 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7600 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7602 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7603 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7604 g_list_free (tree_view->priv->column_drag_info);
7605 tree_view->priv->column_drag_info = NULL;
7608 /* We fill in the ranges for the columns, now that we've isolated them */
7609 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7611 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7613 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7615 reorder->left_align = left;
7616 if (tmp_list->next != NULL)
7618 g_assert (tmp_list->next->data);
7619 left = reorder->right_align = (reorder->right_column->allocation.x +
7620 reorder->right_column->allocation.width +
7621 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7625 gint width = gdk_window_get_width (tree_view->priv->header_window);
7626 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7632 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7633 PsppSheetViewColumn *column)
7635 GdkEvent *send_event;
7636 GtkAllocation allocation;
7638 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7639 GdkDisplay *display = gdk_screen_get_display (screen);
7641 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7642 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7643 g_return_if_fail (column->button);
7645 pspp_sheet_view_set_column_drag_info (tree_view, column);
7647 if (tree_view->priv->column_drag_info == NULL)
7650 if (tree_view->priv->drag_window == NULL)
7652 GdkWindowAttr attributes;
7653 guint attributes_mask;
7655 attributes.window_type = GDK_WINDOW_CHILD;
7656 attributes.wclass = GDK_INPUT_OUTPUT;
7657 attributes.x = column->allocation.x;
7659 attributes.width = column->allocation.width;
7660 attributes.height = column->allocation.height;
7661 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7662 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
7663 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7664 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
7666 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7669 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7672 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7673 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7675 gtk_grab_remove (column->button);
7677 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7678 send_event->crossing.send_event = TRUE;
7679 send_event->crossing.window = g_object_ref (GTK_BUTTON (column->button)->event_window);
7680 send_event->crossing.subwindow = NULL;
7681 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7682 send_event->crossing.time = GDK_CURRENT_TIME;
7684 gtk_propagate_event (column->button, send_event);
7685 gdk_event_free (send_event);
7687 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7688 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7689 send_event->button.send_event = TRUE;
7690 send_event->button.time = GDK_CURRENT_TIME;
7691 send_event->button.x = -1;
7692 send_event->button.y = -1;
7693 send_event->button.axes = NULL;
7694 send_event->button.state = 0;
7695 send_event->button.button = 1;
7696 send_event->button.device = gdk_display_get_core_pointer (display);
7697 send_event->button.x_root = 0;
7698 send_event->button.y_root = 0;
7700 gtk_propagate_event (column->button, send_event);
7701 gdk_event_free (send_event);
7703 /* Kids, don't try this at home */
7704 g_object_ref (column->button);
7705 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7706 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7707 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7708 g_object_unref (column->button);
7710 tree_view->priv->drag_column_x = column->allocation.x;
7711 allocation = column->allocation;
7713 gtk_widget_size_allocate (column->button, &allocation);
7714 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7716 tree_view->priv->drag_column = column;
7717 gdk_window_show (tree_view->priv->drag_window);
7719 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7721 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7722 while (gtk_events_pending ())
7723 gtk_main_iteration ();
7725 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7726 gdk_pointer_grab (tree_view->priv->drag_window,
7728 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7729 NULL, NULL, GDK_CURRENT_TIME);
7730 gdk_keyboard_grab (tree_view->priv->drag_window,
7736 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7738 const GdkRectangle *clip_rect)
7742 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7746 rect.width = MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width);
7748 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7749 rect.height = ROW_HEIGHT (tree_view);
7753 GdkRectangle new_rect;
7755 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7757 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7761 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7766 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7768 const GdkRectangle *clip_rect)
7772 _pspp_sheet_view_find_node (tree_view, path, &node);
7775 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7779 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7782 GtkTreePath *cursor_path;
7784 if ((tree_view->priv->row_count == 0) ||
7785 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7789 if (tree_view->priv->cursor)
7790 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7792 if (cursor_path == NULL)
7794 /* There's no cursor. Move the cursor to the first selected row, if any
7795 * are selected, otherwise to the first row in the sheetview.
7797 GList *selected_rows;
7798 GtkTreeModel *model;
7799 PsppSheetSelection *selection;
7801 selection = pspp_sheet_view_get_selection (tree_view);
7802 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7806 /* XXX we could avoid doing O(n) work to get this result */
7807 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7808 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7809 g_list_free (selected_rows);
7813 cursor_path = gtk_tree_path_new_first ();
7814 search_first_focusable_path (tree_view, &cursor_path,
7818 gtk_tree_row_reference_free (tree_view->priv->cursor);
7819 tree_view->priv->cursor = NULL;
7823 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7824 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7825 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE, 0);
7827 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, 0);
7833 /* Now find a column for the cursor. */
7834 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7836 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7837 gtk_tree_path_free (cursor_path);
7839 if (tree_view->priv->focus_column == NULL)
7842 for (list = tree_view->priv->columns; list; list = list->next)
7844 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7846 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7847 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7848 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7858 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7860 PsppSheetSelectMode mode)
7862 gint selection_count;
7863 int cursor_node = -1;
7864 int new_cursor_node = -1;
7865 GtkTreePath *cursor_path = NULL;
7866 gboolean grab_focus = TRUE;
7868 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7872 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7873 /* FIXME: we lost the cursor; should we get the first? */
7876 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7877 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7879 if (cursor_node < 0)
7880 /* FIXME: we lost the cursor; should we get the first? */
7883 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7885 if (selection_count == 0
7886 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7887 && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
7889 /* Don't move the cursor, but just select the current node */
7890 new_cursor_node = cursor_node;
7895 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7897 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7900 gtk_tree_path_free (cursor_path);
7902 if (new_cursor_node)
7904 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7906 search_first_focusable_path (tree_view, &cursor_path,
7911 gtk_tree_path_free (cursor_path);
7915 * If the list has only one item and multi-selection is set then select
7916 * the row (if not yet selected).
7918 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7919 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7920 new_cursor_node < 0)
7923 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7925 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7927 if (new_cursor_node < 0
7928 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7930 new_cursor_node = cursor_node;
7934 new_cursor_node = -1;
7938 if (new_cursor_node >= 0)
7940 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7941 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE, mode);
7942 gtk_tree_path_free (cursor_path);
7946 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7948 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
7950 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7952 GTK_DIR_UP : GTK_DIR_DOWN))
7954 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
7957 gtk_widget_child_focus (toplevel,
7959 GTK_DIR_TAB_BACKWARD :
7960 GTK_DIR_TAB_FORWARD);
7967 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7972 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7974 return new_cursor_node >= 0;
7978 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
7980 PsppSheetSelectMode mode)
7982 int cursor_node = -1;
7983 GtkTreePath *old_cursor_path = NULL;
7984 GtkTreePath *cursor_path = NULL;
7985 int start_cursor_node = -1;
7988 gint vertical_separator;
7990 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7993 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
7994 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7996 /* This is sorta weird. Focus in should give us a cursor */
7999 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
8000 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
8002 if (cursor_node < 0)
8004 /* FIXME: we lost the cursor. Should we try to get one? */
8005 gtk_tree_path_free (old_cursor_path);
8009 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8010 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
8011 y += tree_view->priv->cursor_offset;
8012 y += count * (int)tree_view->priv->vadjustment->page_increment;
8013 y = CLAMP (y, (gint)tree_view->priv->vadjustment->lower, (gint)tree_view->priv->vadjustment->upper - vertical_separator);
8015 if (y >= tree_view->priv->height)
8016 y = tree_view->priv->height - 1;
8018 tree_view->priv->cursor_offset =
8019 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
8021 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
8023 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
8024 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
8027 y -= tree_view->priv->cursor_offset;
8028 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8030 start_cursor_node = cursor_node;
8032 if (! search_first_focusable_path (tree_view, &cursor_path,
8036 /* It looks like we reached the end of the view without finding
8037 * a focusable row. We will step backwards to find the last
8040 cursor_node = start_cursor_node;
8041 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8043 search_first_focusable_path (tree_view, &cursor_path,
8052 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8054 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, mode);
8057 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
8058 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8059 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8061 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
8062 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8064 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8067 gtk_tree_path_free (old_cursor_path);
8068 gtk_tree_path_free (cursor_path);
8072 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
8074 PsppSheetSelectMode mode)
8076 int cursor_node = -1;
8077 GtkTreePath *cursor_path = NULL;
8078 PsppSheetViewColumn *column;
8081 gboolean found_column = FALSE;
8084 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8086 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8089 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8090 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8094 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8095 if (cursor_node < 0)
8097 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8099 gtk_tree_path_free (cursor_path);
8102 gtk_tree_path_free (cursor_path);
8104 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8105 if (tree_view->priv->focus_column)
8107 for (; list; list = (rtl ? list->prev : list->next))
8109 if (list->data == tree_view->priv->focus_column)
8116 gboolean left, right;
8118 column = list->data;
8119 if (column->visible == FALSE || column->row_head)
8122 pspp_sheet_view_column_cell_set_cell_data (column,
8123 tree_view->priv->model,
8128 right = list->prev ? TRUE : FALSE;
8129 left = list->next ? TRUE : FALSE;
8133 left = list->prev ? TRUE : FALSE;
8134 right = list->next ? TRUE : FALSE;
8137 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8139 tree_view->priv->focus_column = column;
8140 found_column = TRUE;
8145 list = rtl ? list->prev : list->next;
8147 list = rtl ? list->next : list->prev;
8152 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8153 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8154 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8158 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8161 pspp_sheet_view_clamp_column_visible (tree_view,
8162 tree_view->priv->focus_column, TRUE);
8166 pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
8168 PsppSheetSelectMode mode)
8170 int cursor_node = -1;
8171 GtkTreePath *cursor_path = NULL;
8172 PsppSheetViewColumn *column;
8173 PsppSheetViewColumn *found_column;
8178 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8180 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8183 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8184 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8188 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8189 if (cursor_node < 0)
8191 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8193 gtk_tree_path_free (cursor_path);
8196 gtk_tree_path_free (cursor_path);
8198 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8199 if (tree_view->priv->focus_column)
8201 for (; list; list = (rtl ? list->prev : list->next))
8203 if (list->data == tree_view->priv->focus_column)
8208 found_column = NULL;
8211 gboolean left, right;
8213 column = list->data;
8214 if (column->visible == FALSE || column->row_head)
8217 pspp_sheet_view_column_cell_set_cell_data (column,
8218 tree_view->priv->model,
8223 right = list->prev ? TRUE : FALSE;
8224 left = list->next ? TRUE : FALSE;
8228 left = list->prev ? TRUE : FALSE;
8229 right = list->next ? TRUE : FALSE;
8232 if (column->tabbable
8233 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8234 found_column = column;
8238 list = rtl ? list->prev : list->next;
8240 list = rtl ? list->next : list->prev;
8245 tree_view->priv->focus_column = found_column;
8246 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8247 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8248 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8251 pspp_sheet_view_clamp_column_visible (tree_view,
8252 tree_view->priv->focus_column, TRUE);
8256 try_move_cursor_tab (PsppSheetView *tree_view,
8257 gboolean start_at_focus_column,
8260 PsppSheetViewColumn *column;
8262 int cursor_node = -1;
8263 GtkTreePath *cursor_path = NULL;
8267 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8268 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8272 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8273 if (cursor_node < 0)
8275 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8277 gtk_tree_path_free (cursor_path);
8280 gtk_tree_path_free (cursor_path);
8282 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
8283 if (start_at_focus_column)
8286 ? g_list_last (tree_view->priv->columns)
8287 : g_list_first (tree_view->priv->columns));
8288 if (tree_view->priv->focus_column)
8290 for (; list; list = (rtl ? list->prev : list->next))
8292 if (list->data == tree_view->priv->focus_column)
8299 list = (rtl ^ (count == 1)
8300 ? g_list_first (tree_view->priv->columns)
8301 : g_list_last (tree_view->priv->columns));
8306 gboolean left, right;
8308 column = list->data;
8309 if (column->visible == FALSE || !column->tabbable)
8312 pspp_sheet_view_column_cell_set_cell_data (column,
8313 tree_view->priv->model,
8318 right = list->prev ? TRUE : FALSE;
8319 left = list->next ? TRUE : FALSE;
8323 left = list->prev ? TRUE : FALSE;
8324 right = list->next ? TRUE : FALSE;
8327 if (column->tabbable
8328 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8330 tree_view->priv->focus_column = column;
8331 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8332 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8333 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8338 list = rtl ? list->prev : list->next;
8340 list = rtl ? list->next : list->prev;
8347 pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
8350 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8353 if (!try_move_cursor_tab (tree_view, TRUE, count))
8355 if (pspp_sheet_view_move_cursor_up_down (tree_view, count, 0)
8356 && !try_move_cursor_tab (tree_view, FALSE, count))
8357 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8360 pspp_sheet_view_clamp_column_visible (tree_view,
8361 tree_view->priv->focus_column, TRUE);
8365 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8367 PsppSheetSelectMode mode)
8371 GtkTreePath *old_path;
8373 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8376 g_return_if_fail (tree_view->priv->row_count > 0);
8378 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8382 /* Now go forward to find the first focusable row. */
8383 path = _pspp_sheet_view_find_path (tree_view, 0);
8384 search_first_focusable_path (tree_view, &path,
8385 TRUE, &cursor_node);
8389 /* Now go backwards to find last focusable row. */
8390 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8391 search_first_focusable_path (tree_view, &path,
8392 FALSE, &cursor_node);
8398 if (gtk_tree_path_compare (old_path, path))
8400 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
8401 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8405 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8409 gtk_tree_path_free (old_path);
8410 gtk_tree_path_free (path);
8414 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8416 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8419 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8420 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8423 pspp_sheet_selection_select_all (tree_view->priv->selection);
8429 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8431 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8434 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8435 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8438 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8444 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8445 gboolean start_editing,
8446 PsppSheetSelectMode mode)
8449 int cursor_node = -1;
8450 GtkTreePath *cursor_path = NULL;
8452 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8455 if (tree_view->priv->cursor)
8456 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8458 if (cursor_path == NULL)
8461 _pspp_sheet_view_find_node (tree_view, cursor_path,
8464 if (cursor_node < 0)
8466 gtk_tree_path_free (cursor_path);
8470 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND) && start_editing &&
8471 tree_view->priv->focus_column)
8473 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8475 gtk_tree_path_free (cursor_path);
8480 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8486 /* We bail out if the original (tree, node) don't exist anymore after
8487 * handling the selection-changed callback. We do return TRUE because
8488 * the key press has been handled at this point.
8490 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8492 if (cursor_node != new_node)
8495 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8497 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8498 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8500 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
8501 pspp_sheet_view_row_activated (tree_view, cursor_path,
8502 tree_view->priv->focus_column);
8504 gtk_tree_path_free (cursor_path);
8510 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8513 int cursor_node = -1;
8514 GtkTreePath *cursor_path = NULL;
8516 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8520 if (tree_view->priv->cursor)
8521 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8523 if (cursor_path == NULL)
8526 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8527 if (cursor_node < 0)
8529 gtk_tree_path_free (cursor_path);
8533 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8536 PSPP_SHEET_SELECT_MODE_TOGGLE,
8539 /* We bail out if the original (tree, node) don't exist anymore after
8540 * handling the selection-changed callback. We do return TRUE because
8541 * the key press has been handled at this point.
8543 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8545 if (cursor_node != new_node)
8548 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8550 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8551 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8552 gtk_tree_path_free (cursor_path);
8558 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8560 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8561 tree_view->priv->typeselect_flush_timeout = 0;
8566 /* Cut and paste from gtkwindow.c */
8568 send_focus_change (GtkWidget *widget,
8571 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8573 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8574 fevent->focus_change.window = g_object_ref (gtk_widget_get_window (widget));
8575 fevent->focus_change.in = in;
8577 gtk_widget_send_focus_change (widget, fevent);
8578 gdk_event_free (fevent);
8582 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8584 GtkWidget *frame, *vbox, *toplevel;
8587 if (tree_view->priv->search_custom_entry_set)
8590 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8591 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8593 if (tree_view->priv->search_window != NULL)
8595 if (GTK_WINDOW (toplevel)->group)
8596 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8597 GTK_WINDOW (tree_view->priv->search_window));
8598 else if (GTK_WINDOW (tree_view->priv->search_window)->group)
8599 gtk_window_group_remove_window (GTK_WINDOW (tree_view->priv->search_window)->group,
8600 GTK_WINDOW (tree_view->priv->search_window));
8601 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8605 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8606 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8608 if (GTK_WINDOW (toplevel)->group)
8609 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8610 GTK_WINDOW (tree_view->priv->search_window));
8612 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8613 GDK_WINDOW_TYPE_HINT_UTILITY);
8614 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8615 g_signal_connect (tree_view->priv->search_window, "delete-event",
8616 G_CALLBACK (pspp_sheet_view_search_delete_event),
8618 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8619 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8621 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8622 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8624 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8625 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8628 frame = gtk_frame_new (NULL);
8629 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8630 gtk_widget_show (frame);
8631 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8633 vbox = gtk_vbox_new (FALSE, 0);
8634 gtk_widget_show (vbox);
8635 gtk_container_add (GTK_CONTAINER (frame), vbox);
8636 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8639 tree_view->priv->search_entry = gtk_entry_new ();
8640 gtk_widget_show (tree_view->priv->search_entry);
8641 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8642 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8644 g_signal_connect (tree_view->priv->search_entry,
8645 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8647 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8649 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8651 gtk_container_add (GTK_CONTAINER (vbox),
8652 tree_view->priv->search_entry);
8654 gtk_widget_realize (tree_view->priv->search_entry);
8657 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8658 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8661 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8662 gboolean keybinding)
8664 /* We only start interactive search if we have focus or the columns
8665 * have focus. If one of our children have focus, we don't want to
8669 gboolean found_focus = FALSE;
8670 GtkWidgetClass *entry_parent_class;
8672 if (!tree_view->priv->enable_search && !keybinding)
8675 if (tree_view->priv->search_custom_entry_set)
8678 if (tree_view->priv->search_window != NULL &&
8679 gtk_widget_get_visible (tree_view->priv->search_window))
8682 for (list = tree_view->priv->columns; list; list = list->next)
8684 PsppSheetViewColumn *column;
8686 column = list->data;
8687 if (! column->visible)
8690 if (column->button && gtk_widget_has_focus (column->button))
8697 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8703 if (tree_view->priv->search_column < 0)
8706 pspp_sheet_view_ensure_interactive_directory (tree_view);
8709 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8712 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8713 gtk_widget_show (tree_view->priv->search_window);
8714 if (tree_view->priv->search_entry_changed_id == 0)
8716 tree_view->priv->search_entry_changed_id =
8717 g_signal_connect (tree_view->priv->search_entry, "changed",
8718 G_CALLBACK (pspp_sheet_view_search_init),
8722 tree_view->priv->typeselect_flush_timeout =
8723 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8724 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8727 /* Grab focus will select all the text. We don't want that to happen, so we
8728 * call the parent instance and bypass the selection change. This is probably
8729 * really non-kosher. */
8730 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8731 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8733 /* send focus-in event */
8734 send_focus_change (tree_view->priv->search_entry, TRUE);
8736 /* search first matching iter */
8737 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8743 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8745 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8748 /* this function returns the new width of the column being resized given
8749 * the column and x position of the cursor; the x cursor position is passed
8750 * in as a pointer and automagicly corrected if it's beyond min/max limits
8753 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8757 PsppSheetViewColumn *column;
8761 /* first translate the x position from gtk_widget_get_window (widget)
8762 * to clist->clist_window
8764 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8765 column = g_list_nth (tree_view->priv->columns, i)->data;
8766 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8768 /* Clamp down the value */
8769 if (column->min_width == -1)
8770 width = MAX (column->button_request, width);
8772 width = MAX (column->min_width, width);
8773 if (column->max_width != -1)
8774 width = MIN (width, column->max_width);
8776 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8782 /* FIXME this adjust_allocation is a big cut-and-paste from
8783 * GtkCList, needs to be some "official" way to do this
8793 /* The window to which gtk_widget_get_window (widget) is relative */
8794 #define ALLOCATION_WINDOW(widget) \
8795 (!gtk_widget_get_has_window (widget) ? \
8796 (widget)->window : \
8797 gdk_window_get_parent ((widget)->window))
8800 adjust_allocation_recurse (GtkWidget *widget,
8803 ScrollData *scroll_data = data;
8805 /* Need to really size allocate instead of just poking
8806 * into widget->allocation if the widget is not realized.
8807 * FIXME someone figure out why this was.
8809 if (!gtk_widget_get_realized (widget))
8811 if (gtk_widget_get_visible (widget))
8813 GdkRectangle tmp_rectangle = widget->allocation;
8814 tmp_rectangle.x += scroll_data->dx;
8815 tmp_rectangle.y += scroll_data->dy;
8817 gtk_widget_size_allocate (widget, &tmp_rectangle);
8822 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8824 widget->allocation.x += scroll_data->dx;
8825 widget->allocation.y += scroll_data->dy;
8827 if (GTK_IS_CONTAINER (widget))
8828 gtk_container_forall (GTK_CONTAINER (widget),
8829 adjust_allocation_recurse,
8836 adjust_allocation (GtkWidget *widget,
8840 ScrollData scroll_data;
8842 if (gtk_widget_get_realized (widget))
8843 scroll_data.window = ALLOCATION_WINDOW (widget);
8845 scroll_data.window = NULL;
8847 scroll_data.dx = dx;
8848 scroll_data.dy = dy;
8850 adjust_allocation_recurse (widget, &scroll_data);
8854 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8858 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8859 PsppSheetView *tree_view)
8861 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8866 gdk_window_move (tree_view->priv->bin_window,
8867 - tree_view->priv->hadjustment->value,
8868 TREE_VIEW_HEADER_HEIGHT (tree_view));
8869 gdk_window_move (tree_view->priv->header_window,
8870 - tree_view->priv->hadjustment->value,
8872 dy = tree_view->priv->dy - (int) tree_view->priv->vadjustment->value;
8875 update_prelight (tree_view,
8876 tree_view->priv->event_last_x,
8877 tree_view->priv->event_last_y - dy);
8879 if (tree_view->priv->edited_column &&
8880 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8884 PsppSheetViewChild *child = NULL;
8886 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8887 adjust_allocation (widget, 0, dy);
8889 for (list = tree_view->priv->children; list; list = list->next)
8891 child = (PsppSheetViewChild *)list->data;
8892 if (child->widget == widget)
8900 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8902 if (tree_view->priv->dy != (int) tree_view->priv->vadjustment->value)
8904 /* update our dy and top_row */
8905 tree_view->priv->dy = (int) tree_view->priv->vadjustment->value;
8907 if (!tree_view->priv->in_top_row_to_dy)
8908 pspp_sheet_view_dy_to_top_row (tree_view);
8911 for (list = tree_view->priv->columns; list; list = list->next)
8913 PsppSheetViewColumn *column = list->data;
8914 GtkAllocation *allocation = &column->allocation;
8916 if (span_intersects (allocation->x, allocation->width,
8917 tree_view->priv->hadjustment->value,
8918 GTK_WIDGET (tree_view)->allocation.width))
8920 pspp_sheet_view_column_set_need_button (column, TRUE);
8921 if (!column->button)
8922 pspp_sheet_view_column_update_button (column);
8934 * pspp_sheet_view_new:
8936 * Creates a new #PsppSheetView widget.
8938 * Return value: A newly created #PsppSheetView widget.
8941 pspp_sheet_view_new (void)
8943 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8947 * pspp_sheet_view_new_with_model:
8948 * @model: the model.
8950 * Creates a new #PsppSheetView widget with the model initialized to @model.
8952 * Return value: A newly created #PsppSheetView widget.
8955 pspp_sheet_view_new_with_model (GtkTreeModel *model)
8957 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
8964 * pspp_sheet_view_get_model:
8965 * @tree_view: a #PsppSheetView
8967 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
8970 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
8973 pspp_sheet_view_get_model (PsppSheetView *tree_view)
8975 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8977 return tree_view->priv->model;
8981 * pspp_sheet_view_set_model:
8982 * @tree_view: A #GtkTreeNode.
8983 * @model: (allow-none): The model.
8985 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
8986 * set, it will remove it before setting the new model. If @model is %NULL,
8987 * then it will unset the old model.
8990 pspp_sheet_view_set_model (PsppSheetView *tree_view,
8991 GtkTreeModel *model)
8993 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8994 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
8996 if (model == tree_view->priv->model)
8999 if (tree_view->priv->scroll_to_path)
9001 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9002 tree_view->priv->scroll_to_path = NULL;
9005 if (tree_view->priv->model)
9007 GList *tmplist = tree_view->priv->columns;
9009 if (tree_view->priv->selected)
9010 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
9011 pspp_sheet_view_stop_editing (tree_view, TRUE);
9013 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9014 pspp_sheet_view_row_changed,
9016 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9017 pspp_sheet_view_row_inserted,
9019 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9020 pspp_sheet_view_row_deleted,
9022 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9023 pspp_sheet_view_rows_reordered,
9026 for (; tmplist; tmplist = tmplist->next)
9027 _pspp_sheet_view_column_unset_model (tmplist->data,
9028 tree_view->priv->model);
9030 tree_view->priv->prelight_node = -1;
9032 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
9033 tree_view->priv->drag_dest_row = NULL;
9034 gtk_tree_row_reference_free (tree_view->priv->cursor);
9035 tree_view->priv->cursor = NULL;
9036 gtk_tree_row_reference_free (tree_view->priv->anchor);
9037 tree_view->priv->anchor = NULL;
9038 gtk_tree_row_reference_free (tree_view->priv->top_row);
9039 tree_view->priv->top_row = NULL;
9040 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9041 tree_view->priv->scroll_to_path = NULL;
9043 tree_view->priv->scroll_to_column = NULL;
9045 g_object_unref (tree_view->priv->model);
9047 tree_view->priv->search_column = -1;
9048 tree_view->priv->fixed_height = -1;
9049 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
9050 tree_view->priv->last_button_x = -1;
9051 tree_view->priv->last_button_y = -1;
9054 tree_view->priv->model = model;
9056 if (tree_view->priv->model)
9060 if (tree_view->priv->search_column == -1)
9062 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
9064 GType type = gtk_tree_model_get_column_type (model, i);
9066 if (g_value_type_transformable (type, G_TYPE_STRING))
9068 tree_view->priv->search_column = i;
9074 g_object_ref (tree_view->priv->model);
9075 g_signal_connect (tree_view->priv->model,
9077 G_CALLBACK (pspp_sheet_view_row_changed),
9079 g_signal_connect (tree_view->priv->model,
9081 G_CALLBACK (pspp_sheet_view_row_inserted),
9083 g_signal_connect (tree_view->priv->model,
9085 G_CALLBACK (pspp_sheet_view_row_deleted),
9087 g_signal_connect (tree_view->priv->model,
9089 G_CALLBACK (pspp_sheet_view_rows_reordered),
9092 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
9094 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
9095 install_presize_handler (tree_view);
9098 g_object_notify (G_OBJECT (tree_view), "model");
9100 if (tree_view->priv->selection)
9101 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
9103 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9104 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9108 * pspp_sheet_view_get_selection:
9109 * @tree_view: A #PsppSheetView.
9111 * Gets the #PsppSheetSelection associated with @tree_view.
9113 * Return value: A #PsppSheetSelection object.
9115 PsppSheetSelection *
9116 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
9118 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9120 return tree_view->priv->selection;
9124 * pspp_sheet_view_get_hadjustment:
9125 * @tree_view: A #PsppSheetView
9127 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
9129 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9133 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
9135 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9137 if (tree_view->priv->hadjustment == NULL)
9138 pspp_sheet_view_set_hadjustment (tree_view, NULL);
9140 return tree_view->priv->hadjustment;
9144 * pspp_sheet_view_set_hadjustment:
9145 * @tree_view: A #PsppSheetView
9146 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9148 * Sets the #GtkAdjustment for the current horizontal aspect.
9151 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
9152 GtkAdjustment *adjustment)
9154 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9156 pspp_sheet_view_set_adjustments (tree_view,
9158 tree_view->priv->vadjustment);
9160 g_object_notify (G_OBJECT (tree_view), "hadjustment");
9164 * pspp_sheet_view_get_vadjustment:
9165 * @tree_view: A #PsppSheetView
9167 * Gets the #GtkAdjustment currently being used for the vertical aspect.
9169 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9173 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
9175 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9177 if (tree_view->priv->vadjustment == NULL)
9178 pspp_sheet_view_set_vadjustment (tree_view, NULL);
9180 return tree_view->priv->vadjustment;
9184 * pspp_sheet_view_set_vadjustment:
9185 * @tree_view: A #PsppSheetView
9186 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9188 * Sets the #GtkAdjustment for the current vertical aspect.
9191 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
9192 GtkAdjustment *adjustment)
9194 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9196 pspp_sheet_view_set_adjustments (tree_view,
9197 tree_view->priv->hadjustment,
9200 g_object_notify (G_OBJECT (tree_view), "vadjustment");
9203 /* Column and header operations */
9206 * pspp_sheet_view_get_headers_visible:
9207 * @tree_view: A #PsppSheetView.
9209 * Returns %TRUE if the headers on the @tree_view are visible.
9211 * Return value: Whether the headers are visible or not.
9214 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
9216 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9218 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9222 * pspp_sheet_view_set_headers_visible:
9223 * @tree_view: A #PsppSheetView.
9224 * @headers_visible: %TRUE if the headers are visible
9226 * Sets the visibility state of the headers.
9229 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
9230 gboolean headers_visible)
9234 PsppSheetViewColumn *column;
9236 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9238 headers_visible = !! headers_visible;
9240 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
9243 if (headers_visible)
9244 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9246 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9248 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9250 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
9251 if (headers_visible)
9253 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));
9255 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9256 pspp_sheet_view_map_buttons (tree_view);
9260 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9262 for (list = tree_view->priv->columns; list; list = list->next)
9264 column = list->data;
9266 gtk_widget_unmap (column->button);
9268 gdk_window_hide (tree_view->priv->header_window);
9272 tree_view->priv->vadjustment->page_size = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
9273 tree_view->priv->vadjustment->page_increment = (GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2;
9274 tree_view->priv->vadjustment->lower = 0;
9275 tree_view->priv->vadjustment->upper = tree_view->priv->height;
9276 gtk_adjustment_changed (tree_view->priv->vadjustment);
9278 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9280 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9284 * pspp_sheet_view_columns_autosize:
9285 * @tree_view: A #PsppSheetView.
9287 * Resizes all columns to their optimal width. Only works after the
9288 * treeview has been realized.
9291 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9293 gboolean dirty = FALSE;
9295 PsppSheetViewColumn *column;
9297 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9299 for (list = tree_view->priv->columns; list; list = list->next)
9301 column = list->data;
9302 _pspp_sheet_view_column_cell_set_dirty (column);
9307 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9311 * pspp_sheet_view_set_headers_clickable:
9312 * @tree_view: A #PsppSheetView.
9313 * @setting: %TRUE if the columns are clickable.
9315 * Allow the column title buttons to be clicked.
9318 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9323 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9325 for (list = tree_view->priv->columns; list; list = list->next)
9326 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9328 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9333 * pspp_sheet_view_get_headers_clickable:
9334 * @tree_view: A #PsppSheetView.
9336 * Returns whether all header columns are clickable.
9338 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9343 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9347 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9349 for (list = tree_view->priv->columns; list; list = list->next)
9350 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9357 * pspp_sheet_view_set_rules_hint
9358 * @tree_view: a #PsppSheetView
9359 * @setting: %TRUE if the tree requires reading across rows
9361 * This function tells GTK+ that the user interface for your
9362 * application requires users to read across tree rows and associate
9363 * cells with one another. By default, GTK+ will then render the tree
9364 * with alternating row colors. Do <emphasis>not</emphasis> use it
9365 * just because you prefer the appearance of the ruled tree; that's a
9366 * question for the theme. Some themes will draw tree rows in
9367 * alternating colors even when rules are turned off, and users who
9368 * prefer that appearance all the time can choose those themes. You
9369 * should call this function only as a <emphasis>semantic</emphasis>
9370 * hint to the theme engine that your tree makes alternating colors
9371 * useful from a functional standpoint (since it has lots of columns,
9376 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9379 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9381 setting = setting != FALSE;
9383 if (tree_view->priv->has_rules != setting)
9385 tree_view->priv->has_rules = setting;
9386 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9389 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9393 * pspp_sheet_view_get_rules_hint
9394 * @tree_view: a #PsppSheetView
9396 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9398 * Return value: %TRUE if rules are useful for the user of this tree
9401 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9403 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9405 return tree_view->priv->has_rules;
9408 /* Public Column functions
9412 * pspp_sheet_view_append_column:
9413 * @tree_view: A #PsppSheetView.
9414 * @column: The #PsppSheetViewColumn to add.
9416 * Appends @column to the list of columns.
9418 * Return value: The number of columns in @tree_view after appending.
9421 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9422 PsppSheetViewColumn *column)
9424 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9425 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9426 g_return_val_if_fail (column->tree_view == NULL, -1);
9428 return pspp_sheet_view_insert_column (tree_view, column, -1);
9433 * pspp_sheet_view_remove_column:
9434 * @tree_view: A #PsppSheetView.
9435 * @column: The #PsppSheetViewColumn to remove.
9437 * Removes @column from @tree_view.
9439 * Return value: The number of columns in @tree_view after removing.
9442 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9443 PsppSheetViewColumn *column)
9445 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9446 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9447 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9449 if (tree_view->priv->focus_column == column)
9450 tree_view->priv->focus_column = NULL;
9452 if (tree_view->priv->edited_column == column)
9454 pspp_sheet_view_stop_editing (tree_view, TRUE);
9456 /* no need to, but just to be sure ... */
9457 tree_view->priv->edited_column = NULL;
9460 _pspp_sheet_view_column_unset_tree_view (column);
9462 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9463 tree_view->priv->n_columns--;
9465 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9469 _pspp_sheet_view_column_unrealize_button (column);
9470 for (list = tree_view->priv->columns; list; list = list->next)
9472 PsppSheetViewColumn *tmp_column;
9474 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9475 if (tmp_column->visible)
9476 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9479 if (tree_view->priv->n_columns == 0 &&
9480 pspp_sheet_view_get_headers_visible (tree_view) &&
9481 tree_view->priv->header_window)
9482 gdk_window_hide (tree_view->priv->header_window);
9484 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9487 g_object_unref (column);
9488 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9490 return tree_view->priv->n_columns;
9494 * pspp_sheet_view_insert_column:
9495 * @tree_view: A #PsppSheetView.
9496 * @column: The #PsppSheetViewColumn to be inserted.
9497 * @position: The position to insert @column in.
9499 * This inserts the @column into the @tree_view at @position. If @position is
9500 * -1, then the column is inserted at the end.
9502 * Return value: The number of columns in @tree_view after insertion.
9505 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9506 PsppSheetViewColumn *column,
9509 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9510 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9511 g_return_val_if_fail (column->tree_view == NULL, -1);
9513 g_object_ref_sink (column);
9515 if (tree_view->priv->n_columns == 0 &&
9516 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9517 pspp_sheet_view_get_headers_visible (tree_view))
9519 gdk_window_show (tree_view->priv->header_window);
9522 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9524 tree_view->priv->n_columns++;
9526 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9528 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9532 _pspp_sheet_view_column_realize_button (column);
9534 for (list = tree_view->priv->columns; list; list = list->next)
9536 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9537 if (column->visible)
9538 _pspp_sheet_view_column_cell_set_dirty (column);
9540 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9543 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9545 return tree_view->priv->n_columns;
9549 * pspp_sheet_view_insert_column_with_attributes:
9550 * @tree_view: A #PsppSheetView
9551 * @position: The position to insert the new column in.
9552 * @title: The title to set the header to.
9553 * @cell: The #GtkCellRenderer.
9554 * @Varargs: A %NULL-terminated list of attributes.
9556 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9557 * @position. If @position is -1, then the newly created column is inserted at
9558 * the end. The column is initialized with the attributes given.
9560 * Return value: The number of columns in @tree_view after insertion.
9563 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9566 GtkCellRenderer *cell,
9569 PsppSheetViewColumn *column;
9574 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9576 column = pspp_sheet_view_column_new ();
9577 pspp_sheet_view_column_set_title (column, title);
9578 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9580 va_start (args, cell);
9582 attribute = va_arg (args, gchar *);
9584 while (attribute != NULL)
9586 column_id = va_arg (args, gint);
9587 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9588 attribute = va_arg (args, gchar *);
9593 pspp_sheet_view_insert_column (tree_view, column, position);
9595 return tree_view->priv->n_columns;
9599 * pspp_sheet_view_insert_column_with_data_func:
9600 * @tree_view: a #PsppSheetView
9601 * @position: Position to insert, -1 for append
9602 * @title: column title
9603 * @cell: cell renderer for column
9604 * @func: function to set attributes of cell renderer
9605 * @data: data for @func
9606 * @dnotify: destroy notifier for @data
9608 * Convenience function that inserts a new column into the #PsppSheetView
9609 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9610 * attributes (normally using data from the model). See also
9611 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9613 * Return value: number of columns in the tree view post-insert
9616 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9619 GtkCellRenderer *cell,
9620 PsppSheetCellDataFunc func,
9622 GDestroyNotify dnotify)
9624 PsppSheetViewColumn *column;
9626 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9628 column = pspp_sheet_view_column_new ();
9629 pspp_sheet_view_column_set_title (column, title);
9630 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9631 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9633 pspp_sheet_view_insert_column (tree_view, column, position);
9635 return tree_view->priv->n_columns;
9639 * pspp_sheet_view_get_column:
9640 * @tree_view: A #PsppSheetView.
9641 * @n: The position of the column, counting from 0.
9643 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9645 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9648 PsppSheetViewColumn *
9649 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9652 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9654 if (n < 0 || n >= tree_view->priv->n_columns)
9657 if (tree_view->priv->columns == NULL)
9660 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9664 * pspp_sheet_view_get_columns:
9665 * @tree_view: A #PsppSheetView
9667 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9668 * The returned list must be freed with g_list_free ().
9670 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9673 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9675 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9677 return g_list_copy (tree_view->priv->columns);
9681 * pspp_sheet_view_move_column_after:
9682 * @tree_view: A #PsppSheetView
9683 * @column: The #PsppSheetViewColumn to be moved.
9684 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9686 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9687 * @column is placed in the first position.
9690 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9691 PsppSheetViewColumn *column,
9692 PsppSheetViewColumn *base_column)
9694 GList *column_list_el, *base_el = NULL;
9696 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9698 column_list_el = g_list_find (tree_view->priv->columns, column);
9699 g_return_if_fail (column_list_el != NULL);
9703 base_el = g_list_find (tree_view->priv->columns, base_column);
9704 g_return_if_fail (base_el != NULL);
9707 if (column_list_el->prev == base_el)
9710 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9711 if (base_el == NULL)
9713 column_list_el->prev = NULL;
9714 column_list_el->next = tree_view->priv->columns;
9715 if (column_list_el->next)
9716 column_list_el->next->prev = column_list_el;
9717 tree_view->priv->columns = column_list_el;
9721 column_list_el->prev = base_el;
9722 column_list_el->next = base_el->next;
9723 if (column_list_el->next)
9724 column_list_el->next->prev = column_list_el;
9725 base_el->next = column_list_el;
9728 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9730 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9731 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9734 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9738 * pspp_sheet_view_set_column_drag_function:
9739 * @tree_view: A #PsppSheetView.
9740 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9741 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9742 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9744 * Sets a user function for determining where a column may be dropped when
9745 * dragged. This function is called on every column pair in turn at the
9746 * beginning of a column drag to determine where a drop can take place. The
9747 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9748 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9749 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9750 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9751 * @tree_view reverts to the default behavior of allowing all columns to be
9752 * dropped everywhere.
9755 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9756 PsppSheetViewColumnDropFunc func,
9758 GDestroyNotify destroy)
9760 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9762 if (tree_view->priv->column_drop_func_data_destroy)
9763 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9765 tree_view->priv->column_drop_func = func;
9766 tree_view->priv->column_drop_func_data = user_data;
9767 tree_view->priv->column_drop_func_data_destroy = destroy;
9771 * pspp_sheet_view_scroll_to_point:
9772 * @tree_view: a #PsppSheetView
9773 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9774 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9776 * Scrolls the tree view such that the top-left corner of the visible
9777 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9778 * in tree coordinates. The @tree_view must be realized before
9779 * this function is called. If it isn't, you probably want to be
9780 * using pspp_sheet_view_scroll_to_cell().
9782 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9785 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9789 GtkAdjustment *hadj;
9790 GtkAdjustment *vadj;
9792 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9793 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9795 hadj = tree_view->priv->hadjustment;
9796 vadj = tree_view->priv->vadjustment;
9799 gtk_adjustment_set_value (hadj, CLAMP (tree_x, hadj->lower, hadj->upper - hadj->page_size));
9801 gtk_adjustment_set_value (vadj, CLAMP (tree_y, vadj->lower, vadj->upper - vadj->page_size));
9805 * pspp_sheet_view_scroll_to_cell:
9806 * @tree_view: A #PsppSheetView.
9807 * @path: (allow-none): The path of the row to move to, or %NULL.
9808 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9809 * @use_align: whether to use alignment arguments, or %FALSE.
9810 * @row_align: The vertical alignment of the row specified by @path.
9811 * @col_align: The horizontal alignment of the column specified by @column.
9813 * Moves the alignments of @tree_view to the position specified by @column and
9814 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9815 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9816 * or @path need to be non-%NULL. @row_align determines where the row is
9817 * placed, and @col_align determines where @column is placed. Both are expected
9818 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9819 * right/bottom alignment, 0.5 means center.
9821 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9822 * tree does the minimum amount of work to scroll the cell onto the screen.
9823 * This means that the cell will be scrolled to the edge closest to its current
9824 * position. If the cell is currently visible on the screen, nothing is done.
9826 * This function only works if the model is set, and @path is a valid row on the
9827 * model. If the model changes before the @tree_view is realized, the centered
9828 * path will be modified to reflect this change.
9831 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9833 PsppSheetViewColumn *column,
9838 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9839 g_return_if_fail (tree_view->priv->model != NULL);
9840 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9841 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9842 g_return_if_fail (path != NULL || column != NULL);
9845 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9846 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9848 row_align = CLAMP (row_align, 0.0, 1.0);
9849 col_align = CLAMP (col_align, 0.0, 1.0);
9852 /* Note: Despite the benefits that come from having one code path for the
9853 * scrolling code, we short-circuit validate_visible_area's immplementation as
9854 * it is much slower than just going to the point.
9856 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9857 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9858 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9860 if (tree_view->priv->scroll_to_path)
9861 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9863 tree_view->priv->scroll_to_path = NULL;
9864 tree_view->priv->scroll_to_column = NULL;
9867 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9869 tree_view->priv->scroll_to_column = column;
9870 tree_view->priv->scroll_to_use_align = use_align;
9871 tree_view->priv->scroll_to_row_align = row_align;
9872 tree_view->priv->scroll_to_col_align = col_align;
9874 install_presize_handler (tree_view);
9878 GdkRectangle cell_rect;
9879 GdkRectangle vis_rect;
9880 gint dest_x, dest_y;
9882 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9883 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9885 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9887 dest_x = vis_rect.x;
9888 dest_y = vis_rect.y;
9894 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9898 if (cell_rect.x < vis_rect.x)
9899 dest_x = cell_rect.x;
9900 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9901 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9909 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9910 dest_y = MAX (dest_y, 0);
9914 if (cell_rect.y < vis_rect.y)
9915 dest_y = cell_rect.y;
9916 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9917 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9921 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9926 * pspp_sheet_view_row_activated:
9927 * @tree_view: A #PsppSheetView
9928 * @path: The #GtkTreePath to be activated.
9929 * @column: The #PsppSheetViewColumn to be activated.
9931 * Activates the cell determined by @path and @column.
9934 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9936 PsppSheetViewColumn *column)
9938 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9940 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
9945 * pspp_sheet_view_get_reorderable:
9946 * @tree_view: a #PsppSheetView
9948 * Retrieves whether the user can reorder the tree via drag-and-drop. See
9949 * pspp_sheet_view_set_reorderable().
9951 * Return value: %TRUE if the tree can be reordered.
9954 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
9956 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9958 return tree_view->priv->reorderable;
9962 * pspp_sheet_view_set_reorderable:
9963 * @tree_view: A #PsppSheetView.
9964 * @reorderable: %TRUE, if the tree can be reordered.
9966 * This function is a convenience function to allow you to reorder
9967 * models that support the #GtkDragSourceIface and the
9968 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
9969 * these. If @reorderable is %TRUE, then the user can reorder the
9970 * model by dragging and dropping rows. The developer can listen to
9971 * these changes by connecting to the model's row_inserted and
9972 * row_deleted signals. The reordering is implemented by setting up
9973 * the tree view as a drag source and destination. Therefore, drag and
9974 * drop can not be used in a reorderable view for any other purpose.
9976 * This function does not give you any degree of control over the order -- any
9977 * reordering is allowed. If more control is needed, you should probably
9978 * handle drag and drop manually.
9981 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
9982 gboolean reorderable)
9984 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9986 reorderable = reorderable != FALSE;
9988 if (tree_view->priv->reorderable == reorderable)
9993 const GtkTargetEntry row_targets[] = {
9994 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
9997 pspp_sheet_view_enable_model_drag_source (tree_view,
10000 G_N_ELEMENTS (row_targets),
10002 pspp_sheet_view_enable_model_drag_dest (tree_view,
10004 G_N_ELEMENTS (row_targets),
10009 pspp_sheet_view_unset_rows_drag_source (tree_view);
10010 pspp_sheet_view_unset_rows_drag_dest (tree_view);
10013 tree_view->priv->reorderable = reorderable;
10015 g_object_notify (G_OBJECT (tree_view), "reorderable");
10018 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
10019 is pressed, other rows will be unselected.
10021 If CLAMP_NODE is true, then the sheetview will scroll to make the row
10024 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
10026 gboolean clear_and_select,
10027 gboolean clamp_node,
10028 PsppSheetSelectMode mode)
10032 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10034 GtkTreePath *cursor_path;
10035 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10036 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
10037 gtk_tree_path_free (cursor_path);
10040 gtk_tree_row_reference_free (tree_view->priv->cursor);
10041 tree_view->priv->cursor = NULL;
10043 _pspp_sheet_view_find_node (tree_view, path, &node);
10044 tree_view->priv->cursor =
10045 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
10046 tree_view->priv->model,
10049 if (tree_view->priv->row_count > 0)
10053 if (clear_and_select && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
10054 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
10058 /* We have to re-find tree and node here again, somebody might have
10059 * cleared the node or the whole tree in the PsppSheetSelection::changed
10060 * callback. If the nodes differ we bail out here.
10062 _pspp_sheet_view_find_node (tree_view, path, &new_node);
10064 if (node != new_node)
10069 pspp_sheet_view_clamp_node_visible (tree_view, node);
10070 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10074 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
10078 * pspp_sheet_view_get_cursor:
10079 * @tree_view: A #PsppSheetView
10080 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
10081 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
10083 * Fills in @path and @focus_column with the current path and focus column. If
10084 * the cursor isn't currently set, then *@path will be %NULL. If no column
10085 * currently has focus, then *@focus_column will be %NULL.
10087 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
10088 * you are done with it.
10091 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
10092 GtkTreePath **path,
10093 PsppSheetViewColumn **focus_column)
10095 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10099 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10100 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10107 *focus_column = tree_view->priv->focus_column;
10112 * pspp_sheet_view_set_cursor:
10113 * @tree_view: A #PsppSheetView
10114 * @path: A #GtkTreePath
10115 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10116 * @start_editing: %TRUE if the specified cell should start being edited.
10118 * Sets the current keyboard focus to be at @path, and selects it. This is
10119 * useful when you want to focus the user's attention on a particular row. If
10120 * @focus_column is not %NULL, then focus is given to the column specified by
10121 * it. Additionally, if @focus_column is specified, and @start_editing is
10122 * %TRUE, then editing should be started in the specified cell.
10123 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
10124 * in order to give keyboard focus to the widget. Please note that editing
10125 * can only happen when the widget is realized.
10127 * If @path is invalid for @model, the current cursor (if any) will be unset
10128 * and the function will return without failing.
10131 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
10133 PsppSheetViewColumn *focus_column,
10134 gboolean start_editing)
10136 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
10137 NULL, start_editing);
10141 * pspp_sheet_view_set_cursor_on_cell:
10142 * @tree_view: A #PsppSheetView
10143 * @path: A #GtkTreePath
10144 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10145 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
10146 * @start_editing: %TRUE if the specified cell should start being edited.
10148 * Sets the current keyboard focus to be at @path, and selects it. This is
10149 * useful when you want to focus the user's attention on a particular row. If
10150 * @focus_column is not %NULL, then focus is given to the column specified by
10151 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
10152 * contains 2 or more editable or activatable cells, then focus is given to
10153 * the cell specified by @focus_cell. Additionally, if @focus_column is
10154 * specified, and @start_editing is %TRUE, then editing should be started in
10155 * the specified cell. This function is often followed by
10156 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
10157 * widget. Please note that editing can only happen when the widget is
10160 * If @path is invalid for @model, the current cursor (if any) will be unset
10161 * and the function will return without failing.
10166 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
10168 PsppSheetViewColumn *focus_column,
10169 GtkCellRenderer *focus_cell,
10170 gboolean start_editing)
10172 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10173 g_return_if_fail (path != NULL);
10174 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
10176 if (!tree_view->priv->model)
10181 g_return_if_fail (focus_column);
10182 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
10185 /* cancel the current editing, if it exists */
10186 if (tree_view->priv->edited_column &&
10187 tree_view->priv->edited_column->editable_widget)
10188 pspp_sheet_view_stop_editing (tree_view, TRUE);
10190 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
10192 if (focus_column && focus_column->visible)
10195 gboolean column_in_tree = FALSE;
10197 for (list = tree_view->priv->columns; list; list = list->next)
10198 if (list->data == focus_column)
10200 column_in_tree = TRUE;
10203 g_return_if_fail (column_in_tree);
10204 tree_view->priv->focus_column = focus_column;
10206 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
10208 pspp_sheet_view_start_editing (tree_view, path);
10210 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
10211 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
10217 * pspp_sheet_view_get_bin_window:
10218 * @tree_view: A #PsppSheetView
10220 * Returns the window that @tree_view renders to. This is used primarily to
10221 * compare to <literal>event->window</literal> to confirm that the event on
10222 * @tree_view is on the right window.
10224 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
10227 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
10229 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
10231 return tree_view->priv->bin_window;
10235 * pspp_sheet_view_get_path_at_pos:
10236 * @tree_view: A #PsppSheetView.
10237 * @x: The x position to be identified (relative to bin_window).
10238 * @y: The y position to be identified (relative to bin_window).
10239 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
10240 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
10241 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
10242 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
10244 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10245 * (please see pspp_sheet_view_get_bin_window()).
10246 * That is, @x and @y are relative to an events coordinates. @x and @y must
10247 * come from an event on the @tree_view only where <literal>event->window ==
10248 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10249 * things like popup menus. If @path is non-%NULL, then it will be filled
10250 * with the #GtkTreePath at that point. This path should be freed with
10251 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10252 * with the column at that point. @cell_x and @cell_y return the coordinates
10253 * relative to the cell background (i.e. the @background_area passed to
10254 * gtk_cell_renderer_render()). This function is only meaningful if
10255 * @tree_view is realized. Therefore this function will always return %FALSE
10256 * if @tree_view is not realized or does not have a model.
10258 * For converting widget coordinates (eg. the ones you get from
10259 * GtkWidget::query-tooltip), please see
10260 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10262 * Return value: %TRUE if a row exists at that coordinate.
10265 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10268 GtkTreePath **path,
10269 PsppSheetViewColumn **column,
10276 g_return_val_if_fail (tree_view != NULL, FALSE);
10283 if (tree_view->priv->bin_window == NULL)
10286 if (tree_view->priv->row_count == 0)
10289 if (x > tree_view->priv->hadjustment->upper)
10292 if (x < 0 || y < 0)
10295 if (column || cell_x)
10297 PsppSheetViewColumn *tmp_column;
10298 PsppSheetViewColumn *last_column = NULL;
10300 gint remaining_x = x;
10301 gboolean found = FALSE;
10304 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10305 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10307 list = (rtl ? list->prev : list->next))
10309 tmp_column = list->data;
10311 if (tmp_column->visible == FALSE)
10314 last_column = tmp_column;
10315 if (remaining_x <= tmp_column->width)
10320 *column = tmp_column;
10323 *cell_x = remaining_x;
10327 remaining_x -= tmp_column->width;
10330 /* If found is FALSE and there is a last_column, then it the remainder
10331 * space is in that area
10338 *column = last_column;
10341 *cell_x = last_column->width + remaining_x;
10350 y_offset = pspp_sheet_view_find_offset (tree_view,
10351 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10358 *cell_y = y_offset;
10361 *path = _pspp_sheet_view_find_path (tree_view, node);
10366 /* Computes 'cell_area' from 'background_area', which must be the background
10367 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10368 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10369 the cell area as passed to _pspp_sheet_view_column_cell_render().
10371 'column' is required to properly adjust 'cell_area->x' and
10372 'cell_area->width'. It may be set to NULL if these values are not of
10373 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10376 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10377 PsppSheetViewColumn *column,
10378 const GdkRectangle *background_area,
10379 gboolean subtract_focus_rect,
10380 GdkRectangle *cell_area)
10382 gint vertical_separator;
10383 gint horizontal_separator;
10385 *cell_area = *background_area;
10387 gtk_widget_style_get (GTK_WIDGET (tree_view),
10388 "vertical-separator", &vertical_separator,
10389 "horizontal-separator", &horizontal_separator,
10391 cell_area->x += horizontal_separator / 2;
10392 cell_area->y += vertical_separator / 2;
10393 cell_area->width -= horizontal_separator;
10394 cell_area->height -= vertical_separator;
10396 if (subtract_focus_rect)
10398 int focus_line_width;
10400 gtk_widget_style_get (GTK_WIDGET (tree_view),
10401 "focus-line-width", &focus_line_width,
10403 cell_area->x += focus_line_width;
10404 cell_area->y += focus_line_width;
10405 cell_area->width -= 2 * focus_line_width;
10406 cell_area->height -= 2 * focus_line_width;
10409 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10411 gint grid_line_width;
10412 gtk_widget_style_get (GTK_WIDGET (tree_view),
10413 "grid-line-width", &grid_line_width,
10416 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10417 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10420 PsppSheetViewColumn *first_column, *last_column;
10423 /* Find the last visible column. */
10424 last_column = NULL;
10425 for (list = g_list_last (tree_view->priv->columns);
10429 PsppSheetViewColumn *c = list->data;
10437 /* Find the first visible column. */
10438 first_column = NULL;
10439 for (list = g_list_first (tree_view->priv->columns);
10443 PsppSheetViewColumn *c = list->data;
10451 if (column == first_column)
10453 cell_area->width -= grid_line_width / 2;
10455 else if (column == last_column)
10457 cell_area->x += grid_line_width / 2;
10458 cell_area->width -= grid_line_width / 2;
10462 cell_area->x += grid_line_width / 2;
10463 cell_area->width -= grid_line_width;
10467 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10468 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10470 cell_area->y += grid_line_width / 2;
10471 cell_area->height -= grid_line_width;
10475 if (column == NULL)
10478 cell_area->width = 0;
10483 * pspp_sheet_view_get_cell_area:
10484 * @tree_view: a #PsppSheetView
10485 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10486 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10487 * @rect: rectangle to fill with cell rect
10489 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10490 * row specified by @path and the column specified by @column. If @path is
10491 * %NULL, or points to a path not currently displayed, the @y and @height fields
10492 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10493 * fields will be filled with 0. The sum of all cell rects does not cover the
10494 * entire tree; there are extra pixels in between rows, for example. The
10495 * returned rectangle is equivalent to the @cell_area passed to
10496 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10500 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10502 PsppSheetViewColumn *column,
10503 GdkRectangle *rect)
10505 GdkRectangle background_area;
10507 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10508 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10509 g_return_if_fail (rect != NULL);
10510 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10511 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10513 pspp_sheet_view_get_background_area (tree_view, path, column,
10515 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10520 * pspp_sheet_view_get_background_area:
10521 * @tree_view: a #PsppSheetView
10522 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10523 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10524 * @rect: rectangle to fill with cell background rect
10526 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10527 * row specified by @path and the column specified by @column. If @path is
10528 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10529 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10530 * fields will be filled with 0. The returned rectangle is equivalent to the
10531 * @background_area passed to gtk_cell_renderer_render(). These background
10532 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10533 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10534 * itself, excluding surrounding borders.
10538 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10540 PsppSheetViewColumn *column,
10541 GdkRectangle *rect)
10545 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10546 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10547 g_return_if_fail (rect != NULL);
10556 /* Get vertical coords */
10558 _pspp_sheet_view_find_node (tree_view, path, &node);
10562 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10564 rect->height = ROW_HEIGHT (tree_view);
10571 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10572 rect->width = x2 - rect->x;
10577 * pspp_sheet_view_get_visible_rect:
10578 * @tree_view: a #PsppSheetView
10579 * @visible_rect: rectangle to fill
10581 * Fills @visible_rect with the currently-visible region of the
10582 * buffer, in tree coordinates. Convert to bin_window coordinates with
10583 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10584 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10585 * scrollable area of the tree.
10588 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10589 GdkRectangle *visible_rect)
10593 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10595 widget = GTK_WIDGET (tree_view);
10599 visible_rect->x = tree_view->priv->hadjustment->value;
10600 visible_rect->y = tree_view->priv->vadjustment->value;
10601 visible_rect->width = widget->allocation.width;
10602 visible_rect->height = widget->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10607 * pspp_sheet_view_widget_to_tree_coords:
10608 * @tree_view: a #PsppSheetView
10609 * @wx: X coordinate relative to bin_window
10610 * @wy: Y coordinate relative to bin_window
10611 * @tx: return location for tree X coordinate
10612 * @ty: return location for tree Y coordinate
10614 * Converts bin_window coordinates to coordinates for the
10615 * tree (the full scrollable area of the tree).
10617 * Deprecated: 2.12: Due to historial reasons the name of this function is
10618 * incorrect. For converting coordinates relative to the widget to
10619 * bin_window coordinates, please see
10620 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10624 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10630 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10633 *tx = wx + tree_view->priv->hadjustment->value;
10635 *ty = wy + tree_view->priv->dy;
10639 * pspp_sheet_view_tree_to_widget_coords:
10640 * @tree_view: a #PsppSheetView
10641 * @tx: tree X coordinate
10642 * @ty: tree Y coordinate
10643 * @wx: return location for X coordinate relative to bin_window
10644 * @wy: return location for Y coordinate relative to bin_window
10646 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10647 * to bin_window coordinates.
10649 * Deprecated: 2.12: Due to historial reasons the name of this function is
10650 * incorrect. For converting bin_window coordinates to coordinates relative
10651 * to bin_window, please see
10652 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10656 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10662 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10665 *wx = tx - tree_view->priv->hadjustment->value;
10667 *wy = ty - tree_view->priv->dy;
10672 * pspp_sheet_view_convert_widget_to_tree_coords:
10673 * @tree_view: a #PsppSheetView
10674 * @wx: X coordinate relative to the widget
10675 * @wy: Y coordinate relative to the widget
10676 * @tx: return location for tree X coordinate
10677 * @ty: return location for tree Y coordinate
10679 * Converts widget coordinates to coordinates for the
10680 * tree (the full scrollable area of the tree).
10685 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10693 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10695 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10698 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10704 * pspp_sheet_view_convert_tree_to_widget_coords:
10705 * @tree_view: a #PsppSheetView
10706 * @tx: X coordinate relative to the tree
10707 * @ty: Y coordinate relative to the tree
10708 * @wx: return location for widget X coordinate
10709 * @wy: return location for widget Y coordinate
10711 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10712 * to widget coordinates.
10717 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10725 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10727 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10730 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10736 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10737 * @tree_view: a #PsppSheetView
10738 * @wx: X coordinate relative to the widget
10739 * @wy: Y coordinate relative to the widget
10740 * @bx: return location for bin_window X coordinate
10741 * @by: return location for bin_window Y coordinate
10743 * Converts widget coordinates to coordinates for the bin_window
10744 * (see pspp_sheet_view_get_bin_window()).
10749 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10755 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10758 *bx = wx + tree_view->priv->hadjustment->value;
10760 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10764 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10765 * @tree_view: a #PsppSheetView
10766 * @bx: bin_window X coordinate
10767 * @by: bin_window Y coordinate
10768 * @wx: return location for widget X coordinate
10769 * @wy: return location for widget Y coordinate
10771 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10772 * to widget relative coordinates.
10777 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10783 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10786 *wx = bx - tree_view->priv->hadjustment->value;
10788 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10792 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10793 * @tree_view: a #PsppSheetView
10794 * @tx: tree X coordinate
10795 * @ty: tree Y coordinate
10796 * @bx: return location for X coordinate relative to bin_window
10797 * @by: return location for Y coordinate relative to bin_window
10799 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10800 * to bin_window coordinates.
10805 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10811 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10816 *by = ty - tree_view->priv->dy;
10820 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10821 * @tree_view: a #PsppSheetView
10822 * @bx: X coordinate relative to bin_window
10823 * @by: Y coordinate relative to bin_window
10824 * @tx: return location for tree X coordinate
10825 * @ty: return location for tree Y coordinate
10827 * Converts bin_window coordinates to coordinates for the
10828 * tree (the full scrollable area of the tree).
10833 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10839 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10844 *ty = by + tree_view->priv->dy;
10850 * pspp_sheet_view_get_visible_range:
10851 * @tree_view: A #PsppSheetView
10852 * @start_path: (allow-none): Return location for start of region, or %NULL.
10853 * @end_path: (allow-none): Return location for end of region, or %NULL.
10855 * Sets @start_path and @end_path to be the first and last visible path.
10856 * Note that there may be invisible paths in between.
10858 * The paths should be freed with gtk_tree_path_free() after use.
10860 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10865 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10866 GtkTreePath **start_path,
10867 GtkTreePath **end_path)
10872 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10874 if (!tree_view->priv->row_count)
10881 pspp_sheet_view_find_offset (tree_view,
10882 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10885 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10894 if (tree_view->priv->height < tree_view->priv->vadjustment->page_size)
10895 y = tree_view->priv->height - 1;
10897 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, tree_view->priv->vadjustment->page_size) - 1;
10899 pspp_sheet_view_find_offset (tree_view, y, &node);
10901 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10910 unset_reorderable (PsppSheetView *tree_view)
10912 if (tree_view->priv->reorderable)
10914 tree_view->priv->reorderable = FALSE;
10915 g_object_notify (G_OBJECT (tree_view), "reorderable");
10920 * pspp_sheet_view_enable_model_drag_source:
10921 * @tree_view: a #PsppSheetView
10922 * @start_button_mask: Mask of allowed buttons to start drag
10923 * @targets: the table of targets that the drag will support
10924 * @n_targets: the number of items in @targets
10925 * @actions: the bitmask of possible actions for a drag from this
10928 * Turns @tree_view into a drag source for automatic DND. Calling this
10929 * method sets #PsppSheetView:reorderable to %FALSE.
10932 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10933 GdkModifierType start_button_mask,
10934 const GtkTargetEntry *targets,
10936 GdkDragAction actions)
10938 TreeViewDragInfo *di;
10940 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10942 gtk_drag_source_set (GTK_WIDGET (tree_view),
10948 di = ensure_info (tree_view);
10950 di->start_button_mask = start_button_mask;
10951 di->source_actions = actions;
10952 di->source_set = TRUE;
10954 unset_reorderable (tree_view);
10958 * pspp_sheet_view_enable_model_drag_dest:
10959 * @tree_view: a #PsppSheetView
10960 * @targets: the table of targets that the drag will support
10961 * @n_targets: the number of items in @targets
10962 * @actions: the bitmask of possible actions for a drag from this
10965 * Turns @tree_view into a drop destination for automatic DND. Calling
10966 * this method sets #PsppSheetView:reorderable to %FALSE.
10969 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
10970 const GtkTargetEntry *targets,
10972 GdkDragAction actions)
10974 TreeViewDragInfo *di;
10976 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10978 gtk_drag_dest_set (GTK_WIDGET (tree_view),
10984 di = ensure_info (tree_view);
10985 di->dest_set = TRUE;
10987 unset_reorderable (tree_view);
10991 * pspp_sheet_view_unset_rows_drag_source:
10992 * @tree_view: a #PsppSheetView
10994 * Undoes the effect of
10995 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
10996 * #PsppSheetView:reorderable to %FALSE.
10999 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
11001 TreeViewDragInfo *di;
11003 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11005 di = get_info (tree_view);
11009 if (di->source_set)
11011 gtk_drag_source_unset (GTK_WIDGET (tree_view));
11012 di->source_set = FALSE;
11015 if (!di->dest_set && !di->source_set)
11016 remove_info (tree_view);
11019 unset_reorderable (tree_view);
11023 * pspp_sheet_view_unset_rows_drag_dest:
11024 * @tree_view: a #PsppSheetView
11026 * Undoes the effect of
11027 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
11028 * #PsppSheetView:reorderable to %FALSE.
11031 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
11033 TreeViewDragInfo *di;
11035 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11037 di = get_info (tree_view);
11043 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
11044 di->dest_set = FALSE;
11047 if (!di->dest_set && !di->source_set)
11048 remove_info (tree_view);
11051 unset_reorderable (tree_view);
11055 * pspp_sheet_view_set_drag_dest_row:
11056 * @tree_view: a #PsppSheetView
11057 * @path: (allow-none): The path of the row to highlight, or %NULL.
11058 * @pos: Specifies whether to drop before, after or into the row
11060 * Sets the row that is highlighted for feedback.
11063 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
11065 PsppSheetViewDropPosition pos)
11067 GtkTreePath *current_dest;
11069 /* Note; this function is exported to allow a custom DND
11070 * implementation, so it can't touch TreeViewDragInfo
11073 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11075 current_dest = NULL;
11077 if (tree_view->priv->drag_dest_row)
11079 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11080 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
11083 /* special case a drop on an empty model */
11084 tree_view->priv->empty_view_drop = 0;
11086 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
11087 && gtk_tree_path_get_depth (path) == 1
11088 && gtk_tree_path_get_indices (path)[0] == 0)
11092 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
11096 tree_view->priv->empty_view_drop = 1;
11099 tree_view->priv->drag_dest_pos = pos;
11103 tree_view->priv->drag_dest_row =
11104 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
11105 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
11108 tree_view->priv->drag_dest_row = NULL;
11112 int node, new_node;
11114 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
11115 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
11119 new_node = pspp_sheet_view_node_next (tree_view, node);
11121 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11123 new_node = pspp_sheet_view_node_prev (tree_view, node);
11125 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11127 gtk_tree_path_free (current_dest);
11132 * pspp_sheet_view_get_drag_dest_row:
11133 * @tree_view: a #PsppSheetView
11134 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11135 * @pos: (allow-none): Return location for the drop position, or %NULL
11137 * Gets information about the row that is highlighted for feedback.
11140 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
11141 GtkTreePath **path,
11142 PsppSheetViewDropPosition *pos)
11144 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11148 if (tree_view->priv->drag_dest_row)
11149 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11152 if (tree_view->priv->empty_view_drop)
11153 *path = gtk_tree_path_new_from_indices (0, -1);
11160 *pos = tree_view->priv->drag_dest_pos;
11164 * pspp_sheet_view_get_dest_row_at_pos:
11165 * @tree_view: a #PsppSheetView
11166 * @drag_x: the position to determine the destination row for
11167 * @drag_y: the position to determine the destination row for
11168 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11169 * @pos: (allow-none): Return location for the drop position, or %NULL
11171 * Determines the destination row for a given position. @drag_x and
11172 * @drag_y are expected to be in widget coordinates. This function is only
11173 * meaningful if @tree_view is realized. Therefore this function will always
11174 * return %FALSE if @tree_view is not realized or does not have a model.
11176 * Return value: whether there is a row at the given position, %TRUE if this
11177 * is indeed the case.
11180 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
11183 GtkTreePath **path,
11184 PsppSheetViewDropPosition *pos)
11188 gdouble offset_into_row;
11191 PsppSheetViewColumn *column = NULL;
11192 GtkTreePath *tmp_path = NULL;
11194 /* Note; this function is exported to allow a custom DND
11195 * implementation, so it can't touch TreeViewDragInfo
11198 g_return_val_if_fail (tree_view != NULL, FALSE);
11199 g_return_val_if_fail (drag_x >= 0, FALSE);
11200 g_return_val_if_fail (drag_y >= 0, FALSE);
11205 if (tree_view->priv->bin_window == NULL)
11208 if (tree_view->priv->row_count == 0)
11211 /* If in the top third of a row, we drop before that row; if
11212 * in the bottom third, drop after that row; if in the middle,
11213 * and the row has children, drop into the row.
11215 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
11218 if (!pspp_sheet_view_get_path_at_pos (tree_view,
11227 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
11230 offset_into_row = cell_y;
11235 gtk_tree_path_free (tmp_path);
11239 third = cell.height / 3.0;
11243 if (offset_into_row < third)
11245 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11247 else if (offset_into_row < (cell.height / 2.0))
11249 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11251 else if (offset_into_row < third * 2.0)
11253 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11257 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11266 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11268 * pspp_sheet_view_create_row_drag_icon:
11269 * @tree_view: a #PsppSheetView
11270 * @path: a #GtkTreePath in @tree_view
11272 * Creates a #GdkPixmap representation of the row at @path.
11273 * This image is used for a drag icon.
11275 * Return value: a newly-allocated pixmap of the drag icon.
11278 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11285 GdkRectangle background_area;
11286 GdkRectangle expose_area;
11288 /* start drawing inside the black outline */
11290 GdkDrawable *drawable;
11291 gint bin_window_width;
11294 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11295 g_return_val_if_fail (path != NULL, NULL);
11297 widget = GTK_WIDGET (tree_view);
11299 if (!gtk_widget_get_realized (widget))
11302 _pspp_sheet_view_find_node (tree_view,
11309 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11316 background_area.y = y;
11317 background_area.height = ROW_HEIGHT (tree_view);
11319 bin_window_width = gdk_window_get_width (tree_view->priv->bin_window);
11321 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11322 bin_window_width + 2,
11323 background_area.height + 2,
11328 expose_area.width = bin_window_width + 2;
11329 expose_area.height = background_area.height + 2;
11331 #if GTK3_TRANSITION
11332 gdk_draw_rectangle (drawable,
11333 widget->style->base_gc [gtk_widget_get_state (widget)],
11336 bin_window_width + 2,
11337 background_area.height + 2);
11340 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11342 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11344 list = (rtl ? list->prev : list->next))
11346 PsppSheetViewColumn *column = list->data;
11347 GdkRectangle cell_area;
11348 gint vertical_separator;
11350 if (!column->visible)
11353 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11355 background_area.x = cell_offset;
11356 background_area.width = column->width;
11358 gtk_widget_style_get (widget,
11359 "vertical-separator", &vertical_separator,
11362 cell_area = background_area;
11364 cell_area.y += vertical_separator / 2;
11365 cell_area.height -= vertical_separator;
11367 if (pspp_sheet_view_column_cell_is_visible (column))
11368 _pspp_sheet_view_column_cell_render (column,
11374 cell_offset += column->width;
11377 #if GTK3_TRANSITION
11378 gdk_draw_rectangle (drawable,
11379 widget->style->black_gc,
11382 bin_window_width + 1,
11383 background_area.height + 1);
11391 * pspp_sheet_view_set_destroy_count_func:
11392 * @tree_view: A #PsppSheetView
11393 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11394 * @data: (allow-none): User data to be passed to @func, or %NULL
11395 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11397 * This function should almost never be used. It is meant for private use by
11398 * ATK for determining the number of visible children that are removed when a row is deleted.
11401 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11402 PsppSheetDestroyCountFunc func,
11404 GDestroyNotify destroy)
11406 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11408 if (tree_view->priv->destroy_count_destroy)
11409 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11411 tree_view->priv->destroy_count_func = func;
11412 tree_view->priv->destroy_count_data = data;
11413 tree_view->priv->destroy_count_destroy = destroy;
11418 * Interactive search
11422 * pspp_sheet_view_set_enable_search:
11423 * @tree_view: A #PsppSheetView
11424 * @enable_search: %TRUE, if the user can search interactively
11426 * If @enable_search is set, then the user can type in text to search through
11427 * the tree interactively (this is sometimes called "typeahead find").
11429 * Note that even if this is %FALSE, the user can still initiate a search
11430 * using the "start-interactive-search" key binding.
11433 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11434 gboolean enable_search)
11436 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11438 enable_search = !!enable_search;
11440 if (tree_view->priv->enable_search != enable_search)
11442 tree_view->priv->enable_search = enable_search;
11443 g_object_notify (G_OBJECT (tree_view), "enable-search");
11448 * pspp_sheet_view_get_enable_search:
11449 * @tree_view: A #PsppSheetView
11451 * Returns whether or not the tree allows to start interactive searching
11452 * by typing in text.
11454 * Return value: whether or not to let the user search interactively
11457 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11459 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11461 return tree_view->priv->enable_search;
11466 * pspp_sheet_view_get_search_column:
11467 * @tree_view: A #PsppSheetView
11469 * Gets the column searched on by the interactive search code.
11471 * Return value: the column the interactive search code searches in.
11474 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11476 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11478 return (tree_view->priv->search_column);
11482 * pspp_sheet_view_set_search_column:
11483 * @tree_view: A #PsppSheetView
11484 * @column: the column of the model to search in, or -1 to disable searching
11486 * Sets @column as the column where the interactive search code should
11487 * search in for the current model.
11489 * If the search column is set, users can use the "start-interactive-search"
11490 * key binding to bring up search popup. The enable-search property controls
11491 * whether simply typing text will also start an interactive search.
11493 * Note that @column refers to a column of the current model. The search
11494 * column is reset to -1 when the model is changed.
11497 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11500 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11501 g_return_if_fail (column >= -1);
11503 if (tree_view->priv->search_column == column)
11506 tree_view->priv->search_column = column;
11507 g_object_notify (G_OBJECT (tree_view), "search-column");
11511 * pspp_sheet_view_get_search_equal_func:
11512 * @tree_view: A #PsppSheetView
11514 * Returns the compare function currently in use.
11516 * Return value: the currently used compare function for the search code.
11519 PsppSheetViewSearchEqualFunc
11520 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11522 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11524 return tree_view->priv->search_equal_func;
11528 * pspp_sheet_view_set_search_equal_func:
11529 * @tree_view: A #PsppSheetView
11530 * @search_equal_func: the compare function to use during the search
11531 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11532 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11534 * Sets the compare function for the interactive search capabilities; note
11535 * that somewhat like strcmp() returning 0 for equality
11536 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11539 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11540 PsppSheetViewSearchEqualFunc search_equal_func,
11541 gpointer search_user_data,
11542 GDestroyNotify search_destroy)
11544 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11545 g_return_if_fail (search_equal_func != NULL);
11547 if (tree_view->priv->search_destroy)
11548 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11550 tree_view->priv->search_equal_func = search_equal_func;
11551 tree_view->priv->search_user_data = search_user_data;
11552 tree_view->priv->search_destroy = search_destroy;
11553 if (tree_view->priv->search_equal_func == NULL)
11554 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11558 * pspp_sheet_view_get_search_entry:
11559 * @tree_view: A #PsppSheetView
11561 * Returns the #GtkEntry which is currently in use as interactive search
11562 * entry for @tree_view. In case the built-in entry is being used, %NULL
11563 * will be returned.
11565 * Return value: the entry currently in use as search entry.
11570 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11572 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11574 if (tree_view->priv->search_custom_entry_set)
11575 return GTK_ENTRY (tree_view->priv->search_entry);
11581 * pspp_sheet_view_set_search_entry:
11582 * @tree_view: A #PsppSheetView
11583 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11585 * Sets the entry which the interactive search code will use for this
11586 * @tree_view. This is useful when you want to provide a search entry
11587 * in our interface at all time at a fixed position. Passing %NULL for
11588 * @entry will make the interactive search code use the built-in popup
11594 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11597 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11598 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11600 if (tree_view->priv->search_custom_entry_set)
11602 if (tree_view->priv->search_entry_changed_id)
11604 g_signal_handler_disconnect (tree_view->priv->search_entry,
11605 tree_view->priv->search_entry_changed_id);
11606 tree_view->priv->search_entry_changed_id = 0;
11608 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11609 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11612 g_object_unref (tree_view->priv->search_entry);
11614 else if (tree_view->priv->search_window)
11616 gtk_widget_destroy (tree_view->priv->search_window);
11618 tree_view->priv->search_window = NULL;
11623 tree_view->priv->search_entry = g_object_ref (entry);
11624 tree_view->priv->search_custom_entry_set = TRUE;
11626 if (tree_view->priv->search_entry_changed_id == 0)
11628 tree_view->priv->search_entry_changed_id =
11629 g_signal_connect (tree_view->priv->search_entry, "changed",
11630 G_CALLBACK (pspp_sheet_view_search_init),
11634 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11635 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11638 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11642 tree_view->priv->search_entry = NULL;
11643 tree_view->priv->search_custom_entry_set = FALSE;
11648 * pspp_sheet_view_set_search_position_func:
11649 * @tree_view: A #PsppSheetView
11650 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11651 * to use the default search position function
11652 * @data: (allow-none): user data to pass to @func, or %NULL
11653 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11655 * Sets the function to use when positioning the search dialog.
11660 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11661 PsppSheetViewSearchPositionFunc func,
11662 gpointer user_data,
11663 GDestroyNotify destroy)
11665 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11667 if (tree_view->priv->search_position_destroy)
11668 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11670 tree_view->priv->search_position_func = func;
11671 tree_view->priv->search_position_user_data = user_data;
11672 tree_view->priv->search_position_destroy = destroy;
11673 if (tree_view->priv->search_position_func == NULL)
11674 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11678 * pspp_sheet_view_get_search_position_func:
11679 * @tree_view: A #PsppSheetView
11681 * Returns the positioning function currently in use.
11683 * Return value: the currently used function for positioning the search dialog.
11687 PsppSheetViewSearchPositionFunc
11688 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11690 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11692 return tree_view->priv->search_position_func;
11697 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11698 PsppSheetView *tree_view)
11700 if (tree_view->priv->disable_popdown)
11703 if (tree_view->priv->search_entry_changed_id)
11705 g_signal_handler_disconnect (tree_view->priv->search_entry,
11706 tree_view->priv->search_entry_changed_id);
11707 tree_view->priv->search_entry_changed_id = 0;
11709 if (tree_view->priv->typeselect_flush_timeout)
11711 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11712 tree_view->priv->typeselect_flush_timeout = 0;
11715 if (gtk_widget_get_visible (search_dialog))
11717 /* send focus-in event */
11718 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11719 gtk_widget_hide (search_dialog);
11720 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11721 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11726 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11727 GtkWidget *search_dialog,
11728 gpointer user_data)
11731 gint tree_x, tree_y;
11732 gint tree_width, tree_height;
11733 GdkWindow *tree_window = gtk_widget_get_window (GTK_WIDGET (tree_view));
11734 GdkScreen *screen = gdk_window_get_screen (tree_window);
11735 GtkRequisition requisition;
11737 GdkRectangle monitor;
11739 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11740 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11742 gtk_widget_realize (search_dialog);
11744 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11745 tree_width = gdk_window_get_width (tree_window);
11746 tree_height = gdk_window_get_height (tree_window);
11748 gtk_widget_size_request (search_dialog, &requisition);
11750 if (tree_x + tree_width > gdk_screen_get_width (screen))
11751 x = gdk_screen_get_width (screen) - requisition.width;
11752 else if (tree_x + tree_width - requisition.width < 0)
11755 x = tree_x + tree_width - requisition.width;
11757 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11758 y = gdk_screen_get_height (screen) - requisition.height;
11759 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11762 y = tree_y + tree_height;
11764 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11768 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11772 PsppSheetView *tree_view = (PsppSheetView *)data;
11774 tree_view->priv->disable_popdown = 1;
11775 g_signal_connect (menu, "hide",
11776 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11779 /* Because we're visible but offscreen, we just set a flag in the preedit
11783 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11784 PsppSheetView *tree_view)
11786 tree_view->priv->imcontext_changed = 1;
11787 if (tree_view->priv->typeselect_flush_timeout)
11789 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11790 tree_view->priv->typeselect_flush_timeout =
11791 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11792 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11799 pspp_sheet_view_search_activate (GtkEntry *entry,
11800 PsppSheetView *tree_view)
11805 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11808 /* If we have a row selected and it's the cursor row, we activate
11810 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11812 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11814 _pspp_sheet_view_find_node (tree_view, path, &node);
11816 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11817 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11819 gtk_tree_path_free (path);
11824 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11826 PsppSheetView *tree_view = (PsppSheetView *)data;
11828 tree_view->priv->disable_popdown = 0;
11834 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11837 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11841 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11842 GdkEventAny *event,
11843 PsppSheetView *tree_view)
11845 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11847 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11853 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11854 GdkEventButton *event,
11855 PsppSheetView *tree_view)
11857 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11859 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11861 if (event->window == tree_view->priv->bin_window)
11862 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11868 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11869 GdkEventScroll *event,
11870 PsppSheetView *tree_view)
11872 gboolean retval = FALSE;
11874 if (event->direction == GDK_SCROLL_UP)
11876 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11879 else if (event->direction == GDK_SCROLL_DOWN)
11881 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11885 /* renew the flush timeout */
11886 if (retval && tree_view->priv->typeselect_flush_timeout
11887 && !tree_view->priv->search_custom_entry_set)
11889 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11890 tree_view->priv->typeselect_flush_timeout =
11891 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11892 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11900 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11901 GdkEventKey *event,
11902 PsppSheetView *tree_view)
11904 gboolean retval = FALSE;
11906 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11907 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11909 /* close window and cancel the search */
11910 if (!tree_view->priv->search_custom_entry_set
11911 && (event->keyval == GDK_Escape ||
11912 event->keyval == GDK_Tab ||
11913 event->keyval == GDK_KP_Tab ||
11914 event->keyval == GDK_ISO_Left_Tab))
11916 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11920 /* select previous matching iter */
11921 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11923 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11924 gtk_widget_error_bell (widget);
11929 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11930 && (event->keyval == GDK_g || event->keyval == GDK_G))
11932 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11933 gtk_widget_error_bell (widget);
11938 /* select next matching iter */
11939 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
11941 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11942 gtk_widget_error_bell (widget);
11947 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
11948 && (event->keyval == GDK_g || event->keyval == GDK_G))
11950 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11951 gtk_widget_error_bell (widget);
11956 /* renew the flush timeout */
11957 if (retval && tree_view->priv->typeselect_flush_timeout
11958 && !tree_view->priv->search_custom_entry_set)
11960 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11961 tree_view->priv->typeselect_flush_timeout =
11962 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11963 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11970 /* this function returns FALSE if there is a search string but
11971 * nothing was found, and TRUE otherwise.
11974 pspp_sheet_view_search_move (GtkWidget *window,
11975 PsppSheetView *tree_view,
11983 GtkTreeModel *model;
11984 PsppSheetSelection *selection;
11986 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
11988 g_return_val_if_fail (text != NULL, FALSE);
11990 len = strlen (text);
11992 if (up && tree_view->priv->selected_iter == 1)
11993 return strlen (text) < 1;
11995 len = strlen (text);
12000 model = pspp_sheet_view_get_model (tree_view);
12001 selection = pspp_sheet_view_get_selection (tree_view);
12004 pspp_sheet_selection_unselect_all (selection);
12005 if (!gtk_tree_model_get_iter_first (model, &iter))
12008 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
12009 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
12014 tree_view->priv->selected_iter += up?(-1):(1);
12019 /* return to old iter */
12021 gtk_tree_model_get_iter_first (model, &iter);
12022 pspp_sheet_view_search_iter (model, selection,
12024 &count, tree_view->priv->selected_iter);
12030 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
12034 gpointer search_data)
12036 gboolean retval = TRUE;
12038 gchar *normalized_string;
12039 gchar *normalized_key;
12040 gchar *case_normalized_string = NULL;
12041 gchar *case_normalized_key = NULL;
12042 GValue value = {0,};
12043 GValue transformed = {0,};
12045 gtk_tree_model_get_value (model, iter, column, &value);
12047 g_value_init (&transformed, G_TYPE_STRING);
12049 if (!g_value_transform (&value, &transformed))
12051 g_value_unset (&value);
12055 g_value_unset (&value);
12057 str = g_value_get_string (&transformed);
12060 g_value_unset (&transformed);
12064 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
12065 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
12067 if (normalized_string && normalized_key)
12069 case_normalized_string = g_utf8_casefold (normalized_string, -1);
12070 case_normalized_key = g_utf8_casefold (normalized_key, -1);
12072 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
12076 g_value_unset (&transformed);
12077 g_free (normalized_key);
12078 g_free (normalized_string);
12079 g_free (case_normalized_key);
12080 g_free (case_normalized_string);
12086 pspp_sheet_view_search_iter (GtkTreeModel *model,
12087 PsppSheetSelection *selection,
12096 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
12098 path = gtk_tree_model_get_path (model, iter);
12099 _pspp_sheet_view_find_node (tree_view, path, &node);
12103 gboolean done = FALSE;
12105 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
12110 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
12112 pspp_sheet_selection_select_iter (selection, iter);
12113 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12116 gtk_tree_path_free (path);
12125 node = pspp_sheet_view_node_next (tree_view, node);
12131 has_next = gtk_tree_model_iter_next (model, iter);
12134 gtk_tree_path_next (path);
12137 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
12142 gtk_tree_path_free (path);
12144 /* we've run out of tree, done with this func */
12156 pspp_sheet_view_search_init (GtkWidget *entry,
12157 PsppSheetView *tree_view)
12163 GtkTreeModel *model;
12164 PsppSheetSelection *selection;
12166 g_return_if_fail (GTK_IS_ENTRY (entry));
12167 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12169 text = gtk_entry_get_text (GTK_ENTRY (entry));
12171 model = pspp_sheet_view_get_model (tree_view);
12172 selection = pspp_sheet_view_get_selection (tree_view);
12175 pspp_sheet_selection_unselect_all (selection);
12176 if (tree_view->priv->typeselect_flush_timeout
12177 && !tree_view->priv->search_custom_entry_set)
12179 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12180 tree_view->priv->typeselect_flush_timeout =
12181 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12182 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12189 if (!gtk_tree_model_get_iter_first (model, &iter))
12192 ret = pspp_sheet_view_search_iter (model, selection,
12197 tree_view->priv->selected_iter = 1;
12201 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
12202 PsppSheetView *tree_view)
12204 if (tree_view->priv->edited_column == NULL)
12207 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
12208 tree_view->priv->edited_column = NULL;
12210 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
12211 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12213 g_signal_handlers_disconnect_by_func (cell_editable,
12214 pspp_sheet_view_remove_widget,
12216 g_signal_handlers_disconnect_by_func (cell_editable,
12217 pspp_sheet_view_editable_button_press_event,
12219 g_signal_handlers_disconnect_by_func (cell_editable,
12220 pspp_sheet_view_editable_clicked,
12223 gtk_container_remove (GTK_CONTAINER (tree_view),
12224 GTK_WIDGET (cell_editable));
12226 /* FIXME should only redraw a single node */
12227 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12231 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
12232 GtkTreePath *cursor_path)
12235 GdkRectangle background_area;
12236 GdkRectangle cell_area;
12237 GtkCellEditable *editable_widget = NULL;
12238 gchar *path_string;
12239 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
12240 gint retval = FALSE;
12243 g_assert (tree_view->priv->focus_column);
12245 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12248 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12249 if (cursor_node < 0)
12252 path_string = gtk_tree_path_to_string (cursor_path);
12253 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12255 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12256 tree_view->priv->model,
12258 pspp_sheet_view_get_background_area (tree_view,
12260 tree_view->priv->focus_column,
12262 pspp_sheet_view_get_cell_area (tree_view,
12264 tree_view->priv->focus_column,
12267 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12276 if (editable_widget != NULL)
12280 GtkCellRenderer *cell;
12283 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12285 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12288 area.width -= right + left;
12290 pspp_sheet_view_real_start_editing (tree_view,
12291 tree_view->priv->focus_column,
12300 g_free (path_string);
12305 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12306 GdkEventButton *event,
12307 PsppSheetView *sheet_view)
12311 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12312 "pspp-sheet-view-node"));
12313 return pspp_sheet_view_row_head_clicked (sheet_view,
12315 sheet_view->priv->edited_column,
12320 pspp_sheet_view_editable_clicked (GtkButton *button,
12321 PsppSheetView *sheet_view)
12323 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12328 is_all_selected (GtkWidget *widget)
12330 GtkEntryBuffer *buffer;
12331 gint start_pos, end_pos;
12333 if (!GTK_IS_ENTRY (widget))
12336 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12337 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12338 &start_pos, &end_pos)
12340 && end_pos == gtk_entry_buffer_get_length (buffer));
12344 is_at_left (GtkWidget *widget)
12346 return (GTK_IS_ENTRY (widget)
12347 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12351 is_at_right (GtkWidget *widget)
12353 GtkEntryBuffer *buffer;
12356 if (!GTK_IS_ENTRY (widget))
12359 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12360 length = gtk_entry_buffer_get_length (buffer);
12361 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12365 pspp_sheet_view_event (GtkWidget *widget,
12366 GdkEventKey *event,
12367 PsppSheetView *tree_view)
12369 PsppSheetViewColumn *column;
12376 /* Intercept only key press events.
12377 It would make sense to use "key-press-event" instead of "event", but
12378 GtkEntry attaches its own signal handler to "key-press-event" that runs
12379 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12381 if (event->type != GDK_KEY_PRESS)
12384 keyval = event->keyval;
12386 switch (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12389 switch (event->keyval)
12391 case GDK_Left: case GDK_KP_Left:
12392 case GDK_Home: case GDK_KP_Home:
12393 if (!is_all_selected (widget) && !is_at_left (widget))
12397 case GDK_Right: case GDK_KP_Right:
12398 case GDK_End: case GDK_KP_End:
12399 if (!is_all_selected (widget) && !is_at_right (widget))
12403 case GDK_Up: case GDK_KP_Up:
12404 case GDK_Down: case GDK_KP_Down:
12407 case GDK_Page_Up: case GDK_KP_Page_Up:
12408 case GDK_Page_Down: case GDK_KP_Page_Down:
12419 case GDK_Tab: case GDK_KP_Tab:
12420 case GDK_ISO_Left_Tab:
12429 case GDK_SHIFT_MASK:
12430 switch (event->keyval)
12433 case GDK_ISO_Left_Tab:
12442 case GDK_CONTROL_MASK:
12443 switch (event->keyval)
12445 case GDK_Left: case GDK_KP_Left:
12446 if (!is_all_selected (widget) && !is_at_left (widget))
12450 case GDK_Right: case GDK_KP_Right:
12451 if (!is_all_selected (widget) && !is_at_right (widget))
12455 case GDK_Up: case GDK_KP_Up:
12456 case GDK_Down: case GDK_KP_Down:
12468 row = tree_view->priv->edited_row;
12469 column = tree_view->priv->edited_column;
12470 path = gtk_tree_path_new_from_indices (row, -1);
12472 pspp_sheet_view_stop_editing (tree_view, cancel);
12473 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12475 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12476 gtk_tree_path_free (path);
12478 handled = gtk_binding_set_activate (edit_bindings, keyval, event->state,
12479 GTK_OBJECT (tree_view));
12481 g_signal_stop_emission_by_name (widget, "event");
12483 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12484 pspp_sheet_view_start_editing (tree_view, path);
12485 gtk_tree_path_free (path);
12491 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12494 PsppSheetView *sheet_view = data;
12496 g_signal_connect (widget, "event",
12497 G_CALLBACK (pspp_sheet_view_event),
12500 if (GTK_IS_CONTAINER (widget))
12501 gtk_container_foreach (GTK_CONTAINER (widget),
12502 pspp_sheet_view_override_cell_keypresses,
12507 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12508 PsppSheetViewColumn *column,
12510 GtkCellEditable *cell_editable,
12511 GdkRectangle *cell_area,
12515 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12516 gint pre_val = tree_view->priv->vadjustment->value;
12517 GtkRequisition requisition;
12520 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12522 tree_view->priv->edited_column = column;
12523 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12525 row = gtk_tree_path_get_indices (path)[0];
12526 tree_view->priv->edited_row = row;
12527 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12528 cell_area->y += pre_val - (int)tree_view->priv->vadjustment->value;
12530 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12531 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12532 tree_view->priv->anchor_column = column;
12534 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12536 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12538 if (requisition.height < cell_area->height)
12540 gint diff = cell_area->height - requisition.height;
12541 pspp_sheet_view_put (tree_view,
12542 GTK_WIDGET (cell_editable),
12543 cell_area->x, cell_area->y + diff/2,
12544 cell_area->width, requisition.height);
12548 pspp_sheet_view_put (tree_view,
12549 GTK_WIDGET (cell_editable),
12550 cell_area->x, cell_area->y,
12551 cell_area->width, cell_area->height);
12554 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12555 (GdkEvent *)event);
12557 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12558 g_signal_connect (cell_editable, "remove-widget",
12559 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12560 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12561 GTK_IS_BUTTON (cell_editable))
12563 g_signal_connect (cell_editable, "button-press-event",
12564 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12566 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12567 GINT_TO_POINTER (row));
12568 g_signal_connect (cell_editable, "clicked",
12569 G_CALLBACK (pspp_sheet_view_editable_clicked),
12573 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12578 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12579 gboolean cancel_editing)
12581 PsppSheetViewColumn *column;
12582 GtkCellRenderer *cell;
12584 if (tree_view->priv->edited_column == NULL)
12588 * This is very evil. We need to do this, because
12589 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12590 * later on. If pspp_sheet_view_row_changed notices
12591 * tree_view->priv->edited_column != NULL, it'll call
12592 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12594 * Please read that again if you intend to modify anything here.
12597 column = tree_view->priv->edited_column;
12598 tree_view->priv->edited_column = NULL;
12600 cell = _pspp_sheet_view_column_get_edited_cell (column);
12601 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12603 if (!cancel_editing)
12604 gtk_cell_editable_editing_done (column->editable_widget);
12606 tree_view->priv->edited_column = column;
12608 gtk_cell_editable_remove_widget (column->editable_widget);
12613 * pspp_sheet_view_set_hover_selection:
12614 * @tree_view: a #PsppSheetView
12615 * @hover: %TRUE to enable hover selection mode
12617 * Enables of disables the hover selection mode of @tree_view.
12618 * Hover selection makes the selected row follow the pointer.
12619 * Currently, this works only for the selection modes
12620 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12625 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12628 hover = hover != FALSE;
12630 if (hover != tree_view->priv->hover_selection)
12632 tree_view->priv->hover_selection = hover;
12634 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12639 * pspp_sheet_view_get_hover_selection:
12640 * @tree_view: a #PsppSheetView
12642 * Returns whether hover selection mode is turned on for @tree_view.
12644 * Return value: %TRUE if @tree_view is in hover selection mode
12649 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12651 return tree_view->priv->hover_selection;
12655 * pspp_sheet_view_set_rubber_banding:
12656 * @tree_view: a #PsppSheetView
12657 * @enable: %TRUE to enable rubber banding
12659 * Enables or disables rubber banding in @tree_view. If the selection mode is
12660 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12661 * banding will allow the user to select multiple rows by dragging the mouse.
12666 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12669 enable = enable != FALSE;
12671 if (enable != tree_view->priv->rubber_banding_enable)
12673 tree_view->priv->rubber_banding_enable = enable;
12675 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12680 * pspp_sheet_view_get_rubber_banding:
12681 * @tree_view: a #PsppSheetView
12683 * Returns whether rubber banding is turned on for @tree_view. If the
12684 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12685 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12686 * select multiple rows by dragging the mouse.
12688 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12693 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12695 return tree_view->priv->rubber_banding_enable;
12699 * pspp_sheet_view_is_rubber_banding_active:
12700 * @tree_view: a #PsppSheetView
12702 * Returns whether a rubber banding operation is currently being done
12705 * Return value: %TRUE if a rubber banding operation is currently being
12706 * done in @tree_view.
12711 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12713 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12715 if (tree_view->priv->rubber_banding_enable
12716 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12723 pspp_sheet_view_grab_notify (GtkWidget *widget,
12724 gboolean was_grabbed)
12726 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12728 tree_view->priv->in_grab = !was_grabbed;
12732 tree_view->priv->pressed_button = -1;
12734 if (tree_view->priv->rubber_band_status)
12735 pspp_sheet_view_stop_rubber_band (tree_view);
12740 pspp_sheet_view_state_changed (GtkWidget *widget,
12741 GtkStateType previous_state)
12743 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12745 if (gtk_widget_get_realized (widget))
12747 gdk_window_set_back_pixmap (gtk_widget_get_window (widget), NULL, FALSE);
12748 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
12751 gtk_widget_queue_draw (widget);
12755 * pspp_sheet_view_get_grid_lines:
12756 * @tree_view: a #PsppSheetView
12758 * Returns which grid lines are enabled in @tree_view.
12760 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12765 PsppSheetViewGridLines
12766 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12768 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12770 return tree_view->priv->grid_lines;
12774 * pspp_sheet_view_set_grid_lines:
12775 * @tree_view: a #PsppSheetView
12776 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12779 * Sets which grid lines to draw in @tree_view.
12784 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12785 PsppSheetViewGridLines grid_lines)
12787 PsppSheetViewPrivate *priv;
12788 PsppSheetViewGridLines old_grid_lines;
12790 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12792 priv = tree_view->priv;
12794 old_grid_lines = priv->grid_lines;
12795 priv->grid_lines = grid_lines;
12797 if (old_grid_lines != grid_lines)
12799 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12801 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12806 * pspp_sheet_view_get_special_cells:
12807 * @tree_view: a #PsppSheetView
12809 * Returns which grid lines are enabled in @tree_view.
12811 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12812 * the sheet view contain special cells.
12814 PsppSheetViewSpecialCells
12815 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12817 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12819 return tree_view->priv->special_cells;
12823 * pspp_sheet_view_set_special_cells:
12824 * @tree_view: a #PsppSheetView
12825 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12826 * the sheet view contain special cells.
12828 * Sets whether rows in the sheet view contain special cells, controlling the
12829 * rendering of row selections.
12832 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12833 PsppSheetViewSpecialCells special_cells)
12835 PsppSheetViewPrivate *priv;
12837 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12839 priv = tree_view->priv;
12841 if (priv->special_cells != special_cells)
12843 priv->special_cells = special_cells;
12844 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12845 g_object_notify (G_OBJECT (tree_view), "special-cells");
12850 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12852 /* XXX (re)calculate fixed_height if necessary */
12853 return tree_view->priv->fixed_height;
12857 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12860 g_return_if_fail (fixed_height > 0);
12862 if (tree_view->priv->fixed_height != fixed_height)
12864 tree_view->priv->fixed_height = fixed_height;
12865 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12867 if (!tree_view->priv->fixed_height_set)
12869 tree_view->priv->fixed_height_set = TRUE;
12870 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12875 * pspp_sheet_view_set_tooltip_row:
12876 * @tree_view: a #PsppSheetView
12877 * @tooltip: a #GtkTooltip
12878 * @path: a #GtkTreePath
12880 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12881 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12882 * See also gtk_tooltip_set_tip_area().
12887 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12888 GtkTooltip *tooltip,
12891 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12892 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12894 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12898 * pspp_sheet_view_set_tooltip_cell:
12899 * @tree_view: a #PsppSheetView
12900 * @tooltip: a #GtkTooltip
12901 * @path: (allow-none): a #GtkTreePath or %NULL
12902 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12903 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12905 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12906 * in common. For example if @path is %NULL and @column is set, the tip
12907 * area will be set to the full area covered by @column. See also
12908 * gtk_tooltip_set_tip_area().
12910 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12915 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12916 GtkTooltip *tooltip,
12918 PsppSheetViewColumn *column,
12919 GtkCellRenderer *cell)
12923 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12924 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12925 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12926 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12928 /* Determine x values. */
12929 if (column && cell)
12934 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12935 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12937 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12940 rect.width = width;
12946 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
12947 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12950 rect.width = tmp.width;
12955 rect.width = GTK_WIDGET (tree_view)->allocation.width;
12958 /* Determine y values. */
12963 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
12964 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12967 rect.height = tmp.height;
12972 rect.height = tree_view->priv->vadjustment->page_size;
12975 gtk_tooltip_set_tip_area (tooltip, &rect);
12979 * pspp_sheet_view_get_tooltip_context:
12980 * @tree_view: a #PsppSheetView
12981 * @x: the x coordinate (relative to widget coordinates)
12982 * @y: the y coordinate (relative to widget coordinates)
12983 * @keyboard_tip: whether this is a keyboard tooltip or not
12984 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
12985 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
12986 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
12988 * This function is supposed to be used in a #GtkWidget::query-tooltip
12989 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
12990 * which are received in the signal handler, should be passed to this
12991 * function without modification.
12993 * The return value indicates whether there is a tree view row at the given
12994 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
12995 * tooltips the row returned will be the cursor row. When %TRUE, then any of
12996 * @model, @path and @iter which have been provided will be set to point to
12997 * that row and the corresponding model. @x and @y will always be converted
12998 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
13000 * Return value: whether or not the given tooltip context points to a row.
13005 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
13008 gboolean keyboard_tip,
13009 GtkTreeModel **model,
13010 GtkTreePath **path,
13013 GtkTreePath *tmppath = NULL;
13015 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
13016 g_return_val_if_fail (x != NULL, FALSE);
13017 g_return_val_if_fail (y != NULL, FALSE);
13021 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
13028 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
13031 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
13032 &tmppath, NULL, NULL, NULL))
13037 *model = pspp_sheet_view_get_model (tree_view);
13040 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
13046 gtk_tree_path_free (tmppath);
13052 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
13055 gboolean keyboard_tip,
13056 GtkTooltip *tooltip,
13059 GValue value = { 0, };
13060 GValue transformed = { 0, };
13063 GtkTreeModel *model;
13064 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
13066 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
13069 &model, &path, &iter))
13072 gtk_tree_model_get_value (model, &iter,
13073 tree_view->priv->tooltip_column, &value);
13075 g_value_init (&transformed, G_TYPE_STRING);
13077 if (!g_value_transform (&value, &transformed))
13079 g_value_unset (&value);
13080 gtk_tree_path_free (path);
13085 g_value_unset (&value);
13087 if (!g_value_get_string (&transformed))
13089 g_value_unset (&transformed);
13090 gtk_tree_path_free (path);
13095 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
13096 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
13098 gtk_tree_path_free (path);
13099 g_value_unset (&transformed);
13105 * pspp_sheet_view_set_tooltip_column:
13106 * @tree_view: a #PsppSheetView
13107 * @column: an integer, which is a valid column number for @tree_view's model
13109 * If you only plan to have simple (text-only) tooltips on full rows, you
13110 * can use this function to have #PsppSheetView handle these automatically
13111 * for you. @column should be set to the column in @tree_view's model
13112 * containing the tooltip texts, or -1 to disable this feature.
13114 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
13115 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
13117 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
13118 * so &, <, etc have to be escaped in the text.
13123 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
13126 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13128 if (column == tree_view->priv->tooltip_column)
13133 g_signal_handlers_disconnect_by_func (tree_view,
13134 pspp_sheet_view_set_tooltip_query_cb,
13136 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
13140 if (tree_view->priv->tooltip_column == -1)
13142 g_signal_connect (tree_view, "query-tooltip",
13143 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
13144 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
13148 tree_view->priv->tooltip_column = column;
13149 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
13153 * pspp_sheet_view_get_tooltip_column:
13154 * @tree_view: a #PsppSheetView
13156 * Returns the column of @tree_view's model which is being used for
13157 * displaying tooltips on @tree_view's rows.
13159 * Return value: the index of the tooltip column that is currently being
13160 * used, or -1 if this is disabled.
13165 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
13167 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
13169 return tree_view->priv->tooltip_column;
13173 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
13174 GValue *return_accu,
13175 const GValue *handler_return,
13178 gboolean continue_emission;
13179 gboolean signal_handled;
13181 signal_handled = g_value_get_boolean (handler_return);
13182 g_value_set_boolean (return_accu, signal_handled);
13183 continue_emission = !signal_handled;
13185 return continue_emission;
13190 pspp_sheet_view_grid_lines_get_type (void)
13192 static GType etype = 0;
13193 if (G_UNLIKELY(etype == 0)) {
13194 static const GEnumValue values[] = {
13195 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
13196 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
13197 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
13198 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
13201 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
13207 pspp_sheet_view_special_cells_get_type (void)
13209 static GType etype = 0;
13210 if (G_UNLIKELY(etype == 0)) {
13211 static const GEnumValue values[] = {
13212 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
13213 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
13214 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
13217 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);