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_drawable_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);
6612 if (GTK_CONTAINER (tree_view)->focus_child != focus_column->button)
6613 gtk_widget_grab_focus (focus_column->button);
6615 if (clamp_column_visible)
6616 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6619 /* Returns TRUE if the focus is within the headers, after the focus operation is
6623 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6624 GtkDirectionType dir,
6625 gboolean clamp_column_visible)
6627 GtkWidget *focus_child;
6628 PsppSheetViewColumn *focus_column;
6629 GList *last_column, *first_column;
6633 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6636 focus_child = GTK_CONTAINER (tree_view)->focus_child;
6638 first_column = tree_view->priv->columns;
6639 while (first_column)
6641 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6643 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6645 first_column = first_column->next;
6648 /* No headers are visible, or are focusable. We can't focus in or out.
6650 if (first_column == NULL)
6653 last_column = g_list_last (tree_view->priv->columns);
6656 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6658 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6660 last_column = last_column->prev;
6664 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6668 case GTK_DIR_TAB_BACKWARD:
6669 case GTK_DIR_TAB_FORWARD:
6672 if (focus_child == NULL)
6674 if (tree_view->priv->focus_column != NULL &&
6675 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6676 focus_column = tree_view->priv->focus_column;
6678 focus_column = first_column->data;
6679 pspp_sheet_view_focus_column (tree_view, focus_column,
6680 clamp_column_visible);
6687 if (focus_child == NULL)
6689 if (tree_view->priv->focus_column != NULL)
6690 focus_column = tree_view->priv->focus_column;
6691 else if (dir == GTK_DIR_LEFT)
6692 focus_column = last_column->data;
6694 focus_column = first_column->data;
6695 pspp_sheet_view_focus_column (tree_view, focus_column,
6696 clamp_column_visible);
6700 if (gtk_widget_child_focus (focus_child, dir))
6702 /* The focus moves inside the button. */
6703 /* This is probably a great example of bad UI */
6704 if (clamp_column_visible)
6705 pspp_sheet_view_clamp_column_visible (tree_view,
6706 tree_view->priv->focus_column,
6711 /* We need to move the focus among the row of buttons. */
6712 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6713 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6716 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6717 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6719 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6725 PsppSheetViewColumn *column;
6727 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6728 tmp_list = tmp_list->next;
6730 tmp_list = tmp_list->prev;
6732 if (tmp_list == NULL)
6734 g_warning ("Internal button not found");
6737 column = tmp_list->data;
6738 if (column->visible &&
6739 pspp_sheet_view_column_can_focus (column))
6741 pspp_sheet_view_column_set_need_button (column, TRUE);
6744 pspp_sheet_view_focus_column (tree_view, column,
6745 clamp_column_visible);
6753 g_assert_not_reached ();
6760 /* This function returns in 'path' the first focusable path, if the given path
6761 * is already focusable, it's the returned one.
6765 search_first_focusable_path (PsppSheetView *tree_view,
6767 gboolean search_forward,
6770 /* XXX this function is trivial given that the sheetview doesn't support
6774 if (!path || !*path)
6777 _pspp_sheet_view_find_node (tree_view, *path, &node);
6785 return (*path != NULL);
6789 pspp_sheet_view_focus (GtkWidget *widget,
6790 GtkDirectionType direction)
6792 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6793 GtkContainer *container = GTK_CONTAINER (widget);
6794 GtkWidget *focus_child;
6796 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6799 focus_child = container->focus_child;
6801 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6802 /* Case 1. Headers currently have focus. */
6809 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6811 case GTK_DIR_TAB_BACKWARD:
6814 case GTK_DIR_TAB_FORWARD:
6816 gtk_widget_grab_focus (widget);
6819 g_assert_not_reached ();
6824 /* Case 2. We don't have focus at all. */
6825 if (!gtk_widget_has_focus (widget))
6827 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6828 gtk_widget_grab_focus (widget);
6832 /* Case 3. We have focus already. */
6833 if (direction == GTK_DIR_TAB_BACKWARD)
6834 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6835 else if (direction == GTK_DIR_TAB_FORWARD)
6838 /* Other directions caught by the keybindings */
6839 gtk_widget_grab_focus (widget);
6844 pspp_sheet_view_grab_focus (GtkWidget *widget)
6846 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6848 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6852 pspp_sheet_view_style_set (GtkWidget *widget,
6853 GtkStyle *previous_style)
6855 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6857 PsppSheetViewColumn *column;
6859 if (gtk_widget_get_realized (widget))
6862 PsppSheetViewPrivate *priv = PSPP_SHEET_VIEW (widget)->priv;
6864 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
6865 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
6866 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
6867 for (i = 0; i < 5 ; ++i)
6869 g_object_unref (priv->grid_line_gc[i]);
6870 priv->grid_line_gc[i] = gdk_gc_new (widget->window);
6871 gdk_gc_copy (priv->grid_line_gc[i], widget->style->text_aa_gc[i]);
6874 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6877 gtk_widget_style_get (widget,
6878 "expander-size", &tree_view->priv->expander_size,
6880 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6882 for (list = tree_view->priv->columns; list; list = list->next)
6884 column = list->data;
6885 _pspp_sheet_view_column_cell_set_dirty (column);
6888 tree_view->priv->fixed_height = -1;
6890 /* Invalidate cached button style. */
6891 if (tree_view->priv->button_style)
6893 g_object_unref (tree_view->priv->button_style);
6894 tree_view->priv->button_style = NULL;
6897 gtk_widget_queue_resize (widget);
6902 pspp_sheet_view_set_focus_child (GtkContainer *container,
6905 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6908 for (list = tree_view->priv->columns; list; list = list->next)
6910 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6912 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6917 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6921 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6922 GtkAdjustment *hadj,
6923 GtkAdjustment *vadj)
6925 gboolean need_adjust = FALSE;
6927 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6930 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6932 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6934 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
6936 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6938 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
6940 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
6941 pspp_sheet_view_adjustment_changed,
6943 g_object_unref (tree_view->priv->hadjustment);
6946 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
6948 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
6949 pspp_sheet_view_adjustment_changed,
6951 g_object_unref (tree_view->priv->vadjustment);
6954 if (tree_view->priv->hadjustment != hadj)
6956 tree_view->priv->hadjustment = hadj;
6957 g_object_ref_sink (tree_view->priv->hadjustment);
6959 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
6960 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6965 if (tree_view->priv->vadjustment != vadj)
6967 tree_view->priv->vadjustment = vadj;
6968 g_object_ref_sink (tree_view->priv->vadjustment);
6970 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
6971 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6977 pspp_sheet_view_adjustment_changed (NULL, tree_view);
6982 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
6983 GtkMovementStep step,
6986 PsppSheetSelectMode mode;
6987 GdkModifierType state;
6989 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
6990 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
6991 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
6992 step == GTK_MOVEMENT_DISPLAY_LINES ||
6993 step == GTK_MOVEMENT_PAGES ||
6994 step == GTK_MOVEMENT_BUFFER_ENDS ||
6995 step == GTK_MOVEMENT_DISPLAY_LINE_ENDS, FALSE);
6997 if (tree_view->priv->row_count == 0)
6999 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7002 pspp_sheet_view_stop_editing (tree_view, FALSE);
7003 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7004 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7007 if (gtk_get_current_event_state (&state))
7009 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7010 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
7011 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
7012 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
7014 /* else we assume not pressed */
7018 case GTK_MOVEMENT_LOGICAL_POSITIONS:
7019 pspp_sheet_view_move_cursor_tab (tree_view, count);
7021 case GTK_MOVEMENT_VISUAL_POSITIONS:
7022 pspp_sheet_view_move_cursor_left_right (tree_view, count, mode);
7024 case GTK_MOVEMENT_DISPLAY_LINES:
7025 pspp_sheet_view_move_cursor_up_down (tree_view, count, mode);
7027 case GTK_MOVEMENT_PAGES:
7028 pspp_sheet_view_move_cursor_page_up_down (tree_view, count, mode);
7030 case GTK_MOVEMENT_BUFFER_ENDS:
7031 pspp_sheet_view_move_cursor_start_end (tree_view, count, mode);
7033 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
7034 pspp_sheet_view_move_cursor_line_start_end (tree_view, count, mode);
7037 g_assert_not_reached ();
7044 pspp_sheet_view_put (PsppSheetView *tree_view,
7045 GtkWidget *child_widget,
7046 /* in bin_window coordinates */
7052 PsppSheetViewChild *child;
7054 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7055 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7057 child = g_slice_new (PsppSheetViewChild);
7059 child->widget = child_widget;
7062 child->width = width;
7063 child->height = height;
7065 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7067 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7068 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7070 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7074 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7076 /* in tree coordinates */
7082 PsppSheetViewChild *child = NULL;
7084 GdkRectangle allocation;
7086 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7087 g_return_if_fail (GTK_IS_WIDGET (widget));
7089 for (list = tree_view->priv->children; list; list = list->next)
7091 if (((PsppSheetViewChild *)list->data)->widget == widget)
7100 allocation.x = child->x = x;
7101 allocation.y = child->y = y;
7102 allocation.width = child->width = width;
7103 allocation.height = child->height = height;
7105 if (gtk_widget_get_realized (widget))
7106 gtk_widget_size_allocate (widget, &allocation);
7110 /* TreeModel Callbacks
7114 pspp_sheet_view_row_changed (GtkTreeModel *model,
7119 PsppSheetView *tree_view = (PsppSheetView *)data;
7121 gboolean free_path = FALSE;
7122 GtkTreePath *cursor_path;
7124 g_return_if_fail (path != NULL || iter != NULL);
7126 if (tree_view->priv->cursor != NULL)
7127 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7131 if (tree_view->priv->edited_column &&
7132 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7133 pspp_sheet_view_stop_editing (tree_view, TRUE);
7135 if (cursor_path != NULL)
7136 gtk_tree_path_free (cursor_path);
7140 path = gtk_tree_model_get_path (model, iter);
7143 else if (iter == NULL)
7144 gtk_tree_model_get_iter (model, iter, path);
7146 _pspp_sheet_view_find_node (tree_view,
7152 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7153 pspp_sheet_view_node_queue_redraw (tree_view, node);
7157 gtk_tree_path_free (path);
7161 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7166 PsppSheetView *tree_view = (PsppSheetView *) data;
7169 gint height = tree_view->priv->fixed_height;
7170 gboolean free_path = FALSE;
7171 gboolean node_visible = TRUE;
7173 g_return_if_fail (path != NULL || iter != NULL);
7177 path = gtk_tree_model_get_path (model, iter);
7180 else if (iter == NULL)
7181 gtk_tree_model_get_iter (model, iter, path);
7183 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7185 /* Update all row-references */
7186 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7187 indices = gtk_tree_path_get_indices (path);
7188 tmpnode = indices[0];
7190 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7194 if (node_visible && node_is_visible (tree_view, tmpnode))
7195 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7197 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7200 install_presize_handler (tree_view);
7202 gtk_tree_path_free (path);
7206 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7210 PsppSheetView *tree_view = (PsppSheetView *)data;
7213 g_return_if_fail (path != NULL);
7215 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7217 _pspp_sheet_view_find_node (tree_view, path, &node);
7222 range_tower_delete (tree_view->priv->selected, node, 1);
7224 /* Ensure we don't have a dangling pointer to a dead node */
7225 ensure_unprelighted (tree_view);
7227 /* Cancel editting if we've started */
7228 pspp_sheet_view_stop_editing (tree_view, TRUE);
7230 if (tree_view->priv->destroy_count_func)
7232 gint child_count = 0;
7233 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7236 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7238 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7240 gtk_tree_row_reference_free (tree_view->priv->top_row);
7241 tree_view->priv->top_row = NULL;
7244 install_scroll_sync_handler (tree_view);
7246 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7249 if (helper_data.changed)
7250 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7255 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7256 GtkTreePath *parent,
7261 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7264 /* XXX need to adjust selection */
7265 len = gtk_tree_model_iter_n_children (model, iter);
7270 gtk_tree_row_reference_reordered (G_OBJECT (data),
7275 if (gtk_tree_path_get_depth (parent) != 0)
7278 if (tree_view->priv->edited_column)
7279 pspp_sheet_view_stop_editing (tree_view, TRUE);
7281 /* we need to be unprelighted */
7282 ensure_unprelighted (tree_view);
7284 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7286 pspp_sheet_view_dy_to_top_row (tree_view);
7290 /* Internal tree functions
7295 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7296 PsppSheetViewColumn *column,
7300 PsppSheetViewColumn *tmp_column = NULL;
7311 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7314 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7316 list = (rtl ? list->prev : list->next))
7318 tmp_column = list->data;
7320 if (tmp_column == column)
7323 if (tmp_column->visible)
7324 total_width += tmp_column->width;
7327 if (tmp_column != column)
7329 g_warning (G_STRLOC": passed-in column isn't in the tree");
7338 if (column->visible)
7339 *x2 = total_width + column->width;
7341 *x2 = total_width; /* width of 0 */
7345 /* Make sure the node is visible vertically */
7347 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7350 gint node_dy, height;
7351 GtkTreePath *path = NULL;
7353 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7356 /* just return if the node is visible, avoiding a costly expose */
7357 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7358 height = ROW_HEIGHT (tree_view);
7359 if (node_dy >= tree_view->priv->vadjustment->value
7360 && node_dy + height <= (tree_view->priv->vadjustment->value
7361 + tree_view->priv->vadjustment->page_size))
7364 path = _pspp_sheet_view_find_path (tree_view, node);
7367 /* We process updates because we want to clear old selected items when we scroll.
7368 * if this is removed, we get a "selection streak" at the bottom. */
7369 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7370 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7371 gtk_tree_path_free (path);
7376 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7377 PsppSheetViewColumn *column,
7378 gboolean focus_to_cell)
7385 x = column->allocation.x;
7386 width = column->allocation.width;
7388 if (width > tree_view->priv->hadjustment->page_size)
7390 /* The column is larger than the horizontal page size. If the
7391 * column has cells which can be focussed individually, then we make
7392 * sure the cell which gets focus is fully visible (if even the
7393 * focus cell is bigger than the page size, we make sure the
7394 * left-hand side of the cell is visible).
7396 * If the column does not have those so-called special cells, we
7397 * make sure the left-hand side of the column is visible.
7400 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7402 GtkTreePath *cursor_path;
7403 GdkRectangle background_area, cell_area, focus_area;
7405 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7407 pspp_sheet_view_get_cell_area (tree_view,
7408 cursor_path, column, &cell_area);
7409 pspp_sheet_view_get_background_area (tree_view,
7410 cursor_path, column,
7413 gtk_tree_path_free (cursor_path);
7415 _pspp_sheet_view_column_get_focus_area (column,
7421 width = focus_area.width;
7423 if (width < tree_view->priv->hadjustment->page_size)
7425 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7426 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7427 x + width - tree_view->priv->hadjustment->page_size);
7428 else if (tree_view->priv->hadjustment->value > x)
7429 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7433 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7435 tree_view->priv->hadjustment->lower,
7436 tree_view->priv->hadjustment->upper
7437 - tree_view->priv->hadjustment->page_size));
7441 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7442 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7443 x + width - tree_view->priv->hadjustment->page_size);
7444 else if (tree_view->priv->hadjustment->value > x)
7445 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7450 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7455 path = gtk_tree_path_new ();
7457 gtk_tree_path_append_index (path, node);
7462 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7466 gint *indices = gtk_tree_path_get_indices (path);
7467 gint depth = gtk_tree_path_get_depth (path);
7470 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7476 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7479 gboolean add_shifted_binding,
7480 GtkMovementStep step,
7484 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7489 if (add_shifted_binding)
7490 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7495 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7498 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7503 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7510 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7511 PsppSheetViewColumn *column)
7513 PsppSheetViewColumn *left_column;
7514 PsppSheetViewColumn *cur_column = NULL;
7515 PsppSheetViewColumnReorder *reorder;
7520 /* We want to precalculate the motion list such that we know what column slots
7524 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7526 /* First, identify all possible drop spots */
7528 tmp_list = g_list_last (tree_view->priv->columns);
7530 tmp_list = g_list_first (tree_view->priv->columns);
7534 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7535 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7537 if (cur_column->visible == FALSE)
7540 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7541 if (left_column != column && cur_column != column &&
7542 tree_view->priv->column_drop_func &&
7543 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7545 left_column = cur_column;
7548 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7549 reorder->left_column = left_column;
7550 left_column = reorder->right_column = cur_column;
7552 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7555 /* Add the last one */
7556 if (tree_view->priv->column_drop_func == NULL ||
7557 ((left_column != column) &&
7558 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7560 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7561 reorder->left_column = left_column;
7562 reorder->right_column = NULL;
7563 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7566 /* We quickly check to see if it even makes sense to reorder columns. */
7567 /* If there is nothing that can be moved, then we return */
7569 if (tree_view->priv->column_drag_info == NULL)
7572 /* We know there are always 2 slots possbile, as you can always return column. */
7573 /* If that's all there is, return */
7574 if (tree_view->priv->column_drag_info->next == NULL ||
7575 (tree_view->priv->column_drag_info->next->next == NULL &&
7576 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7577 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7579 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7580 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7581 g_list_free (tree_view->priv->column_drag_info);
7582 tree_view->priv->column_drag_info = NULL;
7585 /* We fill in the ranges for the columns, now that we've isolated them */
7586 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7588 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7590 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7592 reorder->left_align = left;
7593 if (tmp_list->next != NULL)
7595 g_assert (tmp_list->next->data);
7596 left = reorder->right_align = (reorder->right_column->allocation.x +
7597 reorder->right_column->allocation.width +
7598 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7604 gdk_drawable_get_size (tree_view->priv->header_window, &width, NULL);
7605 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7611 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7612 PsppSheetViewColumn *column)
7614 GdkEvent *send_event;
7615 GtkAllocation allocation;
7616 gint x, y, width, height;
7617 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7618 GdkDisplay *display = gdk_screen_get_display (screen);
7620 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7621 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7622 g_return_if_fail (column->button);
7624 pspp_sheet_view_set_column_drag_info (tree_view, column);
7626 if (tree_view->priv->column_drag_info == NULL)
7629 if (tree_view->priv->drag_window == NULL)
7631 GdkWindowAttr attributes;
7632 guint attributes_mask;
7634 attributes.window_type = GDK_WINDOW_CHILD;
7635 attributes.wclass = GDK_INPUT_OUTPUT;
7636 attributes.x = column->allocation.x;
7638 attributes.width = column->allocation.width;
7639 attributes.height = column->allocation.height;
7640 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7641 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
7642 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7643 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
7645 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7648 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7651 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7652 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7654 gtk_grab_remove (column->button);
7656 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7657 send_event->crossing.send_event = TRUE;
7658 send_event->crossing.window = g_object_ref (GTK_BUTTON (column->button)->event_window);
7659 send_event->crossing.subwindow = NULL;
7660 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7661 send_event->crossing.time = GDK_CURRENT_TIME;
7663 gtk_propagate_event (column->button, send_event);
7664 gdk_event_free (send_event);
7666 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7667 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7668 send_event->button.send_event = TRUE;
7669 send_event->button.time = GDK_CURRENT_TIME;
7670 send_event->button.x = -1;
7671 send_event->button.y = -1;
7672 send_event->button.axes = NULL;
7673 send_event->button.state = 0;
7674 send_event->button.button = 1;
7675 send_event->button.device = gdk_display_get_core_pointer (display);
7676 send_event->button.x_root = 0;
7677 send_event->button.y_root = 0;
7679 gtk_propagate_event (column->button, send_event);
7680 gdk_event_free (send_event);
7682 /* Kids, don't try this at home */
7683 g_object_ref (column->button);
7684 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7685 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7686 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7687 g_object_unref (column->button);
7689 tree_view->priv->drag_column_x = column->allocation.x;
7690 allocation = column->allocation;
7692 gtk_widget_size_allocate (column->button, &allocation);
7693 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7695 tree_view->priv->drag_column = column;
7696 gdk_window_show (tree_view->priv->drag_window);
7698 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7699 gdk_drawable_get_size (tree_view->priv->header_window, &width, &height);
7701 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7702 while (gtk_events_pending ())
7703 gtk_main_iteration ();
7705 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7706 gdk_pointer_grab (tree_view->priv->drag_window,
7708 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7709 NULL, NULL, GDK_CURRENT_TIME);
7710 gdk_keyboard_grab (tree_view->priv->drag_window,
7716 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7718 const GdkRectangle *clip_rect)
7722 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7726 rect.width = MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width);
7728 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7729 rect.height = ROW_HEIGHT (tree_view);
7733 GdkRectangle new_rect;
7735 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7737 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7741 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7746 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7748 const GdkRectangle *clip_rect)
7752 _pspp_sheet_view_find_node (tree_view, path, &node);
7755 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7759 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7762 GtkTreePath *cursor_path;
7764 if ((tree_view->priv->row_count == 0) ||
7765 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7769 if (tree_view->priv->cursor)
7770 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7772 if (cursor_path == NULL)
7774 /* There's no cursor. Move the cursor to the first selected row, if any
7775 * are selected, otherwise to the first row in the sheetview.
7777 GList *selected_rows;
7778 GtkTreeModel *model;
7779 PsppSheetSelection *selection;
7781 selection = pspp_sheet_view_get_selection (tree_view);
7782 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7786 /* XXX we could avoid doing O(n) work to get this result */
7787 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7788 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7789 g_list_free (selected_rows);
7793 cursor_path = gtk_tree_path_new_first ();
7794 search_first_focusable_path (tree_view, &cursor_path,
7798 gtk_tree_row_reference_free (tree_view->priv->cursor);
7799 tree_view->priv->cursor = NULL;
7803 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7804 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7805 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE, 0);
7807 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, 0);
7813 /* Now find a column for the cursor. */
7814 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7816 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7817 gtk_tree_path_free (cursor_path);
7819 if (tree_view->priv->focus_column == NULL)
7822 for (list = tree_view->priv->columns; list; list = list->next)
7824 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7826 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7827 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7828 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7838 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7840 PsppSheetSelectMode mode)
7842 gint selection_count;
7843 int cursor_node = -1;
7844 int new_cursor_node = -1;
7845 GtkTreePath *cursor_path = NULL;
7846 gboolean grab_focus = TRUE;
7848 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7852 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7853 /* FIXME: we lost the cursor; should we get the first? */
7856 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7857 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7859 if (cursor_node < 0)
7860 /* FIXME: we lost the cursor; should we get the first? */
7863 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7865 if (selection_count == 0
7866 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7867 && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
7869 /* Don't move the cursor, but just select the current node */
7870 new_cursor_node = cursor_node;
7875 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7877 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7880 gtk_tree_path_free (cursor_path);
7882 if (new_cursor_node)
7884 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7886 search_first_focusable_path (tree_view, &cursor_path,
7891 gtk_tree_path_free (cursor_path);
7895 * If the list has only one item and multi-selection is set then select
7896 * the row (if not yet selected).
7898 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7899 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7900 new_cursor_node < 0)
7903 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7905 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7907 if (new_cursor_node < 0
7908 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7910 new_cursor_node = cursor_node;
7914 new_cursor_node = -1;
7918 if (new_cursor_node >= 0)
7920 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7921 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE, mode);
7922 gtk_tree_path_free (cursor_path);
7926 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7928 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
7930 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7932 GTK_DIR_UP : GTK_DIR_DOWN))
7934 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
7937 gtk_widget_child_focus (toplevel,
7939 GTK_DIR_TAB_BACKWARD :
7940 GTK_DIR_TAB_FORWARD);
7947 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7952 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7954 return new_cursor_node >= 0;
7958 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
7960 PsppSheetSelectMode mode)
7962 int cursor_node = -1;
7963 GtkTreePath *old_cursor_path = NULL;
7964 GtkTreePath *cursor_path = NULL;
7965 int start_cursor_node = -1;
7968 gint vertical_separator;
7970 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7973 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
7974 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7976 /* This is sorta weird. Focus in should give us a cursor */
7979 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
7980 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
7982 if (cursor_node < 0)
7984 /* FIXME: we lost the cursor. Should we try to get one? */
7985 gtk_tree_path_free (old_cursor_path);
7989 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7990 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
7991 y += tree_view->priv->cursor_offset;
7992 y += count * (int)tree_view->priv->vadjustment->page_increment;
7993 y = CLAMP (y, (gint)tree_view->priv->vadjustment->lower, (gint)tree_view->priv->vadjustment->upper - vertical_separator);
7995 if (y >= tree_view->priv->height)
7996 y = tree_view->priv->height - 1;
7998 tree_view->priv->cursor_offset =
7999 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
8001 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
8003 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
8004 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
8007 y -= tree_view->priv->cursor_offset;
8008 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8010 start_cursor_node = cursor_node;
8012 if (! search_first_focusable_path (tree_view, &cursor_path,
8016 /* It looks like we reached the end of the view without finding
8017 * a focusable row. We will step backwards to find the last
8020 cursor_node = start_cursor_node;
8021 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8023 search_first_focusable_path (tree_view, &cursor_path,
8032 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8034 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, mode);
8037 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
8038 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8039 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8041 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
8042 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8044 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8047 gtk_tree_path_free (old_cursor_path);
8048 gtk_tree_path_free (cursor_path);
8052 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
8054 PsppSheetSelectMode mode)
8056 int cursor_node = -1;
8057 GtkTreePath *cursor_path = NULL;
8058 PsppSheetViewColumn *column;
8061 gboolean found_column = FALSE;
8064 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8066 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8069 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8070 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8074 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8075 if (cursor_node < 0)
8077 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8079 gtk_tree_path_free (cursor_path);
8082 gtk_tree_path_free (cursor_path);
8084 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8085 if (tree_view->priv->focus_column)
8087 for (; list; list = (rtl ? list->prev : list->next))
8089 if (list->data == tree_view->priv->focus_column)
8096 gboolean left, right;
8098 column = list->data;
8099 if (column->visible == FALSE || column->row_head)
8102 pspp_sheet_view_column_cell_set_cell_data (column,
8103 tree_view->priv->model,
8108 right = list->prev ? TRUE : FALSE;
8109 left = list->next ? TRUE : FALSE;
8113 left = list->prev ? TRUE : FALSE;
8114 right = list->next ? TRUE : FALSE;
8117 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8119 tree_view->priv->focus_column = column;
8120 found_column = TRUE;
8125 list = rtl ? list->prev : list->next;
8127 list = rtl ? list->next : list->prev;
8132 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8133 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8134 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8138 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8141 pspp_sheet_view_clamp_column_visible (tree_view,
8142 tree_view->priv->focus_column, TRUE);
8146 pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
8148 PsppSheetSelectMode mode)
8150 int cursor_node = -1;
8151 GtkTreePath *cursor_path = NULL;
8152 PsppSheetViewColumn *column;
8153 PsppSheetViewColumn *found_column;
8158 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8160 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8163 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8164 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8168 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8169 if (cursor_node < 0)
8171 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8173 gtk_tree_path_free (cursor_path);
8176 gtk_tree_path_free (cursor_path);
8178 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8179 if (tree_view->priv->focus_column)
8181 for (; list; list = (rtl ? list->prev : list->next))
8183 if (list->data == tree_view->priv->focus_column)
8188 found_column = NULL;
8191 gboolean left, right;
8193 column = list->data;
8194 if (column->visible == FALSE || column->row_head)
8197 pspp_sheet_view_column_cell_set_cell_data (column,
8198 tree_view->priv->model,
8203 right = list->prev ? TRUE : FALSE;
8204 left = list->next ? TRUE : FALSE;
8208 left = list->prev ? TRUE : FALSE;
8209 right = list->next ? TRUE : FALSE;
8212 if (column->tabbable
8213 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8214 found_column = column;
8218 list = rtl ? list->prev : list->next;
8220 list = rtl ? list->next : list->prev;
8225 tree_view->priv->focus_column = found_column;
8226 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8227 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8228 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8231 pspp_sheet_view_clamp_column_visible (tree_view,
8232 tree_view->priv->focus_column, TRUE);
8236 try_move_cursor_tab (PsppSheetView *tree_view,
8237 gboolean start_at_focus_column,
8240 PsppSheetViewColumn *column;
8242 int cursor_node = -1;
8243 GtkTreePath *cursor_path = NULL;
8247 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8248 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8252 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8253 if (cursor_node < 0)
8255 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8257 gtk_tree_path_free (cursor_path);
8260 gtk_tree_path_free (cursor_path);
8262 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
8263 if (start_at_focus_column)
8266 ? g_list_last (tree_view->priv->columns)
8267 : g_list_first (tree_view->priv->columns));
8268 if (tree_view->priv->focus_column)
8270 for (; list; list = (rtl ? list->prev : list->next))
8272 if (list->data == tree_view->priv->focus_column)
8279 list = (rtl ^ (count == 1)
8280 ? g_list_first (tree_view->priv->columns)
8281 : g_list_last (tree_view->priv->columns));
8286 gboolean left, right;
8288 column = list->data;
8289 if (column->visible == FALSE || !column->tabbable)
8292 pspp_sheet_view_column_cell_set_cell_data (column,
8293 tree_view->priv->model,
8298 right = list->prev ? TRUE : FALSE;
8299 left = list->next ? TRUE : FALSE;
8303 left = list->prev ? TRUE : FALSE;
8304 right = list->next ? TRUE : FALSE;
8307 if (column->tabbable
8308 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8310 tree_view->priv->focus_column = column;
8311 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8312 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8313 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8318 list = rtl ? list->prev : list->next;
8320 list = rtl ? list->next : list->prev;
8327 pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
8330 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8333 if (!try_move_cursor_tab (tree_view, TRUE, count))
8335 if (pspp_sheet_view_move_cursor_up_down (tree_view, count, 0)
8336 && !try_move_cursor_tab (tree_view, FALSE, count))
8337 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8340 pspp_sheet_view_clamp_column_visible (tree_view,
8341 tree_view->priv->focus_column, TRUE);
8345 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8347 PsppSheetSelectMode mode)
8351 GtkTreePath *old_path;
8353 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8356 g_return_if_fail (tree_view->priv->row_count > 0);
8358 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8362 /* Now go forward to find the first focusable row. */
8363 path = _pspp_sheet_view_find_path (tree_view, 0);
8364 search_first_focusable_path (tree_view, &path,
8365 TRUE, &cursor_node);
8369 /* Now go backwards to find last focusable row. */
8370 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8371 search_first_focusable_path (tree_view, &path,
8372 FALSE, &cursor_node);
8378 if (gtk_tree_path_compare (old_path, path))
8380 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
8381 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8385 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8389 gtk_tree_path_free (old_path);
8390 gtk_tree_path_free (path);
8394 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8396 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8399 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8400 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8403 pspp_sheet_selection_select_all (tree_view->priv->selection);
8409 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8411 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8414 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8415 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8418 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8424 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8425 gboolean start_editing,
8426 PsppSheetSelectMode mode)
8429 int cursor_node = -1;
8430 GtkTreePath *cursor_path = NULL;
8432 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8435 if (tree_view->priv->cursor)
8436 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8438 if (cursor_path == NULL)
8441 _pspp_sheet_view_find_node (tree_view, cursor_path,
8444 if (cursor_node < 0)
8446 gtk_tree_path_free (cursor_path);
8450 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND) && start_editing &&
8451 tree_view->priv->focus_column)
8453 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8455 gtk_tree_path_free (cursor_path);
8460 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8466 /* We bail out if the original (tree, node) don't exist anymore after
8467 * handling the selection-changed callback. We do return TRUE because
8468 * the key press has been handled at this point.
8470 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8472 if (cursor_node != new_node)
8475 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8477 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8478 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8480 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
8481 pspp_sheet_view_row_activated (tree_view, cursor_path,
8482 tree_view->priv->focus_column);
8484 gtk_tree_path_free (cursor_path);
8490 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8493 int cursor_node = -1;
8494 GtkTreePath *cursor_path = NULL;
8496 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8500 if (tree_view->priv->cursor)
8501 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8503 if (cursor_path == NULL)
8506 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8507 if (cursor_node < 0)
8509 gtk_tree_path_free (cursor_path);
8513 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8516 PSPP_SHEET_SELECT_MODE_TOGGLE,
8519 /* We bail out if the original (tree, node) don't exist anymore after
8520 * handling the selection-changed callback. We do return TRUE because
8521 * the key press has been handled at this point.
8523 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8525 if (cursor_node != new_node)
8528 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8530 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8531 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8532 gtk_tree_path_free (cursor_path);
8538 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8540 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8541 tree_view->priv->typeselect_flush_timeout = 0;
8546 /* Cut and paste from gtkwindow.c */
8548 send_focus_change (GtkWidget *widget,
8551 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8553 g_object_ref (widget);
8556 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
8558 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
8560 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8561 fevent->focus_change.window = g_object_ref (widget->window);
8562 fevent->focus_change.in = in;
8564 gtk_widget_event (widget, fevent);
8566 g_object_notify (G_OBJECT (widget), "has-focus");
8568 g_object_unref (widget);
8569 gdk_event_free (fevent);
8573 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8575 GtkWidget *frame, *vbox, *toplevel;
8578 if (tree_view->priv->search_custom_entry_set)
8581 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8582 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8584 if (tree_view->priv->search_window != NULL)
8586 if (GTK_WINDOW (toplevel)->group)
8587 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8588 GTK_WINDOW (tree_view->priv->search_window));
8589 else if (GTK_WINDOW (tree_view->priv->search_window)->group)
8590 gtk_window_group_remove_window (GTK_WINDOW (tree_view->priv->search_window)->group,
8591 GTK_WINDOW (tree_view->priv->search_window));
8592 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8596 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8597 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8599 if (GTK_WINDOW (toplevel)->group)
8600 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8601 GTK_WINDOW (tree_view->priv->search_window));
8603 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8604 GDK_WINDOW_TYPE_HINT_UTILITY);
8605 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8606 g_signal_connect (tree_view->priv->search_window, "delete-event",
8607 G_CALLBACK (pspp_sheet_view_search_delete_event),
8609 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8610 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8612 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8613 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8615 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8616 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8619 frame = gtk_frame_new (NULL);
8620 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8621 gtk_widget_show (frame);
8622 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8624 vbox = gtk_vbox_new (FALSE, 0);
8625 gtk_widget_show (vbox);
8626 gtk_container_add (GTK_CONTAINER (frame), vbox);
8627 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8630 tree_view->priv->search_entry = gtk_entry_new ();
8631 gtk_widget_show (tree_view->priv->search_entry);
8632 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8633 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8635 g_signal_connect (tree_view->priv->search_entry,
8636 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8638 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8640 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8642 gtk_container_add (GTK_CONTAINER (vbox),
8643 tree_view->priv->search_entry);
8645 gtk_widget_realize (tree_view->priv->search_entry);
8648 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8649 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8652 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8653 gboolean keybinding)
8655 /* We only start interactive search if we have focus or the columns
8656 * have focus. If one of our children have focus, we don't want to
8660 gboolean found_focus = FALSE;
8661 GtkWidgetClass *entry_parent_class;
8663 if (!tree_view->priv->enable_search && !keybinding)
8666 if (tree_view->priv->search_custom_entry_set)
8669 if (tree_view->priv->search_window != NULL &&
8670 gtk_widget_get_visible (tree_view->priv->search_window))
8673 for (list = tree_view->priv->columns; list; list = list->next)
8675 PsppSheetViewColumn *column;
8677 column = list->data;
8678 if (! column->visible)
8681 if (column->button && gtk_widget_has_focus (column->button))
8688 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8694 if (tree_view->priv->search_column < 0)
8697 pspp_sheet_view_ensure_interactive_directory (tree_view);
8700 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8703 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8704 gtk_widget_show (tree_view->priv->search_window);
8705 if (tree_view->priv->search_entry_changed_id == 0)
8707 tree_view->priv->search_entry_changed_id =
8708 g_signal_connect (tree_view->priv->search_entry, "changed",
8709 G_CALLBACK (pspp_sheet_view_search_init),
8713 tree_view->priv->typeselect_flush_timeout =
8714 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8715 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8718 /* Grab focus will select all the text. We don't want that to happen, so we
8719 * call the parent instance and bypass the selection change. This is probably
8720 * really non-kosher. */
8721 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8722 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8724 /* send focus-in event */
8725 send_focus_change (tree_view->priv->search_entry, TRUE);
8727 /* search first matching iter */
8728 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8734 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8736 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8739 /* this function returns the new width of the column being resized given
8740 * the column and x position of the cursor; the x cursor position is passed
8741 * in as a pointer and automagicly corrected if it's beyond min/max limits
8744 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8748 PsppSheetViewColumn *column;
8752 /* first translate the x position from widget->window
8753 * to clist->clist_window
8755 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8756 column = g_list_nth (tree_view->priv->columns, i)->data;
8757 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8759 /* Clamp down the value */
8760 if (column->min_width == -1)
8761 width = MAX (column->button_request, width);
8763 width = MAX (column->min_width, width);
8764 if (column->max_width != -1)
8765 width = MIN (width, column->max_width);
8767 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8773 /* FIXME this adjust_allocation is a big cut-and-paste from
8774 * GtkCList, needs to be some "official" way to do this
8784 /* The window to which widget->window is relative */
8785 #define ALLOCATION_WINDOW(widget) \
8786 (!gtk_widget_get_has_window (widget) ? \
8787 (widget)->window : \
8788 gdk_window_get_parent ((widget)->window))
8791 adjust_allocation_recurse (GtkWidget *widget,
8794 ScrollData *scroll_data = data;
8796 /* Need to really size allocate instead of just poking
8797 * into widget->allocation if the widget is not realized.
8798 * FIXME someone figure out why this was.
8800 if (!gtk_widget_get_realized (widget))
8802 if (gtk_widget_get_visible (widget))
8804 GdkRectangle tmp_rectangle = widget->allocation;
8805 tmp_rectangle.x += scroll_data->dx;
8806 tmp_rectangle.y += scroll_data->dy;
8808 gtk_widget_size_allocate (widget, &tmp_rectangle);
8813 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8815 widget->allocation.x += scroll_data->dx;
8816 widget->allocation.y += scroll_data->dy;
8818 if (GTK_IS_CONTAINER (widget))
8819 gtk_container_forall (GTK_CONTAINER (widget),
8820 adjust_allocation_recurse,
8827 adjust_allocation (GtkWidget *widget,
8831 ScrollData scroll_data;
8833 if (gtk_widget_get_realized (widget))
8834 scroll_data.window = ALLOCATION_WINDOW (widget);
8836 scroll_data.window = NULL;
8838 scroll_data.dx = dx;
8839 scroll_data.dy = dy;
8841 adjust_allocation_recurse (widget, &scroll_data);
8845 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8849 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8850 PsppSheetView *tree_view)
8852 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8857 gdk_window_move (tree_view->priv->bin_window,
8858 - tree_view->priv->hadjustment->value,
8859 TREE_VIEW_HEADER_HEIGHT (tree_view));
8860 gdk_window_move (tree_view->priv->header_window,
8861 - tree_view->priv->hadjustment->value,
8863 dy = tree_view->priv->dy - (int) tree_view->priv->vadjustment->value;
8866 update_prelight (tree_view,
8867 tree_view->priv->event_last_x,
8868 tree_view->priv->event_last_y - dy);
8870 if (tree_view->priv->edited_column &&
8871 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8875 PsppSheetViewChild *child = NULL;
8877 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8878 adjust_allocation (widget, 0, dy);
8880 for (list = tree_view->priv->children; list; list = list->next)
8882 child = (PsppSheetViewChild *)list->data;
8883 if (child->widget == widget)
8891 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8893 if (tree_view->priv->dy != (int) tree_view->priv->vadjustment->value)
8895 /* update our dy and top_row */
8896 tree_view->priv->dy = (int) tree_view->priv->vadjustment->value;
8898 if (!tree_view->priv->in_top_row_to_dy)
8899 pspp_sheet_view_dy_to_top_row (tree_view);
8902 for (list = tree_view->priv->columns; list; list = list->next)
8904 PsppSheetViewColumn *column = list->data;
8905 GtkAllocation *allocation = &column->allocation;
8907 if (span_intersects (allocation->x, allocation->width,
8908 tree_view->priv->hadjustment->value,
8909 GTK_WIDGET (tree_view)->allocation.width))
8911 pspp_sheet_view_column_set_need_button (column, TRUE);
8912 if (!column->button)
8913 pspp_sheet_view_column_update_button (column);
8925 * pspp_sheet_view_new:
8927 * Creates a new #PsppSheetView widget.
8929 * Return value: A newly created #PsppSheetView widget.
8932 pspp_sheet_view_new (void)
8934 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8938 * pspp_sheet_view_new_with_model:
8939 * @model: the model.
8941 * Creates a new #PsppSheetView widget with the model initialized to @model.
8943 * Return value: A newly created #PsppSheetView widget.
8946 pspp_sheet_view_new_with_model (GtkTreeModel *model)
8948 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
8955 * pspp_sheet_view_get_model:
8956 * @tree_view: a #PsppSheetView
8958 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
8961 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
8964 pspp_sheet_view_get_model (PsppSheetView *tree_view)
8966 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8968 return tree_view->priv->model;
8972 * pspp_sheet_view_set_model:
8973 * @tree_view: A #GtkTreeNode.
8974 * @model: (allow-none): The model.
8976 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
8977 * set, it will remove it before setting the new model. If @model is %NULL,
8978 * then it will unset the old model.
8981 pspp_sheet_view_set_model (PsppSheetView *tree_view,
8982 GtkTreeModel *model)
8984 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8985 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
8987 if (model == tree_view->priv->model)
8990 if (tree_view->priv->scroll_to_path)
8992 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8993 tree_view->priv->scroll_to_path = NULL;
8996 if (tree_view->priv->model)
8998 GList *tmplist = tree_view->priv->columns;
9000 if (tree_view->priv->selected)
9001 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
9002 pspp_sheet_view_stop_editing (tree_view, TRUE);
9004 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9005 pspp_sheet_view_row_changed,
9007 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9008 pspp_sheet_view_row_inserted,
9010 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9011 pspp_sheet_view_row_deleted,
9013 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9014 pspp_sheet_view_rows_reordered,
9017 for (; tmplist; tmplist = tmplist->next)
9018 _pspp_sheet_view_column_unset_model (tmplist->data,
9019 tree_view->priv->model);
9021 tree_view->priv->prelight_node = -1;
9023 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
9024 tree_view->priv->drag_dest_row = NULL;
9025 gtk_tree_row_reference_free (tree_view->priv->cursor);
9026 tree_view->priv->cursor = NULL;
9027 gtk_tree_row_reference_free (tree_view->priv->anchor);
9028 tree_view->priv->anchor = NULL;
9029 gtk_tree_row_reference_free (tree_view->priv->top_row);
9030 tree_view->priv->top_row = NULL;
9031 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9032 tree_view->priv->scroll_to_path = NULL;
9034 tree_view->priv->scroll_to_column = NULL;
9036 g_object_unref (tree_view->priv->model);
9038 tree_view->priv->search_column = -1;
9039 tree_view->priv->fixed_height = -1;
9040 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
9041 tree_view->priv->last_button_x = -1;
9042 tree_view->priv->last_button_y = -1;
9045 tree_view->priv->model = model;
9047 if (tree_view->priv->model)
9051 if (tree_view->priv->search_column == -1)
9053 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
9055 GType type = gtk_tree_model_get_column_type (model, i);
9057 if (g_value_type_transformable (type, G_TYPE_STRING))
9059 tree_view->priv->search_column = i;
9065 g_object_ref (tree_view->priv->model);
9066 g_signal_connect (tree_view->priv->model,
9068 G_CALLBACK (pspp_sheet_view_row_changed),
9070 g_signal_connect (tree_view->priv->model,
9072 G_CALLBACK (pspp_sheet_view_row_inserted),
9074 g_signal_connect (tree_view->priv->model,
9076 G_CALLBACK (pspp_sheet_view_row_deleted),
9078 g_signal_connect (tree_view->priv->model,
9080 G_CALLBACK (pspp_sheet_view_rows_reordered),
9083 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
9085 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
9086 install_presize_handler (tree_view);
9089 g_object_notify (G_OBJECT (tree_view), "model");
9091 if (tree_view->priv->selection)
9092 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
9094 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9095 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9099 * pspp_sheet_view_get_selection:
9100 * @tree_view: A #PsppSheetView.
9102 * Gets the #PsppSheetSelection associated with @tree_view.
9104 * Return value: A #PsppSheetSelection object.
9106 PsppSheetSelection *
9107 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
9109 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9111 return tree_view->priv->selection;
9115 * pspp_sheet_view_get_hadjustment:
9116 * @tree_view: A #PsppSheetView
9118 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
9120 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9124 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
9126 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9128 if (tree_view->priv->hadjustment == NULL)
9129 pspp_sheet_view_set_hadjustment (tree_view, NULL);
9131 return tree_view->priv->hadjustment;
9135 * pspp_sheet_view_set_hadjustment:
9136 * @tree_view: A #PsppSheetView
9137 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9139 * Sets the #GtkAdjustment for the current horizontal aspect.
9142 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
9143 GtkAdjustment *adjustment)
9145 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9147 pspp_sheet_view_set_adjustments (tree_view,
9149 tree_view->priv->vadjustment);
9151 g_object_notify (G_OBJECT (tree_view), "hadjustment");
9155 * pspp_sheet_view_get_vadjustment:
9156 * @tree_view: A #PsppSheetView
9158 * Gets the #GtkAdjustment currently being used for the vertical aspect.
9160 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9164 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
9166 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9168 if (tree_view->priv->vadjustment == NULL)
9169 pspp_sheet_view_set_vadjustment (tree_view, NULL);
9171 return tree_view->priv->vadjustment;
9175 * pspp_sheet_view_set_vadjustment:
9176 * @tree_view: A #PsppSheetView
9177 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9179 * Sets the #GtkAdjustment for the current vertical aspect.
9182 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
9183 GtkAdjustment *adjustment)
9185 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9187 pspp_sheet_view_set_adjustments (tree_view,
9188 tree_view->priv->hadjustment,
9191 g_object_notify (G_OBJECT (tree_view), "vadjustment");
9194 /* Column and header operations */
9197 * pspp_sheet_view_get_headers_visible:
9198 * @tree_view: A #PsppSheetView.
9200 * Returns %TRUE if the headers on the @tree_view are visible.
9202 * Return value: Whether the headers are visible or not.
9205 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
9207 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9209 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9213 * pspp_sheet_view_set_headers_visible:
9214 * @tree_view: A #PsppSheetView.
9215 * @headers_visible: %TRUE if the headers are visible
9217 * Sets the visibility state of the headers.
9220 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
9221 gboolean headers_visible)
9225 PsppSheetViewColumn *column;
9227 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9229 headers_visible = !! headers_visible;
9231 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
9234 if (headers_visible)
9235 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9237 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9239 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9241 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
9242 if (headers_visible)
9244 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));
9246 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9247 pspp_sheet_view_map_buttons (tree_view);
9251 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9253 for (list = tree_view->priv->columns; list; list = list->next)
9255 column = list->data;
9257 gtk_widget_unmap (column->button);
9259 gdk_window_hide (tree_view->priv->header_window);
9263 tree_view->priv->vadjustment->page_size = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
9264 tree_view->priv->vadjustment->page_increment = (GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2;
9265 tree_view->priv->vadjustment->lower = 0;
9266 tree_view->priv->vadjustment->upper = tree_view->priv->height;
9267 gtk_adjustment_changed (tree_view->priv->vadjustment);
9269 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9271 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9275 * pspp_sheet_view_columns_autosize:
9276 * @tree_view: A #PsppSheetView.
9278 * Resizes all columns to their optimal width. Only works after the
9279 * treeview has been realized.
9282 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9284 gboolean dirty = FALSE;
9286 PsppSheetViewColumn *column;
9288 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9290 for (list = tree_view->priv->columns; list; list = list->next)
9292 column = list->data;
9293 _pspp_sheet_view_column_cell_set_dirty (column);
9298 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9302 * pspp_sheet_view_set_headers_clickable:
9303 * @tree_view: A #PsppSheetView.
9304 * @setting: %TRUE if the columns are clickable.
9306 * Allow the column title buttons to be clicked.
9309 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9314 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9316 for (list = tree_view->priv->columns; list; list = list->next)
9317 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9319 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9324 * pspp_sheet_view_get_headers_clickable:
9325 * @tree_view: A #PsppSheetView.
9327 * Returns whether all header columns are clickable.
9329 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9334 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9338 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9340 for (list = tree_view->priv->columns; list; list = list->next)
9341 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9348 * pspp_sheet_view_set_rules_hint
9349 * @tree_view: a #PsppSheetView
9350 * @setting: %TRUE if the tree requires reading across rows
9352 * This function tells GTK+ that the user interface for your
9353 * application requires users to read across tree rows and associate
9354 * cells with one another. By default, GTK+ will then render the tree
9355 * with alternating row colors. Do <emphasis>not</emphasis> use it
9356 * just because you prefer the appearance of the ruled tree; that's a
9357 * question for the theme. Some themes will draw tree rows in
9358 * alternating colors even when rules are turned off, and users who
9359 * prefer that appearance all the time can choose those themes. You
9360 * should call this function only as a <emphasis>semantic</emphasis>
9361 * hint to the theme engine that your tree makes alternating colors
9362 * useful from a functional standpoint (since it has lots of columns,
9367 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9370 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9372 setting = setting != FALSE;
9374 if (tree_view->priv->has_rules != setting)
9376 tree_view->priv->has_rules = setting;
9377 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9380 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9384 * pspp_sheet_view_get_rules_hint
9385 * @tree_view: a #PsppSheetView
9387 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9389 * Return value: %TRUE if rules are useful for the user of this tree
9392 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9394 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9396 return tree_view->priv->has_rules;
9399 /* Public Column functions
9403 * pspp_sheet_view_append_column:
9404 * @tree_view: A #PsppSheetView.
9405 * @column: The #PsppSheetViewColumn to add.
9407 * Appends @column to the list of columns.
9409 * Return value: The number of columns in @tree_view after appending.
9412 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9413 PsppSheetViewColumn *column)
9415 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9416 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9417 g_return_val_if_fail (column->tree_view == NULL, -1);
9419 return pspp_sheet_view_insert_column (tree_view, column, -1);
9424 * pspp_sheet_view_remove_column:
9425 * @tree_view: A #PsppSheetView.
9426 * @column: The #PsppSheetViewColumn to remove.
9428 * Removes @column from @tree_view.
9430 * Return value: The number of columns in @tree_view after removing.
9433 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9434 PsppSheetViewColumn *column)
9436 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9437 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9438 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9440 if (tree_view->priv->focus_column == column)
9441 tree_view->priv->focus_column = NULL;
9443 if (tree_view->priv->edited_column == column)
9445 pspp_sheet_view_stop_editing (tree_view, TRUE);
9447 /* no need to, but just to be sure ... */
9448 tree_view->priv->edited_column = NULL;
9451 _pspp_sheet_view_column_unset_tree_view (column);
9453 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9454 tree_view->priv->n_columns--;
9456 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9460 _pspp_sheet_view_column_unrealize_button (column);
9461 for (list = tree_view->priv->columns; list; list = list->next)
9463 PsppSheetViewColumn *tmp_column;
9465 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9466 if (tmp_column->visible)
9467 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9470 if (tree_view->priv->n_columns == 0 &&
9471 pspp_sheet_view_get_headers_visible (tree_view) &&
9472 tree_view->priv->header_window)
9473 gdk_window_hide (tree_view->priv->header_window);
9475 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9478 g_object_unref (column);
9479 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9481 return tree_view->priv->n_columns;
9485 * pspp_sheet_view_insert_column:
9486 * @tree_view: A #PsppSheetView.
9487 * @column: The #PsppSheetViewColumn to be inserted.
9488 * @position: The position to insert @column in.
9490 * This inserts the @column into the @tree_view at @position. If @position is
9491 * -1, then the column is inserted at the end.
9493 * Return value: The number of columns in @tree_view after insertion.
9496 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9497 PsppSheetViewColumn *column,
9500 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9501 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9502 g_return_val_if_fail (column->tree_view == NULL, -1);
9504 g_object_ref_sink (column);
9506 if (tree_view->priv->n_columns == 0 &&
9507 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9508 pspp_sheet_view_get_headers_visible (tree_view))
9510 gdk_window_show (tree_view->priv->header_window);
9513 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9515 tree_view->priv->n_columns++;
9517 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9519 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9523 _pspp_sheet_view_column_realize_button (column);
9525 for (list = tree_view->priv->columns; list; list = list->next)
9527 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9528 if (column->visible)
9529 _pspp_sheet_view_column_cell_set_dirty (column);
9531 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9534 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9536 return tree_view->priv->n_columns;
9540 * pspp_sheet_view_insert_column_with_attributes:
9541 * @tree_view: A #PsppSheetView
9542 * @position: The position to insert the new column in.
9543 * @title: The title to set the header to.
9544 * @cell: The #GtkCellRenderer.
9545 * @Varargs: A %NULL-terminated list of attributes.
9547 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9548 * @position. If @position is -1, then the newly created column is inserted at
9549 * the end. The column is initialized with the attributes given.
9551 * Return value: The number of columns in @tree_view after insertion.
9554 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9557 GtkCellRenderer *cell,
9560 PsppSheetViewColumn *column;
9565 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9567 column = pspp_sheet_view_column_new ();
9568 pspp_sheet_view_column_set_title (column, title);
9569 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9571 va_start (args, cell);
9573 attribute = va_arg (args, gchar *);
9575 while (attribute != NULL)
9577 column_id = va_arg (args, gint);
9578 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9579 attribute = va_arg (args, gchar *);
9584 pspp_sheet_view_insert_column (tree_view, column, position);
9586 return tree_view->priv->n_columns;
9590 * pspp_sheet_view_insert_column_with_data_func:
9591 * @tree_view: a #PsppSheetView
9592 * @position: Position to insert, -1 for append
9593 * @title: column title
9594 * @cell: cell renderer for column
9595 * @func: function to set attributes of cell renderer
9596 * @data: data for @func
9597 * @dnotify: destroy notifier for @data
9599 * Convenience function that inserts a new column into the #PsppSheetView
9600 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9601 * attributes (normally using data from the model). See also
9602 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9604 * Return value: number of columns in the tree view post-insert
9607 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9610 GtkCellRenderer *cell,
9611 PsppSheetCellDataFunc func,
9613 GDestroyNotify dnotify)
9615 PsppSheetViewColumn *column;
9617 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9619 column = pspp_sheet_view_column_new ();
9620 pspp_sheet_view_column_set_title (column, title);
9621 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9622 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9624 pspp_sheet_view_insert_column (tree_view, column, position);
9626 return tree_view->priv->n_columns;
9630 * pspp_sheet_view_get_column:
9631 * @tree_view: A #PsppSheetView.
9632 * @n: The position of the column, counting from 0.
9634 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9636 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9639 PsppSheetViewColumn *
9640 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9643 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9645 if (n < 0 || n >= tree_view->priv->n_columns)
9648 if (tree_view->priv->columns == NULL)
9651 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9655 * pspp_sheet_view_get_columns:
9656 * @tree_view: A #PsppSheetView
9658 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9659 * The returned list must be freed with g_list_free ().
9661 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9664 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9666 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9668 return g_list_copy (tree_view->priv->columns);
9672 * pspp_sheet_view_move_column_after:
9673 * @tree_view: A #PsppSheetView
9674 * @column: The #PsppSheetViewColumn to be moved.
9675 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9677 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9678 * @column is placed in the first position.
9681 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9682 PsppSheetViewColumn *column,
9683 PsppSheetViewColumn *base_column)
9685 GList *column_list_el, *base_el = NULL;
9687 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9689 column_list_el = g_list_find (tree_view->priv->columns, column);
9690 g_return_if_fail (column_list_el != NULL);
9694 base_el = g_list_find (tree_view->priv->columns, base_column);
9695 g_return_if_fail (base_el != NULL);
9698 if (column_list_el->prev == base_el)
9701 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9702 if (base_el == NULL)
9704 column_list_el->prev = NULL;
9705 column_list_el->next = tree_view->priv->columns;
9706 if (column_list_el->next)
9707 column_list_el->next->prev = column_list_el;
9708 tree_view->priv->columns = column_list_el;
9712 column_list_el->prev = base_el;
9713 column_list_el->next = base_el->next;
9714 if (column_list_el->next)
9715 column_list_el->next->prev = column_list_el;
9716 base_el->next = column_list_el;
9719 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9721 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9722 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9725 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9729 * pspp_sheet_view_set_column_drag_function:
9730 * @tree_view: A #PsppSheetView.
9731 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9732 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9733 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9735 * Sets a user function for determining where a column may be dropped when
9736 * dragged. This function is called on every column pair in turn at the
9737 * beginning of a column drag to determine where a drop can take place. The
9738 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9739 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9740 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9741 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9742 * @tree_view reverts to the default behavior of allowing all columns to be
9743 * dropped everywhere.
9746 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9747 PsppSheetViewColumnDropFunc func,
9749 GDestroyNotify destroy)
9751 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9753 if (tree_view->priv->column_drop_func_data_destroy)
9754 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9756 tree_view->priv->column_drop_func = func;
9757 tree_view->priv->column_drop_func_data = user_data;
9758 tree_view->priv->column_drop_func_data_destroy = destroy;
9762 * pspp_sheet_view_scroll_to_point:
9763 * @tree_view: a #PsppSheetView
9764 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9765 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9767 * Scrolls the tree view such that the top-left corner of the visible
9768 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9769 * in tree coordinates. The @tree_view must be realized before
9770 * this function is called. If it isn't, you probably want to be
9771 * using pspp_sheet_view_scroll_to_cell().
9773 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9776 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9780 GtkAdjustment *hadj;
9781 GtkAdjustment *vadj;
9783 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9784 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9786 hadj = tree_view->priv->hadjustment;
9787 vadj = tree_view->priv->vadjustment;
9790 gtk_adjustment_set_value (hadj, CLAMP (tree_x, hadj->lower, hadj->upper - hadj->page_size));
9792 gtk_adjustment_set_value (vadj, CLAMP (tree_y, vadj->lower, vadj->upper - vadj->page_size));
9796 * pspp_sheet_view_scroll_to_cell:
9797 * @tree_view: A #PsppSheetView.
9798 * @path: (allow-none): The path of the row to move to, or %NULL.
9799 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9800 * @use_align: whether to use alignment arguments, or %FALSE.
9801 * @row_align: The vertical alignment of the row specified by @path.
9802 * @col_align: The horizontal alignment of the column specified by @column.
9804 * Moves the alignments of @tree_view to the position specified by @column and
9805 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9806 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9807 * or @path need to be non-%NULL. @row_align determines where the row is
9808 * placed, and @col_align determines where @column is placed. Both are expected
9809 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9810 * right/bottom alignment, 0.5 means center.
9812 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9813 * tree does the minimum amount of work to scroll the cell onto the screen.
9814 * This means that the cell will be scrolled to the edge closest to its current
9815 * position. If the cell is currently visible on the screen, nothing is done.
9817 * This function only works if the model is set, and @path is a valid row on the
9818 * model. If the model changes before the @tree_view is realized, the centered
9819 * path will be modified to reflect this change.
9822 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9824 PsppSheetViewColumn *column,
9829 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9830 g_return_if_fail (tree_view->priv->model != NULL);
9831 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9832 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9833 g_return_if_fail (path != NULL || column != NULL);
9836 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9837 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9839 row_align = CLAMP (row_align, 0.0, 1.0);
9840 col_align = CLAMP (col_align, 0.0, 1.0);
9843 /* Note: Despite the benefits that come from having one code path for the
9844 * scrolling code, we short-circuit validate_visible_area's immplementation as
9845 * it is much slower than just going to the point.
9847 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9848 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9849 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9851 if (tree_view->priv->scroll_to_path)
9852 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9854 tree_view->priv->scroll_to_path = NULL;
9855 tree_view->priv->scroll_to_column = NULL;
9858 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9860 tree_view->priv->scroll_to_column = column;
9861 tree_view->priv->scroll_to_use_align = use_align;
9862 tree_view->priv->scroll_to_row_align = row_align;
9863 tree_view->priv->scroll_to_col_align = col_align;
9865 install_presize_handler (tree_view);
9869 GdkRectangle cell_rect;
9870 GdkRectangle vis_rect;
9871 gint dest_x, dest_y;
9873 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9874 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9876 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9878 dest_x = vis_rect.x;
9879 dest_y = vis_rect.y;
9885 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9889 if (cell_rect.x < vis_rect.x)
9890 dest_x = cell_rect.x;
9891 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9892 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9900 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9901 dest_y = MAX (dest_y, 0);
9905 if (cell_rect.y < vis_rect.y)
9906 dest_y = cell_rect.y;
9907 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9908 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9912 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9917 * pspp_sheet_view_row_activated:
9918 * @tree_view: A #PsppSheetView
9919 * @path: The #GtkTreePath to be activated.
9920 * @column: The #PsppSheetViewColumn to be activated.
9922 * Activates the cell determined by @path and @column.
9925 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9927 PsppSheetViewColumn *column)
9929 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9931 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
9936 * pspp_sheet_view_get_reorderable:
9937 * @tree_view: a #PsppSheetView
9939 * Retrieves whether the user can reorder the tree via drag-and-drop. See
9940 * pspp_sheet_view_set_reorderable().
9942 * Return value: %TRUE if the tree can be reordered.
9945 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
9947 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9949 return tree_view->priv->reorderable;
9953 * pspp_sheet_view_set_reorderable:
9954 * @tree_view: A #PsppSheetView.
9955 * @reorderable: %TRUE, if the tree can be reordered.
9957 * This function is a convenience function to allow you to reorder
9958 * models that support the #GtkDragSourceIface and the
9959 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
9960 * these. If @reorderable is %TRUE, then the user can reorder the
9961 * model by dragging and dropping rows. The developer can listen to
9962 * these changes by connecting to the model's row_inserted and
9963 * row_deleted signals. The reordering is implemented by setting up
9964 * the tree view as a drag source and destination. Therefore, drag and
9965 * drop can not be used in a reorderable view for any other purpose.
9967 * This function does not give you any degree of control over the order -- any
9968 * reordering is allowed. If more control is needed, you should probably
9969 * handle drag and drop manually.
9972 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
9973 gboolean reorderable)
9975 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9977 reorderable = reorderable != FALSE;
9979 if (tree_view->priv->reorderable == reorderable)
9984 const GtkTargetEntry row_targets[] = {
9985 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
9988 pspp_sheet_view_enable_model_drag_source (tree_view,
9991 G_N_ELEMENTS (row_targets),
9993 pspp_sheet_view_enable_model_drag_dest (tree_view,
9995 G_N_ELEMENTS (row_targets),
10000 pspp_sheet_view_unset_rows_drag_source (tree_view);
10001 pspp_sheet_view_unset_rows_drag_dest (tree_view);
10004 tree_view->priv->reorderable = reorderable;
10006 g_object_notify (G_OBJECT (tree_view), "reorderable");
10009 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
10010 is pressed, other rows will be unselected.
10012 If CLAMP_NODE is true, then the sheetview will scroll to make the row
10015 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
10017 gboolean clear_and_select,
10018 gboolean clamp_node,
10019 PsppSheetSelectMode mode)
10023 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10025 GtkTreePath *cursor_path;
10026 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10027 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
10028 gtk_tree_path_free (cursor_path);
10031 gtk_tree_row_reference_free (tree_view->priv->cursor);
10032 tree_view->priv->cursor = NULL;
10034 _pspp_sheet_view_find_node (tree_view, path, &node);
10035 tree_view->priv->cursor =
10036 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
10037 tree_view->priv->model,
10040 if (tree_view->priv->row_count > 0)
10044 if (clear_and_select && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
10045 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
10049 /* We have to re-find tree and node here again, somebody might have
10050 * cleared the node or the whole tree in the PsppSheetSelection::changed
10051 * callback. If the nodes differ we bail out here.
10053 _pspp_sheet_view_find_node (tree_view, path, &new_node);
10055 if (node != new_node)
10060 pspp_sheet_view_clamp_node_visible (tree_view, node);
10061 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10065 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
10069 * pspp_sheet_view_get_cursor:
10070 * @tree_view: A #PsppSheetView
10071 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
10072 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
10074 * Fills in @path and @focus_column with the current path and focus column. If
10075 * the cursor isn't currently set, then *@path will be %NULL. If no column
10076 * currently has focus, then *@focus_column will be %NULL.
10078 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
10079 * you are done with it.
10082 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
10083 GtkTreePath **path,
10084 PsppSheetViewColumn **focus_column)
10086 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10090 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10091 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10098 *focus_column = tree_view->priv->focus_column;
10103 * pspp_sheet_view_set_cursor:
10104 * @tree_view: A #PsppSheetView
10105 * @path: A #GtkTreePath
10106 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10107 * @start_editing: %TRUE if the specified cell should start being edited.
10109 * Sets the current keyboard focus to be at @path, and selects it. This is
10110 * useful when you want to focus the user's attention on a particular row. If
10111 * @focus_column is not %NULL, then focus is given to the column specified by
10112 * it. Additionally, if @focus_column is specified, and @start_editing is
10113 * %TRUE, then editing should be started in the specified cell.
10114 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
10115 * in order to give keyboard focus to the widget. Please note that editing
10116 * can only happen when the widget is realized.
10118 * If @path is invalid for @model, the current cursor (if any) will be unset
10119 * and the function will return without failing.
10122 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
10124 PsppSheetViewColumn *focus_column,
10125 gboolean start_editing)
10127 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
10128 NULL, start_editing);
10132 * pspp_sheet_view_set_cursor_on_cell:
10133 * @tree_view: A #PsppSheetView
10134 * @path: A #GtkTreePath
10135 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10136 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
10137 * @start_editing: %TRUE if the specified cell should start being edited.
10139 * Sets the current keyboard focus to be at @path, and selects it. This is
10140 * useful when you want to focus the user's attention on a particular row. If
10141 * @focus_column is not %NULL, then focus is given to the column specified by
10142 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
10143 * contains 2 or more editable or activatable cells, then focus is given to
10144 * the cell specified by @focus_cell. Additionally, if @focus_column is
10145 * specified, and @start_editing is %TRUE, then editing should be started in
10146 * the specified cell. This function is often followed by
10147 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
10148 * widget. Please note that editing can only happen when the widget is
10151 * If @path is invalid for @model, the current cursor (if any) will be unset
10152 * and the function will return without failing.
10157 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
10159 PsppSheetViewColumn *focus_column,
10160 GtkCellRenderer *focus_cell,
10161 gboolean start_editing)
10163 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10164 g_return_if_fail (path != NULL);
10165 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
10167 if (!tree_view->priv->model)
10172 g_return_if_fail (focus_column);
10173 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
10176 /* cancel the current editing, if it exists */
10177 if (tree_view->priv->edited_column &&
10178 tree_view->priv->edited_column->editable_widget)
10179 pspp_sheet_view_stop_editing (tree_view, TRUE);
10181 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
10183 if (focus_column && focus_column->visible)
10186 gboolean column_in_tree = FALSE;
10188 for (list = tree_view->priv->columns; list; list = list->next)
10189 if (list->data == focus_column)
10191 column_in_tree = TRUE;
10194 g_return_if_fail (column_in_tree);
10195 tree_view->priv->focus_column = focus_column;
10197 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
10199 pspp_sheet_view_start_editing (tree_view, path);
10201 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
10202 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
10208 * pspp_sheet_view_get_bin_window:
10209 * @tree_view: A #PsppSheetView
10211 * Returns the window that @tree_view renders to. This is used primarily to
10212 * compare to <literal>event->window</literal> to confirm that the event on
10213 * @tree_view is on the right window.
10215 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
10218 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
10220 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
10222 return tree_view->priv->bin_window;
10226 * pspp_sheet_view_get_path_at_pos:
10227 * @tree_view: A #PsppSheetView.
10228 * @x: The x position to be identified (relative to bin_window).
10229 * @y: The y position to be identified (relative to bin_window).
10230 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
10231 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
10232 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
10233 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
10235 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10236 * (please see pspp_sheet_view_get_bin_window()).
10237 * That is, @x and @y are relative to an events coordinates. @x and @y must
10238 * come from an event on the @tree_view only where <literal>event->window ==
10239 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10240 * things like popup menus. If @path is non-%NULL, then it will be filled
10241 * with the #GtkTreePath at that point. This path should be freed with
10242 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10243 * with the column at that point. @cell_x and @cell_y return the coordinates
10244 * relative to the cell background (i.e. the @background_area passed to
10245 * gtk_cell_renderer_render()). This function is only meaningful if
10246 * @tree_view is realized. Therefore this function will always return %FALSE
10247 * if @tree_view is not realized or does not have a model.
10249 * For converting widget coordinates (eg. the ones you get from
10250 * GtkWidget::query-tooltip), please see
10251 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10253 * Return value: %TRUE if a row exists at that coordinate.
10256 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10259 GtkTreePath **path,
10260 PsppSheetViewColumn **column,
10267 g_return_val_if_fail (tree_view != NULL, FALSE);
10274 if (tree_view->priv->bin_window == NULL)
10277 if (tree_view->priv->row_count == 0)
10280 if (x > tree_view->priv->hadjustment->upper)
10283 if (x < 0 || y < 0)
10286 if (column || cell_x)
10288 PsppSheetViewColumn *tmp_column;
10289 PsppSheetViewColumn *last_column = NULL;
10291 gint remaining_x = x;
10292 gboolean found = FALSE;
10295 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10296 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10298 list = (rtl ? list->prev : list->next))
10300 tmp_column = list->data;
10302 if (tmp_column->visible == FALSE)
10305 last_column = tmp_column;
10306 if (remaining_x <= tmp_column->width)
10311 *column = tmp_column;
10314 *cell_x = remaining_x;
10318 remaining_x -= tmp_column->width;
10321 /* If found is FALSE and there is a last_column, then it the remainder
10322 * space is in that area
10329 *column = last_column;
10332 *cell_x = last_column->width + remaining_x;
10341 y_offset = pspp_sheet_view_find_offset (tree_view,
10342 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10349 *cell_y = y_offset;
10352 *path = _pspp_sheet_view_find_path (tree_view, node);
10357 /* Computes 'cell_area' from 'background_area', which must be the background
10358 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10359 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10360 the cell area as passed to _pspp_sheet_view_column_cell_render().
10362 'column' is required to properly adjust 'cell_area->x' and
10363 'cell_area->width'. It may be set to NULL if these values are not of
10364 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10367 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10368 PsppSheetViewColumn *column,
10369 const GdkRectangle *background_area,
10370 gboolean subtract_focus_rect,
10371 GdkRectangle *cell_area)
10373 gint vertical_separator;
10374 gint horizontal_separator;
10376 *cell_area = *background_area;
10378 gtk_widget_style_get (GTK_WIDGET (tree_view),
10379 "vertical-separator", &vertical_separator,
10380 "horizontal-separator", &horizontal_separator,
10382 cell_area->x += horizontal_separator / 2;
10383 cell_area->y += vertical_separator / 2;
10384 cell_area->width -= horizontal_separator;
10385 cell_area->height -= vertical_separator;
10387 if (subtract_focus_rect)
10389 int focus_line_width;
10391 gtk_widget_style_get (GTK_WIDGET (tree_view),
10392 "focus-line-width", &focus_line_width,
10394 cell_area->x += focus_line_width;
10395 cell_area->y += focus_line_width;
10396 cell_area->width -= 2 * focus_line_width;
10397 cell_area->height -= 2 * focus_line_width;
10400 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10402 gint grid_line_width;
10403 gtk_widget_style_get (GTK_WIDGET (tree_view),
10404 "grid-line-width", &grid_line_width,
10407 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10408 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10411 PsppSheetViewColumn *first_column, *last_column;
10414 /* Find the last visible column. */
10415 last_column = NULL;
10416 for (list = g_list_last (tree_view->priv->columns);
10420 PsppSheetViewColumn *c = list->data;
10428 /* Find the first visible column. */
10429 first_column = NULL;
10430 for (list = g_list_first (tree_view->priv->columns);
10434 PsppSheetViewColumn *c = list->data;
10442 if (column == first_column)
10444 cell_area->width -= grid_line_width / 2;
10446 else if (column == last_column)
10448 cell_area->x += grid_line_width / 2;
10449 cell_area->width -= grid_line_width / 2;
10453 cell_area->x += grid_line_width / 2;
10454 cell_area->width -= grid_line_width;
10458 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10459 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10461 cell_area->y += grid_line_width / 2;
10462 cell_area->height -= grid_line_width;
10466 if (column == NULL)
10469 cell_area->width = 0;
10474 * pspp_sheet_view_get_cell_area:
10475 * @tree_view: a #PsppSheetView
10476 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10477 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10478 * @rect: rectangle to fill with cell rect
10480 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10481 * row specified by @path and the column specified by @column. If @path is
10482 * %NULL, or points to a path not currently displayed, the @y and @height fields
10483 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10484 * fields will be filled with 0. The sum of all cell rects does not cover the
10485 * entire tree; there are extra pixels in between rows, for example. The
10486 * returned rectangle is equivalent to the @cell_area passed to
10487 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10491 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10493 PsppSheetViewColumn *column,
10494 GdkRectangle *rect)
10496 GdkRectangle background_area;
10498 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10499 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10500 g_return_if_fail (rect != NULL);
10501 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10502 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10504 pspp_sheet_view_get_background_area (tree_view, path, column,
10506 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10511 * pspp_sheet_view_get_background_area:
10512 * @tree_view: a #PsppSheetView
10513 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10514 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10515 * @rect: rectangle to fill with cell background rect
10517 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10518 * row specified by @path and the column specified by @column. If @path is
10519 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10520 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10521 * fields will be filled with 0. The returned rectangle is equivalent to the
10522 * @background_area passed to gtk_cell_renderer_render(). These background
10523 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10524 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10525 * itself, excluding surrounding borders.
10529 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10531 PsppSheetViewColumn *column,
10532 GdkRectangle *rect)
10536 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10537 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10538 g_return_if_fail (rect != NULL);
10547 /* Get vertical coords */
10549 _pspp_sheet_view_find_node (tree_view, path, &node);
10553 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10555 rect->height = ROW_HEIGHT (tree_view);
10562 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10563 rect->width = x2 - rect->x;
10568 * pspp_sheet_view_get_visible_rect:
10569 * @tree_view: a #PsppSheetView
10570 * @visible_rect: rectangle to fill
10572 * Fills @visible_rect with the currently-visible region of the
10573 * buffer, in tree coordinates. Convert to bin_window coordinates with
10574 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10575 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10576 * scrollable area of the tree.
10579 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10580 GdkRectangle *visible_rect)
10584 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10586 widget = GTK_WIDGET (tree_view);
10590 visible_rect->x = tree_view->priv->hadjustment->value;
10591 visible_rect->y = tree_view->priv->vadjustment->value;
10592 visible_rect->width = widget->allocation.width;
10593 visible_rect->height = widget->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10598 * pspp_sheet_view_widget_to_tree_coords:
10599 * @tree_view: a #PsppSheetView
10600 * @wx: X coordinate relative to bin_window
10601 * @wy: Y coordinate relative to bin_window
10602 * @tx: return location for tree X coordinate
10603 * @ty: return location for tree Y coordinate
10605 * Converts bin_window coordinates to coordinates for the
10606 * tree (the full scrollable area of the tree).
10608 * Deprecated: 2.12: Due to historial reasons the name of this function is
10609 * incorrect. For converting coordinates relative to the widget to
10610 * bin_window coordinates, please see
10611 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10615 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10621 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10624 *tx = wx + tree_view->priv->hadjustment->value;
10626 *ty = wy + tree_view->priv->dy;
10630 * pspp_sheet_view_tree_to_widget_coords:
10631 * @tree_view: a #PsppSheetView
10632 * @tx: tree X coordinate
10633 * @ty: tree Y coordinate
10634 * @wx: return location for X coordinate relative to bin_window
10635 * @wy: return location for Y coordinate relative to bin_window
10637 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10638 * to bin_window coordinates.
10640 * Deprecated: 2.12: Due to historial reasons the name of this function is
10641 * incorrect. For converting bin_window coordinates to coordinates relative
10642 * to bin_window, please see
10643 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10647 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10653 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10656 *wx = tx - tree_view->priv->hadjustment->value;
10658 *wy = ty - tree_view->priv->dy;
10663 * pspp_sheet_view_convert_widget_to_tree_coords:
10664 * @tree_view: a #PsppSheetView
10665 * @wx: X coordinate relative to the widget
10666 * @wy: Y coordinate relative to the widget
10667 * @tx: return location for tree X coordinate
10668 * @ty: return location for tree Y coordinate
10670 * Converts widget coordinates to coordinates for the
10671 * tree (the full scrollable area of the tree).
10676 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10684 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10686 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10689 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10695 * pspp_sheet_view_convert_tree_to_widget_coords:
10696 * @tree_view: a #PsppSheetView
10697 * @tx: X coordinate relative to the tree
10698 * @ty: Y coordinate relative to the tree
10699 * @wx: return location for widget X coordinate
10700 * @wy: return location for widget Y coordinate
10702 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10703 * to widget coordinates.
10708 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10716 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10718 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10721 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10727 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10728 * @tree_view: a #PsppSheetView
10729 * @wx: X coordinate relative to the widget
10730 * @wy: Y coordinate relative to the widget
10731 * @bx: return location for bin_window X coordinate
10732 * @by: return location for bin_window Y coordinate
10734 * Converts widget coordinates to coordinates for the bin_window
10735 * (see pspp_sheet_view_get_bin_window()).
10740 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10746 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10749 *bx = wx + tree_view->priv->hadjustment->value;
10751 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10755 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10756 * @tree_view: a #PsppSheetView
10757 * @bx: bin_window X coordinate
10758 * @by: bin_window Y coordinate
10759 * @wx: return location for widget X coordinate
10760 * @wy: return location for widget Y coordinate
10762 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10763 * to widget relative coordinates.
10768 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10774 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10777 *wx = bx - tree_view->priv->hadjustment->value;
10779 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10783 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10784 * @tree_view: a #PsppSheetView
10785 * @tx: tree X coordinate
10786 * @ty: tree Y coordinate
10787 * @bx: return location for X coordinate relative to bin_window
10788 * @by: return location for Y coordinate relative to bin_window
10790 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10791 * to bin_window coordinates.
10796 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10802 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10807 *by = ty - tree_view->priv->dy;
10811 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10812 * @tree_view: a #PsppSheetView
10813 * @bx: X coordinate relative to bin_window
10814 * @by: Y coordinate relative to bin_window
10815 * @tx: return location for tree X coordinate
10816 * @ty: return location for tree Y coordinate
10818 * Converts bin_window coordinates to coordinates for the
10819 * tree (the full scrollable area of the tree).
10824 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10830 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10835 *ty = by + tree_view->priv->dy;
10841 * pspp_sheet_view_get_visible_range:
10842 * @tree_view: A #PsppSheetView
10843 * @start_path: (allow-none): Return location for start of region, or %NULL.
10844 * @end_path: (allow-none): Return location for end of region, or %NULL.
10846 * Sets @start_path and @end_path to be the first and last visible path.
10847 * Note that there may be invisible paths in between.
10849 * The paths should be freed with gtk_tree_path_free() after use.
10851 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10856 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10857 GtkTreePath **start_path,
10858 GtkTreePath **end_path)
10863 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10865 if (!tree_view->priv->row_count)
10872 pspp_sheet_view_find_offset (tree_view,
10873 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10876 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10885 if (tree_view->priv->height < tree_view->priv->vadjustment->page_size)
10886 y = tree_view->priv->height - 1;
10888 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, tree_view->priv->vadjustment->page_size) - 1;
10890 pspp_sheet_view_find_offset (tree_view, y, &node);
10892 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10901 unset_reorderable (PsppSheetView *tree_view)
10903 if (tree_view->priv->reorderable)
10905 tree_view->priv->reorderable = FALSE;
10906 g_object_notify (G_OBJECT (tree_view), "reorderable");
10911 * pspp_sheet_view_enable_model_drag_source:
10912 * @tree_view: a #PsppSheetView
10913 * @start_button_mask: Mask of allowed buttons to start drag
10914 * @targets: the table of targets that the drag will support
10915 * @n_targets: the number of items in @targets
10916 * @actions: the bitmask of possible actions for a drag from this
10919 * Turns @tree_view into a drag source for automatic DND. Calling this
10920 * method sets #PsppSheetView:reorderable to %FALSE.
10923 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10924 GdkModifierType start_button_mask,
10925 const GtkTargetEntry *targets,
10927 GdkDragAction actions)
10929 TreeViewDragInfo *di;
10931 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10933 gtk_drag_source_set (GTK_WIDGET (tree_view),
10939 di = ensure_info (tree_view);
10941 di->start_button_mask = start_button_mask;
10942 di->source_actions = actions;
10943 di->source_set = TRUE;
10945 unset_reorderable (tree_view);
10949 * pspp_sheet_view_enable_model_drag_dest:
10950 * @tree_view: a #PsppSheetView
10951 * @targets: the table of targets that the drag will support
10952 * @n_targets: the number of items in @targets
10953 * @actions: the bitmask of possible actions for a drag from this
10956 * Turns @tree_view into a drop destination for automatic DND. Calling
10957 * this method sets #PsppSheetView:reorderable to %FALSE.
10960 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
10961 const GtkTargetEntry *targets,
10963 GdkDragAction actions)
10965 TreeViewDragInfo *di;
10967 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10969 gtk_drag_dest_set (GTK_WIDGET (tree_view),
10975 di = ensure_info (tree_view);
10976 di->dest_set = TRUE;
10978 unset_reorderable (tree_view);
10982 * pspp_sheet_view_unset_rows_drag_source:
10983 * @tree_view: a #PsppSheetView
10985 * Undoes the effect of
10986 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
10987 * #PsppSheetView:reorderable to %FALSE.
10990 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
10992 TreeViewDragInfo *di;
10994 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10996 di = get_info (tree_view);
11000 if (di->source_set)
11002 gtk_drag_source_unset (GTK_WIDGET (tree_view));
11003 di->source_set = FALSE;
11006 if (!di->dest_set && !di->source_set)
11007 remove_info (tree_view);
11010 unset_reorderable (tree_view);
11014 * pspp_sheet_view_unset_rows_drag_dest:
11015 * @tree_view: a #PsppSheetView
11017 * Undoes the effect of
11018 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
11019 * #PsppSheetView:reorderable to %FALSE.
11022 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
11024 TreeViewDragInfo *di;
11026 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11028 di = get_info (tree_view);
11034 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
11035 di->dest_set = FALSE;
11038 if (!di->dest_set && !di->source_set)
11039 remove_info (tree_view);
11042 unset_reorderable (tree_view);
11046 * pspp_sheet_view_set_drag_dest_row:
11047 * @tree_view: a #PsppSheetView
11048 * @path: (allow-none): The path of the row to highlight, or %NULL.
11049 * @pos: Specifies whether to drop before, after or into the row
11051 * Sets the row that is highlighted for feedback.
11054 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
11056 PsppSheetViewDropPosition pos)
11058 GtkTreePath *current_dest;
11060 /* Note; this function is exported to allow a custom DND
11061 * implementation, so it can't touch TreeViewDragInfo
11064 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11066 current_dest = NULL;
11068 if (tree_view->priv->drag_dest_row)
11070 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11071 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
11074 /* special case a drop on an empty model */
11075 tree_view->priv->empty_view_drop = 0;
11077 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
11078 && gtk_tree_path_get_depth (path) == 1
11079 && gtk_tree_path_get_indices (path)[0] == 0)
11083 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
11087 tree_view->priv->empty_view_drop = 1;
11090 tree_view->priv->drag_dest_pos = pos;
11094 tree_view->priv->drag_dest_row =
11095 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
11096 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
11099 tree_view->priv->drag_dest_row = NULL;
11103 int node, new_node;
11105 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
11106 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
11110 new_node = pspp_sheet_view_node_next (tree_view, node);
11112 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11114 new_node = pspp_sheet_view_node_prev (tree_view, node);
11116 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11118 gtk_tree_path_free (current_dest);
11123 * pspp_sheet_view_get_drag_dest_row:
11124 * @tree_view: a #PsppSheetView
11125 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11126 * @pos: (allow-none): Return location for the drop position, or %NULL
11128 * Gets information about the row that is highlighted for feedback.
11131 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
11132 GtkTreePath **path,
11133 PsppSheetViewDropPosition *pos)
11135 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11139 if (tree_view->priv->drag_dest_row)
11140 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11143 if (tree_view->priv->empty_view_drop)
11144 *path = gtk_tree_path_new_from_indices (0, -1);
11151 *pos = tree_view->priv->drag_dest_pos;
11155 * pspp_sheet_view_get_dest_row_at_pos:
11156 * @tree_view: a #PsppSheetView
11157 * @drag_x: the position to determine the destination row for
11158 * @drag_y: the position to determine the destination row for
11159 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11160 * @pos: (allow-none): Return location for the drop position, or %NULL
11162 * Determines the destination row for a given position. @drag_x and
11163 * @drag_y are expected to be in widget coordinates. This function is only
11164 * meaningful if @tree_view is realized. Therefore this function will always
11165 * return %FALSE if @tree_view is not realized or does not have a model.
11167 * Return value: whether there is a row at the given position, %TRUE if this
11168 * is indeed the case.
11171 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
11174 GtkTreePath **path,
11175 PsppSheetViewDropPosition *pos)
11179 gdouble offset_into_row;
11182 PsppSheetViewColumn *column = NULL;
11183 GtkTreePath *tmp_path = NULL;
11185 /* Note; this function is exported to allow a custom DND
11186 * implementation, so it can't touch TreeViewDragInfo
11189 g_return_val_if_fail (tree_view != NULL, FALSE);
11190 g_return_val_if_fail (drag_x >= 0, FALSE);
11191 g_return_val_if_fail (drag_y >= 0, FALSE);
11196 if (tree_view->priv->bin_window == NULL)
11199 if (tree_view->priv->row_count == 0)
11202 /* If in the top third of a row, we drop before that row; if
11203 * in the bottom third, drop after that row; if in the middle,
11204 * and the row has children, drop into the row.
11206 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
11209 if (!pspp_sheet_view_get_path_at_pos (tree_view,
11218 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
11221 offset_into_row = cell_y;
11226 gtk_tree_path_free (tmp_path);
11230 third = cell.height / 3.0;
11234 if (offset_into_row < third)
11236 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11238 else if (offset_into_row < (cell.height / 2.0))
11240 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11242 else if (offset_into_row < third * 2.0)
11244 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11248 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11257 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11259 * pspp_sheet_view_create_row_drag_icon:
11260 * @tree_view: a #PsppSheetView
11261 * @path: a #GtkTreePath in @tree_view
11263 * Creates a #GdkPixmap representation of the row at @path.
11264 * This image is used for a drag icon.
11266 * Return value: a newly-allocated pixmap of the drag icon.
11269 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11276 GdkRectangle background_area;
11277 GdkRectangle expose_area;
11279 /* start drawing inside the black outline */
11281 GdkDrawable *drawable;
11282 gint bin_window_width;
11285 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11286 g_return_val_if_fail (path != NULL, NULL);
11288 widget = GTK_WIDGET (tree_view);
11290 if (!gtk_widget_get_realized (widget))
11293 _pspp_sheet_view_find_node (tree_view,
11300 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11307 background_area.y = y;
11308 background_area.height = ROW_HEIGHT (tree_view);
11310 gdk_drawable_get_size (tree_view->priv->bin_window,
11311 &bin_window_width, NULL);
11313 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11314 bin_window_width + 2,
11315 background_area.height + 2,
11320 expose_area.width = bin_window_width + 2;
11321 expose_area.height = background_area.height + 2;
11323 gdk_draw_rectangle (drawable,
11324 widget->style->base_gc [gtk_widget_get_state (widget)],
11327 bin_window_width + 2,
11328 background_area.height + 2);
11330 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11332 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11334 list = (rtl ? list->prev : list->next))
11336 PsppSheetViewColumn *column = list->data;
11337 GdkRectangle cell_area;
11338 gint vertical_separator;
11340 if (!column->visible)
11343 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11345 background_area.x = cell_offset;
11346 background_area.width = column->width;
11348 gtk_widget_style_get (widget,
11349 "vertical-separator", &vertical_separator,
11352 cell_area = background_area;
11354 cell_area.y += vertical_separator / 2;
11355 cell_area.height -= vertical_separator;
11357 if (pspp_sheet_view_column_cell_is_visible (column))
11358 _pspp_sheet_view_column_cell_render (column,
11364 cell_offset += column->width;
11367 gdk_draw_rectangle (drawable,
11368 widget->style->black_gc,
11371 bin_window_width + 1,
11372 background_area.height + 1);
11379 * pspp_sheet_view_set_destroy_count_func:
11380 * @tree_view: A #PsppSheetView
11381 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11382 * @data: (allow-none): User data to be passed to @func, or %NULL
11383 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11385 * This function should almost never be used. It is meant for private use by
11386 * ATK for determining the number of visible children that are removed when a row is deleted.
11389 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11390 PsppSheetDestroyCountFunc func,
11392 GDestroyNotify destroy)
11394 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11396 if (tree_view->priv->destroy_count_destroy)
11397 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11399 tree_view->priv->destroy_count_func = func;
11400 tree_view->priv->destroy_count_data = data;
11401 tree_view->priv->destroy_count_destroy = destroy;
11406 * Interactive search
11410 * pspp_sheet_view_set_enable_search:
11411 * @tree_view: A #PsppSheetView
11412 * @enable_search: %TRUE, if the user can search interactively
11414 * If @enable_search is set, then the user can type in text to search through
11415 * the tree interactively (this is sometimes called "typeahead find").
11417 * Note that even if this is %FALSE, the user can still initiate a search
11418 * using the "start-interactive-search" key binding.
11421 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11422 gboolean enable_search)
11424 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11426 enable_search = !!enable_search;
11428 if (tree_view->priv->enable_search != enable_search)
11430 tree_view->priv->enable_search = enable_search;
11431 g_object_notify (G_OBJECT (tree_view), "enable-search");
11436 * pspp_sheet_view_get_enable_search:
11437 * @tree_view: A #PsppSheetView
11439 * Returns whether or not the tree allows to start interactive searching
11440 * by typing in text.
11442 * Return value: whether or not to let the user search interactively
11445 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11447 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11449 return tree_view->priv->enable_search;
11454 * pspp_sheet_view_get_search_column:
11455 * @tree_view: A #PsppSheetView
11457 * Gets the column searched on by the interactive search code.
11459 * Return value: the column the interactive search code searches in.
11462 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11464 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11466 return (tree_view->priv->search_column);
11470 * pspp_sheet_view_set_search_column:
11471 * @tree_view: A #PsppSheetView
11472 * @column: the column of the model to search in, or -1 to disable searching
11474 * Sets @column as the column where the interactive search code should
11475 * search in for the current model.
11477 * If the search column is set, users can use the "start-interactive-search"
11478 * key binding to bring up search popup. The enable-search property controls
11479 * whether simply typing text will also start an interactive search.
11481 * Note that @column refers to a column of the current model. The search
11482 * column is reset to -1 when the model is changed.
11485 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11488 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11489 g_return_if_fail (column >= -1);
11491 if (tree_view->priv->search_column == column)
11494 tree_view->priv->search_column = column;
11495 g_object_notify (G_OBJECT (tree_view), "search-column");
11499 * pspp_sheet_view_get_search_equal_func:
11500 * @tree_view: A #PsppSheetView
11502 * Returns the compare function currently in use.
11504 * Return value: the currently used compare function for the search code.
11507 PsppSheetViewSearchEqualFunc
11508 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11510 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11512 return tree_view->priv->search_equal_func;
11516 * pspp_sheet_view_set_search_equal_func:
11517 * @tree_view: A #PsppSheetView
11518 * @search_equal_func: the compare function to use during the search
11519 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11520 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11522 * Sets the compare function for the interactive search capabilities; note
11523 * that somewhat like strcmp() returning 0 for equality
11524 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11527 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11528 PsppSheetViewSearchEqualFunc search_equal_func,
11529 gpointer search_user_data,
11530 GDestroyNotify search_destroy)
11532 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11533 g_return_if_fail (search_equal_func != NULL);
11535 if (tree_view->priv->search_destroy)
11536 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11538 tree_view->priv->search_equal_func = search_equal_func;
11539 tree_view->priv->search_user_data = search_user_data;
11540 tree_view->priv->search_destroy = search_destroy;
11541 if (tree_view->priv->search_equal_func == NULL)
11542 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11546 * pspp_sheet_view_get_search_entry:
11547 * @tree_view: A #PsppSheetView
11549 * Returns the #GtkEntry which is currently in use as interactive search
11550 * entry for @tree_view. In case the built-in entry is being used, %NULL
11551 * will be returned.
11553 * Return value: the entry currently in use as search entry.
11558 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11560 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11562 if (tree_view->priv->search_custom_entry_set)
11563 return GTK_ENTRY (tree_view->priv->search_entry);
11569 * pspp_sheet_view_set_search_entry:
11570 * @tree_view: A #PsppSheetView
11571 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11573 * Sets the entry which the interactive search code will use for this
11574 * @tree_view. This is useful when you want to provide a search entry
11575 * in our interface at all time at a fixed position. Passing %NULL for
11576 * @entry will make the interactive search code use the built-in popup
11582 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11585 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11586 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11588 if (tree_view->priv->search_custom_entry_set)
11590 if (tree_view->priv->search_entry_changed_id)
11592 g_signal_handler_disconnect (tree_view->priv->search_entry,
11593 tree_view->priv->search_entry_changed_id);
11594 tree_view->priv->search_entry_changed_id = 0;
11596 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11597 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11600 g_object_unref (tree_view->priv->search_entry);
11602 else if (tree_view->priv->search_window)
11604 gtk_widget_destroy (tree_view->priv->search_window);
11606 tree_view->priv->search_window = NULL;
11611 tree_view->priv->search_entry = g_object_ref (entry);
11612 tree_view->priv->search_custom_entry_set = TRUE;
11614 if (tree_view->priv->search_entry_changed_id == 0)
11616 tree_view->priv->search_entry_changed_id =
11617 g_signal_connect (tree_view->priv->search_entry, "changed",
11618 G_CALLBACK (pspp_sheet_view_search_init),
11622 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11623 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11626 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11630 tree_view->priv->search_entry = NULL;
11631 tree_view->priv->search_custom_entry_set = FALSE;
11636 * pspp_sheet_view_set_search_position_func:
11637 * @tree_view: A #PsppSheetView
11638 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11639 * to use the default search position function
11640 * @data: (allow-none): user data to pass to @func, or %NULL
11641 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11643 * Sets the function to use when positioning the search dialog.
11648 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11649 PsppSheetViewSearchPositionFunc func,
11650 gpointer user_data,
11651 GDestroyNotify destroy)
11653 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11655 if (tree_view->priv->search_position_destroy)
11656 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11658 tree_view->priv->search_position_func = func;
11659 tree_view->priv->search_position_user_data = user_data;
11660 tree_view->priv->search_position_destroy = destroy;
11661 if (tree_view->priv->search_position_func == NULL)
11662 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11666 * pspp_sheet_view_get_search_position_func:
11667 * @tree_view: A #PsppSheetView
11669 * Returns the positioning function currently in use.
11671 * Return value: the currently used function for positioning the search dialog.
11675 PsppSheetViewSearchPositionFunc
11676 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11678 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11680 return tree_view->priv->search_position_func;
11685 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11686 PsppSheetView *tree_view)
11688 if (tree_view->priv->disable_popdown)
11691 if (tree_view->priv->search_entry_changed_id)
11693 g_signal_handler_disconnect (tree_view->priv->search_entry,
11694 tree_view->priv->search_entry_changed_id);
11695 tree_view->priv->search_entry_changed_id = 0;
11697 if (tree_view->priv->typeselect_flush_timeout)
11699 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11700 tree_view->priv->typeselect_flush_timeout = 0;
11703 if (gtk_widget_get_visible (search_dialog))
11705 /* send focus-in event */
11706 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11707 gtk_widget_hide (search_dialog);
11708 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11709 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11714 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11715 GtkWidget *search_dialog,
11716 gpointer user_data)
11719 gint tree_x, tree_y;
11720 gint tree_width, tree_height;
11721 GdkWindow *tree_window = GTK_WIDGET (tree_view)->window;
11722 GdkScreen *screen = gdk_drawable_get_screen (tree_window);
11723 GtkRequisition requisition;
11725 GdkRectangle monitor;
11727 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11728 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11730 gtk_widget_realize (search_dialog);
11732 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11733 gdk_drawable_get_size (tree_window,
11736 gtk_widget_size_request (search_dialog, &requisition);
11738 if (tree_x + tree_width > gdk_screen_get_width (screen))
11739 x = gdk_screen_get_width (screen) - requisition.width;
11740 else if (tree_x + tree_width - requisition.width < 0)
11743 x = tree_x + tree_width - requisition.width;
11745 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11746 y = gdk_screen_get_height (screen) - requisition.height;
11747 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11750 y = tree_y + tree_height;
11752 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11756 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11760 PsppSheetView *tree_view = (PsppSheetView *)data;
11762 tree_view->priv->disable_popdown = 1;
11763 g_signal_connect (menu, "hide",
11764 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11767 /* Because we're visible but offscreen, we just set a flag in the preedit
11771 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11772 PsppSheetView *tree_view)
11774 tree_view->priv->imcontext_changed = 1;
11775 if (tree_view->priv->typeselect_flush_timeout)
11777 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11778 tree_view->priv->typeselect_flush_timeout =
11779 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11780 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11787 pspp_sheet_view_search_activate (GtkEntry *entry,
11788 PsppSheetView *tree_view)
11793 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11796 /* If we have a row selected and it's the cursor row, we activate
11798 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11800 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11802 _pspp_sheet_view_find_node (tree_view, path, &node);
11804 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11805 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11807 gtk_tree_path_free (path);
11812 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11814 PsppSheetView *tree_view = (PsppSheetView *)data;
11816 tree_view->priv->disable_popdown = 0;
11822 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11825 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11829 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11830 GdkEventAny *event,
11831 PsppSheetView *tree_view)
11833 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11835 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11841 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11842 GdkEventButton *event,
11843 PsppSheetView *tree_view)
11845 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11847 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11849 if (event->window == tree_view->priv->bin_window)
11850 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11856 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11857 GdkEventScroll *event,
11858 PsppSheetView *tree_view)
11860 gboolean retval = FALSE;
11862 if (event->direction == GDK_SCROLL_UP)
11864 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11867 else if (event->direction == GDK_SCROLL_DOWN)
11869 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11873 /* renew the flush timeout */
11874 if (retval && tree_view->priv->typeselect_flush_timeout
11875 && !tree_view->priv->search_custom_entry_set)
11877 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11878 tree_view->priv->typeselect_flush_timeout =
11879 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11880 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11888 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11889 GdkEventKey *event,
11890 PsppSheetView *tree_view)
11892 gboolean retval = FALSE;
11894 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11895 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11897 /* close window and cancel the search */
11898 if (!tree_view->priv->search_custom_entry_set
11899 && (event->keyval == GDK_Escape ||
11900 event->keyval == GDK_Tab ||
11901 event->keyval == GDK_KP_Tab ||
11902 event->keyval == GDK_ISO_Left_Tab))
11904 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11908 /* select previous matching iter */
11909 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11911 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11912 gtk_widget_error_bell (widget);
11917 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11918 && (event->keyval == GDK_g || event->keyval == GDK_G))
11920 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11921 gtk_widget_error_bell (widget);
11926 /* select next matching iter */
11927 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
11929 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11930 gtk_widget_error_bell (widget);
11935 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
11936 && (event->keyval == GDK_g || event->keyval == GDK_G))
11938 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11939 gtk_widget_error_bell (widget);
11944 /* renew the flush timeout */
11945 if (retval && tree_view->priv->typeselect_flush_timeout
11946 && !tree_view->priv->search_custom_entry_set)
11948 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11949 tree_view->priv->typeselect_flush_timeout =
11950 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11951 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11958 /* this function returns FALSE if there is a search string but
11959 * nothing was found, and TRUE otherwise.
11962 pspp_sheet_view_search_move (GtkWidget *window,
11963 PsppSheetView *tree_view,
11971 GtkTreeModel *model;
11972 PsppSheetSelection *selection;
11974 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
11976 g_return_val_if_fail (text != NULL, FALSE);
11978 len = strlen (text);
11980 if (up && tree_view->priv->selected_iter == 1)
11981 return strlen (text) < 1;
11983 len = strlen (text);
11988 model = pspp_sheet_view_get_model (tree_view);
11989 selection = pspp_sheet_view_get_selection (tree_view);
11992 pspp_sheet_selection_unselect_all (selection);
11993 if (!gtk_tree_model_get_iter_first (model, &iter))
11996 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
11997 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
12002 tree_view->priv->selected_iter += up?(-1):(1);
12007 /* return to old iter */
12009 gtk_tree_model_get_iter_first (model, &iter);
12010 pspp_sheet_view_search_iter (model, selection,
12012 &count, tree_view->priv->selected_iter);
12018 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
12022 gpointer search_data)
12024 gboolean retval = TRUE;
12026 gchar *normalized_string;
12027 gchar *normalized_key;
12028 gchar *case_normalized_string = NULL;
12029 gchar *case_normalized_key = NULL;
12030 GValue value = {0,};
12031 GValue transformed = {0,};
12033 gtk_tree_model_get_value (model, iter, column, &value);
12035 g_value_init (&transformed, G_TYPE_STRING);
12037 if (!g_value_transform (&value, &transformed))
12039 g_value_unset (&value);
12043 g_value_unset (&value);
12045 str = g_value_get_string (&transformed);
12048 g_value_unset (&transformed);
12052 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
12053 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
12055 if (normalized_string && normalized_key)
12057 case_normalized_string = g_utf8_casefold (normalized_string, -1);
12058 case_normalized_key = g_utf8_casefold (normalized_key, -1);
12060 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
12064 g_value_unset (&transformed);
12065 g_free (normalized_key);
12066 g_free (normalized_string);
12067 g_free (case_normalized_key);
12068 g_free (case_normalized_string);
12074 pspp_sheet_view_search_iter (GtkTreeModel *model,
12075 PsppSheetSelection *selection,
12084 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
12086 path = gtk_tree_model_get_path (model, iter);
12087 _pspp_sheet_view_find_node (tree_view, path, &node);
12091 gboolean done = FALSE;
12093 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
12098 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
12100 pspp_sheet_selection_select_iter (selection, iter);
12101 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12104 gtk_tree_path_free (path);
12113 node = pspp_sheet_view_node_next (tree_view, node);
12119 has_next = gtk_tree_model_iter_next (model, iter);
12122 gtk_tree_path_next (path);
12125 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
12130 gtk_tree_path_free (path);
12132 /* we've run out of tree, done with this func */
12144 pspp_sheet_view_search_init (GtkWidget *entry,
12145 PsppSheetView *tree_view)
12151 GtkTreeModel *model;
12152 PsppSheetSelection *selection;
12154 g_return_if_fail (GTK_IS_ENTRY (entry));
12155 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12157 text = gtk_entry_get_text (GTK_ENTRY (entry));
12159 model = pspp_sheet_view_get_model (tree_view);
12160 selection = pspp_sheet_view_get_selection (tree_view);
12163 pspp_sheet_selection_unselect_all (selection);
12164 if (tree_view->priv->typeselect_flush_timeout
12165 && !tree_view->priv->search_custom_entry_set)
12167 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12168 tree_view->priv->typeselect_flush_timeout =
12169 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12170 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12177 if (!gtk_tree_model_get_iter_first (model, &iter))
12180 ret = pspp_sheet_view_search_iter (model, selection,
12185 tree_view->priv->selected_iter = 1;
12189 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
12190 PsppSheetView *tree_view)
12192 if (tree_view->priv->edited_column == NULL)
12195 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
12196 tree_view->priv->edited_column = NULL;
12198 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
12199 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12201 g_signal_handlers_disconnect_by_func (cell_editable,
12202 pspp_sheet_view_remove_widget,
12204 g_signal_handlers_disconnect_by_func (cell_editable,
12205 pspp_sheet_view_editable_button_press_event,
12207 g_signal_handlers_disconnect_by_func (cell_editable,
12208 pspp_sheet_view_editable_clicked,
12211 gtk_container_remove (GTK_CONTAINER (tree_view),
12212 GTK_WIDGET (cell_editable));
12214 /* FIXME should only redraw a single node */
12215 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12219 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
12220 GtkTreePath *cursor_path)
12223 GdkRectangle background_area;
12224 GdkRectangle cell_area;
12225 GtkCellEditable *editable_widget = NULL;
12226 gchar *path_string;
12227 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
12228 gint retval = FALSE;
12231 g_assert (tree_view->priv->focus_column);
12233 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12236 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12237 if (cursor_node < 0)
12240 path_string = gtk_tree_path_to_string (cursor_path);
12241 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12243 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12244 tree_view->priv->model,
12246 pspp_sheet_view_get_background_area (tree_view,
12248 tree_view->priv->focus_column,
12250 pspp_sheet_view_get_cell_area (tree_view,
12252 tree_view->priv->focus_column,
12255 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12264 if (editable_widget != NULL)
12268 GtkCellRenderer *cell;
12271 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12273 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12276 area.width -= right + left;
12278 pspp_sheet_view_real_start_editing (tree_view,
12279 tree_view->priv->focus_column,
12288 g_free (path_string);
12293 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12294 GdkEventButton *event,
12295 PsppSheetView *sheet_view)
12299 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12300 "pspp-sheet-view-node"));
12301 return pspp_sheet_view_row_head_clicked (sheet_view,
12303 sheet_view->priv->edited_column,
12308 pspp_sheet_view_editable_clicked (GtkButton *button,
12309 PsppSheetView *sheet_view)
12311 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12316 is_all_selected (GtkWidget *widget)
12318 GtkEntryBuffer *buffer;
12319 gint start_pos, end_pos;
12321 if (!GTK_IS_ENTRY (widget))
12324 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12325 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12326 &start_pos, &end_pos)
12328 && end_pos == gtk_entry_buffer_get_length (buffer));
12332 is_at_left (GtkWidget *widget)
12334 return (GTK_IS_ENTRY (widget)
12335 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12339 is_at_right (GtkWidget *widget)
12341 GtkEntryBuffer *buffer;
12344 if (!GTK_IS_ENTRY (widget))
12347 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12348 length = gtk_entry_buffer_get_length (buffer);
12349 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12353 pspp_sheet_view_event (GtkWidget *widget,
12354 GdkEventKey *event,
12355 PsppSheetView *tree_view)
12357 PsppSheetViewColumn *column;
12364 /* Intercept only key press events.
12365 It would make sense to use "key-press-event" instead of "event", but
12366 GtkEntry attaches its own signal handler to "key-press-event" that runs
12367 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12369 if (event->type != GDK_KEY_PRESS)
12372 keyval = event->keyval;
12374 switch (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12377 switch (event->keyval)
12379 case GDK_Left: case GDK_KP_Left:
12380 case GDK_Home: case GDK_KP_Home:
12381 if (!is_all_selected (widget) && !is_at_left (widget))
12385 case GDK_Right: case GDK_KP_Right:
12386 case GDK_End: case GDK_KP_End:
12387 if (!is_all_selected (widget) && !is_at_right (widget))
12391 case GDK_Up: case GDK_KP_Up:
12392 case GDK_Down: case GDK_KP_Down:
12395 case GDK_Page_Up: case GDK_KP_Page_Up:
12396 case GDK_Page_Down: case GDK_KP_Page_Down:
12407 case GDK_Tab: case GDK_KP_Tab:
12408 case GDK_ISO_Left_Tab:
12417 case GDK_SHIFT_MASK:
12418 switch (event->keyval)
12421 case GDK_ISO_Left_Tab:
12430 case GDK_CONTROL_MASK:
12431 switch (event->keyval)
12433 case GDK_Left: case GDK_KP_Left:
12434 if (!is_all_selected (widget) && !is_at_left (widget))
12438 case GDK_Right: case GDK_KP_Right:
12439 if (!is_all_selected (widget) && !is_at_right (widget))
12443 case GDK_Up: case GDK_KP_Up:
12444 case GDK_Down: case GDK_KP_Down:
12456 row = tree_view->priv->edited_row;
12457 column = tree_view->priv->edited_column;
12458 path = gtk_tree_path_new_from_indices (row, -1);
12460 pspp_sheet_view_stop_editing (tree_view, cancel);
12461 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12463 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12464 gtk_tree_path_free (path);
12466 handled = gtk_binding_set_activate (edit_bindings, keyval, event->state,
12467 GTK_OBJECT (tree_view));
12469 g_signal_stop_emission_by_name (widget, "event");
12471 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12472 pspp_sheet_view_start_editing (tree_view, path);
12473 gtk_tree_path_free (path);
12479 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12482 PsppSheetView *sheet_view = data;
12484 g_signal_connect (widget, "event",
12485 G_CALLBACK (pspp_sheet_view_event),
12488 if (GTK_IS_CONTAINER (widget))
12489 gtk_container_foreach (GTK_CONTAINER (widget),
12490 pspp_sheet_view_override_cell_keypresses,
12495 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12496 PsppSheetViewColumn *column,
12498 GtkCellEditable *cell_editable,
12499 GdkRectangle *cell_area,
12503 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12504 gint pre_val = tree_view->priv->vadjustment->value;
12505 GtkRequisition requisition;
12508 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12510 tree_view->priv->edited_column = column;
12511 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12513 row = gtk_tree_path_get_indices (path)[0];
12514 tree_view->priv->edited_row = row;
12515 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12516 cell_area->y += pre_val - (int)tree_view->priv->vadjustment->value;
12518 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12519 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12520 tree_view->priv->anchor_column = column;
12522 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12524 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12526 if (requisition.height < cell_area->height)
12528 gint diff = cell_area->height - requisition.height;
12529 pspp_sheet_view_put (tree_view,
12530 GTK_WIDGET (cell_editable),
12531 cell_area->x, cell_area->y + diff/2,
12532 cell_area->width, requisition.height);
12536 pspp_sheet_view_put (tree_view,
12537 GTK_WIDGET (cell_editable),
12538 cell_area->x, cell_area->y,
12539 cell_area->width, cell_area->height);
12542 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12543 (GdkEvent *)event);
12545 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12546 g_signal_connect (cell_editable, "remove-widget",
12547 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12548 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12549 GTK_IS_BUTTON (cell_editable))
12551 g_signal_connect (cell_editable, "button-press-event",
12552 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12554 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12555 GINT_TO_POINTER (row));
12556 g_signal_connect (cell_editable, "clicked",
12557 G_CALLBACK (pspp_sheet_view_editable_clicked),
12561 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12566 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12567 gboolean cancel_editing)
12569 PsppSheetViewColumn *column;
12570 GtkCellRenderer *cell;
12572 if (tree_view->priv->edited_column == NULL)
12576 * This is very evil. We need to do this, because
12577 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12578 * later on. If pspp_sheet_view_row_changed notices
12579 * tree_view->priv->edited_column != NULL, it'll call
12580 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12582 * Please read that again if you intend to modify anything here.
12585 column = tree_view->priv->edited_column;
12586 tree_view->priv->edited_column = NULL;
12588 cell = _pspp_sheet_view_column_get_edited_cell (column);
12589 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12591 if (!cancel_editing)
12592 gtk_cell_editable_editing_done (column->editable_widget);
12594 tree_view->priv->edited_column = column;
12596 gtk_cell_editable_remove_widget (column->editable_widget);
12601 * pspp_sheet_view_set_hover_selection:
12602 * @tree_view: a #PsppSheetView
12603 * @hover: %TRUE to enable hover selection mode
12605 * Enables of disables the hover selection mode of @tree_view.
12606 * Hover selection makes the selected row follow the pointer.
12607 * Currently, this works only for the selection modes
12608 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12613 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12616 hover = hover != FALSE;
12618 if (hover != tree_view->priv->hover_selection)
12620 tree_view->priv->hover_selection = hover;
12622 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12627 * pspp_sheet_view_get_hover_selection:
12628 * @tree_view: a #PsppSheetView
12630 * Returns whether hover selection mode is turned on for @tree_view.
12632 * Return value: %TRUE if @tree_view is in hover selection mode
12637 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12639 return tree_view->priv->hover_selection;
12643 * pspp_sheet_view_set_rubber_banding:
12644 * @tree_view: a #PsppSheetView
12645 * @enable: %TRUE to enable rubber banding
12647 * Enables or disables rubber banding in @tree_view. If the selection mode is
12648 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12649 * banding will allow the user to select multiple rows by dragging the mouse.
12654 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12657 enable = enable != FALSE;
12659 if (enable != tree_view->priv->rubber_banding_enable)
12661 tree_view->priv->rubber_banding_enable = enable;
12663 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12668 * pspp_sheet_view_get_rubber_banding:
12669 * @tree_view: a #PsppSheetView
12671 * Returns whether rubber banding is turned on for @tree_view. If the
12672 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12673 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12674 * select multiple rows by dragging the mouse.
12676 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12681 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12683 return tree_view->priv->rubber_banding_enable;
12687 * pspp_sheet_view_is_rubber_banding_active:
12688 * @tree_view: a #PsppSheetView
12690 * Returns whether a rubber banding operation is currently being done
12693 * Return value: %TRUE if a rubber banding operation is currently being
12694 * done in @tree_view.
12699 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12701 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12703 if (tree_view->priv->rubber_banding_enable
12704 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12711 pspp_sheet_view_grab_notify (GtkWidget *widget,
12712 gboolean was_grabbed)
12714 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12716 tree_view->priv->in_grab = !was_grabbed;
12720 tree_view->priv->pressed_button = -1;
12722 if (tree_view->priv->rubber_band_status)
12723 pspp_sheet_view_stop_rubber_band (tree_view);
12728 pspp_sheet_view_state_changed (GtkWidget *widget,
12729 GtkStateType previous_state)
12731 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12733 if (gtk_widget_get_realized (widget))
12735 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
12736 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
12739 gtk_widget_queue_draw (widget);
12743 * pspp_sheet_view_get_grid_lines:
12744 * @tree_view: a #PsppSheetView
12746 * Returns which grid lines are enabled in @tree_view.
12748 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12753 PsppSheetViewGridLines
12754 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12756 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12758 return tree_view->priv->grid_lines;
12762 * pspp_sheet_view_set_grid_lines:
12763 * @tree_view: a #PsppSheetView
12764 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12767 * Sets which grid lines to draw in @tree_view.
12772 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12773 PsppSheetViewGridLines grid_lines)
12775 PsppSheetViewPrivate *priv;
12776 PsppSheetViewGridLines old_grid_lines;
12778 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12780 priv = tree_view->priv;
12782 old_grid_lines = priv->grid_lines;
12783 priv->grid_lines = grid_lines;
12785 if (old_grid_lines != grid_lines)
12787 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12789 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12794 * pspp_sheet_view_get_special_cells:
12795 * @tree_view: a #PsppSheetView
12797 * Returns which grid lines are enabled in @tree_view.
12799 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12800 * the sheet view contain special cells.
12802 PsppSheetViewSpecialCells
12803 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12805 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12807 return tree_view->priv->special_cells;
12811 * pspp_sheet_view_set_special_cells:
12812 * @tree_view: a #PsppSheetView
12813 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12814 * the sheet view contain special cells.
12816 * Sets whether rows in the sheet view contain special cells, controlling the
12817 * rendering of row selections.
12820 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12821 PsppSheetViewSpecialCells special_cells)
12823 PsppSheetViewPrivate *priv;
12825 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12827 priv = tree_view->priv;
12829 if (priv->special_cells != special_cells)
12831 priv->special_cells = special_cells;
12832 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12833 g_object_notify (G_OBJECT (tree_view), "special-cells");
12838 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12840 /* XXX (re)calculate fixed_height if necessary */
12841 return tree_view->priv->fixed_height;
12845 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12848 g_return_if_fail (fixed_height > 0);
12850 if (tree_view->priv->fixed_height != fixed_height)
12852 tree_view->priv->fixed_height = fixed_height;
12853 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12855 if (!tree_view->priv->fixed_height_set)
12857 tree_view->priv->fixed_height_set = TRUE;
12858 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12863 * pspp_sheet_view_set_tooltip_row:
12864 * @tree_view: a #PsppSheetView
12865 * @tooltip: a #GtkTooltip
12866 * @path: a #GtkTreePath
12868 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12869 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12870 * See also gtk_tooltip_set_tip_area().
12875 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12876 GtkTooltip *tooltip,
12879 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12880 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12882 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12886 * pspp_sheet_view_set_tooltip_cell:
12887 * @tree_view: a #PsppSheetView
12888 * @tooltip: a #GtkTooltip
12889 * @path: (allow-none): a #GtkTreePath or %NULL
12890 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12891 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12893 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12894 * in common. For example if @path is %NULL and @column is set, the tip
12895 * area will be set to the full area covered by @column. See also
12896 * gtk_tooltip_set_tip_area().
12898 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12903 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12904 GtkTooltip *tooltip,
12906 PsppSheetViewColumn *column,
12907 GtkCellRenderer *cell)
12911 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12912 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12913 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12914 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12916 /* Determine x values. */
12917 if (column && cell)
12922 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12923 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12925 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12928 rect.width = width;
12934 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
12935 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12938 rect.width = tmp.width;
12943 rect.width = GTK_WIDGET (tree_view)->allocation.width;
12946 /* Determine y values. */
12951 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
12952 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12955 rect.height = tmp.height;
12960 rect.height = tree_view->priv->vadjustment->page_size;
12963 gtk_tooltip_set_tip_area (tooltip, &rect);
12967 * pspp_sheet_view_get_tooltip_context:
12968 * @tree_view: a #PsppSheetView
12969 * @x: the x coordinate (relative to widget coordinates)
12970 * @y: the y coordinate (relative to widget coordinates)
12971 * @keyboard_tip: whether this is a keyboard tooltip or not
12972 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
12973 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
12974 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
12976 * This function is supposed to be used in a #GtkWidget::query-tooltip
12977 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
12978 * which are received in the signal handler, should be passed to this
12979 * function without modification.
12981 * The return value indicates whether there is a tree view row at the given
12982 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
12983 * tooltips the row returned will be the cursor row. When %TRUE, then any of
12984 * @model, @path and @iter which have been provided will be set to point to
12985 * that row and the corresponding model. @x and @y will always be converted
12986 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
12988 * Return value: whether or not the given tooltip context points to a row.
12993 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
12996 gboolean keyboard_tip,
12997 GtkTreeModel **model,
12998 GtkTreePath **path,
13001 GtkTreePath *tmppath = NULL;
13003 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
13004 g_return_val_if_fail (x != NULL, FALSE);
13005 g_return_val_if_fail (y != NULL, FALSE);
13009 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
13016 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
13019 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
13020 &tmppath, NULL, NULL, NULL))
13025 *model = pspp_sheet_view_get_model (tree_view);
13028 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
13034 gtk_tree_path_free (tmppath);
13040 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
13043 gboolean keyboard_tip,
13044 GtkTooltip *tooltip,
13047 GValue value = { 0, };
13048 GValue transformed = { 0, };
13051 GtkTreeModel *model;
13052 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
13054 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
13057 &model, &path, &iter))
13060 gtk_tree_model_get_value (model, &iter,
13061 tree_view->priv->tooltip_column, &value);
13063 g_value_init (&transformed, G_TYPE_STRING);
13065 if (!g_value_transform (&value, &transformed))
13067 g_value_unset (&value);
13068 gtk_tree_path_free (path);
13073 g_value_unset (&value);
13075 if (!g_value_get_string (&transformed))
13077 g_value_unset (&transformed);
13078 gtk_tree_path_free (path);
13083 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
13084 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
13086 gtk_tree_path_free (path);
13087 g_value_unset (&transformed);
13093 * pspp_sheet_view_set_tooltip_column:
13094 * @tree_view: a #PsppSheetView
13095 * @column: an integer, which is a valid column number for @tree_view's model
13097 * If you only plan to have simple (text-only) tooltips on full rows, you
13098 * can use this function to have #PsppSheetView handle these automatically
13099 * for you. @column should be set to the column in @tree_view's model
13100 * containing the tooltip texts, or -1 to disable this feature.
13102 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
13103 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
13105 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
13106 * so &, <, etc have to be escaped in the text.
13111 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
13114 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13116 if (column == tree_view->priv->tooltip_column)
13121 g_signal_handlers_disconnect_by_func (tree_view,
13122 pspp_sheet_view_set_tooltip_query_cb,
13124 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
13128 if (tree_view->priv->tooltip_column == -1)
13130 g_signal_connect (tree_view, "query-tooltip",
13131 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
13132 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
13136 tree_view->priv->tooltip_column = column;
13137 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
13141 * pspp_sheet_view_get_tooltip_column:
13142 * @tree_view: a #PsppSheetView
13144 * Returns the column of @tree_view's model which is being used for
13145 * displaying tooltips on @tree_view's rows.
13147 * Return value: the index of the tooltip column that is currently being
13148 * used, or -1 if this is disabled.
13153 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
13155 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
13157 return tree_view->priv->tooltip_column;
13161 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
13162 GValue *return_accu,
13163 const GValue *handler_return,
13166 gboolean continue_emission;
13167 gboolean signal_handled;
13169 signal_handled = g_value_get_boolean (handler_return);
13170 g_value_set_boolean (return_accu, signal_handled);
13171 continue_emission = !signal_handled;
13173 return continue_emission;
13177 pspp_sheet_view_grid_lines_get_type (void)
13179 static GType etype = 0;
13180 if (G_UNLIKELY(etype == 0)) {
13181 static const GEnumValue values[] = {
13182 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
13183 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
13184 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
13185 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
13188 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
13194 pspp_sheet_view_special_cells_get_type (void)
13196 static GType etype = 0;
13197 if (G_UNLIKELY(etype == 0)) {
13198 static const GEnumValue values[] = {
13199 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
13200 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
13201 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
13204 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);