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 (widget->window);
1455 pspp_sheet_view_realize (GtkWidget *widget)
1458 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1460 GdkWindowAttr attributes;
1461 gint attributes_mask;
1463 gtk_widget_set_realized (widget, TRUE);
1465 /* Make the main, clipping window */
1466 attributes.window_type = GDK_WINDOW_CHILD;
1467 attributes.x = widget->allocation.x;
1468 attributes.y = widget->allocation.y;
1469 attributes.width = widget->allocation.width;
1470 attributes.height = widget->allocation.height;
1471 attributes.wclass = GDK_INPUT_OUTPUT;
1472 attributes.visual = gtk_widget_get_visual (widget);
1473 attributes.colormap = gtk_widget_get_colormap (widget);
1474 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1476 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1478 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1479 &attributes, attributes_mask);
1480 gdk_window_set_user_data (widget->window, 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 (widget->window,
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 (widget->window,
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, widget->window);
1519 gdk_window_set_back_pixmap (widget->window, 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);
1540 for (i = 0; i < 5; ++i)
1542 tree_view->priv->grid_line_gc[i] = gdk_gc_new (widget->window);
1543 gdk_gc_copy (tree_view->priv->grid_line_gc[i], widget->style->text_aa_gc[i]);
1548 pspp_sheet_view_unrealize (GtkWidget *widget)
1551 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1552 PsppSheetViewPrivate *priv = tree_view->priv;
1555 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1557 if (priv->scroll_timeout != 0)
1559 g_source_remove (priv->scroll_timeout);
1560 priv->scroll_timeout = 0;
1563 if (priv->open_dest_timeout != 0)
1565 g_source_remove (priv->open_dest_timeout);
1566 priv->open_dest_timeout = 0;
1569 if (priv->presize_handler_timer != 0)
1571 g_source_remove (priv->presize_handler_timer);
1572 priv->presize_handler_timer = 0;
1575 if (priv->validate_rows_timer != 0)
1577 g_source_remove (priv->validate_rows_timer);
1578 priv->validate_rows_timer = 0;
1581 if (priv->scroll_sync_timer != 0)
1583 g_source_remove (priv->scroll_sync_timer);
1584 priv->scroll_sync_timer = 0;
1587 if (priv->typeselect_flush_timeout)
1589 g_source_remove (priv->typeselect_flush_timeout);
1590 priv->typeselect_flush_timeout = 0;
1593 for (list = priv->columns; list; list = list->next)
1594 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1596 gdk_window_set_user_data (priv->bin_window, NULL);
1597 gdk_window_destroy (priv->bin_window);
1598 priv->bin_window = NULL;
1600 gdk_window_set_user_data (priv->header_window, NULL);
1601 gdk_window_destroy (priv->header_window);
1602 priv->header_window = NULL;
1604 if (priv->drag_window)
1606 gdk_window_set_user_data (priv->drag_window, NULL);
1607 gdk_window_destroy (priv->drag_window);
1608 priv->drag_window = NULL;
1611 if (priv->drag_highlight_window)
1613 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1614 gdk_window_destroy (priv->drag_highlight_window);
1615 priv->drag_highlight_window = NULL;
1618 for (x = 0 ; x < 5 ; ++x)
1619 g_object_unref (priv->grid_line_gc[x]);
1621 if (tree_view->priv->columns != NULL)
1623 list = tree_view->priv->columns;
1626 PsppSheetViewColumn *column;
1627 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1629 pspp_sheet_view_remove_column (tree_view, column);
1631 tree_view->priv->columns = NULL;
1635 /* GtkWidget::size_request helper */
1637 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1641 tree_view->priv->header_height = 0;
1643 if (tree_view->priv->model)
1645 for (list = tree_view->priv->columns; list; list = list->next)
1647 GtkRequisition requisition;
1648 PsppSheetViewColumn *column = list->data;
1650 pspp_sheet_view_column_size_request (column, &requisition);
1651 column->button_request = requisition.width;
1652 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1658 /* Called only by ::size_request */
1660 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1663 PsppSheetViewColumn *column;
1666 if (tree_view->priv->model == NULL)
1668 tree_view->priv->width = 0;
1669 tree_view->priv->prev_width = 0;
1670 tree_view->priv->height = 0;
1674 tree_view->priv->prev_width = tree_view->priv->width;
1675 tree_view->priv->width = 0;
1677 /* keep this in sync with size_allocate below */
1678 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1680 gint real_requested_width = 0;
1681 column = list->data;
1682 if (!column->visible)
1685 if (column->use_resized_width)
1687 real_requested_width = column->resized_width;
1691 real_requested_width = column->fixed_width;
1694 if (column->min_width != -1)
1695 real_requested_width = MAX (real_requested_width, column->min_width);
1696 if (column->max_width != -1)
1697 real_requested_width = MIN (real_requested_width, column->max_width);
1699 tree_view->priv->width += real_requested_width;
1702 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1706 pspp_sheet_view_size_request (GtkWidget *widget,
1707 GtkRequisition *requisition)
1709 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1712 /* we validate some rows initially just to make sure we have some size.
1713 * In practice, with a lot of static lists, this should get a good width.
1715 initialize_fixed_height_mode (tree_view);
1716 pspp_sheet_view_size_request_columns (tree_view);
1717 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1719 requisition->width = tree_view->priv->width;
1720 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1722 tmp_list = tree_view->priv->children;
1726 PsppSheetViewChild *child = tmp_list->data;
1727 GtkRequisition child_requisition;
1729 tmp_list = tmp_list->next;
1731 if (gtk_widget_get_visible (child->widget))
1732 gtk_widget_size_request (child->widget, &child_requisition);
1737 invalidate_column (PsppSheetView *tree_view,
1738 PsppSheetViewColumn *column)
1740 gint column_offset = 0;
1742 GtkWidget *widget = GTK_WIDGET (tree_view);
1745 if (!gtk_widget_get_realized (widget))
1748 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1749 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1751 list = (rtl ? list->prev : list->next))
1753 PsppSheetViewColumn *tmpcolumn = list->data;
1754 if (tmpcolumn == column)
1756 GdkRectangle invalid_rect;
1758 invalid_rect.x = column_offset;
1760 invalid_rect.width = column->width;
1761 invalid_rect.height = widget->allocation.height;
1763 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
1767 column_offset += tmpcolumn->width;
1772 invalidate_last_column (PsppSheetView *tree_view)
1777 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1779 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1781 last_column = (rtl ? last_column->next : last_column->prev))
1783 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1785 invalidate_column (tree_view, last_column->data);
1792 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1793 PsppSheetViewColumn *column)
1795 gint real_requested_width;
1797 if (column->use_resized_width)
1799 real_requested_width = column->resized_width;
1803 real_requested_width = column->fixed_width;
1806 if (column->min_width != -1)
1807 real_requested_width = MAX (real_requested_width, column->min_width);
1808 if (column->max_width != -1)
1809 real_requested_width = MIN (real_requested_width, column->max_width);
1811 return real_requested_width;
1815 span_intersects (int a0, int a_width,
1816 int b0, int b_width)
1818 int a1 = a0 + a_width;
1819 int b1 = b0 + b_width;
1820 return (a0 >= b0 && a0 < b1) || (b0 >= a0 && b0 < a1);
1823 /* GtkWidget::size_allocate helper */
1825 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1826 gboolean *width_changed)
1828 PsppSheetView *tree_view;
1829 GList *list, *first_column, *last_column;
1830 PsppSheetViewColumn *column;
1831 GtkAllocation allocation;
1833 gint extra, extra_per_column;
1834 gint full_requested_width = 0;
1835 gint number_of_expand_columns = 0;
1836 gboolean column_changed = FALSE;
1839 tree_view = PSPP_SHEET_VIEW (widget);
1841 for (last_column = g_list_last (tree_view->priv->columns);
1842 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1843 last_column = last_column->prev)
1845 if (last_column == NULL)
1848 for (first_column = g_list_first (tree_view->priv->columns);
1849 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1850 first_column = first_column->next)
1854 allocation.height = tree_view->priv->header_height;
1856 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1858 /* find out how many extra space and expandable columns we have */
1859 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1861 column = (PsppSheetViewColumn *)list->data;
1863 if (!column->visible)
1866 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1869 number_of_expand_columns++;
1872 extra = MAX (widget->allocation.width - full_requested_width, 0);
1873 if (number_of_expand_columns > 0)
1874 extra_per_column = extra/number_of_expand_columns;
1876 extra_per_column = 0;
1878 for (list = (rtl ? last_column : first_column);
1879 list != (rtl ? first_column->prev : last_column->next);
1880 list = (rtl ? list->prev : list->next))
1882 gint real_requested_width = 0;
1885 column = list->data;
1886 old_width = column->width;
1888 if (!column->visible)
1891 /* We need to handle the dragged button specially.
1893 if (column == tree_view->priv->drag_column)
1895 GtkAllocation drag_allocation;
1896 gdk_drawable_get_size (tree_view->priv->drag_window,
1897 &(drag_allocation.width),
1898 &(drag_allocation.height));
1899 drag_allocation.x = 0;
1900 drag_allocation.y = 0;
1901 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1903 width += drag_allocation.width;
1907 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1909 allocation.x = width;
1910 column->width = real_requested_width;
1914 if (number_of_expand_columns == 1)
1916 /* We add the remander to the last column as
1918 column->width += extra;
1922 column->width += extra_per_column;
1923 extra -= extra_per_column;
1924 number_of_expand_columns --;
1928 if (column->width != old_width)
1929 g_object_notify (G_OBJECT (column), "width");
1931 allocation.width = column->width;
1932 width += column->width;
1934 if (column->width > old_width)
1935 column_changed = TRUE;
1937 pspp_sheet_view_column_size_allocate (column, &allocation);
1939 if (span_intersects (allocation.x, allocation.width,
1940 tree_view->priv->hadjustment->value,
1941 widget->allocation.width)
1942 && gtk_widget_get_realized (widget))
1943 pspp_sheet_view_column_set_need_button (column, TRUE);
1946 gdk_window_move_resize (column->window,
1947 allocation.x + (rtl ? 0 : allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1949 TREE_VIEW_DRAG_WIDTH, allocation.height);
1952 /* We change the width here. The user might have been resizing columns,
1953 * so the total width of the tree view changes.
1955 tree_view->priv->width = width;
1957 *width_changed = TRUE;
1960 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
1965 pspp_sheet_view_size_allocate (GtkWidget *widget,
1966 GtkAllocation *allocation)
1968 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1970 gboolean width_changed = FALSE;
1971 gint old_width = widget->allocation.width;
1973 if (allocation->width != widget->allocation.width)
1974 width_changed = TRUE;
1976 widget->allocation = *allocation;
1978 tmp_list = tree_view->priv->children;
1982 GtkAllocation allocation;
1984 PsppSheetViewChild *child = tmp_list->data;
1985 tmp_list = tmp_list->next;
1987 /* totally ignore our child's requisition */
1988 allocation.x = child->x;
1989 allocation.y = child->y;
1990 allocation.width = child->width;
1991 allocation.height = child->height;
1992 gtk_widget_size_allocate (child->widget, &allocation);
1995 /* We size-allocate the columns first because the width of the
1996 * tree view (used in updating the adjustments below) might change.
1998 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
2000 tree_view->priv->hadjustment->page_size = allocation->width;
2001 tree_view->priv->hadjustment->page_increment = allocation->width * 0.9;
2002 tree_view->priv->hadjustment->step_increment = allocation->width * 0.1;
2003 tree_view->priv->hadjustment->lower = 0;
2004 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->page_size, tree_view->priv->width);
2006 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
2008 if (allocation->width < tree_view->priv->width)
2010 if (tree_view->priv->init_hadjust_value)
2012 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
2013 tree_view->priv->init_hadjust_value = FALSE;
2015 else if (allocation->width != old_width)
2017 tree_view->priv->hadjustment->value = CLAMP (tree_view->priv->hadjustment->value - allocation->width + old_width, 0, tree_view->priv->width - allocation->width);
2020 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);
2024 tree_view->priv->hadjustment->value = 0;
2025 tree_view->priv->init_hadjust_value = TRUE;
2029 if (tree_view->priv->hadjustment->value + allocation->width > tree_view->priv->width)
2030 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
2032 gtk_adjustment_changed (tree_view->priv->hadjustment);
2034 tree_view->priv->vadjustment->page_size = allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view);
2035 tree_view->priv->vadjustment->step_increment = tree_view->priv->vadjustment->page_size * 0.1;
2036 tree_view->priv->vadjustment->page_increment = tree_view->priv->vadjustment->page_size * 0.9;
2037 tree_view->priv->vadjustment->lower = 0;
2038 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->page_size, tree_view->priv->height);
2040 gtk_adjustment_changed (tree_view->priv->vadjustment);
2042 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
2043 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
2044 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
2045 else if (tree_view->priv->vadjustment->value + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
2046 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
2047 tree_view->priv->height - tree_view->priv->vadjustment->page_size);
2048 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
2049 pspp_sheet_view_top_row_to_dy (tree_view);
2051 pspp_sheet_view_dy_to_top_row (tree_view);
2053 if (gtk_widget_get_realized (widget))
2055 gdk_window_move_resize (widget->window,
2056 allocation->x, allocation->y,
2057 allocation->width, allocation->height);
2058 gdk_window_move_resize (tree_view->priv->header_window,
2059 - (gint) tree_view->priv->hadjustment->value,
2061 MAX (tree_view->priv->width, allocation->width),
2062 tree_view->priv->header_height);
2063 gdk_window_move_resize (tree_view->priv->bin_window,
2064 - (gint) tree_view->priv->hadjustment->value,
2065 TREE_VIEW_HEADER_HEIGHT (tree_view),
2066 MAX (tree_view->priv->width, allocation->width),
2067 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2070 if (tree_view->priv->row_count == 0)
2071 invalidate_empty_focus (tree_view);
2073 if (gtk_widget_get_realized (widget))
2075 gboolean has_expand_column = FALSE;
2076 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2078 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2080 has_expand_column = TRUE;
2085 /* This little hack only works if we have an LTR locale, and no column has the */
2088 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2089 ! has_expand_column)
2090 invalidate_last_column (tree_view);
2092 gtk_widget_queue_draw (widget);
2097 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2099 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2101 GtkWidget *widget = GTK_WIDGET (tree_view);
2103 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2104 gtk_widget_grab_focus (widget);
2105 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2109 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2112 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2116 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2119 range_tower_set1 (tree_view->priv->selected, node, 1);
2123 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2126 range_tower_set0 (tree_view->priv->selected, node, 1);
2130 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2133 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2137 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2140 return node > 0 ? node - 1 : -1;
2144 all_columns_selected (PsppSheetView *tree_view)
2148 for (list = tree_view->priv->columns; list; list = list->next)
2150 PsppSheetViewColumn *column = list->data;
2151 if (column->selectable && !column->selected)
2159 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2161 PsppSheetViewColumn *column,
2162 GdkEventButton *event)
2164 PsppSheetSelection *selection;
2165 PsppSheetSelectionMode mode;
2167 gboolean update_anchor;
2171 g_return_val_if_fail (tree_view != NULL, FALSE);
2172 g_return_val_if_fail (column != NULL, FALSE);
2174 selection = tree_view->priv->selection;
2175 mode = pspp_sheet_selection_get_mode (selection);
2176 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2179 if (!column->row_head)
2184 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2185 if (event->type != GDK_BUTTON_PRESS
2186 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2192 path = gtk_tree_path_new_from_indices (node, -1);
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;
2201 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2203 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2204 || !all_columns_selected (tree_view))
2206 pspp_sheet_selection_unselect_all (selection);
2207 pspp_sheet_selection_select_path (selection, path);
2208 pspp_sheet_selection_select_all_columns (selection);
2209 update_anchor = TRUE;
2213 update_anchor = handled = FALSE;
2215 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2216 && modifiers == GDK_CONTROL_MASK)
2218 if (!all_columns_selected (tree_view))
2220 pspp_sheet_selection_unselect_all (selection);
2221 pspp_sheet_selection_select_all_columns (selection);
2224 if (pspp_sheet_selection_path_is_selected (selection, path))
2225 pspp_sheet_selection_unselect_path (selection, path);
2227 pspp_sheet_selection_select_path (selection, path);
2228 update_anchor = TRUE;
2231 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2232 && modifiers == GDK_SHIFT_MASK)
2234 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2235 GtkTreePath *anchor_path;
2237 if (all_columns_selected (tree_view)
2238 && gtk_tree_row_reference_valid (anchor))
2240 update_anchor = FALSE;
2241 anchor_path = gtk_tree_row_reference_get_path (anchor);
2245 update_anchor = TRUE;
2246 anchor_path = gtk_tree_path_copy (path);
2249 pspp_sheet_selection_unselect_all (selection);
2250 pspp_sheet_selection_select_range (selection, anchor_path, path);
2251 pspp_sheet_selection_select_all_columns (selection);
2253 gtk_tree_path_free (anchor_path);
2258 update_anchor = handled = FALSE;
2262 if (tree_view->priv->anchor)
2263 gtk_tree_row_reference_free (tree_view->priv->anchor);
2264 tree_view->priv->anchor =
2265 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2266 tree_view->priv->model,
2270 gtk_tree_path_free (path);
2275 find_click (PsppSheetView *tree_view,
2278 PsppSheetViewColumn **column,
2279 GdkRectangle *background_area,
2280 GdkRectangle *cell_area)
2287 /* find the node that was clicked */
2288 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2291 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2296 background_area->y = y_offset + y;
2297 background_area->height = ROW_HEIGHT (tree_view);
2298 background_area->x = 0;
2300 /* Let the column have a chance at selecting it. */
2301 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2302 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2303 list; list = (rtl ? list->prev : list->next))
2305 PsppSheetViewColumn *candidate = list->data;
2307 if (!candidate->visible)
2310 background_area->width = candidate->width;
2311 if ((background_area->x > x) ||
2312 (background_area->x + background_area->width <= x))
2314 background_area->x += background_area->width;
2318 /* we found the focus column */
2320 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2322 *column = candidate;
2330 pspp_sheet_view_button_press (GtkWidget *widget,
2331 GdkEventButton *event)
2333 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2335 PsppSheetViewColumn *column = NULL;
2337 GdkRectangle background_area;
2338 GdkRectangle cell_area;
2341 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2342 pspp_sheet_view_stop_editing (tree_view, FALSE);
2345 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2346 * we're done handling the button press.
2349 if (event->window == tree_view->priv->bin_window)
2354 gint pre_val, aft_val;
2355 PsppSheetViewColumn *column = NULL;
2356 GtkCellRenderer *focus_cell = NULL;
2357 gboolean row_double_click = FALSE;
2360 if (tree_view->priv->row_count == 0)
2362 grab_focus_and_unset_draw_keyfocus (tree_view);
2366 if (!find_click (tree_view, event->x, event->y, &node, &column,
2367 &background_area, &cell_area))
2369 grab_focus_and_unset_draw_keyfocus (tree_view);
2373 tree_view->priv->focus_column = column;
2375 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2379 pre_val = tree_view->priv->vadjustment->value;
2381 path = _pspp_sheet_view_find_path (tree_view, node);
2383 /* we only handle selection modifications on the first button press
2385 if (event->type == GDK_BUTTON_PRESS)
2387 PsppSheetSelectionMode mode = 0;
2389 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2390 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
2391 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2392 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
2394 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2396 pspp_sheet_view_column_focus_cell (column, focus_cell);
2398 if (event->state & GDK_CONTROL_MASK)
2400 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, mode);
2401 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2403 else if (event->state & GDK_SHIFT_MASK)
2405 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
2406 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE, mode);
2410 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
2413 if (tree_view->priv->anchor_column == NULL ||
2414 !(event->state & GDK_SHIFT_MASK))
2415 tree_view->priv->anchor_column = column;
2416 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2417 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2418 tree_view->priv->anchor_column,
2422 /* the treeview may have been scrolled because of _set_cursor,
2426 aft_val = tree_view->priv->vadjustment->value;
2427 dval = pre_val - aft_val;
2429 cell_area.y += dval;
2430 background_area.y += dval;
2432 /* Save press to possibly begin a drag
2434 if (!tree_view->priv->in_grab &&
2435 tree_view->priv->pressed_button < 0)
2437 tree_view->priv->pressed_button = event->button;
2438 tree_view->priv->press_start_x = event->x;
2439 tree_view->priv->press_start_y = event->y;
2440 tree_view->priv->press_start_node = node;
2442 if (tree_view->priv->rubber_banding_enable
2443 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2444 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2446 tree_view->priv->press_start_y += tree_view->priv->dy;
2447 tree_view->priv->rubber_band_x = event->x;
2448 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2449 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2451 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2452 tree_view->priv->rubber_band_ctrl = TRUE;
2453 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2454 tree_view->priv->rubber_band_shift = TRUE;
2459 /* Test if a double click happened on the same row. */
2460 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2462 int double_click_time, double_click_distance;
2464 g_object_get (gtk_settings_get_for_screen (
2465 gtk_widget_get_screen (widget)),
2466 "gtk-double-click-time", &double_click_time,
2467 "gtk-double-click-distance", &double_click_distance,
2470 /* Same conditions as _gdk_event_button_generate */
2471 if (tree_view->priv->last_button_x != -1 &&
2472 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2473 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2474 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2476 /* We do no longer compare paths of this row and the
2477 * row clicked previously. We use the double click
2478 * distance to decide whether this is a valid click,
2479 * allowing the mouse to slightly move over another row.
2481 row_double_click = TRUE;
2483 tree_view->priv->last_button_time = 0;
2484 tree_view->priv->last_button_x = -1;
2485 tree_view->priv->last_button_y = -1;
2489 tree_view->priv->last_button_time = event->time;
2490 tree_view->priv->last_button_x = event->x;
2491 tree_view->priv->last_button_y = event->y;
2495 if (row_double_click)
2497 gtk_grab_remove (widget);
2498 pspp_sheet_view_row_activated (tree_view, path, column);
2500 if (tree_view->priv->pressed_button == event->button)
2501 tree_view->priv->pressed_button = -1;
2504 gtk_tree_path_free (path);
2506 /* If we activated the row through a double click we don't want to grab
2507 * focus back, as moving focus to another widget is pretty common.
2509 if (!row_double_click)
2510 grab_focus_and_unset_draw_keyfocus (tree_view);
2515 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2517 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2519 column = list->data;
2520 if (event->window == column->window &&
2521 column->resizable &&
2526 if (gdk_pointer_grab (column->window, FALSE,
2527 GDK_POINTER_MOTION_HINT_MASK |
2528 GDK_BUTTON1_MOTION_MASK |
2529 GDK_BUTTON_RELEASE_MASK,
2530 NULL, NULL, event->time))
2533 gtk_grab_add (widget);
2534 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2535 column->resized_width = column->width;
2537 /* block attached dnd signal handler */
2538 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2540 g_signal_handlers_block_matched (widget,
2541 G_SIGNAL_MATCH_DATA,
2545 tree_view->priv->drag_pos = i;
2546 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2548 if (!gtk_widget_has_focus (widget))
2549 gtk_widget_grab_focus (widget);
2557 /* GtkWidget::button_release_event helper */
2559 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2560 GdkEventButton *event)
2562 PsppSheetView *tree_view;
2566 tree_view = PSPP_SHEET_VIEW (widget);
2568 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2569 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2570 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2572 /* Move the button back */
2573 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2575 g_object_ref (tree_view->priv->drag_column->button);
2576 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2577 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2578 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2579 g_object_unref (tree_view->priv->drag_column->button);
2580 gtk_widget_queue_resize (widget);
2581 if (tree_view->priv->drag_column->resizable)
2583 gdk_window_raise (tree_view->priv->drag_column->window);
2584 gdk_window_show (tree_view->priv->drag_column->window);
2587 gdk_window_hide (tree_view->priv->drag_column->window);
2589 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2593 if (tree_view->priv->cur_reorder &&
2594 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2595 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2596 tree_view->priv->cur_reorder->right_column);
2600 if (tree_view->priv->cur_reorder &&
2601 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2602 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2603 tree_view->priv->cur_reorder->left_column);
2605 tree_view->priv->drag_column = NULL;
2606 gdk_window_hide (tree_view->priv->drag_window);
2608 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2609 g_slice_free (PsppSheetViewColumnReorder, l->data);
2610 g_list_free (tree_view->priv->column_drag_info);
2611 tree_view->priv->column_drag_info = NULL;
2612 tree_view->priv->cur_reorder = NULL;
2614 if (tree_view->priv->drag_highlight_window)
2615 gdk_window_hide (tree_view->priv->drag_highlight_window);
2617 /* Reset our flags */
2618 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2619 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2624 /* GtkWidget::button_release_event helper */
2626 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2627 GdkEventButton *event)
2629 PsppSheetView *tree_view;
2632 tree_view = PSPP_SHEET_VIEW (widget);
2634 tree_view->priv->drag_pos = -1;
2636 /* unblock attached dnd signal handler */
2637 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2639 g_signal_handlers_unblock_matched (widget,
2640 G_SIGNAL_MATCH_DATA,
2644 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2645 gtk_grab_remove (widget);
2646 gdk_display_pointer_ungrab (gdk_window_get_display (event->window),
2652 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2653 GdkEventButton *event)
2655 GtkCellEditable *cell_editable;
2660 PsppSheetViewColumn *column;
2661 GdkRectangle background_area;
2662 GdkRectangle cell_area;
2668 if (event->window != tree_view->priv->bin_window)
2671 /* Ignore a released button, if that button wasn't depressed */
2672 if (tree_view->priv->pressed_button != event->button)
2675 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2679 /* decide if we edit */
2680 path = _pspp_sheet_view_find_path (tree_view, node);
2681 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2682 if (event->button != 1 || modifiers)
2685 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2686 pspp_sheet_view_column_cell_set_cell_data (column,
2687 tree_view->priv->model,
2690 if (!pspp_sheet_view_column_get_quick_edit (column)
2691 && _pspp_sheet_view_column_has_editable_cell (column))
2694 flags = 0; /* FIXME: get the right flags */
2695 path_string = gtk_tree_path_to_string (path);
2697 if (!_pspp_sheet_view_column_cell_event (column,
2705 if (cell_editable == NULL)
2708 pspp_sheet_view_real_set_cursor (tree_view, path,
2709 TRUE, TRUE, 0); /* XXX mode? */
2710 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2713 _pspp_sheet_view_column_get_neighbor_sizes (
2714 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2717 area.width -= right + left;
2719 pspp_sheet_view_real_start_editing (tree_view,
2726 g_free (path_string);
2727 gtk_tree_path_free (path);
2732 pspp_sheet_view_button_release (GtkWidget *widget,
2733 GdkEventButton *event)
2735 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2737 pspp_sheet_view_stop_editing (tree_view, FALSE);
2738 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2739 && pspp_sheet_view_button_release_edit (tree_view, event))
2741 if (tree_view->priv->pressed_button == event->button)
2742 tree_view->priv->pressed_button = -1;
2744 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2748 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2749 return pspp_sheet_view_button_release_drag_column (widget, event);
2751 if (tree_view->priv->rubber_band_status)
2752 pspp_sheet_view_stop_rubber_band (tree_view);
2754 if (tree_view->priv->pressed_button == event->button)
2755 tree_view->priv->pressed_button = -1;
2757 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2758 return pspp_sheet_view_button_release_column_resize (widget, event);
2764 pspp_sheet_view_grab_broken (GtkWidget *widget,
2765 GdkEventGrabBroken *event)
2767 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2769 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2770 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2772 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2773 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2778 /* GtkWidget::motion_event function set.
2782 do_prelight (PsppSheetView *tree_view,
2784 /* these are in bin_window coords */
2788 int prev_node = tree_view->priv->prelight_node;
2790 if (prev_node != node)
2792 tree_view->priv->prelight_node = node;
2795 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2798 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2803 prelight_or_select (PsppSheetView *tree_view,
2805 /* these are in bin_window coords */
2809 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2811 if (tree_view->priv->hover_selection &&
2812 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2813 !(tree_view->priv->edited_column &&
2814 tree_view->priv->edited_column->editable_widget))
2818 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2822 path = _pspp_sheet_view_find_path (tree_view, node);
2823 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2824 if (pspp_sheet_view_node_is_selected (tree_view, node))
2826 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2827 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE, 0); /* XXX mode? */
2829 gtk_tree_path_free (path);
2833 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2834 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2837 do_prelight (tree_view, node, x, y);
2841 ensure_unprelighted (PsppSheetView *tree_view)
2843 do_prelight (tree_view,
2845 -1000, -1000); /* coords not possibly over an arrow */
2847 g_assert (tree_view->priv->prelight_node < 0);
2851 update_prelight (PsppSheetView *tree_view,
2858 if (tree_view->priv->row_count == 0)
2863 ensure_unprelighted (tree_view);
2867 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2871 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2874 prelight_or_select (tree_view, node, x, y);
2880 /* Our motion arrow is either a box (in the case of the original spot)
2881 * or an arrow. It is expander_size wide.
2904 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2906 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2907 GtkWidget *widget = GTK_WIDGET (tree_view);
2908 GdkBitmap *mask = NULL;
2913 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2914 GdkWindowAttr attributes;
2915 guint attributes_mask;
2918 reorder->left_column == tree_view->priv->drag_column ||
2919 reorder->right_column == tree_view->priv->drag_column)
2920 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2921 else if (reorder->left_column || reorder->right_column)
2923 GdkRectangle visible_rect;
2924 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2925 if (reorder->left_column)
2926 x = reorder->left_column->allocation.x + reorder->left_column->allocation.width;
2928 x = reorder->right_column->allocation.x;
2930 if (x < visible_rect.x)
2931 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2932 else if (x > visible_rect.x + visible_rect.width)
2933 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2935 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2938 /* We want to draw the rectangle over the initial location. */
2939 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2944 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2946 if (tree_view->priv->drag_highlight_window)
2948 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2950 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2953 attributes.window_type = GDK_WINDOW_CHILD;
2954 attributes.wclass = GDK_INPUT_OUTPUT;
2955 attributes.x = tree_view->priv->drag_column_x;
2957 width = attributes.width = tree_view->priv->drag_column->allocation.width;
2958 height = attributes.height = tree_view->priv->drag_column->allocation.height;
2959 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2960 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2961 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2962 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2963 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
2964 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2966 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2967 gc = gdk_gc_new (mask);
2969 gdk_gc_set_foreground (gc, &col);
2970 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2972 gdk_gc_set_foreground(gc, &col);
2973 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
2974 g_object_unref (gc);
2976 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
2978 if (mask) g_object_unref (mask);
2979 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2982 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
2988 width = tree_view->priv->expander_size;
2990 /* Get x, y, width, height of arrow */
2991 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
2992 if (reorder->left_column)
2994 x += reorder->left_column->allocation.x + reorder->left_column->allocation.width - width/2;
2995 height = reorder->left_column->allocation.height;
2999 x += reorder->right_column->allocation.x - width/2;
3000 height = reorder->right_column->allocation.height;
3002 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
3003 height += tree_view->priv->expander_size;
3005 /* Create the new window */
3006 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
3008 if (tree_view->priv->drag_highlight_window)
3010 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3012 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3015 attributes.window_type = GDK_WINDOW_TEMP;
3016 attributes.wclass = GDK_INPUT_OUTPUT;
3017 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3018 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3019 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3020 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3023 attributes.width = width;
3024 attributes.height = height;
3025 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
3026 &attributes, attributes_mask);
3027 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3029 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3030 gc = gdk_gc_new (mask);
3032 gdk_gc_set_foreground (gc, &col);
3033 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3035 /* Draw the 2 arrows as per above */
3037 gdk_gc_set_foreground (gc, &col);
3038 for (i = 0; i < width; i ++)
3040 if (i == (width/2 - 1))
3042 gdk_draw_line (mask, gc, i, j, i, height - j);
3043 if (i < (width/2 - 1))
3048 g_object_unref (gc);
3049 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3051 if (mask) g_object_unref (mask);
3054 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
3055 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3057 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
3058 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3064 width = tree_view->priv->expander_size;
3066 /* Get x, y, width, height of arrow */
3067 width = width/2; /* remember, the arrow only takes half the available width */
3068 gdk_window_get_origin (widget->window, &x, &y);
3069 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3070 x += widget->allocation.width - width;
3072 if (reorder->left_column)
3073 height = reorder->left_column->allocation.height;
3075 height = reorder->right_column->allocation.height;
3077 y -= tree_view->priv->expander_size;
3078 height += 2*tree_view->priv->expander_size;
3080 /* Create the new window */
3081 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
3082 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3084 if (tree_view->priv->drag_highlight_window)
3086 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3088 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3091 attributes.window_type = GDK_WINDOW_TEMP;
3092 attributes.wclass = GDK_INPUT_OUTPUT;
3093 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3094 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3095 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3096 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3099 attributes.width = width;
3100 attributes.height = height;
3101 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3102 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3104 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3105 gc = gdk_gc_new (mask);
3107 gdk_gc_set_foreground (gc, &col);
3108 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3110 /* Draw the 2 arrows as per above */
3112 gdk_gc_set_foreground (gc, &col);
3113 j = tree_view->priv->expander_size;
3114 for (i = 0; i < width; i ++)
3117 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3121 gdk_draw_line (mask, gc, k, j, k, height - j);
3122 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3123 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3126 g_object_unref (gc);
3127 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3129 if (mask) g_object_unref (mask);
3132 tree_view->priv->drag_column_window_state = arrow_type;
3133 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3137 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3138 gdk_window_hide (tree_view->priv->drag_highlight_window);
3142 gdk_window_show (tree_view->priv->drag_highlight_window);
3143 gdk_window_raise (tree_view->priv->drag_highlight_window);
3147 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3148 GdkEventMotion *event)
3152 PsppSheetViewColumn *column;
3153 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3155 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3157 if (event->is_hint || event->window != widget->window)
3158 gtk_widget_get_pointer (widget, &x, NULL);
3162 if (tree_view->priv->hadjustment)
3163 x += tree_view->priv->hadjustment->value;
3165 new_width = pspp_sheet_view_new_column_width (tree_view,
3166 tree_view->priv->drag_pos, &x);
3167 if (x != tree_view->priv->x_drag &&
3168 (new_width != column->fixed_width))
3170 column->use_resized_width = TRUE;
3171 column->resized_width = new_width;
3174 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3176 gtk_widget_queue_resize (widget);
3184 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3186 PsppSheetViewColumnReorder *reorder = NULL;
3190 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3191 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3193 reorder = (PsppSheetViewColumnReorder *) list->data;
3194 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3199 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3202 tree_view->priv->cur_reorder = reorder;
3203 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3207 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3209 GdkRectangle visible_rect;
3214 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3215 y += tree_view->priv->dy;
3217 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3219 /* see if we are near the edge. */
3220 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3223 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3228 value = CLAMP (tree_view->priv->vadjustment->value + offset, 0.0,
3229 tree_view->priv->vadjustment->upper - tree_view->priv->vadjustment->page_size);
3230 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3234 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3236 GdkRectangle visible_rect;
3241 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3243 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3245 /* See if we are near the edge. */
3246 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3249 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3255 value = CLAMP (tree_view->priv->hadjustment->value + offset,
3256 0.0, tree_view->priv->hadjustment->upper - tree_view->priv->hadjustment->page_size);
3257 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3264 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3265 GdkEventMotion *event)
3267 PsppSheetView *tree_view = (PsppSheetView *) widget;
3268 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3272 if ((column == NULL) ||
3273 (event->window != tree_view->priv->drag_window))
3276 /* Handle moving the header */
3277 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3278 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3279 MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width) - column->allocation.width);
3280 gdk_window_move (tree_view->priv->drag_window, x, y);
3282 /* autoscroll, if needed */
3283 pspp_sheet_view_horizontal_autoscroll (tree_view);
3284 /* Update the current reorder position and arrow; */
3285 pspp_sheet_view_update_current_reorder (tree_view);
3291 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3293 remove_scroll_timeout (tree_view);
3294 gtk_grab_remove (GTK_WIDGET (tree_view));
3296 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3298 GtkTreePath *tmp_path;
3300 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3302 /* The anchor path should be set to the start path */
3303 tmp_path = _pspp_sheet_view_find_path (tree_view,
3304 tree_view->priv->rubber_band_start_node);
3306 if (tree_view->priv->anchor)
3307 gtk_tree_row_reference_free (tree_view->priv->anchor);
3309 tree_view->priv->anchor =
3310 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3311 tree_view->priv->model,
3314 gtk_tree_path_free (tmp_path);
3316 /* ... and the cursor to the end path */
3317 tmp_path = _pspp_sheet_view_find_path (tree_view,
3318 tree_view->priv->rubber_band_end_node);
3319 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE, 0); /* XXX mode? */
3320 gtk_tree_path_free (tmp_path);
3322 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3325 /* Clear status variables */
3326 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3327 tree_view->priv->rubber_band_shift = 0;
3328 tree_view->priv->rubber_band_ctrl = 0;
3330 tree_view->priv->rubber_band_start_node = -1;
3331 tree_view->priv->rubber_band_end_node = -1;
3335 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3339 gboolean skip_start,
3342 if (start_node == end_node)
3345 /* We skip the first node and jump inside the loop */
3351 /* Small optimization by assuming insensitive nodes are never
3356 if (tree_view->priv->rubber_band_shift)
3357 pspp_sheet_view_node_select (tree_view, start_node);
3358 else if (tree_view->priv->rubber_band_ctrl)
3360 /* Toggle the selection state */
3361 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3362 pspp_sheet_view_node_unselect (tree_view, start_node);
3364 pspp_sheet_view_node_select (tree_view, start_node);
3367 pspp_sheet_view_node_select (tree_view, start_node);
3371 /* Mirror the above */
3372 if (tree_view->priv->rubber_band_shift)
3373 pspp_sheet_view_node_unselect (tree_view, start_node);
3374 else if (tree_view->priv->rubber_band_ctrl)
3376 /* Toggle the selection state */
3377 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3378 pspp_sheet_view_node_unselect (tree_view, start_node);
3380 pspp_sheet_view_node_select (tree_view, start_node);
3383 pspp_sheet_view_node_unselect (tree_view, start_node);
3386 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3388 if (start_node == end_node)
3393 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3396 /* Ran out of tree */
3399 if (skip_end && start_node == end_node)
3406 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3409 return node * tree_view->priv->fixed_height;
3413 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3417 int fixed_height = tree_view->priv->fixed_height;
3418 if (fixed_height <= 0
3420 || height >= tree_view->priv->row_count * fixed_height)
3427 *new_node = height / fixed_height;
3428 return height % fixed_height;
3433 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3438 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3439 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3441 /* Handle the start area first */
3442 if (tree_view->priv->rubber_band_start_node < 0)
3444 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3451 else if (start_node < tree_view->priv->rubber_band_start_node)
3453 /* New node is above the old one; selection became bigger */
3454 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3456 tree_view->priv->rubber_band_start_node,
3461 else if (start_node > tree_view->priv->rubber_band_start_node)
3463 /* New node is below the old one; selection became smaller */
3464 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3465 tree_view->priv->rubber_band_start_node,
3472 tree_view->priv->rubber_band_start_node = start_node;
3474 /* Next, handle the end area */
3475 if (tree_view->priv->rubber_band_end_node < 0)
3477 /* In the event this happens, start_node was also -1; this case is
3481 else if (end_node < 0)
3483 /* Find the last node in the tree */
3484 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3487 /* Selection reached end of the tree */
3488 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3489 tree_view->priv->rubber_band_end_node,
3495 else if (end_node > tree_view->priv->rubber_band_end_node)
3497 /* New node is below the old one; selection became bigger */
3498 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3499 tree_view->priv->rubber_band_end_node,
3505 else if (end_node < tree_view->priv->rubber_band_end_node)
3507 /* New node is above the old one; selection became smaller */
3508 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3510 tree_view->priv->rubber_band_end_node,
3516 tree_view->priv->rubber_band_end_node = end_node;
3520 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3523 GdkRectangle old_area;
3524 GdkRectangle new_area;
3525 GdkRectangle common;
3526 GdkRegion *invalid_region;
3527 PsppSheetViewColumn *column;
3529 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3530 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3531 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3532 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3534 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3537 y = MAX (y, 0) + tree_view->priv->dy;
3539 new_area.x = MIN (tree_view->priv->press_start_x, x);
3540 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3541 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3542 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3544 invalid_region = gdk_region_rectangle (&old_area);
3545 gdk_region_union_with_rect (invalid_region, &new_area);
3547 gdk_rectangle_intersect (&old_area, &new_area, &common);
3548 if (common.width > 2 && common.height > 2)
3550 GdkRegion *common_region;
3552 /* make sure the border is invalidated */
3558 common_region = gdk_region_rectangle (&common);
3560 gdk_region_subtract (invalid_region, common_region);
3561 gdk_region_destroy (common_region);
3564 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3566 gdk_region_destroy (invalid_region);
3568 tree_view->priv->rubber_band_x = x;
3569 tree_view->priv->rubber_band_y = y;
3570 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3572 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3573 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3574 tree_view->priv->anchor_column,
3577 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3579 pspp_sheet_view_update_rubber_band_selection (tree_view);
3583 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3588 GdkRectangle rubber_rect;
3591 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3592 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3593 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3594 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3596 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3599 cr = gdk_cairo_create (tree_view->priv->bin_window);
3600 cairo_set_line_width (cr, 1.0);
3602 cairo_set_source_rgba (cr,
3603 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3604 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3605 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.,
3608 gdk_cairo_rectangle (cr, &rect);
3612 cairo_set_source_rgb (cr,
3613 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3614 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3615 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.);
3617 cairo_rectangle (cr,
3618 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3619 rubber_rect.width - 1, rubber_rect.height - 1);
3626 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3627 GdkEventMotion *event)
3629 PsppSheetView *tree_view;
3633 tree_view = (PsppSheetView *) widget;
3635 if (tree_view->priv->row_count == 0)
3638 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3640 GdkRectangle background_area, cell_area;
3641 PsppSheetViewColumn *column;
3643 if (find_click (tree_view, event->x, event->y, &node, &column,
3644 &background_area, &cell_area)
3645 && tree_view->priv->focus_column == column
3646 && tree_view->priv->press_start_node == node)
3649 gtk_grab_add (GTK_WIDGET (tree_view));
3650 pspp_sheet_view_update_rubber_band (tree_view);
3652 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3654 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3656 pspp_sheet_view_update_rubber_band (tree_view);
3658 add_scroll_timeout (tree_view);
3661 /* only check for an initiated drag when a button is pressed */
3662 if (tree_view->priv->pressed_button >= 0
3663 && !tree_view->priv->rubber_band_status)
3664 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3666 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3670 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3672 tree_view->priv->event_last_x = event->x;
3673 tree_view->priv->event_last_y = event->y;
3675 prelight_or_select (tree_view, node, event->x, event->y);
3681 pspp_sheet_view_motion (GtkWidget *widget,
3682 GdkEventMotion *event)
3684 PsppSheetView *tree_view;
3686 tree_view = (PsppSheetView *) widget;
3688 /* Resizing a column */
3689 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3690 return pspp_sheet_view_motion_resize_column (widget, event);
3693 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3694 return pspp_sheet_view_motion_drag_column (widget, event);
3696 /* Sanity check it */
3697 if (event->window == tree_view->priv->bin_window)
3698 return pspp_sheet_view_motion_bin_window (widget, event);
3703 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3704 * the tree is empty.
3707 invalidate_empty_focus (PsppSheetView *tree_view)
3711 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3716 gdk_drawable_get_size (tree_view->priv->bin_window, &area.width, &area.height);
3717 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3720 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3724 draw_empty_focus (PsppSheetView *tree_view, GdkRectangle *clip_area)
3726 GtkWidget *widget = GTK_WIDGET (tree_view);
3729 if (!gtk_widget_has_focus (widget))
3732 gdk_drawable_get_size (tree_view->priv->bin_window, &w, &h);
3738 gtk_paint_focus (gtk_widget_get_style (widget),
3739 tree_view->priv->bin_window,
3740 gtk_widget_get_state (widget),
3748 pspp_sheet_view_draw_grid_lines (PsppSheetView *tree_view,
3749 GdkEventExpose *event,
3750 gint n_visible_columns,
3754 GList *list = tree_view->priv->columns;
3759 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3760 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3763 gdk_drawable_get_size (event->window, NULL, &height);
3765 /* Only draw the lines for visible rows and columns */
3766 for (list = tree_view->priv->columns; list; list = list->next, i++)
3768 PsppSheetViewColumn *column = list->data;
3770 /* We don't want a line for the last column */
3771 if (i == n_visible_columns - 1)
3774 if (! column->visible)
3777 current_x += column->width;
3779 if (current_x - 1 >= event->area.x
3780 && current_x - 1 < event->area.x + event->area.width)
3781 gdk_draw_line (event->window,
3782 tree_view->priv->grid_line_gc[GTK_WIDGET(tree_view)->state],
3783 current_x - 1, min_y,
3784 current_x - 1, max_y - min_y);
3788 /* Warning: Very scary function.
3789 * Modify at your own risk
3791 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3792 * FIXME: It's not...
3795 pspp_sheet_view_bin_expose (GtkWidget *widget,
3796 GdkEventExpose *event)
3798 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3803 int drag_highlight = -1;
3806 gint y_offset, cell_offset;
3808 GdkRectangle background_area;
3809 GdkRectangle cell_area;
3811 gint bin_window_width;
3812 gint bin_window_height;
3813 GtkTreePath *cursor_path;
3814 GtkTreePath *drag_dest_path;
3815 GList *first_column, *last_column;
3816 gint vertical_separator;
3817 gint horizontal_separator;
3818 gint focus_line_width;
3819 gboolean allow_rules;
3820 gboolean has_special_cell;
3822 gint n_visible_columns;
3823 gint grid_line_width;
3824 gboolean row_ending_details;
3825 gboolean draw_vgrid_lines, draw_hgrid_lines;
3828 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3830 gtk_widget_style_get (widget,
3831 "horizontal-separator", &horizontal_separator,
3832 "vertical-separator", &vertical_separator,
3833 "allow-rules", &allow_rules,
3834 "focus-line-width", &focus_line_width,
3835 "row-ending-details", &row_ending_details,
3838 if (tree_view->priv->row_count == 0)
3840 draw_empty_focus (tree_view, &event->area);
3844 /* clip event->area to the visible area */
3845 if (event->area.height < 0)
3848 validate_visible_area (tree_view);
3850 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, event->area.y);
3854 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3855 gdk_drawable_get_size (tree_view->priv->bin_window,
3856 &bin_window_width, &bin_window_height);
3858 if (tree_view->priv->height < bin_window_height)
3860 gtk_paint_flat_box (widget->style,
3867 0, tree_view->priv->height,
3869 bin_window_height - tree_view->priv->height);
3875 /* find the path for the node */
3876 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3877 gtk_tree_model_get_iter (tree_view->priv->model,
3880 gtk_tree_path_free (path);
3883 drag_dest_path = NULL;
3885 if (tree_view->priv->cursor)
3886 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3889 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3891 if (tree_view->priv->drag_dest_row)
3892 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3895 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3899 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3900 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3902 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3903 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3905 if (draw_vgrid_lines || draw_hgrid_lines)
3906 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3908 n_visible_columns = 0;
3909 for (list = tree_view->priv->columns; list; list = list->next)
3911 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3913 n_visible_columns ++;
3916 /* Find the last column */
3917 for (last_column = g_list_last (tree_view->priv->columns);
3918 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
3919 last_column = last_column->prev)
3923 for (first_column = g_list_first (tree_view->priv->columns);
3924 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
3925 first_column = first_column->next)
3928 /* Actually process the expose event. To do this, we want to
3929 * start at the first node of the event, and walk the tree in
3930 * order, drawing each successive node.
3937 gboolean is_first = FALSE;
3938 gboolean is_last = FALSE;
3939 gboolean done = FALSE;
3942 max_height = ROW_HEIGHT (tree_view);
3946 background_area.y = y_offset + event->area.y;
3947 background_area.height = max_height;
3948 max_y = background_area.y + max_height;
3952 if (node == tree_view->priv->prelight_node)
3953 flags |= GTK_CELL_RENDERER_PRELIT;
3955 selected = pspp_sheet_view_node_is_selected (tree_view, node);
3959 if (tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
3961 /* we *need* to set cell data on all cells before the call
3962 * to _has_special_cell, else _has_special_cell() does not
3963 * return a correct value.
3965 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3967 list = (rtl ? list->prev : list->next))
3969 PsppSheetViewColumn *column = list->data;
3970 pspp_sheet_view_column_cell_set_cell_data (column,
3971 tree_view->priv->model,
3975 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
3978 has_special_cell = tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
3980 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3982 list = (rtl ? list->prev : list->next))
3984 PsppSheetViewColumn *column = list->data;
3985 const gchar *detail = NULL;
3986 gboolean selected_column;
3989 if (!column->visible)
3992 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
3993 selected_column = column->selected && column->selectable;
3995 selected_column = TRUE;
3997 if (cell_offset > event->area.x + event->area.width ||
3998 cell_offset + column->width < event->area.x)
4000 cell_offset += column->width;
4004 if (selected && selected_column)
4005 flags |= GTK_CELL_RENDERER_SELECTED;
4007 flags &= ~GTK_CELL_RENDERER_SELECTED;
4009 if (column->show_sort_indicator)
4010 flags |= GTK_CELL_RENDERER_SORTED;
4012 flags &= ~GTK_CELL_RENDERER_SORTED;
4015 flags |= GTK_CELL_RENDERER_FOCUSED;
4017 flags &= ~GTK_CELL_RENDERER_FOCUSED;
4019 background_area.x = cell_offset;
4020 background_area.width = column->width;
4022 cell_area = background_area;
4023 cell_area.y += vertical_separator / 2;
4024 cell_area.x += horizontal_separator / 2;
4025 cell_area.height -= vertical_separator;
4026 cell_area.width -= horizontal_separator;
4028 if (draw_vgrid_lines)
4030 if (list == first_column)
4032 cell_area.width -= grid_line_width / 2;
4034 else if (list == last_column)
4036 cell_area.x += grid_line_width / 2;
4037 cell_area.width -= grid_line_width / 2;
4041 cell_area.x += grid_line_width / 2;
4042 cell_area.width -= grid_line_width;
4046 if (draw_hgrid_lines)
4048 cell_area.y += grid_line_width / 2;
4049 cell_area.height -= grid_line_width;
4052 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
4054 cell_offset += column->width;
4058 pspp_sheet_view_column_cell_set_cell_data (column,
4059 tree_view->priv->model,
4062 /* Select the detail for drawing the cell. relevant
4063 * factors are parity, sortedness, and whether to
4066 if (allow_rules && tree_view->priv->has_rules)
4068 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4069 n_visible_columns >= 3)
4072 detail = "cell_odd_ruled_sorted";
4074 detail = "cell_even_ruled_sorted";
4079 detail = "cell_odd_ruled";
4081 detail = "cell_even_ruled";
4086 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4087 n_visible_columns >= 3)
4090 detail = "cell_odd_sorted";
4092 detail = "cell_even_sorted";
4097 detail = "cell_odd";
4099 detail = "cell_even";
4105 if (widget->state == GTK_STATE_INSENSITIVE)
4106 state = GTK_STATE_INSENSITIVE;
4107 else if (flags & GTK_CELL_RENDERER_SELECTED)
4108 state = GTK_STATE_SELECTED;
4110 state = GTK_STATE_NORMAL;
4112 /* Draw background */
4113 if (row_ending_details)
4115 char new_detail[128];
4117 is_first = (rtl ? !list->next : !list->prev);
4118 is_last = (rtl ? !list->prev : !list->next);
4120 /* (I don't like the snprintfs either, but couldn't find a
4123 if (is_first && is_last)
4124 g_snprintf (new_detail, 127, "%s", detail);
4126 g_snprintf (new_detail, 127, "%s_start", detail);
4128 g_snprintf (new_detail, 127, "%s_end", detail);
4130 g_snprintf (new_detail, 128, "%s_middle", detail);
4132 gtk_paint_flat_box (widget->style,
4141 background_area.width,
4142 background_area.height);
4146 gtk_paint_flat_box (widget->style,
4155 background_area.width,
4156 background_area.height);
4159 if (draw_hgrid_lines)
4161 if (background_area.y > 0)
4162 gdk_draw_line (event->window,
4163 tree_view->priv->grid_line_gc[widget->state],
4164 background_area.x, background_area.y,
4165 background_area.x + background_area.width,
4168 if (y_offset + max_height >= event->area.height)
4169 gdk_draw_line (event->window,
4170 tree_view->priv->grid_line_gc[widget->state],
4171 background_area.x, background_area.y + max_height,
4172 background_area.x + background_area.width,
4173 background_area.y + max_height);
4176 _pspp_sheet_view_column_cell_render (column,
4183 if (node == cursor && has_special_cell &&
4184 ((column == tree_view->priv->focus_column &&
4185 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4186 gtk_widget_has_focus (widget)) ||
4187 (column == tree_view->priv->edited_column)))
4189 _pspp_sheet_view_column_cell_draw_focus (column,
4197 cell_offset += column->width;
4200 if (cell_offset < event->area.x)
4202 gtk_paint_flat_box (widget->style,
4211 event->area.x - cell_offset,
4212 background_area.height);
4215 if (node == drag_highlight)
4217 /* Draw indicator for the drop
4219 gint highlight_y = -1;
4223 switch (tree_view->priv->drag_dest_pos)
4225 case PSPP_SHEET_VIEW_DROP_BEFORE:
4226 highlight_y = background_area.y - 1;
4227 if (highlight_y < 0)
4231 case PSPP_SHEET_VIEW_DROP_AFTER:
4232 highlight_y = background_area.y + background_area.height - 1;
4235 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4236 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4237 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4241 gdk_drawable_get_size (tree_view->priv->bin_window,
4244 if (row_ending_details)
4245 gtk_paint_focus (widget->style,
4246 tree_view->priv->bin_window,
4247 gtk_widget_get_state (widget),
4251 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4252 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4253 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4254 - focus_line_width / 2,
4255 width, ROW_HEIGHT (tree_view)
4256 - focus_line_width + 1);
4258 gtk_paint_focus (widget->style,
4259 tree_view->priv->bin_window,
4260 gtk_widget_get_state (widget),
4263 "treeview-drop-indicator",
4264 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4265 - focus_line_width / 2,
4266 width, ROW_HEIGHT (tree_view)
4267 - focus_line_width + 1);
4271 if (highlight_y >= 0)
4273 gdk_draw_line (event->window,
4274 widget->style->fg_gc[gtk_widget_get_state (widget)],
4277 rtl ? 0 : bin_window_width,
4282 /* draw the big row-spanning focus rectangle, if needed */
4283 if (!has_special_cell && node == cursor &&
4284 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4285 gtk_widget_has_focus (widget))
4287 gint tmp_y, tmp_height;
4289 GtkStateType focus_rect_state;
4292 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4293 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4294 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4297 gdk_drawable_get_size (tree_view->priv->bin_window,
4300 if (draw_hgrid_lines)
4302 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4303 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4307 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4308 tmp_height = ROW_HEIGHT (tree_view);
4311 if (row_ending_details)
4312 gtk_paint_focus (widget->style,
4313 tree_view->priv->bin_window,
4318 ? (is_last ? "treeview" : "treeview-left" )
4319 : (is_last ? "treeview-right" : "treeview-middle" )),
4323 gtk_paint_focus (widget->style,
4324 tree_view->priv->bin_window,
4333 y_offset += max_height;
4337 node = pspp_sheet_view_node_next (tree_view, node);
4340 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4344 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4351 while (y_offset < event->area.height);
4354 pspp_sheet_view_draw_grid_lines (tree_view, event, n_visible_columns,
4357 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4359 GdkRectangle *rectangles;
4362 gdk_region_get_rectangles (event->region,
4366 while (n_rectangles--)
4367 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4369 g_free (rectangles);
4373 gtk_tree_path_free (cursor_path);
4376 gtk_tree_path_free (drag_dest_path);
4382 pspp_sheet_view_expose (GtkWidget *widget,
4383 GdkEventExpose *event)
4385 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4387 if (event->window == tree_view->priv->bin_window)
4392 retval = pspp_sheet_view_bin_expose (widget, event);
4394 /* We can't just chain up to Container::expose as it will try to send the
4395 * event to the headers, so we handle propagating it to our children
4396 * (eg. widgets being edited) ourselves.
4398 tmp_list = tree_view->priv->children;
4401 PsppSheetViewChild *child = tmp_list->data;
4402 tmp_list = tmp_list->next;
4404 gtk_container_propagate_expose (GTK_CONTAINER (tree_view), child->widget, event);
4410 else if (event->window == tree_view->priv->header_window)
4412 gint n_visible_columns;
4415 gtk_paint_flat_box (widget->style,
4425 event->area.height);
4427 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4429 PsppSheetViewColumn *column = list->data;
4431 if (column == tree_view->priv->drag_column || !column->visible)
4434 if (span_intersects (column->allocation.x, column->allocation.width,
4435 event->area.x, event->area.width)
4436 && column->button != NULL)
4437 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4438 column->button, event);
4441 n_visible_columns = 0;
4442 for (list = tree_view->priv->columns; list; list = list->next)
4444 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4446 n_visible_columns ++;
4448 pspp_sheet_view_draw_grid_lines (tree_view,
4452 event->area.height);
4454 else if (event->window == tree_view->priv->drag_window)
4456 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4457 tree_view->priv->drag_column->button,
4471 /* returns 0x1 when no column has been found -- yes it's hackish */
4472 static PsppSheetViewColumn *
4473 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4474 PsppSheetViewColumn *column,
4477 PsppSheetViewColumn *left_column = NULL;
4478 PsppSheetViewColumn *cur_column = NULL;
4481 if (!column->reorderable)
4482 return (PsppSheetViewColumn *)0x1;
4484 switch (drop_position)
4487 /* find first column where we can drop */
4488 tmp_list = tree_view->priv->columns;
4489 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4490 return (PsppSheetViewColumn *)0x1;
4494 g_assert (tmp_list);
4496 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4497 tmp_list = tmp_list->next;
4499 if (left_column && left_column->visible == FALSE)
4502 if (!tree_view->priv->column_drop_func)
4505 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4507 left_column = cur_column;
4514 if (!tree_view->priv->column_drop_func)
4517 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4520 return (PsppSheetViewColumn *)0x1;
4524 /* find first column after column where we can drop */
4525 tmp_list = tree_view->priv->columns;
4527 for (; tmp_list; tmp_list = tmp_list->next)
4528 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4531 if (!tmp_list || !tmp_list->next)
4532 return (PsppSheetViewColumn *)0x1;
4534 tmp_list = tmp_list->next;
4535 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4536 tmp_list = tmp_list->next;
4540 g_assert (tmp_list);
4542 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4543 tmp_list = tmp_list->next;
4545 if (left_column && left_column->visible == FALSE)
4547 left_column = cur_column;
4549 tmp_list = tmp_list->next;
4553 if (!tree_view->priv->column_drop_func)
4556 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4558 left_column = cur_column;
4565 if (!tree_view->priv->column_drop_func)
4568 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4571 return (PsppSheetViewColumn *)0x1;
4575 /* find first column before column where we can drop */
4576 tmp_list = tree_view->priv->columns;
4578 for (; tmp_list; tmp_list = tmp_list->next)
4579 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4582 if (!tmp_list || !tmp_list->prev)
4583 return (PsppSheetViewColumn *)0x1;
4585 tmp_list = tmp_list->prev;
4586 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4587 tmp_list = tmp_list->prev;
4591 g_assert (tmp_list);
4593 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4595 if (left_column && !left_column->visible)
4597 /*if (!tmp_list->prev)
4598 return (PsppSheetViewColumn *)0x1;
4601 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4602 tmp_list = tmp_list->prev->prev;
4605 cur_column = left_column;
4607 tmp_list = tmp_list->prev;
4611 if (!tree_view->priv->column_drop_func)
4614 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4617 cur_column = left_column;
4618 tmp_list = tmp_list->prev;
4621 if (!tree_view->priv->column_drop_func)
4624 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4627 return (PsppSheetViewColumn *)0x1;
4631 /* same as DROP_HOME case, but doing it backwards */
4632 tmp_list = g_list_last (tree_view->priv->columns);
4635 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4636 return (PsppSheetViewColumn *)0x1;
4640 g_assert (tmp_list);
4642 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4644 if (left_column && !left_column->visible)
4646 cur_column = left_column;
4647 tmp_list = tmp_list->prev;
4650 if (!tree_view->priv->column_drop_func)
4653 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4656 cur_column = left_column;
4657 tmp_list = tmp_list->prev;
4660 if (!tree_view->priv->column_drop_func)
4663 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4666 return (PsppSheetViewColumn *)0x1;
4670 return (PsppSheetViewColumn *)0x1;
4674 pspp_sheet_view_key_press (GtkWidget *widget,
4677 PsppSheetView *tree_view = (PsppSheetView *) widget;
4679 if (tree_view->priv->rubber_band_status)
4681 if (event->keyval == GDK_Escape)
4682 pspp_sheet_view_stop_rubber_band (tree_view);
4687 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4689 if (event->keyval == GDK_Escape)
4691 tree_view->priv->cur_reorder = NULL;
4692 pspp_sheet_view_button_release_drag_column (widget, NULL);
4697 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4699 GList *focus_column;
4702 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4704 for (focus_column = tree_view->priv->columns;
4706 focus_column = focus_column->next)
4708 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4710 if (column->button && gtk_widget_has_focus (column->button))
4715 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4716 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4717 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4719 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4721 if (!column->resizable)
4723 gtk_widget_error_bell (widget);
4727 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4728 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4730 gint old_width = column->resized_width;
4732 column->resized_width = MAX (column->resized_width,
4734 column->resized_width -= 2;
4735 if (column->resized_width < 0)
4736 column->resized_width = 0;
4738 if (column->min_width == -1)
4739 column->resized_width = MAX (column->button_request,
4740 column->resized_width);
4742 column->resized_width = MAX (column->min_width,
4743 column->resized_width);
4745 if (column->max_width != -1)
4746 column->resized_width = MIN (column->resized_width,
4749 column->use_resized_width = TRUE;
4751 if (column->resized_width != old_width)
4752 gtk_widget_queue_resize (widget);
4754 gtk_widget_error_bell (widget);
4756 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4757 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4759 gint old_width = column->resized_width;
4761 column->resized_width = MAX (column->resized_width,
4763 column->resized_width += 2;
4765 if (column->max_width != -1)
4766 column->resized_width = MIN (column->resized_width,
4769 column->use_resized_width = TRUE;
4771 if (column->resized_width != old_width)
4772 gtk_widget_queue_resize (widget);
4774 gtk_widget_error_bell (widget);
4781 (event->state & GDK_MOD1_MASK) &&
4782 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4783 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4784 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4785 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4787 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4789 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4790 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4792 PsppSheetViewColumn *col;
4793 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4794 if (col != (PsppSheetViewColumn *)0x1)
4795 pspp_sheet_view_move_column_after (tree_view, column, col);
4797 gtk_widget_error_bell (widget);
4799 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4800 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4802 PsppSheetViewColumn *col;
4803 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4804 if (col != (PsppSheetViewColumn *)0x1)
4805 pspp_sheet_view_move_column_after (tree_view, column, col);
4807 gtk_widget_error_bell (widget);
4809 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4811 PsppSheetViewColumn *col;
4812 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4813 if (col != (PsppSheetViewColumn *)0x1)
4814 pspp_sheet_view_move_column_after (tree_view, column, col);
4816 gtk_widget_error_bell (widget);
4818 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4820 PsppSheetViewColumn *col;
4821 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4822 if (col != (PsppSheetViewColumn *)0x1)
4823 pspp_sheet_view_move_column_after (tree_view, column, col);
4825 gtk_widget_error_bell (widget);
4832 /* Chain up to the parent class. It handles the keybindings. */
4833 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4836 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4838 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4842 /* We pass the event to the search_entry. If its text changes, then we start
4843 * the typeahead find capabilities. */
4844 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4845 && tree_view->priv->enable_search
4846 && !tree_view->priv->search_custom_entry_set)
4848 GdkEvent *new_event;
4850 const char *new_text;
4853 gboolean text_modified;
4854 gulong popup_menu_id;
4856 pspp_sheet_view_ensure_interactive_directory (tree_view);
4858 /* Make a copy of the current text */
4859 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4860 new_event = gdk_event_copy ((GdkEvent *) event);
4861 g_object_unref (((GdkEventKey *) new_event)->window);
4862 ((GdkEventKey *) new_event)->window = g_object_ref (tree_view->priv->search_window->window);
4863 gtk_widget_realize (tree_view->priv->search_window);
4865 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4866 "popup-menu", G_CALLBACK (gtk_true),
4869 /* Move the entry off screen */
4870 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4871 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4872 gdk_screen_get_width (screen) + 1,
4873 gdk_screen_get_height (screen) + 1);
4874 gtk_widget_show (tree_view->priv->search_window);
4876 /* Send the event to the window. If the preedit_changed signal is emitted
4877 * during this event, we will set priv->imcontext_changed */
4878 tree_view->priv->imcontext_changed = FALSE;
4879 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4880 gdk_event_free (new_event);
4881 gtk_widget_hide (tree_view->priv->search_window);
4883 g_signal_handler_disconnect (tree_view->priv->search_entry,
4886 /* We check to make sure that the entry tried to handle the text, and that
4887 * the text has changed.
4889 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4890 text_modified = strcmp (old_text, new_text) != 0;
4892 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4893 (retval && text_modified)) /* ...or the text was modified */
4895 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4897 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4902 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
4912 pspp_sheet_view_key_release (GtkWidget *widget,
4915 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4917 if (tree_view->priv->rubber_band_status)
4920 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
4923 /* FIXME Is this function necessary? Can I get an enter_notify event
4924 * w/o either an expose event or a mouse motion event?
4927 pspp_sheet_view_enter_notify (GtkWidget *widget,
4928 GdkEventCrossing *event)
4930 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4934 /* Sanity check it */
4935 if (event->window != tree_view->priv->bin_window)
4938 if (tree_view->priv->row_count == 0)
4941 if (event->mode == GDK_CROSSING_GRAB ||
4942 event->mode == GDK_CROSSING_GTK_GRAB ||
4943 event->mode == GDK_CROSSING_GTK_UNGRAB ||
4944 event->mode == GDK_CROSSING_STATE_CHANGED)
4947 /* find the node internally */
4948 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
4951 pspp_sheet_view_find_offset (tree_view, new_y, &node);
4953 tree_view->priv->event_last_x = event->x;
4954 tree_view->priv->event_last_y = event->y;
4956 prelight_or_select (tree_view, node, event->x, event->y);
4962 pspp_sheet_view_leave_notify (GtkWidget *widget,
4963 GdkEventCrossing *event)
4965 PsppSheetView *tree_view;
4967 if (event->mode == GDK_CROSSING_GRAB)
4970 tree_view = PSPP_SHEET_VIEW (widget);
4972 if (tree_view->priv->prelight_node >= 0)
4973 _pspp_sheet_view_queue_draw_node (tree_view,
4974 tree_view->priv->prelight_node,
4977 tree_view->priv->event_last_x = -10000;
4978 tree_view->priv->event_last_y = -10000;
4980 prelight_or_select (tree_view,
4982 -1000, -1000); /* coords not possibly over an arrow */
4989 pspp_sheet_view_focus_out (GtkWidget *widget,
4990 GdkEventFocus *event)
4992 PsppSheetView *tree_view;
4994 tree_view = PSPP_SHEET_VIEW (widget);
4996 gtk_widget_queue_draw (widget);
4998 /* destroy interactive search dialog */
4999 if (tree_view->priv->search_window)
5000 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
5006 /* Incremental Reflow
5010 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
5015 y = pspp_sheet_view_node_find_offset (tree_view, node)
5016 - tree_view->priv->vadjustment->value
5017 + TREE_VIEW_HEADER_HEIGHT (tree_view);
5019 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
5021 GTK_WIDGET (tree_view)->allocation.width,
5022 tree_view->priv->fixed_height);
5026 node_is_visible (PsppSheetView *tree_view,
5032 y = pspp_sheet_view_node_find_offset (tree_view, node);
5033 height = ROW_HEIGHT (tree_view);
5035 if (y >= tree_view->priv->vadjustment->value &&
5036 y + height <= (tree_view->priv->vadjustment->value
5037 + tree_view->priv->vadjustment->page_size))
5043 /* Returns the row height. */
5045 validate_row (PsppSheetView *tree_view,
5050 PsppSheetViewColumn *column;
5051 GList *list, *first_column, *last_column;
5053 gint horizontal_separator;
5054 gint vertical_separator;
5055 gint focus_line_width;
5056 gboolean draw_vgrid_lines, draw_hgrid_lines;
5058 gint grid_line_width;
5059 gboolean wide_separators;
5060 gint separator_height;
5062 gtk_widget_style_get (GTK_WIDGET (tree_view),
5063 "focus-padding", &focus_pad,
5064 "focus-line-width", &focus_line_width,
5065 "horizontal-separator", &horizontal_separator,
5066 "vertical-separator", &vertical_separator,
5067 "grid-line-width", &grid_line_width,
5068 "wide-separators", &wide_separators,
5069 "separator-height", &separator_height,
5073 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5074 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5076 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5077 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5079 for (last_column = g_list_last (tree_view->priv->columns);
5080 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5081 last_column = last_column->prev)
5084 for (first_column = g_list_first (tree_view->priv->columns);
5085 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5086 first_column = first_column->next)
5089 for (list = tree_view->priv->columns; list; list = list->next)
5094 column = list->data;
5096 if (! column->visible)
5099 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5100 pspp_sheet_view_column_cell_get_size (column,
5102 &tmp_width, &tmp_height);
5104 tmp_height += vertical_separator;
5105 height = MAX (height, tmp_height);
5107 tmp_width = tmp_width + horizontal_separator;
5109 if (draw_vgrid_lines)
5111 if (list->data == first_column || list->data == last_column)
5112 tmp_width += grid_line_width / 2.0;
5114 tmp_width += grid_line_width;
5117 if (tmp_width > column->requested_width)
5118 column->requested_width = tmp_width;
5121 if (draw_hgrid_lines)
5122 height += grid_line_width;
5124 tree_view->priv->post_validation_flag = TRUE;
5130 validate_visible_area (PsppSheetView *tree_view)
5132 GtkTreePath *path = NULL;
5133 GtkTreePath *above_path = NULL;
5136 gboolean size_changed = FALSE;
5138 gint area_above = 0;
5139 gint area_below = 0;
5141 if (tree_view->priv->row_count == 0)
5144 if (tree_view->priv->scroll_to_path == NULL)
5147 total_height = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5149 if (total_height == 0)
5152 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5155 /* we are going to scroll, and will update dy */
5156 _pspp_sheet_view_find_node (tree_view, path, &node);
5157 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5159 if (tree_view->priv->scroll_to_use_align)
5161 gint height = ROW_HEIGHT (tree_view);
5162 area_above = (total_height - height) *
5163 tree_view->priv->scroll_to_row_align;
5164 area_below = total_height - area_above - height;
5165 area_above = MAX (area_above, 0);
5166 area_below = MAX (area_below, 0);
5171 * 1) row not visible
5175 gint height = ROW_HEIGHT (tree_view);
5177 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5179 if (dy >= tree_view->priv->vadjustment->value &&
5180 dy + height <= (tree_view->priv->vadjustment->value
5181 + tree_view->priv->vadjustment->page_size))
5183 /* row visible: keep the row at the same position */
5184 area_above = dy - tree_view->priv->vadjustment->value;
5185 area_below = (tree_view->priv->vadjustment->value +
5186 tree_view->priv->vadjustment->page_size)
5191 /* row not visible */
5193 && dy + height <= tree_view->priv->vadjustment->page_size)
5195 /* row at the beginning -- fixed */
5197 area_below = tree_view->priv->vadjustment->page_size
5198 - area_above - height;
5200 else if (dy >= (tree_view->priv->vadjustment->upper -
5201 tree_view->priv->vadjustment->page_size))
5203 /* row at the end -- fixed */
5204 area_above = dy - (tree_view->priv->vadjustment->upper -
5205 tree_view->priv->vadjustment->page_size);
5206 area_below = tree_view->priv->vadjustment->page_size -
5207 area_above - height;
5211 area_above = tree_view->priv->vadjustment->page_size - height;
5217 /* row somewhere in the middle, bring it to the top
5221 area_below = total_height - height;
5227 /* the scroll to isn't valid; ignore it.
5230 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5231 tree_view->priv->scroll_to_path = NULL;
5235 above_path = gtk_tree_path_copy (path);
5237 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5238 * backwards is much slower then forward, as there is no iter_prev function.
5239 * We go forwards first in case we run out of tree. Then we go backwards to
5242 while (node >= 0 && area_below > 0)
5244 gboolean done = FALSE;
5247 node = pspp_sheet_view_node_next (tree_view, node);
5250 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5252 gtk_tree_path_next (path);
5255 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5265 area_below -= ROW_HEIGHT (tree_view);
5267 gtk_tree_path_free (path);
5269 /* If we ran out of tree, and have extra area_below left, we need to add it
5272 area_above += area_below;
5274 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5276 /* We walk backwards */
5277 while (area_above > 0)
5279 node = pspp_sheet_view_node_prev (tree_view, node);
5281 /* Always find the new path in the tree. We cannot just assume
5282 * a gtk_tree_path_prev() is enough here, as there might be children
5283 * in between this node and the previous sibling node. If this
5284 * appears to be a performance hotspot in profiles, we can look into
5285 * intrigate logic for keeping path, node and iter in sync like
5286 * we do for forward walks. (Which will be hard because of the lacking
5293 gtk_tree_path_free (above_path);
5294 above_path = _pspp_sheet_view_find_path (tree_view, node);
5296 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5298 area_above -= ROW_HEIGHT (tree_view);
5301 /* set the dy here to scroll to the path,
5302 * and sync the top row accordingly
5304 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5305 pspp_sheet_view_top_row_to_dy (tree_view);
5307 /* update width/height and queue a resize */
5310 GtkRequisition requisition;
5312 /* We temporarily guess a size, under the assumption that it will be the
5313 * same when we get our next size_allocate. If we don't do this, we'll be
5314 * in an inconsistent state if we call top_row_to_dy. */
5316 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5317 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5318 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5319 gtk_adjustment_changed (tree_view->priv->hadjustment);
5320 gtk_adjustment_changed (tree_view->priv->vadjustment);
5321 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5324 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5325 tree_view->priv->scroll_to_path = NULL;
5328 gtk_tree_path_free (above_path);
5330 if (tree_view->priv->scroll_to_column)
5332 tree_view->priv->scroll_to_column = NULL;
5334 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5338 initialize_fixed_height_mode (PsppSheetView *tree_view)
5340 if (!tree_view->priv->row_count)
5343 if (tree_view->priv->fixed_height_set)
5346 if (tree_view->priv->fixed_height < 0)
5353 path = _pspp_sheet_view_find_path (tree_view, node);
5354 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5356 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5358 gtk_tree_path_free (path);
5360 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5364 /* Our strategy for finding nodes to validate is a little convoluted. We find
5365 * the left-most uninvalidated node. We then try walking right, validating
5366 * nodes. Once we find a valid node, we repeat the previous process of finding
5367 * the first invalid node.
5371 validate_rows_handler (PsppSheetView *tree_view)
5373 initialize_fixed_height_mode (tree_view);
5374 if (tree_view->priv->validate_rows_timer)
5376 g_source_remove (tree_view->priv->validate_rows_timer);
5377 tree_view->priv->validate_rows_timer = 0;
5384 do_presize_handler (PsppSheetView *tree_view)
5386 GtkRequisition requisition;
5388 validate_visible_area (tree_view);
5389 tree_view->priv->presize_handler_timer = 0;
5391 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5394 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5396 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5397 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5398 gtk_adjustment_changed (tree_view->priv->hadjustment);
5399 gtk_adjustment_changed (tree_view->priv->vadjustment);
5400 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5406 presize_handler_callback (gpointer data)
5408 do_presize_handler (PSPP_SHEET_VIEW (data));
5414 install_presize_handler (PsppSheetView *tree_view)
5416 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5419 if (! tree_view->priv->presize_handler_timer)
5421 tree_view->priv->presize_handler_timer =
5422 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5424 if (! tree_view->priv->validate_rows_timer)
5426 tree_view->priv->validate_rows_timer =
5427 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5432 scroll_sync_handler (PsppSheetView *tree_view)
5434 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
5435 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5436 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5437 pspp_sheet_view_top_row_to_dy (tree_view);
5439 pspp_sheet_view_dy_to_top_row (tree_view);
5441 tree_view->priv->scroll_sync_timer = 0;
5447 install_scroll_sync_handler (PsppSheetView *tree_view)
5449 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5452 if (!tree_view->priv->scroll_sync_timer)
5454 tree_view->priv->scroll_sync_timer =
5455 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5460 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5464 gtk_tree_row_reference_free (tree_view->priv->top_row);
5468 tree_view->priv->top_row = NULL;
5469 tree_view->priv->top_row_dy = 0;
5473 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5474 tree_view->priv->top_row_dy = offset;
5478 /* Always call this iff dy is in the visible range. If the tree is empty, then
5479 * it's set to be NULL, and top_row_dy is 0;
5482 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5488 if (tree_view->priv->row_count == 0)
5490 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5494 offset = pspp_sheet_view_find_offset (tree_view,
5495 tree_view->priv->dy,
5500 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5504 path = _pspp_sheet_view_find_path (tree_view, node);
5505 pspp_sheet_view_set_top_row (tree_view, path, offset);
5506 gtk_tree_path_free (path);
5512 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5518 /* Avoid recursive calls */
5519 if (tree_view->priv->in_top_row_to_dy)
5522 if (tree_view->priv->top_row)
5523 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5530 _pspp_sheet_view_find_node (tree_view, path, &node);
5533 gtk_tree_path_free (path);
5537 /* keep dy and set new toprow */
5538 gtk_tree_row_reference_free (tree_view->priv->top_row);
5539 tree_view->priv->top_row = NULL;
5540 tree_view->priv->top_row_dy = 0;
5541 /* DO NOT install the idle handler */
5542 pspp_sheet_view_dy_to_top_row (tree_view);
5546 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5548 /* new top row -- do NOT install the idle handler */
5549 pspp_sheet_view_dy_to_top_row (tree_view);
5553 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5554 new_dy += tree_view->priv->top_row_dy;
5556 if (new_dy + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
5557 new_dy = tree_view->priv->height - tree_view->priv->vadjustment->page_size;
5559 new_dy = MAX (0, new_dy);
5561 tree_view->priv->in_top_row_to_dy = TRUE;
5562 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5563 tree_view->priv->in_top_row_to_dy = FALSE;
5568 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5570 install_presize_handler (tree_view);
5576 set_source_row (GdkDragContext *context,
5577 GtkTreeModel *model,
5578 GtkTreePath *source_row)
5580 g_object_set_data_full (G_OBJECT (context),
5581 "gtk-tree-view-source-row",
5582 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5583 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5587 get_source_row (GdkDragContext *context)
5589 GtkTreeRowReference *ref =
5590 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5593 return gtk_tree_row_reference_get_path (ref);
5600 GtkTreeRowReference *dest_row;
5601 guint path_down_mode : 1;
5602 guint empty_view_drop : 1;
5603 guint drop_append_mode : 1;
5608 dest_row_free (gpointer data)
5610 DestRow *dr = (DestRow *)data;
5612 gtk_tree_row_reference_free (dr->dest_row);
5613 g_slice_free (DestRow, dr);
5617 set_dest_row (GdkDragContext *context,
5618 GtkTreeModel *model,
5619 GtkTreePath *dest_row,
5620 gboolean path_down_mode,
5621 gboolean empty_view_drop,
5622 gboolean drop_append_mode)
5628 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5633 dr = g_slice_new (DestRow);
5635 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5636 dr->path_down_mode = path_down_mode != FALSE;
5637 dr->empty_view_drop = empty_view_drop != FALSE;
5638 dr->drop_append_mode = drop_append_mode != FALSE;
5640 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5641 dr, (GDestroyNotify) dest_row_free);
5645 get_dest_row (GdkDragContext *context,
5646 gboolean *path_down_mode)
5649 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5653 GtkTreePath *path = NULL;
5656 *path_down_mode = dr->path_down_mode;
5659 path = gtk_tree_row_reference_get_path (dr->dest_row);
5660 else if (dr->empty_view_drop)
5661 path = gtk_tree_path_new_from_indices (0, -1);
5665 if (path && dr->drop_append_mode)
5666 gtk_tree_path_next (path);
5674 /* Get/set whether drag_motion requested the drag data and
5675 * drag_data_received should thus not actually insert the data,
5676 * since the data doesn't result from a drop.
5679 set_status_pending (GdkDragContext *context,
5680 GdkDragAction suggested_action)
5682 g_object_set_data (G_OBJECT (context),
5683 "gtk-tree-view-status-pending",
5684 GINT_TO_POINTER (suggested_action));
5687 static GdkDragAction
5688 get_status_pending (GdkDragContext *context)
5690 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5691 "gtk-tree-view-status-pending"));
5694 static TreeViewDragInfo*
5695 get_info (PsppSheetView *tree_view)
5697 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5701 destroy_info (TreeViewDragInfo *di)
5703 g_slice_free (TreeViewDragInfo, di);
5706 static TreeViewDragInfo*
5707 ensure_info (PsppSheetView *tree_view)
5709 TreeViewDragInfo *di;
5711 di = get_info (tree_view);
5715 di = g_slice_new0 (TreeViewDragInfo);
5717 g_object_set_data_full (G_OBJECT (tree_view),
5718 "gtk-tree-view-drag-info",
5720 (GDestroyNotify) destroy_info);
5727 remove_info (PsppSheetView *tree_view)
5729 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5734 drag_scan_timeout (gpointer data)
5736 PsppSheetView *tree_view;
5738 GdkModifierType state;
5739 GtkTreePath *path = NULL;
5740 PsppSheetViewColumn *column = NULL;
5741 GdkRectangle visible_rect;
5743 GDK_THREADS_ENTER ();
5745 tree_view = PSPP_SHEET_VIEW (data);
5747 gdk_window_get_pointer (tree_view->priv->bin_window,
5750 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5752 /* See if we are near the edge. */
5753 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5754 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5755 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5756 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5758 pspp_sheet_view_get_path_at_pos (tree_view,
5759 tree_view->priv->bin_window,
5768 pspp_sheet_view_scroll_to_cell (tree_view,
5774 gtk_tree_path_free (path);
5778 GDK_THREADS_LEAVE ();
5785 add_scroll_timeout (PsppSheetView *tree_view)
5787 if (tree_view->priv->scroll_timeout == 0)
5789 tree_view->priv->scroll_timeout =
5790 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5795 remove_scroll_timeout (PsppSheetView *tree_view)
5797 if (tree_view->priv->scroll_timeout != 0)
5799 g_source_remove (tree_view->priv->scroll_timeout);
5800 tree_view->priv->scroll_timeout = 0;
5805 check_model_dnd (GtkTreeModel *model,
5806 GType required_iface,
5807 const gchar *signal)
5809 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5811 g_warning ("You must override the default '%s' handler "
5812 "on PsppSheetView when using models that don't support "
5813 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5814 "is to connect to '%s' and call "
5815 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5816 "the default handler from running. Look at the source code "
5817 "for the default handler in gtktreeview.c to get an idea what "
5818 "your handler should do. (gtktreeview.c is in the GTK source "
5819 "code.) If you're using GTK from a language other than C, "
5820 "there may be a more natural way to override default handlers, e.g. via derivation.",
5821 signal, g_type_name (required_iface), signal);
5829 scroll_row_timeout (gpointer data)
5831 PsppSheetView *tree_view = data;
5833 pspp_sheet_view_horizontal_autoscroll (tree_view);
5834 pspp_sheet_view_vertical_autoscroll (tree_view);
5836 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5837 pspp_sheet_view_update_rubber_band (tree_view);
5842 /* Returns TRUE if event should not be propagated to parent widgets */
5844 set_destination_row (PsppSheetView *tree_view,
5845 GdkDragContext *context,
5846 /* coordinates relative to the widget */
5849 GdkDragAction *suggested_action,
5852 GtkTreePath *path = NULL;
5853 PsppSheetViewDropPosition pos;
5854 PsppSheetViewDropPosition old_pos;
5855 TreeViewDragInfo *di;
5857 GtkTreePath *old_dest_path = NULL;
5858 gboolean can_drop = FALSE;
5860 *suggested_action = 0;
5863 widget = GTK_WIDGET (tree_view);
5865 di = get_info (tree_view);
5867 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5869 /* someone unset us as a drag dest, note that if
5870 * we return FALSE drag_leave isn't called
5873 pspp_sheet_view_set_drag_dest_row (tree_view,
5875 PSPP_SHEET_VIEW_DROP_BEFORE);
5877 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5879 return FALSE; /* no longer a drop site */
5882 *target = gtk_drag_dest_find_target (widget, context,
5883 gtk_drag_dest_get_target_list (widget));
5884 if (*target == GDK_NONE)
5889 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5895 GtkTreeModel *model;
5897 /* the row got dropped on empty space, let's setup a special case
5901 gtk_tree_path_free (path);
5903 model = pspp_sheet_view_get_model (tree_view);
5905 n_children = gtk_tree_model_iter_n_children (model, NULL);
5908 pos = PSPP_SHEET_VIEW_DROP_AFTER;
5909 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5913 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
5914 path = gtk_tree_path_new_from_indices (0, -1);
5924 /* If we left the current row's "open" zone, unset the timeout for
5927 pspp_sheet_view_get_drag_dest_row (tree_view,
5932 gtk_tree_path_free (old_dest_path);
5934 if (TRUE /* FIXME if the location droppable predicate */)
5942 GtkWidget *source_widget;
5944 *suggested_action = context->suggested_action;
5945 source_widget = gtk_drag_get_source_widget (context);
5947 if (source_widget == widget)
5949 /* Default to MOVE, unless the user has
5950 * pressed ctrl or shift to affect available actions
5952 if ((context->actions & GDK_ACTION_MOVE) != 0)
5953 *suggested_action = GDK_ACTION_MOVE;
5956 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5961 /* can't drop here */
5962 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5964 PSPP_SHEET_VIEW_DROP_BEFORE);
5968 gtk_tree_path_free (path);
5974 get_logical_dest_row (PsppSheetView *tree_view,
5975 gboolean *path_down_mode,
5976 gboolean *drop_append_mode)
5978 /* adjust path to point to the row the drop goes in front of */
5979 GtkTreePath *path = NULL;
5980 PsppSheetViewDropPosition pos;
5982 g_return_val_if_fail (path_down_mode != NULL, NULL);
5983 g_return_val_if_fail (drop_append_mode != NULL, NULL);
5985 *path_down_mode = FALSE;
5986 *drop_append_mode = 0;
5988 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
5993 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
5995 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
5996 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
5997 *path_down_mode = TRUE;
6001 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
6003 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
6005 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6006 !gtk_tree_model_iter_next (model, &iter))
6007 *drop_append_mode = 1;
6010 *drop_append_mode = 0;
6011 gtk_tree_path_next (path);
6019 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
6020 GdkEventMotion *event)
6022 GtkWidget *widget = GTK_WIDGET (tree_view);
6023 GdkDragContext *context;
6024 TreeViewDragInfo *di;
6025 GtkTreePath *path = NULL;
6027 gint cell_x, cell_y;
6028 GtkTreeModel *model;
6029 gboolean retval = FALSE;
6031 di = get_info (tree_view);
6033 if (di == NULL || !di->source_set)
6036 if (tree_view->priv->pressed_button < 0)
6039 if (!gtk_drag_check_threshold (widget,
6040 tree_view->priv->press_start_x,
6041 tree_view->priv->press_start_y,
6042 event->x, event->y))
6045 model = pspp_sheet_view_get_model (tree_view);
6050 button = tree_view->priv->pressed_button;
6051 tree_view->priv->pressed_button = -1;
6053 pspp_sheet_view_get_path_at_pos (tree_view,
6054 tree_view->priv->press_start_x,
6055 tree_view->priv->press_start_y,
6064 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6065 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6069 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6072 /* Now we can begin the drag */
6076 context = gtk_drag_begin (widget,
6077 gtk_drag_source_get_target_list (widget),
6082 set_source_row (context, model, path);
6086 gtk_tree_path_free (path);
6093 pspp_sheet_view_drag_begin (GtkWidget *widget,
6094 GdkDragContext *context)
6096 PsppSheetView *tree_view;
6097 GtkTreePath *path = NULL;
6098 gint cell_x, cell_y;
6100 TreeViewDragInfo *di;
6102 tree_view = PSPP_SHEET_VIEW (widget);
6104 /* if the user uses a custom DND source impl, we don't set the icon here */
6105 di = get_info (tree_view);
6107 if (di == NULL || !di->source_set)
6110 pspp_sheet_view_get_path_at_pos (tree_view,
6111 tree_view->priv->press_start_x,
6112 tree_view->priv->press_start_y,
6118 g_return_if_fail (path != NULL);
6120 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6123 gtk_drag_set_icon_pixmap (context,
6124 gdk_drawable_get_colormap (row_pix),
6127 /* the + 1 is for the black border in the icon */
6128 tree_view->priv->press_start_x + 1,
6131 g_object_unref (row_pix);
6132 gtk_tree_path_free (path);
6136 pspp_sheet_view_drag_end (GtkWidget *widget,
6137 GdkDragContext *context)
6142 /* Default signal implementations for the drag signals */
6144 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6145 GdkDragContext *context,
6146 GtkSelectionData *selection_data,
6150 PsppSheetView *tree_view;
6151 GtkTreeModel *model;
6152 TreeViewDragInfo *di;
6153 GtkTreePath *source_row;
6155 tree_view = PSPP_SHEET_VIEW (widget);
6157 model = pspp_sheet_view_get_model (tree_view);
6162 di = get_info (PSPP_SHEET_VIEW (widget));
6167 source_row = get_source_row (context);
6169 if (source_row == NULL)
6172 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6173 * any model; for DragSource models there are some other targets
6177 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6178 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6183 /* If drag_data_get does nothing, try providing row data. */
6184 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6186 gtk_tree_set_row_drag_data (selection_data,
6192 gtk_tree_path_free (source_row);
6197 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6198 GdkDragContext *context)
6200 TreeViewDragInfo *di;
6201 GtkTreeModel *model;
6202 PsppSheetView *tree_view;
6203 GtkTreePath *source_row;
6205 tree_view = PSPP_SHEET_VIEW (widget);
6206 model = pspp_sheet_view_get_model (tree_view);
6208 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6211 di = get_info (tree_view);
6216 source_row = get_source_row (context);
6218 if (source_row == NULL)
6221 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6224 gtk_tree_path_free (source_row);
6226 set_source_row (context, NULL, NULL);
6230 pspp_sheet_view_drag_leave (GtkWidget *widget,
6231 GdkDragContext *context,
6234 /* unset any highlight row */
6235 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6237 PSPP_SHEET_VIEW_DROP_BEFORE);
6239 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6244 pspp_sheet_view_drag_motion (GtkWidget *widget,
6245 GdkDragContext *context,
6246 /* coordinates relative to the widget */
6252 GtkTreePath *path = NULL;
6253 PsppSheetViewDropPosition pos;
6254 PsppSheetView *tree_view;
6255 GdkDragAction suggested_action = 0;
6258 tree_view = PSPP_SHEET_VIEW (widget);
6260 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6263 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6265 /* we only know this *after* set_desination_row */
6266 empty = tree_view->priv->empty_view_drop;
6268 if (path == NULL && !empty)
6270 /* Can't drop here. */
6271 gdk_drag_status (context, 0, time);
6275 if (tree_view->priv->open_dest_timeout == 0 &&
6276 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6277 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6283 add_scroll_timeout (tree_view);
6286 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6288 /* Request data so we can use the source row when
6289 * determining whether to accept the drop
6291 set_status_pending (context, suggested_action);
6292 gtk_drag_get_data (widget, context, target, time);
6296 set_status_pending (context, 0);
6297 gdk_drag_status (context, suggested_action, time);
6302 gtk_tree_path_free (path);
6309 pspp_sheet_view_drag_drop (GtkWidget *widget,
6310 GdkDragContext *context,
6311 /* coordinates relative to the widget */
6316 PsppSheetView *tree_view;
6318 GdkDragAction suggested_action = 0;
6319 GdkAtom target = GDK_NONE;
6320 TreeViewDragInfo *di;
6321 GtkTreeModel *model;
6322 gboolean path_down_mode;
6323 gboolean drop_append_mode;
6325 tree_view = PSPP_SHEET_VIEW (widget);
6327 model = pspp_sheet_view_get_model (tree_view);
6329 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6331 di = get_info (tree_view);
6336 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6339 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6342 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6344 if (target != GDK_NONE && path != NULL)
6346 /* in case a motion had requested drag data, change things so we
6347 * treat drag data receives as a drop.
6349 set_status_pending (context, 0);
6350 set_dest_row (context, model, path,
6351 path_down_mode, tree_view->priv->empty_view_drop,
6356 gtk_tree_path_free (path);
6358 /* Unset this thing */
6359 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6361 PSPP_SHEET_VIEW_DROP_BEFORE);
6363 if (target != GDK_NONE)
6365 gtk_drag_get_data (widget, context, target, time);
6373 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6374 GdkDragContext *context,
6375 /* coordinates relative to the widget */
6378 GtkSelectionData *selection_data,
6383 TreeViewDragInfo *di;
6384 gboolean accepted = FALSE;
6385 GtkTreeModel *model;
6386 PsppSheetView *tree_view;
6387 GtkTreePath *dest_row;
6388 GdkDragAction suggested_action;
6389 gboolean path_down_mode;
6390 gboolean drop_append_mode;
6392 tree_view = PSPP_SHEET_VIEW (widget);
6394 model = pspp_sheet_view_get_model (tree_view);
6396 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6399 di = get_info (tree_view);
6404 suggested_action = get_status_pending (context);
6406 if (suggested_action)
6408 /* We are getting this data due to a request in drag_motion,
6409 * rather than due to a request in drag_drop, so we are just
6410 * supposed to call drag_status, not actually paste in the
6413 path = get_logical_dest_row (tree_view, &path_down_mode,
6417 suggested_action = 0;
6418 else if (path_down_mode)
6419 gtk_tree_path_down (path);
6421 if (suggested_action)
6423 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6429 path_down_mode = FALSE;
6430 gtk_tree_path_up (path);
6432 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6435 suggested_action = 0;
6438 suggested_action = 0;
6442 gdk_drag_status (context, suggested_action, time);
6445 gtk_tree_path_free (path);
6447 /* If you can't drop, remove user drop indicator until the next motion */
6448 if (suggested_action == 0)
6449 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6451 PSPP_SHEET_VIEW_DROP_BEFORE);
6456 dest_row = get_dest_row (context, &path_down_mode);
6458 if (dest_row == NULL)
6461 if (selection_data->length >= 0)
6465 gtk_tree_path_down (dest_row);
6466 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6467 dest_row, selection_data))
6468 gtk_tree_path_up (dest_row);
6472 if (selection_data->length >= 0)
6474 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6480 gtk_drag_finish (context,
6482 (context->action == GDK_ACTION_MOVE),
6485 if (gtk_tree_path_get_depth (dest_row) == 1
6486 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6488 /* special special case drag to "0", scroll to first item */
6489 if (!tree_view->priv->scroll_to_path)
6490 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6493 gtk_tree_path_free (dest_row);
6496 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6501 /* GtkContainer Methods
6506 pspp_sheet_view_remove (GtkContainer *container,
6509 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6510 PsppSheetViewChild *child = NULL;
6513 tmp_list = tree_view->priv->children;
6516 child = tmp_list->data;
6517 if (child->widget == widget)
6519 gtk_widget_unparent (widget);
6521 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6522 g_list_free_1 (tmp_list);
6523 g_slice_free (PsppSheetViewChild, child);
6527 tmp_list = tmp_list->next;
6530 tmp_list = tree_view->priv->columns;
6534 PsppSheetViewColumn *column;
6535 column = tmp_list->data;
6536 if (column->button == widget)
6538 gtk_widget_unparent (widget);
6541 tmp_list = tmp_list->next;
6546 pspp_sheet_view_forall (GtkContainer *container,
6547 gboolean include_internals,
6548 GtkCallback callback,
6549 gpointer callback_data)
6551 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6552 PsppSheetViewChild *child = NULL;
6553 PsppSheetViewColumn *column;
6556 tmp_list = tree_view->priv->children;
6559 child = tmp_list->data;
6560 tmp_list = tmp_list->next;
6562 (* callback) (child->widget, callback_data);
6564 if (include_internals == FALSE)
6567 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6569 column = tmp_list->data;
6572 (* callback) (column->button, callback_data);
6576 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6577 * cells. If so we draw one big row-spanning focus rectangle.
6580 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6584 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6585 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6587 for (list = tree_view->priv->columns; list; list = list->next)
6589 if (!((PsppSheetViewColumn *)list->data)->visible)
6591 if (_pspp_sheet_view_column_count_special_cells (list->data))
6599 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6600 PsppSheetViewColumn *focus_column,
6601 gboolean clamp_column_visible)
6603 g_return_if_fail (focus_column != NULL);
6605 tree_view->priv->focus_column = focus_column;
6606 if (!focus_column->button)
6608 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6609 // g_return_if_fail (focus_column->button != NULL);
6610 if (focus_column->button == NULL)
6614 if (GTK_CONTAINER (tree_view)->focus_child != focus_column->button)
6615 gtk_widget_grab_focus (focus_column->button);
6617 if (clamp_column_visible)
6618 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6621 /* Returns TRUE if the focus is within the headers, after the focus operation is
6625 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6626 GtkDirectionType dir,
6627 gboolean clamp_column_visible)
6629 GtkWidget *focus_child;
6630 PsppSheetViewColumn *focus_column;
6631 GList *last_column, *first_column;
6635 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6638 focus_child = GTK_CONTAINER (tree_view)->focus_child;
6640 first_column = tree_view->priv->columns;
6641 while (first_column)
6643 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6645 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6647 first_column = first_column->next;
6650 /* No headers are visible, or are focusable. We can't focus in or out.
6652 if (first_column == NULL)
6655 last_column = g_list_last (tree_view->priv->columns);
6658 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6660 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6662 last_column = last_column->prev;
6666 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6670 case GTK_DIR_TAB_BACKWARD:
6671 case GTK_DIR_TAB_FORWARD:
6674 if (focus_child == NULL)
6676 if (tree_view->priv->focus_column != NULL &&
6677 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6678 focus_column = tree_view->priv->focus_column;
6680 focus_column = first_column->data;
6681 pspp_sheet_view_focus_column (tree_view, focus_column,
6682 clamp_column_visible);
6689 if (focus_child == NULL)
6691 if (tree_view->priv->focus_column != NULL)
6692 focus_column = tree_view->priv->focus_column;
6693 else if (dir == GTK_DIR_LEFT)
6694 focus_column = last_column->data;
6696 focus_column = first_column->data;
6697 pspp_sheet_view_focus_column (tree_view, focus_column,
6698 clamp_column_visible);
6702 if (gtk_widget_child_focus (focus_child, dir))
6704 /* The focus moves inside the button. */
6705 /* This is probably a great example of bad UI */
6706 if (clamp_column_visible)
6707 pspp_sheet_view_clamp_column_visible (tree_view,
6708 tree_view->priv->focus_column,
6713 /* We need to move the focus among the row of buttons. */
6714 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6715 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6718 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6719 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6721 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6727 PsppSheetViewColumn *column;
6729 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6730 tmp_list = tmp_list->next;
6732 tmp_list = tmp_list->prev;
6734 if (tmp_list == NULL)
6736 g_warning ("Internal button not found");
6739 column = tmp_list->data;
6740 if (column->visible &&
6741 pspp_sheet_view_column_can_focus (column))
6743 pspp_sheet_view_column_set_need_button (column, TRUE);
6746 pspp_sheet_view_focus_column (tree_view, column,
6747 clamp_column_visible);
6755 g_assert_not_reached ();
6762 /* This function returns in 'path' the first focusable path, if the given path
6763 * is already focusable, it's the returned one.
6767 search_first_focusable_path (PsppSheetView *tree_view,
6769 gboolean search_forward,
6772 /* XXX this function is trivial given that the sheetview doesn't support
6776 if (!path || !*path)
6779 _pspp_sheet_view_find_node (tree_view, *path, &node);
6787 return (*path != NULL);
6791 pspp_sheet_view_focus (GtkWidget *widget,
6792 GtkDirectionType direction)
6794 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6795 GtkContainer *container = GTK_CONTAINER (widget);
6796 GtkWidget *focus_child;
6798 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6801 focus_child = container->focus_child;
6803 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6804 /* Case 1. Headers currently have focus. */
6811 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6813 case GTK_DIR_TAB_BACKWARD:
6816 case GTK_DIR_TAB_FORWARD:
6818 gtk_widget_grab_focus (widget);
6821 g_assert_not_reached ();
6826 /* Case 2. We don't have focus at all. */
6827 if (!gtk_widget_has_focus (widget))
6829 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6830 gtk_widget_grab_focus (widget);
6834 /* Case 3. We have focus already. */
6835 if (direction == GTK_DIR_TAB_BACKWARD)
6836 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6837 else if (direction == GTK_DIR_TAB_FORWARD)
6840 /* Other directions caught by the keybindings */
6841 gtk_widget_grab_focus (widget);
6846 pspp_sheet_view_grab_focus (GtkWidget *widget)
6848 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6850 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6854 pspp_sheet_view_style_set (GtkWidget *widget,
6855 GtkStyle *previous_style)
6857 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6859 PsppSheetViewColumn *column;
6861 if (gtk_widget_get_realized (widget))
6864 PsppSheetViewPrivate *priv = PSPP_SHEET_VIEW (widget)->priv;
6866 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
6867 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
6868 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
6869 for (i = 0; i < 5 ; ++i)
6871 g_object_unref (priv->grid_line_gc[i]);
6872 priv->grid_line_gc[i] = gdk_gc_new (widget->window);
6873 gdk_gc_copy (priv->grid_line_gc[i], widget->style->text_aa_gc[i]);
6876 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6879 gtk_widget_style_get (widget,
6880 "expander-size", &tree_view->priv->expander_size,
6882 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6884 for (list = tree_view->priv->columns; list; list = list->next)
6886 column = list->data;
6887 _pspp_sheet_view_column_cell_set_dirty (column);
6890 tree_view->priv->fixed_height = -1;
6892 /* Invalidate cached button style. */
6893 if (tree_view->priv->button_style)
6895 g_object_unref (tree_view->priv->button_style);
6896 tree_view->priv->button_style = NULL;
6899 gtk_widget_queue_resize (widget);
6904 pspp_sheet_view_set_focus_child (GtkContainer *container,
6907 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6910 for (list = tree_view->priv->columns; list; list = list->next)
6912 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6914 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6919 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6923 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6924 GtkAdjustment *hadj,
6925 GtkAdjustment *vadj)
6927 gboolean need_adjust = FALSE;
6929 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6932 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6934 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6936 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
6938 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6940 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
6942 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
6943 pspp_sheet_view_adjustment_changed,
6945 g_object_unref (tree_view->priv->hadjustment);
6948 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
6950 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
6951 pspp_sheet_view_adjustment_changed,
6953 g_object_unref (tree_view->priv->vadjustment);
6956 if (tree_view->priv->hadjustment != hadj)
6958 tree_view->priv->hadjustment = hadj;
6959 g_object_ref_sink (tree_view->priv->hadjustment);
6961 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
6962 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6967 if (tree_view->priv->vadjustment != vadj)
6969 tree_view->priv->vadjustment = vadj;
6970 g_object_ref_sink (tree_view->priv->vadjustment);
6972 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
6973 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6979 pspp_sheet_view_adjustment_changed (NULL, tree_view);
6984 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
6985 GtkMovementStep step,
6988 PsppSheetSelectMode mode;
6989 GdkModifierType state;
6991 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
6992 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
6993 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
6994 step == GTK_MOVEMENT_DISPLAY_LINES ||
6995 step == GTK_MOVEMENT_PAGES ||
6996 step == GTK_MOVEMENT_BUFFER_ENDS ||
6997 step == GTK_MOVEMENT_DISPLAY_LINE_ENDS, FALSE);
6999 if (tree_view->priv->row_count == 0)
7001 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7004 pspp_sheet_view_stop_editing (tree_view, FALSE);
7005 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7006 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7009 if (gtk_get_current_event_state (&state))
7011 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7012 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
7013 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
7014 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
7016 /* else we assume not pressed */
7020 case GTK_MOVEMENT_LOGICAL_POSITIONS:
7021 pspp_sheet_view_move_cursor_tab (tree_view, count);
7023 case GTK_MOVEMENT_VISUAL_POSITIONS:
7024 pspp_sheet_view_move_cursor_left_right (tree_view, count, mode);
7026 case GTK_MOVEMENT_DISPLAY_LINES:
7027 pspp_sheet_view_move_cursor_up_down (tree_view, count, mode);
7029 case GTK_MOVEMENT_PAGES:
7030 pspp_sheet_view_move_cursor_page_up_down (tree_view, count, mode);
7032 case GTK_MOVEMENT_BUFFER_ENDS:
7033 pspp_sheet_view_move_cursor_start_end (tree_view, count, mode);
7035 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
7036 pspp_sheet_view_move_cursor_line_start_end (tree_view, count, mode);
7039 g_assert_not_reached ();
7046 pspp_sheet_view_put (PsppSheetView *tree_view,
7047 GtkWidget *child_widget,
7048 /* in bin_window coordinates */
7054 PsppSheetViewChild *child;
7056 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7057 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7059 child = g_slice_new (PsppSheetViewChild);
7061 child->widget = child_widget;
7064 child->width = width;
7065 child->height = height;
7067 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7069 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7070 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7072 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7076 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7078 /* in tree coordinates */
7084 PsppSheetViewChild *child = NULL;
7086 GdkRectangle allocation;
7088 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7089 g_return_if_fail (GTK_IS_WIDGET (widget));
7091 for (list = tree_view->priv->children; list; list = list->next)
7093 if (((PsppSheetViewChild *)list->data)->widget == widget)
7102 allocation.x = child->x = x;
7103 allocation.y = child->y = y;
7104 allocation.width = child->width = width;
7105 allocation.height = child->height = height;
7107 if (gtk_widget_get_realized (widget))
7108 gtk_widget_size_allocate (widget, &allocation);
7112 /* TreeModel Callbacks
7116 pspp_sheet_view_row_changed (GtkTreeModel *model,
7121 PsppSheetView *tree_view = (PsppSheetView *)data;
7123 gboolean free_path = FALSE;
7124 GtkTreePath *cursor_path;
7126 g_return_if_fail (path != NULL || iter != NULL);
7128 if (tree_view->priv->cursor != NULL)
7129 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7133 if (tree_view->priv->edited_column &&
7134 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7135 pspp_sheet_view_stop_editing (tree_view, TRUE);
7137 if (cursor_path != NULL)
7138 gtk_tree_path_free (cursor_path);
7142 path = gtk_tree_model_get_path (model, iter);
7145 else if (iter == NULL)
7146 gtk_tree_model_get_iter (model, iter, path);
7148 _pspp_sheet_view_find_node (tree_view,
7154 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7155 pspp_sheet_view_node_queue_redraw (tree_view, node);
7159 gtk_tree_path_free (path);
7163 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7168 PsppSheetView *tree_view = (PsppSheetView *) data;
7171 gint height = tree_view->priv->fixed_height;
7172 gboolean free_path = FALSE;
7173 gboolean node_visible = TRUE;
7175 g_return_if_fail (path != NULL || iter != NULL);
7179 path = gtk_tree_model_get_path (model, iter);
7182 else if (iter == NULL)
7183 gtk_tree_model_get_iter (model, iter, path);
7185 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7187 /* Update all row-references */
7188 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7189 indices = gtk_tree_path_get_indices (path);
7190 tmpnode = indices[0];
7192 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7196 if (node_visible && node_is_visible (tree_view, tmpnode))
7197 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7199 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7202 install_presize_handler (tree_view);
7204 gtk_tree_path_free (path);
7208 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7212 PsppSheetView *tree_view = (PsppSheetView *)data;
7215 g_return_if_fail (path != NULL);
7217 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7219 _pspp_sheet_view_find_node (tree_view, path, &node);
7224 range_tower_delete (tree_view->priv->selected, node, 1);
7226 /* Ensure we don't have a dangling pointer to a dead node */
7227 ensure_unprelighted (tree_view);
7229 /* Cancel editting if we've started */
7230 pspp_sheet_view_stop_editing (tree_view, TRUE);
7232 if (tree_view->priv->destroy_count_func)
7234 gint child_count = 0;
7235 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7238 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7240 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7242 gtk_tree_row_reference_free (tree_view->priv->top_row);
7243 tree_view->priv->top_row = NULL;
7246 install_scroll_sync_handler (tree_view);
7248 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7251 if (helper_data.changed)
7252 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7257 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7258 GtkTreePath *parent,
7263 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7266 /* XXX need to adjust selection */
7267 len = gtk_tree_model_iter_n_children (model, iter);
7272 gtk_tree_row_reference_reordered (G_OBJECT (data),
7277 if (gtk_tree_path_get_depth (parent) != 0)
7280 if (tree_view->priv->edited_column)
7281 pspp_sheet_view_stop_editing (tree_view, TRUE);
7283 /* we need to be unprelighted */
7284 ensure_unprelighted (tree_view);
7286 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7288 pspp_sheet_view_dy_to_top_row (tree_view);
7292 /* Internal tree functions
7297 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7298 PsppSheetViewColumn *column,
7302 PsppSheetViewColumn *tmp_column = NULL;
7313 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7316 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7318 list = (rtl ? list->prev : list->next))
7320 tmp_column = list->data;
7322 if (tmp_column == column)
7325 if (tmp_column->visible)
7326 total_width += tmp_column->width;
7329 if (tmp_column != column)
7331 g_warning (G_STRLOC": passed-in column isn't in the tree");
7340 if (column->visible)
7341 *x2 = total_width + column->width;
7343 *x2 = total_width; /* width of 0 */
7347 /* Make sure the node is visible vertically */
7349 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7352 gint node_dy, height;
7353 GtkTreePath *path = NULL;
7355 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7358 /* just return if the node is visible, avoiding a costly expose */
7359 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7360 height = ROW_HEIGHT (tree_view);
7361 if (node_dy >= tree_view->priv->vadjustment->value
7362 && node_dy + height <= (tree_view->priv->vadjustment->value
7363 + tree_view->priv->vadjustment->page_size))
7366 path = _pspp_sheet_view_find_path (tree_view, node);
7369 /* We process updates because we want to clear old selected items when we scroll.
7370 * if this is removed, we get a "selection streak" at the bottom. */
7371 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7372 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7373 gtk_tree_path_free (path);
7378 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7379 PsppSheetViewColumn *column,
7380 gboolean focus_to_cell)
7387 x = column->allocation.x;
7388 width = column->allocation.width;
7390 if (width > tree_view->priv->hadjustment->page_size)
7392 /* The column is larger than the horizontal page size. If the
7393 * column has cells which can be focussed individually, then we make
7394 * sure the cell which gets focus is fully visible (if even the
7395 * focus cell is bigger than the page size, we make sure the
7396 * left-hand side of the cell is visible).
7398 * If the column does not have those so-called special cells, we
7399 * make sure the left-hand side of the column is visible.
7402 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7404 GtkTreePath *cursor_path;
7405 GdkRectangle background_area, cell_area, focus_area;
7407 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7409 pspp_sheet_view_get_cell_area (tree_view,
7410 cursor_path, column, &cell_area);
7411 pspp_sheet_view_get_background_area (tree_view,
7412 cursor_path, column,
7415 gtk_tree_path_free (cursor_path);
7417 _pspp_sheet_view_column_get_focus_area (column,
7423 width = focus_area.width;
7425 if (width < tree_view->priv->hadjustment->page_size)
7427 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7428 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7429 x + width - tree_view->priv->hadjustment->page_size);
7430 else if (tree_view->priv->hadjustment->value > x)
7431 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7435 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7437 tree_view->priv->hadjustment->lower,
7438 tree_view->priv->hadjustment->upper
7439 - tree_view->priv->hadjustment->page_size));
7443 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7444 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7445 x + width - tree_view->priv->hadjustment->page_size);
7446 else if (tree_view->priv->hadjustment->value > x)
7447 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7452 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7457 path = gtk_tree_path_new ();
7459 gtk_tree_path_append_index (path, node);
7464 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7468 gint *indices = gtk_tree_path_get_indices (path);
7469 gint depth = gtk_tree_path_get_depth (path);
7472 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7478 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7481 gboolean add_shifted_binding,
7482 GtkMovementStep step,
7486 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7491 if (add_shifted_binding)
7492 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7497 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7500 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7505 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7512 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7513 PsppSheetViewColumn *column)
7515 PsppSheetViewColumn *left_column;
7516 PsppSheetViewColumn *cur_column = NULL;
7517 PsppSheetViewColumnReorder *reorder;
7522 /* We want to precalculate the motion list such that we know what column slots
7526 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7528 /* First, identify all possible drop spots */
7530 tmp_list = g_list_last (tree_view->priv->columns);
7532 tmp_list = g_list_first (tree_view->priv->columns);
7536 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7537 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7539 if (cur_column->visible == FALSE)
7542 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7543 if (left_column != column && cur_column != column &&
7544 tree_view->priv->column_drop_func &&
7545 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7547 left_column = cur_column;
7550 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7551 reorder->left_column = left_column;
7552 left_column = reorder->right_column = cur_column;
7554 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7557 /* Add the last one */
7558 if (tree_view->priv->column_drop_func == NULL ||
7559 ((left_column != column) &&
7560 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7562 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7563 reorder->left_column = left_column;
7564 reorder->right_column = NULL;
7565 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7568 /* We quickly check to see if it even makes sense to reorder columns. */
7569 /* If there is nothing that can be moved, then we return */
7571 if (tree_view->priv->column_drag_info == NULL)
7574 /* We know there are always 2 slots possbile, as you can always return column. */
7575 /* If that's all there is, return */
7576 if (tree_view->priv->column_drag_info->next == NULL ||
7577 (tree_view->priv->column_drag_info->next->next == NULL &&
7578 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7579 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7581 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7582 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7583 g_list_free (tree_view->priv->column_drag_info);
7584 tree_view->priv->column_drag_info = NULL;
7587 /* We fill in the ranges for the columns, now that we've isolated them */
7588 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7590 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7592 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7594 reorder->left_align = left;
7595 if (tmp_list->next != NULL)
7597 g_assert (tmp_list->next->data);
7598 left = reorder->right_align = (reorder->right_column->allocation.x +
7599 reorder->right_column->allocation.width +
7600 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7606 gdk_drawable_get_size (tree_view->priv->header_window, &width, NULL);
7607 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7613 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7614 PsppSheetViewColumn *column)
7616 GdkEvent *send_event;
7617 GtkAllocation allocation;
7618 gint x, y, width, height;
7619 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7620 GdkDisplay *display = gdk_screen_get_display (screen);
7622 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7623 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7624 g_return_if_fail (column->button);
7626 pspp_sheet_view_set_column_drag_info (tree_view, column);
7628 if (tree_view->priv->column_drag_info == NULL)
7631 if (tree_view->priv->drag_window == NULL)
7633 GdkWindowAttr attributes;
7634 guint attributes_mask;
7636 attributes.window_type = GDK_WINDOW_CHILD;
7637 attributes.wclass = GDK_INPUT_OUTPUT;
7638 attributes.x = column->allocation.x;
7640 attributes.width = column->allocation.width;
7641 attributes.height = column->allocation.height;
7642 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7643 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
7644 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7645 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
7647 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7650 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7653 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7654 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7656 gtk_grab_remove (column->button);
7658 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7659 send_event->crossing.send_event = TRUE;
7660 send_event->crossing.window = g_object_ref (GTK_BUTTON (column->button)->event_window);
7661 send_event->crossing.subwindow = NULL;
7662 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7663 send_event->crossing.time = GDK_CURRENT_TIME;
7665 gtk_propagate_event (column->button, send_event);
7666 gdk_event_free (send_event);
7668 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7669 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7670 send_event->button.send_event = TRUE;
7671 send_event->button.time = GDK_CURRENT_TIME;
7672 send_event->button.x = -1;
7673 send_event->button.y = -1;
7674 send_event->button.axes = NULL;
7675 send_event->button.state = 0;
7676 send_event->button.button = 1;
7677 send_event->button.device = gdk_display_get_core_pointer (display);
7678 send_event->button.x_root = 0;
7679 send_event->button.y_root = 0;
7681 gtk_propagate_event (column->button, send_event);
7682 gdk_event_free (send_event);
7684 /* Kids, don't try this at home */
7685 g_object_ref (column->button);
7686 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7687 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7688 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7689 g_object_unref (column->button);
7691 tree_view->priv->drag_column_x = column->allocation.x;
7692 allocation = column->allocation;
7694 gtk_widget_size_allocate (column->button, &allocation);
7695 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7697 tree_view->priv->drag_column = column;
7698 gdk_window_show (tree_view->priv->drag_window);
7700 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7701 gdk_drawable_get_size (tree_view->priv->header_window, &width, &height);
7703 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7704 while (gtk_events_pending ())
7705 gtk_main_iteration ();
7707 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7708 gdk_pointer_grab (tree_view->priv->drag_window,
7710 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7711 NULL, NULL, GDK_CURRENT_TIME);
7712 gdk_keyboard_grab (tree_view->priv->drag_window,
7718 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7720 const GdkRectangle *clip_rect)
7724 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7728 rect.width = MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width);
7730 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7731 rect.height = ROW_HEIGHT (tree_view);
7735 GdkRectangle new_rect;
7737 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7739 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7743 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7748 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7750 const GdkRectangle *clip_rect)
7754 _pspp_sheet_view_find_node (tree_view, path, &node);
7757 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7761 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7764 GtkTreePath *cursor_path;
7766 if ((tree_view->priv->row_count == 0) ||
7767 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7771 if (tree_view->priv->cursor)
7772 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7774 if (cursor_path == NULL)
7776 /* There's no cursor. Move the cursor to the first selected row, if any
7777 * are selected, otherwise to the first row in the sheetview.
7779 GList *selected_rows;
7780 GtkTreeModel *model;
7781 PsppSheetSelection *selection;
7783 selection = pspp_sheet_view_get_selection (tree_view);
7784 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7788 /* XXX we could avoid doing O(n) work to get this result */
7789 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7790 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7791 g_list_free (selected_rows);
7795 cursor_path = gtk_tree_path_new_first ();
7796 search_first_focusable_path (tree_view, &cursor_path,
7800 gtk_tree_row_reference_free (tree_view->priv->cursor);
7801 tree_view->priv->cursor = NULL;
7805 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7806 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7807 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE, 0);
7809 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, 0);
7815 /* Now find a column for the cursor. */
7816 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7818 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7819 gtk_tree_path_free (cursor_path);
7821 if (tree_view->priv->focus_column == NULL)
7824 for (list = tree_view->priv->columns; list; list = list->next)
7826 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7828 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7829 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7830 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7840 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7842 PsppSheetSelectMode mode)
7844 gint selection_count;
7845 int cursor_node = -1;
7846 int new_cursor_node = -1;
7847 GtkTreePath *cursor_path = NULL;
7848 gboolean grab_focus = TRUE;
7850 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7854 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7855 /* FIXME: we lost the cursor; should we get the first? */
7858 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7859 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7861 if (cursor_node < 0)
7862 /* FIXME: we lost the cursor; should we get the first? */
7865 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7867 if (selection_count == 0
7868 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7869 && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
7871 /* Don't move the cursor, but just select the current node */
7872 new_cursor_node = cursor_node;
7877 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7879 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7882 gtk_tree_path_free (cursor_path);
7884 if (new_cursor_node)
7886 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7888 search_first_focusable_path (tree_view, &cursor_path,
7893 gtk_tree_path_free (cursor_path);
7897 * If the list has only one item and multi-selection is set then select
7898 * the row (if not yet selected).
7900 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7901 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7902 new_cursor_node < 0)
7905 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7907 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7909 if (new_cursor_node < 0
7910 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7912 new_cursor_node = cursor_node;
7916 new_cursor_node = -1;
7920 if (new_cursor_node >= 0)
7922 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7923 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE, mode);
7924 gtk_tree_path_free (cursor_path);
7928 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7930 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
7932 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7934 GTK_DIR_UP : GTK_DIR_DOWN))
7936 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
7939 gtk_widget_child_focus (toplevel,
7941 GTK_DIR_TAB_BACKWARD :
7942 GTK_DIR_TAB_FORWARD);
7949 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7954 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7956 return new_cursor_node >= 0;
7960 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
7962 PsppSheetSelectMode mode)
7964 int cursor_node = -1;
7965 GtkTreePath *old_cursor_path = NULL;
7966 GtkTreePath *cursor_path = NULL;
7967 int start_cursor_node = -1;
7970 gint vertical_separator;
7972 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7975 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
7976 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7978 /* This is sorta weird. Focus in should give us a cursor */
7981 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
7982 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
7984 if (cursor_node < 0)
7986 /* FIXME: we lost the cursor. Should we try to get one? */
7987 gtk_tree_path_free (old_cursor_path);
7991 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7992 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
7993 y += tree_view->priv->cursor_offset;
7994 y += count * (int)tree_view->priv->vadjustment->page_increment;
7995 y = CLAMP (y, (gint)tree_view->priv->vadjustment->lower, (gint)tree_view->priv->vadjustment->upper - vertical_separator);
7997 if (y >= tree_view->priv->height)
7998 y = tree_view->priv->height - 1;
8000 tree_view->priv->cursor_offset =
8001 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
8003 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
8005 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
8006 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
8009 y -= tree_view->priv->cursor_offset;
8010 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8012 start_cursor_node = cursor_node;
8014 if (! search_first_focusable_path (tree_view, &cursor_path,
8018 /* It looks like we reached the end of the view without finding
8019 * a focusable row. We will step backwards to find the last
8022 cursor_node = start_cursor_node;
8023 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8025 search_first_focusable_path (tree_view, &cursor_path,
8034 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8036 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, mode);
8039 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
8040 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8041 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8043 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
8044 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8046 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8049 gtk_tree_path_free (old_cursor_path);
8050 gtk_tree_path_free (cursor_path);
8054 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
8056 PsppSheetSelectMode mode)
8058 int cursor_node = -1;
8059 GtkTreePath *cursor_path = NULL;
8060 PsppSheetViewColumn *column;
8063 gboolean found_column = FALSE;
8066 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8068 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8071 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8072 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8076 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8077 if (cursor_node < 0)
8079 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8081 gtk_tree_path_free (cursor_path);
8084 gtk_tree_path_free (cursor_path);
8086 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8087 if (tree_view->priv->focus_column)
8089 for (; list; list = (rtl ? list->prev : list->next))
8091 if (list->data == tree_view->priv->focus_column)
8098 gboolean left, right;
8100 column = list->data;
8101 if (column->visible == FALSE || column->row_head)
8104 pspp_sheet_view_column_cell_set_cell_data (column,
8105 tree_view->priv->model,
8110 right = list->prev ? TRUE : FALSE;
8111 left = list->next ? TRUE : FALSE;
8115 left = list->prev ? TRUE : FALSE;
8116 right = list->next ? TRUE : FALSE;
8119 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8121 tree_view->priv->focus_column = column;
8122 found_column = TRUE;
8127 list = rtl ? list->prev : list->next;
8129 list = rtl ? list->next : list->prev;
8134 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8135 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8136 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8140 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8143 pspp_sheet_view_clamp_column_visible (tree_view,
8144 tree_view->priv->focus_column, TRUE);
8148 pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
8150 PsppSheetSelectMode mode)
8152 int cursor_node = -1;
8153 GtkTreePath *cursor_path = NULL;
8154 PsppSheetViewColumn *column;
8155 PsppSheetViewColumn *found_column;
8160 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8162 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8165 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8166 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8170 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8171 if (cursor_node < 0)
8173 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8175 gtk_tree_path_free (cursor_path);
8178 gtk_tree_path_free (cursor_path);
8180 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8181 if (tree_view->priv->focus_column)
8183 for (; list; list = (rtl ? list->prev : list->next))
8185 if (list->data == tree_view->priv->focus_column)
8190 found_column = NULL;
8193 gboolean left, right;
8195 column = list->data;
8196 if (column->visible == FALSE || column->row_head)
8199 pspp_sheet_view_column_cell_set_cell_data (column,
8200 tree_view->priv->model,
8205 right = list->prev ? TRUE : FALSE;
8206 left = list->next ? TRUE : FALSE;
8210 left = list->prev ? TRUE : FALSE;
8211 right = list->next ? TRUE : FALSE;
8214 if (column->tabbable
8215 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8216 found_column = column;
8220 list = rtl ? list->prev : list->next;
8222 list = rtl ? list->next : list->prev;
8227 tree_view->priv->focus_column = found_column;
8228 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8229 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8230 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8233 pspp_sheet_view_clamp_column_visible (tree_view,
8234 tree_view->priv->focus_column, TRUE);
8238 try_move_cursor_tab (PsppSheetView *tree_view,
8239 gboolean start_at_focus_column,
8242 PsppSheetViewColumn *column;
8244 int cursor_node = -1;
8245 GtkTreePath *cursor_path = NULL;
8249 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8250 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8254 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8255 if (cursor_node < 0)
8257 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8259 gtk_tree_path_free (cursor_path);
8262 gtk_tree_path_free (cursor_path);
8264 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
8265 if (start_at_focus_column)
8268 ? g_list_last (tree_view->priv->columns)
8269 : g_list_first (tree_view->priv->columns));
8270 if (tree_view->priv->focus_column)
8272 for (; list; list = (rtl ? list->prev : list->next))
8274 if (list->data == tree_view->priv->focus_column)
8281 list = (rtl ^ (count == 1)
8282 ? g_list_first (tree_view->priv->columns)
8283 : g_list_last (tree_view->priv->columns));
8288 gboolean left, right;
8290 column = list->data;
8291 if (column->visible == FALSE || !column->tabbable)
8294 pspp_sheet_view_column_cell_set_cell_data (column,
8295 tree_view->priv->model,
8300 right = list->prev ? TRUE : FALSE;
8301 left = list->next ? TRUE : FALSE;
8305 left = list->prev ? TRUE : FALSE;
8306 right = list->next ? TRUE : FALSE;
8309 if (column->tabbable
8310 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8312 tree_view->priv->focus_column = column;
8313 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8314 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8315 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8320 list = rtl ? list->prev : list->next;
8322 list = rtl ? list->next : list->prev;
8329 pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
8332 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8335 if (!try_move_cursor_tab (tree_view, TRUE, count))
8337 if (pspp_sheet_view_move_cursor_up_down (tree_view, count, 0)
8338 && !try_move_cursor_tab (tree_view, FALSE, count))
8339 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8342 pspp_sheet_view_clamp_column_visible (tree_view,
8343 tree_view->priv->focus_column, TRUE);
8347 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8349 PsppSheetSelectMode mode)
8353 GtkTreePath *old_path;
8355 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8358 g_return_if_fail (tree_view->priv->row_count > 0);
8360 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8364 /* Now go forward to find the first focusable row. */
8365 path = _pspp_sheet_view_find_path (tree_view, 0);
8366 search_first_focusable_path (tree_view, &path,
8367 TRUE, &cursor_node);
8371 /* Now go backwards to find last focusable row. */
8372 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8373 search_first_focusable_path (tree_view, &path,
8374 FALSE, &cursor_node);
8380 if (gtk_tree_path_compare (old_path, path))
8382 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
8383 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8387 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8391 gtk_tree_path_free (old_path);
8392 gtk_tree_path_free (path);
8396 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8398 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8401 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8402 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8405 pspp_sheet_selection_select_all (tree_view->priv->selection);
8411 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8413 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8416 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8417 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8420 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8426 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8427 gboolean start_editing,
8428 PsppSheetSelectMode mode)
8431 int cursor_node = -1;
8432 GtkTreePath *cursor_path = NULL;
8434 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8437 if (tree_view->priv->cursor)
8438 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8440 if (cursor_path == NULL)
8443 _pspp_sheet_view_find_node (tree_view, cursor_path,
8446 if (cursor_node < 0)
8448 gtk_tree_path_free (cursor_path);
8452 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND) && start_editing &&
8453 tree_view->priv->focus_column)
8455 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8457 gtk_tree_path_free (cursor_path);
8462 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8468 /* We bail out if the original (tree, node) don't exist anymore after
8469 * handling the selection-changed callback. We do return TRUE because
8470 * the key press has been handled at this point.
8472 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8474 if (cursor_node != new_node)
8477 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8479 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8480 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8482 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
8483 pspp_sheet_view_row_activated (tree_view, cursor_path,
8484 tree_view->priv->focus_column);
8486 gtk_tree_path_free (cursor_path);
8492 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8495 int cursor_node = -1;
8496 GtkTreePath *cursor_path = NULL;
8498 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8502 if (tree_view->priv->cursor)
8503 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8505 if (cursor_path == NULL)
8508 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8509 if (cursor_node < 0)
8511 gtk_tree_path_free (cursor_path);
8515 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8518 PSPP_SHEET_SELECT_MODE_TOGGLE,
8521 /* We bail out if the original (tree, node) don't exist anymore after
8522 * handling the selection-changed callback. We do return TRUE because
8523 * the key press has been handled at this point.
8525 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8527 if (cursor_node != new_node)
8530 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8532 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8533 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8534 gtk_tree_path_free (cursor_path);
8540 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8542 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8543 tree_view->priv->typeselect_flush_timeout = 0;
8548 /* Cut and paste from gtkwindow.c */
8550 send_focus_change (GtkWidget *widget,
8553 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8555 g_object_ref (widget);
8558 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
8560 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
8562 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8563 fevent->focus_change.window = g_object_ref (widget->window);
8564 fevent->focus_change.in = in;
8566 gtk_widget_event (widget, fevent);
8568 g_object_notify (G_OBJECT (widget), "has-focus");
8570 g_object_unref (widget);
8571 gdk_event_free (fevent);
8575 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8577 GtkWidget *frame, *vbox, *toplevel;
8580 if (tree_view->priv->search_custom_entry_set)
8583 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8584 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8586 if (tree_view->priv->search_window != NULL)
8588 if (GTK_WINDOW (toplevel)->group)
8589 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8590 GTK_WINDOW (tree_view->priv->search_window));
8591 else if (GTK_WINDOW (tree_view->priv->search_window)->group)
8592 gtk_window_group_remove_window (GTK_WINDOW (tree_view->priv->search_window)->group,
8593 GTK_WINDOW (tree_view->priv->search_window));
8594 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8598 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8599 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8601 if (GTK_WINDOW (toplevel)->group)
8602 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8603 GTK_WINDOW (tree_view->priv->search_window));
8605 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8606 GDK_WINDOW_TYPE_HINT_UTILITY);
8607 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8608 g_signal_connect (tree_view->priv->search_window, "delete-event",
8609 G_CALLBACK (pspp_sheet_view_search_delete_event),
8611 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8612 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8614 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8615 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8617 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8618 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8621 frame = gtk_frame_new (NULL);
8622 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8623 gtk_widget_show (frame);
8624 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8626 vbox = gtk_vbox_new (FALSE, 0);
8627 gtk_widget_show (vbox);
8628 gtk_container_add (GTK_CONTAINER (frame), vbox);
8629 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8632 tree_view->priv->search_entry = gtk_entry_new ();
8633 gtk_widget_show (tree_view->priv->search_entry);
8634 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8635 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8637 g_signal_connect (tree_view->priv->search_entry,
8638 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8640 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8642 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8644 gtk_container_add (GTK_CONTAINER (vbox),
8645 tree_view->priv->search_entry);
8647 gtk_widget_realize (tree_view->priv->search_entry);
8650 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8651 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8654 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8655 gboolean keybinding)
8657 /* We only start interactive search if we have focus or the columns
8658 * have focus. If one of our children have focus, we don't want to
8662 gboolean found_focus = FALSE;
8663 GtkWidgetClass *entry_parent_class;
8665 if (!tree_view->priv->enable_search && !keybinding)
8668 if (tree_view->priv->search_custom_entry_set)
8671 if (tree_view->priv->search_window != NULL &&
8672 gtk_widget_get_visible (tree_view->priv->search_window))
8675 for (list = tree_view->priv->columns; list; list = list->next)
8677 PsppSheetViewColumn *column;
8679 column = list->data;
8680 if (! column->visible)
8683 if (column->button && gtk_widget_has_focus (column->button))
8690 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8696 if (tree_view->priv->search_column < 0)
8699 pspp_sheet_view_ensure_interactive_directory (tree_view);
8702 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8705 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8706 gtk_widget_show (tree_view->priv->search_window);
8707 if (tree_view->priv->search_entry_changed_id == 0)
8709 tree_view->priv->search_entry_changed_id =
8710 g_signal_connect (tree_view->priv->search_entry, "changed",
8711 G_CALLBACK (pspp_sheet_view_search_init),
8715 tree_view->priv->typeselect_flush_timeout =
8716 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8717 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8720 /* Grab focus will select all the text. We don't want that to happen, so we
8721 * call the parent instance and bypass the selection change. This is probably
8722 * really non-kosher. */
8723 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8724 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8726 /* send focus-in event */
8727 send_focus_change (tree_view->priv->search_entry, TRUE);
8729 /* search first matching iter */
8730 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8736 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8738 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8741 /* this function returns the new width of the column being resized given
8742 * the column and x position of the cursor; the x cursor position is passed
8743 * in as a pointer and automagicly corrected if it's beyond min/max limits
8746 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8750 PsppSheetViewColumn *column;
8754 /* first translate the x position from widget->window
8755 * to clist->clist_window
8757 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8758 column = g_list_nth (tree_view->priv->columns, i)->data;
8759 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8761 /* Clamp down the value */
8762 if (column->min_width == -1)
8763 width = MAX (column->button_request, width);
8765 width = MAX (column->min_width, width);
8766 if (column->max_width != -1)
8767 width = MIN (width, column->max_width);
8769 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8775 /* FIXME this adjust_allocation is a big cut-and-paste from
8776 * GtkCList, needs to be some "official" way to do this
8786 /* The window to which widget->window is relative */
8787 #define ALLOCATION_WINDOW(widget) \
8788 (!gtk_widget_get_has_window (widget) ? \
8789 (widget)->window : \
8790 gdk_window_get_parent ((widget)->window))
8793 adjust_allocation_recurse (GtkWidget *widget,
8796 ScrollData *scroll_data = data;
8798 /* Need to really size allocate instead of just poking
8799 * into widget->allocation if the widget is not realized.
8800 * FIXME someone figure out why this was.
8802 if (!gtk_widget_get_realized (widget))
8804 if (gtk_widget_get_visible (widget))
8806 GdkRectangle tmp_rectangle = widget->allocation;
8807 tmp_rectangle.x += scroll_data->dx;
8808 tmp_rectangle.y += scroll_data->dy;
8810 gtk_widget_size_allocate (widget, &tmp_rectangle);
8815 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8817 widget->allocation.x += scroll_data->dx;
8818 widget->allocation.y += scroll_data->dy;
8820 if (GTK_IS_CONTAINER (widget))
8821 gtk_container_forall (GTK_CONTAINER (widget),
8822 adjust_allocation_recurse,
8829 adjust_allocation (GtkWidget *widget,
8833 ScrollData scroll_data;
8835 if (gtk_widget_get_realized (widget))
8836 scroll_data.window = ALLOCATION_WINDOW (widget);
8838 scroll_data.window = NULL;
8840 scroll_data.dx = dx;
8841 scroll_data.dy = dy;
8843 adjust_allocation_recurse (widget, &scroll_data);
8847 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8851 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8852 PsppSheetView *tree_view)
8854 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8859 gdk_window_move (tree_view->priv->bin_window,
8860 - tree_view->priv->hadjustment->value,
8861 TREE_VIEW_HEADER_HEIGHT (tree_view));
8862 gdk_window_move (tree_view->priv->header_window,
8863 - tree_view->priv->hadjustment->value,
8865 dy = tree_view->priv->dy - (int) tree_view->priv->vadjustment->value;
8868 update_prelight (tree_view,
8869 tree_view->priv->event_last_x,
8870 tree_view->priv->event_last_y - dy);
8872 if (tree_view->priv->edited_column &&
8873 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8877 PsppSheetViewChild *child = NULL;
8879 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8880 adjust_allocation (widget, 0, dy);
8882 for (list = tree_view->priv->children; list; list = list->next)
8884 child = (PsppSheetViewChild *)list->data;
8885 if (child->widget == widget)
8893 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8895 if (tree_view->priv->dy != (int) tree_view->priv->vadjustment->value)
8897 /* update our dy and top_row */
8898 tree_view->priv->dy = (int) tree_view->priv->vadjustment->value;
8900 if (!tree_view->priv->in_top_row_to_dy)
8901 pspp_sheet_view_dy_to_top_row (tree_view);
8904 for (list = tree_view->priv->columns; list; list = list->next)
8906 PsppSheetViewColumn *column = list->data;
8907 GtkAllocation *allocation = &column->allocation;
8909 if (span_intersects (allocation->x, allocation->width,
8910 tree_view->priv->hadjustment->value,
8911 GTK_WIDGET (tree_view)->allocation.width))
8913 pspp_sheet_view_column_set_need_button (column, TRUE);
8914 if (!column->button)
8915 pspp_sheet_view_column_update_button (column);
8927 * pspp_sheet_view_new:
8929 * Creates a new #PsppSheetView widget.
8931 * Return value: A newly created #PsppSheetView widget.
8934 pspp_sheet_view_new (void)
8936 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8940 * pspp_sheet_view_new_with_model:
8941 * @model: the model.
8943 * Creates a new #PsppSheetView widget with the model initialized to @model.
8945 * Return value: A newly created #PsppSheetView widget.
8948 pspp_sheet_view_new_with_model (GtkTreeModel *model)
8950 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
8957 * pspp_sheet_view_get_model:
8958 * @tree_view: a #PsppSheetView
8960 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
8963 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
8966 pspp_sheet_view_get_model (PsppSheetView *tree_view)
8968 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8970 return tree_view->priv->model;
8974 * pspp_sheet_view_set_model:
8975 * @tree_view: A #GtkTreeNode.
8976 * @model: (allow-none): The model.
8978 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
8979 * set, it will remove it before setting the new model. If @model is %NULL,
8980 * then it will unset the old model.
8983 pspp_sheet_view_set_model (PsppSheetView *tree_view,
8984 GtkTreeModel *model)
8986 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8987 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
8989 if (model == tree_view->priv->model)
8992 if (tree_view->priv->scroll_to_path)
8994 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8995 tree_view->priv->scroll_to_path = NULL;
8998 if (tree_view->priv->model)
9000 GList *tmplist = tree_view->priv->columns;
9002 if (tree_view->priv->selected)
9003 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
9004 pspp_sheet_view_stop_editing (tree_view, TRUE);
9006 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9007 pspp_sheet_view_row_changed,
9009 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9010 pspp_sheet_view_row_inserted,
9012 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9013 pspp_sheet_view_row_deleted,
9015 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9016 pspp_sheet_view_rows_reordered,
9019 for (; tmplist; tmplist = tmplist->next)
9020 _pspp_sheet_view_column_unset_model (tmplist->data,
9021 tree_view->priv->model);
9023 tree_view->priv->prelight_node = -1;
9025 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
9026 tree_view->priv->drag_dest_row = NULL;
9027 gtk_tree_row_reference_free (tree_view->priv->cursor);
9028 tree_view->priv->cursor = NULL;
9029 gtk_tree_row_reference_free (tree_view->priv->anchor);
9030 tree_view->priv->anchor = NULL;
9031 gtk_tree_row_reference_free (tree_view->priv->top_row);
9032 tree_view->priv->top_row = NULL;
9033 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9034 tree_view->priv->scroll_to_path = NULL;
9036 tree_view->priv->scroll_to_column = NULL;
9038 g_object_unref (tree_view->priv->model);
9040 tree_view->priv->search_column = -1;
9041 tree_view->priv->fixed_height = -1;
9042 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
9043 tree_view->priv->last_button_x = -1;
9044 tree_view->priv->last_button_y = -1;
9047 tree_view->priv->model = model;
9049 if (tree_view->priv->model)
9053 if (tree_view->priv->search_column == -1)
9055 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
9057 GType type = gtk_tree_model_get_column_type (model, i);
9059 if (g_value_type_transformable (type, G_TYPE_STRING))
9061 tree_view->priv->search_column = i;
9067 g_object_ref (tree_view->priv->model);
9068 g_signal_connect (tree_view->priv->model,
9070 G_CALLBACK (pspp_sheet_view_row_changed),
9072 g_signal_connect (tree_view->priv->model,
9074 G_CALLBACK (pspp_sheet_view_row_inserted),
9076 g_signal_connect (tree_view->priv->model,
9078 G_CALLBACK (pspp_sheet_view_row_deleted),
9080 g_signal_connect (tree_view->priv->model,
9082 G_CALLBACK (pspp_sheet_view_rows_reordered),
9085 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
9087 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
9088 install_presize_handler (tree_view);
9091 g_object_notify (G_OBJECT (tree_view), "model");
9093 if (tree_view->priv->selection)
9094 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
9096 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9097 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9101 * pspp_sheet_view_get_selection:
9102 * @tree_view: A #PsppSheetView.
9104 * Gets the #PsppSheetSelection associated with @tree_view.
9106 * Return value: A #PsppSheetSelection object.
9108 PsppSheetSelection *
9109 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
9111 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9113 return tree_view->priv->selection;
9117 * pspp_sheet_view_get_hadjustment:
9118 * @tree_view: A #PsppSheetView
9120 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
9122 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9126 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
9128 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9130 if (tree_view->priv->hadjustment == NULL)
9131 pspp_sheet_view_set_hadjustment (tree_view, NULL);
9133 return tree_view->priv->hadjustment;
9137 * pspp_sheet_view_set_hadjustment:
9138 * @tree_view: A #PsppSheetView
9139 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9141 * Sets the #GtkAdjustment for the current horizontal aspect.
9144 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
9145 GtkAdjustment *adjustment)
9147 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9149 pspp_sheet_view_set_adjustments (tree_view,
9151 tree_view->priv->vadjustment);
9153 g_object_notify (G_OBJECT (tree_view), "hadjustment");
9157 * pspp_sheet_view_get_vadjustment:
9158 * @tree_view: A #PsppSheetView
9160 * Gets the #GtkAdjustment currently being used for the vertical aspect.
9162 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9166 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
9168 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9170 if (tree_view->priv->vadjustment == NULL)
9171 pspp_sheet_view_set_vadjustment (tree_view, NULL);
9173 return tree_view->priv->vadjustment;
9177 * pspp_sheet_view_set_vadjustment:
9178 * @tree_view: A #PsppSheetView
9179 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9181 * Sets the #GtkAdjustment for the current vertical aspect.
9184 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
9185 GtkAdjustment *adjustment)
9187 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9189 pspp_sheet_view_set_adjustments (tree_view,
9190 tree_view->priv->hadjustment,
9193 g_object_notify (G_OBJECT (tree_view), "vadjustment");
9196 /* Column and header operations */
9199 * pspp_sheet_view_get_headers_visible:
9200 * @tree_view: A #PsppSheetView.
9202 * Returns %TRUE if the headers on the @tree_view are visible.
9204 * Return value: Whether the headers are visible or not.
9207 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
9209 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9211 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9215 * pspp_sheet_view_set_headers_visible:
9216 * @tree_view: A #PsppSheetView.
9217 * @headers_visible: %TRUE if the headers are visible
9219 * Sets the visibility state of the headers.
9222 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
9223 gboolean headers_visible)
9227 PsppSheetViewColumn *column;
9229 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9231 headers_visible = !! headers_visible;
9233 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
9236 if (headers_visible)
9237 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9239 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9241 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9243 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
9244 if (headers_visible)
9246 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));
9248 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9249 pspp_sheet_view_map_buttons (tree_view);
9253 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9255 for (list = tree_view->priv->columns; list; list = list->next)
9257 column = list->data;
9259 gtk_widget_unmap (column->button);
9261 gdk_window_hide (tree_view->priv->header_window);
9265 tree_view->priv->vadjustment->page_size = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
9266 tree_view->priv->vadjustment->page_increment = (GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2;
9267 tree_view->priv->vadjustment->lower = 0;
9268 tree_view->priv->vadjustment->upper = tree_view->priv->height;
9269 gtk_adjustment_changed (tree_view->priv->vadjustment);
9271 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9273 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9277 * pspp_sheet_view_columns_autosize:
9278 * @tree_view: A #PsppSheetView.
9280 * Resizes all columns to their optimal width. Only works after the
9281 * treeview has been realized.
9284 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9286 gboolean dirty = FALSE;
9288 PsppSheetViewColumn *column;
9290 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9292 for (list = tree_view->priv->columns; list; list = list->next)
9294 column = list->data;
9295 _pspp_sheet_view_column_cell_set_dirty (column);
9300 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9304 * pspp_sheet_view_set_headers_clickable:
9305 * @tree_view: A #PsppSheetView.
9306 * @setting: %TRUE if the columns are clickable.
9308 * Allow the column title buttons to be clicked.
9311 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9316 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9318 for (list = tree_view->priv->columns; list; list = list->next)
9319 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9321 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9326 * pspp_sheet_view_get_headers_clickable:
9327 * @tree_view: A #PsppSheetView.
9329 * Returns whether all header columns are clickable.
9331 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9336 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9340 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9342 for (list = tree_view->priv->columns; list; list = list->next)
9343 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9350 * pspp_sheet_view_set_rules_hint
9351 * @tree_view: a #PsppSheetView
9352 * @setting: %TRUE if the tree requires reading across rows
9354 * This function tells GTK+ that the user interface for your
9355 * application requires users to read across tree rows and associate
9356 * cells with one another. By default, GTK+ will then render the tree
9357 * with alternating row colors. Do <emphasis>not</emphasis> use it
9358 * just because you prefer the appearance of the ruled tree; that's a
9359 * question for the theme. Some themes will draw tree rows in
9360 * alternating colors even when rules are turned off, and users who
9361 * prefer that appearance all the time can choose those themes. You
9362 * should call this function only as a <emphasis>semantic</emphasis>
9363 * hint to the theme engine that your tree makes alternating colors
9364 * useful from a functional standpoint (since it has lots of columns,
9369 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9372 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9374 setting = setting != FALSE;
9376 if (tree_view->priv->has_rules != setting)
9378 tree_view->priv->has_rules = setting;
9379 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9382 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9386 * pspp_sheet_view_get_rules_hint
9387 * @tree_view: a #PsppSheetView
9389 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9391 * Return value: %TRUE if rules are useful for the user of this tree
9394 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9396 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9398 return tree_view->priv->has_rules;
9401 /* Public Column functions
9405 * pspp_sheet_view_append_column:
9406 * @tree_view: A #PsppSheetView.
9407 * @column: The #PsppSheetViewColumn to add.
9409 * Appends @column to the list of columns.
9411 * Return value: The number of columns in @tree_view after appending.
9414 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9415 PsppSheetViewColumn *column)
9417 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9418 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9419 g_return_val_if_fail (column->tree_view == NULL, -1);
9421 return pspp_sheet_view_insert_column (tree_view, column, -1);
9426 * pspp_sheet_view_remove_column:
9427 * @tree_view: A #PsppSheetView.
9428 * @column: The #PsppSheetViewColumn to remove.
9430 * Removes @column from @tree_view.
9432 * Return value: The number of columns in @tree_view after removing.
9435 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9436 PsppSheetViewColumn *column)
9438 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9439 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9440 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9442 if (tree_view->priv->focus_column == column)
9443 tree_view->priv->focus_column = NULL;
9445 if (tree_view->priv->edited_column == column)
9447 pspp_sheet_view_stop_editing (tree_view, TRUE);
9449 /* no need to, but just to be sure ... */
9450 tree_view->priv->edited_column = NULL;
9453 _pspp_sheet_view_column_unset_tree_view (column);
9455 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9456 tree_view->priv->n_columns--;
9458 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9462 _pspp_sheet_view_column_unrealize_button (column);
9463 for (list = tree_view->priv->columns; list; list = list->next)
9465 PsppSheetViewColumn *tmp_column;
9467 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9468 if (tmp_column->visible)
9469 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9472 if (tree_view->priv->n_columns == 0 &&
9473 pspp_sheet_view_get_headers_visible (tree_view) &&
9474 tree_view->priv->header_window)
9475 gdk_window_hide (tree_view->priv->header_window);
9477 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9480 g_object_unref (column);
9481 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9483 return tree_view->priv->n_columns;
9487 * pspp_sheet_view_insert_column:
9488 * @tree_view: A #PsppSheetView.
9489 * @column: The #PsppSheetViewColumn to be inserted.
9490 * @position: The position to insert @column in.
9492 * This inserts the @column into the @tree_view at @position. If @position is
9493 * -1, then the column is inserted at the end.
9495 * Return value: The number of columns in @tree_view after insertion.
9498 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9499 PsppSheetViewColumn *column,
9502 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9503 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9504 g_return_val_if_fail (column->tree_view == NULL, -1);
9506 g_object_ref_sink (column);
9508 if (tree_view->priv->n_columns == 0 &&
9509 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9510 pspp_sheet_view_get_headers_visible (tree_view))
9512 gdk_window_show (tree_view->priv->header_window);
9515 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9517 tree_view->priv->n_columns++;
9519 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9521 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9525 _pspp_sheet_view_column_realize_button (column);
9527 for (list = tree_view->priv->columns; list; list = list->next)
9529 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9530 if (column->visible)
9531 _pspp_sheet_view_column_cell_set_dirty (column);
9533 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9536 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9538 return tree_view->priv->n_columns;
9542 * pspp_sheet_view_insert_column_with_attributes:
9543 * @tree_view: A #PsppSheetView
9544 * @position: The position to insert the new column in.
9545 * @title: The title to set the header to.
9546 * @cell: The #GtkCellRenderer.
9547 * @Varargs: A %NULL-terminated list of attributes.
9549 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9550 * @position. If @position is -1, then the newly created column is inserted at
9551 * the end. The column is initialized with the attributes given.
9553 * Return value: The number of columns in @tree_view after insertion.
9556 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9559 GtkCellRenderer *cell,
9562 PsppSheetViewColumn *column;
9567 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9569 column = pspp_sheet_view_column_new ();
9570 pspp_sheet_view_column_set_title (column, title);
9571 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9573 va_start (args, cell);
9575 attribute = va_arg (args, gchar *);
9577 while (attribute != NULL)
9579 column_id = va_arg (args, gint);
9580 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9581 attribute = va_arg (args, gchar *);
9586 pspp_sheet_view_insert_column (tree_view, column, position);
9588 return tree_view->priv->n_columns;
9592 * pspp_sheet_view_insert_column_with_data_func:
9593 * @tree_view: a #PsppSheetView
9594 * @position: Position to insert, -1 for append
9595 * @title: column title
9596 * @cell: cell renderer for column
9597 * @func: function to set attributes of cell renderer
9598 * @data: data for @func
9599 * @dnotify: destroy notifier for @data
9601 * Convenience function that inserts a new column into the #PsppSheetView
9602 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9603 * attributes (normally using data from the model). See also
9604 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9606 * Return value: number of columns in the tree view post-insert
9609 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9612 GtkCellRenderer *cell,
9613 PsppSheetCellDataFunc func,
9615 GDestroyNotify dnotify)
9617 PsppSheetViewColumn *column;
9619 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9621 column = pspp_sheet_view_column_new ();
9622 pspp_sheet_view_column_set_title (column, title);
9623 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9624 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9626 pspp_sheet_view_insert_column (tree_view, column, position);
9628 return tree_view->priv->n_columns;
9632 * pspp_sheet_view_get_column:
9633 * @tree_view: A #PsppSheetView.
9634 * @n: The position of the column, counting from 0.
9636 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9638 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9641 PsppSheetViewColumn *
9642 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9645 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9647 if (n < 0 || n >= tree_view->priv->n_columns)
9650 if (tree_view->priv->columns == NULL)
9653 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9657 * pspp_sheet_view_get_columns:
9658 * @tree_view: A #PsppSheetView
9660 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9661 * The returned list must be freed with g_list_free ().
9663 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9666 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9668 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9670 return g_list_copy (tree_view->priv->columns);
9674 * pspp_sheet_view_move_column_after:
9675 * @tree_view: A #PsppSheetView
9676 * @column: The #PsppSheetViewColumn to be moved.
9677 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9679 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9680 * @column is placed in the first position.
9683 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9684 PsppSheetViewColumn *column,
9685 PsppSheetViewColumn *base_column)
9687 GList *column_list_el, *base_el = NULL;
9689 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9691 column_list_el = g_list_find (tree_view->priv->columns, column);
9692 g_return_if_fail (column_list_el != NULL);
9696 base_el = g_list_find (tree_view->priv->columns, base_column);
9697 g_return_if_fail (base_el != NULL);
9700 if (column_list_el->prev == base_el)
9703 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9704 if (base_el == NULL)
9706 column_list_el->prev = NULL;
9707 column_list_el->next = tree_view->priv->columns;
9708 if (column_list_el->next)
9709 column_list_el->next->prev = column_list_el;
9710 tree_view->priv->columns = column_list_el;
9714 column_list_el->prev = base_el;
9715 column_list_el->next = base_el->next;
9716 if (column_list_el->next)
9717 column_list_el->next->prev = column_list_el;
9718 base_el->next = column_list_el;
9721 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9723 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9724 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9727 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9731 * pspp_sheet_view_set_column_drag_function:
9732 * @tree_view: A #PsppSheetView.
9733 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9734 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9735 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9737 * Sets a user function for determining where a column may be dropped when
9738 * dragged. This function is called on every column pair in turn at the
9739 * beginning of a column drag to determine where a drop can take place. The
9740 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9741 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9742 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9743 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9744 * @tree_view reverts to the default behavior of allowing all columns to be
9745 * dropped everywhere.
9748 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9749 PsppSheetViewColumnDropFunc func,
9751 GDestroyNotify destroy)
9753 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9755 if (tree_view->priv->column_drop_func_data_destroy)
9756 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9758 tree_view->priv->column_drop_func = func;
9759 tree_view->priv->column_drop_func_data = user_data;
9760 tree_view->priv->column_drop_func_data_destroy = destroy;
9764 * pspp_sheet_view_scroll_to_point:
9765 * @tree_view: a #PsppSheetView
9766 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9767 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9769 * Scrolls the tree view such that the top-left corner of the visible
9770 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9771 * in tree coordinates. The @tree_view must be realized before
9772 * this function is called. If it isn't, you probably want to be
9773 * using pspp_sheet_view_scroll_to_cell().
9775 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9778 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9782 GtkAdjustment *hadj;
9783 GtkAdjustment *vadj;
9785 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9786 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9788 hadj = tree_view->priv->hadjustment;
9789 vadj = tree_view->priv->vadjustment;
9792 gtk_adjustment_set_value (hadj, CLAMP (tree_x, hadj->lower, hadj->upper - hadj->page_size));
9794 gtk_adjustment_set_value (vadj, CLAMP (tree_y, vadj->lower, vadj->upper - vadj->page_size));
9798 * pspp_sheet_view_scroll_to_cell:
9799 * @tree_view: A #PsppSheetView.
9800 * @path: (allow-none): The path of the row to move to, or %NULL.
9801 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9802 * @use_align: whether to use alignment arguments, or %FALSE.
9803 * @row_align: The vertical alignment of the row specified by @path.
9804 * @col_align: The horizontal alignment of the column specified by @column.
9806 * Moves the alignments of @tree_view to the position specified by @column and
9807 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9808 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9809 * or @path need to be non-%NULL. @row_align determines where the row is
9810 * placed, and @col_align determines where @column is placed. Both are expected
9811 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9812 * right/bottom alignment, 0.5 means center.
9814 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9815 * tree does the minimum amount of work to scroll the cell onto the screen.
9816 * This means that the cell will be scrolled to the edge closest to its current
9817 * position. If the cell is currently visible on the screen, nothing is done.
9819 * This function only works if the model is set, and @path is a valid row on the
9820 * model. If the model changes before the @tree_view is realized, the centered
9821 * path will be modified to reflect this change.
9824 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9826 PsppSheetViewColumn *column,
9831 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9832 g_return_if_fail (tree_view->priv->model != NULL);
9833 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9834 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9835 g_return_if_fail (path != NULL || column != NULL);
9838 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9839 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9841 row_align = CLAMP (row_align, 0.0, 1.0);
9842 col_align = CLAMP (col_align, 0.0, 1.0);
9845 /* Note: Despite the benefits that come from having one code path for the
9846 * scrolling code, we short-circuit validate_visible_area's immplementation as
9847 * it is much slower than just going to the point.
9849 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9850 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9851 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9853 if (tree_view->priv->scroll_to_path)
9854 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9856 tree_view->priv->scroll_to_path = NULL;
9857 tree_view->priv->scroll_to_column = NULL;
9860 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9862 tree_view->priv->scroll_to_column = column;
9863 tree_view->priv->scroll_to_use_align = use_align;
9864 tree_view->priv->scroll_to_row_align = row_align;
9865 tree_view->priv->scroll_to_col_align = col_align;
9867 install_presize_handler (tree_view);
9871 GdkRectangle cell_rect;
9872 GdkRectangle vis_rect;
9873 gint dest_x, dest_y;
9875 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9876 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9878 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9880 dest_x = vis_rect.x;
9881 dest_y = vis_rect.y;
9887 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9891 if (cell_rect.x < vis_rect.x)
9892 dest_x = cell_rect.x;
9893 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9894 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9902 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9903 dest_y = MAX (dest_y, 0);
9907 if (cell_rect.y < vis_rect.y)
9908 dest_y = cell_rect.y;
9909 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9910 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9914 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9919 * pspp_sheet_view_row_activated:
9920 * @tree_view: A #PsppSheetView
9921 * @path: The #GtkTreePath to be activated.
9922 * @column: The #PsppSheetViewColumn to be activated.
9924 * Activates the cell determined by @path and @column.
9927 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9929 PsppSheetViewColumn *column)
9931 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9933 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
9938 * pspp_sheet_view_get_reorderable:
9939 * @tree_view: a #PsppSheetView
9941 * Retrieves whether the user can reorder the tree via drag-and-drop. See
9942 * pspp_sheet_view_set_reorderable().
9944 * Return value: %TRUE if the tree can be reordered.
9947 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
9949 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9951 return tree_view->priv->reorderable;
9955 * pspp_sheet_view_set_reorderable:
9956 * @tree_view: A #PsppSheetView.
9957 * @reorderable: %TRUE, if the tree can be reordered.
9959 * This function is a convenience function to allow you to reorder
9960 * models that support the #GtkDragSourceIface and the
9961 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
9962 * these. If @reorderable is %TRUE, then the user can reorder the
9963 * model by dragging and dropping rows. The developer can listen to
9964 * these changes by connecting to the model's row_inserted and
9965 * row_deleted signals. The reordering is implemented by setting up
9966 * the tree view as a drag source and destination. Therefore, drag and
9967 * drop can not be used in a reorderable view for any other purpose.
9969 * This function does not give you any degree of control over the order -- any
9970 * reordering is allowed. If more control is needed, you should probably
9971 * handle drag and drop manually.
9974 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
9975 gboolean reorderable)
9977 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9979 reorderable = reorderable != FALSE;
9981 if (tree_view->priv->reorderable == reorderable)
9986 const GtkTargetEntry row_targets[] = {
9987 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
9990 pspp_sheet_view_enable_model_drag_source (tree_view,
9993 G_N_ELEMENTS (row_targets),
9995 pspp_sheet_view_enable_model_drag_dest (tree_view,
9997 G_N_ELEMENTS (row_targets),
10002 pspp_sheet_view_unset_rows_drag_source (tree_view);
10003 pspp_sheet_view_unset_rows_drag_dest (tree_view);
10006 tree_view->priv->reorderable = reorderable;
10008 g_object_notify (G_OBJECT (tree_view), "reorderable");
10011 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
10012 is pressed, other rows will be unselected.
10014 If CLAMP_NODE is true, then the sheetview will scroll to make the row
10017 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
10019 gboolean clear_and_select,
10020 gboolean clamp_node,
10021 PsppSheetSelectMode mode)
10025 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10027 GtkTreePath *cursor_path;
10028 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10029 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
10030 gtk_tree_path_free (cursor_path);
10033 gtk_tree_row_reference_free (tree_view->priv->cursor);
10034 tree_view->priv->cursor = NULL;
10036 _pspp_sheet_view_find_node (tree_view, path, &node);
10037 tree_view->priv->cursor =
10038 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
10039 tree_view->priv->model,
10042 if (tree_view->priv->row_count > 0)
10046 if (clear_and_select && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
10047 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
10051 /* We have to re-find tree and node here again, somebody might have
10052 * cleared the node or the whole tree in the PsppSheetSelection::changed
10053 * callback. If the nodes differ we bail out here.
10055 _pspp_sheet_view_find_node (tree_view, path, &new_node);
10057 if (node != new_node)
10062 pspp_sheet_view_clamp_node_visible (tree_view, node);
10063 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10067 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
10071 * pspp_sheet_view_get_cursor:
10072 * @tree_view: A #PsppSheetView
10073 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
10074 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
10076 * Fills in @path and @focus_column with the current path and focus column. If
10077 * the cursor isn't currently set, then *@path will be %NULL. If no column
10078 * currently has focus, then *@focus_column will be %NULL.
10080 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
10081 * you are done with it.
10084 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
10085 GtkTreePath **path,
10086 PsppSheetViewColumn **focus_column)
10088 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10092 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10093 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10100 *focus_column = tree_view->priv->focus_column;
10105 * pspp_sheet_view_set_cursor:
10106 * @tree_view: A #PsppSheetView
10107 * @path: A #GtkTreePath
10108 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10109 * @start_editing: %TRUE if the specified cell should start being edited.
10111 * Sets the current keyboard focus to be at @path, and selects it. This is
10112 * useful when you want to focus the user's attention on a particular row. If
10113 * @focus_column is not %NULL, then focus is given to the column specified by
10114 * it. Additionally, if @focus_column is specified, and @start_editing is
10115 * %TRUE, then editing should be started in the specified cell.
10116 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
10117 * in order to give keyboard focus to the widget. Please note that editing
10118 * can only happen when the widget is realized.
10120 * If @path is invalid for @model, the current cursor (if any) will be unset
10121 * and the function will return without failing.
10124 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
10126 PsppSheetViewColumn *focus_column,
10127 gboolean start_editing)
10129 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
10130 NULL, start_editing);
10134 * pspp_sheet_view_set_cursor_on_cell:
10135 * @tree_view: A #PsppSheetView
10136 * @path: A #GtkTreePath
10137 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10138 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
10139 * @start_editing: %TRUE if the specified cell should start being edited.
10141 * Sets the current keyboard focus to be at @path, and selects it. This is
10142 * useful when you want to focus the user's attention on a particular row. If
10143 * @focus_column is not %NULL, then focus is given to the column specified by
10144 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
10145 * contains 2 or more editable or activatable cells, then focus is given to
10146 * the cell specified by @focus_cell. Additionally, if @focus_column is
10147 * specified, and @start_editing is %TRUE, then editing should be started in
10148 * the specified cell. This function is often followed by
10149 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
10150 * widget. Please note that editing can only happen when the widget is
10153 * If @path is invalid for @model, the current cursor (if any) will be unset
10154 * and the function will return without failing.
10159 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
10161 PsppSheetViewColumn *focus_column,
10162 GtkCellRenderer *focus_cell,
10163 gboolean start_editing)
10165 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10166 g_return_if_fail (path != NULL);
10167 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
10169 if (!tree_view->priv->model)
10174 g_return_if_fail (focus_column);
10175 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
10178 /* cancel the current editing, if it exists */
10179 if (tree_view->priv->edited_column &&
10180 tree_view->priv->edited_column->editable_widget)
10181 pspp_sheet_view_stop_editing (tree_view, TRUE);
10183 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
10185 if (focus_column && focus_column->visible)
10188 gboolean column_in_tree = FALSE;
10190 for (list = tree_view->priv->columns; list; list = list->next)
10191 if (list->data == focus_column)
10193 column_in_tree = TRUE;
10196 g_return_if_fail (column_in_tree);
10197 tree_view->priv->focus_column = focus_column;
10199 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
10201 pspp_sheet_view_start_editing (tree_view, path);
10203 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
10204 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
10210 * pspp_sheet_view_get_bin_window:
10211 * @tree_view: A #PsppSheetView
10213 * Returns the window that @tree_view renders to. This is used primarily to
10214 * compare to <literal>event->window</literal> to confirm that the event on
10215 * @tree_view is on the right window.
10217 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
10220 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
10222 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
10224 return tree_view->priv->bin_window;
10228 * pspp_sheet_view_get_path_at_pos:
10229 * @tree_view: A #PsppSheetView.
10230 * @x: The x position to be identified (relative to bin_window).
10231 * @y: The y position to be identified (relative to bin_window).
10232 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
10233 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
10234 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
10235 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
10237 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10238 * (please see pspp_sheet_view_get_bin_window()).
10239 * That is, @x and @y are relative to an events coordinates. @x and @y must
10240 * come from an event on the @tree_view only where <literal>event->window ==
10241 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10242 * things like popup menus. If @path is non-%NULL, then it will be filled
10243 * with the #GtkTreePath at that point. This path should be freed with
10244 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10245 * with the column at that point. @cell_x and @cell_y return the coordinates
10246 * relative to the cell background (i.e. the @background_area passed to
10247 * gtk_cell_renderer_render()). This function is only meaningful if
10248 * @tree_view is realized. Therefore this function will always return %FALSE
10249 * if @tree_view is not realized or does not have a model.
10251 * For converting widget coordinates (eg. the ones you get from
10252 * GtkWidget::query-tooltip), please see
10253 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10255 * Return value: %TRUE if a row exists at that coordinate.
10258 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10261 GtkTreePath **path,
10262 PsppSheetViewColumn **column,
10269 g_return_val_if_fail (tree_view != NULL, FALSE);
10276 if (tree_view->priv->bin_window == NULL)
10279 if (tree_view->priv->row_count == 0)
10282 if (x > tree_view->priv->hadjustment->upper)
10285 if (x < 0 || y < 0)
10288 if (column || cell_x)
10290 PsppSheetViewColumn *tmp_column;
10291 PsppSheetViewColumn *last_column = NULL;
10293 gint remaining_x = x;
10294 gboolean found = FALSE;
10297 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10298 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10300 list = (rtl ? list->prev : list->next))
10302 tmp_column = list->data;
10304 if (tmp_column->visible == FALSE)
10307 last_column = tmp_column;
10308 if (remaining_x <= tmp_column->width)
10313 *column = tmp_column;
10316 *cell_x = remaining_x;
10320 remaining_x -= tmp_column->width;
10323 /* If found is FALSE and there is a last_column, then it the remainder
10324 * space is in that area
10331 *column = last_column;
10334 *cell_x = last_column->width + remaining_x;
10343 y_offset = pspp_sheet_view_find_offset (tree_view,
10344 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10351 *cell_y = y_offset;
10354 *path = _pspp_sheet_view_find_path (tree_view, node);
10359 /* Computes 'cell_area' from 'background_area', which must be the background
10360 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10361 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10362 the cell area as passed to _pspp_sheet_view_column_cell_render().
10364 'column' is required to properly adjust 'cell_area->x' and
10365 'cell_area->width'. It may be set to NULL if these values are not of
10366 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10369 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10370 PsppSheetViewColumn *column,
10371 const GdkRectangle *background_area,
10372 gboolean subtract_focus_rect,
10373 GdkRectangle *cell_area)
10375 gint vertical_separator;
10376 gint horizontal_separator;
10378 *cell_area = *background_area;
10380 gtk_widget_style_get (GTK_WIDGET (tree_view),
10381 "vertical-separator", &vertical_separator,
10382 "horizontal-separator", &horizontal_separator,
10384 cell_area->x += horizontal_separator / 2;
10385 cell_area->y += vertical_separator / 2;
10386 cell_area->width -= horizontal_separator;
10387 cell_area->height -= vertical_separator;
10389 if (subtract_focus_rect)
10391 int focus_line_width;
10393 gtk_widget_style_get (GTK_WIDGET (tree_view),
10394 "focus-line-width", &focus_line_width,
10396 cell_area->x += focus_line_width;
10397 cell_area->y += focus_line_width;
10398 cell_area->width -= 2 * focus_line_width;
10399 cell_area->height -= 2 * focus_line_width;
10402 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10404 gint grid_line_width;
10405 gtk_widget_style_get (GTK_WIDGET (tree_view),
10406 "grid-line-width", &grid_line_width,
10409 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10410 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10413 PsppSheetViewColumn *first_column, *last_column;
10416 /* Find the last visible column. */
10417 last_column = NULL;
10418 for (list = g_list_last (tree_view->priv->columns);
10422 PsppSheetViewColumn *c = list->data;
10430 /* Find the first visible column. */
10431 first_column = NULL;
10432 for (list = g_list_first (tree_view->priv->columns);
10436 PsppSheetViewColumn *c = list->data;
10444 if (column == first_column)
10446 cell_area->width -= grid_line_width / 2;
10448 else if (column == last_column)
10450 cell_area->x += grid_line_width / 2;
10451 cell_area->width -= grid_line_width / 2;
10455 cell_area->x += grid_line_width / 2;
10456 cell_area->width -= grid_line_width;
10460 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10461 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10463 cell_area->y += grid_line_width / 2;
10464 cell_area->height -= grid_line_width;
10468 if (column == NULL)
10471 cell_area->width = 0;
10476 * pspp_sheet_view_get_cell_area:
10477 * @tree_view: a #PsppSheetView
10478 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10479 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10480 * @rect: rectangle to fill with cell rect
10482 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10483 * row specified by @path and the column specified by @column. If @path is
10484 * %NULL, or points to a path not currently displayed, the @y and @height fields
10485 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10486 * fields will be filled with 0. The sum of all cell rects does not cover the
10487 * entire tree; there are extra pixels in between rows, for example. The
10488 * returned rectangle is equivalent to the @cell_area passed to
10489 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10493 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10495 PsppSheetViewColumn *column,
10496 GdkRectangle *rect)
10498 GdkRectangle background_area;
10500 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10501 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10502 g_return_if_fail (rect != NULL);
10503 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10504 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10506 pspp_sheet_view_get_background_area (tree_view, path, column,
10508 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10513 * pspp_sheet_view_get_background_area:
10514 * @tree_view: a #PsppSheetView
10515 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10516 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10517 * @rect: rectangle to fill with cell background rect
10519 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10520 * row specified by @path and the column specified by @column. If @path is
10521 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10522 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10523 * fields will be filled with 0. The returned rectangle is equivalent to the
10524 * @background_area passed to gtk_cell_renderer_render(). These background
10525 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10526 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10527 * itself, excluding surrounding borders.
10531 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10533 PsppSheetViewColumn *column,
10534 GdkRectangle *rect)
10538 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10539 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10540 g_return_if_fail (rect != NULL);
10549 /* Get vertical coords */
10551 _pspp_sheet_view_find_node (tree_view, path, &node);
10555 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10557 rect->height = ROW_HEIGHT (tree_view);
10564 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10565 rect->width = x2 - rect->x;
10570 * pspp_sheet_view_get_visible_rect:
10571 * @tree_view: a #PsppSheetView
10572 * @visible_rect: rectangle to fill
10574 * Fills @visible_rect with the currently-visible region of the
10575 * buffer, in tree coordinates. Convert to bin_window coordinates with
10576 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10577 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10578 * scrollable area of the tree.
10581 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10582 GdkRectangle *visible_rect)
10586 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10588 widget = GTK_WIDGET (tree_view);
10592 visible_rect->x = tree_view->priv->hadjustment->value;
10593 visible_rect->y = tree_view->priv->vadjustment->value;
10594 visible_rect->width = widget->allocation.width;
10595 visible_rect->height = widget->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10600 * pspp_sheet_view_widget_to_tree_coords:
10601 * @tree_view: a #PsppSheetView
10602 * @wx: X coordinate relative to bin_window
10603 * @wy: Y coordinate relative to bin_window
10604 * @tx: return location for tree X coordinate
10605 * @ty: return location for tree Y coordinate
10607 * Converts bin_window coordinates to coordinates for the
10608 * tree (the full scrollable area of the tree).
10610 * Deprecated: 2.12: Due to historial reasons the name of this function is
10611 * incorrect. For converting coordinates relative to the widget to
10612 * bin_window coordinates, please see
10613 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10617 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10623 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10626 *tx = wx + tree_view->priv->hadjustment->value;
10628 *ty = wy + tree_view->priv->dy;
10632 * pspp_sheet_view_tree_to_widget_coords:
10633 * @tree_view: a #PsppSheetView
10634 * @tx: tree X coordinate
10635 * @ty: tree Y coordinate
10636 * @wx: return location for X coordinate relative to bin_window
10637 * @wy: return location for Y coordinate relative to bin_window
10639 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10640 * to bin_window coordinates.
10642 * Deprecated: 2.12: Due to historial reasons the name of this function is
10643 * incorrect. For converting bin_window coordinates to coordinates relative
10644 * to bin_window, please see
10645 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10649 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10655 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10658 *wx = tx - tree_view->priv->hadjustment->value;
10660 *wy = ty - tree_view->priv->dy;
10665 * pspp_sheet_view_convert_widget_to_tree_coords:
10666 * @tree_view: a #PsppSheetView
10667 * @wx: X coordinate relative to the widget
10668 * @wy: Y coordinate relative to the widget
10669 * @tx: return location for tree X coordinate
10670 * @ty: return location for tree Y coordinate
10672 * Converts widget coordinates to coordinates for the
10673 * tree (the full scrollable area of the tree).
10678 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10686 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10688 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10691 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10697 * pspp_sheet_view_convert_tree_to_widget_coords:
10698 * @tree_view: a #PsppSheetView
10699 * @tx: X coordinate relative to the tree
10700 * @ty: Y coordinate relative to the tree
10701 * @wx: return location for widget X coordinate
10702 * @wy: return location for widget Y coordinate
10704 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10705 * to widget coordinates.
10710 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10718 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10720 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10723 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10729 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10730 * @tree_view: a #PsppSheetView
10731 * @wx: X coordinate relative to the widget
10732 * @wy: Y coordinate relative to the widget
10733 * @bx: return location for bin_window X coordinate
10734 * @by: return location for bin_window Y coordinate
10736 * Converts widget coordinates to coordinates for the bin_window
10737 * (see pspp_sheet_view_get_bin_window()).
10742 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10748 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10751 *bx = wx + tree_view->priv->hadjustment->value;
10753 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10757 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10758 * @tree_view: a #PsppSheetView
10759 * @bx: bin_window X coordinate
10760 * @by: bin_window Y coordinate
10761 * @wx: return location for widget X coordinate
10762 * @wy: return location for widget Y coordinate
10764 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10765 * to widget relative coordinates.
10770 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10776 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10779 *wx = bx - tree_view->priv->hadjustment->value;
10781 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10785 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10786 * @tree_view: a #PsppSheetView
10787 * @tx: tree X coordinate
10788 * @ty: tree Y coordinate
10789 * @bx: return location for X coordinate relative to bin_window
10790 * @by: return location for Y coordinate relative to bin_window
10792 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10793 * to bin_window coordinates.
10798 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10804 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10809 *by = ty - tree_view->priv->dy;
10813 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10814 * @tree_view: a #PsppSheetView
10815 * @bx: X coordinate relative to bin_window
10816 * @by: Y coordinate relative to bin_window
10817 * @tx: return location for tree X coordinate
10818 * @ty: return location for tree Y coordinate
10820 * Converts bin_window coordinates to coordinates for the
10821 * tree (the full scrollable area of the tree).
10826 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10832 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10837 *ty = by + tree_view->priv->dy;
10843 * pspp_sheet_view_get_visible_range:
10844 * @tree_view: A #PsppSheetView
10845 * @start_path: (allow-none): Return location for start of region, or %NULL.
10846 * @end_path: (allow-none): Return location for end of region, or %NULL.
10848 * Sets @start_path and @end_path to be the first and last visible path.
10849 * Note that there may be invisible paths in between.
10851 * The paths should be freed with gtk_tree_path_free() after use.
10853 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10858 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10859 GtkTreePath **start_path,
10860 GtkTreePath **end_path)
10865 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10867 if (!tree_view->priv->row_count)
10874 pspp_sheet_view_find_offset (tree_view,
10875 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10878 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10887 if (tree_view->priv->height < tree_view->priv->vadjustment->page_size)
10888 y = tree_view->priv->height - 1;
10890 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, tree_view->priv->vadjustment->page_size) - 1;
10892 pspp_sheet_view_find_offset (tree_view, y, &node);
10894 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10903 unset_reorderable (PsppSheetView *tree_view)
10905 if (tree_view->priv->reorderable)
10907 tree_view->priv->reorderable = FALSE;
10908 g_object_notify (G_OBJECT (tree_view), "reorderable");
10913 * pspp_sheet_view_enable_model_drag_source:
10914 * @tree_view: a #PsppSheetView
10915 * @start_button_mask: Mask of allowed buttons to start drag
10916 * @targets: the table of targets that the drag will support
10917 * @n_targets: the number of items in @targets
10918 * @actions: the bitmask of possible actions for a drag from this
10921 * Turns @tree_view into a drag source for automatic DND. Calling this
10922 * method sets #PsppSheetView:reorderable to %FALSE.
10925 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10926 GdkModifierType start_button_mask,
10927 const GtkTargetEntry *targets,
10929 GdkDragAction actions)
10931 TreeViewDragInfo *di;
10933 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10935 gtk_drag_source_set (GTK_WIDGET (tree_view),
10941 di = ensure_info (tree_view);
10943 di->start_button_mask = start_button_mask;
10944 di->source_actions = actions;
10945 di->source_set = TRUE;
10947 unset_reorderable (tree_view);
10951 * pspp_sheet_view_enable_model_drag_dest:
10952 * @tree_view: a #PsppSheetView
10953 * @targets: the table of targets that the drag will support
10954 * @n_targets: the number of items in @targets
10955 * @actions: the bitmask of possible actions for a drag from this
10958 * Turns @tree_view into a drop destination for automatic DND. Calling
10959 * this method sets #PsppSheetView:reorderable to %FALSE.
10962 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
10963 const GtkTargetEntry *targets,
10965 GdkDragAction actions)
10967 TreeViewDragInfo *di;
10969 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10971 gtk_drag_dest_set (GTK_WIDGET (tree_view),
10977 di = ensure_info (tree_view);
10978 di->dest_set = TRUE;
10980 unset_reorderable (tree_view);
10984 * pspp_sheet_view_unset_rows_drag_source:
10985 * @tree_view: a #PsppSheetView
10987 * Undoes the effect of
10988 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
10989 * #PsppSheetView:reorderable to %FALSE.
10992 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
10994 TreeViewDragInfo *di;
10996 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10998 di = get_info (tree_view);
11002 if (di->source_set)
11004 gtk_drag_source_unset (GTK_WIDGET (tree_view));
11005 di->source_set = FALSE;
11008 if (!di->dest_set && !di->source_set)
11009 remove_info (tree_view);
11012 unset_reorderable (tree_view);
11016 * pspp_sheet_view_unset_rows_drag_dest:
11017 * @tree_view: a #PsppSheetView
11019 * Undoes the effect of
11020 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
11021 * #PsppSheetView:reorderable to %FALSE.
11024 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
11026 TreeViewDragInfo *di;
11028 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11030 di = get_info (tree_view);
11036 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
11037 di->dest_set = FALSE;
11040 if (!di->dest_set && !di->source_set)
11041 remove_info (tree_view);
11044 unset_reorderable (tree_view);
11048 * pspp_sheet_view_set_drag_dest_row:
11049 * @tree_view: a #PsppSheetView
11050 * @path: (allow-none): The path of the row to highlight, or %NULL.
11051 * @pos: Specifies whether to drop before, after or into the row
11053 * Sets the row that is highlighted for feedback.
11056 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
11058 PsppSheetViewDropPosition pos)
11060 GtkTreePath *current_dest;
11062 /* Note; this function is exported to allow a custom DND
11063 * implementation, so it can't touch TreeViewDragInfo
11066 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11068 current_dest = NULL;
11070 if (tree_view->priv->drag_dest_row)
11072 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11073 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
11076 /* special case a drop on an empty model */
11077 tree_view->priv->empty_view_drop = 0;
11079 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
11080 && gtk_tree_path_get_depth (path) == 1
11081 && gtk_tree_path_get_indices (path)[0] == 0)
11085 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
11089 tree_view->priv->empty_view_drop = 1;
11092 tree_view->priv->drag_dest_pos = pos;
11096 tree_view->priv->drag_dest_row =
11097 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
11098 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
11101 tree_view->priv->drag_dest_row = NULL;
11105 int node, new_node;
11107 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
11108 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
11112 new_node = pspp_sheet_view_node_next (tree_view, node);
11114 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11116 new_node = pspp_sheet_view_node_prev (tree_view, node);
11118 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11120 gtk_tree_path_free (current_dest);
11125 * pspp_sheet_view_get_drag_dest_row:
11126 * @tree_view: a #PsppSheetView
11127 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11128 * @pos: (allow-none): Return location for the drop position, or %NULL
11130 * Gets information about the row that is highlighted for feedback.
11133 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
11134 GtkTreePath **path,
11135 PsppSheetViewDropPosition *pos)
11137 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11141 if (tree_view->priv->drag_dest_row)
11142 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11145 if (tree_view->priv->empty_view_drop)
11146 *path = gtk_tree_path_new_from_indices (0, -1);
11153 *pos = tree_view->priv->drag_dest_pos;
11157 * pspp_sheet_view_get_dest_row_at_pos:
11158 * @tree_view: a #PsppSheetView
11159 * @drag_x: the position to determine the destination row for
11160 * @drag_y: the position to determine the destination row for
11161 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11162 * @pos: (allow-none): Return location for the drop position, or %NULL
11164 * Determines the destination row for a given position. @drag_x and
11165 * @drag_y are expected to be in widget coordinates. This function is only
11166 * meaningful if @tree_view is realized. Therefore this function will always
11167 * return %FALSE if @tree_view is not realized or does not have a model.
11169 * Return value: whether there is a row at the given position, %TRUE if this
11170 * is indeed the case.
11173 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
11176 GtkTreePath **path,
11177 PsppSheetViewDropPosition *pos)
11181 gdouble offset_into_row;
11184 PsppSheetViewColumn *column = NULL;
11185 GtkTreePath *tmp_path = NULL;
11187 /* Note; this function is exported to allow a custom DND
11188 * implementation, so it can't touch TreeViewDragInfo
11191 g_return_val_if_fail (tree_view != NULL, FALSE);
11192 g_return_val_if_fail (drag_x >= 0, FALSE);
11193 g_return_val_if_fail (drag_y >= 0, FALSE);
11198 if (tree_view->priv->bin_window == NULL)
11201 if (tree_view->priv->row_count == 0)
11204 /* If in the top third of a row, we drop before that row; if
11205 * in the bottom third, drop after that row; if in the middle,
11206 * and the row has children, drop into the row.
11208 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
11211 if (!pspp_sheet_view_get_path_at_pos (tree_view,
11220 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
11223 offset_into_row = cell_y;
11228 gtk_tree_path_free (tmp_path);
11232 third = cell.height / 3.0;
11236 if (offset_into_row < third)
11238 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11240 else if (offset_into_row < (cell.height / 2.0))
11242 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11244 else if (offset_into_row < third * 2.0)
11246 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11250 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11259 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11261 * pspp_sheet_view_create_row_drag_icon:
11262 * @tree_view: a #PsppSheetView
11263 * @path: a #GtkTreePath in @tree_view
11265 * Creates a #GdkPixmap representation of the row at @path.
11266 * This image is used for a drag icon.
11268 * Return value: a newly-allocated pixmap of the drag icon.
11271 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11278 GdkRectangle background_area;
11279 GdkRectangle expose_area;
11281 /* start drawing inside the black outline */
11283 GdkDrawable *drawable;
11284 gint bin_window_width;
11287 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11288 g_return_val_if_fail (path != NULL, NULL);
11290 widget = GTK_WIDGET (tree_view);
11292 if (!gtk_widget_get_realized (widget))
11295 _pspp_sheet_view_find_node (tree_view,
11302 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11309 background_area.y = y;
11310 background_area.height = ROW_HEIGHT (tree_view);
11312 gdk_drawable_get_size (tree_view->priv->bin_window,
11313 &bin_window_width, NULL);
11315 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11316 bin_window_width + 2,
11317 background_area.height + 2,
11322 expose_area.width = bin_window_width + 2;
11323 expose_area.height = background_area.height + 2;
11325 gdk_draw_rectangle (drawable,
11326 widget->style->base_gc [gtk_widget_get_state (widget)],
11329 bin_window_width + 2,
11330 background_area.height + 2);
11332 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11334 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11336 list = (rtl ? list->prev : list->next))
11338 PsppSheetViewColumn *column = list->data;
11339 GdkRectangle cell_area;
11340 gint vertical_separator;
11342 if (!column->visible)
11345 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11347 background_area.x = cell_offset;
11348 background_area.width = column->width;
11350 gtk_widget_style_get (widget,
11351 "vertical-separator", &vertical_separator,
11354 cell_area = background_area;
11356 cell_area.y += vertical_separator / 2;
11357 cell_area.height -= vertical_separator;
11359 if (pspp_sheet_view_column_cell_is_visible (column))
11360 _pspp_sheet_view_column_cell_render (column,
11366 cell_offset += column->width;
11369 gdk_draw_rectangle (drawable,
11370 widget->style->black_gc,
11373 bin_window_width + 1,
11374 background_area.height + 1);
11381 * pspp_sheet_view_set_destroy_count_func:
11382 * @tree_view: A #PsppSheetView
11383 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11384 * @data: (allow-none): User data to be passed to @func, or %NULL
11385 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11387 * This function should almost never be used. It is meant for private use by
11388 * ATK for determining the number of visible children that are removed when a row is deleted.
11391 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11392 PsppSheetDestroyCountFunc func,
11394 GDestroyNotify destroy)
11396 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11398 if (tree_view->priv->destroy_count_destroy)
11399 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11401 tree_view->priv->destroy_count_func = func;
11402 tree_view->priv->destroy_count_data = data;
11403 tree_view->priv->destroy_count_destroy = destroy;
11408 * Interactive search
11412 * pspp_sheet_view_set_enable_search:
11413 * @tree_view: A #PsppSheetView
11414 * @enable_search: %TRUE, if the user can search interactively
11416 * If @enable_search is set, then the user can type in text to search through
11417 * the tree interactively (this is sometimes called "typeahead find").
11419 * Note that even if this is %FALSE, the user can still initiate a search
11420 * using the "start-interactive-search" key binding.
11423 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11424 gboolean enable_search)
11426 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11428 enable_search = !!enable_search;
11430 if (tree_view->priv->enable_search != enable_search)
11432 tree_view->priv->enable_search = enable_search;
11433 g_object_notify (G_OBJECT (tree_view), "enable-search");
11438 * pspp_sheet_view_get_enable_search:
11439 * @tree_view: A #PsppSheetView
11441 * Returns whether or not the tree allows to start interactive searching
11442 * by typing in text.
11444 * Return value: whether or not to let the user search interactively
11447 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11449 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11451 return tree_view->priv->enable_search;
11456 * pspp_sheet_view_get_search_column:
11457 * @tree_view: A #PsppSheetView
11459 * Gets the column searched on by the interactive search code.
11461 * Return value: the column the interactive search code searches in.
11464 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11466 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11468 return (tree_view->priv->search_column);
11472 * pspp_sheet_view_set_search_column:
11473 * @tree_view: A #PsppSheetView
11474 * @column: the column of the model to search in, or -1 to disable searching
11476 * Sets @column as the column where the interactive search code should
11477 * search in for the current model.
11479 * If the search column is set, users can use the "start-interactive-search"
11480 * key binding to bring up search popup. The enable-search property controls
11481 * whether simply typing text will also start an interactive search.
11483 * Note that @column refers to a column of the current model. The search
11484 * column is reset to -1 when the model is changed.
11487 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11490 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11491 g_return_if_fail (column >= -1);
11493 if (tree_view->priv->search_column == column)
11496 tree_view->priv->search_column = column;
11497 g_object_notify (G_OBJECT (tree_view), "search-column");
11501 * pspp_sheet_view_get_search_equal_func:
11502 * @tree_view: A #PsppSheetView
11504 * Returns the compare function currently in use.
11506 * Return value: the currently used compare function for the search code.
11509 PsppSheetViewSearchEqualFunc
11510 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11512 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11514 return tree_view->priv->search_equal_func;
11518 * pspp_sheet_view_set_search_equal_func:
11519 * @tree_view: A #PsppSheetView
11520 * @search_equal_func: the compare function to use during the search
11521 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11522 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11524 * Sets the compare function for the interactive search capabilities; note
11525 * that somewhat like strcmp() returning 0 for equality
11526 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11529 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11530 PsppSheetViewSearchEqualFunc search_equal_func,
11531 gpointer search_user_data,
11532 GDestroyNotify search_destroy)
11534 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11535 g_return_if_fail (search_equal_func != NULL);
11537 if (tree_view->priv->search_destroy)
11538 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11540 tree_view->priv->search_equal_func = search_equal_func;
11541 tree_view->priv->search_user_data = search_user_data;
11542 tree_view->priv->search_destroy = search_destroy;
11543 if (tree_view->priv->search_equal_func == NULL)
11544 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11548 * pspp_sheet_view_get_search_entry:
11549 * @tree_view: A #PsppSheetView
11551 * Returns the #GtkEntry which is currently in use as interactive search
11552 * entry for @tree_view. In case the built-in entry is being used, %NULL
11553 * will be returned.
11555 * Return value: the entry currently in use as search entry.
11560 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11562 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11564 if (tree_view->priv->search_custom_entry_set)
11565 return GTK_ENTRY (tree_view->priv->search_entry);
11571 * pspp_sheet_view_set_search_entry:
11572 * @tree_view: A #PsppSheetView
11573 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11575 * Sets the entry which the interactive search code will use for this
11576 * @tree_view. This is useful when you want to provide a search entry
11577 * in our interface at all time at a fixed position. Passing %NULL for
11578 * @entry will make the interactive search code use the built-in popup
11584 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11587 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11588 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11590 if (tree_view->priv->search_custom_entry_set)
11592 if (tree_view->priv->search_entry_changed_id)
11594 g_signal_handler_disconnect (tree_view->priv->search_entry,
11595 tree_view->priv->search_entry_changed_id);
11596 tree_view->priv->search_entry_changed_id = 0;
11598 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11599 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11602 g_object_unref (tree_view->priv->search_entry);
11604 else if (tree_view->priv->search_window)
11606 gtk_widget_destroy (tree_view->priv->search_window);
11608 tree_view->priv->search_window = NULL;
11613 tree_view->priv->search_entry = g_object_ref (entry);
11614 tree_view->priv->search_custom_entry_set = TRUE;
11616 if (tree_view->priv->search_entry_changed_id == 0)
11618 tree_view->priv->search_entry_changed_id =
11619 g_signal_connect (tree_view->priv->search_entry, "changed",
11620 G_CALLBACK (pspp_sheet_view_search_init),
11624 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11625 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11628 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11632 tree_view->priv->search_entry = NULL;
11633 tree_view->priv->search_custom_entry_set = FALSE;
11638 * pspp_sheet_view_set_search_position_func:
11639 * @tree_view: A #PsppSheetView
11640 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11641 * to use the default search position function
11642 * @data: (allow-none): user data to pass to @func, or %NULL
11643 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11645 * Sets the function to use when positioning the search dialog.
11650 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11651 PsppSheetViewSearchPositionFunc func,
11652 gpointer user_data,
11653 GDestroyNotify destroy)
11655 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11657 if (tree_view->priv->search_position_destroy)
11658 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11660 tree_view->priv->search_position_func = func;
11661 tree_view->priv->search_position_user_data = user_data;
11662 tree_view->priv->search_position_destroy = destroy;
11663 if (tree_view->priv->search_position_func == NULL)
11664 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11668 * pspp_sheet_view_get_search_position_func:
11669 * @tree_view: A #PsppSheetView
11671 * Returns the positioning function currently in use.
11673 * Return value: the currently used function for positioning the search dialog.
11677 PsppSheetViewSearchPositionFunc
11678 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11680 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11682 return tree_view->priv->search_position_func;
11687 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11688 PsppSheetView *tree_view)
11690 if (tree_view->priv->disable_popdown)
11693 if (tree_view->priv->search_entry_changed_id)
11695 g_signal_handler_disconnect (tree_view->priv->search_entry,
11696 tree_view->priv->search_entry_changed_id);
11697 tree_view->priv->search_entry_changed_id = 0;
11699 if (tree_view->priv->typeselect_flush_timeout)
11701 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11702 tree_view->priv->typeselect_flush_timeout = 0;
11705 if (gtk_widget_get_visible (search_dialog))
11707 /* send focus-in event */
11708 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11709 gtk_widget_hide (search_dialog);
11710 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11711 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11716 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11717 GtkWidget *search_dialog,
11718 gpointer user_data)
11721 gint tree_x, tree_y;
11722 gint tree_width, tree_height;
11723 GdkWindow *tree_window = GTK_WIDGET (tree_view)->window;
11724 GdkScreen *screen = gdk_window_get_screen (tree_window);
11725 GtkRequisition requisition;
11727 GdkRectangle monitor;
11729 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11730 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11732 gtk_widget_realize (search_dialog);
11734 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11735 gdk_drawable_get_size (tree_window,
11738 gtk_widget_size_request (search_dialog, &requisition);
11740 if (tree_x + tree_width > gdk_screen_get_width (screen))
11741 x = gdk_screen_get_width (screen) - requisition.width;
11742 else if (tree_x + tree_width - requisition.width < 0)
11745 x = tree_x + tree_width - requisition.width;
11747 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11748 y = gdk_screen_get_height (screen) - requisition.height;
11749 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11752 y = tree_y + tree_height;
11754 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11758 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11762 PsppSheetView *tree_view = (PsppSheetView *)data;
11764 tree_view->priv->disable_popdown = 1;
11765 g_signal_connect (menu, "hide",
11766 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11769 /* Because we're visible but offscreen, we just set a flag in the preedit
11773 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11774 PsppSheetView *tree_view)
11776 tree_view->priv->imcontext_changed = 1;
11777 if (tree_view->priv->typeselect_flush_timeout)
11779 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11780 tree_view->priv->typeselect_flush_timeout =
11781 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11782 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11789 pspp_sheet_view_search_activate (GtkEntry *entry,
11790 PsppSheetView *tree_view)
11795 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11798 /* If we have a row selected and it's the cursor row, we activate
11800 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11802 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11804 _pspp_sheet_view_find_node (tree_view, path, &node);
11806 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11807 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11809 gtk_tree_path_free (path);
11814 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11816 PsppSheetView *tree_view = (PsppSheetView *)data;
11818 tree_view->priv->disable_popdown = 0;
11824 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11827 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11831 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11832 GdkEventAny *event,
11833 PsppSheetView *tree_view)
11835 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11837 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11843 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11844 GdkEventButton *event,
11845 PsppSheetView *tree_view)
11847 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11849 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11851 if (event->window == tree_view->priv->bin_window)
11852 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11858 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11859 GdkEventScroll *event,
11860 PsppSheetView *tree_view)
11862 gboolean retval = FALSE;
11864 if (event->direction == GDK_SCROLL_UP)
11866 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11869 else if (event->direction == GDK_SCROLL_DOWN)
11871 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11875 /* renew the flush timeout */
11876 if (retval && tree_view->priv->typeselect_flush_timeout
11877 && !tree_view->priv->search_custom_entry_set)
11879 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11880 tree_view->priv->typeselect_flush_timeout =
11881 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11882 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11890 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11891 GdkEventKey *event,
11892 PsppSheetView *tree_view)
11894 gboolean retval = FALSE;
11896 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11897 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11899 /* close window and cancel the search */
11900 if (!tree_view->priv->search_custom_entry_set
11901 && (event->keyval == GDK_Escape ||
11902 event->keyval == GDK_Tab ||
11903 event->keyval == GDK_KP_Tab ||
11904 event->keyval == GDK_ISO_Left_Tab))
11906 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11910 /* select previous matching iter */
11911 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11913 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11914 gtk_widget_error_bell (widget);
11919 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11920 && (event->keyval == GDK_g || event->keyval == GDK_G))
11922 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11923 gtk_widget_error_bell (widget);
11928 /* select next matching iter */
11929 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
11931 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11932 gtk_widget_error_bell (widget);
11937 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
11938 && (event->keyval == GDK_g || event->keyval == GDK_G))
11940 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11941 gtk_widget_error_bell (widget);
11946 /* renew the flush timeout */
11947 if (retval && tree_view->priv->typeselect_flush_timeout
11948 && !tree_view->priv->search_custom_entry_set)
11950 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11951 tree_view->priv->typeselect_flush_timeout =
11952 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11953 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11960 /* this function returns FALSE if there is a search string but
11961 * nothing was found, and TRUE otherwise.
11964 pspp_sheet_view_search_move (GtkWidget *window,
11965 PsppSheetView *tree_view,
11973 GtkTreeModel *model;
11974 PsppSheetSelection *selection;
11976 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
11978 g_return_val_if_fail (text != NULL, FALSE);
11980 len = strlen (text);
11982 if (up && tree_view->priv->selected_iter == 1)
11983 return strlen (text) < 1;
11985 len = strlen (text);
11990 model = pspp_sheet_view_get_model (tree_view);
11991 selection = pspp_sheet_view_get_selection (tree_view);
11994 pspp_sheet_selection_unselect_all (selection);
11995 if (!gtk_tree_model_get_iter_first (model, &iter))
11998 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
11999 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
12004 tree_view->priv->selected_iter += up?(-1):(1);
12009 /* return to old iter */
12011 gtk_tree_model_get_iter_first (model, &iter);
12012 pspp_sheet_view_search_iter (model, selection,
12014 &count, tree_view->priv->selected_iter);
12020 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
12024 gpointer search_data)
12026 gboolean retval = TRUE;
12028 gchar *normalized_string;
12029 gchar *normalized_key;
12030 gchar *case_normalized_string = NULL;
12031 gchar *case_normalized_key = NULL;
12032 GValue value = {0,};
12033 GValue transformed = {0,};
12035 gtk_tree_model_get_value (model, iter, column, &value);
12037 g_value_init (&transformed, G_TYPE_STRING);
12039 if (!g_value_transform (&value, &transformed))
12041 g_value_unset (&value);
12045 g_value_unset (&value);
12047 str = g_value_get_string (&transformed);
12050 g_value_unset (&transformed);
12054 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
12055 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
12057 if (normalized_string && normalized_key)
12059 case_normalized_string = g_utf8_casefold (normalized_string, -1);
12060 case_normalized_key = g_utf8_casefold (normalized_key, -1);
12062 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
12066 g_value_unset (&transformed);
12067 g_free (normalized_key);
12068 g_free (normalized_string);
12069 g_free (case_normalized_key);
12070 g_free (case_normalized_string);
12076 pspp_sheet_view_search_iter (GtkTreeModel *model,
12077 PsppSheetSelection *selection,
12086 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
12088 path = gtk_tree_model_get_path (model, iter);
12089 _pspp_sheet_view_find_node (tree_view, path, &node);
12093 gboolean done = FALSE;
12095 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
12100 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
12102 pspp_sheet_selection_select_iter (selection, iter);
12103 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12106 gtk_tree_path_free (path);
12115 node = pspp_sheet_view_node_next (tree_view, node);
12121 has_next = gtk_tree_model_iter_next (model, iter);
12124 gtk_tree_path_next (path);
12127 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
12132 gtk_tree_path_free (path);
12134 /* we've run out of tree, done with this func */
12146 pspp_sheet_view_search_init (GtkWidget *entry,
12147 PsppSheetView *tree_view)
12153 GtkTreeModel *model;
12154 PsppSheetSelection *selection;
12156 g_return_if_fail (GTK_IS_ENTRY (entry));
12157 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12159 text = gtk_entry_get_text (GTK_ENTRY (entry));
12161 model = pspp_sheet_view_get_model (tree_view);
12162 selection = pspp_sheet_view_get_selection (tree_view);
12165 pspp_sheet_selection_unselect_all (selection);
12166 if (tree_view->priv->typeselect_flush_timeout
12167 && !tree_view->priv->search_custom_entry_set)
12169 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12170 tree_view->priv->typeselect_flush_timeout =
12171 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12172 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12179 if (!gtk_tree_model_get_iter_first (model, &iter))
12182 ret = pspp_sheet_view_search_iter (model, selection,
12187 tree_view->priv->selected_iter = 1;
12191 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
12192 PsppSheetView *tree_view)
12194 if (tree_view->priv->edited_column == NULL)
12197 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
12198 tree_view->priv->edited_column = NULL;
12200 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
12201 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12203 g_signal_handlers_disconnect_by_func (cell_editable,
12204 pspp_sheet_view_remove_widget,
12206 g_signal_handlers_disconnect_by_func (cell_editable,
12207 pspp_sheet_view_editable_button_press_event,
12209 g_signal_handlers_disconnect_by_func (cell_editable,
12210 pspp_sheet_view_editable_clicked,
12213 gtk_container_remove (GTK_CONTAINER (tree_view),
12214 GTK_WIDGET (cell_editable));
12216 /* FIXME should only redraw a single node */
12217 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12221 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
12222 GtkTreePath *cursor_path)
12225 GdkRectangle background_area;
12226 GdkRectangle cell_area;
12227 GtkCellEditable *editable_widget = NULL;
12228 gchar *path_string;
12229 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
12230 gint retval = FALSE;
12233 g_assert (tree_view->priv->focus_column);
12235 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12238 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12239 if (cursor_node < 0)
12242 path_string = gtk_tree_path_to_string (cursor_path);
12243 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12245 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12246 tree_view->priv->model,
12248 pspp_sheet_view_get_background_area (tree_view,
12250 tree_view->priv->focus_column,
12252 pspp_sheet_view_get_cell_area (tree_view,
12254 tree_view->priv->focus_column,
12257 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12266 if (editable_widget != NULL)
12270 GtkCellRenderer *cell;
12273 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12275 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12278 area.width -= right + left;
12280 pspp_sheet_view_real_start_editing (tree_view,
12281 tree_view->priv->focus_column,
12290 g_free (path_string);
12295 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12296 GdkEventButton *event,
12297 PsppSheetView *sheet_view)
12301 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12302 "pspp-sheet-view-node"));
12303 return pspp_sheet_view_row_head_clicked (sheet_view,
12305 sheet_view->priv->edited_column,
12310 pspp_sheet_view_editable_clicked (GtkButton *button,
12311 PsppSheetView *sheet_view)
12313 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12318 is_all_selected (GtkWidget *widget)
12320 GtkEntryBuffer *buffer;
12321 gint start_pos, end_pos;
12323 if (!GTK_IS_ENTRY (widget))
12326 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12327 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12328 &start_pos, &end_pos)
12330 && end_pos == gtk_entry_buffer_get_length (buffer));
12334 is_at_left (GtkWidget *widget)
12336 return (GTK_IS_ENTRY (widget)
12337 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12341 is_at_right (GtkWidget *widget)
12343 GtkEntryBuffer *buffer;
12346 if (!GTK_IS_ENTRY (widget))
12349 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12350 length = gtk_entry_buffer_get_length (buffer);
12351 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12355 pspp_sheet_view_event (GtkWidget *widget,
12356 GdkEventKey *event,
12357 PsppSheetView *tree_view)
12359 PsppSheetViewColumn *column;
12366 /* Intercept only key press events.
12367 It would make sense to use "key-press-event" instead of "event", but
12368 GtkEntry attaches its own signal handler to "key-press-event" that runs
12369 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12371 if (event->type != GDK_KEY_PRESS)
12374 keyval = event->keyval;
12376 switch (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12379 switch (event->keyval)
12381 case GDK_Left: case GDK_KP_Left:
12382 case GDK_Home: case GDK_KP_Home:
12383 if (!is_all_selected (widget) && !is_at_left (widget))
12387 case GDK_Right: case GDK_KP_Right:
12388 case GDK_End: case GDK_KP_End:
12389 if (!is_all_selected (widget) && !is_at_right (widget))
12393 case GDK_Up: case GDK_KP_Up:
12394 case GDK_Down: case GDK_KP_Down:
12397 case GDK_Page_Up: case GDK_KP_Page_Up:
12398 case GDK_Page_Down: case GDK_KP_Page_Down:
12409 case GDK_Tab: case GDK_KP_Tab:
12410 case GDK_ISO_Left_Tab:
12419 case GDK_SHIFT_MASK:
12420 switch (event->keyval)
12423 case GDK_ISO_Left_Tab:
12432 case GDK_CONTROL_MASK:
12433 switch (event->keyval)
12435 case GDK_Left: case GDK_KP_Left:
12436 if (!is_all_selected (widget) && !is_at_left (widget))
12440 case GDK_Right: case GDK_KP_Right:
12441 if (!is_all_selected (widget) && !is_at_right (widget))
12445 case GDK_Up: case GDK_KP_Up:
12446 case GDK_Down: case GDK_KP_Down:
12458 row = tree_view->priv->edited_row;
12459 column = tree_view->priv->edited_column;
12460 path = gtk_tree_path_new_from_indices (row, -1);
12462 pspp_sheet_view_stop_editing (tree_view, cancel);
12463 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12465 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12466 gtk_tree_path_free (path);
12468 handled = gtk_binding_set_activate (edit_bindings, keyval, event->state,
12469 GTK_OBJECT (tree_view));
12471 g_signal_stop_emission_by_name (widget, "event");
12473 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12474 pspp_sheet_view_start_editing (tree_view, path);
12475 gtk_tree_path_free (path);
12481 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12484 PsppSheetView *sheet_view = data;
12486 g_signal_connect (widget, "event",
12487 G_CALLBACK (pspp_sheet_view_event),
12490 if (GTK_IS_CONTAINER (widget))
12491 gtk_container_foreach (GTK_CONTAINER (widget),
12492 pspp_sheet_view_override_cell_keypresses,
12497 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12498 PsppSheetViewColumn *column,
12500 GtkCellEditable *cell_editable,
12501 GdkRectangle *cell_area,
12505 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12506 gint pre_val = tree_view->priv->vadjustment->value;
12507 GtkRequisition requisition;
12510 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12512 tree_view->priv->edited_column = column;
12513 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12515 row = gtk_tree_path_get_indices (path)[0];
12516 tree_view->priv->edited_row = row;
12517 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12518 cell_area->y += pre_val - (int)tree_view->priv->vadjustment->value;
12520 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12521 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12522 tree_view->priv->anchor_column = column;
12524 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12526 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12528 if (requisition.height < cell_area->height)
12530 gint diff = cell_area->height - requisition.height;
12531 pspp_sheet_view_put (tree_view,
12532 GTK_WIDGET (cell_editable),
12533 cell_area->x, cell_area->y + diff/2,
12534 cell_area->width, requisition.height);
12538 pspp_sheet_view_put (tree_view,
12539 GTK_WIDGET (cell_editable),
12540 cell_area->x, cell_area->y,
12541 cell_area->width, cell_area->height);
12544 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12545 (GdkEvent *)event);
12547 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12548 g_signal_connect (cell_editable, "remove-widget",
12549 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12550 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12551 GTK_IS_BUTTON (cell_editable))
12553 g_signal_connect (cell_editable, "button-press-event",
12554 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12556 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12557 GINT_TO_POINTER (row));
12558 g_signal_connect (cell_editable, "clicked",
12559 G_CALLBACK (pspp_sheet_view_editable_clicked),
12563 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12568 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12569 gboolean cancel_editing)
12571 PsppSheetViewColumn *column;
12572 GtkCellRenderer *cell;
12574 if (tree_view->priv->edited_column == NULL)
12578 * This is very evil. We need to do this, because
12579 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12580 * later on. If pspp_sheet_view_row_changed notices
12581 * tree_view->priv->edited_column != NULL, it'll call
12582 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12584 * Please read that again if you intend to modify anything here.
12587 column = tree_view->priv->edited_column;
12588 tree_view->priv->edited_column = NULL;
12590 cell = _pspp_sheet_view_column_get_edited_cell (column);
12591 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12593 if (!cancel_editing)
12594 gtk_cell_editable_editing_done (column->editable_widget);
12596 tree_view->priv->edited_column = column;
12598 gtk_cell_editable_remove_widget (column->editable_widget);
12603 * pspp_sheet_view_set_hover_selection:
12604 * @tree_view: a #PsppSheetView
12605 * @hover: %TRUE to enable hover selection mode
12607 * Enables of disables the hover selection mode of @tree_view.
12608 * Hover selection makes the selected row follow the pointer.
12609 * Currently, this works only for the selection modes
12610 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12615 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12618 hover = hover != FALSE;
12620 if (hover != tree_view->priv->hover_selection)
12622 tree_view->priv->hover_selection = hover;
12624 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12629 * pspp_sheet_view_get_hover_selection:
12630 * @tree_view: a #PsppSheetView
12632 * Returns whether hover selection mode is turned on for @tree_view.
12634 * Return value: %TRUE if @tree_view is in hover selection mode
12639 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12641 return tree_view->priv->hover_selection;
12645 * pspp_sheet_view_set_rubber_banding:
12646 * @tree_view: a #PsppSheetView
12647 * @enable: %TRUE to enable rubber banding
12649 * Enables or disables rubber banding in @tree_view. If the selection mode is
12650 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12651 * banding will allow the user to select multiple rows by dragging the mouse.
12656 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12659 enable = enable != FALSE;
12661 if (enable != tree_view->priv->rubber_banding_enable)
12663 tree_view->priv->rubber_banding_enable = enable;
12665 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12670 * pspp_sheet_view_get_rubber_banding:
12671 * @tree_view: a #PsppSheetView
12673 * Returns whether rubber banding is turned on for @tree_view. If the
12674 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12675 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12676 * select multiple rows by dragging the mouse.
12678 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12683 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12685 return tree_view->priv->rubber_banding_enable;
12689 * pspp_sheet_view_is_rubber_banding_active:
12690 * @tree_view: a #PsppSheetView
12692 * Returns whether a rubber banding operation is currently being done
12695 * Return value: %TRUE if a rubber banding operation is currently being
12696 * done in @tree_view.
12701 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12703 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12705 if (tree_view->priv->rubber_banding_enable
12706 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12713 pspp_sheet_view_grab_notify (GtkWidget *widget,
12714 gboolean was_grabbed)
12716 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12718 tree_view->priv->in_grab = !was_grabbed;
12722 tree_view->priv->pressed_button = -1;
12724 if (tree_view->priv->rubber_band_status)
12725 pspp_sheet_view_stop_rubber_band (tree_view);
12730 pspp_sheet_view_state_changed (GtkWidget *widget,
12731 GtkStateType previous_state)
12733 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12735 if (gtk_widget_get_realized (widget))
12737 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
12738 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
12741 gtk_widget_queue_draw (widget);
12745 * pspp_sheet_view_get_grid_lines:
12746 * @tree_view: a #PsppSheetView
12748 * Returns which grid lines are enabled in @tree_view.
12750 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12755 PsppSheetViewGridLines
12756 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12758 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12760 return tree_view->priv->grid_lines;
12764 * pspp_sheet_view_set_grid_lines:
12765 * @tree_view: a #PsppSheetView
12766 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12769 * Sets which grid lines to draw in @tree_view.
12774 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12775 PsppSheetViewGridLines grid_lines)
12777 PsppSheetViewPrivate *priv;
12778 PsppSheetViewGridLines old_grid_lines;
12780 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12782 priv = tree_view->priv;
12784 old_grid_lines = priv->grid_lines;
12785 priv->grid_lines = grid_lines;
12787 if (old_grid_lines != grid_lines)
12789 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12791 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12796 * pspp_sheet_view_get_special_cells:
12797 * @tree_view: a #PsppSheetView
12799 * Returns which grid lines are enabled in @tree_view.
12801 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12802 * the sheet view contain special cells.
12804 PsppSheetViewSpecialCells
12805 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12807 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12809 return tree_view->priv->special_cells;
12813 * pspp_sheet_view_set_special_cells:
12814 * @tree_view: a #PsppSheetView
12815 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12816 * the sheet view contain special cells.
12818 * Sets whether rows in the sheet view contain special cells, controlling the
12819 * rendering of row selections.
12822 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12823 PsppSheetViewSpecialCells special_cells)
12825 PsppSheetViewPrivate *priv;
12827 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12829 priv = tree_view->priv;
12831 if (priv->special_cells != special_cells)
12833 priv->special_cells = special_cells;
12834 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12835 g_object_notify (G_OBJECT (tree_view), "special-cells");
12840 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12842 /* XXX (re)calculate fixed_height if necessary */
12843 return tree_view->priv->fixed_height;
12847 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12850 g_return_if_fail (fixed_height > 0);
12852 if (tree_view->priv->fixed_height != fixed_height)
12854 tree_view->priv->fixed_height = fixed_height;
12855 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12857 if (!tree_view->priv->fixed_height_set)
12859 tree_view->priv->fixed_height_set = TRUE;
12860 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12865 * pspp_sheet_view_set_tooltip_row:
12866 * @tree_view: a #PsppSheetView
12867 * @tooltip: a #GtkTooltip
12868 * @path: a #GtkTreePath
12870 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12871 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12872 * See also gtk_tooltip_set_tip_area().
12877 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12878 GtkTooltip *tooltip,
12881 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12882 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12884 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12888 * pspp_sheet_view_set_tooltip_cell:
12889 * @tree_view: a #PsppSheetView
12890 * @tooltip: a #GtkTooltip
12891 * @path: (allow-none): a #GtkTreePath or %NULL
12892 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12893 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12895 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12896 * in common. For example if @path is %NULL and @column is set, the tip
12897 * area will be set to the full area covered by @column. See also
12898 * gtk_tooltip_set_tip_area().
12900 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12905 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12906 GtkTooltip *tooltip,
12908 PsppSheetViewColumn *column,
12909 GtkCellRenderer *cell)
12913 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12914 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12915 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12916 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12918 /* Determine x values. */
12919 if (column && cell)
12924 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12925 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12927 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12930 rect.width = width;
12936 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
12937 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12940 rect.width = tmp.width;
12945 rect.width = GTK_WIDGET (tree_view)->allocation.width;
12948 /* Determine y values. */
12953 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
12954 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12957 rect.height = tmp.height;
12962 rect.height = tree_view->priv->vadjustment->page_size;
12965 gtk_tooltip_set_tip_area (tooltip, &rect);
12969 * pspp_sheet_view_get_tooltip_context:
12970 * @tree_view: a #PsppSheetView
12971 * @x: the x coordinate (relative to widget coordinates)
12972 * @y: the y coordinate (relative to widget coordinates)
12973 * @keyboard_tip: whether this is a keyboard tooltip or not
12974 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
12975 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
12976 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
12978 * This function is supposed to be used in a #GtkWidget::query-tooltip
12979 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
12980 * which are received in the signal handler, should be passed to this
12981 * function without modification.
12983 * The return value indicates whether there is a tree view row at the given
12984 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
12985 * tooltips the row returned will be the cursor row. When %TRUE, then any of
12986 * @model, @path and @iter which have been provided will be set to point to
12987 * that row and the corresponding model. @x and @y will always be converted
12988 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
12990 * Return value: whether or not the given tooltip context points to a row.
12995 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
12998 gboolean keyboard_tip,
12999 GtkTreeModel **model,
13000 GtkTreePath **path,
13003 GtkTreePath *tmppath = NULL;
13005 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
13006 g_return_val_if_fail (x != NULL, FALSE);
13007 g_return_val_if_fail (y != NULL, FALSE);
13011 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
13018 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
13021 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
13022 &tmppath, NULL, NULL, NULL))
13027 *model = pspp_sheet_view_get_model (tree_view);
13030 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
13036 gtk_tree_path_free (tmppath);
13042 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
13045 gboolean keyboard_tip,
13046 GtkTooltip *tooltip,
13049 GValue value = { 0, };
13050 GValue transformed = { 0, };
13053 GtkTreeModel *model;
13054 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
13056 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
13059 &model, &path, &iter))
13062 gtk_tree_model_get_value (model, &iter,
13063 tree_view->priv->tooltip_column, &value);
13065 g_value_init (&transformed, G_TYPE_STRING);
13067 if (!g_value_transform (&value, &transformed))
13069 g_value_unset (&value);
13070 gtk_tree_path_free (path);
13075 g_value_unset (&value);
13077 if (!g_value_get_string (&transformed))
13079 g_value_unset (&transformed);
13080 gtk_tree_path_free (path);
13085 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
13086 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
13088 gtk_tree_path_free (path);
13089 g_value_unset (&transformed);
13095 * pspp_sheet_view_set_tooltip_column:
13096 * @tree_view: a #PsppSheetView
13097 * @column: an integer, which is a valid column number for @tree_view's model
13099 * If you only plan to have simple (text-only) tooltips on full rows, you
13100 * can use this function to have #PsppSheetView handle these automatically
13101 * for you. @column should be set to the column in @tree_view's model
13102 * containing the tooltip texts, or -1 to disable this feature.
13104 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
13105 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
13107 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
13108 * so &, <, etc have to be escaped in the text.
13113 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
13116 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13118 if (column == tree_view->priv->tooltip_column)
13123 g_signal_handlers_disconnect_by_func (tree_view,
13124 pspp_sheet_view_set_tooltip_query_cb,
13126 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
13130 if (tree_view->priv->tooltip_column == -1)
13132 g_signal_connect (tree_view, "query-tooltip",
13133 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
13134 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
13138 tree_view->priv->tooltip_column = column;
13139 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
13143 * pspp_sheet_view_get_tooltip_column:
13144 * @tree_view: a #PsppSheetView
13146 * Returns the column of @tree_view's model which is being used for
13147 * displaying tooltips on @tree_view's rows.
13149 * Return value: the index of the tooltip column that is currently being
13150 * used, or -1 if this is disabled.
13155 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
13157 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
13159 return tree_view->priv->tooltip_column;
13163 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
13164 GValue *return_accu,
13165 const GValue *handler_return,
13168 gboolean continue_emission;
13169 gboolean signal_handled;
13171 signal_handled = g_value_get_boolean (handler_return);
13172 g_value_set_boolean (return_accu, signal_handled);
13173 continue_emission = !signal_handled;
13175 return continue_emission;
13179 pspp_sheet_view_grid_lines_get_type (void)
13181 static GType etype = 0;
13182 if (G_UNLIKELY(etype == 0)) {
13183 static const GEnumValue values[] = {
13184 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
13185 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
13186 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
13187 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
13190 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
13196 pspp_sheet_view_special_cells_get_type (void)
13198 static GType etype = 0;
13199 if (G_UNLIKELY(etype == 0)) {
13200 static const GEnumValue values[] = {
13201 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
13202 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
13203 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
13206 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);