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,
359 static void pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
360 PsppSheetView *tree_view);
362 static void pspp_sheet_view_search_activate (GtkEntry *entry,
363 PsppSheetView *tree_view);
364 static gboolean pspp_sheet_view_real_search_enable_popdown(gpointer data);
365 static void pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
367 static gboolean pspp_sheet_view_search_delete_event (GtkWidget *widget,
369 PsppSheetView *tree_view);
370 static gboolean pspp_sheet_view_search_button_press_event (GtkWidget *widget,
371 GdkEventButton *event,
372 PsppSheetView *tree_view);
373 static gboolean pspp_sheet_view_search_scroll_event (GtkWidget *entry,
374 GdkEventScroll *event,
375 PsppSheetView *tree_view);
376 static gboolean pspp_sheet_view_search_key_press_event (GtkWidget *entry,
378 PsppSheetView *tree_view);
379 static gboolean pspp_sheet_view_search_move (GtkWidget *window,
380 PsppSheetView *tree_view,
382 static gboolean pspp_sheet_view_search_equal_func (GtkTreeModel *model,
386 gpointer search_data);
387 static gboolean pspp_sheet_view_search_iter (GtkTreeModel *model,
388 PsppSheetSelection *selection,
393 static void pspp_sheet_view_search_init (GtkWidget *entry,
394 PsppSheetView *tree_view);
395 static void pspp_sheet_view_put (PsppSheetView *tree_view,
396 GtkWidget *child_widget,
401 static gboolean pspp_sheet_view_start_editing (PsppSheetView *tree_view,
402 GtkTreePath *cursor_path);
403 static gboolean pspp_sheet_view_editable_button_press_event (GtkWidget *,
406 static void pspp_sheet_view_editable_clicked (GtkButton *, PsppSheetView *);
407 static void pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
408 PsppSheetViewColumn *column,
410 GtkCellEditable *cell_editable,
411 GdkRectangle *cell_area,
414 static gboolean pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
415 gboolean keybinding);
416 static gboolean pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view);
417 static PsppSheetViewColumn *pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
418 PsppSheetViewColumn *column,
421 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
422 PsppSheetViewColumn *column,
423 const GdkRectangle *background_area,
424 gboolean subtract_focus_rect,
425 GdkRectangle *cell_area);
426 static gint pspp_sheet_view_find_offset (PsppSheetView *tree_view,
431 static void pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
435 static void pspp_sheet_view_buildable_init (GtkBuildableIface *iface);
438 static gboolean scroll_row_timeout (gpointer data);
439 static void add_scroll_timeout (PsppSheetView *tree_view);
440 static void remove_scroll_timeout (PsppSheetView *tree_view);
442 static guint tree_view_signals [LAST_SIGNAL] = { 0 };
444 static GtkBindingSet *edit_bindings;
451 G_DEFINE_TYPE_WITH_CODE (PsppSheetView, pspp_sheet_view, GTK_TYPE_CONTAINER,
452 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
453 pspp_sheet_view_buildable_init))
456 pspp_sheet_view_class_init (PsppSheetViewClass *class)
458 GObjectClass *o_class;
459 GtkWidgetClass *widget_class;
460 GtkContainerClass *container_class;
461 GtkBindingSet *binding_set[2];
464 binding_set[0] = gtk_binding_set_by_class (class);
466 binding_set[1] = gtk_binding_set_new ("PsppSheetViewEditing");
467 edit_bindings = binding_set[1];
469 o_class = (GObjectClass *) class;
470 widget_class = (GtkWidgetClass *) class;
471 container_class = (GtkContainerClass *) class;
473 /* GObject signals */
474 o_class->set_property = pspp_sheet_view_set_property;
475 o_class->get_property = pspp_sheet_view_get_property;
476 o_class->finalize = pspp_sheet_view_finalize;
477 o_class->dispose = pspp_sheet_view_dispose;
479 /* GtkWidget signals */
480 widget_class->map = pspp_sheet_view_map;
481 widget_class->realize = pspp_sheet_view_realize;
482 widget_class->unrealize = pspp_sheet_view_unrealize;
483 widget_class->size_request = pspp_sheet_view_size_request;
484 widget_class->size_allocate = pspp_sheet_view_size_allocate;
485 widget_class->button_press_event = pspp_sheet_view_button_press;
486 widget_class->button_release_event = pspp_sheet_view_button_release;
487 widget_class->grab_broken_event = pspp_sheet_view_grab_broken;
488 /*widget_class->configure_event = pspp_sheet_view_configure;*/
489 widget_class->motion_notify_event = pspp_sheet_view_motion;
490 widget_class->expose_event = pspp_sheet_view_expose;
491 widget_class->key_press_event = pspp_sheet_view_key_press;
492 widget_class->key_release_event = pspp_sheet_view_key_release;
493 widget_class->enter_notify_event = pspp_sheet_view_enter_notify;
494 widget_class->leave_notify_event = pspp_sheet_view_leave_notify;
495 widget_class->focus_out_event = pspp_sheet_view_focus_out;
496 widget_class->drag_begin = pspp_sheet_view_drag_begin;
497 widget_class->drag_end = pspp_sheet_view_drag_end;
498 widget_class->drag_data_get = pspp_sheet_view_drag_data_get;
499 widget_class->drag_data_delete = pspp_sheet_view_drag_data_delete;
500 widget_class->drag_leave = pspp_sheet_view_drag_leave;
501 widget_class->drag_motion = pspp_sheet_view_drag_motion;
502 widget_class->drag_drop = pspp_sheet_view_drag_drop;
503 widget_class->drag_data_received = pspp_sheet_view_drag_data_received;
504 widget_class->focus = pspp_sheet_view_focus;
505 widget_class->grab_focus = pspp_sheet_view_grab_focus;
506 widget_class->style_set = pspp_sheet_view_style_set;
507 widget_class->grab_notify = pspp_sheet_view_grab_notify;
508 widget_class->state_changed = pspp_sheet_view_state_changed;
510 /* GtkContainer signals */
511 container_class->remove = pspp_sheet_view_remove;
512 container_class->forall = pspp_sheet_view_forall;
513 container_class->set_focus_child = pspp_sheet_view_set_focus_child;
515 class->set_scroll_adjustments = pspp_sheet_view_set_adjustments;
516 class->move_cursor = pspp_sheet_view_real_move_cursor;
517 class->select_all = pspp_sheet_view_real_select_all;
518 class->unselect_all = pspp_sheet_view_real_unselect_all;
519 class->select_cursor_row = pspp_sheet_view_real_select_cursor_row;
520 class->toggle_cursor_row = pspp_sheet_view_real_toggle_cursor_row;
521 class->start_interactive_search = pspp_sheet_view_start_interactive_search;
525 g_object_class_install_property (o_class,
527 g_param_spec_object ("model",
528 P_("TreeView Model"),
529 P_("The model for the tree view"),
531 GTK_PARAM_READWRITE));
533 g_object_class_install_property (o_class,
535 g_param_spec_object ("hadjustment",
536 P_("Horizontal Adjustment"),
537 P_("Horizontal Adjustment for the widget"),
539 GTK_PARAM_READWRITE));
541 g_object_class_install_property (o_class,
543 g_param_spec_object ("vadjustment",
544 P_("Vertical Adjustment"),
545 P_("Vertical Adjustment for the widget"),
547 GTK_PARAM_READWRITE));
549 g_object_class_install_property (o_class,
550 PROP_HEADERS_VISIBLE,
551 g_param_spec_boolean ("headers-visible",
552 P_("Headers Visible"),
553 P_("Show the column header buttons"),
555 GTK_PARAM_READWRITE));
557 g_object_class_install_property (o_class,
558 PROP_HEADERS_CLICKABLE,
559 g_param_spec_boolean ("headers-clickable",
560 P_("Headers Clickable"),
561 P_("Column headers respond to click events"),
563 GTK_PARAM_READWRITE));
565 g_object_class_install_property (o_class,
567 g_param_spec_boolean ("reorderable",
569 P_("View is reorderable"),
571 GTK_PARAM_READWRITE));
573 g_object_class_install_property (o_class,
575 g_param_spec_boolean ("rules-hint",
577 P_("Set a hint to the theme engine to draw rows in alternating colors"),
579 GTK_PARAM_READWRITE));
581 g_object_class_install_property (o_class,
583 g_param_spec_boolean ("enable-search",
585 P_("View allows user to search through columns interactively"),
587 GTK_PARAM_READWRITE));
589 g_object_class_install_property (o_class,
591 g_param_spec_int ("search-column",
593 P_("Model column to search through during interactive search"),
597 GTK_PARAM_READWRITE));
600 * PsppSheetView:hover-selection:
602 * Enables of disables the hover selection mode of @tree_view.
603 * Hover selection makes the selected row follow the pointer.
604 * Currently, this works only for the selection modes
605 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
607 * This mode is primarily intended for treeviews in popups, e.g.
608 * in #GtkComboBox or #GtkEntryCompletion.
612 g_object_class_install_property (o_class,
613 PROP_HOVER_SELECTION,
614 g_param_spec_boolean ("hover-selection",
615 P_("Hover Selection"),
616 P_("Whether the selection should follow the pointer"),
618 GTK_PARAM_READWRITE));
620 g_object_class_install_property (o_class,
622 g_param_spec_boolean ("rubber-banding",
623 P_("Rubber Banding"),
624 P_("Whether to enable selection of multiple items by dragging the mouse pointer"),
626 GTK_PARAM_READWRITE));
628 g_object_class_install_property (o_class,
629 PROP_ENABLE_GRID_LINES,
630 g_param_spec_enum ("enable-grid-lines",
631 P_("Enable Grid Lines"),
632 P_("Whether grid lines should be drawn in the tree view"),
633 PSPP_TYPE_SHEET_VIEW_GRID_LINES,
634 PSPP_SHEET_VIEW_GRID_LINES_NONE,
635 GTK_PARAM_READWRITE));
637 g_object_class_install_property (o_class,
639 g_param_spec_int ("tooltip-column",
640 P_("Tooltip Column"),
641 P_("The column in the model containing the tooltip texts for the rows"),
645 GTK_PARAM_READWRITE));
647 g_object_class_install_property (o_class,
649 g_param_spec_enum ("special-cells",
651 P_("Whether rows have special cells."),
652 PSPP_TYPE_SHEET_VIEW_SPECIAL_CELLS,
653 PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT,
654 GTK_PARAM_READWRITE));
656 g_object_class_install_property (o_class,
658 g_param_spec_int ("fixed-height",
660 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."),
664 GTK_PARAM_READWRITE));
666 g_object_class_install_property (o_class,
667 PROP_FIXED_HEIGHT_SET,
668 g_param_spec_boolean ("fixed-height-set",
669 P_("Fixed Height Set"),
670 P_("Whether fixed-height was set externally."),
672 GTK_PARAM_READWRITE));
674 /* Style properties */
675 #define _TREE_VIEW_EXPANDER_SIZE 12
676 #define _TREE_VIEW_VERTICAL_SEPARATOR 2
677 #define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
679 gtk_widget_class_install_style_property (widget_class,
680 g_param_spec_int ("expander-size",
682 P_("Size of the expander arrow"),
685 _TREE_VIEW_EXPANDER_SIZE,
686 GTK_PARAM_READABLE));
688 gtk_widget_class_install_style_property (widget_class,
689 g_param_spec_int ("vertical-separator",
690 P_("Vertical Separator Width"),
691 P_("Vertical space between cells. Must be an even number"),
694 _TREE_VIEW_VERTICAL_SEPARATOR,
695 GTK_PARAM_READABLE));
697 gtk_widget_class_install_style_property (widget_class,
698 g_param_spec_int ("horizontal-separator",
699 P_("Horizontal Separator Width"),
700 P_("Horizontal space between cells. Must be an even number"),
703 _TREE_VIEW_HORIZONTAL_SEPARATOR,
704 GTK_PARAM_READABLE));
706 gtk_widget_class_install_style_property (widget_class,
707 g_param_spec_boolean ("allow-rules",
709 P_("Allow drawing of alternating color rows"),
711 GTK_PARAM_READABLE));
713 gtk_widget_class_install_style_property (widget_class,
714 g_param_spec_boxed ("even-row-color",
715 P_("Even Row Color"),
716 P_("Color to use for even rows"),
718 GTK_PARAM_READABLE));
720 gtk_widget_class_install_style_property (widget_class,
721 g_param_spec_boxed ("odd-row-color",
723 P_("Color to use for odd rows"),
725 GTK_PARAM_READABLE));
727 gtk_widget_class_install_style_property (widget_class,
728 g_param_spec_boolean ("row-ending-details",
729 P_("Row Ending details"),
730 P_("Enable extended row background theming"),
732 GTK_PARAM_READABLE));
734 gtk_widget_class_install_style_property (widget_class,
735 g_param_spec_int ("grid-line-width",
736 P_("Grid line width"),
737 P_("Width, in pixels, of the tree view grid lines"),
739 GTK_PARAM_READABLE));
741 gtk_widget_class_install_style_property (widget_class,
742 g_param_spec_int ("tree-line-width",
743 P_("Tree line width"),
744 P_("Width, in pixels, of the tree view lines"),
746 GTK_PARAM_READABLE));
748 gtk_widget_class_install_style_property (widget_class,
749 g_param_spec_string ("tree-line-pattern",
750 P_("Tree line pattern"),
751 P_("Dash pattern used to draw the tree view lines"),
753 GTK_PARAM_READABLE));
757 * PsppSheetView::set-scroll-adjustments
758 * @horizontal: the horizontal #GtkAdjustment
759 * @vertical: the vertical #GtkAdjustment
761 * Set the scroll adjustments for the tree view. Usually scrolled containers
762 * like #GtkScrolledWindow will emit this signal to connect two instances
763 * of #GtkScrollbar to the scroll directions of the #PsppSheetView.
765 widget_class->set_scroll_adjustments_signal =
766 g_signal_new ("set-scroll-adjustments",
767 G_TYPE_FROM_CLASS (o_class),
768 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
769 G_STRUCT_OFFSET (PsppSheetViewClass, set_scroll_adjustments),
771 psppire_marshal_VOID__OBJECT_OBJECT,
774 GTK_TYPE_ADJUSTMENT);
777 * PsppSheetView::row-activated:
778 * @tree_view: the object on which the signal is emitted
779 * @path: the #GtkTreePath for the activated row
780 * @column: the #PsppSheetViewColumn in which the activation occurred
782 * The "row-activated" signal is emitted when the method
783 * pspp_sheet_view_row_activated() is called or the user double clicks
784 * a treeview row. It is also emitted when a non-editable row is
785 * selected and one of the keys: Space, Shift+Space, Return or
788 * For selection handling refer to the <link linkend="TreeWidget">tree
789 * widget conceptual overview</link> as well as #PsppSheetSelection.
791 tree_view_signals[ROW_ACTIVATED] =
792 g_signal_new ("row-activated",
793 G_TYPE_FROM_CLASS (o_class),
794 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
795 G_STRUCT_OFFSET (PsppSheetViewClass, row_activated),
797 psppire_marshal_VOID__BOXED_OBJECT,
800 PSPP_TYPE_SHEET_VIEW_COLUMN);
803 * PsppSheetView::columns-changed:
804 * @tree_view: the object on which the signal is emitted
806 * The number of columns of the treeview has changed.
808 tree_view_signals[COLUMNS_CHANGED] =
809 g_signal_new ("columns-changed",
810 G_TYPE_FROM_CLASS (o_class),
812 G_STRUCT_OFFSET (PsppSheetViewClass, columns_changed),
814 g_cclosure_marshal_VOID__VOID,
818 * PsppSheetView::cursor-changed:
819 * @tree_view: the object on which the signal is emitted
821 * The position of the cursor (focused cell) has changed.
823 tree_view_signals[CURSOR_CHANGED] =
824 g_signal_new ("cursor-changed",
825 G_TYPE_FROM_CLASS (o_class),
827 G_STRUCT_OFFSET (PsppSheetViewClass, cursor_changed),
829 g_cclosure_marshal_VOID__VOID,
832 tree_view_signals[MOVE_CURSOR] =
833 g_signal_new ("move-cursor",
834 G_TYPE_FROM_CLASS (o_class),
835 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
836 G_STRUCT_OFFSET (PsppSheetViewClass, move_cursor),
838 psppire_marshal_BOOLEAN__ENUM_INT,
840 GTK_TYPE_MOVEMENT_STEP,
843 tree_view_signals[SELECT_ALL] =
844 g_signal_new ("select-all",
845 G_TYPE_FROM_CLASS (o_class),
846 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
847 G_STRUCT_OFFSET (PsppSheetViewClass, select_all),
849 psppire_marshal_BOOLEAN__VOID,
852 tree_view_signals[UNSELECT_ALL] =
853 g_signal_new ("unselect-all",
854 G_TYPE_FROM_CLASS (o_class),
855 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
856 G_STRUCT_OFFSET (PsppSheetViewClass, unselect_all),
858 psppire_marshal_BOOLEAN__VOID,
861 tree_view_signals[SELECT_CURSOR_ROW] =
862 g_signal_new ("select-cursor-row",
863 G_TYPE_FROM_CLASS (o_class),
864 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
865 G_STRUCT_OFFSET (PsppSheetViewClass, select_cursor_row),
867 psppire_marshal_BOOLEAN__BOOLEAN,
869 G_TYPE_BOOLEAN, G_TYPE_INT);
871 tree_view_signals[TOGGLE_CURSOR_ROW] =
872 g_signal_new ("toggle-cursor-row",
873 G_TYPE_FROM_CLASS (o_class),
874 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
875 G_STRUCT_OFFSET (PsppSheetViewClass, toggle_cursor_row),
877 psppire_marshal_BOOLEAN__VOID,
880 tree_view_signals[START_INTERACTIVE_SEARCH] =
881 g_signal_new ("start-interactive-search",
882 G_TYPE_FROM_CLASS (o_class),
883 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
884 G_STRUCT_OFFSET (PsppSheetViewClass, start_interactive_search),
886 psppire_marshal_BOOLEAN__VOID,
890 for (i = 0; i < 2; i++)
892 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Up, 0, TRUE,
893 GTK_MOVEMENT_DISPLAY_LINES, -1);
894 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Up, 0, TRUE,
895 GTK_MOVEMENT_DISPLAY_LINES, -1);
897 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Down, 0, TRUE,
898 GTK_MOVEMENT_DISPLAY_LINES, 1);
899 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Down, 0, TRUE,
900 GTK_MOVEMENT_DISPLAY_LINES, 1);
902 pspp_sheet_view_add_move_binding (binding_set[i], GDK_p, GDK_CONTROL_MASK, FALSE,
903 GTK_MOVEMENT_DISPLAY_LINES, -1);
905 pspp_sheet_view_add_move_binding (binding_set[i], GDK_n, GDK_CONTROL_MASK, FALSE,
906 GTK_MOVEMENT_DISPLAY_LINES, 1);
908 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Home, 0, TRUE,
909 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
910 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Home, 0, TRUE,
911 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
913 pspp_sheet_view_add_move_binding (binding_set[i], GDK_End, 0, TRUE,
914 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
915 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_End, 0, TRUE,
916 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
918 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Up, 0, TRUE,
919 GTK_MOVEMENT_PAGES, -1);
920 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Up, 0, TRUE,
921 GTK_MOVEMENT_PAGES, -1);
923 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Down, 0, TRUE,
924 GTK_MOVEMENT_PAGES, 1);
925 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Down, 0, TRUE,
926 GTK_MOVEMENT_PAGES, 1);
929 gtk_binding_entry_add_signal (binding_set[i], GDK_Up, GDK_CONTROL_MASK, "move-cursor", 2,
930 G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
933 gtk_binding_entry_add_signal (binding_set[i], GDK_Down, GDK_CONTROL_MASK, "move-cursor", 2,
934 G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
937 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, 0, "move-cursor", 2,
938 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
941 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, 0, "move-cursor", 2,
942 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
945 gtk_binding_entry_add_signal (binding_set[i], GDK_Tab, 0, "move-cursor", 2,
946 G_TYPE_ENUM, GTK_MOVEMENT_LOGICAL_POSITIONS,
949 gtk_binding_entry_add_signal (binding_set[i], GDK_Tab, GDK_SHIFT_MASK, "move-cursor", 2,
950 G_TYPE_ENUM, GTK_MOVEMENT_LOGICAL_POSITIONS,
953 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, 0, "move-cursor", 2,
954 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
957 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, 0, "move-cursor", 2,
958 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
961 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, GDK_CONTROL_MASK,
963 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
966 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, GDK_CONTROL_MASK,
968 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
971 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, GDK_CONTROL_MASK,
973 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
976 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, GDK_CONTROL_MASK,
978 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
981 gtk_binding_entry_add_signal (binding_set[i], GDK_f, GDK_CONTROL_MASK, "start-interactive-search", 0);
983 gtk_binding_entry_add_signal (binding_set[i], GDK_F, GDK_CONTROL_MASK, "start-interactive-search", 0);
986 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
987 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
989 gtk_binding_entry_add_signal (binding_set[0], GDK_a, GDK_CONTROL_MASK, "select-all", 0);
990 gtk_binding_entry_add_signal (binding_set[0], GDK_slash, GDK_CONTROL_MASK, "select-all", 0);
992 gtk_binding_entry_add_signal (binding_set[0], GDK_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0);
993 gtk_binding_entry_add_signal (binding_set[0], GDK_backslash, GDK_CONTROL_MASK, "unselect-all", 0);
995 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_SHIFT_MASK, "select-cursor-row", 1,
996 G_TYPE_BOOLEAN, TRUE,
997 G_TYPE_INT, PSPP_SHEET_SELECT_MODE_EXTEND);
998 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", 1,
999 G_TYPE_BOOLEAN, TRUE,
1000 G_TYPE_INT, PSPP_SHEET_SELECT_MODE_EXTEND);
1002 gtk_binding_entry_add_signal (binding_set[0], GDK_space, 0, "select-cursor-row", 1,
1003 G_TYPE_BOOLEAN, TRUE,
1005 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, 0, "select-cursor-row", 1,
1006 G_TYPE_BOOLEAN, TRUE,
1008 gtk_binding_entry_add_signal (binding_set[0], GDK_Return, 0, "select-cursor-row", 1,
1009 G_TYPE_BOOLEAN, TRUE,
1011 gtk_binding_entry_add_signal (binding_set[0], GDK_ISO_Enter, 0, "select-cursor-row", 1,
1012 G_TYPE_BOOLEAN, TRUE,
1014 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Enter, 0, "select-cursor-row", 1,
1015 G_TYPE_BOOLEAN, TRUE,
1018 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, 0, "select-cursor-parent", 0);
1019 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", 0);
1021 g_type_class_add_private (o_class, sizeof (PsppSheetViewPrivate));
1025 pspp_sheet_view_buildable_init (GtkBuildableIface *iface)
1027 iface->add_child = pspp_sheet_view_buildable_add_child;
1031 pspp_sheet_view_init (PsppSheetView *tree_view)
1033 tree_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (tree_view, PSPP_TYPE_SHEET_VIEW, PsppSheetViewPrivate);
1035 gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
1036 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (tree_view), FALSE);
1038 tree_view->priv->flags = PSPP_SHEET_VIEW_DRAW_KEYFOCUS
1039 | PSPP_SHEET_VIEW_HEADERS_VISIBLE;
1041 /* We need some padding */
1042 tree_view->priv->selected = range_tower_create ();
1043 tree_view->priv->dy = 0;
1044 tree_view->priv->cursor_offset = 0;
1045 tree_view->priv->n_columns = 0;
1046 tree_view->priv->header_height = 1;
1047 tree_view->priv->x_drag = 0;
1048 tree_view->priv->drag_pos = -1;
1049 tree_view->priv->header_has_focus = FALSE;
1050 tree_view->priv->pressed_button = -1;
1051 tree_view->priv->press_start_x = -1;
1052 tree_view->priv->press_start_y = -1;
1053 tree_view->priv->reorderable = FALSE;
1054 tree_view->priv->presize_handler_timer = 0;
1055 tree_view->priv->scroll_sync_timer = 0;
1056 tree_view->priv->fixed_height = -1;
1057 tree_view->priv->fixed_height_set = FALSE;
1058 pspp_sheet_view_set_adjustments (tree_view, NULL, NULL);
1059 tree_view->priv->selection = _pspp_sheet_selection_new_with_tree_view (tree_view);
1060 tree_view->priv->enable_search = TRUE;
1061 tree_view->priv->search_column = -1;
1062 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
1063 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
1064 tree_view->priv->search_custom_entry_set = FALSE;
1065 tree_view->priv->typeselect_flush_timeout = 0;
1066 tree_view->priv->init_hadjust_value = TRUE;
1067 tree_view->priv->width = 0;
1069 tree_view->priv->hover_selection = FALSE;
1071 tree_view->priv->rubber_banding_enable = FALSE;
1073 tree_view->priv->grid_lines = PSPP_SHEET_VIEW_GRID_LINES_NONE;
1075 tree_view->priv->tooltip_column = -1;
1077 tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT;
1079 tree_view->priv->post_validation_flag = FALSE;
1081 tree_view->priv->last_button_x = -1;
1082 tree_view->priv->last_button_y = -1;
1084 tree_view->priv->event_last_x = -10000;
1085 tree_view->priv->event_last_y = -10000;
1087 tree_view->priv->prelight_node = -1;
1088 tree_view->priv->rubber_band_start_node = -1;
1089 tree_view->priv->rubber_band_end_node = -1;
1091 tree_view->priv->anchor_column = NULL;
1093 tree_view->priv->button_style = NULL;
1095 tree_view->dispose_has_run = FALSE;
1104 pspp_sheet_view_set_property (GObject *object,
1106 const GValue *value,
1109 PsppSheetView *tree_view;
1111 tree_view = PSPP_SHEET_VIEW (object);
1116 pspp_sheet_view_set_model (tree_view, g_value_get_object (value));
1118 case PROP_HADJUSTMENT:
1119 pspp_sheet_view_set_hadjustment (tree_view, g_value_get_object (value));
1121 case PROP_VADJUSTMENT:
1122 pspp_sheet_view_set_vadjustment (tree_view, g_value_get_object (value));
1124 case PROP_HEADERS_VISIBLE:
1125 pspp_sheet_view_set_headers_visible (tree_view, g_value_get_boolean (value));
1127 case PROP_HEADERS_CLICKABLE:
1128 pspp_sheet_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
1130 case PROP_REORDERABLE:
1131 pspp_sheet_view_set_reorderable (tree_view, g_value_get_boolean (value));
1133 case PROP_RULES_HINT:
1134 pspp_sheet_view_set_rules_hint (tree_view, g_value_get_boolean (value));
1136 case PROP_ENABLE_SEARCH:
1137 pspp_sheet_view_set_enable_search (tree_view, g_value_get_boolean (value));
1139 case PROP_SEARCH_COLUMN:
1140 pspp_sheet_view_set_search_column (tree_view, g_value_get_int (value));
1142 case PROP_HOVER_SELECTION:
1143 tree_view->priv->hover_selection = g_value_get_boolean (value);
1145 case PROP_RUBBER_BANDING:
1146 tree_view->priv->rubber_banding_enable = g_value_get_boolean (value);
1148 case PROP_ENABLE_GRID_LINES:
1149 pspp_sheet_view_set_grid_lines (tree_view, g_value_get_enum (value));
1151 case PROP_TOOLTIP_COLUMN:
1152 pspp_sheet_view_set_tooltip_column (tree_view, g_value_get_int (value));
1154 case PROP_SPECIAL_CELLS:
1155 pspp_sheet_view_set_special_cells (tree_view, g_value_get_enum (value));
1157 case PROP_FIXED_HEIGHT:
1158 pspp_sheet_view_set_fixed_height (tree_view, g_value_get_int (value));
1160 case PROP_FIXED_HEIGHT_SET:
1161 if (g_value_get_boolean (value))
1163 if (!tree_view->priv->fixed_height_set
1164 && tree_view->priv->fixed_height >= 0)
1166 tree_view->priv->fixed_height_set = true;
1167 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1172 if (tree_view->priv->fixed_height_set)
1174 tree_view->priv->fixed_height_set = false;
1175 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1176 install_presize_handler (tree_view);
1181 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1187 pspp_sheet_view_get_property (GObject *object,
1192 PsppSheetView *tree_view;
1194 tree_view = PSPP_SHEET_VIEW (object);
1199 g_value_set_object (value, tree_view->priv->model);
1201 case PROP_HADJUSTMENT:
1202 g_value_set_object (value, tree_view->priv->hadjustment);
1204 case PROP_VADJUSTMENT:
1205 g_value_set_object (value, tree_view->priv->vadjustment);
1207 case PROP_HEADERS_VISIBLE:
1208 g_value_set_boolean (value, pspp_sheet_view_get_headers_visible (tree_view));
1210 case PROP_HEADERS_CLICKABLE:
1211 g_value_set_boolean (value, pspp_sheet_view_get_headers_clickable (tree_view));
1213 case PROP_REORDERABLE:
1214 g_value_set_boolean (value, tree_view->priv->reorderable);
1216 case PROP_RULES_HINT:
1217 g_value_set_boolean (value, tree_view->priv->has_rules);
1219 case PROP_ENABLE_SEARCH:
1220 g_value_set_boolean (value, tree_view->priv->enable_search);
1222 case PROP_SEARCH_COLUMN:
1223 g_value_set_int (value, tree_view->priv->search_column);
1225 case PROP_HOVER_SELECTION:
1226 g_value_set_boolean (value, tree_view->priv->hover_selection);
1228 case PROP_RUBBER_BANDING:
1229 g_value_set_boolean (value, tree_view->priv->rubber_banding_enable);
1231 case PROP_ENABLE_GRID_LINES:
1232 g_value_set_enum (value, tree_view->priv->grid_lines);
1234 case PROP_TOOLTIP_COLUMN:
1235 g_value_set_int (value, tree_view->priv->tooltip_column);
1237 case PROP_SPECIAL_CELLS:
1238 g_value_set_enum (value, tree_view->priv->special_cells);
1240 case PROP_FIXED_HEIGHT:
1241 g_value_set_int (value, pspp_sheet_view_get_fixed_height (tree_view));
1243 case PROP_FIXED_HEIGHT_SET:
1244 g_value_set_boolean (value, tree_view->priv->fixed_height_set);
1247 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1253 pspp_sheet_view_dispose (GObject *object)
1255 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1257 if (tree_view->dispose_has_run)
1260 tree_view->dispose_has_run = TRUE;
1262 if (tree_view->priv->selection != NULL)
1264 _pspp_sheet_selection_set_tree_view (tree_view->priv->selection, NULL);
1265 g_object_unref (tree_view->priv->selection);
1266 tree_view->priv->selection = NULL;
1269 if (tree_view->priv->hadjustment)
1271 g_object_unref (tree_view->priv->hadjustment);
1272 tree_view->priv->hadjustment = NULL;
1274 if (tree_view->priv->vadjustment)
1276 g_object_unref (tree_view->priv->vadjustment);
1277 tree_view->priv->vadjustment = NULL;
1280 if (tree_view->priv->button_style)
1282 g_object_unref (tree_view->priv->button_style);
1283 tree_view->priv->button_style = NULL;
1287 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->dispose (object);
1293 pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
1294 GtkBuilder *builder,
1298 pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), PSPP_SHEET_VIEW_COLUMN (child));
1302 pspp_sheet_view_finalize (GObject *object)
1304 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1306 pspp_sheet_view_stop_editing (tree_view, TRUE);
1308 if (tree_view->priv->selected != NULL)
1310 range_tower_destroy (tree_view->priv->selected);
1311 tree_view->priv->selected = NULL;
1315 tree_view->priv->prelight_node = -1;
1318 if (tree_view->priv->scroll_to_path != NULL)
1320 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1321 tree_view->priv->scroll_to_path = NULL;
1324 if (tree_view->priv->drag_dest_row != NULL)
1326 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
1327 tree_view->priv->drag_dest_row = NULL;
1330 if (tree_view->priv->top_row != NULL)
1332 gtk_tree_row_reference_free (tree_view->priv->top_row);
1333 tree_view->priv->top_row = NULL;
1336 if (tree_view->priv->column_drop_func_data &&
1337 tree_view->priv->column_drop_func_data_destroy)
1339 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
1340 tree_view->priv->column_drop_func_data = NULL;
1343 if (tree_view->priv->destroy_count_destroy &&
1344 tree_view->priv->destroy_count_data)
1346 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
1347 tree_view->priv->destroy_count_data = NULL;
1350 gtk_tree_row_reference_free (tree_view->priv->cursor);
1351 tree_view->priv->cursor = NULL;
1353 gtk_tree_row_reference_free (tree_view->priv->anchor);
1354 tree_view->priv->anchor = NULL;
1356 /* destroy interactive search dialog */
1357 if (tree_view->priv->search_window)
1359 gtk_widget_destroy (tree_view->priv->search_window);
1360 tree_view->priv->search_window = NULL;
1361 tree_view->priv->search_entry = NULL;
1362 if (tree_view->priv->typeselect_flush_timeout)
1364 g_source_remove (tree_view->priv->typeselect_flush_timeout);
1365 tree_view->priv->typeselect_flush_timeout = 0;
1369 if (tree_view->priv->search_destroy && tree_view->priv->search_user_data)
1371 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
1372 tree_view->priv->search_user_data = NULL;
1375 if (tree_view->priv->search_position_destroy && tree_view->priv->search_position_user_data)
1377 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
1378 tree_view->priv->search_position_user_data = NULL;
1381 pspp_sheet_view_set_model (tree_view, NULL);
1384 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->finalize (object);
1389 /* GtkWidget Methods
1392 /* GtkWidget::map helper */
1394 pspp_sheet_view_map_buttons (PsppSheetView *tree_view)
1398 g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (tree_view)));
1400 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
1402 PsppSheetViewColumn *column;
1404 for (list = tree_view->priv->columns; list; list = list->next)
1406 column = list->data;
1407 if (column->button != NULL &&
1408 gtk_widget_get_visible (column->button) &&
1409 !gtk_widget_get_mapped (column->button))
1410 gtk_widget_map (column->button);
1412 for (list = tree_view->priv->columns; list; list = list->next)
1414 column = list->data;
1415 if (column->visible == FALSE || column->window == NULL)
1417 if (column->resizable)
1419 gdk_window_raise (column->window);
1420 gdk_window_show (column->window);
1423 gdk_window_hide (column->window);
1425 gdk_window_show (tree_view->priv->header_window);
1430 pspp_sheet_view_map (GtkWidget *widget)
1432 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1435 gtk_widget_set_mapped (widget, TRUE);
1437 tmp_list = tree_view->priv->children;
1440 PsppSheetViewChild *child = tmp_list->data;
1441 tmp_list = tmp_list->next;
1443 if (gtk_widget_get_visible (child->widget))
1445 if (!gtk_widget_get_mapped (child->widget))
1446 gtk_widget_map (child->widget);
1449 gdk_window_show (tree_view->priv->bin_window);
1451 pspp_sheet_view_map_buttons (tree_view);
1453 gdk_window_show (gtk_widget_get_window (widget));
1457 pspp_sheet_view_realize (GtkWidget *widget)
1459 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1461 GdkWindowAttr attributes;
1462 gint attributes_mask;
1463 GtkAllocation allocation;
1464 GtkAllocation old_allocation;
1466 gtk_widget_set_realized (widget, TRUE);
1468 gtk_widget_get_allocation (widget, &allocation);
1469 gtk_widget_get_allocation (widget, &old_allocation);
1471 /* Make the main, clipping window */
1472 attributes.window_type = GDK_WINDOW_CHILD;
1473 attributes.x = allocation.x;
1474 attributes.y = allocation.y;
1475 attributes.width = allocation.width;
1476 attributes.height = allocation.height;
1477 attributes.wclass = GDK_INPUT_OUTPUT;
1478 attributes.visual = gtk_widget_get_visual (widget);
1479 attributes.colormap = gtk_widget_get_colormap (widget);
1480 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1482 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1484 gtk_widget_set_window (widget,
1485 gdk_window_new (gtk_widget_get_parent_window (widget),
1486 &attributes, attributes_mask));
1487 gdk_window_set_user_data (gtk_widget_get_window (widget), widget);
1489 /* Make the window for the tree */
1491 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1492 attributes.width = MAX (tree_view->priv->width, old_allocation.width);
1493 attributes.height = old_allocation.height;
1494 attributes.event_mask = (GDK_EXPOSURE_MASK |
1496 GDK_POINTER_MOTION_MASK |
1497 GDK_ENTER_NOTIFY_MASK |
1498 GDK_LEAVE_NOTIFY_MASK |
1499 GDK_BUTTON_PRESS_MASK |
1500 GDK_BUTTON_RELEASE_MASK |
1501 gtk_widget_get_events (widget));
1503 tree_view->priv->bin_window = gdk_window_new (gtk_widget_get_window (widget),
1504 &attributes, attributes_mask);
1505 gdk_window_set_user_data (tree_view->priv->bin_window, widget);
1507 /* Make the column header window */
1510 attributes.width = MAX (tree_view->priv->width, old_allocation.width);
1511 attributes.height = tree_view->priv->header_height;
1512 attributes.event_mask = (GDK_EXPOSURE_MASK |
1514 GDK_BUTTON_PRESS_MASK |
1515 GDK_BUTTON_RELEASE_MASK |
1516 GDK_KEY_PRESS_MASK |
1517 GDK_KEY_RELEASE_MASK |
1518 gtk_widget_get_events (widget));
1520 tree_view->priv->header_window = gdk_window_new (gtk_widget_get_window (widget),
1521 &attributes, attributes_mask);
1522 gdk_window_set_user_data (tree_view->priv->header_window, widget);
1524 /* Add them all up. */
1525 gtk_widget_set_style (widget,
1526 gtk_style_attach (gtk_widget_get_style (widget), gtk_widget_get_window (widget)));
1527 gdk_window_set_back_pixmap (gtk_widget_get_window (widget), NULL, FALSE);
1528 gdk_window_set_background (tree_view->priv->bin_window, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1529 gtk_style_set_background (gtk_widget_get_style (widget), tree_view->priv->header_window, GTK_STATE_NORMAL);
1531 tmp_list = tree_view->priv->children;
1534 PsppSheetViewChild *child = tmp_list->data;
1535 tmp_list = tmp_list->next;
1537 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1540 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1541 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1543 /* Need to call those here, since they create GCs */
1544 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1546 install_presize_handler (tree_view);
1550 pspp_sheet_view_unrealize (GtkWidget *widget)
1552 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1553 PsppSheetViewPrivate *priv = tree_view->priv;
1556 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1558 if (priv->scroll_timeout != 0)
1560 g_source_remove (priv->scroll_timeout);
1561 priv->scroll_timeout = 0;
1564 if (priv->open_dest_timeout != 0)
1566 g_source_remove (priv->open_dest_timeout);
1567 priv->open_dest_timeout = 0;
1570 if (priv->presize_handler_timer != 0)
1572 g_source_remove (priv->presize_handler_timer);
1573 priv->presize_handler_timer = 0;
1576 if (priv->validate_rows_timer != 0)
1578 g_source_remove (priv->validate_rows_timer);
1579 priv->validate_rows_timer = 0;
1582 if (priv->scroll_sync_timer != 0)
1584 g_source_remove (priv->scroll_sync_timer);
1585 priv->scroll_sync_timer = 0;
1588 if (priv->typeselect_flush_timeout)
1590 g_source_remove (priv->typeselect_flush_timeout);
1591 priv->typeselect_flush_timeout = 0;
1594 for (list = priv->columns; list; list = list->next)
1595 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1597 gdk_window_set_user_data (priv->bin_window, NULL);
1598 gdk_window_destroy (priv->bin_window);
1599 priv->bin_window = NULL;
1601 gdk_window_set_user_data (priv->header_window, NULL);
1602 gdk_window_destroy (priv->header_window);
1603 priv->header_window = NULL;
1605 if (priv->drag_window)
1607 gdk_window_set_user_data (priv->drag_window, NULL);
1608 gdk_window_destroy (priv->drag_window);
1609 priv->drag_window = NULL;
1612 if (priv->drag_highlight_window)
1614 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1615 gdk_window_destroy (priv->drag_highlight_window);
1616 priv->drag_highlight_window = NULL;
1619 if (tree_view->priv->columns != NULL)
1621 list = tree_view->priv->columns;
1624 PsppSheetViewColumn *column;
1625 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1627 pspp_sheet_view_remove_column (tree_view, column);
1629 tree_view->priv->columns = NULL;
1633 /* GtkWidget::size_request helper */
1635 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1639 tree_view->priv->header_height = 0;
1641 if (tree_view->priv->model)
1643 for (list = tree_view->priv->columns; list; list = list->next)
1645 GtkRequisition requisition;
1646 PsppSheetViewColumn *column = list->data;
1648 pspp_sheet_view_column_size_request (column, &requisition);
1649 column->button_request = requisition.width;
1650 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1656 /* Called only by ::size_request */
1658 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1661 PsppSheetViewColumn *column;
1664 if (tree_view->priv->model == NULL)
1666 tree_view->priv->width = 0;
1667 tree_view->priv->prev_width = 0;
1668 tree_view->priv->height = 0;
1672 tree_view->priv->prev_width = tree_view->priv->width;
1673 tree_view->priv->width = 0;
1675 /* keep this in sync with size_allocate below */
1676 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1678 gint real_requested_width = 0;
1679 column = list->data;
1680 if (!column->visible)
1683 if (column->use_resized_width)
1685 real_requested_width = column->resized_width;
1689 real_requested_width = column->fixed_width;
1692 if (column->min_width != -1)
1693 real_requested_width = MAX (real_requested_width, column->min_width);
1694 if (column->max_width != -1)
1695 real_requested_width = MIN (real_requested_width, column->max_width);
1697 tree_view->priv->width += real_requested_width;
1700 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1704 pspp_sheet_view_size_request (GtkWidget *widget,
1705 GtkRequisition *requisition)
1707 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1710 /* we validate some rows initially just to make sure we have some size.
1711 * In practice, with a lot of static lists, this should get a good width.
1713 initialize_fixed_height_mode (tree_view);
1714 pspp_sheet_view_size_request_columns (tree_view);
1715 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1717 requisition->width = tree_view->priv->width;
1718 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1720 tmp_list = tree_view->priv->children;
1724 PsppSheetViewChild *child = tmp_list->data;
1725 GtkRequisition child_requisition;
1727 tmp_list = tmp_list->next;
1729 if (gtk_widget_get_visible (child->widget))
1730 gtk_widget_size_request (child->widget, &child_requisition);
1735 invalidate_column (PsppSheetView *tree_view,
1736 PsppSheetViewColumn *column)
1738 gint column_offset = 0;
1740 GtkWidget *widget = GTK_WIDGET (tree_view);
1743 if (!gtk_widget_get_realized (widget))
1746 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1747 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1749 list = (rtl ? list->prev : list->next))
1751 PsppSheetViewColumn *tmpcolumn = list->data;
1752 if (tmpcolumn == column)
1754 GdkRectangle invalid_rect;
1755 GtkAllocation allocation;
1757 gtk_widget_get_allocation (widget, &allocation);
1758 invalid_rect.x = column_offset;
1760 invalid_rect.width = column->width;
1761 invalid_rect.height = allocation.height;
1763 gdk_window_invalidate_rect (gtk_widget_get_window (widget), &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 col_allocation;
1832 GtkAllocation allocation;
1834 gint extra, extra_per_column;
1835 gint full_requested_width = 0;
1836 gint number_of_expand_columns = 0;
1837 gboolean column_changed = FALSE;
1840 tree_view = PSPP_SHEET_VIEW (widget);
1842 for (last_column = g_list_last (tree_view->priv->columns);
1843 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1844 last_column = last_column->prev)
1847 if (last_column == NULL)
1850 for (first_column = g_list_first (tree_view->priv->columns);
1851 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1852 first_column = first_column->next)
1855 col_allocation.y = 0;
1856 col_allocation.height = tree_view->priv->header_height;
1858 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1860 /* find out how many extra space and expandable columns we have */
1861 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1863 column = (PsppSheetViewColumn *)list->data;
1865 if (!column->visible)
1868 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1871 number_of_expand_columns++;
1874 gtk_widget_get_allocation (widget, &allocation);
1875 extra = MAX (allocation.width - full_requested_width, 0);
1876 if (number_of_expand_columns > 0)
1877 extra_per_column = extra/number_of_expand_columns;
1879 extra_per_column = 0;
1881 for (list = (rtl ? last_column : first_column);
1882 list != (rtl ? first_column->prev : last_column->next);
1883 list = (rtl ? list->prev : list->next))
1885 gint real_requested_width = 0;
1888 column = list->data;
1889 old_width = column->width;
1891 if (!column->visible)
1894 /* We need to handle the dragged button specially.
1896 if (column == tree_view->priv->drag_column)
1898 GtkAllocation drag_allocation;
1899 drag_allocation.width = gdk_window_get_width (tree_view->priv->drag_window);
1900 drag_allocation.height = gdk_window_get_height (tree_view->priv->drag_window);
1901 drag_allocation.x = 0;
1902 drag_allocation.y = 0;
1903 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1905 width += drag_allocation.width;
1909 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1911 col_allocation.x = width;
1912 column->width = real_requested_width;
1916 if (number_of_expand_columns == 1)
1918 /* We add the remander to the last column as
1920 column->width += extra;
1924 column->width += extra_per_column;
1925 extra -= extra_per_column;
1926 number_of_expand_columns --;
1930 if (column->width != old_width)
1931 g_object_notify (G_OBJECT (column), "width");
1933 col_allocation.width = column->width;
1934 width += column->width;
1936 if (column->width > old_width)
1937 column_changed = TRUE;
1939 pspp_sheet_view_column_size_allocate (column, &col_allocation);
1941 if (span_intersects (col_allocation.x, col_allocation.width,
1942 gtk_adjustment_get_value (tree_view->priv->hadjustment),
1944 && gtk_widget_get_realized (widget))
1945 pspp_sheet_view_column_set_need_button (column, TRUE);
1948 gdk_window_move_resize (column->window,
1949 col_allocation.x + (rtl ? 0 : col_allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1951 TREE_VIEW_DRAG_WIDTH, col_allocation.height);
1954 /* We change the width here. The user might have been resizing columns,
1955 * so the total width of the tree view changes.
1957 tree_view->priv->width = width;
1959 *width_changed = TRUE;
1962 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
1966 pspp_sheet_view_size_allocate (GtkWidget *widget,
1967 GtkAllocation *allocation)
1969 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1971 gboolean width_changed = FALSE;
1972 GtkAllocation old_allocation;
1973 gtk_widget_get_allocation (widget, &old_allocation);
1975 if (allocation->width != old_allocation.width)
1976 width_changed = TRUE;
1979 gtk_widget_set_allocation (widget, allocation);
1981 tmp_list = tree_view->priv->children;
1985 GtkAllocation allocation;
1987 PsppSheetViewChild *child = tmp_list->data;
1988 tmp_list = tmp_list->next;
1990 /* totally ignore our child's requisition */
1991 allocation.x = child->x;
1992 allocation.y = child->y;
1993 allocation.width = child->width;
1994 allocation.height = child->height;
1995 gtk_widget_size_allocate (child->widget, &allocation);
1998 /* We size-allocate the columns first because the width of the
1999 * tree view (used in updating the adjustments below) might change.
2001 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
2003 gtk_adjustment_set_page_size (tree_view->priv->hadjustment, allocation->width);
2004 gtk_adjustment_set_page_increment (tree_view->priv->hadjustment, allocation->width * 0.9);
2005 gtk_adjustment_set_step_increment (tree_view->priv->hadjustment, allocation->width * 0.1);
2006 gtk_adjustment_set_lower (tree_view->priv->hadjustment, 0);
2007 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_page_size (tree_view->priv->hadjustment), tree_view->priv->width));
2009 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
2011 if (allocation->width < tree_view->priv->width)
2013 if (tree_view->priv->init_hadjust_value)
2015 gtk_adjustment_set_value (tree_view->priv->hadjustment, MAX (tree_view->priv->width - allocation->width, 0));
2016 tree_view->priv->init_hadjust_value = FALSE;
2018 else if (allocation->width != old_allocation.width)
2020 gtk_adjustment_set_value (tree_view->priv->hadjustment, CLAMP (gtk_adjustment_get_value (tree_view->priv->hadjustment) - allocation->width + old_allocation.width, 0, tree_view->priv->width - allocation->width));
2023 gtk_adjustment_set_value (tree_view->priv->hadjustment, CLAMP (tree_view->priv->width - (tree_view->priv->prev_width - gtk_adjustment_get_value (tree_view->priv->hadjustment)), 0, tree_view->priv->width - allocation->width));
2027 gtk_adjustment_set_value (tree_view->priv->hadjustment, 0);
2028 tree_view->priv->init_hadjust_value = TRUE;
2032 if (gtk_adjustment_get_value (tree_view->priv->hadjustment) + allocation->width > tree_view->priv->width)
2033 gtk_adjustment_set_value (tree_view->priv->hadjustment, MAX (tree_view->priv->width - allocation->width, 0));
2035 gtk_adjustment_changed (tree_view->priv->hadjustment);
2037 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2038 gtk_adjustment_set_step_increment (tree_view->priv->vadjustment, gtk_adjustment_get_page_size (tree_view->priv->vadjustment) * 0.1);
2039 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, gtk_adjustment_get_page_size (tree_view->priv->vadjustment) * 0.9);
2040 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
2041 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_page_size (tree_view->priv->vadjustment), tree_view->priv->height));
2043 gtk_adjustment_changed (tree_view->priv->vadjustment);
2045 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
2046 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
2047 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
2048 else if (gtk_adjustment_get_value (tree_view->priv->vadjustment) + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
2049 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
2050 tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
2051 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
2052 pspp_sheet_view_top_row_to_dy (tree_view);
2054 pspp_sheet_view_dy_to_top_row (tree_view);
2056 if (gtk_widget_get_realized (widget))
2058 gdk_window_move_resize (gtk_widget_get_window (widget),
2059 allocation->x, allocation->y,
2060 allocation->width, allocation->height);
2061 gdk_window_move_resize (tree_view->priv->header_window,
2062 - (gint) gtk_adjustment_get_value (tree_view->priv->hadjustment),
2064 MAX (tree_view->priv->width, allocation->width),
2065 tree_view->priv->header_height);
2066 gdk_window_move_resize (tree_view->priv->bin_window,
2067 - (gint) gtk_adjustment_get_value (tree_view->priv->hadjustment),
2068 TREE_VIEW_HEADER_HEIGHT (tree_view),
2069 MAX (tree_view->priv->width, allocation->width),
2070 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2073 if (tree_view->priv->row_count == 0)
2074 invalidate_empty_focus (tree_view);
2076 if (gtk_widget_get_realized (widget))
2078 gboolean has_expand_column = FALSE;
2079 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2081 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2083 has_expand_column = TRUE;
2088 /* This little hack only works if we have an LTR locale, and no column has the */
2091 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2092 ! has_expand_column)
2093 invalidate_last_column (tree_view);
2095 gtk_widget_queue_draw (widget);
2100 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2102 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2104 GtkWidget *widget = GTK_WIDGET (tree_view);
2106 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2107 gtk_widget_grab_focus (widget);
2108 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2112 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2115 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2119 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2122 range_tower_set1 (tree_view->priv->selected, node, 1);
2126 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2129 range_tower_set0 (tree_view->priv->selected, node, 1);
2133 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2136 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2140 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2143 return node > 0 ? node - 1 : -1;
2147 all_columns_selected (PsppSheetView *tree_view)
2151 for (list = tree_view->priv->columns; list; list = list->next)
2153 PsppSheetViewColumn *column = list->data;
2154 if (column->selectable && !column->selected)
2162 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2164 PsppSheetViewColumn *column,
2165 GdkEventButton *event)
2167 PsppSheetSelection *selection;
2168 PsppSheetSelectionMode mode;
2170 gboolean update_anchor;
2174 g_return_val_if_fail (tree_view != NULL, FALSE);
2175 g_return_val_if_fail (column != NULL, FALSE);
2177 selection = tree_view->priv->selection;
2178 mode = pspp_sheet_selection_get_mode (selection);
2179 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2182 if (!column->row_head)
2187 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2188 if (event->type != GDK_BUTTON_PRESS
2189 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2195 path = gtk_tree_path_new_from_indices (node, -1);
2198 pspp_sheet_selection_unselect_all (selection);
2199 pspp_sheet_selection_select_path (selection, path);
2200 pspp_sheet_selection_select_all_columns (selection);
2201 update_anchor = TRUE;
2204 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2206 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2207 || !all_columns_selected (tree_view))
2209 pspp_sheet_selection_unselect_all (selection);
2210 pspp_sheet_selection_select_path (selection, path);
2211 pspp_sheet_selection_select_all_columns (selection);
2212 update_anchor = TRUE;
2216 update_anchor = handled = FALSE;
2218 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2219 && modifiers == GDK_CONTROL_MASK)
2221 if (!all_columns_selected (tree_view))
2223 pspp_sheet_selection_unselect_all (selection);
2224 pspp_sheet_selection_select_all_columns (selection);
2227 if (pspp_sheet_selection_path_is_selected (selection, path))
2228 pspp_sheet_selection_unselect_path (selection, path);
2230 pspp_sheet_selection_select_path (selection, path);
2231 update_anchor = TRUE;
2234 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2235 && modifiers == GDK_SHIFT_MASK)
2237 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2238 GtkTreePath *anchor_path;
2240 if (all_columns_selected (tree_view)
2241 && gtk_tree_row_reference_valid (anchor))
2243 update_anchor = FALSE;
2244 anchor_path = gtk_tree_row_reference_get_path (anchor);
2248 update_anchor = TRUE;
2249 anchor_path = gtk_tree_path_copy (path);
2252 pspp_sheet_selection_unselect_all (selection);
2253 pspp_sheet_selection_select_range (selection, anchor_path, path);
2254 pspp_sheet_selection_select_all_columns (selection);
2256 gtk_tree_path_free (anchor_path);
2261 update_anchor = handled = FALSE;
2265 if (tree_view->priv->anchor)
2266 gtk_tree_row_reference_free (tree_view->priv->anchor);
2267 tree_view->priv->anchor =
2268 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2269 tree_view->priv->model,
2273 gtk_tree_path_free (path);
2278 find_click (PsppSheetView *tree_view,
2281 PsppSheetViewColumn **column,
2282 GdkRectangle *background_area,
2283 GdkRectangle *cell_area)
2290 /* find the node that was clicked */
2291 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2294 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2299 background_area->y = y_offset + y;
2300 background_area->height = ROW_HEIGHT (tree_view);
2301 background_area->x = 0;
2303 /* Let the column have a chance at selecting it. */
2304 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2305 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2306 list; list = (rtl ? list->prev : list->next))
2308 PsppSheetViewColumn *candidate = list->data;
2310 if (!candidate->visible)
2313 background_area->width = candidate->width;
2314 if ((background_area->x > x) ||
2315 (background_area->x + background_area->width <= x))
2317 background_area->x += background_area->width;
2321 /* we found the focus column */
2323 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2325 *column = candidate;
2333 pspp_sheet_view_button_press (GtkWidget *widget,
2334 GdkEventButton *event)
2336 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2338 PsppSheetViewColumn *column = NULL;
2340 GdkRectangle background_area;
2341 GdkRectangle cell_area;
2344 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2345 pspp_sheet_view_stop_editing (tree_view, FALSE);
2348 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2349 * we're done handling the button press.
2352 if (event->window == tree_view->priv->bin_window)
2357 gint pre_val, aft_val;
2358 PsppSheetViewColumn *column = NULL;
2359 GtkCellRenderer *focus_cell = NULL;
2360 gboolean row_double_click = FALSE;
2363 if (tree_view->priv->row_count == 0)
2365 grab_focus_and_unset_draw_keyfocus (tree_view);
2369 if (!find_click (tree_view, event->x, event->y, &node, &column,
2370 &background_area, &cell_area))
2372 grab_focus_and_unset_draw_keyfocus (tree_view);
2376 tree_view->priv->focus_column = column;
2378 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2382 pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
2384 path = _pspp_sheet_view_find_path (tree_view, node);
2386 /* we only handle selection modifications on the first button press
2388 if (event->type == GDK_BUTTON_PRESS)
2390 PsppSheetSelectionMode mode = 0;
2392 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2393 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
2394 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2395 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
2397 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2399 pspp_sheet_view_column_focus_cell (column, focus_cell);
2401 if (event->state & GDK_CONTROL_MASK)
2403 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, mode);
2404 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2406 else if (event->state & GDK_SHIFT_MASK)
2408 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
2409 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE, mode);
2413 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
2416 if (tree_view->priv->anchor_column == NULL ||
2417 !(event->state & GDK_SHIFT_MASK))
2418 tree_view->priv->anchor_column = column;
2419 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2420 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2421 tree_view->priv->anchor_column,
2425 /* the treeview may have been scrolled because of _set_cursor,
2429 aft_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
2430 dval = pre_val - aft_val;
2432 cell_area.y += dval;
2433 background_area.y += dval;
2435 /* Save press to possibly begin a drag
2437 if (!tree_view->priv->in_grab &&
2438 tree_view->priv->pressed_button < 0)
2440 tree_view->priv->pressed_button = event->button;
2441 tree_view->priv->press_start_x = event->x;
2442 tree_view->priv->press_start_y = event->y;
2443 tree_view->priv->press_start_node = node;
2445 if (tree_view->priv->rubber_banding_enable
2446 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2447 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2449 tree_view->priv->press_start_y += tree_view->priv->dy;
2450 tree_view->priv->rubber_band_x = event->x;
2451 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2452 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2454 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2455 tree_view->priv->rubber_band_ctrl = TRUE;
2456 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2457 tree_view->priv->rubber_band_shift = TRUE;
2462 /* Test if a double click happened on the same row. */
2463 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2465 int double_click_time, double_click_distance;
2467 g_object_get (gtk_settings_get_for_screen (
2468 gtk_widget_get_screen (widget)),
2469 "gtk-double-click-time", &double_click_time,
2470 "gtk-double-click-distance", &double_click_distance,
2473 /* Same conditions as _gdk_event_button_generate */
2474 if (tree_view->priv->last_button_x != -1 &&
2475 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2476 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2477 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2479 /* We do no longer compare paths of this row and the
2480 * row clicked previously. We use the double click
2481 * distance to decide whether this is a valid click,
2482 * allowing the mouse to slightly move over another row.
2484 row_double_click = TRUE;
2486 tree_view->priv->last_button_time = 0;
2487 tree_view->priv->last_button_x = -1;
2488 tree_view->priv->last_button_y = -1;
2492 tree_view->priv->last_button_time = event->time;
2493 tree_view->priv->last_button_x = event->x;
2494 tree_view->priv->last_button_y = event->y;
2498 if (row_double_click)
2500 gtk_grab_remove (widget);
2501 pspp_sheet_view_row_activated (tree_view, path, column);
2503 if (tree_view->priv->pressed_button == event->button)
2504 tree_view->priv->pressed_button = -1;
2507 gtk_tree_path_free (path);
2509 /* If we activated the row through a double click we don't want to grab
2510 * focus back, as moving focus to another widget is pretty common.
2512 if (!row_double_click)
2513 grab_focus_and_unset_draw_keyfocus (tree_view);
2518 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2520 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2522 column = list->data;
2523 if (event->window == column->window &&
2524 column->resizable &&
2529 if (gdk_pointer_grab (column->window, FALSE,
2530 GDK_POINTER_MOTION_HINT_MASK |
2531 GDK_BUTTON1_MOTION_MASK |
2532 GDK_BUTTON_RELEASE_MASK,
2533 NULL, NULL, event->time))
2536 gtk_grab_add (widget);
2537 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2538 column->resized_width = column->width;
2540 /* block attached dnd signal handler */
2541 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2543 g_signal_handlers_block_matched (widget,
2544 G_SIGNAL_MATCH_DATA,
2548 tree_view->priv->drag_pos = i;
2549 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2551 if (!gtk_widget_has_focus (widget))
2552 gtk_widget_grab_focus (widget);
2560 /* GtkWidget::button_release_event helper */
2562 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2563 GdkEventButton *event)
2565 PsppSheetView *tree_view;
2569 tree_view = PSPP_SHEET_VIEW (widget);
2571 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2572 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2573 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2575 /* Move the button back */
2576 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2578 g_object_ref (tree_view->priv->drag_column->button);
2579 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2580 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2581 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2582 g_object_unref (tree_view->priv->drag_column->button);
2583 gtk_widget_queue_resize (widget);
2584 if (tree_view->priv->drag_column->resizable)
2586 gdk_window_raise (tree_view->priv->drag_column->window);
2587 gdk_window_show (tree_view->priv->drag_column->window);
2590 gdk_window_hide (tree_view->priv->drag_column->window);
2592 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2596 if (tree_view->priv->cur_reorder &&
2597 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2598 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2599 tree_view->priv->cur_reorder->right_column);
2603 if (tree_view->priv->cur_reorder &&
2604 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2605 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2606 tree_view->priv->cur_reorder->left_column);
2608 tree_view->priv->drag_column = NULL;
2609 gdk_window_hide (tree_view->priv->drag_window);
2611 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2612 g_slice_free (PsppSheetViewColumnReorder, l->data);
2613 g_list_free (tree_view->priv->column_drag_info);
2614 tree_view->priv->column_drag_info = NULL;
2615 tree_view->priv->cur_reorder = NULL;
2617 if (tree_view->priv->drag_highlight_window)
2618 gdk_window_hide (tree_view->priv->drag_highlight_window);
2620 /* Reset our flags */
2621 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2622 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2627 /* GtkWidget::button_release_event helper */
2629 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2630 GdkEventButton *event)
2632 PsppSheetView *tree_view;
2635 tree_view = PSPP_SHEET_VIEW (widget);
2637 tree_view->priv->drag_pos = -1;
2639 /* unblock attached dnd signal handler */
2640 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2642 g_signal_handlers_unblock_matched (widget,
2643 G_SIGNAL_MATCH_DATA,
2647 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2648 gtk_grab_remove (widget);
2649 gdk_display_pointer_ungrab (gdk_window_get_display (event->window),
2655 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2656 GdkEventButton *event)
2658 GtkCellEditable *cell_editable;
2663 PsppSheetViewColumn *column;
2664 GdkRectangle background_area;
2665 GdkRectangle cell_area;
2671 if (event->window != tree_view->priv->bin_window)
2674 /* Ignore a released button, if that button wasn't depressed */
2675 if (tree_view->priv->pressed_button != event->button)
2678 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2682 /* decide if we edit */
2683 path = _pspp_sheet_view_find_path (tree_view, node);
2684 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2685 if (event->button != 1 || modifiers)
2688 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2689 pspp_sheet_view_column_cell_set_cell_data (column,
2690 tree_view->priv->model,
2693 if (!pspp_sheet_view_column_get_quick_edit (column)
2694 && _pspp_sheet_view_column_has_editable_cell (column))
2697 flags = 0; /* FIXME: get the right flags */
2698 path_string = gtk_tree_path_to_string (path);
2700 if (!_pspp_sheet_view_column_cell_event (column,
2708 if (cell_editable == NULL)
2711 pspp_sheet_view_real_set_cursor (tree_view, path,
2712 TRUE, TRUE, 0); /* XXX mode? */
2713 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2716 _pspp_sheet_view_column_get_neighbor_sizes (
2717 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2720 area.width -= right + left;
2722 pspp_sheet_view_real_start_editing (tree_view,
2729 g_free (path_string);
2730 gtk_tree_path_free (path);
2735 pspp_sheet_view_button_release (GtkWidget *widget,
2736 GdkEventButton *event)
2738 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2740 pspp_sheet_view_stop_editing (tree_view, FALSE);
2741 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2742 && pspp_sheet_view_button_release_edit (tree_view, event))
2744 if (tree_view->priv->pressed_button == event->button)
2745 tree_view->priv->pressed_button = -1;
2747 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2751 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2752 return pspp_sheet_view_button_release_drag_column (widget, event);
2754 if (tree_view->priv->rubber_band_status)
2755 pspp_sheet_view_stop_rubber_band (tree_view);
2757 if (tree_view->priv->pressed_button == event->button)
2758 tree_view->priv->pressed_button = -1;
2760 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2761 return pspp_sheet_view_button_release_column_resize (widget, event);
2767 pspp_sheet_view_grab_broken (GtkWidget *widget,
2768 GdkEventGrabBroken *event)
2770 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2772 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2773 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2775 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2776 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2781 /* GtkWidget::motion_event function set.
2785 do_prelight (PsppSheetView *tree_view,
2787 /* these are in bin_window coords */
2791 int prev_node = tree_view->priv->prelight_node;
2793 if (prev_node != node)
2795 tree_view->priv->prelight_node = node;
2798 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2801 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2807 prelight_or_select (PsppSheetView *tree_view,
2809 /* these are in bin_window coords */
2813 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2815 if (tree_view->priv->hover_selection &&
2816 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2817 !(tree_view->priv->edited_column &&
2818 tree_view->priv->edited_column->editable_widget))
2822 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2826 path = _pspp_sheet_view_find_path (tree_view, node);
2827 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2828 if (pspp_sheet_view_node_is_selected (tree_view, node))
2830 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2831 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE, 0); /* XXX mode? */
2833 gtk_tree_path_free (path);
2837 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2838 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2841 do_prelight (tree_view, node, x, y);
2845 ensure_unprelighted (PsppSheetView *tree_view)
2847 do_prelight (tree_view,
2849 -1000, -1000); /* coords not possibly over an arrow */
2851 g_assert (tree_view->priv->prelight_node < 0);
2855 update_prelight (PsppSheetView *tree_view,
2862 if (tree_view->priv->row_count == 0)
2867 ensure_unprelighted (tree_view);
2871 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2875 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2878 prelight_or_select (tree_view, node, x, y);
2884 /* Our motion arrow is either a box (in the case of the original spot)
2885 * or an arrow. It is expander_size wide.
2908 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2911 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2912 GtkWidget *widget = GTK_WIDGET (tree_view);
2913 GdkBitmap *mask = NULL;
2918 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2919 GdkWindowAttr attributes;
2920 guint attributes_mask;
2923 reorder->left_column == tree_view->priv->drag_column ||
2924 reorder->right_column == tree_view->priv->drag_column)
2925 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2926 else if (reorder->left_column || reorder->right_column)
2928 GdkRectangle visible_rect;
2929 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2930 if (reorder->left_column)
2931 x = reorder->left_column->allocation.x + reorder->left_column->allocation.width;
2933 x = reorder->right_column->allocation.x;
2935 if (x < visible_rect.x)
2936 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2937 else if (x > visible_rect.x + visible_rect.width)
2938 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2940 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2943 /* We want to draw the rectangle over the initial location. */
2944 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2949 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2951 if (tree_view->priv->drag_highlight_window)
2953 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2955 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2958 attributes.window_type = GDK_WINDOW_CHILD;
2959 attributes.wclass = GDK_INPUT_OUTPUT;
2960 attributes.x = tree_view->priv->drag_column_x;
2962 width = attributes.width = tree_view->priv->drag_column->allocation.width;
2963 height = attributes.height = tree_view->priv->drag_column->allocation.height;
2964 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2965 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2966 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2967 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2968 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
2969 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2971 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2972 gc = gdk_gc_new (mask);
2974 gdk_gc_set_foreground (gc, &col);
2975 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2977 gdk_gc_set_foreground(gc, &col);
2978 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
2979 g_object_unref (gc);
2981 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
2983 if (mask) g_object_unref (mask);
2984 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2987 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
2993 width = tree_view->priv->expander_size;
2995 /* Get x, y, width, height of arrow */
2996 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
2997 if (reorder->left_column)
2999 x += reorder->left_column->allocation.x + reorder->left_column->allocation.width - width/2;
3000 height = reorder->left_column->allocation.height;
3004 x += reorder->right_column->allocation.x - width/2;
3005 height = reorder->right_column->allocation.height;
3007 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
3008 height += tree_view->priv->expander_size;
3010 /* Create the new window */
3011 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
3013 if (tree_view->priv->drag_highlight_window)
3015 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3017 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3020 attributes.window_type = GDK_WINDOW_TEMP;
3021 attributes.wclass = GDK_INPUT_OUTPUT;
3022 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3023 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3024 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3025 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3028 attributes.width = width;
3029 attributes.height = height;
3030 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
3031 &attributes, attributes_mask);
3032 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3034 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3035 gc = gdk_gc_new (mask);
3037 gdk_gc_set_foreground (gc, &col);
3038 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3040 /* Draw the 2 arrows as per above */
3042 gdk_gc_set_foreground (gc, &col);
3043 for (i = 0; i < width; i ++)
3045 if (i == (width/2 - 1))
3047 gdk_draw_line (mask, gc, i, j, i, height - j);
3048 if (i < (width/2 - 1))
3053 g_object_unref (gc);
3054 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3056 if (mask) g_object_unref (mask);
3059 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
3060 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3062 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
3063 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3069 width = tree_view->priv->expander_size;
3071 /* Get x, y, width, height of arrow */
3072 width = width/2; /* remember, the arrow only takes half the available width */
3073 gdk_window_get_origin (gtk_widget_get_window (widget), &x, &y);
3074 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3075 x += widget->allocation.width - width;
3077 if (reorder->left_column)
3078 height = reorder->left_column->allocation.height;
3080 height = reorder->right_column->allocation.height;
3082 y -= tree_view->priv->expander_size;
3083 height += 2*tree_view->priv->expander_size;
3085 /* Create the new window */
3086 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
3087 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3089 if (tree_view->priv->drag_highlight_window)
3091 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3093 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3096 attributes.window_type = GDK_WINDOW_TEMP;
3097 attributes.wclass = GDK_INPUT_OUTPUT;
3098 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3099 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3100 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3101 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3104 attributes.width = width;
3105 attributes.height = height;
3106 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3107 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3109 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3110 gc = gdk_gc_new (mask);
3112 gdk_gc_set_foreground (gc, &col);
3113 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3115 /* Draw the 2 arrows as per above */
3117 gdk_gc_set_foreground (gc, &col);
3118 j = tree_view->priv->expander_size;
3119 for (i = 0; i < width; i ++)
3122 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3126 gdk_draw_line (mask, gc, k, j, k, height - j);
3127 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3128 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3131 g_object_unref (gc);
3132 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3134 if (mask) g_object_unref (mask);
3137 tree_view->priv->drag_column_window_state = arrow_type;
3138 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3142 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3143 gdk_window_hide (tree_view->priv->drag_highlight_window);
3147 gdk_window_show (tree_view->priv->drag_highlight_window);
3148 gdk_window_raise (tree_view->priv->drag_highlight_window);
3153 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3154 GdkEventMotion *event)
3158 PsppSheetViewColumn *column;
3159 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3161 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3163 if (event->is_hint || event->window != gtk_widget_get_window (widget))
3164 gtk_widget_get_pointer (widget, &x, NULL);
3168 if (tree_view->priv->hadjustment)
3169 x += gtk_adjustment_get_value (tree_view->priv->hadjustment);
3171 new_width = pspp_sheet_view_new_column_width (tree_view,
3172 tree_view->priv->drag_pos, &x);
3173 if (x != tree_view->priv->x_drag &&
3174 (new_width != column->fixed_width))
3176 column->use_resized_width = TRUE;
3177 column->resized_width = new_width;
3180 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3182 gtk_widget_queue_resize (widget);
3190 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3192 PsppSheetViewColumnReorder *reorder = NULL;
3196 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3197 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3199 reorder = (PsppSheetViewColumnReorder *) list->data;
3200 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3205 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3208 tree_view->priv->cur_reorder = reorder;
3209 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3213 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3215 GdkRectangle visible_rect;
3220 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3221 y += tree_view->priv->dy;
3223 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3225 /* see if we are near the edge. */
3226 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3229 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3234 value = CLAMP (gtk_adjustment_get_value (tree_view->priv->vadjustment) + offset, 0.0,
3235 gtk_adjustment_get_upper (tree_view->priv->vadjustment) - gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
3236 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3240 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3242 GdkRectangle visible_rect;
3247 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3249 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3251 /* See if we are near the edge. */
3252 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3255 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3261 value = CLAMP (gtk_adjustment_get_value (tree_view->priv->hadjustment) + offset,
3262 0.0, gtk_adjustment_get_upper (tree_view->priv->hadjustment) - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
3263 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3270 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3271 GdkEventMotion *event)
3273 PsppSheetView *tree_view = (PsppSheetView *) widget;
3274 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3276 GtkAllocation allocation;
3279 if ((column == NULL) ||
3280 (event->window != tree_view->priv->drag_window))
3283 /* Handle moving the header */
3284 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3285 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
3286 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3287 MAX (tree_view->priv->width, allocation.width) - column->allocation.width);
3288 gdk_window_move (tree_view->priv->drag_window, x, y);
3290 /* autoscroll, if needed */
3291 pspp_sheet_view_horizontal_autoscroll (tree_view);
3292 /* Update the current reorder position and arrow; */
3293 pspp_sheet_view_update_current_reorder (tree_view);
3299 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3301 remove_scroll_timeout (tree_view);
3302 gtk_grab_remove (GTK_WIDGET (tree_view));
3304 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3306 GtkTreePath *tmp_path;
3308 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3310 /* The anchor path should be set to the start path */
3311 tmp_path = _pspp_sheet_view_find_path (tree_view,
3312 tree_view->priv->rubber_band_start_node);
3314 if (tree_view->priv->anchor)
3315 gtk_tree_row_reference_free (tree_view->priv->anchor);
3317 tree_view->priv->anchor =
3318 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3319 tree_view->priv->model,
3322 gtk_tree_path_free (tmp_path);
3324 /* ... and the cursor to the end path */
3325 tmp_path = _pspp_sheet_view_find_path (tree_view,
3326 tree_view->priv->rubber_band_end_node);
3327 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE, 0); /* XXX mode? */
3328 gtk_tree_path_free (tmp_path);
3330 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3333 /* Clear status variables */
3334 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3335 tree_view->priv->rubber_band_shift = 0;
3336 tree_view->priv->rubber_band_ctrl = 0;
3338 tree_view->priv->rubber_band_start_node = -1;
3339 tree_view->priv->rubber_band_end_node = -1;
3343 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3347 gboolean skip_start,
3350 if (start_node == end_node)
3353 /* We skip the first node and jump inside the loop */
3359 /* Small optimization by assuming insensitive nodes are never
3364 if (tree_view->priv->rubber_band_shift)
3365 pspp_sheet_view_node_select (tree_view, start_node);
3366 else if (tree_view->priv->rubber_band_ctrl)
3368 /* Toggle the selection state */
3369 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3370 pspp_sheet_view_node_unselect (tree_view, start_node);
3372 pspp_sheet_view_node_select (tree_view, start_node);
3375 pspp_sheet_view_node_select (tree_view, start_node);
3379 /* Mirror the above */
3380 if (tree_view->priv->rubber_band_shift)
3381 pspp_sheet_view_node_unselect (tree_view, start_node);
3382 else if (tree_view->priv->rubber_band_ctrl)
3384 /* Toggle the selection state */
3385 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3386 pspp_sheet_view_node_unselect (tree_view, start_node);
3388 pspp_sheet_view_node_select (tree_view, start_node);
3391 pspp_sheet_view_node_unselect (tree_view, start_node);
3394 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3396 if (start_node == end_node)
3401 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3404 /* Ran out of tree */
3407 if (skip_end && start_node == end_node)
3414 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3417 return node * tree_view->priv->fixed_height;
3421 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3425 int fixed_height = tree_view->priv->fixed_height;
3426 if (fixed_height <= 0
3428 || height >= tree_view->priv->row_count * fixed_height)
3435 *new_node = height / fixed_height;
3436 return height % fixed_height;
3441 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3446 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3447 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3449 /* Handle the start area first */
3450 if (tree_view->priv->rubber_band_start_node < 0)
3452 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3459 else if (start_node < tree_view->priv->rubber_band_start_node)
3461 /* New node is above the old one; selection became bigger */
3462 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3464 tree_view->priv->rubber_band_start_node,
3469 else if (start_node > tree_view->priv->rubber_band_start_node)
3471 /* New node is below the old one; selection became smaller */
3472 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3473 tree_view->priv->rubber_band_start_node,
3480 tree_view->priv->rubber_band_start_node = start_node;
3482 /* Next, handle the end area */
3483 if (tree_view->priv->rubber_band_end_node < 0)
3485 /* In the event this happens, start_node was also -1; this case is
3489 else if (end_node < 0)
3491 /* Find the last node in the tree */
3492 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3495 /* Selection reached end of the tree */
3496 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3497 tree_view->priv->rubber_band_end_node,
3503 else if (end_node > tree_view->priv->rubber_band_end_node)
3505 /* New node is below the old one; selection became bigger */
3506 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3507 tree_view->priv->rubber_band_end_node,
3513 else if (end_node < tree_view->priv->rubber_band_end_node)
3515 /* New node is above the old one; selection became smaller */
3516 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3518 tree_view->priv->rubber_band_end_node,
3524 tree_view->priv->rubber_band_end_node = end_node;
3528 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3531 GdkRectangle old_area;
3532 GdkRectangle new_area;
3533 GdkRectangle common;
3534 GdkRegion *invalid_region;
3535 PsppSheetViewColumn *column;
3537 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3538 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3539 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3540 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3542 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3545 y = MAX (y, 0) + tree_view->priv->dy;
3547 new_area.x = MIN (tree_view->priv->press_start_x, x);
3548 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3549 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3550 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3552 invalid_region = gdk_region_rectangle (&old_area);
3553 gdk_region_union_with_rect (invalid_region, &new_area);
3555 gdk_rectangle_intersect (&old_area, &new_area, &common);
3556 if (common.width > 2 && common.height > 2)
3558 GdkRegion *common_region;
3560 /* make sure the border is invalidated */
3566 common_region = gdk_region_rectangle (&common);
3568 gdk_region_subtract (invalid_region, common_region);
3569 gdk_region_destroy (common_region);
3572 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3574 gdk_region_destroy (invalid_region);
3576 tree_view->priv->rubber_band_x = x;
3577 tree_view->priv->rubber_band_y = y;
3578 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3580 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3581 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3582 tree_view->priv->anchor_column,
3585 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3587 pspp_sheet_view_update_rubber_band_selection (tree_view);
3591 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3596 GdkRectangle rubber_rect;
3600 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3601 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3602 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3603 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3605 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3608 cr = gdk_cairo_create (tree_view->priv->bin_window);
3609 cairo_set_line_width (cr, 1.0);
3611 style = gtk_widget_get_style (GTK_WIDGET (tree_view));
3612 cairo_set_source_rgba (cr,
3613 style->fg[GTK_STATE_NORMAL].red / 65535.,
3614 style->fg[GTK_STATE_NORMAL].green / 65535.,
3615 style->fg[GTK_STATE_NORMAL].blue / 65535.,
3618 gdk_cairo_rectangle (cr, &rect);
3622 cairo_set_source_rgb (cr,
3623 style->fg[GTK_STATE_NORMAL].red / 65535.,
3624 style->fg[GTK_STATE_NORMAL].green / 65535.,
3625 style->fg[GTK_STATE_NORMAL].blue / 65535.);
3627 cairo_rectangle (cr,
3628 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3629 rubber_rect.width - 1, rubber_rect.height - 1);
3636 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3637 GdkEventMotion *event)
3639 PsppSheetView *tree_view;
3643 tree_view = (PsppSheetView *) widget;
3645 if (tree_view->priv->row_count == 0)
3648 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3650 GdkRectangle background_area, cell_area;
3651 PsppSheetViewColumn *column;
3653 if (find_click (tree_view, event->x, event->y, &node, &column,
3654 &background_area, &cell_area)
3655 && tree_view->priv->focus_column == column
3656 && tree_view->priv->press_start_node == node)
3659 gtk_grab_add (GTK_WIDGET (tree_view));
3660 pspp_sheet_view_update_rubber_band (tree_view);
3662 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3664 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3666 pspp_sheet_view_update_rubber_band (tree_view);
3668 add_scroll_timeout (tree_view);
3671 /* only check for an initiated drag when a button is pressed */
3672 if (tree_view->priv->pressed_button >= 0
3673 && !tree_view->priv->rubber_band_status)
3674 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3676 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3680 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3682 tree_view->priv->event_last_x = event->x;
3683 tree_view->priv->event_last_y = event->y;
3685 prelight_or_select (tree_view, node, event->x, event->y);
3691 pspp_sheet_view_motion (GtkWidget *widget,
3692 GdkEventMotion *event)
3694 PsppSheetView *tree_view;
3696 tree_view = (PsppSheetView *) widget;
3698 /* Resizing a column */
3699 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3700 return pspp_sheet_view_motion_resize_column (widget, event);
3703 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3704 return pspp_sheet_view_motion_drag_column (widget, event);
3706 /* Sanity check it */
3707 if (event->window == tree_view->priv->bin_window)
3708 return pspp_sheet_view_motion_bin_window (widget, event);
3713 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3714 * the tree is empty.
3717 invalidate_empty_focus (PsppSheetView *tree_view)
3721 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3726 area.width = gdk_window_get_width (tree_view->priv->bin_window);
3727 area.height = gdk_window_get_height (tree_view->priv->bin_window);
3728 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3731 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3735 draw_empty_focus (PsppSheetView *tree_view, GdkRectangle *clip_area)
3737 GtkWidget *widget = GTK_WIDGET (tree_view);
3740 if (!gtk_widget_has_focus (widget))
3743 w = gdk_window_get_width (tree_view->priv->bin_window);
3744 h = gdk_window_get_height (tree_view->priv->bin_window);
3750 gtk_paint_focus (gtk_widget_get_style (widget),
3751 tree_view->priv->bin_window,
3752 gtk_widget_get_state (widget),
3760 pspp_sheet_view_draw_vertical_grid_lines (PsppSheetView *tree_view,
3761 GdkEventExpose *event,
3762 gint n_visible_columns,
3766 GList *list = tree_view->priv->columns;
3770 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3771 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3774 /* Only draw the lines for visible rows and columns */
3775 for (list = tree_view->priv->columns; list; list = list->next, i++)
3777 PsppSheetViewColumn *column = list->data;
3779 /* We don't want a line for the last column */
3780 if (i == n_visible_columns - 1)
3783 if (! column->visible)
3786 current_x += column->width;
3788 if (current_x - 1 >= event->area.x
3789 && current_x - 1 < event->area.x + event->area.width)
3792 gdk_draw_line (event->window,
3793 tree_view->priv->grid_line_gc[GTK_WIDGET(tree_view)->state],
3794 current_x - 1, min_y,
3795 current_x - 1, max_y - min_y);
3798 cairo_t *cr = gdk_cairo_create (event->window);
3799 cairo_set_line_width (cr, 1.0);
3800 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
3801 cairo_move_to (cr, current_x - 0.5, min_y);
3802 cairo_line_to (cr, current_x - 0.5 , max_y - min_y);
3811 /* Warning: Very scary function.
3812 * Modify at your own risk
3814 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3815 * FIXME: It's not...
3818 pspp_sheet_view_bin_expose (GtkWidget *widget,
3819 GdkEventExpose *event)
3821 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3826 int drag_highlight = -1;
3829 gint y_offset, cell_offset;
3831 GdkRectangle background_area;
3832 GdkRectangle cell_area;
3834 gint bin_window_width;
3835 gint bin_window_height;
3836 GtkTreePath *cursor_path;
3837 GtkTreePath *drag_dest_path;
3838 GList *first_column, *last_column;
3839 gint vertical_separator;
3840 gint horizontal_separator;
3841 gint focus_line_width;
3842 gboolean allow_rules;
3843 gboolean has_special_cell;
3845 gint n_visible_columns;
3846 gint grid_line_width;
3847 gboolean row_ending_details;
3848 gboolean draw_vgrid_lines, draw_hgrid_lines;
3851 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3853 gtk_widget_style_get (widget,
3854 "horizontal-separator", &horizontal_separator,
3855 "vertical-separator", &vertical_separator,
3856 "allow-rules", &allow_rules,
3857 "focus-line-width", &focus_line_width,
3858 "row-ending-details", &row_ending_details,
3861 if (tree_view->priv->row_count == 0)
3863 draw_empty_focus (tree_view, &event->area);
3867 /* clip event->area to the visible area */
3868 if (event->area.height < 0.5)
3871 validate_visible_area (tree_view);
3873 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, event->area.y);
3877 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3879 gdk_window_get_width (tree_view->priv->bin_window);
3882 gdk_window_get_height (tree_view->priv->bin_window);
3885 if (tree_view->priv->height < bin_window_height)
3887 gtk_paint_flat_box (gtk_widget_get_style (widget),
3889 gtk_widget_get_state (widget),
3894 0, tree_view->priv->height,
3896 bin_window_height - tree_view->priv->height);
3902 /* find the path for the node */
3903 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3904 gtk_tree_model_get_iter (tree_view->priv->model,
3907 gtk_tree_path_free (path);
3910 drag_dest_path = NULL;
3912 if (tree_view->priv->cursor)
3913 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3916 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3918 if (tree_view->priv->drag_dest_row)
3919 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3922 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3926 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3927 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3929 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3930 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3932 if (draw_vgrid_lines || draw_hgrid_lines)
3933 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3935 n_visible_columns = 0;
3936 for (list = tree_view->priv->columns; list; list = list->next)
3938 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3940 n_visible_columns ++;
3943 /* Find the last column */
3944 for (last_column = g_list_last (tree_view->priv->columns);
3945 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
3946 last_column = last_column->prev)
3950 for (first_column = g_list_first (tree_view->priv->columns);
3951 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
3952 first_column = first_column->next)
3955 /* Actually process the expose event. To do this, we want to
3956 * start at the first node of the event, and walk the tree in
3957 * order, drawing each successive node.
3964 gboolean is_first = FALSE;
3965 gboolean is_last = FALSE;
3966 gboolean done = FALSE;
3969 max_height = ROW_HEIGHT (tree_view);
3973 background_area.y = y_offset + event->area.y;
3974 background_area.height = max_height;
3975 max_y = background_area.y + max_height;
3979 if (node == tree_view->priv->prelight_node)
3980 flags |= GTK_CELL_RENDERER_PRELIT;
3982 selected = pspp_sheet_view_node_is_selected (tree_view, node);
3986 if (tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
3988 /* we *need* to set cell data on all cells before the call
3989 * to _has_special_cell, else _has_special_cell() does not
3990 * return a correct value.
3992 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3994 list = (rtl ? list->prev : list->next))
3996 PsppSheetViewColumn *column = list->data;
3997 pspp_sheet_view_column_cell_set_cell_data (column,
3998 tree_view->priv->model,
4002 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
4005 has_special_cell = tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
4007 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
4009 list = (rtl ? list->prev : list->next))
4011 PsppSheetViewColumn *column = list->data;
4012 const gchar *detail = NULL;
4013 gboolean selected_column;
4016 if (!column->visible)
4019 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
4020 selected_column = column->selected && column->selectable;
4022 selected_column = TRUE;
4024 if (cell_offset > event->area.x + event->area.width ||
4025 cell_offset + column->width < event->area.x)
4027 cell_offset += column->width;
4031 if (selected && selected_column)
4032 flags |= GTK_CELL_RENDERER_SELECTED;
4034 flags &= ~GTK_CELL_RENDERER_SELECTED;
4036 if (column->show_sort_indicator)
4037 flags |= GTK_CELL_RENDERER_SORTED;
4039 flags &= ~GTK_CELL_RENDERER_SORTED;
4042 flags |= GTK_CELL_RENDERER_FOCUSED;
4044 flags &= ~GTK_CELL_RENDERER_FOCUSED;
4046 background_area.x = cell_offset;
4047 background_area.width = column->width;
4049 cell_area = background_area;
4050 cell_area.y += vertical_separator / 2;
4051 cell_area.x += horizontal_separator / 2;
4052 cell_area.height -= vertical_separator;
4053 cell_area.width -= horizontal_separator;
4055 if (draw_vgrid_lines)
4057 if (list == first_column)
4059 cell_area.width -= grid_line_width / 2;
4061 else if (list == last_column)
4063 cell_area.x += grid_line_width / 2;
4064 cell_area.width -= grid_line_width / 2;
4068 cell_area.x += grid_line_width / 2;
4069 cell_area.width -= grid_line_width;
4073 if (draw_hgrid_lines)
4075 cell_area.y += grid_line_width / 2;
4076 cell_area.height -= grid_line_width;
4079 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
4081 cell_offset += column->width;
4085 pspp_sheet_view_column_cell_set_cell_data (column,
4086 tree_view->priv->model,
4089 /* Select the detail for drawing the cell. relevant
4090 * factors are parity, sortedness, and whether to
4093 if (allow_rules && tree_view->priv->has_rules)
4095 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4096 n_visible_columns >= 3)
4099 detail = "cell_odd_ruled_sorted";
4101 detail = "cell_even_ruled_sorted";
4106 detail = "cell_odd_ruled";
4108 detail = "cell_even_ruled";
4113 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4114 n_visible_columns >= 3)
4117 detail = "cell_odd_sorted";
4119 detail = "cell_even_sorted";
4124 detail = "cell_odd";
4126 detail = "cell_even";
4132 if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE)
4133 state = GTK_STATE_INSENSITIVE;
4134 else if (flags & GTK_CELL_RENDERER_SELECTED)
4135 state = GTK_STATE_SELECTED;
4137 state = GTK_STATE_NORMAL;
4139 /* Draw background */
4140 if (row_ending_details)
4142 char new_detail[128];
4144 is_first = (rtl ? !list->next : !list->prev);
4145 is_last = (rtl ? !list->prev : !list->next);
4147 /* (I don't like the snprintfs either, but couldn't find a
4150 if (is_first && is_last)
4151 g_snprintf (new_detail, 127, "%s", detail);
4153 g_snprintf (new_detail, 127, "%s_start", detail);
4155 g_snprintf (new_detail, 127, "%s_end", detail);
4157 g_snprintf (new_detail, 128, "%s_middle", detail);
4159 gtk_paint_flat_box (gtk_widget_get_style (widget),
4168 background_area.width,
4169 background_area.height);
4173 gtk_paint_flat_box (gtk_widget_get_style (widget),
4182 background_area.width,
4183 background_area.height);
4186 if (draw_hgrid_lines)
4188 cairo_t *cr = gdk_cairo_create (event->window);
4189 cairo_set_line_width (cr, 1.0);
4190 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
4192 if (background_area.y >= 0)
4195 gdk_draw_line (event->window,
4196 tree_view->priv->grid_line_gc[widget->state],
4197 background_area.x, background_area.y,
4198 background_area.x + background_area.width,
4201 cairo_move_to (cr, background_area.x, background_area.y - 0.5);
4202 cairo_line_to (cr, background_area.x + background_area.width,
4203 background_area.y - 0.5);
4207 if (y_offset + max_height >= event->area.height - 0.5)
4210 gdk_draw_line (event->window,
4211 tree_view->priv->grid_line_gc[widget->state],
4212 background_area.x, background_area.y + max_height,
4213 background_area.x + background_area.width,
4214 background_area.y + max_height);
4217 cairo_move_to (cr, background_area.x, background_area.y + max_height - 0.5);
4218 cairo_line_to (cr, background_area.x + background_area.width,
4219 background_area.y + max_height - 0.5);
4226 _pspp_sheet_view_column_cell_render (column,
4233 if (node == cursor && has_special_cell &&
4234 ((column == tree_view->priv->focus_column &&
4235 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4236 gtk_widget_has_focus (widget)) ||
4237 (column == tree_view->priv->edited_column)))
4239 _pspp_sheet_view_column_cell_draw_focus (column,
4247 cell_offset += column->width;
4250 if (cell_offset < event->area.x)
4252 gtk_paint_flat_box (gtk_widget_get_style (widget),
4261 event->area.x - cell_offset,
4262 background_area.height);
4265 if (node == drag_highlight)
4267 /* Draw indicator for the drop
4269 gint highlight_y = -1;
4273 switch (tree_view->priv->drag_dest_pos)
4275 case PSPP_SHEET_VIEW_DROP_BEFORE:
4276 highlight_y = background_area.y - 1;
4277 if (highlight_y < 0)
4281 case PSPP_SHEET_VIEW_DROP_AFTER:
4282 highlight_y = background_area.y + background_area.height - 1;
4285 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4286 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4287 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4291 width = gdk_window_get_width (tree_view->priv->bin_window);
4293 if (row_ending_details)
4294 gtk_paint_focus (gtk_widget_get_style (widget),
4295 tree_view->priv->bin_window,
4296 gtk_widget_get_state (widget),
4300 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4301 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4302 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4303 - focus_line_width / 2,
4304 width, ROW_HEIGHT (tree_view)
4305 - focus_line_width + 1);
4307 gtk_paint_focus (gtk_widget_get_style (widget),
4308 tree_view->priv->bin_window,
4309 gtk_widget_get_state (widget),
4312 "treeview-drop-indicator",
4313 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4314 - focus_line_width / 2,
4315 width, ROW_HEIGHT (tree_view)
4316 - focus_line_width + 1);
4321 if (highlight_y >= 0)
4323 gdk_draw_line (event->window,
4324 widget->style->fg_gc[gtk_widget_get_state (widget)],
4327 rtl ? 0 : bin_window_width,
4333 /* draw the big row-spanning focus rectangle, if needed */
4334 if (!has_special_cell && node == cursor &&
4335 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4336 gtk_widget_has_focus (widget))
4338 gint tmp_y, tmp_height;
4340 GtkStateType focus_rect_state;
4343 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4344 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4345 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4348 width = gdk_window_get_width (tree_view->priv->bin_window);
4350 if (draw_hgrid_lines)
4352 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4353 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4357 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4358 tmp_height = ROW_HEIGHT (tree_view);
4361 if (row_ending_details)
4362 gtk_paint_focus (gtk_widget_get_style (widget),
4363 tree_view->priv->bin_window,
4368 ? (is_last ? "treeview" : "treeview-left" )
4369 : (is_last ? "treeview-right" : "treeview-middle" )),
4373 gtk_paint_focus (gtk_widget_get_style (widget),
4374 tree_view->priv->bin_window,
4383 y_offset += max_height;
4387 node = pspp_sheet_view_node_next (tree_view, node);
4390 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4394 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4401 while (y_offset < event->area.height);
4404 pspp_sheet_view_draw_vertical_grid_lines (tree_view, event, n_visible_columns,
4407 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4409 GdkRectangle *rectangles;
4412 gdk_region_get_rectangles (event->region,
4416 while (n_rectangles--)
4417 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4419 g_free (rectangles);
4423 gtk_tree_path_free (cursor_path);
4426 gtk_tree_path_free (drag_dest_path);
4432 pspp_sheet_view_expose (GtkWidget *widget,
4433 GdkEventExpose *event)
4435 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4437 if (event->window == tree_view->priv->bin_window)
4442 retval = pspp_sheet_view_bin_expose (widget, event);
4444 /* We can't just chain up to Container::expose as it will try to send the
4445 * event to the headers, so we handle propagating it to our children
4446 * (eg. widgets being edited) ourselves.
4448 tmp_list = tree_view->priv->children;
4451 PsppSheetViewChild *child = tmp_list->data;
4452 tmp_list = tmp_list->next;
4454 gtk_container_propagate_expose (GTK_CONTAINER (tree_view), child->widget, event);
4459 else if (event->window == tree_view->priv->header_window)
4461 gint n_visible_columns;
4464 gtk_paint_flat_box (gtk_widget_get_style (widget),
4474 event->area.height);
4476 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4478 PsppSheetViewColumn *column = list->data;
4480 if (column == tree_view->priv->drag_column || !column->visible)
4483 if (span_intersects (column->allocation.x, column->allocation.width,
4484 event->area.x, event->area.width)
4485 && column->button != NULL)
4486 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4487 column->button, event);
4490 n_visible_columns = 0;
4491 for (list = tree_view->priv->columns; list; list = list->next)
4493 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4495 n_visible_columns ++;
4497 pspp_sheet_view_draw_vertical_grid_lines (tree_view,
4501 event->area.height);
4503 else if (event->window == tree_view->priv->drag_window)
4505 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4506 tree_view->priv->drag_column->button,
4520 /* returns 0x1 when no column has been found -- yes it's hackish */
4521 static PsppSheetViewColumn *
4522 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4523 PsppSheetViewColumn *column,
4526 PsppSheetViewColumn *left_column = NULL;
4527 PsppSheetViewColumn *cur_column = NULL;
4530 if (!column->reorderable)
4531 return (PsppSheetViewColumn *)0x1;
4533 switch (drop_position)
4536 /* find first column where we can drop */
4537 tmp_list = tree_view->priv->columns;
4538 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4539 return (PsppSheetViewColumn *)0x1;
4543 g_assert (tmp_list);
4545 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4546 tmp_list = tmp_list->next;
4548 if (left_column && left_column->visible == FALSE)
4551 if (!tree_view->priv->column_drop_func)
4554 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4556 left_column = cur_column;
4563 if (!tree_view->priv->column_drop_func)
4566 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4569 return (PsppSheetViewColumn *)0x1;
4573 /* find first column after column where we can drop */
4574 tmp_list = tree_view->priv->columns;
4576 for (; tmp_list; tmp_list = tmp_list->next)
4577 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4580 if (!tmp_list || !tmp_list->next)
4581 return (PsppSheetViewColumn *)0x1;
4583 tmp_list = tmp_list->next;
4584 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4585 tmp_list = tmp_list->next;
4589 g_assert (tmp_list);
4591 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4592 tmp_list = tmp_list->next;
4594 if (left_column && left_column->visible == FALSE)
4596 left_column = cur_column;
4598 tmp_list = tmp_list->next;
4602 if (!tree_view->priv->column_drop_func)
4605 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4607 left_column = cur_column;
4614 if (!tree_view->priv->column_drop_func)
4617 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4620 return (PsppSheetViewColumn *)0x1;
4624 /* find first column before column where we can drop */
4625 tmp_list = tree_view->priv->columns;
4627 for (; tmp_list; tmp_list = tmp_list->next)
4628 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4631 if (!tmp_list || !tmp_list->prev)
4632 return (PsppSheetViewColumn *)0x1;
4634 tmp_list = tmp_list->prev;
4635 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4636 tmp_list = tmp_list->prev;
4640 g_assert (tmp_list);
4642 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4644 if (left_column && !left_column->visible)
4646 /*if (!tmp_list->prev)
4647 return (PsppSheetViewColumn *)0x1;
4650 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4651 tmp_list = tmp_list->prev->prev;
4654 cur_column = left_column;
4656 tmp_list = tmp_list->prev;
4660 if (!tree_view->priv->column_drop_func)
4663 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4666 cur_column = left_column;
4667 tmp_list = tmp_list->prev;
4670 if (!tree_view->priv->column_drop_func)
4673 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4676 return (PsppSheetViewColumn *)0x1;
4680 /* same as DROP_HOME case, but doing it backwards */
4681 tmp_list = g_list_last (tree_view->priv->columns);
4684 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4685 return (PsppSheetViewColumn *)0x1;
4689 g_assert (tmp_list);
4691 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4693 if (left_column && !left_column->visible)
4695 cur_column = left_column;
4696 tmp_list = tmp_list->prev;
4699 if (!tree_view->priv->column_drop_func)
4702 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4705 cur_column = left_column;
4706 tmp_list = tmp_list->prev;
4709 if (!tree_view->priv->column_drop_func)
4712 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4715 return (PsppSheetViewColumn *)0x1;
4719 return (PsppSheetViewColumn *)0x1;
4723 pspp_sheet_view_key_press (GtkWidget *widget,
4726 PsppSheetView *tree_view = (PsppSheetView *) widget;
4728 if (tree_view->priv->rubber_band_status)
4730 if (event->keyval == GDK_Escape)
4731 pspp_sheet_view_stop_rubber_band (tree_view);
4736 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4738 if (event->keyval == GDK_Escape)
4740 tree_view->priv->cur_reorder = NULL;
4741 pspp_sheet_view_button_release_drag_column (widget, NULL);
4746 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4748 GList *focus_column;
4751 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4753 for (focus_column = tree_view->priv->columns;
4755 focus_column = focus_column->next)
4757 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4759 if (column->button && gtk_widget_has_focus (column->button))
4764 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4765 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4766 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4768 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4770 if (!column->resizable)
4772 gtk_widget_error_bell (widget);
4776 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4777 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4779 gint old_width = column->resized_width;
4781 column->resized_width = MAX (column->resized_width,
4783 column->resized_width -= 2;
4784 if (column->resized_width < 0)
4785 column->resized_width = 0;
4787 if (column->min_width == -1)
4788 column->resized_width = MAX (column->button_request,
4789 column->resized_width);
4791 column->resized_width = MAX (column->min_width,
4792 column->resized_width);
4794 if (column->max_width != -1)
4795 column->resized_width = MIN (column->resized_width,
4798 column->use_resized_width = TRUE;
4800 if (column->resized_width != old_width)
4801 gtk_widget_queue_resize (widget);
4803 gtk_widget_error_bell (widget);
4805 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4806 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4808 gint old_width = column->resized_width;
4810 column->resized_width = MAX (column->resized_width,
4812 column->resized_width += 2;
4814 if (column->max_width != -1)
4815 column->resized_width = MIN (column->resized_width,
4818 column->use_resized_width = TRUE;
4820 if (column->resized_width != old_width)
4821 gtk_widget_queue_resize (widget);
4823 gtk_widget_error_bell (widget);
4830 (event->state & GDK_MOD1_MASK) &&
4831 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4832 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4833 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4834 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4836 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4838 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4839 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4841 PsppSheetViewColumn *col;
4842 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4843 if (col != (PsppSheetViewColumn *)0x1)
4844 pspp_sheet_view_move_column_after (tree_view, column, col);
4846 gtk_widget_error_bell (widget);
4848 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4849 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4851 PsppSheetViewColumn *col;
4852 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4853 if (col != (PsppSheetViewColumn *)0x1)
4854 pspp_sheet_view_move_column_after (tree_view, column, col);
4856 gtk_widget_error_bell (widget);
4858 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4860 PsppSheetViewColumn *col;
4861 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4862 if (col != (PsppSheetViewColumn *)0x1)
4863 pspp_sheet_view_move_column_after (tree_view, column, col);
4865 gtk_widget_error_bell (widget);
4867 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4869 PsppSheetViewColumn *col;
4870 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4871 if (col != (PsppSheetViewColumn *)0x1)
4872 pspp_sheet_view_move_column_after (tree_view, column, col);
4874 gtk_widget_error_bell (widget);
4881 /* Chain up to the parent class. It handles the keybindings. */
4882 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4885 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4887 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4891 /* We pass the event to the search_entry. If its text changes, then we start
4892 * the typeahead find capabilities. */
4893 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4894 && tree_view->priv->enable_search
4895 && !tree_view->priv->search_custom_entry_set)
4897 GdkEvent *new_event;
4899 const char *new_text;
4902 gboolean text_modified;
4903 gulong popup_menu_id;
4905 pspp_sheet_view_ensure_interactive_directory (tree_view);
4907 /* Make a copy of the current text */
4908 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4909 new_event = gdk_event_copy ((GdkEvent *) event);
4910 g_object_unref (((GdkEventKey *) new_event)->window);
4911 ((GdkEventKey *) new_event)->window = g_object_ref (gtk_widget_get_window (tree_view->priv->search_window));
4912 gtk_widget_realize (tree_view->priv->search_window);
4914 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4915 "popup-menu", G_CALLBACK (gtk_true),
4918 /* Move the entry off screen */
4919 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4920 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4921 gdk_screen_get_width (screen) + 1,
4922 gdk_screen_get_height (screen) + 1);
4923 gtk_widget_show (tree_view->priv->search_window);
4925 /* Send the event to the window. If the preedit_changed signal is emitted
4926 * during this event, we will set priv->imcontext_changed */
4927 tree_view->priv->imcontext_changed = FALSE;
4928 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4929 gdk_event_free (new_event);
4930 gtk_widget_hide (tree_view->priv->search_window);
4932 g_signal_handler_disconnect (tree_view->priv->search_entry,
4935 /* We check to make sure that the entry tried to handle the text, and that
4936 * the text has changed.
4938 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4939 text_modified = strcmp (old_text, new_text) != 0;
4941 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4942 (retval && text_modified)) /* ...or the text was modified */
4944 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4946 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4951 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
4961 pspp_sheet_view_key_release (GtkWidget *widget,
4964 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4966 if (tree_view->priv->rubber_band_status)
4969 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
4972 /* FIXME Is this function necessary? Can I get an enter_notify event
4973 * w/o either an expose event or a mouse motion event?
4976 pspp_sheet_view_enter_notify (GtkWidget *widget,
4977 GdkEventCrossing *event)
4979 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4983 /* Sanity check it */
4984 if (event->window != tree_view->priv->bin_window)
4987 if (tree_view->priv->row_count == 0)
4990 if (event->mode == GDK_CROSSING_GRAB ||
4991 event->mode == GDK_CROSSING_GTK_GRAB ||
4992 event->mode == GDK_CROSSING_GTK_UNGRAB ||
4993 event->mode == GDK_CROSSING_STATE_CHANGED)
4996 /* find the node internally */
4997 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
5000 pspp_sheet_view_find_offset (tree_view, new_y, &node);
5002 tree_view->priv->event_last_x = event->x;
5003 tree_view->priv->event_last_y = event->y;
5005 prelight_or_select (tree_view, node, event->x, event->y);
5011 pspp_sheet_view_leave_notify (GtkWidget *widget,
5012 GdkEventCrossing *event)
5014 PsppSheetView *tree_view;
5016 if (event->mode == GDK_CROSSING_GRAB)
5019 tree_view = PSPP_SHEET_VIEW (widget);
5021 if (tree_view->priv->prelight_node >= 0)
5022 _pspp_sheet_view_queue_draw_node (tree_view,
5023 tree_view->priv->prelight_node,
5026 tree_view->priv->event_last_x = -10000;
5027 tree_view->priv->event_last_y = -10000;
5029 prelight_or_select (tree_view,
5031 -1000, -1000); /* coords not possibly over an arrow */
5038 pspp_sheet_view_focus_out (GtkWidget *widget,
5039 GdkEventFocus *event)
5041 PsppSheetView *tree_view;
5043 tree_view = PSPP_SHEET_VIEW (widget);
5045 gtk_widget_queue_draw (widget);
5047 /* destroy interactive search dialog */
5048 if (tree_view->priv->search_window)
5049 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
5055 /* Incremental Reflow
5059 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
5062 GtkAllocation allocation;
5063 gint y = pspp_sheet_view_node_find_offset (tree_view, node)
5064 - gtk_adjustment_get_value (tree_view->priv->vadjustment)
5065 + TREE_VIEW_HEADER_HEIGHT (tree_view);
5067 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5069 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
5072 tree_view->priv->fixed_height);
5076 node_is_visible (PsppSheetView *tree_view,
5082 y = pspp_sheet_view_node_find_offset (tree_view, node);
5083 height = ROW_HEIGHT (tree_view);
5085 if (y >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5086 y + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5087 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5093 /* Returns the row height. */
5095 validate_row (PsppSheetView *tree_view,
5100 PsppSheetViewColumn *column;
5101 GList *list, *first_column, *last_column;
5103 gint horizontal_separator;
5104 gint vertical_separator;
5105 gint focus_line_width;
5106 gboolean draw_vgrid_lines, draw_hgrid_lines;
5108 gint grid_line_width;
5109 gboolean wide_separators;
5110 gint separator_height;
5112 gtk_widget_style_get (GTK_WIDGET (tree_view),
5113 "focus-padding", &focus_pad,
5114 "focus-line-width", &focus_line_width,
5115 "horizontal-separator", &horizontal_separator,
5116 "vertical-separator", &vertical_separator,
5117 "grid-line-width", &grid_line_width,
5118 "wide-separators", &wide_separators,
5119 "separator-height", &separator_height,
5123 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5124 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5126 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5127 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5129 for (last_column = g_list_last (tree_view->priv->columns);
5130 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5131 last_column = last_column->prev)
5134 for (first_column = g_list_first (tree_view->priv->columns);
5135 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5136 first_column = first_column->next)
5139 for (list = tree_view->priv->columns; list; list = list->next)
5144 column = list->data;
5146 if (! column->visible)
5149 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5150 pspp_sheet_view_column_cell_get_size (column,
5152 &tmp_width, &tmp_height);
5154 tmp_height += vertical_separator;
5155 height = MAX (height, tmp_height);
5157 tmp_width = tmp_width + horizontal_separator;
5159 if (draw_vgrid_lines)
5161 if (list->data == first_column || list->data == last_column)
5162 tmp_width += grid_line_width / 2.0;
5164 tmp_width += grid_line_width;
5167 if (tmp_width > column->requested_width)
5168 column->requested_width = tmp_width;
5171 if (draw_hgrid_lines)
5172 height += grid_line_width;
5174 tree_view->priv->post_validation_flag = TRUE;
5180 validate_visible_area (PsppSheetView *tree_view)
5182 GtkTreePath *path = NULL;
5183 GtkTreePath *above_path = NULL;
5186 gboolean size_changed = FALSE;
5188 gint area_above = 0;
5189 gint area_below = 0;
5190 GtkAllocation allocation;
5192 if (tree_view->priv->row_count == 0)
5195 if (tree_view->priv->scroll_to_path == NULL)
5198 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5200 total_height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5202 if (total_height == 0)
5205 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5208 /* we are going to scroll, and will update dy */
5209 _pspp_sheet_view_find_node (tree_view, path, &node);
5210 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5212 if (tree_view->priv->scroll_to_use_align)
5214 gint height = ROW_HEIGHT (tree_view);
5215 area_above = (total_height - height) *
5216 tree_view->priv->scroll_to_row_align;
5217 area_below = total_height - area_above - height;
5218 area_above = MAX (area_above, 0);
5219 area_below = MAX (area_below, 0);
5224 * 1) row not visible
5228 gint height = ROW_HEIGHT (tree_view);
5230 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5232 if (dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5233 dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5234 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5236 /* row visible: keep the row at the same position */
5237 area_above = dy - gtk_adjustment_get_value (tree_view->priv->vadjustment);
5238 area_below = (gtk_adjustment_get_value (tree_view->priv->vadjustment) +
5239 gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5244 /* row not visible */
5246 && dy + height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5248 /* row at the beginning -- fixed */
5250 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment)
5251 - area_above - height;
5253 else if (dy >= (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5254 gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5256 /* row at the end -- fixed */
5257 area_above = dy - (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5258 gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
5259 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) -
5260 area_above - height;
5264 area_above = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) - height;
5270 /* row somewhere in the middle, bring it to the top
5274 area_below = total_height - height;
5280 /* the scroll to isn't valid; ignore it.
5283 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5284 tree_view->priv->scroll_to_path = NULL;
5288 above_path = gtk_tree_path_copy (path);
5290 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5291 * backwards is much slower then forward, as there is no iter_prev function.
5292 * We go forwards first in case we run out of tree. Then we go backwards to
5295 while (node >= 0 && area_below > 0)
5297 gboolean done = FALSE;
5300 node = pspp_sheet_view_node_next (tree_view, node);
5303 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5305 gtk_tree_path_next (path);
5308 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5318 area_below -= ROW_HEIGHT (tree_view);
5320 gtk_tree_path_free (path);
5322 /* If we ran out of tree, and have extra area_below left, we need to add it
5325 area_above += area_below;
5327 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5329 /* We walk backwards */
5330 while (area_above > 0)
5332 node = pspp_sheet_view_node_prev (tree_view, node);
5334 /* Always find the new path in the tree. We cannot just assume
5335 * a gtk_tree_path_prev() is enough here, as there might be children
5336 * in between this node and the previous sibling node. If this
5337 * appears to be a performance hotspot in profiles, we can look into
5338 * intrigate logic for keeping path, node and iter in sync like
5339 * we do for forward walks. (Which will be hard because of the lacking
5346 gtk_tree_path_free (above_path);
5347 above_path = _pspp_sheet_view_find_path (tree_view, node);
5349 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5351 area_above -= ROW_HEIGHT (tree_view);
5354 /* set the dy here to scroll to the path,
5355 * and sync the top row accordingly
5357 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5358 pspp_sheet_view_top_row_to_dy (tree_view);
5360 /* update width/height and queue a resize */
5363 GtkRequisition requisition;
5365 /* We temporarily guess a size, under the assumption that it will be the
5366 * same when we get our next size_allocate. If we don't do this, we'll be
5367 * in an inconsistent state if we call top_row_to_dy. */
5369 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5370 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5371 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5372 gtk_adjustment_changed (tree_view->priv->hadjustment);
5373 gtk_adjustment_changed (tree_view->priv->vadjustment);
5374 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5377 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5378 tree_view->priv->scroll_to_path = NULL;
5381 gtk_tree_path_free (above_path);
5383 if (tree_view->priv->scroll_to_column)
5385 tree_view->priv->scroll_to_column = NULL;
5387 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5391 initialize_fixed_height_mode (PsppSheetView *tree_view)
5393 if (!tree_view->priv->row_count)
5396 if (tree_view->priv->fixed_height_set)
5399 if (tree_view->priv->fixed_height < 0)
5406 path = _pspp_sheet_view_find_path (tree_view, node);
5407 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5409 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5411 gtk_tree_path_free (path);
5413 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5417 /* Our strategy for finding nodes to validate is a little convoluted. We find
5418 * the left-most uninvalidated node. We then try walking right, validating
5419 * nodes. Once we find a valid node, we repeat the previous process of finding
5420 * the first invalid node.
5424 validate_rows_handler (PsppSheetView *tree_view)
5426 initialize_fixed_height_mode (tree_view);
5427 if (tree_view->priv->validate_rows_timer)
5429 g_source_remove (tree_view->priv->validate_rows_timer);
5430 tree_view->priv->validate_rows_timer = 0;
5437 do_presize_handler (PsppSheetView *tree_view)
5439 GtkRequisition requisition;
5441 validate_visible_area (tree_view);
5442 tree_view->priv->presize_handler_timer = 0;
5444 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5447 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5449 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5450 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5451 gtk_adjustment_changed (tree_view->priv->hadjustment);
5452 gtk_adjustment_changed (tree_view->priv->vadjustment);
5453 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5459 presize_handler_callback (gpointer data)
5461 do_presize_handler (PSPP_SHEET_VIEW (data));
5467 install_presize_handler (PsppSheetView *tree_view)
5469 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5472 if (! tree_view->priv->presize_handler_timer)
5474 tree_view->priv->presize_handler_timer =
5475 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5477 if (! tree_view->priv->validate_rows_timer)
5479 tree_view->priv->validate_rows_timer =
5480 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5485 scroll_sync_handler (PsppSheetView *tree_view)
5487 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5488 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5489 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5490 pspp_sheet_view_top_row_to_dy (tree_view);
5492 pspp_sheet_view_dy_to_top_row (tree_view);
5494 tree_view->priv->scroll_sync_timer = 0;
5500 install_scroll_sync_handler (PsppSheetView *tree_view)
5502 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5505 if (!tree_view->priv->scroll_sync_timer)
5507 tree_view->priv->scroll_sync_timer =
5508 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5513 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5517 gtk_tree_row_reference_free (tree_view->priv->top_row);
5521 tree_view->priv->top_row = NULL;
5522 tree_view->priv->top_row_dy = 0;
5526 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5527 tree_view->priv->top_row_dy = offset;
5531 /* Always call this iff dy is in the visible range. If the tree is empty, then
5532 * it's set to be NULL, and top_row_dy is 0;
5535 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5541 if (tree_view->priv->row_count == 0)
5543 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5547 offset = pspp_sheet_view_find_offset (tree_view,
5548 tree_view->priv->dy,
5553 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5557 path = _pspp_sheet_view_find_path (tree_view, node);
5558 pspp_sheet_view_set_top_row (tree_view, path, offset);
5559 gtk_tree_path_free (path);
5565 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5571 /* Avoid recursive calls */
5572 if (tree_view->priv->in_top_row_to_dy)
5575 if (tree_view->priv->top_row)
5576 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5583 _pspp_sheet_view_find_node (tree_view, path, &node);
5586 gtk_tree_path_free (path);
5590 /* keep dy and set new toprow */
5591 gtk_tree_row_reference_free (tree_view->priv->top_row);
5592 tree_view->priv->top_row = NULL;
5593 tree_view->priv->top_row_dy = 0;
5594 /* DO NOT install the idle handler */
5595 pspp_sheet_view_dy_to_top_row (tree_view);
5599 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5601 /* new top row -- do NOT install the idle handler */
5602 pspp_sheet_view_dy_to_top_row (tree_view);
5606 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5607 new_dy += tree_view->priv->top_row_dy;
5609 if (new_dy + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
5610 new_dy = tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
5612 new_dy = MAX (0, new_dy);
5614 tree_view->priv->in_top_row_to_dy = TRUE;
5615 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5616 tree_view->priv->in_top_row_to_dy = FALSE;
5621 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5623 install_presize_handler (tree_view);
5629 set_source_row (GdkDragContext *context,
5630 GtkTreeModel *model,
5631 GtkTreePath *source_row)
5633 g_object_set_data_full (G_OBJECT (context),
5634 "gtk-tree-view-source-row",
5635 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5636 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5640 get_source_row (GdkDragContext *context)
5642 GtkTreeRowReference *ref =
5643 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5646 return gtk_tree_row_reference_get_path (ref);
5653 GtkTreeRowReference *dest_row;
5654 guint path_down_mode : 1;
5655 guint empty_view_drop : 1;
5656 guint drop_append_mode : 1;
5661 dest_row_free (gpointer data)
5663 DestRow *dr = (DestRow *)data;
5665 gtk_tree_row_reference_free (dr->dest_row);
5666 g_slice_free (DestRow, dr);
5670 set_dest_row (GdkDragContext *context,
5671 GtkTreeModel *model,
5672 GtkTreePath *dest_row,
5673 gboolean path_down_mode,
5674 gboolean empty_view_drop,
5675 gboolean drop_append_mode)
5681 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5686 dr = g_slice_new (DestRow);
5688 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5689 dr->path_down_mode = path_down_mode != FALSE;
5690 dr->empty_view_drop = empty_view_drop != FALSE;
5691 dr->drop_append_mode = drop_append_mode != FALSE;
5693 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5694 dr, (GDestroyNotify) dest_row_free);
5698 get_dest_row (GdkDragContext *context,
5699 gboolean *path_down_mode)
5702 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5706 GtkTreePath *path = NULL;
5709 *path_down_mode = dr->path_down_mode;
5712 path = gtk_tree_row_reference_get_path (dr->dest_row);
5713 else if (dr->empty_view_drop)
5714 path = gtk_tree_path_new_from_indices (0, -1);
5718 if (path && dr->drop_append_mode)
5719 gtk_tree_path_next (path);
5727 /* Get/set whether drag_motion requested the drag data and
5728 * drag_data_received should thus not actually insert the data,
5729 * since the data doesn't result from a drop.
5732 set_status_pending (GdkDragContext *context,
5733 GdkDragAction suggested_action)
5735 g_object_set_data (G_OBJECT (context),
5736 "gtk-tree-view-status-pending",
5737 GINT_TO_POINTER (suggested_action));
5740 static GdkDragAction
5741 get_status_pending (GdkDragContext *context)
5743 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5744 "gtk-tree-view-status-pending"));
5747 static TreeViewDragInfo*
5748 get_info (PsppSheetView *tree_view)
5750 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5754 destroy_info (TreeViewDragInfo *di)
5756 g_slice_free (TreeViewDragInfo, di);
5759 static TreeViewDragInfo*
5760 ensure_info (PsppSheetView *tree_view)
5762 TreeViewDragInfo *di;
5764 di = get_info (tree_view);
5768 di = g_slice_new0 (TreeViewDragInfo);
5770 g_object_set_data_full (G_OBJECT (tree_view),
5771 "gtk-tree-view-drag-info",
5773 (GDestroyNotify) destroy_info);
5780 remove_info (PsppSheetView *tree_view)
5782 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5787 drag_scan_timeout (gpointer data)
5789 PsppSheetView *tree_view;
5791 GdkModifierType state;
5792 GtkTreePath *path = NULL;
5793 PsppSheetViewColumn *column = NULL;
5794 GdkRectangle visible_rect;
5796 GDK_THREADS_ENTER ();
5798 tree_view = PSPP_SHEET_VIEW (data);
5800 gdk_window_get_pointer (tree_view->priv->bin_window,
5803 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5805 /* See if we are near the edge. */
5806 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5807 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5808 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5809 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5811 pspp_sheet_view_get_path_at_pos (tree_view,
5812 tree_view->priv->bin_window,
5821 pspp_sheet_view_scroll_to_cell (tree_view,
5827 gtk_tree_path_free (path);
5831 GDK_THREADS_LEAVE ();
5838 add_scroll_timeout (PsppSheetView *tree_view)
5840 if (tree_view->priv->scroll_timeout == 0)
5842 tree_view->priv->scroll_timeout =
5843 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5848 remove_scroll_timeout (PsppSheetView *tree_view)
5850 if (tree_view->priv->scroll_timeout != 0)
5852 g_source_remove (tree_view->priv->scroll_timeout);
5853 tree_view->priv->scroll_timeout = 0;
5858 check_model_dnd (GtkTreeModel *model,
5859 GType required_iface,
5860 const gchar *signal)
5862 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5864 g_warning ("You must override the default '%s' handler "
5865 "on PsppSheetView when using models that don't support "
5866 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5867 "is to connect to '%s' and call "
5868 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5869 "the default handler from running. Look at the source code "
5870 "for the default handler in gtktreeview.c to get an idea what "
5871 "your handler should do. (gtktreeview.c is in the GTK source "
5872 "code.) If you're using GTK from a language other than C, "
5873 "there may be a more natural way to override default handlers, e.g. via derivation.",
5874 signal, g_type_name (required_iface), signal);
5882 scroll_row_timeout (gpointer data)
5884 PsppSheetView *tree_view = data;
5886 pspp_sheet_view_horizontal_autoscroll (tree_view);
5887 pspp_sheet_view_vertical_autoscroll (tree_view);
5889 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5890 pspp_sheet_view_update_rubber_band (tree_view);
5895 /* Returns TRUE if event should not be propagated to parent widgets */
5897 set_destination_row (PsppSheetView *tree_view,
5898 GdkDragContext *context,
5899 /* coordinates relative to the widget */
5902 GdkDragAction *suggested_action,
5905 GtkTreePath *path = NULL;
5906 PsppSheetViewDropPosition pos;
5907 PsppSheetViewDropPosition old_pos;
5908 TreeViewDragInfo *di;
5910 GtkTreePath *old_dest_path = NULL;
5911 gboolean can_drop = FALSE;
5913 *suggested_action = 0;
5916 widget = GTK_WIDGET (tree_view);
5918 di = get_info (tree_view);
5920 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5922 /* someone unset us as a drag dest, note that if
5923 * we return FALSE drag_leave isn't called
5926 pspp_sheet_view_set_drag_dest_row (tree_view,
5928 PSPP_SHEET_VIEW_DROP_BEFORE);
5930 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5932 return FALSE; /* no longer a drop site */
5935 *target = gtk_drag_dest_find_target (widget, context,
5936 gtk_drag_dest_get_target_list (widget));
5937 if (*target == GDK_NONE)
5942 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5948 GtkTreeModel *model;
5950 /* the row got dropped on empty space, let's setup a special case
5954 gtk_tree_path_free (path);
5956 model = pspp_sheet_view_get_model (tree_view);
5958 n_children = gtk_tree_model_iter_n_children (model, NULL);
5961 pos = PSPP_SHEET_VIEW_DROP_AFTER;
5962 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5966 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
5967 path = gtk_tree_path_new_from_indices (0, -1);
5977 /* If we left the current row's "open" zone, unset the timeout for
5980 pspp_sheet_view_get_drag_dest_row (tree_view,
5985 gtk_tree_path_free (old_dest_path);
5987 if (TRUE /* FIXME if the location droppable predicate */)
5995 GtkWidget *source_widget;
5997 *suggested_action = gdk_drag_context_get_suggested_action (context);
5998 source_widget = gtk_drag_get_source_widget (context);
6000 if (source_widget == widget)
6002 /* Default to MOVE, unless the user has
6003 * pressed ctrl or shift to affect available actions
6005 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6006 *suggested_action = GDK_ACTION_MOVE;
6009 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6014 /* can't drop here */
6015 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6017 PSPP_SHEET_VIEW_DROP_BEFORE);
6021 gtk_tree_path_free (path);
6027 get_logical_dest_row (PsppSheetView *tree_view,
6028 gboolean *path_down_mode,
6029 gboolean *drop_append_mode)
6031 /* adjust path to point to the row the drop goes in front of */
6032 GtkTreePath *path = NULL;
6033 PsppSheetViewDropPosition pos;
6035 g_return_val_if_fail (path_down_mode != NULL, NULL);
6036 g_return_val_if_fail (drop_append_mode != NULL, NULL);
6038 *path_down_mode = FALSE;
6039 *drop_append_mode = 0;
6041 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6046 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
6048 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
6049 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
6050 *path_down_mode = TRUE;
6054 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
6056 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
6058 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6059 !gtk_tree_model_iter_next (model, &iter))
6060 *drop_append_mode = 1;
6063 *drop_append_mode = 0;
6064 gtk_tree_path_next (path);
6072 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
6073 GdkEventMotion *event)
6075 GtkWidget *widget = GTK_WIDGET (tree_view);
6076 GdkDragContext *context;
6077 TreeViewDragInfo *di;
6078 GtkTreePath *path = NULL;
6080 gint cell_x, cell_y;
6081 GtkTreeModel *model;
6082 gboolean retval = FALSE;
6084 di = get_info (tree_view);
6086 if (di == NULL || !di->source_set)
6089 if (tree_view->priv->pressed_button < 0)
6092 if (!gtk_drag_check_threshold (widget,
6093 tree_view->priv->press_start_x,
6094 tree_view->priv->press_start_y,
6095 event->x, event->y))
6098 model = pspp_sheet_view_get_model (tree_view);
6103 button = tree_view->priv->pressed_button;
6104 tree_view->priv->pressed_button = -1;
6106 pspp_sheet_view_get_path_at_pos (tree_view,
6107 tree_view->priv->press_start_x,
6108 tree_view->priv->press_start_y,
6117 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6118 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6122 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6125 /* Now we can begin the drag */
6129 context = gtk_drag_begin (widget,
6130 gtk_drag_source_get_target_list (widget),
6135 set_source_row (context, model, path);
6139 gtk_tree_path_free (path);
6146 pspp_sheet_view_drag_begin (GtkWidget *widget,
6147 GdkDragContext *context)
6149 PsppSheetView *tree_view;
6150 GtkTreePath *path = NULL;
6151 gint cell_x, cell_y;
6153 TreeViewDragInfo *di;
6155 tree_view = PSPP_SHEET_VIEW (widget);
6157 /* if the user uses a custom DND source impl, we don't set the icon here */
6158 di = get_info (tree_view);
6160 if (di == NULL || !di->source_set)
6163 pspp_sheet_view_get_path_at_pos (tree_view,
6164 tree_view->priv->press_start_x,
6165 tree_view->priv->press_start_y,
6171 g_return_if_fail (path != NULL);
6173 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6176 gtk_drag_set_icon_pixmap (context,
6177 gdk_drawable_get_colormap (row_pix),
6180 /* the + 1 is for the black border in the icon */
6181 tree_view->priv->press_start_x + 1,
6184 g_object_unref (row_pix);
6185 gtk_tree_path_free (path);
6189 pspp_sheet_view_drag_end (GtkWidget *widget,
6190 GdkDragContext *context)
6195 /* Default signal implementations for the drag signals */
6197 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6198 GdkDragContext *context,
6199 GtkSelectionData *selection_data,
6203 PsppSheetView *tree_view;
6204 GtkTreeModel *model;
6205 TreeViewDragInfo *di;
6206 GtkTreePath *source_row;
6208 tree_view = PSPP_SHEET_VIEW (widget);
6210 model = pspp_sheet_view_get_model (tree_view);
6215 di = get_info (PSPP_SHEET_VIEW (widget));
6220 source_row = get_source_row (context);
6222 if (source_row == NULL)
6225 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6226 * any model; for DragSource models there are some other targets
6230 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6231 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6236 /* If drag_data_get does nothing, try providing row data. */
6237 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6239 gtk_tree_set_row_drag_data (selection_data,
6245 gtk_tree_path_free (source_row);
6250 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6251 GdkDragContext *context)
6253 TreeViewDragInfo *di;
6254 GtkTreeModel *model;
6255 PsppSheetView *tree_view;
6256 GtkTreePath *source_row;
6258 tree_view = PSPP_SHEET_VIEW (widget);
6259 model = pspp_sheet_view_get_model (tree_view);
6261 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6264 di = get_info (tree_view);
6269 source_row = get_source_row (context);
6271 if (source_row == NULL)
6274 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6277 gtk_tree_path_free (source_row);
6279 set_source_row (context, NULL, NULL);
6283 pspp_sheet_view_drag_leave (GtkWidget *widget,
6284 GdkDragContext *context,
6287 /* unset any highlight row */
6288 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6290 PSPP_SHEET_VIEW_DROP_BEFORE);
6292 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6297 pspp_sheet_view_drag_motion (GtkWidget *widget,
6298 GdkDragContext *context,
6299 /* coordinates relative to the widget */
6305 GtkTreePath *path = NULL;
6306 PsppSheetViewDropPosition pos;
6307 PsppSheetView *tree_view;
6308 GdkDragAction suggested_action = 0;
6311 tree_view = PSPP_SHEET_VIEW (widget);
6313 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6316 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6318 /* we only know this *after* set_desination_row */
6319 empty = tree_view->priv->empty_view_drop;
6321 if (path == NULL && !empty)
6323 /* Can't drop here. */
6324 gdk_drag_status (context, 0, time);
6328 if (tree_view->priv->open_dest_timeout == 0 &&
6329 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6330 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6336 add_scroll_timeout (tree_view);
6339 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6341 /* Request data so we can use the source row when
6342 * determining whether to accept the drop
6344 set_status_pending (context, suggested_action);
6345 gtk_drag_get_data (widget, context, target, time);
6349 set_status_pending (context, 0);
6350 gdk_drag_status (context, suggested_action, time);
6355 gtk_tree_path_free (path);
6362 pspp_sheet_view_drag_drop (GtkWidget *widget,
6363 GdkDragContext *context,
6364 /* coordinates relative to the widget */
6369 PsppSheetView *tree_view;
6371 GdkDragAction suggested_action = 0;
6372 GdkAtom target = GDK_NONE;
6373 TreeViewDragInfo *di;
6374 GtkTreeModel *model;
6375 gboolean path_down_mode;
6376 gboolean drop_append_mode;
6378 tree_view = PSPP_SHEET_VIEW (widget);
6380 model = pspp_sheet_view_get_model (tree_view);
6382 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6384 di = get_info (tree_view);
6389 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6392 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6395 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6397 if (target != GDK_NONE && path != NULL)
6399 /* in case a motion had requested drag data, change things so we
6400 * treat drag data receives as a drop.
6402 set_status_pending (context, 0);
6403 set_dest_row (context, model, path,
6404 path_down_mode, tree_view->priv->empty_view_drop,
6409 gtk_tree_path_free (path);
6411 /* Unset this thing */
6412 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6414 PSPP_SHEET_VIEW_DROP_BEFORE);
6416 if (target != GDK_NONE)
6418 gtk_drag_get_data (widget, context, target, time);
6426 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6427 GdkDragContext *context,
6428 /* coordinates relative to the widget */
6431 GtkSelectionData *selection_data,
6436 TreeViewDragInfo *di;
6437 gboolean accepted = FALSE;
6438 GtkTreeModel *model;
6439 PsppSheetView *tree_view;
6440 GtkTreePath *dest_row;
6441 GdkDragAction suggested_action;
6442 gboolean path_down_mode;
6443 gboolean drop_append_mode;
6445 tree_view = PSPP_SHEET_VIEW (widget);
6447 model = pspp_sheet_view_get_model (tree_view);
6449 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6452 di = get_info (tree_view);
6457 suggested_action = get_status_pending (context);
6459 if (suggested_action)
6461 /* We are getting this data due to a request in drag_motion,
6462 * rather than due to a request in drag_drop, so we are just
6463 * supposed to call drag_status, not actually paste in the
6466 path = get_logical_dest_row (tree_view, &path_down_mode,
6470 suggested_action = 0;
6471 else if (path_down_mode)
6472 gtk_tree_path_down (path);
6474 if (suggested_action)
6476 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6482 path_down_mode = FALSE;
6483 gtk_tree_path_up (path);
6485 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6488 suggested_action = 0;
6491 suggested_action = 0;
6495 gdk_drag_status (context, suggested_action, time);
6498 gtk_tree_path_free (path);
6500 /* If you can't drop, remove user drop indicator until the next motion */
6501 if (suggested_action == 0)
6502 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6504 PSPP_SHEET_VIEW_DROP_BEFORE);
6509 dest_row = get_dest_row (context, &path_down_mode);
6511 if (dest_row == NULL)
6514 if (gtk_selection_data_get_length (selection_data) >= 0)
6518 gtk_tree_path_down (dest_row);
6519 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6520 dest_row, selection_data))
6521 gtk_tree_path_up (dest_row);
6525 if (gtk_selection_data_get_length (selection_data) >= 0)
6527 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6533 gtk_drag_finish (context,
6535 (gdk_drag_context_get_actions (context) == GDK_ACTION_MOVE),
6538 if (gtk_tree_path_get_depth (dest_row) == 1
6539 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6541 /* special special case drag to "0", scroll to first item */
6542 if (!tree_view->priv->scroll_to_path)
6543 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6546 gtk_tree_path_free (dest_row);
6549 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6554 /* GtkContainer Methods
6559 pspp_sheet_view_remove (GtkContainer *container,
6562 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6563 PsppSheetViewChild *child = NULL;
6566 tmp_list = tree_view->priv->children;
6569 child = tmp_list->data;
6570 if (child->widget == widget)
6572 gtk_widget_unparent (widget);
6574 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6575 g_list_free_1 (tmp_list);
6576 g_slice_free (PsppSheetViewChild, child);
6580 tmp_list = tmp_list->next;
6583 tmp_list = tree_view->priv->columns;
6587 PsppSheetViewColumn *column;
6588 column = tmp_list->data;
6589 if (column->button == widget)
6591 gtk_widget_unparent (widget);
6594 tmp_list = tmp_list->next;
6599 pspp_sheet_view_forall (GtkContainer *container,
6600 gboolean include_internals,
6601 GtkCallback callback,
6602 gpointer callback_data)
6604 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6605 PsppSheetViewChild *child = NULL;
6606 PsppSheetViewColumn *column;
6609 tmp_list = tree_view->priv->children;
6612 child = tmp_list->data;
6613 tmp_list = tmp_list->next;
6615 (* callback) (child->widget, callback_data);
6617 if (include_internals == FALSE)
6620 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6622 column = tmp_list->data;
6625 (* callback) (column->button, callback_data);
6629 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6630 * cells. If so we draw one big row-spanning focus rectangle.
6633 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6637 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6638 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6640 for (list = tree_view->priv->columns; list; list = list->next)
6642 if (!((PsppSheetViewColumn *)list->data)->visible)
6644 if (_pspp_sheet_view_column_count_special_cells (list->data))
6652 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6653 PsppSheetViewColumn *focus_column,
6654 gboolean clamp_column_visible)
6656 g_return_if_fail (focus_column != NULL);
6658 tree_view->priv->focus_column = focus_column;
6659 if (!focus_column->button)
6661 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6662 // g_return_if_fail (focus_column->button != NULL);
6663 if (focus_column->button == NULL)
6667 if (gtk_container_get_focus_child (GTK_CONTAINER (tree_view)) != focus_column->button)
6668 gtk_widget_grab_focus (focus_column->button);
6670 if (clamp_column_visible)
6671 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6674 /* Returns TRUE if the focus is within the headers, after the focus operation is
6678 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6679 GtkDirectionType dir,
6680 gboolean clamp_column_visible)
6682 GtkWidget *focus_child;
6683 PsppSheetViewColumn *focus_column;
6684 GList *last_column, *first_column;
6688 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6691 focus_child = gtk_container_get_focus_child (GTK_CONTAINER (tree_view));
6693 first_column = tree_view->priv->columns;
6694 while (first_column)
6696 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6698 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6700 first_column = first_column->next;
6703 /* No headers are visible, or are focusable. We can't focus in or out.
6705 if (first_column == NULL)
6708 last_column = g_list_last (tree_view->priv->columns);
6711 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6713 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6715 last_column = last_column->prev;
6719 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6723 case GTK_DIR_TAB_BACKWARD:
6724 case GTK_DIR_TAB_FORWARD:
6727 if (focus_child == NULL)
6729 if (tree_view->priv->focus_column != NULL &&
6730 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6731 focus_column = tree_view->priv->focus_column;
6733 focus_column = first_column->data;
6734 pspp_sheet_view_focus_column (tree_view, focus_column,
6735 clamp_column_visible);
6742 if (focus_child == NULL)
6744 if (tree_view->priv->focus_column != NULL)
6745 focus_column = tree_view->priv->focus_column;
6746 else if (dir == GTK_DIR_LEFT)
6747 focus_column = last_column->data;
6749 focus_column = first_column->data;
6750 pspp_sheet_view_focus_column (tree_view, focus_column,
6751 clamp_column_visible);
6755 if (gtk_widget_child_focus (focus_child, dir))
6757 /* The focus moves inside the button. */
6758 /* This is probably a great example of bad UI */
6759 if (clamp_column_visible)
6760 pspp_sheet_view_clamp_column_visible (tree_view,
6761 tree_view->priv->focus_column,
6766 /* We need to move the focus among the row of buttons. */
6767 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6768 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6771 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6772 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6774 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6780 PsppSheetViewColumn *column;
6782 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6783 tmp_list = tmp_list->next;
6785 tmp_list = tmp_list->prev;
6787 if (tmp_list == NULL)
6789 g_warning ("Internal button not found");
6792 column = tmp_list->data;
6793 if (column->visible &&
6794 pspp_sheet_view_column_can_focus (column))
6796 pspp_sheet_view_column_set_need_button (column, TRUE);
6799 pspp_sheet_view_focus_column (tree_view, column,
6800 clamp_column_visible);
6808 g_assert_not_reached ();
6815 /* This function returns in 'path' the first focusable path, if the given path
6816 * is already focusable, it's the returned one.
6820 search_first_focusable_path (PsppSheetView *tree_view,
6822 gboolean search_forward,
6825 /* XXX this function is trivial given that the sheetview doesn't support
6829 if (!path || !*path)
6832 _pspp_sheet_view_find_node (tree_view, *path, &node);
6840 return (*path != NULL);
6844 pspp_sheet_view_focus (GtkWidget *widget,
6845 GtkDirectionType direction)
6847 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6848 GtkContainer *container = GTK_CONTAINER (widget);
6849 GtkWidget *focus_child;
6851 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6854 focus_child = gtk_container_get_focus_child (container);
6856 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6857 /* Case 1. Headers currently have focus. */
6864 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6866 case GTK_DIR_TAB_BACKWARD:
6869 case GTK_DIR_TAB_FORWARD:
6871 gtk_widget_grab_focus (widget);
6874 g_assert_not_reached ();
6879 /* Case 2. We don't have focus at all. */
6880 if (!gtk_widget_has_focus (widget))
6882 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6883 gtk_widget_grab_focus (widget);
6887 /* Case 3. We have focus already. */
6888 if (direction == GTK_DIR_TAB_BACKWARD)
6889 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6890 else if (direction == GTK_DIR_TAB_FORWARD)
6893 /* Other directions caught by the keybindings */
6894 gtk_widget_grab_focus (widget);
6899 pspp_sheet_view_grab_focus (GtkWidget *widget)
6901 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6903 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6907 pspp_sheet_view_style_set (GtkWidget *widget,
6908 GtkStyle *previous_style)
6910 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6912 PsppSheetViewColumn *column;
6914 if (gtk_widget_get_realized (widget))
6916 gdk_window_set_back_pixmap (gtk_widget_get_window (widget), NULL, FALSE);
6917 gdk_window_set_background (tree_view->priv->bin_window, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
6918 gtk_style_set_background (gtk_widget_get_style (widget), tree_view->priv->header_window, GTK_STATE_NORMAL);
6919 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6922 gtk_widget_style_get (widget,
6923 "expander-size", &tree_view->priv->expander_size,
6925 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6927 for (list = tree_view->priv->columns; list; list = list->next)
6929 column = list->data;
6930 _pspp_sheet_view_column_cell_set_dirty (column);
6933 tree_view->priv->fixed_height = -1;
6935 /* Invalidate cached button style. */
6936 if (tree_view->priv->button_style)
6938 g_object_unref (tree_view->priv->button_style);
6939 tree_view->priv->button_style = NULL;
6942 gtk_widget_queue_resize (widget);
6947 pspp_sheet_view_set_focus_child (GtkContainer *container,
6950 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6953 for (list = tree_view->priv->columns; list; list = list->next)
6955 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6957 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6962 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6966 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6967 GtkAdjustment *hadj,
6968 GtkAdjustment *vadj)
6970 gboolean need_adjust = FALSE;
6972 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6975 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6977 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6979 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
6981 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6983 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
6985 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
6986 pspp_sheet_view_adjustment_changed,
6988 g_object_unref (tree_view->priv->hadjustment);
6991 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
6993 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
6994 pspp_sheet_view_adjustment_changed,
6996 g_object_unref (tree_view->priv->vadjustment);
6999 if (tree_view->priv->hadjustment != hadj)
7001 tree_view->priv->hadjustment = hadj;
7002 g_object_ref_sink (tree_view->priv->hadjustment);
7004 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
7005 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7010 if (tree_view->priv->vadjustment != vadj)
7012 tree_view->priv->vadjustment = vadj;
7013 g_object_ref_sink (tree_view->priv->vadjustment);
7015 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
7016 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7022 pspp_sheet_view_adjustment_changed (NULL, tree_view);
7027 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
7028 GtkMovementStep step,
7031 PsppSheetSelectMode mode;
7032 GdkModifierType state;
7034 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
7035 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
7036 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
7037 step == GTK_MOVEMENT_DISPLAY_LINES ||
7038 step == GTK_MOVEMENT_PAGES ||
7039 step == GTK_MOVEMENT_BUFFER_ENDS ||
7040 step == GTK_MOVEMENT_DISPLAY_LINE_ENDS, FALSE);
7042 if (tree_view->priv->row_count == 0)
7044 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7047 pspp_sheet_view_stop_editing (tree_view, FALSE);
7048 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7049 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7052 if (gtk_get_current_event_state (&state))
7054 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7055 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
7056 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
7057 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
7059 /* else we assume not pressed */
7063 case GTK_MOVEMENT_LOGICAL_POSITIONS:
7064 pspp_sheet_view_move_cursor_tab (tree_view, count);
7066 case GTK_MOVEMENT_VISUAL_POSITIONS:
7067 pspp_sheet_view_move_cursor_left_right (tree_view, count, mode);
7069 case GTK_MOVEMENT_DISPLAY_LINES:
7070 pspp_sheet_view_move_cursor_up_down (tree_view, count, mode);
7072 case GTK_MOVEMENT_PAGES:
7073 pspp_sheet_view_move_cursor_page_up_down (tree_view, count, mode);
7075 case GTK_MOVEMENT_BUFFER_ENDS:
7076 pspp_sheet_view_move_cursor_start_end (tree_view, count, mode);
7078 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
7079 pspp_sheet_view_move_cursor_line_start_end (tree_view, count, mode);
7082 g_assert_not_reached ();
7089 pspp_sheet_view_put (PsppSheetView *tree_view,
7090 GtkWidget *child_widget,
7091 /* in bin_window coordinates */
7097 PsppSheetViewChild *child;
7099 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7100 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7102 child = g_slice_new (PsppSheetViewChild);
7104 child->widget = child_widget;
7107 child->width = width;
7108 child->height = height;
7110 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7112 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7113 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7115 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7119 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7121 /* in tree coordinates */
7127 PsppSheetViewChild *child = NULL;
7129 GdkRectangle allocation;
7131 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7132 g_return_if_fail (GTK_IS_WIDGET (widget));
7134 for (list = tree_view->priv->children; list; list = list->next)
7136 if (((PsppSheetViewChild *)list->data)->widget == widget)
7145 allocation.x = child->x = x;
7146 allocation.y = child->y = y;
7147 allocation.width = child->width = width;
7148 allocation.height = child->height = height;
7150 if (gtk_widget_get_realized (widget))
7151 gtk_widget_size_allocate (widget, &allocation);
7155 /* TreeModel Callbacks
7159 pspp_sheet_view_row_changed (GtkTreeModel *model,
7164 PsppSheetView *tree_view = (PsppSheetView *)data;
7166 gboolean free_path = FALSE;
7167 GtkTreePath *cursor_path;
7169 g_return_if_fail (path != NULL || iter != NULL);
7171 if (tree_view->priv->cursor != NULL)
7172 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7176 if (tree_view->priv->edited_column &&
7177 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7178 pspp_sheet_view_stop_editing (tree_view, TRUE);
7180 if (cursor_path != NULL)
7181 gtk_tree_path_free (cursor_path);
7185 path = gtk_tree_model_get_path (model, iter);
7188 else if (iter == NULL)
7189 gtk_tree_model_get_iter (model, iter, path);
7191 _pspp_sheet_view_find_node (tree_view,
7197 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7198 pspp_sheet_view_node_queue_redraw (tree_view, node);
7202 gtk_tree_path_free (path);
7206 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7211 PsppSheetView *tree_view = (PsppSheetView *) data;
7214 gint height = tree_view->priv->fixed_height;
7215 gboolean free_path = FALSE;
7216 gboolean node_visible = TRUE;
7218 g_return_if_fail (path != NULL || iter != NULL);
7222 path = gtk_tree_model_get_path (model, iter);
7225 else if (iter == NULL)
7226 gtk_tree_model_get_iter (model, iter, path);
7228 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7230 /* Update all row-references */
7231 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7232 indices = gtk_tree_path_get_indices (path);
7233 tmpnode = indices[0];
7235 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7239 if (node_visible && node_is_visible (tree_view, tmpnode))
7240 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7242 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7245 install_presize_handler (tree_view);
7247 gtk_tree_path_free (path);
7251 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7255 PsppSheetView *tree_view = (PsppSheetView *)data;
7258 g_return_if_fail (path != NULL);
7260 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7262 _pspp_sheet_view_find_node (tree_view, path, &node);
7267 range_tower_delete (tree_view->priv->selected, node, 1);
7269 /* Ensure we don't have a dangling pointer to a dead node */
7270 ensure_unprelighted (tree_view);
7272 /* Cancel editting if we've started */
7273 pspp_sheet_view_stop_editing (tree_view, TRUE);
7275 if (tree_view->priv->destroy_count_func)
7277 gint child_count = 0;
7278 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7281 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7283 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7285 gtk_tree_row_reference_free (tree_view->priv->top_row);
7286 tree_view->priv->top_row = NULL;
7289 install_scroll_sync_handler (tree_view);
7291 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7294 if (helper_data.changed)
7295 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7300 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7301 GtkTreePath *parent,
7306 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7309 /* XXX need to adjust selection */
7310 len = gtk_tree_model_iter_n_children (model, iter);
7315 gtk_tree_row_reference_reordered (G_OBJECT (data),
7320 if (gtk_tree_path_get_depth (parent) != 0)
7323 if (tree_view->priv->edited_column)
7324 pspp_sheet_view_stop_editing (tree_view, TRUE);
7326 /* we need to be unprelighted */
7327 ensure_unprelighted (tree_view);
7329 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7331 pspp_sheet_view_dy_to_top_row (tree_view);
7335 /* Internal tree functions
7340 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7341 PsppSheetViewColumn *column,
7345 PsppSheetViewColumn *tmp_column = NULL;
7356 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7359 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7361 list = (rtl ? list->prev : list->next))
7363 tmp_column = list->data;
7365 if (tmp_column == column)
7368 if (tmp_column->visible)
7369 total_width += tmp_column->width;
7372 if (tmp_column != column)
7374 g_warning (G_STRLOC": passed-in column isn't in the tree");
7383 if (column->visible)
7384 *x2 = total_width + column->width;
7386 *x2 = total_width; /* width of 0 */
7390 /* Make sure the node is visible vertically */
7392 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7395 gint node_dy, height;
7396 GtkTreePath *path = NULL;
7398 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7401 /* just return if the node is visible, avoiding a costly expose */
7402 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7403 height = ROW_HEIGHT (tree_view);
7404 if (node_dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment)
7405 && node_dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
7406 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
7409 path = _pspp_sheet_view_find_path (tree_view, node);
7412 /* We process updates because we want to clear old selected items when we scroll.
7413 * if this is removed, we get a "selection streak" at the bottom. */
7414 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7415 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7416 gtk_tree_path_free (path);
7421 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7422 PsppSheetViewColumn *column,
7423 gboolean focus_to_cell)
7430 x = column->allocation.x;
7431 width = column->allocation.width;
7433 if (width > gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7435 /* The column is larger than the horizontal page size. If the
7436 * column has cells which can be focussed individually, then we make
7437 * sure the cell which gets focus is fully visible (if even the
7438 * focus cell is bigger than the page size, we make sure the
7439 * left-hand side of the cell is visible).
7441 * If the column does not have those so-called special cells, we
7442 * make sure the left-hand side of the column is visible.
7445 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7447 GtkTreePath *cursor_path;
7448 GdkRectangle background_area, cell_area, focus_area;
7450 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7452 pspp_sheet_view_get_cell_area (tree_view,
7453 cursor_path, column, &cell_area);
7454 pspp_sheet_view_get_background_area (tree_view,
7455 cursor_path, column,
7458 gtk_tree_path_free (cursor_path);
7460 _pspp_sheet_view_column_get_focus_area (column,
7466 width = focus_area.width;
7468 if (width < gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7470 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7471 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7472 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7473 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7474 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7478 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7480 gtk_adjustment_get_lower (tree_view->priv->hadjustment),
7481 gtk_adjustment_get_upper (tree_view->priv->hadjustment)
7482 - gtk_adjustment_get_page_size (tree_view->priv->hadjustment)));
7486 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7487 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7488 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7489 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7490 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7495 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7500 path = gtk_tree_path_new ();
7502 gtk_tree_path_append_index (path, node);
7507 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7511 gint *indices = gtk_tree_path_get_indices (path);
7512 gint depth = gtk_tree_path_get_depth (path);
7515 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7521 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7524 gboolean add_shifted_binding,
7525 GtkMovementStep step,
7529 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7534 if (add_shifted_binding)
7535 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7540 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7543 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7548 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7555 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7556 PsppSheetViewColumn *column)
7558 PsppSheetViewColumn *left_column;
7559 PsppSheetViewColumn *cur_column = NULL;
7560 PsppSheetViewColumnReorder *reorder;
7565 /* We want to precalculate the motion list such that we know what column slots
7569 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7571 /* First, identify all possible drop spots */
7573 tmp_list = g_list_last (tree_view->priv->columns);
7575 tmp_list = g_list_first (tree_view->priv->columns);
7579 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7580 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7582 if (cur_column->visible == FALSE)
7585 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7586 if (left_column != column && cur_column != column &&
7587 tree_view->priv->column_drop_func &&
7588 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7590 left_column = cur_column;
7593 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7594 reorder->left_column = left_column;
7595 left_column = reorder->right_column = cur_column;
7597 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7600 /* Add the last one */
7601 if (tree_view->priv->column_drop_func == NULL ||
7602 ((left_column != column) &&
7603 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7605 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7606 reorder->left_column = left_column;
7607 reorder->right_column = NULL;
7608 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7611 /* We quickly check to see if it even makes sense to reorder columns. */
7612 /* If there is nothing that can be moved, then we return */
7614 if (tree_view->priv->column_drag_info == NULL)
7617 /* We know there are always 2 slots possbile, as you can always return column. */
7618 /* If that's all there is, return */
7619 if (tree_view->priv->column_drag_info->next == NULL ||
7620 (tree_view->priv->column_drag_info->next->next == NULL &&
7621 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7622 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7624 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7625 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7626 g_list_free (tree_view->priv->column_drag_info);
7627 tree_view->priv->column_drag_info = NULL;
7630 /* We fill in the ranges for the columns, now that we've isolated them */
7631 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7633 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7635 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7637 reorder->left_align = left;
7638 if (tmp_list->next != NULL)
7640 g_assert (tmp_list->next->data);
7641 left = reorder->right_align = (reorder->right_column->allocation.x +
7642 reorder->right_column->allocation.width +
7643 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7647 gint width = gdk_window_get_width (tree_view->priv->header_window);
7648 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7654 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7655 PsppSheetViewColumn *column)
7657 GdkEvent *send_event;
7658 GtkAllocation allocation;
7660 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7661 GdkDisplay *display = gdk_screen_get_display (screen);
7663 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7664 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7665 g_return_if_fail (column->button);
7667 pspp_sheet_view_set_column_drag_info (tree_view, column);
7669 if (tree_view->priv->column_drag_info == NULL)
7672 if (tree_view->priv->drag_window == NULL)
7674 GdkWindowAttr attributes;
7675 guint attributes_mask;
7677 attributes.window_type = GDK_WINDOW_CHILD;
7678 attributes.wclass = GDK_INPUT_OUTPUT;
7679 attributes.x = column->allocation.x;
7681 attributes.width = column->allocation.width;
7682 attributes.height = column->allocation.height;
7683 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7684 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
7685 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7686 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
7688 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7691 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7694 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7695 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7697 gtk_grab_remove (column->button);
7699 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7700 send_event->crossing.send_event = TRUE;
7701 send_event->crossing.window = g_object_ref (gtk_button_get_event_window (GTK_BUTTON (column->button)));
7702 send_event->crossing.subwindow = NULL;
7703 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7704 send_event->crossing.time = GDK_CURRENT_TIME;
7706 gtk_propagate_event (column->button, send_event);
7707 gdk_event_free (send_event);
7709 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7710 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7711 send_event->button.send_event = TRUE;
7712 send_event->button.time = GDK_CURRENT_TIME;
7713 send_event->button.x = -1;
7714 send_event->button.y = -1;
7715 send_event->button.axes = NULL;
7716 send_event->button.state = 0;
7717 send_event->button.button = 1;
7718 send_event->button.device = gdk_display_get_core_pointer (display);
7719 send_event->button.x_root = 0;
7720 send_event->button.y_root = 0;
7722 gtk_propagate_event (column->button, send_event);
7723 gdk_event_free (send_event);
7725 /* Kids, don't try this at home */
7726 g_object_ref (column->button);
7727 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7728 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7729 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7730 g_object_unref (column->button);
7732 tree_view->priv->drag_column_x = column->allocation.x;
7733 allocation = column->allocation;
7735 gtk_widget_size_allocate (column->button, &allocation);
7736 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7738 tree_view->priv->drag_column = column;
7739 gdk_window_show (tree_view->priv->drag_window);
7741 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7743 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7744 while (gtk_events_pending ())
7745 gtk_main_iteration ();
7747 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7748 gdk_pointer_grab (tree_view->priv->drag_window,
7750 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7751 NULL, NULL, GDK_CURRENT_TIME);
7752 gdk_keyboard_grab (tree_view->priv->drag_window,
7758 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7760 const GdkRectangle *clip_rect)
7763 GtkAllocation allocation;
7765 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7768 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
7770 rect.width = MAX (tree_view->priv->width, allocation.width);
7772 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7773 rect.height = ROW_HEIGHT (tree_view);
7777 GdkRectangle new_rect;
7779 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7781 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7785 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7790 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7792 const GdkRectangle *clip_rect)
7796 _pspp_sheet_view_find_node (tree_view, path, &node);
7799 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7803 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7806 GtkTreePath *cursor_path;
7808 if ((tree_view->priv->row_count == 0) ||
7809 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7813 if (tree_view->priv->cursor)
7814 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7816 if (cursor_path == NULL)
7818 /* There's no cursor. Move the cursor to the first selected row, if any
7819 * are selected, otherwise to the first row in the sheetview.
7821 GList *selected_rows;
7822 GtkTreeModel *model;
7823 PsppSheetSelection *selection;
7825 selection = pspp_sheet_view_get_selection (tree_view);
7826 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7830 /* XXX we could avoid doing O(n) work to get this result */
7831 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7832 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7833 g_list_free (selected_rows);
7837 cursor_path = gtk_tree_path_new_first ();
7838 search_first_focusable_path (tree_view, &cursor_path,
7842 gtk_tree_row_reference_free (tree_view->priv->cursor);
7843 tree_view->priv->cursor = NULL;
7847 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7848 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7849 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE, 0);
7851 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, 0);
7857 /* Now find a column for the cursor. */
7858 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7860 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7861 gtk_tree_path_free (cursor_path);
7863 if (tree_view->priv->focus_column == NULL)
7866 for (list = tree_view->priv->columns; list; list = list->next)
7868 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7870 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7871 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7872 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7882 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7884 PsppSheetSelectMode mode)
7886 gint selection_count;
7887 int cursor_node = -1;
7888 int new_cursor_node = -1;
7889 GtkTreePath *cursor_path = NULL;
7890 gboolean grab_focus = TRUE;
7892 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7896 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7897 /* FIXME: we lost the cursor; should we get the first? */
7900 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7901 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7903 if (cursor_node < 0)
7904 /* FIXME: we lost the cursor; should we get the first? */
7907 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7909 if (selection_count == 0
7910 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7911 && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
7913 /* Don't move the cursor, but just select the current node */
7914 new_cursor_node = cursor_node;
7919 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7921 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7924 gtk_tree_path_free (cursor_path);
7926 if (new_cursor_node)
7928 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7930 search_first_focusable_path (tree_view, &cursor_path,
7935 gtk_tree_path_free (cursor_path);
7939 * If the list has only one item and multi-selection is set then select
7940 * the row (if not yet selected).
7942 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7943 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7944 new_cursor_node < 0)
7947 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7949 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7951 if (new_cursor_node < 0
7952 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7954 new_cursor_node = cursor_node;
7958 new_cursor_node = -1;
7962 if (new_cursor_node >= 0)
7964 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7965 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE, mode);
7966 gtk_tree_path_free (cursor_path);
7970 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7972 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
7974 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7976 GTK_DIR_UP : GTK_DIR_DOWN))
7978 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
7981 gtk_widget_child_focus (toplevel,
7983 GTK_DIR_TAB_BACKWARD :
7984 GTK_DIR_TAB_FORWARD);
7991 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7996 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7998 return new_cursor_node >= 0;
8002 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
8004 PsppSheetSelectMode mode)
8006 int cursor_node = -1;
8007 GtkTreePath *old_cursor_path = NULL;
8008 GtkTreePath *cursor_path = NULL;
8009 int start_cursor_node = -1;
8012 gint vertical_separator;
8014 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8017 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8018 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8020 /* This is sorta weird. Focus in should give us a cursor */
8023 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
8024 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
8026 if (cursor_node < 0)
8028 /* FIXME: we lost the cursor. Should we try to get one? */
8029 gtk_tree_path_free (old_cursor_path);
8033 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8034 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
8035 y += tree_view->priv->cursor_offset;
8036 y += count * (int)gtk_adjustment_get_page_increment (tree_view->priv->vadjustment);
8037 y = CLAMP (y, (gint)gtk_adjustment_get_lower (tree_view->priv->vadjustment), (gint)gtk_adjustment_get_upper (tree_view->priv->vadjustment) - vertical_separator);
8039 if (y >= tree_view->priv->height)
8040 y = tree_view->priv->height - 1;
8042 tree_view->priv->cursor_offset =
8043 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
8045 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
8047 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
8048 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
8051 y -= tree_view->priv->cursor_offset;
8052 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8054 start_cursor_node = cursor_node;
8056 if (! search_first_focusable_path (tree_view, &cursor_path,
8060 /* It looks like we reached the end of the view without finding
8061 * a focusable row. We will step backwards to find the last
8064 cursor_node = start_cursor_node;
8065 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8067 search_first_focusable_path (tree_view, &cursor_path,
8076 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8078 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, mode);
8081 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
8082 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8083 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8085 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
8086 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8088 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8091 gtk_tree_path_free (old_cursor_path);
8092 gtk_tree_path_free (cursor_path);
8096 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
8098 PsppSheetSelectMode mode)
8100 int cursor_node = -1;
8101 GtkTreePath *cursor_path = NULL;
8102 PsppSheetViewColumn *column;
8105 gboolean found_column = FALSE;
8108 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8110 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8113 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8114 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8118 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8119 if (cursor_node < 0)
8121 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8123 gtk_tree_path_free (cursor_path);
8126 gtk_tree_path_free (cursor_path);
8128 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8129 if (tree_view->priv->focus_column)
8131 for (; list; list = (rtl ? list->prev : list->next))
8133 if (list->data == tree_view->priv->focus_column)
8140 gboolean left, right;
8142 column = list->data;
8143 if (column->visible == FALSE || column->row_head)
8146 pspp_sheet_view_column_cell_set_cell_data (column,
8147 tree_view->priv->model,
8152 right = list->prev ? TRUE : FALSE;
8153 left = list->next ? TRUE : FALSE;
8157 left = list->prev ? TRUE : FALSE;
8158 right = list->next ? TRUE : FALSE;
8161 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8163 tree_view->priv->focus_column = column;
8164 found_column = TRUE;
8169 list = rtl ? list->prev : list->next;
8171 list = rtl ? list->next : list->prev;
8176 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8177 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8178 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8182 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8185 pspp_sheet_view_clamp_column_visible (tree_view,
8186 tree_view->priv->focus_column, TRUE);
8190 pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
8192 PsppSheetSelectMode mode)
8194 int cursor_node = -1;
8195 GtkTreePath *cursor_path = NULL;
8196 PsppSheetViewColumn *column;
8197 PsppSheetViewColumn *found_column;
8202 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8204 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8207 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8208 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8212 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8213 if (cursor_node < 0)
8215 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8217 gtk_tree_path_free (cursor_path);
8220 gtk_tree_path_free (cursor_path);
8222 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8223 if (tree_view->priv->focus_column)
8225 for (; list; list = (rtl ? list->prev : list->next))
8227 if (list->data == tree_view->priv->focus_column)
8232 found_column = NULL;
8235 gboolean left, right;
8237 column = list->data;
8238 if (column->visible == FALSE || column->row_head)
8241 pspp_sheet_view_column_cell_set_cell_data (column,
8242 tree_view->priv->model,
8247 right = list->prev ? TRUE : FALSE;
8248 left = list->next ? TRUE : FALSE;
8252 left = list->prev ? TRUE : FALSE;
8253 right = list->next ? TRUE : FALSE;
8256 if (column->tabbable
8257 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8258 found_column = column;
8262 list = rtl ? list->prev : list->next;
8264 list = rtl ? list->next : list->prev;
8269 tree_view->priv->focus_column = found_column;
8270 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8271 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8272 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8275 pspp_sheet_view_clamp_column_visible (tree_view,
8276 tree_view->priv->focus_column, TRUE);
8280 try_move_cursor_tab (PsppSheetView *tree_view,
8281 gboolean start_at_focus_column,
8284 PsppSheetViewColumn *column;
8286 int cursor_node = -1;
8287 GtkTreePath *cursor_path = NULL;
8291 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8292 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8296 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8297 if (cursor_node < 0)
8299 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8301 gtk_tree_path_free (cursor_path);
8304 gtk_tree_path_free (cursor_path);
8306 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
8307 if (start_at_focus_column)
8310 ? g_list_last (tree_view->priv->columns)
8311 : g_list_first (tree_view->priv->columns));
8312 if (tree_view->priv->focus_column)
8314 for (; list; list = (rtl ? list->prev : list->next))
8316 if (list->data == tree_view->priv->focus_column)
8323 list = (rtl ^ (count == 1)
8324 ? g_list_first (tree_view->priv->columns)
8325 : g_list_last (tree_view->priv->columns));
8330 gboolean left, right;
8332 column = list->data;
8333 if (column->visible == FALSE || !column->tabbable)
8336 pspp_sheet_view_column_cell_set_cell_data (column,
8337 tree_view->priv->model,
8342 right = list->prev ? TRUE : FALSE;
8343 left = list->next ? TRUE : FALSE;
8347 left = list->prev ? TRUE : FALSE;
8348 right = list->next ? TRUE : FALSE;
8351 if (column->tabbable
8352 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8354 tree_view->priv->focus_column = column;
8355 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8356 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8357 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8362 list = rtl ? list->prev : list->next;
8364 list = rtl ? list->next : list->prev;
8371 pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
8374 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8377 if (!try_move_cursor_tab (tree_view, TRUE, count))
8379 if (pspp_sheet_view_move_cursor_up_down (tree_view, count, 0)
8380 && !try_move_cursor_tab (tree_view, FALSE, count))
8381 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8384 pspp_sheet_view_clamp_column_visible (tree_view,
8385 tree_view->priv->focus_column, TRUE);
8389 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8391 PsppSheetSelectMode mode)
8395 GtkTreePath *old_path;
8397 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8400 g_return_if_fail (tree_view->priv->row_count > 0);
8402 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8406 /* Now go forward to find the first focusable row. */
8407 path = _pspp_sheet_view_find_path (tree_view, 0);
8408 search_first_focusable_path (tree_view, &path,
8409 TRUE, &cursor_node);
8413 /* Now go backwards to find last focusable row. */
8414 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8415 search_first_focusable_path (tree_view, &path,
8416 FALSE, &cursor_node);
8422 if (gtk_tree_path_compare (old_path, path))
8424 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
8425 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8429 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8433 gtk_tree_path_free (old_path);
8434 gtk_tree_path_free (path);
8438 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8440 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8443 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8444 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8447 pspp_sheet_selection_select_all (tree_view->priv->selection);
8453 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8455 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8458 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8459 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8462 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8468 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8469 gboolean start_editing,
8470 PsppSheetSelectMode mode)
8473 int cursor_node = -1;
8474 GtkTreePath *cursor_path = NULL;
8476 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8479 if (tree_view->priv->cursor)
8480 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8482 if (cursor_path == NULL)
8485 _pspp_sheet_view_find_node (tree_view, cursor_path,
8488 if (cursor_node < 0)
8490 gtk_tree_path_free (cursor_path);
8494 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND) && start_editing &&
8495 tree_view->priv->focus_column)
8497 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8499 gtk_tree_path_free (cursor_path);
8504 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8510 /* We bail out if the original (tree, node) don't exist anymore after
8511 * handling the selection-changed callback. We do return TRUE because
8512 * the key press has been handled at this point.
8514 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8516 if (cursor_node != new_node)
8519 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8521 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8522 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8524 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
8525 pspp_sheet_view_row_activated (tree_view, cursor_path,
8526 tree_view->priv->focus_column);
8528 gtk_tree_path_free (cursor_path);
8534 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8537 int cursor_node = -1;
8538 GtkTreePath *cursor_path = NULL;
8540 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8544 if (tree_view->priv->cursor)
8545 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8547 if (cursor_path == NULL)
8550 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8551 if (cursor_node < 0)
8553 gtk_tree_path_free (cursor_path);
8557 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8560 PSPP_SHEET_SELECT_MODE_TOGGLE,
8563 /* We bail out if the original (tree, node) don't exist anymore after
8564 * handling the selection-changed callback. We do return TRUE because
8565 * the key press has been handled at this point.
8567 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8569 if (cursor_node != new_node)
8572 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8574 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8575 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8576 gtk_tree_path_free (cursor_path);
8582 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8584 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8585 tree_view->priv->typeselect_flush_timeout = 0;
8590 /* Cut and paste from gtkwindow.c */
8592 send_focus_change (GtkWidget *widget,
8595 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8597 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8598 fevent->focus_change.window = g_object_ref (gtk_widget_get_window (widget));
8599 fevent->focus_change.in = in;
8601 gtk_widget_send_focus_change (widget, fevent);
8602 gdk_event_free (fevent);
8606 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8608 GtkWidget *frame, *vbox, *toplevel;
8611 if (tree_view->priv->search_custom_entry_set)
8614 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8615 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8617 if (tree_view->priv->search_window != NULL)
8619 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8620 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8621 GTK_WINDOW (tree_view->priv->search_window));
8622 else if (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)))
8623 gtk_window_group_remove_window (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)),
8624 GTK_WINDOW (tree_view->priv->search_window));
8625 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8629 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8630 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8632 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8633 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8634 GTK_WINDOW (tree_view->priv->search_window));
8636 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8637 GDK_WINDOW_TYPE_HINT_UTILITY);
8638 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8639 g_signal_connect (tree_view->priv->search_window, "delete-event",
8640 G_CALLBACK (pspp_sheet_view_search_delete_event),
8642 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8643 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8645 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8646 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8648 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8649 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8652 frame = gtk_frame_new (NULL);
8653 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8654 gtk_widget_show (frame);
8655 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8657 vbox = gtk_vbox_new (FALSE, 0);
8658 gtk_widget_show (vbox);
8659 gtk_container_add (GTK_CONTAINER (frame), vbox);
8660 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8663 tree_view->priv->search_entry = gtk_entry_new ();
8664 gtk_widget_show (tree_view->priv->search_entry);
8665 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8666 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8668 g_signal_connect (tree_view->priv->search_entry,
8669 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8673 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8675 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8679 gtk_container_add (GTK_CONTAINER (vbox),
8680 tree_view->priv->search_entry);
8682 gtk_widget_realize (tree_view->priv->search_entry);
8685 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8686 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8689 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8690 gboolean keybinding)
8692 /* We only start interactive search if we have focus or the columns
8693 * have focus. If one of our children have focus, we don't want to
8697 gboolean found_focus = FALSE;
8698 GtkWidgetClass *entry_parent_class;
8700 if (!tree_view->priv->enable_search && !keybinding)
8703 if (tree_view->priv->search_custom_entry_set)
8706 if (tree_view->priv->search_window != NULL &&
8707 gtk_widget_get_visible (tree_view->priv->search_window))
8710 for (list = tree_view->priv->columns; list; list = list->next)
8712 PsppSheetViewColumn *column;
8714 column = list->data;
8715 if (! column->visible)
8718 if (column->button && gtk_widget_has_focus (column->button))
8725 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8731 if (tree_view->priv->search_column < 0)
8734 pspp_sheet_view_ensure_interactive_directory (tree_view);
8737 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8740 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8741 gtk_widget_show (tree_view->priv->search_window);
8742 if (tree_view->priv->search_entry_changed_id == 0)
8744 tree_view->priv->search_entry_changed_id =
8745 g_signal_connect (tree_view->priv->search_entry, "changed",
8746 G_CALLBACK (pspp_sheet_view_search_init),
8750 tree_view->priv->typeselect_flush_timeout =
8751 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8752 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8755 /* Grab focus will select all the text. We don't want that to happen, so we
8756 * call the parent instance and bypass the selection change. This is probably
8757 * really non-kosher. */
8758 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8759 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8761 /* send focus-in event */
8762 send_focus_change (tree_view->priv->search_entry, TRUE);
8764 /* search first matching iter */
8765 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8771 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8773 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8776 /* this function returns the new width of the column being resized given
8777 * the column and x position of the cursor; the x cursor position is passed
8778 * in as a pointer and automagicly corrected if it's beyond min/max limits
8781 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8785 PsppSheetViewColumn *column;
8789 /* first translate the x position from gtk_widget_get_window (widget)
8790 * to clist->clist_window
8792 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8793 column = g_list_nth (tree_view->priv->columns, i)->data;
8794 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8796 /* Clamp down the value */
8797 if (column->min_width == -1)
8798 width = MAX (column->button_request, width);
8800 width = MAX (column->min_width, width);
8801 if (column->max_width != -1)
8802 width = MIN (width, column->max_width);
8804 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8810 /* FIXME this adjust_allocation is a big cut-and-paste from
8811 * GtkCList, needs to be some "official" way to do this
8821 /* The window to which gtk_widget_get_window (widget) is relative */
8822 #define ALLOCATION_WINDOW(widget) \
8823 (!gtk_widget_get_has_window (widget) ? \
8824 gtk_widget_get_window (widget) : \
8825 gdk_window_get_parent (gtk_widget_get_window (widget)))
8828 adjust_allocation_recurse (GtkWidget *widget,
8831 ScrollData *scroll_data = data;
8832 GtkAllocation allocation;
8833 gtk_widget_get_allocation (widget, &allocation);
8834 /* Need to really size allocate instead of just poking
8835 * into widget->allocation if the widget is not realized.
8836 * FIXME someone figure out why this was.
8838 if (!gtk_widget_get_realized (widget))
8840 if (gtk_widget_get_visible (widget))
8842 GdkRectangle tmp_rectangle = allocation;
8843 tmp_rectangle.x += scroll_data->dx;
8844 tmp_rectangle.y += scroll_data->dy;
8846 gtk_widget_size_allocate (widget, &tmp_rectangle);
8851 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8853 allocation.x += scroll_data->dx;
8854 allocation.y += scroll_data->dy;
8856 if (GTK_IS_CONTAINER (widget))
8857 gtk_container_forall (GTK_CONTAINER (widget),
8858 adjust_allocation_recurse,
8865 adjust_allocation (GtkWidget *widget,
8869 ScrollData scroll_data;
8871 if (gtk_widget_get_realized (widget))
8872 scroll_data.window = ALLOCATION_WINDOW (widget);
8874 scroll_data.window = NULL;
8876 scroll_data.dx = dx;
8877 scroll_data.dy = dy;
8879 adjust_allocation_recurse (widget, &scroll_data);
8883 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8887 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8888 PsppSheetView *tree_view)
8890 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8895 gdk_window_move (tree_view->priv->bin_window,
8896 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8897 TREE_VIEW_HEADER_HEIGHT (tree_view));
8898 gdk_window_move (tree_view->priv->header_window,
8899 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8901 dy = tree_view->priv->dy - (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8904 update_prelight (tree_view,
8905 tree_view->priv->event_last_x,
8906 tree_view->priv->event_last_y - dy);
8908 if (tree_view->priv->edited_column &&
8909 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8913 PsppSheetViewChild *child = NULL;
8915 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8916 adjust_allocation (widget, 0, dy);
8918 for (list = tree_view->priv->children; list; list = list->next)
8920 child = (PsppSheetViewChild *)list->data;
8921 if (child->widget == widget)
8929 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8931 if (tree_view->priv->dy != (int) gtk_adjustment_get_value (tree_view->priv->vadjustment))
8933 /* update our dy and top_row */
8934 tree_view->priv->dy = (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8936 if (!tree_view->priv->in_top_row_to_dy)
8937 pspp_sheet_view_dy_to_top_row (tree_view);
8940 for (list = tree_view->priv->columns; list; list = list->next)
8942 PsppSheetViewColumn *column = list->data;
8943 GtkAllocation *col_allocation = &column->allocation;
8944 GtkAllocation widget_allocation;
8945 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &widget_allocation);
8947 if (span_intersects (col_allocation->x, col_allocation->width,
8948 gtk_adjustment_get_value (tree_view->priv->hadjustment),
8949 widget_allocation.width))
8951 pspp_sheet_view_column_set_need_button (column, TRUE);
8952 if (!column->button)
8953 pspp_sheet_view_column_update_button (column);
8965 * pspp_sheet_view_new:
8967 * Creates a new #PsppSheetView widget.
8969 * Return value: A newly created #PsppSheetView widget.
8972 pspp_sheet_view_new (void)
8974 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8978 * pspp_sheet_view_new_with_model:
8979 * @model: the model.
8981 * Creates a new #PsppSheetView widget with the model initialized to @model.
8983 * Return value: A newly created #PsppSheetView widget.
8986 pspp_sheet_view_new_with_model (GtkTreeModel *model)
8988 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
8995 * pspp_sheet_view_get_model:
8996 * @tree_view: a #PsppSheetView
8998 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
9001 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
9004 pspp_sheet_view_get_model (PsppSheetView *tree_view)
9006 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9008 return tree_view->priv->model;
9012 * pspp_sheet_view_set_model:
9013 * @tree_view: A #GtkTreeNode.
9014 * @model: (allow-none): The model.
9016 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
9017 * set, it will remove it before setting the new model. If @model is %NULL,
9018 * then it will unset the old model.
9021 pspp_sheet_view_set_model (PsppSheetView *tree_view,
9022 GtkTreeModel *model)
9024 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9025 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
9027 if (model == tree_view->priv->model)
9030 if (tree_view->priv->scroll_to_path)
9032 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9033 tree_view->priv->scroll_to_path = NULL;
9036 if (tree_view->priv->model)
9038 GList *tmplist = tree_view->priv->columns;
9040 if (tree_view->priv->selected)
9041 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
9042 pspp_sheet_view_stop_editing (tree_view, TRUE);
9044 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9045 pspp_sheet_view_row_changed,
9047 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9048 pspp_sheet_view_row_inserted,
9050 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9051 pspp_sheet_view_row_deleted,
9053 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9054 pspp_sheet_view_rows_reordered,
9057 for (; tmplist; tmplist = tmplist->next)
9058 _pspp_sheet_view_column_unset_model (tmplist->data,
9059 tree_view->priv->model);
9061 tree_view->priv->prelight_node = -1;
9063 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
9064 tree_view->priv->drag_dest_row = NULL;
9065 gtk_tree_row_reference_free (tree_view->priv->cursor);
9066 tree_view->priv->cursor = NULL;
9067 gtk_tree_row_reference_free (tree_view->priv->anchor);
9068 tree_view->priv->anchor = NULL;
9069 gtk_tree_row_reference_free (tree_view->priv->top_row);
9070 tree_view->priv->top_row = NULL;
9071 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9072 tree_view->priv->scroll_to_path = NULL;
9074 tree_view->priv->scroll_to_column = NULL;
9076 g_object_unref (tree_view->priv->model);
9078 tree_view->priv->search_column = -1;
9079 tree_view->priv->fixed_height = -1;
9080 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
9081 tree_view->priv->last_button_x = -1;
9082 tree_view->priv->last_button_y = -1;
9085 tree_view->priv->model = model;
9087 if (tree_view->priv->model)
9091 if (tree_view->priv->search_column == -1)
9093 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
9095 GType type = gtk_tree_model_get_column_type (model, i);
9097 if (g_value_type_transformable (type, G_TYPE_STRING))
9099 tree_view->priv->search_column = i;
9105 g_object_ref (tree_view->priv->model);
9106 g_signal_connect (tree_view->priv->model,
9108 G_CALLBACK (pspp_sheet_view_row_changed),
9110 g_signal_connect (tree_view->priv->model,
9112 G_CALLBACK (pspp_sheet_view_row_inserted),
9114 g_signal_connect (tree_view->priv->model,
9116 G_CALLBACK (pspp_sheet_view_row_deleted),
9118 g_signal_connect (tree_view->priv->model,
9120 G_CALLBACK (pspp_sheet_view_rows_reordered),
9123 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
9125 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
9126 install_presize_handler (tree_view);
9129 g_object_notify (G_OBJECT (tree_view), "model");
9131 if (tree_view->priv->selection)
9132 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
9134 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9135 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9139 * pspp_sheet_view_get_selection:
9140 * @tree_view: A #PsppSheetView.
9142 * Gets the #PsppSheetSelection associated with @tree_view.
9144 * Return value: A #PsppSheetSelection object.
9146 PsppSheetSelection *
9147 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
9149 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9151 return tree_view->priv->selection;
9155 * pspp_sheet_view_get_hadjustment:
9156 * @tree_view: A #PsppSheetView
9158 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
9160 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9164 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
9166 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9168 if (tree_view->priv->hadjustment == NULL)
9169 pspp_sheet_view_set_hadjustment (tree_view, NULL);
9171 return tree_view->priv->hadjustment;
9175 * pspp_sheet_view_set_hadjustment:
9176 * @tree_view: A #PsppSheetView
9177 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9179 * Sets the #GtkAdjustment for the current horizontal aspect.
9182 pspp_sheet_view_set_hadjustment (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,
9189 tree_view->priv->vadjustment);
9191 g_object_notify (G_OBJECT (tree_view), "hadjustment");
9195 * pspp_sheet_view_get_vadjustment:
9196 * @tree_view: A #PsppSheetView
9198 * Gets the #GtkAdjustment currently being used for the vertical aspect.
9200 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9204 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
9206 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9208 if (tree_view->priv->vadjustment == NULL)
9209 pspp_sheet_view_set_vadjustment (tree_view, NULL);
9211 return tree_view->priv->vadjustment;
9215 * pspp_sheet_view_set_vadjustment:
9216 * @tree_view: A #PsppSheetView
9217 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9219 * Sets the #GtkAdjustment for the current vertical aspect.
9222 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
9223 GtkAdjustment *adjustment)
9225 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9227 pspp_sheet_view_set_adjustments (tree_view,
9228 tree_view->priv->hadjustment,
9231 g_object_notify (G_OBJECT (tree_view), "vadjustment");
9234 /* Column and header operations */
9237 * pspp_sheet_view_get_headers_visible:
9238 * @tree_view: A #PsppSheetView.
9240 * Returns %TRUE if the headers on the @tree_view are visible.
9242 * Return value: Whether the headers are visible or not.
9245 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
9247 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9249 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9253 * pspp_sheet_view_set_headers_visible:
9254 * @tree_view: A #PsppSheetView.
9255 * @headers_visible: %TRUE if the headers are visible
9257 * Sets the visibility state of the headers.
9260 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
9261 gboolean headers_visible)
9265 PsppSheetViewColumn *column;
9266 GtkAllocation allocation;
9268 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9270 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
9272 headers_visible = !! headers_visible;
9274 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
9277 if (headers_visible)
9278 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9280 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9282 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9284 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
9285 if (headers_visible)
9287 gdk_window_move_resize (tree_view->priv->bin_window, x, y + TREE_VIEW_HEADER_HEIGHT (tree_view),
9288 tree_view->priv->width, allocation.height - + TREE_VIEW_HEADER_HEIGHT (tree_view));
9290 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9291 pspp_sheet_view_map_buttons (tree_view);
9295 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9297 for (list = tree_view->priv->columns; list; list = list->next)
9299 column = list->data;
9301 gtk_widget_unmap (column->button);
9303 gdk_window_hide (tree_view->priv->header_window);
9307 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view));
9308 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, (allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2);
9309 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
9310 gtk_adjustment_set_upper (tree_view->priv->vadjustment, tree_view->priv->height);
9311 gtk_adjustment_changed (tree_view->priv->vadjustment);
9313 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9315 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9319 * pspp_sheet_view_columns_autosize:
9320 * @tree_view: A #PsppSheetView.
9322 * Resizes all columns to their optimal width. Only works after the
9323 * treeview has been realized.
9326 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9328 gboolean dirty = FALSE;
9330 PsppSheetViewColumn *column;
9332 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9334 for (list = tree_view->priv->columns; list; list = list->next)
9336 column = list->data;
9337 _pspp_sheet_view_column_cell_set_dirty (column);
9342 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9346 * pspp_sheet_view_set_headers_clickable:
9347 * @tree_view: A #PsppSheetView.
9348 * @setting: %TRUE if the columns are clickable.
9350 * Allow the column title buttons to be clicked.
9353 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9358 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9360 for (list = tree_view->priv->columns; list; list = list->next)
9361 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9363 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9368 * pspp_sheet_view_get_headers_clickable:
9369 * @tree_view: A #PsppSheetView.
9371 * Returns whether all header columns are clickable.
9373 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9378 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9382 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9384 for (list = tree_view->priv->columns; list; list = list->next)
9385 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9392 * pspp_sheet_view_set_rules_hint
9393 * @tree_view: a #PsppSheetView
9394 * @setting: %TRUE if the tree requires reading across rows
9396 * This function tells GTK+ that the user interface for your
9397 * application requires users to read across tree rows and associate
9398 * cells with one another. By default, GTK+ will then render the tree
9399 * with alternating row colors. Do <emphasis>not</emphasis> use it
9400 * just because you prefer the appearance of the ruled tree; that's a
9401 * question for the theme. Some themes will draw tree rows in
9402 * alternating colors even when rules are turned off, and users who
9403 * prefer that appearance all the time can choose those themes. You
9404 * should call this function only as a <emphasis>semantic</emphasis>
9405 * hint to the theme engine that your tree makes alternating colors
9406 * useful from a functional standpoint (since it has lots of columns,
9411 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9414 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9416 setting = setting != FALSE;
9418 if (tree_view->priv->has_rules != setting)
9420 tree_view->priv->has_rules = setting;
9421 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9424 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9428 * pspp_sheet_view_get_rules_hint
9429 * @tree_view: a #PsppSheetView
9431 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9433 * Return value: %TRUE if rules are useful for the user of this tree
9436 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9438 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9440 return tree_view->priv->has_rules;
9443 /* Public Column functions
9447 * pspp_sheet_view_append_column:
9448 * @tree_view: A #PsppSheetView.
9449 * @column: The #PsppSheetViewColumn to add.
9451 * Appends @column to the list of columns.
9453 * Return value: The number of columns in @tree_view after appending.
9456 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9457 PsppSheetViewColumn *column)
9459 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9460 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9461 g_return_val_if_fail (column->tree_view == NULL, -1);
9463 return pspp_sheet_view_insert_column (tree_view, column, -1);
9468 * pspp_sheet_view_remove_column:
9469 * @tree_view: A #PsppSheetView.
9470 * @column: The #PsppSheetViewColumn to remove.
9472 * Removes @column from @tree_view.
9474 * Return value: The number of columns in @tree_view after removing.
9477 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9478 PsppSheetViewColumn *column)
9480 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9481 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9482 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9484 if (tree_view->priv->focus_column == column)
9485 tree_view->priv->focus_column = NULL;
9487 if (tree_view->priv->edited_column == column)
9489 pspp_sheet_view_stop_editing (tree_view, TRUE);
9491 /* no need to, but just to be sure ... */
9492 tree_view->priv->edited_column = NULL;
9495 _pspp_sheet_view_column_unset_tree_view (column);
9497 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9498 tree_view->priv->n_columns--;
9500 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9504 _pspp_sheet_view_column_unrealize_button (column);
9505 for (list = tree_view->priv->columns; list; list = list->next)
9507 PsppSheetViewColumn *tmp_column;
9509 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9510 if (tmp_column->visible)
9511 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9514 if (tree_view->priv->n_columns == 0 &&
9515 pspp_sheet_view_get_headers_visible (tree_view) &&
9516 tree_view->priv->header_window)
9517 gdk_window_hide (tree_view->priv->header_window);
9519 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9522 g_object_unref (column);
9523 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9525 return tree_view->priv->n_columns;
9529 * pspp_sheet_view_insert_column:
9530 * @tree_view: A #PsppSheetView.
9531 * @column: The #PsppSheetViewColumn to be inserted.
9532 * @position: The position to insert @column in.
9534 * This inserts the @column into the @tree_view at @position. If @position is
9535 * -1, then the column is inserted at the end.
9537 * Return value: The number of columns in @tree_view after insertion.
9540 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9541 PsppSheetViewColumn *column,
9544 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9545 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9546 g_return_val_if_fail (column->tree_view == NULL, -1);
9548 g_object_ref_sink (column);
9550 if (tree_view->priv->n_columns == 0 &&
9551 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9552 pspp_sheet_view_get_headers_visible (tree_view))
9554 gdk_window_show (tree_view->priv->header_window);
9557 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9559 tree_view->priv->n_columns++;
9561 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9563 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9567 _pspp_sheet_view_column_realize_button (column);
9569 for (list = tree_view->priv->columns; list; list = list->next)
9571 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9572 if (column->visible)
9573 _pspp_sheet_view_column_cell_set_dirty (column);
9575 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9578 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9580 return tree_view->priv->n_columns;
9584 * pspp_sheet_view_insert_column_with_attributes:
9585 * @tree_view: A #PsppSheetView
9586 * @position: The position to insert the new column in.
9587 * @title: The title to set the header to.
9588 * @cell: The #GtkCellRenderer.
9589 * @Varargs: A %NULL-terminated list of attributes.
9591 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9592 * @position. If @position is -1, then the newly created column is inserted at
9593 * the end. The column is initialized with the attributes given.
9595 * Return value: The number of columns in @tree_view after insertion.
9598 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9601 GtkCellRenderer *cell,
9604 PsppSheetViewColumn *column;
9609 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9611 column = pspp_sheet_view_column_new ();
9612 pspp_sheet_view_column_set_title (column, title);
9613 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9615 va_start (args, cell);
9617 attribute = va_arg (args, gchar *);
9619 while (attribute != NULL)
9621 column_id = va_arg (args, gint);
9622 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9623 attribute = va_arg (args, gchar *);
9628 pspp_sheet_view_insert_column (tree_view, column, position);
9630 return tree_view->priv->n_columns;
9634 * pspp_sheet_view_insert_column_with_data_func:
9635 * @tree_view: a #PsppSheetView
9636 * @position: Position to insert, -1 for append
9637 * @title: column title
9638 * @cell: cell renderer for column
9639 * @func: function to set attributes of cell renderer
9640 * @data: data for @func
9641 * @dnotify: destroy notifier for @data
9643 * Convenience function that inserts a new column into the #PsppSheetView
9644 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9645 * attributes (normally using data from the model). See also
9646 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9648 * Return value: number of columns in the tree view post-insert
9651 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9654 GtkCellRenderer *cell,
9655 PsppSheetCellDataFunc func,
9657 GDestroyNotify dnotify)
9659 PsppSheetViewColumn *column;
9661 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9663 column = pspp_sheet_view_column_new ();
9664 pspp_sheet_view_column_set_title (column, title);
9665 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9666 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9668 pspp_sheet_view_insert_column (tree_view, column, position);
9670 return tree_view->priv->n_columns;
9674 * pspp_sheet_view_get_column:
9675 * @tree_view: A #PsppSheetView.
9676 * @n: The position of the column, counting from 0.
9678 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9680 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9683 PsppSheetViewColumn *
9684 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9687 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9689 if (n < 0 || n >= tree_view->priv->n_columns)
9692 if (tree_view->priv->columns == NULL)
9695 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9699 * pspp_sheet_view_get_columns:
9700 * @tree_view: A #PsppSheetView
9702 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9703 * The returned list must be freed with g_list_free ().
9705 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9708 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9710 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9712 return g_list_copy (tree_view->priv->columns);
9716 * pspp_sheet_view_move_column_after:
9717 * @tree_view: A #PsppSheetView
9718 * @column: The #PsppSheetViewColumn to be moved.
9719 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9721 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9722 * @column is placed in the first position.
9725 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9726 PsppSheetViewColumn *column,
9727 PsppSheetViewColumn *base_column)
9729 GList *column_list_el, *base_el = NULL;
9731 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9733 column_list_el = g_list_find (tree_view->priv->columns, column);
9734 g_return_if_fail (column_list_el != NULL);
9738 base_el = g_list_find (tree_view->priv->columns, base_column);
9739 g_return_if_fail (base_el != NULL);
9742 if (column_list_el->prev == base_el)
9745 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9746 if (base_el == NULL)
9748 column_list_el->prev = NULL;
9749 column_list_el->next = tree_view->priv->columns;
9750 if (column_list_el->next)
9751 column_list_el->next->prev = column_list_el;
9752 tree_view->priv->columns = column_list_el;
9756 column_list_el->prev = base_el;
9757 column_list_el->next = base_el->next;
9758 if (column_list_el->next)
9759 column_list_el->next->prev = column_list_el;
9760 base_el->next = column_list_el;
9763 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9765 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9766 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9769 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9773 * pspp_sheet_view_set_column_drag_function:
9774 * @tree_view: A #PsppSheetView.
9775 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9776 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9777 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9779 * Sets a user function for determining where a column may be dropped when
9780 * dragged. This function is called on every column pair in turn at the
9781 * beginning of a column drag to determine where a drop can take place. The
9782 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9783 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9784 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9785 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9786 * @tree_view reverts to the default behavior of allowing all columns to be
9787 * dropped everywhere.
9790 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9791 PsppSheetViewColumnDropFunc func,
9793 GDestroyNotify destroy)
9795 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9797 if (tree_view->priv->column_drop_func_data_destroy)
9798 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9800 tree_view->priv->column_drop_func = func;
9801 tree_view->priv->column_drop_func_data = user_data;
9802 tree_view->priv->column_drop_func_data_destroy = destroy;
9806 * pspp_sheet_view_scroll_to_point:
9807 * @tree_view: a #PsppSheetView
9808 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9809 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9811 * Scrolls the tree view such that the top-left corner of the visible
9812 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9813 * in tree coordinates. The @tree_view must be realized before
9814 * this function is called. If it isn't, you probably want to be
9815 * using pspp_sheet_view_scroll_to_cell().
9817 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9820 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9824 GtkAdjustment *hadj;
9825 GtkAdjustment *vadj;
9827 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9828 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9830 hadj = tree_view->priv->hadjustment;
9831 vadj = tree_view->priv->vadjustment;
9834 gtk_adjustment_set_value (hadj, CLAMP (tree_x, gtk_adjustment_get_lower (hadj), gtk_adjustment_get_upper (hadj) - gtk_adjustment_get_page_size (hadj)));
9836 gtk_adjustment_set_value (vadj, CLAMP (tree_y, gtk_adjustment_get_lower (vadj), gtk_adjustment_get_upper (vadj) - gtk_adjustment_get_page_size (vadj)));
9840 * pspp_sheet_view_scroll_to_cell:
9841 * @tree_view: A #PsppSheetView.
9842 * @path: (allow-none): The path of the row to move to, or %NULL.
9843 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9844 * @use_align: whether to use alignment arguments, or %FALSE.
9845 * @row_align: The vertical alignment of the row specified by @path.
9846 * @col_align: The horizontal alignment of the column specified by @column.
9848 * Moves the alignments of @tree_view to the position specified by @column and
9849 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9850 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9851 * or @path need to be non-%NULL. @row_align determines where the row is
9852 * placed, and @col_align determines where @column is placed. Both are expected
9853 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9854 * right/bottom alignment, 0.5 means center.
9856 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9857 * tree does the minimum amount of work to scroll the cell onto the screen.
9858 * This means that the cell will be scrolled to the edge closest to its current
9859 * position. If the cell is currently visible on the screen, nothing is done.
9861 * This function only works if the model is set, and @path is a valid row on the
9862 * model. If the model changes before the @tree_view is realized, the centered
9863 * path will be modified to reflect this change.
9866 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9868 PsppSheetViewColumn *column,
9873 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9874 g_return_if_fail (tree_view->priv->model != NULL);
9875 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9876 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9877 g_return_if_fail (path != NULL || column != NULL);
9880 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9881 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9883 row_align = CLAMP (row_align, 0.0, 1.0);
9884 col_align = CLAMP (col_align, 0.0, 1.0);
9887 /* Note: Despite the benefits that come from having one code path for the
9888 * scrolling code, we short-circuit validate_visible_area's immplementation as
9889 * it is much slower than just going to the point.
9891 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9892 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9893 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9895 if (tree_view->priv->scroll_to_path)
9896 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9898 tree_view->priv->scroll_to_path = NULL;
9899 tree_view->priv->scroll_to_column = NULL;
9902 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9904 tree_view->priv->scroll_to_column = column;
9905 tree_view->priv->scroll_to_use_align = use_align;
9906 tree_view->priv->scroll_to_row_align = row_align;
9907 tree_view->priv->scroll_to_col_align = col_align;
9909 install_presize_handler (tree_view);
9913 GdkRectangle cell_rect;
9914 GdkRectangle vis_rect;
9915 gint dest_x, dest_y;
9917 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9918 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9920 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9922 dest_x = vis_rect.x;
9923 dest_y = vis_rect.y;
9929 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9933 if (cell_rect.x < vis_rect.x)
9934 dest_x = cell_rect.x;
9935 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9936 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9944 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9945 dest_y = MAX (dest_y, 0);
9949 if (cell_rect.y < vis_rect.y)
9950 dest_y = cell_rect.y;
9951 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9952 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9956 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9961 * pspp_sheet_view_row_activated:
9962 * @tree_view: A #PsppSheetView
9963 * @path: The #GtkTreePath to be activated.
9964 * @column: The #PsppSheetViewColumn to be activated.
9966 * Activates the cell determined by @path and @column.
9969 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9971 PsppSheetViewColumn *column)
9973 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9975 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
9980 * pspp_sheet_view_get_reorderable:
9981 * @tree_view: a #PsppSheetView
9983 * Retrieves whether the user can reorder the tree via drag-and-drop. See
9984 * pspp_sheet_view_set_reorderable().
9986 * Return value: %TRUE if the tree can be reordered.
9989 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
9991 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9993 return tree_view->priv->reorderable;
9997 * pspp_sheet_view_set_reorderable:
9998 * @tree_view: A #PsppSheetView.
9999 * @reorderable: %TRUE, if the tree can be reordered.
10001 * This function is a convenience function to allow you to reorder
10002 * models that support the #GtkDragSourceIface and the
10003 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
10004 * these. If @reorderable is %TRUE, then the user can reorder the
10005 * model by dragging and dropping rows. The developer can listen to
10006 * these changes by connecting to the model's row_inserted and
10007 * row_deleted signals. The reordering is implemented by setting up
10008 * the tree view as a drag source and destination. Therefore, drag and
10009 * drop can not be used in a reorderable view for any other purpose.
10011 * This function does not give you any degree of control over the order -- any
10012 * reordering is allowed. If more control is needed, you should probably
10013 * handle drag and drop manually.
10016 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
10017 gboolean reorderable)
10019 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10021 reorderable = reorderable != FALSE;
10023 if (tree_view->priv->reorderable == reorderable)
10028 const GtkTargetEntry row_targets[] = {
10029 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
10032 pspp_sheet_view_enable_model_drag_source (tree_view,
10035 G_N_ELEMENTS (row_targets),
10037 pspp_sheet_view_enable_model_drag_dest (tree_view,
10039 G_N_ELEMENTS (row_targets),
10044 pspp_sheet_view_unset_rows_drag_source (tree_view);
10045 pspp_sheet_view_unset_rows_drag_dest (tree_view);
10048 tree_view->priv->reorderable = reorderable;
10050 g_object_notify (G_OBJECT (tree_view), "reorderable");
10053 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
10054 is pressed, other rows will be unselected.
10056 If CLAMP_NODE is true, then the sheetview will scroll to make the row
10059 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
10061 gboolean clear_and_select,
10062 gboolean clamp_node,
10063 PsppSheetSelectMode mode)
10067 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10069 GtkTreePath *cursor_path;
10070 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10071 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
10072 gtk_tree_path_free (cursor_path);
10075 gtk_tree_row_reference_free (tree_view->priv->cursor);
10076 tree_view->priv->cursor = NULL;
10078 _pspp_sheet_view_find_node (tree_view, path, &node);
10079 tree_view->priv->cursor =
10080 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
10081 tree_view->priv->model,
10084 if (tree_view->priv->row_count > 0)
10088 if (clear_and_select && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
10089 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
10093 /* We have to re-find tree and node here again, somebody might have
10094 * cleared the node or the whole tree in the PsppSheetSelection::changed
10095 * callback. If the nodes differ we bail out here.
10097 _pspp_sheet_view_find_node (tree_view, path, &new_node);
10099 if (node != new_node)
10104 pspp_sheet_view_clamp_node_visible (tree_view, node);
10105 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10109 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
10113 * pspp_sheet_view_get_cursor:
10114 * @tree_view: A #PsppSheetView
10115 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
10116 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
10118 * Fills in @path and @focus_column with the current path and focus column. If
10119 * the cursor isn't currently set, then *@path will be %NULL. If no column
10120 * currently has focus, then *@focus_column will be %NULL.
10122 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
10123 * you are done with it.
10126 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
10127 GtkTreePath **path,
10128 PsppSheetViewColumn **focus_column)
10130 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10134 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10135 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10142 *focus_column = tree_view->priv->focus_column;
10147 * pspp_sheet_view_set_cursor:
10148 * @tree_view: A #PsppSheetView
10149 * @path: A #GtkTreePath
10150 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10151 * @start_editing: %TRUE if the specified cell should start being edited.
10153 * Sets the current keyboard focus to be at @path, and selects it. This is
10154 * useful when you want to focus the user's attention on a particular row. If
10155 * @focus_column is not %NULL, then focus is given to the column specified by
10156 * it. Additionally, if @focus_column is specified, and @start_editing is
10157 * %TRUE, then editing should be started in the specified cell.
10158 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
10159 * in order to give keyboard focus to the widget. Please note that editing
10160 * can only happen when the widget is realized.
10162 * If @path is invalid for @model, the current cursor (if any) will be unset
10163 * and the function will return without failing.
10166 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
10168 PsppSheetViewColumn *focus_column,
10169 gboolean start_editing)
10171 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
10172 NULL, start_editing);
10176 * pspp_sheet_view_set_cursor_on_cell:
10177 * @tree_view: A #PsppSheetView
10178 * @path: A #GtkTreePath
10179 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10180 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
10181 * @start_editing: %TRUE if the specified cell should start being edited.
10183 * Sets the current keyboard focus to be at @path, and selects it. This is
10184 * useful when you want to focus the user's attention on a particular row. If
10185 * @focus_column is not %NULL, then focus is given to the column specified by
10186 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
10187 * contains 2 or more editable or activatable cells, then focus is given to
10188 * the cell specified by @focus_cell. Additionally, if @focus_column is
10189 * specified, and @start_editing is %TRUE, then editing should be started in
10190 * the specified cell. This function is often followed by
10191 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
10192 * widget. Please note that editing can only happen when the widget is
10195 * If @path is invalid for @model, the current cursor (if any) will be unset
10196 * and the function will return without failing.
10201 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
10203 PsppSheetViewColumn *focus_column,
10204 GtkCellRenderer *focus_cell,
10205 gboolean start_editing)
10207 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10208 g_return_if_fail (path != NULL);
10209 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
10211 if (!tree_view->priv->model)
10216 g_return_if_fail (focus_column);
10217 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
10220 /* cancel the current editing, if it exists */
10221 if (tree_view->priv->edited_column &&
10222 tree_view->priv->edited_column->editable_widget)
10223 pspp_sheet_view_stop_editing (tree_view, TRUE);
10225 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
10227 if (focus_column && focus_column->visible)
10230 gboolean column_in_tree = FALSE;
10232 for (list = tree_view->priv->columns; list; list = list->next)
10233 if (list->data == focus_column)
10235 column_in_tree = TRUE;
10238 g_return_if_fail (column_in_tree);
10239 tree_view->priv->focus_column = focus_column;
10241 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
10243 pspp_sheet_view_start_editing (tree_view, path);
10245 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
10246 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
10252 * pspp_sheet_view_get_bin_window:
10253 * @tree_view: A #PsppSheetView
10255 * Returns the window that @tree_view renders to. This is used primarily to
10256 * compare to <literal>event->window</literal> to confirm that the event on
10257 * @tree_view is on the right window.
10259 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
10262 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
10264 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
10266 return tree_view->priv->bin_window;
10270 * pspp_sheet_view_get_path_at_pos:
10271 * @tree_view: A #PsppSheetView.
10272 * @x: The x position to be identified (relative to bin_window).
10273 * @y: The y position to be identified (relative to bin_window).
10274 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
10275 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
10276 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
10277 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
10279 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10280 * (please see pspp_sheet_view_get_bin_window()).
10281 * That is, @x and @y are relative to an events coordinates. @x and @y must
10282 * come from an event on the @tree_view only where <literal>event->window ==
10283 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10284 * things like popup menus. If @path is non-%NULL, then it will be filled
10285 * with the #GtkTreePath at that point. This path should be freed with
10286 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10287 * with the column at that point. @cell_x and @cell_y return the coordinates
10288 * relative to the cell background (i.e. the @background_area passed to
10289 * gtk_cell_renderer_render()). This function is only meaningful if
10290 * @tree_view is realized. Therefore this function will always return %FALSE
10291 * if @tree_view is not realized or does not have a model.
10293 * For converting widget coordinates (eg. the ones you get from
10294 * GtkWidget::query-tooltip), please see
10295 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10297 * Return value: %TRUE if a row exists at that coordinate.
10300 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10303 GtkTreePath **path,
10304 PsppSheetViewColumn **column,
10311 g_return_val_if_fail (tree_view != NULL, FALSE);
10318 if (tree_view->priv->bin_window == NULL)
10321 if (tree_view->priv->row_count == 0)
10324 if (x > gtk_adjustment_get_upper (tree_view->priv->hadjustment))
10327 if (x < 0 || y < 0)
10330 if (column || cell_x)
10332 PsppSheetViewColumn *tmp_column;
10333 PsppSheetViewColumn *last_column = NULL;
10335 gint remaining_x = x;
10336 gboolean found = FALSE;
10339 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10340 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10342 list = (rtl ? list->prev : list->next))
10344 tmp_column = list->data;
10346 if (tmp_column->visible == FALSE)
10349 last_column = tmp_column;
10350 if (remaining_x <= tmp_column->width)
10355 *column = tmp_column;
10358 *cell_x = remaining_x;
10362 remaining_x -= tmp_column->width;
10365 /* If found is FALSE and there is a last_column, then it the remainder
10366 * space is in that area
10373 *column = last_column;
10376 *cell_x = last_column->width + remaining_x;
10385 y_offset = pspp_sheet_view_find_offset (tree_view,
10386 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10393 *cell_y = y_offset;
10396 *path = _pspp_sheet_view_find_path (tree_view, node);
10401 /* Computes 'cell_area' from 'background_area', which must be the background
10402 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10403 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10404 the cell area as passed to _pspp_sheet_view_column_cell_render().
10406 'column' is required to properly adjust 'cell_area->x' and
10407 'cell_area->width'. It may be set to NULL if these values are not of
10408 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10411 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10412 PsppSheetViewColumn *column,
10413 const GdkRectangle *background_area,
10414 gboolean subtract_focus_rect,
10415 GdkRectangle *cell_area)
10417 gint vertical_separator;
10418 gint horizontal_separator;
10420 *cell_area = *background_area;
10422 gtk_widget_style_get (GTK_WIDGET (tree_view),
10423 "vertical-separator", &vertical_separator,
10424 "horizontal-separator", &horizontal_separator,
10426 cell_area->x += horizontal_separator / 2;
10427 cell_area->y += vertical_separator / 2;
10428 cell_area->width -= horizontal_separator;
10429 cell_area->height -= vertical_separator;
10431 if (subtract_focus_rect)
10433 int focus_line_width;
10435 gtk_widget_style_get (GTK_WIDGET (tree_view),
10436 "focus-line-width", &focus_line_width,
10438 cell_area->x += focus_line_width;
10439 cell_area->y += focus_line_width;
10440 cell_area->width -= 2 * focus_line_width;
10441 cell_area->height -= 2 * focus_line_width;
10444 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10446 gint grid_line_width;
10447 gtk_widget_style_get (GTK_WIDGET (tree_view),
10448 "grid-line-width", &grid_line_width,
10451 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10452 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10455 PsppSheetViewColumn *first_column, *last_column;
10458 /* Find the last visible column. */
10459 last_column = NULL;
10460 for (list = g_list_last (tree_view->priv->columns);
10464 PsppSheetViewColumn *c = list->data;
10472 /* Find the first visible column. */
10473 first_column = NULL;
10474 for (list = g_list_first (tree_view->priv->columns);
10478 PsppSheetViewColumn *c = list->data;
10486 if (column == first_column)
10488 cell_area->width -= grid_line_width / 2;
10490 else if (column == last_column)
10492 cell_area->x += grid_line_width / 2;
10493 cell_area->width -= grid_line_width / 2;
10497 cell_area->x += grid_line_width / 2;
10498 cell_area->width -= grid_line_width;
10502 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10503 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10505 cell_area->y += grid_line_width / 2;
10506 cell_area->height -= grid_line_width;
10510 if (column == NULL)
10513 cell_area->width = 0;
10518 * pspp_sheet_view_get_cell_area:
10519 * @tree_view: a #PsppSheetView
10520 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10521 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10522 * @rect: rectangle to fill with cell rect
10524 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10525 * row specified by @path and the column specified by @column. If @path is
10526 * %NULL, or points to a path not currently displayed, the @y and @height fields
10527 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10528 * fields will be filled with 0. The sum of all cell rects does not cover the
10529 * entire tree; there are extra pixels in between rows, for example. The
10530 * returned rectangle is equivalent to the @cell_area passed to
10531 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10535 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10537 PsppSheetViewColumn *column,
10538 GdkRectangle *rect)
10540 GdkRectangle background_area;
10542 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10543 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10544 g_return_if_fail (rect != NULL);
10545 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10546 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10548 pspp_sheet_view_get_background_area (tree_view, path, column,
10550 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10555 * pspp_sheet_view_get_background_area:
10556 * @tree_view: a #PsppSheetView
10557 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10558 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10559 * @rect: rectangle to fill with cell background rect
10561 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10562 * row specified by @path and the column specified by @column. If @path is
10563 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10564 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10565 * fields will be filled with 0. The returned rectangle is equivalent to the
10566 * @background_area passed to gtk_cell_renderer_render(). These background
10567 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10568 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10569 * itself, excluding surrounding borders.
10573 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10575 PsppSheetViewColumn *column,
10576 GdkRectangle *rect)
10580 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10581 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10582 g_return_if_fail (rect != NULL);
10591 /* Get vertical coords */
10593 _pspp_sheet_view_find_node (tree_view, path, &node);
10597 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10599 rect->height = ROW_HEIGHT (tree_view);
10606 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10607 rect->width = x2 - rect->x;
10612 * pspp_sheet_view_get_visible_rect:
10613 * @tree_view: a #PsppSheetView
10614 * @visible_rect: rectangle to fill
10616 * Fills @visible_rect with the currently-visible region of the
10617 * buffer, in tree coordinates. Convert to bin_window coordinates with
10618 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10619 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10620 * scrollable area of the tree.
10623 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10624 GdkRectangle *visible_rect)
10628 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10630 widget = GTK_WIDGET (tree_view);
10634 GtkAllocation allocation;
10635 gtk_widget_get_allocation (widget, &allocation);
10636 visible_rect->x = gtk_adjustment_get_value (tree_view->priv->hadjustment);
10637 visible_rect->y = gtk_adjustment_get_value (tree_view->priv->vadjustment);
10638 visible_rect->width = allocation.width;
10639 visible_rect->height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10644 * pspp_sheet_view_widget_to_tree_coords:
10645 * @tree_view: a #PsppSheetView
10646 * @wx: X coordinate relative to bin_window
10647 * @wy: Y coordinate relative to bin_window
10648 * @tx: return location for tree X coordinate
10649 * @ty: return location for tree Y coordinate
10651 * Converts bin_window coordinates to coordinates for the
10652 * tree (the full scrollable area of the tree).
10654 * Deprecated: 2.12: Due to historial reasons the name of this function is
10655 * incorrect. For converting coordinates relative to the widget to
10656 * bin_window coordinates, please see
10657 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10661 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10667 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10670 *tx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10672 *ty = wy + tree_view->priv->dy;
10676 * pspp_sheet_view_tree_to_widget_coords:
10677 * @tree_view: a #PsppSheetView
10678 * @tx: tree X coordinate
10679 * @ty: tree Y coordinate
10680 * @wx: return location for X coordinate relative to bin_window
10681 * @wy: return location for Y coordinate relative to bin_window
10683 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10684 * to bin_window coordinates.
10686 * Deprecated: 2.12: Due to historial reasons the name of this function is
10687 * incorrect. For converting bin_window coordinates to coordinates relative
10688 * to bin_window, please see
10689 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10693 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10699 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10702 *wx = tx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10704 *wy = ty - tree_view->priv->dy;
10709 * pspp_sheet_view_convert_widget_to_tree_coords:
10710 * @tree_view: a #PsppSheetView
10711 * @wx: X coordinate relative to the widget
10712 * @wy: Y coordinate relative to the widget
10713 * @tx: return location for tree X coordinate
10714 * @ty: return location for tree Y coordinate
10716 * Converts widget coordinates to coordinates for the
10717 * tree (the full scrollable area of the tree).
10722 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10730 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10732 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10735 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10741 * pspp_sheet_view_convert_tree_to_widget_coords:
10742 * @tree_view: a #PsppSheetView
10743 * @tx: X coordinate relative to the tree
10744 * @ty: Y coordinate relative to the tree
10745 * @wx: return location for widget X coordinate
10746 * @wy: return location for widget Y coordinate
10748 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10749 * to widget coordinates.
10754 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10762 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10764 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10767 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10773 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10774 * @tree_view: a #PsppSheetView
10775 * @wx: X coordinate relative to the widget
10776 * @wy: Y coordinate relative to the widget
10777 * @bx: return location for bin_window X coordinate
10778 * @by: return location for bin_window Y coordinate
10780 * Converts widget coordinates to coordinates for the bin_window
10781 * (see pspp_sheet_view_get_bin_window()).
10786 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10792 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10795 *bx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10797 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10801 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10802 * @tree_view: a #PsppSheetView
10803 * @bx: bin_window X coordinate
10804 * @by: bin_window Y coordinate
10805 * @wx: return location for widget X coordinate
10806 * @wy: return location for widget Y coordinate
10808 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10809 * to widget relative coordinates.
10814 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10820 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10823 *wx = bx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10825 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10829 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10830 * @tree_view: a #PsppSheetView
10831 * @tx: tree X coordinate
10832 * @ty: tree Y coordinate
10833 * @bx: return location for X coordinate relative to bin_window
10834 * @by: return location for Y coordinate relative to bin_window
10836 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10837 * to bin_window coordinates.
10842 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10848 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10853 *by = ty - tree_view->priv->dy;
10857 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10858 * @tree_view: a #PsppSheetView
10859 * @bx: X coordinate relative to bin_window
10860 * @by: Y coordinate relative to bin_window
10861 * @tx: return location for tree X coordinate
10862 * @ty: return location for tree Y coordinate
10864 * Converts bin_window coordinates to coordinates for the
10865 * tree (the full scrollable area of the tree).
10870 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10876 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10881 *ty = by + tree_view->priv->dy;
10887 * pspp_sheet_view_get_visible_range:
10888 * @tree_view: A #PsppSheetView
10889 * @start_path: (allow-none): Return location for start of region, or %NULL.
10890 * @end_path: (allow-none): Return location for end of region, or %NULL.
10892 * Sets @start_path and @end_path to be the first and last visible path.
10893 * Note that there may be invisible paths in between.
10895 * The paths should be freed with gtk_tree_path_free() after use.
10897 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10902 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10903 GtkTreePath **start_path,
10904 GtkTreePath **end_path)
10909 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10911 if (!tree_view->priv->row_count)
10918 pspp_sheet_view_find_offset (tree_view,
10919 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10922 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10931 if (tree_view->priv->height < gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
10932 y = tree_view->priv->height - 1;
10934 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, gtk_adjustment_get_page_size (tree_view->priv->vadjustment)) - 1;
10936 pspp_sheet_view_find_offset (tree_view, y, &node);
10938 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10947 unset_reorderable (PsppSheetView *tree_view)
10949 if (tree_view->priv->reorderable)
10951 tree_view->priv->reorderable = FALSE;
10952 g_object_notify (G_OBJECT (tree_view), "reorderable");
10957 * pspp_sheet_view_enable_model_drag_source:
10958 * @tree_view: a #PsppSheetView
10959 * @start_button_mask: Mask of allowed buttons to start drag
10960 * @targets: the table of targets that the drag will support
10961 * @n_targets: the number of items in @targets
10962 * @actions: the bitmask of possible actions for a drag from this
10965 * Turns @tree_view into a drag source for automatic DND. Calling this
10966 * method sets #PsppSheetView:reorderable to %FALSE.
10969 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10970 GdkModifierType start_button_mask,
10971 const GtkTargetEntry *targets,
10973 GdkDragAction actions)
10975 TreeViewDragInfo *di;
10977 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10979 gtk_drag_source_set (GTK_WIDGET (tree_view),
10985 di = ensure_info (tree_view);
10987 di->start_button_mask = start_button_mask;
10988 di->source_actions = actions;
10989 di->source_set = TRUE;
10991 unset_reorderable (tree_view);
10995 * pspp_sheet_view_enable_model_drag_dest:
10996 * @tree_view: a #PsppSheetView
10997 * @targets: the table of targets that the drag will support
10998 * @n_targets: the number of items in @targets
10999 * @actions: the bitmask of possible actions for a drag from this
11002 * Turns @tree_view into a drop destination for automatic DND. Calling
11003 * this method sets #PsppSheetView:reorderable to %FALSE.
11006 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
11007 const GtkTargetEntry *targets,
11009 GdkDragAction actions)
11011 TreeViewDragInfo *di;
11013 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11015 gtk_drag_dest_set (GTK_WIDGET (tree_view),
11021 di = ensure_info (tree_view);
11022 di->dest_set = TRUE;
11024 unset_reorderable (tree_view);
11028 * pspp_sheet_view_unset_rows_drag_source:
11029 * @tree_view: a #PsppSheetView
11031 * Undoes the effect of
11032 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
11033 * #PsppSheetView:reorderable to %FALSE.
11036 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
11038 TreeViewDragInfo *di;
11040 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11042 di = get_info (tree_view);
11046 if (di->source_set)
11048 gtk_drag_source_unset (GTK_WIDGET (tree_view));
11049 di->source_set = FALSE;
11052 if (!di->dest_set && !di->source_set)
11053 remove_info (tree_view);
11056 unset_reorderable (tree_view);
11060 * pspp_sheet_view_unset_rows_drag_dest:
11061 * @tree_view: a #PsppSheetView
11063 * Undoes the effect of
11064 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
11065 * #PsppSheetView:reorderable to %FALSE.
11068 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
11070 TreeViewDragInfo *di;
11072 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11074 di = get_info (tree_view);
11080 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
11081 di->dest_set = FALSE;
11084 if (!di->dest_set && !di->source_set)
11085 remove_info (tree_view);
11088 unset_reorderable (tree_view);
11092 * pspp_sheet_view_set_drag_dest_row:
11093 * @tree_view: a #PsppSheetView
11094 * @path: (allow-none): The path of the row to highlight, or %NULL.
11095 * @pos: Specifies whether to drop before, after or into the row
11097 * Sets the row that is highlighted for feedback.
11100 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
11102 PsppSheetViewDropPosition pos)
11104 GtkTreePath *current_dest;
11106 /* Note; this function is exported to allow a custom DND
11107 * implementation, so it can't touch TreeViewDragInfo
11110 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11112 current_dest = NULL;
11114 if (tree_view->priv->drag_dest_row)
11116 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11117 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
11120 /* special case a drop on an empty model */
11121 tree_view->priv->empty_view_drop = 0;
11123 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
11124 && gtk_tree_path_get_depth (path) == 1
11125 && gtk_tree_path_get_indices (path)[0] == 0)
11129 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
11133 tree_view->priv->empty_view_drop = 1;
11136 tree_view->priv->drag_dest_pos = pos;
11140 tree_view->priv->drag_dest_row =
11141 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
11142 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
11145 tree_view->priv->drag_dest_row = NULL;
11149 int node, new_node;
11151 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
11152 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
11156 new_node = pspp_sheet_view_node_next (tree_view, node);
11158 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11160 new_node = pspp_sheet_view_node_prev (tree_view, node);
11162 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11164 gtk_tree_path_free (current_dest);
11169 * pspp_sheet_view_get_drag_dest_row:
11170 * @tree_view: a #PsppSheetView
11171 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11172 * @pos: (allow-none): Return location for the drop position, or %NULL
11174 * Gets information about the row that is highlighted for feedback.
11177 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
11178 GtkTreePath **path,
11179 PsppSheetViewDropPosition *pos)
11181 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11185 if (tree_view->priv->drag_dest_row)
11186 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11189 if (tree_view->priv->empty_view_drop)
11190 *path = gtk_tree_path_new_from_indices (0, -1);
11197 *pos = tree_view->priv->drag_dest_pos;
11201 * pspp_sheet_view_get_dest_row_at_pos:
11202 * @tree_view: a #PsppSheetView
11203 * @drag_x: the position to determine the destination row for
11204 * @drag_y: the position to determine the destination row for
11205 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11206 * @pos: (allow-none): Return location for the drop position, or %NULL
11208 * Determines the destination row for a given position. @drag_x and
11209 * @drag_y are expected to be in widget coordinates. This function is only
11210 * meaningful if @tree_view is realized. Therefore this function will always
11211 * return %FALSE if @tree_view is not realized or does not have a model.
11213 * Return value: whether there is a row at the given position, %TRUE if this
11214 * is indeed the case.
11217 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
11220 GtkTreePath **path,
11221 PsppSheetViewDropPosition *pos)
11225 gdouble offset_into_row;
11228 PsppSheetViewColumn *column = NULL;
11229 GtkTreePath *tmp_path = NULL;
11231 /* Note; this function is exported to allow a custom DND
11232 * implementation, so it can't touch TreeViewDragInfo
11235 g_return_val_if_fail (tree_view != NULL, FALSE);
11236 g_return_val_if_fail (drag_x >= 0, FALSE);
11237 g_return_val_if_fail (drag_y >= 0, FALSE);
11242 if (tree_view->priv->bin_window == NULL)
11245 if (tree_view->priv->row_count == 0)
11248 /* If in the top third of a row, we drop before that row; if
11249 * in the bottom third, drop after that row; if in the middle,
11250 * and the row has children, drop into the row.
11252 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
11255 if (!pspp_sheet_view_get_path_at_pos (tree_view,
11264 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
11267 offset_into_row = cell_y;
11272 gtk_tree_path_free (tmp_path);
11276 third = cell.height / 3.0;
11280 if (offset_into_row < third)
11282 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11284 else if (offset_into_row < (cell.height / 2.0))
11286 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11288 else if (offset_into_row < third * 2.0)
11290 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11294 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11303 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11305 * pspp_sheet_view_create_row_drag_icon:
11306 * @tree_view: a #PsppSheetView
11307 * @path: a #GtkTreePath in @tree_view
11309 * Creates a #GdkPixmap representation of the row at @path.
11310 * This image is used for a drag icon.
11312 * Return value: a newly-allocated pixmap of the drag icon.
11315 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11322 GdkRectangle background_area;
11323 GdkRectangle expose_area;
11325 /* start drawing inside the black outline */
11327 GdkDrawable *drawable;
11328 gint bin_window_width;
11331 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11332 g_return_val_if_fail (path != NULL, NULL);
11334 widget = GTK_WIDGET (tree_view);
11336 if (!gtk_widget_get_realized (widget))
11339 _pspp_sheet_view_find_node (tree_view,
11346 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11353 background_area.y = y;
11354 background_area.height = ROW_HEIGHT (tree_view);
11356 bin_window_width = gdk_window_get_width (tree_view->priv->bin_window);
11358 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11359 bin_window_width + 2,
11360 background_area.height + 2,
11365 expose_area.width = bin_window_width + 2;
11366 expose_area.height = background_area.height + 2;
11368 #if GTK3_TRANSITION
11369 gdk_draw_rectangle (drawable,
11370 widget->style->base_gc [gtk_widget_get_state (widget)],
11373 bin_window_width + 2,
11374 background_area.height + 2);
11377 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11379 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11381 list = (rtl ? list->prev : list->next))
11383 PsppSheetViewColumn *column = list->data;
11384 GdkRectangle cell_area;
11385 gint vertical_separator;
11387 if (!column->visible)
11390 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11392 background_area.x = cell_offset;
11393 background_area.width = column->width;
11395 gtk_widget_style_get (widget,
11396 "vertical-separator", &vertical_separator,
11399 cell_area = background_area;
11401 cell_area.y += vertical_separator / 2;
11402 cell_area.height -= vertical_separator;
11404 if (pspp_sheet_view_column_cell_is_visible (column))
11405 _pspp_sheet_view_column_cell_render (column,
11411 cell_offset += column->width;
11414 #if GTK3_TRANSITION
11415 gdk_draw_rectangle (drawable,
11416 widget->style->black_gc,
11419 bin_window_width + 1,
11420 background_area.height + 1);
11428 * pspp_sheet_view_set_destroy_count_func:
11429 * @tree_view: A #PsppSheetView
11430 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11431 * @data: (allow-none): User data to be passed to @func, or %NULL
11432 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11434 * This function should almost never be used. It is meant for private use by
11435 * ATK for determining the number of visible children that are removed when a row is deleted.
11438 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11439 PsppSheetDestroyCountFunc func,
11441 GDestroyNotify destroy)
11443 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11445 if (tree_view->priv->destroy_count_destroy)
11446 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11448 tree_view->priv->destroy_count_func = func;
11449 tree_view->priv->destroy_count_data = data;
11450 tree_view->priv->destroy_count_destroy = destroy;
11455 * Interactive search
11459 * pspp_sheet_view_set_enable_search:
11460 * @tree_view: A #PsppSheetView
11461 * @enable_search: %TRUE, if the user can search interactively
11463 * If @enable_search is set, then the user can type in text to search through
11464 * the tree interactively (this is sometimes called "typeahead find").
11466 * Note that even if this is %FALSE, the user can still initiate a search
11467 * using the "start-interactive-search" key binding.
11470 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11471 gboolean enable_search)
11473 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11475 enable_search = !!enable_search;
11477 if (tree_view->priv->enable_search != enable_search)
11479 tree_view->priv->enable_search = enable_search;
11480 g_object_notify (G_OBJECT (tree_view), "enable-search");
11485 * pspp_sheet_view_get_enable_search:
11486 * @tree_view: A #PsppSheetView
11488 * Returns whether or not the tree allows to start interactive searching
11489 * by typing in text.
11491 * Return value: whether or not to let the user search interactively
11494 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11496 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11498 return tree_view->priv->enable_search;
11503 * pspp_sheet_view_get_search_column:
11504 * @tree_view: A #PsppSheetView
11506 * Gets the column searched on by the interactive search code.
11508 * Return value: the column the interactive search code searches in.
11511 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11513 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11515 return (tree_view->priv->search_column);
11519 * pspp_sheet_view_set_search_column:
11520 * @tree_view: A #PsppSheetView
11521 * @column: the column of the model to search in, or -1 to disable searching
11523 * Sets @column as the column where the interactive search code should
11524 * search in for the current model.
11526 * If the search column is set, users can use the "start-interactive-search"
11527 * key binding to bring up search popup. The enable-search property controls
11528 * whether simply typing text will also start an interactive search.
11530 * Note that @column refers to a column of the current model. The search
11531 * column is reset to -1 when the model is changed.
11534 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11537 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11538 g_return_if_fail (column >= -1);
11540 if (tree_view->priv->search_column == column)
11543 tree_view->priv->search_column = column;
11544 g_object_notify (G_OBJECT (tree_view), "search-column");
11548 * pspp_sheet_view_get_search_equal_func:
11549 * @tree_view: A #PsppSheetView
11551 * Returns the compare function currently in use.
11553 * Return value: the currently used compare function for the search code.
11556 PsppSheetViewSearchEqualFunc
11557 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11559 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11561 return tree_view->priv->search_equal_func;
11565 * pspp_sheet_view_set_search_equal_func:
11566 * @tree_view: A #PsppSheetView
11567 * @search_equal_func: the compare function to use during the search
11568 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11569 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11571 * Sets the compare function for the interactive search capabilities; note
11572 * that somewhat like strcmp() returning 0 for equality
11573 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11576 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11577 PsppSheetViewSearchEqualFunc search_equal_func,
11578 gpointer search_user_data,
11579 GDestroyNotify search_destroy)
11581 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11582 g_return_if_fail (search_equal_func != NULL);
11584 if (tree_view->priv->search_destroy)
11585 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11587 tree_view->priv->search_equal_func = search_equal_func;
11588 tree_view->priv->search_user_data = search_user_data;
11589 tree_view->priv->search_destroy = search_destroy;
11590 if (tree_view->priv->search_equal_func == NULL)
11591 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11595 * pspp_sheet_view_get_search_entry:
11596 * @tree_view: A #PsppSheetView
11598 * Returns the #GtkEntry which is currently in use as interactive search
11599 * entry for @tree_view. In case the built-in entry is being used, %NULL
11600 * will be returned.
11602 * Return value: the entry currently in use as search entry.
11607 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11609 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11611 if (tree_view->priv->search_custom_entry_set)
11612 return GTK_ENTRY (tree_view->priv->search_entry);
11618 * pspp_sheet_view_set_search_entry:
11619 * @tree_view: A #PsppSheetView
11620 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11622 * Sets the entry which the interactive search code will use for this
11623 * @tree_view. This is useful when you want to provide a search entry
11624 * in our interface at all time at a fixed position. Passing %NULL for
11625 * @entry will make the interactive search code use the built-in popup
11631 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11634 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11635 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11637 if (tree_view->priv->search_custom_entry_set)
11639 if (tree_view->priv->search_entry_changed_id)
11641 g_signal_handler_disconnect (tree_view->priv->search_entry,
11642 tree_view->priv->search_entry_changed_id);
11643 tree_view->priv->search_entry_changed_id = 0;
11645 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11646 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11649 g_object_unref (tree_view->priv->search_entry);
11651 else if (tree_view->priv->search_window)
11653 gtk_widget_destroy (tree_view->priv->search_window);
11655 tree_view->priv->search_window = NULL;
11660 tree_view->priv->search_entry = g_object_ref (entry);
11661 tree_view->priv->search_custom_entry_set = TRUE;
11663 if (tree_view->priv->search_entry_changed_id == 0)
11665 tree_view->priv->search_entry_changed_id =
11666 g_signal_connect (tree_view->priv->search_entry, "changed",
11667 G_CALLBACK (pspp_sheet_view_search_init),
11671 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11672 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11675 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11679 tree_view->priv->search_entry = NULL;
11680 tree_view->priv->search_custom_entry_set = FALSE;
11685 * pspp_sheet_view_set_search_position_func:
11686 * @tree_view: A #PsppSheetView
11687 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11688 * to use the default search position function
11689 * @data: (allow-none): user data to pass to @func, or %NULL
11690 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11692 * Sets the function to use when positioning the search dialog.
11697 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11698 PsppSheetViewSearchPositionFunc func,
11699 gpointer user_data,
11700 GDestroyNotify destroy)
11702 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11704 if (tree_view->priv->search_position_destroy)
11705 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11707 tree_view->priv->search_position_func = func;
11708 tree_view->priv->search_position_user_data = user_data;
11709 tree_view->priv->search_position_destroy = destroy;
11710 if (tree_view->priv->search_position_func == NULL)
11711 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11715 * pspp_sheet_view_get_search_position_func:
11716 * @tree_view: A #PsppSheetView
11718 * Returns the positioning function currently in use.
11720 * Return value: the currently used function for positioning the search dialog.
11724 PsppSheetViewSearchPositionFunc
11725 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11727 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11729 return tree_view->priv->search_position_func;
11734 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11735 PsppSheetView *tree_view)
11737 if (tree_view->priv->disable_popdown)
11740 if (tree_view->priv->search_entry_changed_id)
11742 g_signal_handler_disconnect (tree_view->priv->search_entry,
11743 tree_view->priv->search_entry_changed_id);
11744 tree_view->priv->search_entry_changed_id = 0;
11746 if (tree_view->priv->typeselect_flush_timeout)
11748 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11749 tree_view->priv->typeselect_flush_timeout = 0;
11752 if (gtk_widget_get_visible (search_dialog))
11754 /* send focus-in event */
11755 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11756 gtk_widget_hide (search_dialog);
11757 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11758 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11763 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11764 GtkWidget *search_dialog,
11765 gpointer user_data)
11768 gint tree_x, tree_y;
11769 gint tree_width, tree_height;
11770 GdkWindow *tree_window = gtk_widget_get_window (GTK_WIDGET (tree_view));
11771 GdkScreen *screen = gdk_window_get_screen (tree_window);
11772 GtkRequisition requisition;
11774 GdkRectangle monitor;
11776 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11777 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11779 gtk_widget_realize (search_dialog);
11781 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11782 tree_width = gdk_window_get_width (tree_window);
11783 tree_height = gdk_window_get_height (tree_window);
11785 gtk_widget_size_request (search_dialog, &requisition);
11787 if (tree_x + tree_width > gdk_screen_get_width (screen))
11788 x = gdk_screen_get_width (screen) - requisition.width;
11789 else if (tree_x + tree_width - requisition.width < 0)
11792 x = tree_x + tree_width - requisition.width;
11794 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11795 y = gdk_screen_get_height (screen) - requisition.height;
11796 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11799 y = tree_y + tree_height;
11801 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11805 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11809 PsppSheetView *tree_view = (PsppSheetView *)data;
11811 tree_view->priv->disable_popdown = 1;
11812 g_signal_connect (menu, "hide",
11813 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11816 #if GTK3_TRANSITION
11817 /* Because we're visible but offscreen, we just set a flag in the preedit
11821 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11822 PsppSheetView *tree_view)
11824 tree_view->priv->imcontext_changed = 1;
11825 if (tree_view->priv->typeselect_flush_timeout)
11827 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11828 tree_view->priv->typeselect_flush_timeout =
11829 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11830 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11838 pspp_sheet_view_search_activate (GtkEntry *entry,
11839 PsppSheetView *tree_view)
11844 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11847 /* If we have a row selected and it's the cursor row, we activate
11849 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11851 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11853 _pspp_sheet_view_find_node (tree_view, path, &node);
11855 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11856 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11858 gtk_tree_path_free (path);
11863 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11865 PsppSheetView *tree_view = (PsppSheetView *)data;
11867 tree_view->priv->disable_popdown = 0;
11873 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11876 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11880 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11881 GdkEventAny *event,
11882 PsppSheetView *tree_view)
11884 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11886 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11892 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11893 GdkEventButton *event,
11894 PsppSheetView *tree_view)
11896 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11898 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11900 if (event->window == tree_view->priv->bin_window)
11901 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11907 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11908 GdkEventScroll *event,
11909 PsppSheetView *tree_view)
11911 gboolean retval = FALSE;
11913 if (event->direction == GDK_SCROLL_UP)
11915 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11918 else if (event->direction == GDK_SCROLL_DOWN)
11920 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11924 /* renew the flush timeout */
11925 if (retval && tree_view->priv->typeselect_flush_timeout
11926 && !tree_view->priv->search_custom_entry_set)
11928 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11929 tree_view->priv->typeselect_flush_timeout =
11930 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11931 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11939 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11940 GdkEventKey *event,
11941 PsppSheetView *tree_view)
11943 gboolean retval = FALSE;
11945 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11946 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11948 /* close window and cancel the search */
11949 if (!tree_view->priv->search_custom_entry_set
11950 && (event->keyval == GDK_Escape ||
11951 event->keyval == GDK_Tab ||
11952 event->keyval == GDK_KP_Tab ||
11953 event->keyval == GDK_ISO_Left_Tab))
11955 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11959 /* select previous matching iter */
11960 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11962 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11963 gtk_widget_error_bell (widget);
11968 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11969 && (event->keyval == GDK_g || event->keyval == GDK_G))
11971 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11972 gtk_widget_error_bell (widget);
11977 /* select next matching iter */
11978 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
11980 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11981 gtk_widget_error_bell (widget);
11986 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
11987 && (event->keyval == GDK_g || event->keyval == GDK_G))
11989 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11990 gtk_widget_error_bell (widget);
11995 /* renew the flush timeout */
11996 if (retval && tree_view->priv->typeselect_flush_timeout
11997 && !tree_view->priv->search_custom_entry_set)
11999 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12000 tree_view->priv->typeselect_flush_timeout =
12001 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12002 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12009 /* this function returns FALSE if there is a search string but
12010 * nothing was found, and TRUE otherwise.
12013 pspp_sheet_view_search_move (GtkWidget *window,
12014 PsppSheetView *tree_view,
12022 GtkTreeModel *model;
12023 PsppSheetSelection *selection;
12025 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
12027 g_return_val_if_fail (text != NULL, FALSE);
12029 len = strlen (text);
12031 if (up && tree_view->priv->selected_iter == 1)
12032 return strlen (text) < 1;
12034 len = strlen (text);
12039 model = pspp_sheet_view_get_model (tree_view);
12040 selection = pspp_sheet_view_get_selection (tree_view);
12043 pspp_sheet_selection_unselect_all (selection);
12044 if (!gtk_tree_model_get_iter_first (model, &iter))
12047 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
12048 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
12053 tree_view->priv->selected_iter += up?(-1):(1);
12058 /* return to old iter */
12060 gtk_tree_model_get_iter_first (model, &iter);
12061 pspp_sheet_view_search_iter (model, selection,
12063 &count, tree_view->priv->selected_iter);
12069 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
12073 gpointer search_data)
12075 gboolean retval = TRUE;
12077 gchar *normalized_string;
12078 gchar *normalized_key;
12079 gchar *case_normalized_string = NULL;
12080 gchar *case_normalized_key = NULL;
12081 GValue value = {0,};
12082 GValue transformed = {0,};
12084 gtk_tree_model_get_value (model, iter, column, &value);
12086 g_value_init (&transformed, G_TYPE_STRING);
12088 if (!g_value_transform (&value, &transformed))
12090 g_value_unset (&value);
12094 g_value_unset (&value);
12096 str = g_value_get_string (&transformed);
12099 g_value_unset (&transformed);
12103 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
12104 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
12106 if (normalized_string && normalized_key)
12108 case_normalized_string = g_utf8_casefold (normalized_string, -1);
12109 case_normalized_key = g_utf8_casefold (normalized_key, -1);
12111 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
12115 g_value_unset (&transformed);
12116 g_free (normalized_key);
12117 g_free (normalized_string);
12118 g_free (case_normalized_key);
12119 g_free (case_normalized_string);
12125 pspp_sheet_view_search_iter (GtkTreeModel *model,
12126 PsppSheetSelection *selection,
12135 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
12137 path = gtk_tree_model_get_path (model, iter);
12138 _pspp_sheet_view_find_node (tree_view, path, &node);
12142 gboolean done = FALSE;
12144 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
12149 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
12151 pspp_sheet_selection_select_iter (selection, iter);
12152 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12155 gtk_tree_path_free (path);
12164 node = pspp_sheet_view_node_next (tree_view, node);
12170 has_next = gtk_tree_model_iter_next (model, iter);
12173 gtk_tree_path_next (path);
12176 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
12181 gtk_tree_path_free (path);
12183 /* we've run out of tree, done with this func */
12195 pspp_sheet_view_search_init (GtkWidget *entry,
12196 PsppSheetView *tree_view)
12202 GtkTreeModel *model;
12203 PsppSheetSelection *selection;
12205 g_return_if_fail (GTK_IS_ENTRY (entry));
12206 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12208 text = gtk_entry_get_text (GTK_ENTRY (entry));
12210 model = pspp_sheet_view_get_model (tree_view);
12211 selection = pspp_sheet_view_get_selection (tree_view);
12214 pspp_sheet_selection_unselect_all (selection);
12215 if (tree_view->priv->typeselect_flush_timeout
12216 && !tree_view->priv->search_custom_entry_set)
12218 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12219 tree_view->priv->typeselect_flush_timeout =
12220 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12221 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12228 if (!gtk_tree_model_get_iter_first (model, &iter))
12231 ret = pspp_sheet_view_search_iter (model, selection,
12236 tree_view->priv->selected_iter = 1;
12240 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
12241 PsppSheetView *tree_view)
12243 if (tree_view->priv->edited_column == NULL)
12246 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
12247 tree_view->priv->edited_column = NULL;
12249 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
12250 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12252 g_signal_handlers_disconnect_by_func (cell_editable,
12253 pspp_sheet_view_remove_widget,
12255 g_signal_handlers_disconnect_by_func (cell_editable,
12256 pspp_sheet_view_editable_button_press_event,
12258 g_signal_handlers_disconnect_by_func (cell_editable,
12259 pspp_sheet_view_editable_clicked,
12262 gtk_container_remove (GTK_CONTAINER (tree_view),
12263 GTK_WIDGET (cell_editable));
12265 /* FIXME should only redraw a single node */
12266 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12270 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
12271 GtkTreePath *cursor_path)
12274 GdkRectangle background_area;
12275 GdkRectangle cell_area;
12276 GtkCellEditable *editable_widget = NULL;
12277 gchar *path_string;
12278 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
12279 gint retval = FALSE;
12282 g_assert (tree_view->priv->focus_column);
12284 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12287 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12288 if (cursor_node < 0)
12291 path_string = gtk_tree_path_to_string (cursor_path);
12292 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12294 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12295 tree_view->priv->model,
12297 pspp_sheet_view_get_background_area (tree_view,
12299 tree_view->priv->focus_column,
12301 pspp_sheet_view_get_cell_area (tree_view,
12303 tree_view->priv->focus_column,
12306 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12315 if (editable_widget != NULL)
12319 GtkCellRenderer *cell;
12322 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12324 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12327 area.width -= right + left;
12329 pspp_sheet_view_real_start_editing (tree_view,
12330 tree_view->priv->focus_column,
12339 g_free (path_string);
12344 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12345 GdkEventButton *event,
12346 PsppSheetView *sheet_view)
12350 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12351 "pspp-sheet-view-node"));
12352 return pspp_sheet_view_row_head_clicked (sheet_view,
12354 sheet_view->priv->edited_column,
12359 pspp_sheet_view_editable_clicked (GtkButton *button,
12360 PsppSheetView *sheet_view)
12362 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12367 is_all_selected (GtkWidget *widget)
12369 GtkEntryBuffer *buffer;
12370 gint start_pos, end_pos;
12372 if (!GTK_IS_ENTRY (widget))
12375 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12376 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12377 &start_pos, &end_pos)
12379 && end_pos == gtk_entry_buffer_get_length (buffer));
12383 is_at_left (GtkWidget *widget)
12385 return (GTK_IS_ENTRY (widget)
12386 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12390 is_at_right (GtkWidget *widget)
12392 GtkEntryBuffer *buffer;
12395 if (!GTK_IS_ENTRY (widget))
12398 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12399 length = gtk_entry_buffer_get_length (buffer);
12400 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12404 pspp_sheet_view_event (GtkWidget *widget,
12405 GdkEventKey *event,
12406 PsppSheetView *tree_view)
12408 PsppSheetViewColumn *column;
12415 /* Intercept only key press events.
12416 It would make sense to use "key-press-event" instead of "event", but
12417 GtkEntry attaches its own signal handler to "key-press-event" that runs
12418 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12420 if (event->type != GDK_KEY_PRESS)
12423 keyval = event->keyval;
12425 switch (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12428 switch (event->keyval)
12430 case GDK_Left: case GDK_KP_Left:
12431 case GDK_Home: case GDK_KP_Home:
12432 if (!is_all_selected (widget) && !is_at_left (widget))
12436 case GDK_Right: case GDK_KP_Right:
12437 case GDK_End: case GDK_KP_End:
12438 if (!is_all_selected (widget) && !is_at_right (widget))
12442 case GDK_Up: case GDK_KP_Up:
12443 case GDK_Down: case GDK_KP_Down:
12446 case GDK_Page_Up: case GDK_KP_Page_Up:
12447 case GDK_Page_Down: case GDK_KP_Page_Down:
12458 case GDK_Tab: case GDK_KP_Tab:
12459 case GDK_ISO_Left_Tab:
12468 case GDK_SHIFT_MASK:
12469 switch (event->keyval)
12472 case GDK_ISO_Left_Tab:
12481 case GDK_CONTROL_MASK:
12482 switch (event->keyval)
12484 case GDK_Left: case GDK_KP_Left:
12485 if (!is_all_selected (widget) && !is_at_left (widget))
12489 case GDK_Right: case GDK_KP_Right:
12490 if (!is_all_selected (widget) && !is_at_right (widget))
12494 case GDK_Up: case GDK_KP_Up:
12495 case GDK_Down: case GDK_KP_Down:
12507 row = tree_view->priv->edited_row;
12508 column = tree_view->priv->edited_column;
12509 path = gtk_tree_path_new_from_indices (row, -1);
12511 pspp_sheet_view_stop_editing (tree_view, cancel);
12512 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12514 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12515 gtk_tree_path_free (path);
12517 handled = gtk_binding_set_activate (edit_bindings, keyval, event->state,
12518 GTK_OBJECT (tree_view));
12520 g_signal_stop_emission_by_name (widget, "event");
12522 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12523 pspp_sheet_view_start_editing (tree_view, path);
12524 gtk_tree_path_free (path);
12530 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12533 PsppSheetView *sheet_view = data;
12535 g_signal_connect (widget, "event",
12536 G_CALLBACK (pspp_sheet_view_event),
12539 if (GTK_IS_CONTAINER (widget))
12540 gtk_container_foreach (GTK_CONTAINER (widget),
12541 pspp_sheet_view_override_cell_keypresses,
12546 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12547 PsppSheetViewColumn *column,
12549 GtkCellEditable *cell_editable,
12550 GdkRectangle *cell_area,
12554 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12555 gint pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
12556 GtkRequisition requisition;
12559 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12561 tree_view->priv->edited_column = column;
12562 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12564 row = gtk_tree_path_get_indices (path)[0];
12565 tree_view->priv->edited_row = row;
12566 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12567 cell_area->y += pre_val - (int)gtk_adjustment_get_value (tree_view->priv->vadjustment);
12569 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12570 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12571 tree_view->priv->anchor_column = column;
12573 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12575 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12577 if (requisition.height < cell_area->height)
12579 gint diff = cell_area->height - requisition.height;
12580 pspp_sheet_view_put (tree_view,
12581 GTK_WIDGET (cell_editable),
12582 cell_area->x, cell_area->y + diff/2,
12583 cell_area->width, requisition.height);
12587 pspp_sheet_view_put (tree_view,
12588 GTK_WIDGET (cell_editable),
12589 cell_area->x, cell_area->y,
12590 cell_area->width, cell_area->height);
12593 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12594 (GdkEvent *)event);
12596 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12597 g_signal_connect (cell_editable, "remove-widget",
12598 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12599 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12600 GTK_IS_BUTTON (cell_editable))
12602 g_signal_connect (cell_editable, "button-press-event",
12603 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12605 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12606 GINT_TO_POINTER (row));
12607 g_signal_connect (cell_editable, "clicked",
12608 G_CALLBACK (pspp_sheet_view_editable_clicked),
12612 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12617 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12618 gboolean cancel_editing)
12620 PsppSheetViewColumn *column;
12621 GtkCellRenderer *cell;
12623 if (tree_view->priv->edited_column == NULL)
12627 * This is very evil. We need to do this, because
12628 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12629 * later on. If pspp_sheet_view_row_changed notices
12630 * tree_view->priv->edited_column != NULL, it'll call
12631 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12633 * Please read that again if you intend to modify anything here.
12636 column = tree_view->priv->edited_column;
12637 tree_view->priv->edited_column = NULL;
12639 cell = _pspp_sheet_view_column_get_edited_cell (column);
12640 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12642 if (!cancel_editing)
12643 gtk_cell_editable_editing_done (column->editable_widget);
12645 tree_view->priv->edited_column = column;
12647 gtk_cell_editable_remove_widget (column->editable_widget);
12652 * pspp_sheet_view_set_hover_selection:
12653 * @tree_view: a #PsppSheetView
12654 * @hover: %TRUE to enable hover selection mode
12656 * Enables of disables the hover selection mode of @tree_view.
12657 * Hover selection makes the selected row follow the pointer.
12658 * Currently, this works only for the selection modes
12659 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12664 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12667 hover = hover != FALSE;
12669 if (hover != tree_view->priv->hover_selection)
12671 tree_view->priv->hover_selection = hover;
12673 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12678 * pspp_sheet_view_get_hover_selection:
12679 * @tree_view: a #PsppSheetView
12681 * Returns whether hover selection mode is turned on for @tree_view.
12683 * Return value: %TRUE if @tree_view is in hover selection mode
12688 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12690 return tree_view->priv->hover_selection;
12694 * pspp_sheet_view_set_rubber_banding:
12695 * @tree_view: a #PsppSheetView
12696 * @enable: %TRUE to enable rubber banding
12698 * Enables or disables rubber banding in @tree_view. If the selection mode is
12699 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12700 * banding will allow the user to select multiple rows by dragging the mouse.
12705 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12708 enable = enable != FALSE;
12710 if (enable != tree_view->priv->rubber_banding_enable)
12712 tree_view->priv->rubber_banding_enable = enable;
12714 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12719 * pspp_sheet_view_get_rubber_banding:
12720 * @tree_view: a #PsppSheetView
12722 * Returns whether rubber banding is turned on for @tree_view. If the
12723 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12724 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12725 * select multiple rows by dragging the mouse.
12727 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12732 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12734 return tree_view->priv->rubber_banding_enable;
12738 * pspp_sheet_view_is_rubber_banding_active:
12739 * @tree_view: a #PsppSheetView
12741 * Returns whether a rubber banding operation is currently being done
12744 * Return value: %TRUE if a rubber banding operation is currently being
12745 * done in @tree_view.
12750 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12752 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12754 if (tree_view->priv->rubber_banding_enable
12755 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12762 pspp_sheet_view_grab_notify (GtkWidget *widget,
12763 gboolean was_grabbed)
12765 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12767 tree_view->priv->in_grab = !was_grabbed;
12771 tree_view->priv->pressed_button = -1;
12773 if (tree_view->priv->rubber_band_status)
12774 pspp_sheet_view_stop_rubber_band (tree_view);
12779 pspp_sheet_view_state_changed (GtkWidget *widget,
12780 GtkStateType previous_state)
12782 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12784 if (gtk_widget_get_realized (widget))
12786 GtkStyle *style = gtk_widget_get_style (widget);
12787 gdk_window_set_back_pixmap (gtk_widget_get_window (widget), NULL, FALSE);
12788 gdk_window_set_background (tree_view->priv->bin_window, &style->base[gtk_widget_get_state (widget)]);
12791 gtk_widget_queue_draw (widget);
12795 * pspp_sheet_view_get_grid_lines:
12796 * @tree_view: a #PsppSheetView
12798 * Returns which grid lines are enabled in @tree_view.
12800 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12805 PsppSheetViewGridLines
12806 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12808 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12810 return tree_view->priv->grid_lines;
12814 * pspp_sheet_view_set_grid_lines:
12815 * @tree_view: a #PsppSheetView
12816 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12819 * Sets which grid lines to draw in @tree_view.
12824 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12825 PsppSheetViewGridLines grid_lines)
12827 PsppSheetViewPrivate *priv;
12828 PsppSheetViewGridLines old_grid_lines;
12830 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12832 priv = tree_view->priv;
12834 old_grid_lines = priv->grid_lines;
12835 priv->grid_lines = grid_lines;
12837 if (old_grid_lines != grid_lines)
12839 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12841 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12846 * pspp_sheet_view_get_special_cells:
12847 * @tree_view: a #PsppSheetView
12849 * Returns which grid lines are enabled in @tree_view.
12851 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12852 * the sheet view contain special cells.
12854 PsppSheetViewSpecialCells
12855 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12857 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12859 return tree_view->priv->special_cells;
12863 * pspp_sheet_view_set_special_cells:
12864 * @tree_view: a #PsppSheetView
12865 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12866 * the sheet view contain special cells.
12868 * Sets whether rows in the sheet view contain special cells, controlling the
12869 * rendering of row selections.
12872 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12873 PsppSheetViewSpecialCells special_cells)
12875 PsppSheetViewPrivate *priv;
12877 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12879 priv = tree_view->priv;
12881 if (priv->special_cells != special_cells)
12883 priv->special_cells = special_cells;
12884 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12885 g_object_notify (G_OBJECT (tree_view), "special-cells");
12890 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12892 /* XXX (re)calculate fixed_height if necessary */
12893 return tree_view->priv->fixed_height;
12897 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12900 g_return_if_fail (fixed_height > 0);
12902 if (tree_view->priv->fixed_height != fixed_height)
12904 tree_view->priv->fixed_height = fixed_height;
12905 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12907 if (!tree_view->priv->fixed_height_set)
12909 tree_view->priv->fixed_height_set = TRUE;
12910 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12915 * pspp_sheet_view_set_tooltip_row:
12916 * @tree_view: a #PsppSheetView
12917 * @tooltip: a #GtkTooltip
12918 * @path: a #GtkTreePath
12920 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12921 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12922 * See also gtk_tooltip_set_tip_area().
12927 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12928 GtkTooltip *tooltip,
12931 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12932 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12934 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12938 * pspp_sheet_view_set_tooltip_cell:
12939 * @tree_view: a #PsppSheetView
12940 * @tooltip: a #GtkTooltip
12941 * @path: (allow-none): a #GtkTreePath or %NULL
12942 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12943 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12945 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12946 * in common. For example if @path is %NULL and @column is set, the tip
12947 * area will be set to the full area covered by @column. See also
12948 * gtk_tooltip_set_tip_area().
12950 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12955 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12956 GtkTooltip *tooltip,
12958 PsppSheetViewColumn *column,
12959 GtkCellRenderer *cell)
12963 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12964 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12965 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12966 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12968 /* Determine x values. */
12969 if (column && cell)
12974 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12975 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12977 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12980 rect.width = width;
12986 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
12987 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12990 rect.width = tmp.width;
12994 GtkAllocation allocation;
12995 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
12997 rect.width = allocation.width;
13000 /* Determine y values. */
13005 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
13006 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13009 rect.height = tmp.height;
13014 rect.height = gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
13017 gtk_tooltip_set_tip_area (tooltip, &rect);
13021 * pspp_sheet_view_get_tooltip_context:
13022 * @tree_view: a #PsppSheetView
13023 * @x: the x coordinate (relative to widget coordinates)
13024 * @y: the y coordinate (relative to widget coordinates)
13025 * @keyboard_tip: whether this is a keyboard tooltip or not
13026 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
13027 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
13028 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
13030 * This function is supposed to be used in a #GtkWidget::query-tooltip
13031 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
13032 * which are received in the signal handler, should be passed to this
13033 * function without modification.
13035 * The return value indicates whether there is a tree view row at the given
13036 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
13037 * tooltips the row returned will be the cursor row. When %TRUE, then any of
13038 * @model, @path and @iter which have been provided will be set to point to
13039 * that row and the corresponding model. @x and @y will always be converted
13040 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
13042 * Return value: whether or not the given tooltip context points to a row.
13047 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
13050 gboolean keyboard_tip,
13051 GtkTreeModel **model,
13052 GtkTreePath **path,
13055 GtkTreePath *tmppath = NULL;
13057 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
13058 g_return_val_if_fail (x != NULL, FALSE);
13059 g_return_val_if_fail (y != NULL, FALSE);
13063 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
13070 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
13073 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
13074 &tmppath, NULL, NULL, NULL))
13079 *model = pspp_sheet_view_get_model (tree_view);
13082 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
13088 gtk_tree_path_free (tmppath);
13094 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
13097 gboolean keyboard_tip,
13098 GtkTooltip *tooltip,
13101 GValue value = { 0, };
13102 GValue transformed = { 0, };
13105 GtkTreeModel *model;
13106 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
13108 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
13111 &model, &path, &iter))
13114 gtk_tree_model_get_value (model, &iter,
13115 tree_view->priv->tooltip_column, &value);
13117 g_value_init (&transformed, G_TYPE_STRING);
13119 if (!g_value_transform (&value, &transformed))
13121 g_value_unset (&value);
13122 gtk_tree_path_free (path);
13127 g_value_unset (&value);
13129 if (!g_value_get_string (&transformed))
13131 g_value_unset (&transformed);
13132 gtk_tree_path_free (path);
13137 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
13138 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
13140 gtk_tree_path_free (path);
13141 g_value_unset (&transformed);
13147 * pspp_sheet_view_set_tooltip_column:
13148 * @tree_view: a #PsppSheetView
13149 * @column: an integer, which is a valid column number for @tree_view's model
13151 * If you only plan to have simple (text-only) tooltips on full rows, you
13152 * can use this function to have #PsppSheetView handle these automatically
13153 * for you. @column should be set to the column in @tree_view's model
13154 * containing the tooltip texts, or -1 to disable this feature.
13156 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
13157 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
13159 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
13160 * so &, <, etc have to be escaped in the text.
13165 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
13168 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13170 if (column == tree_view->priv->tooltip_column)
13175 g_signal_handlers_disconnect_by_func (tree_view,
13176 pspp_sheet_view_set_tooltip_query_cb,
13178 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
13182 if (tree_view->priv->tooltip_column == -1)
13184 g_signal_connect (tree_view, "query-tooltip",
13185 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
13186 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
13190 tree_view->priv->tooltip_column = column;
13191 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
13195 * pspp_sheet_view_get_tooltip_column:
13196 * @tree_view: a #PsppSheetView
13198 * Returns the column of @tree_view's model which is being used for
13199 * displaying tooltips on @tree_view's rows.
13201 * Return value: the index of the tooltip column that is currently being
13202 * used, or -1 if this is disabled.
13207 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
13209 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
13211 return tree_view->priv->tooltip_column;
13215 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
13216 GValue *return_accu,
13217 const GValue *handler_return,
13220 gboolean continue_emission;
13221 gboolean signal_handled;
13223 signal_handled = g_value_get_boolean (handler_return);
13224 g_value_set_boolean (return_accu, signal_handled);
13225 continue_emission = !signal_handled;
13227 return continue_emission;
13232 pspp_sheet_view_grid_lines_get_type (void)
13234 static GType etype = 0;
13235 if (G_UNLIKELY(etype == 0)) {
13236 static const GEnumValue values[] = {
13237 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
13238 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
13239 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
13240 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
13243 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
13249 pspp_sheet_view_special_cells_get_type (void)
13251 static GType etype = 0;
13252 if (G_UNLIKELY(etype == 0)) {
13253 static const GEnumValue values[] = {
13254 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
13255 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
13256 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
13259 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);