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);
6147 pspp_sheet_view_drag_begin (GtkWidget *widget,
6148 GdkDragContext *context)
6151 PsppSheetView *tree_view;
6152 GtkTreePath *path = NULL;
6153 gint cell_x, cell_y;
6155 TreeViewDragInfo *di;
6157 tree_view = PSPP_SHEET_VIEW (widget);
6159 /* if the user uses a custom DND source impl, we don't set the icon here */
6160 di = get_info (tree_view);
6162 if (di == NULL || !di->source_set)
6165 pspp_sheet_view_get_path_at_pos (tree_view,
6166 tree_view->priv->press_start_x,
6167 tree_view->priv->press_start_y,
6173 g_return_if_fail (path != NULL);
6175 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6178 gtk_drag_set_icon_pixmap (context,
6179 gdk_drawable_get_colormap (row_pix),
6182 /* the + 1 is for the black border in the icon */
6183 tree_view->priv->press_start_x + 1,
6186 g_object_unref (row_pix);
6187 gtk_tree_path_free (path);
6193 pspp_sheet_view_drag_end (GtkWidget *widget,
6194 GdkDragContext *context)
6199 /* Default signal implementations for the drag signals */
6201 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6202 GdkDragContext *context,
6203 GtkSelectionData *selection_data,
6207 PsppSheetView *tree_view;
6208 GtkTreeModel *model;
6209 TreeViewDragInfo *di;
6210 GtkTreePath *source_row;
6212 tree_view = PSPP_SHEET_VIEW (widget);
6214 model = pspp_sheet_view_get_model (tree_view);
6219 di = get_info (PSPP_SHEET_VIEW (widget));
6224 source_row = get_source_row (context);
6226 if (source_row == NULL)
6229 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6230 * any model; for DragSource models there are some other targets
6234 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6235 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6240 /* If drag_data_get does nothing, try providing row data. */
6241 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6243 gtk_tree_set_row_drag_data (selection_data,
6249 gtk_tree_path_free (source_row);
6254 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6255 GdkDragContext *context)
6257 TreeViewDragInfo *di;
6258 GtkTreeModel *model;
6259 PsppSheetView *tree_view;
6260 GtkTreePath *source_row;
6262 tree_view = PSPP_SHEET_VIEW (widget);
6263 model = pspp_sheet_view_get_model (tree_view);
6265 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6268 di = get_info (tree_view);
6273 source_row = get_source_row (context);
6275 if (source_row == NULL)
6278 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6281 gtk_tree_path_free (source_row);
6283 set_source_row (context, NULL, NULL);
6287 pspp_sheet_view_drag_leave (GtkWidget *widget,
6288 GdkDragContext *context,
6291 /* unset any highlight row */
6292 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6294 PSPP_SHEET_VIEW_DROP_BEFORE);
6296 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6301 pspp_sheet_view_drag_motion (GtkWidget *widget,
6302 GdkDragContext *context,
6303 /* coordinates relative to the widget */
6309 GtkTreePath *path = NULL;
6310 PsppSheetViewDropPosition pos;
6311 PsppSheetView *tree_view;
6312 GdkDragAction suggested_action = 0;
6315 tree_view = PSPP_SHEET_VIEW (widget);
6317 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6320 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6322 /* we only know this *after* set_desination_row */
6323 empty = tree_view->priv->empty_view_drop;
6325 if (path == NULL && !empty)
6327 /* Can't drop here. */
6328 gdk_drag_status (context, 0, time);
6332 if (tree_view->priv->open_dest_timeout == 0 &&
6333 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6334 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6340 add_scroll_timeout (tree_view);
6343 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6345 /* Request data so we can use the source row when
6346 * determining whether to accept the drop
6348 set_status_pending (context, suggested_action);
6349 gtk_drag_get_data (widget, context, target, time);
6353 set_status_pending (context, 0);
6354 gdk_drag_status (context, suggested_action, time);
6359 gtk_tree_path_free (path);
6366 pspp_sheet_view_drag_drop (GtkWidget *widget,
6367 GdkDragContext *context,
6368 /* coordinates relative to the widget */
6373 PsppSheetView *tree_view;
6375 GdkDragAction suggested_action = 0;
6376 GdkAtom target = GDK_NONE;
6377 TreeViewDragInfo *di;
6378 GtkTreeModel *model;
6379 gboolean path_down_mode;
6380 gboolean drop_append_mode;
6382 tree_view = PSPP_SHEET_VIEW (widget);
6384 model = pspp_sheet_view_get_model (tree_view);
6386 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6388 di = get_info (tree_view);
6393 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6396 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6399 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6401 if (target != GDK_NONE && path != NULL)
6403 /* in case a motion had requested drag data, change things so we
6404 * treat drag data receives as a drop.
6406 set_status_pending (context, 0);
6407 set_dest_row (context, model, path,
6408 path_down_mode, tree_view->priv->empty_view_drop,
6413 gtk_tree_path_free (path);
6415 /* Unset this thing */
6416 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6418 PSPP_SHEET_VIEW_DROP_BEFORE);
6420 if (target != GDK_NONE)
6422 gtk_drag_get_data (widget, context, target, time);
6430 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6431 GdkDragContext *context,
6432 /* coordinates relative to the widget */
6435 GtkSelectionData *selection_data,
6440 TreeViewDragInfo *di;
6441 gboolean accepted = FALSE;
6442 GtkTreeModel *model;
6443 PsppSheetView *tree_view;
6444 GtkTreePath *dest_row;
6445 GdkDragAction suggested_action;
6446 gboolean path_down_mode;
6447 gboolean drop_append_mode;
6449 tree_view = PSPP_SHEET_VIEW (widget);
6451 model = pspp_sheet_view_get_model (tree_view);
6453 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6456 di = get_info (tree_view);
6461 suggested_action = get_status_pending (context);
6463 if (suggested_action)
6465 /* We are getting this data due to a request in drag_motion,
6466 * rather than due to a request in drag_drop, so we are just
6467 * supposed to call drag_status, not actually paste in the
6470 path = get_logical_dest_row (tree_view, &path_down_mode,
6474 suggested_action = 0;
6475 else if (path_down_mode)
6476 gtk_tree_path_down (path);
6478 if (suggested_action)
6480 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6486 path_down_mode = FALSE;
6487 gtk_tree_path_up (path);
6489 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6492 suggested_action = 0;
6495 suggested_action = 0;
6499 gdk_drag_status (context, suggested_action, time);
6502 gtk_tree_path_free (path);
6504 /* If you can't drop, remove user drop indicator until the next motion */
6505 if (suggested_action == 0)
6506 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6508 PSPP_SHEET_VIEW_DROP_BEFORE);
6513 dest_row = get_dest_row (context, &path_down_mode);
6515 if (dest_row == NULL)
6518 if (gtk_selection_data_get_length (selection_data) >= 0)
6522 gtk_tree_path_down (dest_row);
6523 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6524 dest_row, selection_data))
6525 gtk_tree_path_up (dest_row);
6529 if (gtk_selection_data_get_length (selection_data) >= 0)
6531 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6537 gtk_drag_finish (context,
6539 (gdk_drag_context_get_actions (context) == GDK_ACTION_MOVE),
6542 if (gtk_tree_path_get_depth (dest_row) == 1
6543 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6545 /* special special case drag to "0", scroll to first item */
6546 if (!tree_view->priv->scroll_to_path)
6547 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6550 gtk_tree_path_free (dest_row);
6553 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6558 /* GtkContainer Methods
6563 pspp_sheet_view_remove (GtkContainer *container,
6566 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6567 PsppSheetViewChild *child = NULL;
6570 tmp_list = tree_view->priv->children;
6573 child = tmp_list->data;
6574 if (child->widget == widget)
6576 gtk_widget_unparent (widget);
6578 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6579 g_list_free_1 (tmp_list);
6580 g_slice_free (PsppSheetViewChild, child);
6584 tmp_list = tmp_list->next;
6587 tmp_list = tree_view->priv->columns;
6591 PsppSheetViewColumn *column;
6592 column = tmp_list->data;
6593 if (column->button == widget)
6595 gtk_widget_unparent (widget);
6598 tmp_list = tmp_list->next;
6603 pspp_sheet_view_forall (GtkContainer *container,
6604 gboolean include_internals,
6605 GtkCallback callback,
6606 gpointer callback_data)
6608 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6609 PsppSheetViewChild *child = NULL;
6610 PsppSheetViewColumn *column;
6613 tmp_list = tree_view->priv->children;
6616 child = tmp_list->data;
6617 tmp_list = tmp_list->next;
6619 (* callback) (child->widget, callback_data);
6621 if (include_internals == FALSE)
6624 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6626 column = tmp_list->data;
6629 (* callback) (column->button, callback_data);
6633 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6634 * cells. If so we draw one big row-spanning focus rectangle.
6637 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6641 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6642 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6644 for (list = tree_view->priv->columns; list; list = list->next)
6646 if (!((PsppSheetViewColumn *)list->data)->visible)
6648 if (_pspp_sheet_view_column_count_special_cells (list->data))
6656 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6657 PsppSheetViewColumn *focus_column,
6658 gboolean clamp_column_visible)
6660 g_return_if_fail (focus_column != NULL);
6662 tree_view->priv->focus_column = focus_column;
6663 if (!focus_column->button)
6665 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6666 // g_return_if_fail (focus_column->button != NULL);
6667 if (focus_column->button == NULL)
6671 if (gtk_container_get_focus_child (GTK_CONTAINER (tree_view)) != focus_column->button)
6672 gtk_widget_grab_focus (focus_column->button);
6674 if (clamp_column_visible)
6675 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6678 /* Returns TRUE if the focus is within the headers, after the focus operation is
6682 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6683 GtkDirectionType dir,
6684 gboolean clamp_column_visible)
6686 GtkWidget *focus_child;
6687 PsppSheetViewColumn *focus_column;
6688 GList *last_column, *first_column;
6692 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6695 focus_child = gtk_container_get_focus_child (GTK_CONTAINER (tree_view));
6697 first_column = tree_view->priv->columns;
6698 while (first_column)
6700 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6702 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6704 first_column = first_column->next;
6707 /* No headers are visible, or are focusable. We can't focus in or out.
6709 if (first_column == NULL)
6712 last_column = g_list_last (tree_view->priv->columns);
6715 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6717 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6719 last_column = last_column->prev;
6723 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6727 case GTK_DIR_TAB_BACKWARD:
6728 case GTK_DIR_TAB_FORWARD:
6731 if (focus_child == NULL)
6733 if (tree_view->priv->focus_column != NULL &&
6734 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6735 focus_column = tree_view->priv->focus_column;
6737 focus_column = first_column->data;
6738 pspp_sheet_view_focus_column (tree_view, focus_column,
6739 clamp_column_visible);
6746 if (focus_child == NULL)
6748 if (tree_view->priv->focus_column != NULL)
6749 focus_column = tree_view->priv->focus_column;
6750 else if (dir == GTK_DIR_LEFT)
6751 focus_column = last_column->data;
6753 focus_column = first_column->data;
6754 pspp_sheet_view_focus_column (tree_view, focus_column,
6755 clamp_column_visible);
6759 if (gtk_widget_child_focus (focus_child, dir))
6761 /* The focus moves inside the button. */
6762 /* This is probably a great example of bad UI */
6763 if (clamp_column_visible)
6764 pspp_sheet_view_clamp_column_visible (tree_view,
6765 tree_view->priv->focus_column,
6770 /* We need to move the focus among the row of buttons. */
6771 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6772 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6775 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6776 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6778 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6784 PsppSheetViewColumn *column;
6786 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6787 tmp_list = tmp_list->next;
6789 tmp_list = tmp_list->prev;
6791 if (tmp_list == NULL)
6793 g_warning ("Internal button not found");
6796 column = tmp_list->data;
6797 if (column->visible &&
6798 pspp_sheet_view_column_can_focus (column))
6800 pspp_sheet_view_column_set_need_button (column, TRUE);
6803 pspp_sheet_view_focus_column (tree_view, column,
6804 clamp_column_visible);
6812 g_assert_not_reached ();
6819 /* This function returns in 'path' the first focusable path, if the given path
6820 * is already focusable, it's the returned one.
6824 search_first_focusable_path (PsppSheetView *tree_view,
6826 gboolean search_forward,
6829 /* XXX this function is trivial given that the sheetview doesn't support
6833 if (!path || !*path)
6836 _pspp_sheet_view_find_node (tree_view, *path, &node);
6844 return (*path != NULL);
6848 pspp_sheet_view_focus (GtkWidget *widget,
6849 GtkDirectionType direction)
6851 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6852 GtkContainer *container = GTK_CONTAINER (widget);
6853 GtkWidget *focus_child;
6855 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6858 focus_child = gtk_container_get_focus_child (container);
6860 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6861 /* Case 1. Headers currently have focus. */
6868 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6870 case GTK_DIR_TAB_BACKWARD:
6873 case GTK_DIR_TAB_FORWARD:
6875 gtk_widget_grab_focus (widget);
6878 g_assert_not_reached ();
6883 /* Case 2. We don't have focus at all. */
6884 if (!gtk_widget_has_focus (widget))
6886 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6887 gtk_widget_grab_focus (widget);
6891 /* Case 3. We have focus already. */
6892 if (direction == GTK_DIR_TAB_BACKWARD)
6893 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6894 else if (direction == GTK_DIR_TAB_FORWARD)
6897 /* Other directions caught by the keybindings */
6898 gtk_widget_grab_focus (widget);
6903 pspp_sheet_view_grab_focus (GtkWidget *widget)
6905 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6907 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6911 pspp_sheet_view_style_set (GtkWidget *widget,
6912 GtkStyle *previous_style)
6914 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6916 PsppSheetViewColumn *column;
6918 if (gtk_widget_get_realized (widget))
6920 gdk_window_set_back_pixmap (gtk_widget_get_window (widget), NULL, FALSE);
6921 gdk_window_set_background (tree_view->priv->bin_window, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
6922 gtk_style_set_background (gtk_widget_get_style (widget), tree_view->priv->header_window, GTK_STATE_NORMAL);
6923 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6926 gtk_widget_style_get (widget,
6927 "expander-size", &tree_view->priv->expander_size,
6929 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6931 for (list = tree_view->priv->columns; list; list = list->next)
6933 column = list->data;
6934 _pspp_sheet_view_column_cell_set_dirty (column);
6937 tree_view->priv->fixed_height = -1;
6939 /* Invalidate cached button style. */
6940 if (tree_view->priv->button_style)
6942 g_object_unref (tree_view->priv->button_style);
6943 tree_view->priv->button_style = NULL;
6946 gtk_widget_queue_resize (widget);
6951 pspp_sheet_view_set_focus_child (GtkContainer *container,
6954 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6957 for (list = tree_view->priv->columns; list; list = list->next)
6959 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6961 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6966 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6970 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6971 GtkAdjustment *hadj,
6972 GtkAdjustment *vadj)
6974 gboolean need_adjust = FALSE;
6976 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6979 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6981 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6983 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
6985 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6987 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
6989 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
6990 pspp_sheet_view_adjustment_changed,
6992 g_object_unref (tree_view->priv->hadjustment);
6995 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
6997 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
6998 pspp_sheet_view_adjustment_changed,
7000 g_object_unref (tree_view->priv->vadjustment);
7003 if (tree_view->priv->hadjustment != hadj)
7005 tree_view->priv->hadjustment = hadj;
7006 g_object_ref_sink (tree_view->priv->hadjustment);
7008 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
7009 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7014 if (tree_view->priv->vadjustment != vadj)
7016 tree_view->priv->vadjustment = vadj;
7017 g_object_ref_sink (tree_view->priv->vadjustment);
7019 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
7020 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7026 pspp_sheet_view_adjustment_changed (NULL, tree_view);
7031 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
7032 GtkMovementStep step,
7035 PsppSheetSelectMode mode;
7036 GdkModifierType state;
7038 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
7039 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
7040 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
7041 step == GTK_MOVEMENT_DISPLAY_LINES ||
7042 step == GTK_MOVEMENT_PAGES ||
7043 step == GTK_MOVEMENT_BUFFER_ENDS ||
7044 step == GTK_MOVEMENT_DISPLAY_LINE_ENDS, FALSE);
7046 if (tree_view->priv->row_count == 0)
7048 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7051 pspp_sheet_view_stop_editing (tree_view, FALSE);
7052 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7053 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7056 if (gtk_get_current_event_state (&state))
7058 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7059 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
7060 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
7061 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
7063 /* else we assume not pressed */
7067 case GTK_MOVEMENT_LOGICAL_POSITIONS:
7068 pspp_sheet_view_move_cursor_tab (tree_view, count);
7070 case GTK_MOVEMENT_VISUAL_POSITIONS:
7071 pspp_sheet_view_move_cursor_left_right (tree_view, count, mode);
7073 case GTK_MOVEMENT_DISPLAY_LINES:
7074 pspp_sheet_view_move_cursor_up_down (tree_view, count, mode);
7076 case GTK_MOVEMENT_PAGES:
7077 pspp_sheet_view_move_cursor_page_up_down (tree_view, count, mode);
7079 case GTK_MOVEMENT_BUFFER_ENDS:
7080 pspp_sheet_view_move_cursor_start_end (tree_view, count, mode);
7082 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
7083 pspp_sheet_view_move_cursor_line_start_end (tree_view, count, mode);
7086 g_assert_not_reached ();
7093 pspp_sheet_view_put (PsppSheetView *tree_view,
7094 GtkWidget *child_widget,
7095 /* in bin_window coordinates */
7101 PsppSheetViewChild *child;
7103 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7104 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7106 child = g_slice_new (PsppSheetViewChild);
7108 child->widget = child_widget;
7111 child->width = width;
7112 child->height = height;
7114 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7116 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7117 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7119 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7123 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7125 /* in tree coordinates */
7131 PsppSheetViewChild *child = NULL;
7133 GdkRectangle allocation;
7135 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7136 g_return_if_fail (GTK_IS_WIDGET (widget));
7138 for (list = tree_view->priv->children; list; list = list->next)
7140 if (((PsppSheetViewChild *)list->data)->widget == widget)
7149 allocation.x = child->x = x;
7150 allocation.y = child->y = y;
7151 allocation.width = child->width = width;
7152 allocation.height = child->height = height;
7154 if (gtk_widget_get_realized (widget))
7155 gtk_widget_size_allocate (widget, &allocation);
7159 /* TreeModel Callbacks
7163 pspp_sheet_view_row_changed (GtkTreeModel *model,
7168 PsppSheetView *tree_view = (PsppSheetView *)data;
7170 gboolean free_path = FALSE;
7171 GtkTreePath *cursor_path;
7173 g_return_if_fail (path != NULL || iter != NULL);
7175 if (tree_view->priv->cursor != NULL)
7176 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7180 if (tree_view->priv->edited_column &&
7181 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7182 pspp_sheet_view_stop_editing (tree_view, TRUE);
7184 if (cursor_path != NULL)
7185 gtk_tree_path_free (cursor_path);
7189 path = gtk_tree_model_get_path (model, iter);
7192 else if (iter == NULL)
7193 gtk_tree_model_get_iter (model, iter, path);
7195 _pspp_sheet_view_find_node (tree_view,
7201 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7202 pspp_sheet_view_node_queue_redraw (tree_view, node);
7206 gtk_tree_path_free (path);
7210 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7215 PsppSheetView *tree_view = (PsppSheetView *) data;
7218 gint height = tree_view->priv->fixed_height;
7219 gboolean free_path = FALSE;
7220 gboolean node_visible = TRUE;
7222 g_return_if_fail (path != NULL || iter != NULL);
7226 path = gtk_tree_model_get_path (model, iter);
7229 else if (iter == NULL)
7230 gtk_tree_model_get_iter (model, iter, path);
7232 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7234 /* Update all row-references */
7235 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7236 indices = gtk_tree_path_get_indices (path);
7237 tmpnode = indices[0];
7239 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7243 if (node_visible && node_is_visible (tree_view, tmpnode))
7244 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7246 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7249 install_presize_handler (tree_view);
7251 gtk_tree_path_free (path);
7255 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7259 PsppSheetView *tree_view = (PsppSheetView *)data;
7262 g_return_if_fail (path != NULL);
7264 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7266 _pspp_sheet_view_find_node (tree_view, path, &node);
7271 range_tower_delete (tree_view->priv->selected, node, 1);
7273 /* Ensure we don't have a dangling pointer to a dead node */
7274 ensure_unprelighted (tree_view);
7276 /* Cancel editting if we've started */
7277 pspp_sheet_view_stop_editing (tree_view, TRUE);
7279 if (tree_view->priv->destroy_count_func)
7281 gint child_count = 0;
7282 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7285 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7287 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7289 gtk_tree_row_reference_free (tree_view->priv->top_row);
7290 tree_view->priv->top_row = NULL;
7293 install_scroll_sync_handler (tree_view);
7295 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7298 if (helper_data.changed)
7299 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7304 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7305 GtkTreePath *parent,
7310 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7313 /* XXX need to adjust selection */
7314 len = gtk_tree_model_iter_n_children (model, iter);
7319 gtk_tree_row_reference_reordered (G_OBJECT (data),
7324 if (gtk_tree_path_get_depth (parent) != 0)
7327 if (tree_view->priv->edited_column)
7328 pspp_sheet_view_stop_editing (tree_view, TRUE);
7330 /* we need to be unprelighted */
7331 ensure_unprelighted (tree_view);
7333 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7335 pspp_sheet_view_dy_to_top_row (tree_view);
7339 /* Internal tree functions
7344 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7345 PsppSheetViewColumn *column,
7349 PsppSheetViewColumn *tmp_column = NULL;
7360 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7363 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7365 list = (rtl ? list->prev : list->next))
7367 tmp_column = list->data;
7369 if (tmp_column == column)
7372 if (tmp_column->visible)
7373 total_width += tmp_column->width;
7376 if (tmp_column != column)
7378 g_warning (G_STRLOC": passed-in column isn't in the tree");
7387 if (column->visible)
7388 *x2 = total_width + column->width;
7390 *x2 = total_width; /* width of 0 */
7394 /* Make sure the node is visible vertically */
7396 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7399 gint node_dy, height;
7400 GtkTreePath *path = NULL;
7402 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7405 /* just return if the node is visible, avoiding a costly expose */
7406 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7407 height = ROW_HEIGHT (tree_view);
7408 if (node_dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment)
7409 && node_dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
7410 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
7413 path = _pspp_sheet_view_find_path (tree_view, node);
7416 /* We process updates because we want to clear old selected items when we scroll.
7417 * if this is removed, we get a "selection streak" at the bottom. */
7418 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7419 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7420 gtk_tree_path_free (path);
7425 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7426 PsppSheetViewColumn *column,
7427 gboolean focus_to_cell)
7434 x = column->allocation.x;
7435 width = column->allocation.width;
7437 if (width > gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7439 /* The column is larger than the horizontal page size. If the
7440 * column has cells which can be focussed individually, then we make
7441 * sure the cell which gets focus is fully visible (if even the
7442 * focus cell is bigger than the page size, we make sure the
7443 * left-hand side of the cell is visible).
7445 * If the column does not have those so-called special cells, we
7446 * make sure the left-hand side of the column is visible.
7449 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7451 GtkTreePath *cursor_path;
7452 GdkRectangle background_area, cell_area, focus_area;
7454 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7456 pspp_sheet_view_get_cell_area (tree_view,
7457 cursor_path, column, &cell_area);
7458 pspp_sheet_view_get_background_area (tree_view,
7459 cursor_path, column,
7462 gtk_tree_path_free (cursor_path);
7464 _pspp_sheet_view_column_get_focus_area (column,
7470 width = focus_area.width;
7472 if (width < gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7474 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7475 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7476 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7477 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7478 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7482 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7484 gtk_adjustment_get_lower (tree_view->priv->hadjustment),
7485 gtk_adjustment_get_upper (tree_view->priv->hadjustment)
7486 - gtk_adjustment_get_page_size (tree_view->priv->hadjustment)));
7490 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7491 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7492 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7493 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7494 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7499 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7504 path = gtk_tree_path_new ();
7506 gtk_tree_path_append_index (path, node);
7511 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7515 gint *indices = gtk_tree_path_get_indices (path);
7516 gint depth = gtk_tree_path_get_depth (path);
7519 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7525 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7528 gboolean add_shifted_binding,
7529 GtkMovementStep step,
7533 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7538 if (add_shifted_binding)
7539 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7544 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7547 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7552 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7559 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7560 PsppSheetViewColumn *column)
7562 PsppSheetViewColumn *left_column;
7563 PsppSheetViewColumn *cur_column = NULL;
7564 PsppSheetViewColumnReorder *reorder;
7569 /* We want to precalculate the motion list such that we know what column slots
7573 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7575 /* First, identify all possible drop spots */
7577 tmp_list = g_list_last (tree_view->priv->columns);
7579 tmp_list = g_list_first (tree_view->priv->columns);
7583 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7584 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7586 if (cur_column->visible == FALSE)
7589 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7590 if (left_column != column && cur_column != column &&
7591 tree_view->priv->column_drop_func &&
7592 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7594 left_column = cur_column;
7597 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7598 reorder->left_column = left_column;
7599 left_column = reorder->right_column = cur_column;
7601 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7604 /* Add the last one */
7605 if (tree_view->priv->column_drop_func == NULL ||
7606 ((left_column != column) &&
7607 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7609 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7610 reorder->left_column = left_column;
7611 reorder->right_column = NULL;
7612 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7615 /* We quickly check to see if it even makes sense to reorder columns. */
7616 /* If there is nothing that can be moved, then we return */
7618 if (tree_view->priv->column_drag_info == NULL)
7621 /* We know there are always 2 slots possbile, as you can always return column. */
7622 /* If that's all there is, return */
7623 if (tree_view->priv->column_drag_info->next == NULL ||
7624 (tree_view->priv->column_drag_info->next->next == NULL &&
7625 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7626 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7628 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7629 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7630 g_list_free (tree_view->priv->column_drag_info);
7631 tree_view->priv->column_drag_info = NULL;
7634 /* We fill in the ranges for the columns, now that we've isolated them */
7635 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7637 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7639 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7641 reorder->left_align = left;
7642 if (tmp_list->next != NULL)
7644 g_assert (tmp_list->next->data);
7645 left = reorder->right_align = (reorder->right_column->allocation.x +
7646 reorder->right_column->allocation.width +
7647 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7651 gint width = gdk_window_get_width (tree_view->priv->header_window);
7652 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7658 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7659 PsppSheetViewColumn *column)
7661 GdkEvent *send_event;
7662 GtkAllocation allocation;
7664 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7665 GdkDisplay *display = gdk_screen_get_display (screen);
7667 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7668 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7669 g_return_if_fail (column->button);
7671 pspp_sheet_view_set_column_drag_info (tree_view, column);
7673 if (tree_view->priv->column_drag_info == NULL)
7676 if (tree_view->priv->drag_window == NULL)
7678 GdkWindowAttr attributes;
7679 guint attributes_mask;
7681 attributes.window_type = GDK_WINDOW_CHILD;
7682 attributes.wclass = GDK_INPUT_OUTPUT;
7683 attributes.x = column->allocation.x;
7685 attributes.width = column->allocation.width;
7686 attributes.height = column->allocation.height;
7687 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7688 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
7689 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7690 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
7692 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7695 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7698 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7699 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7701 gtk_grab_remove (column->button);
7703 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7704 send_event->crossing.send_event = TRUE;
7705 send_event->crossing.window = g_object_ref (gtk_button_get_event_window (GTK_BUTTON (column->button)));
7706 send_event->crossing.subwindow = NULL;
7707 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7708 send_event->crossing.time = GDK_CURRENT_TIME;
7710 gtk_propagate_event (column->button, send_event);
7711 gdk_event_free (send_event);
7713 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7714 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7715 send_event->button.send_event = TRUE;
7716 send_event->button.time = GDK_CURRENT_TIME;
7717 send_event->button.x = -1;
7718 send_event->button.y = -1;
7719 send_event->button.axes = NULL;
7720 send_event->button.state = 0;
7721 send_event->button.button = 1;
7722 send_event->button.device = gdk_display_get_core_pointer (display);
7723 send_event->button.x_root = 0;
7724 send_event->button.y_root = 0;
7726 gtk_propagate_event (column->button, send_event);
7727 gdk_event_free (send_event);
7729 /* Kids, don't try this at home */
7730 g_object_ref (column->button);
7731 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7732 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7733 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7734 g_object_unref (column->button);
7736 tree_view->priv->drag_column_x = column->allocation.x;
7737 allocation = column->allocation;
7739 gtk_widget_size_allocate (column->button, &allocation);
7740 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7742 tree_view->priv->drag_column = column;
7743 gdk_window_show (tree_view->priv->drag_window);
7745 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7747 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7748 while (gtk_events_pending ())
7749 gtk_main_iteration ();
7751 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7752 gdk_pointer_grab (tree_view->priv->drag_window,
7754 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7755 NULL, NULL, GDK_CURRENT_TIME);
7756 gdk_keyboard_grab (tree_view->priv->drag_window,
7762 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7764 const GdkRectangle *clip_rect)
7767 GtkAllocation allocation;
7769 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7772 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
7774 rect.width = MAX (tree_view->priv->width, allocation.width);
7776 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7777 rect.height = ROW_HEIGHT (tree_view);
7781 GdkRectangle new_rect;
7783 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7785 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7789 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7794 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7796 const GdkRectangle *clip_rect)
7800 _pspp_sheet_view_find_node (tree_view, path, &node);
7803 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7807 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7810 GtkTreePath *cursor_path;
7812 if ((tree_view->priv->row_count == 0) ||
7813 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7817 if (tree_view->priv->cursor)
7818 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7820 if (cursor_path == NULL)
7822 /* There's no cursor. Move the cursor to the first selected row, if any
7823 * are selected, otherwise to the first row in the sheetview.
7825 GList *selected_rows;
7826 GtkTreeModel *model;
7827 PsppSheetSelection *selection;
7829 selection = pspp_sheet_view_get_selection (tree_view);
7830 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7834 /* XXX we could avoid doing O(n) work to get this result */
7835 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7836 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7837 g_list_free (selected_rows);
7841 cursor_path = gtk_tree_path_new_first ();
7842 search_first_focusable_path (tree_view, &cursor_path,
7846 gtk_tree_row_reference_free (tree_view->priv->cursor);
7847 tree_view->priv->cursor = NULL;
7851 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7852 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7853 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE, 0);
7855 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, 0);
7861 /* Now find a column for the cursor. */
7862 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7864 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7865 gtk_tree_path_free (cursor_path);
7867 if (tree_view->priv->focus_column == NULL)
7870 for (list = tree_view->priv->columns; list; list = list->next)
7872 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7874 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7875 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7876 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7886 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7888 PsppSheetSelectMode mode)
7890 gint selection_count;
7891 int cursor_node = -1;
7892 int new_cursor_node = -1;
7893 GtkTreePath *cursor_path = NULL;
7894 gboolean grab_focus = TRUE;
7896 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7900 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7901 /* FIXME: we lost the cursor; should we get the first? */
7904 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7905 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7907 if (cursor_node < 0)
7908 /* FIXME: we lost the cursor; should we get the first? */
7911 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7913 if (selection_count == 0
7914 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7915 && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
7917 /* Don't move the cursor, but just select the current node */
7918 new_cursor_node = cursor_node;
7923 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7925 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7928 gtk_tree_path_free (cursor_path);
7930 if (new_cursor_node)
7932 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7934 search_first_focusable_path (tree_view, &cursor_path,
7939 gtk_tree_path_free (cursor_path);
7943 * If the list has only one item and multi-selection is set then select
7944 * the row (if not yet selected).
7946 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7947 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7948 new_cursor_node < 0)
7951 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7953 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7955 if (new_cursor_node < 0
7956 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7958 new_cursor_node = cursor_node;
7962 new_cursor_node = -1;
7966 if (new_cursor_node >= 0)
7968 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7969 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE, mode);
7970 gtk_tree_path_free (cursor_path);
7974 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7976 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
7978 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7980 GTK_DIR_UP : GTK_DIR_DOWN))
7982 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
7985 gtk_widget_child_focus (toplevel,
7987 GTK_DIR_TAB_BACKWARD :
7988 GTK_DIR_TAB_FORWARD);
7995 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8000 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8002 return new_cursor_node >= 0;
8006 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
8008 PsppSheetSelectMode mode)
8010 int cursor_node = -1;
8011 GtkTreePath *old_cursor_path = NULL;
8012 GtkTreePath *cursor_path = NULL;
8013 int start_cursor_node = -1;
8016 gint vertical_separator;
8018 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8021 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8022 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8024 /* This is sorta weird. Focus in should give us a cursor */
8027 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
8028 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
8030 if (cursor_node < 0)
8032 /* FIXME: we lost the cursor. Should we try to get one? */
8033 gtk_tree_path_free (old_cursor_path);
8037 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8038 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
8039 y += tree_view->priv->cursor_offset;
8040 y += count * (int)gtk_adjustment_get_page_increment (tree_view->priv->vadjustment);
8041 y = CLAMP (y, (gint)gtk_adjustment_get_lower (tree_view->priv->vadjustment), (gint)gtk_adjustment_get_upper (tree_view->priv->vadjustment) - vertical_separator);
8043 if (y >= tree_view->priv->height)
8044 y = tree_view->priv->height - 1;
8046 tree_view->priv->cursor_offset =
8047 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
8049 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
8051 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
8052 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
8055 y -= tree_view->priv->cursor_offset;
8056 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8058 start_cursor_node = cursor_node;
8060 if (! search_first_focusable_path (tree_view, &cursor_path,
8064 /* It looks like we reached the end of the view without finding
8065 * a focusable row. We will step backwards to find the last
8068 cursor_node = start_cursor_node;
8069 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8071 search_first_focusable_path (tree_view, &cursor_path,
8080 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8082 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, mode);
8085 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
8086 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8087 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8089 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
8090 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8092 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8095 gtk_tree_path_free (old_cursor_path);
8096 gtk_tree_path_free (cursor_path);
8100 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
8102 PsppSheetSelectMode mode)
8104 int cursor_node = -1;
8105 GtkTreePath *cursor_path = NULL;
8106 PsppSheetViewColumn *column;
8109 gboolean found_column = FALSE;
8112 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8114 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8117 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8118 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8122 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8123 if (cursor_node < 0)
8125 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8127 gtk_tree_path_free (cursor_path);
8130 gtk_tree_path_free (cursor_path);
8132 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8133 if (tree_view->priv->focus_column)
8135 for (; list; list = (rtl ? list->prev : list->next))
8137 if (list->data == tree_view->priv->focus_column)
8144 gboolean left, right;
8146 column = list->data;
8147 if (column->visible == FALSE || column->row_head)
8150 pspp_sheet_view_column_cell_set_cell_data (column,
8151 tree_view->priv->model,
8156 right = list->prev ? TRUE : FALSE;
8157 left = list->next ? TRUE : FALSE;
8161 left = list->prev ? TRUE : FALSE;
8162 right = list->next ? TRUE : FALSE;
8165 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8167 tree_view->priv->focus_column = column;
8168 found_column = TRUE;
8173 list = rtl ? list->prev : list->next;
8175 list = rtl ? list->next : list->prev;
8180 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8181 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8182 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8186 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8189 pspp_sheet_view_clamp_column_visible (tree_view,
8190 tree_view->priv->focus_column, TRUE);
8194 pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
8196 PsppSheetSelectMode mode)
8198 int cursor_node = -1;
8199 GtkTreePath *cursor_path = NULL;
8200 PsppSheetViewColumn *column;
8201 PsppSheetViewColumn *found_column;
8206 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8208 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8211 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8212 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8216 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8217 if (cursor_node < 0)
8219 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8221 gtk_tree_path_free (cursor_path);
8224 gtk_tree_path_free (cursor_path);
8226 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8227 if (tree_view->priv->focus_column)
8229 for (; list; list = (rtl ? list->prev : list->next))
8231 if (list->data == tree_view->priv->focus_column)
8236 found_column = NULL;
8239 gboolean left, right;
8241 column = list->data;
8242 if (column->visible == FALSE || column->row_head)
8245 pspp_sheet_view_column_cell_set_cell_data (column,
8246 tree_view->priv->model,
8251 right = list->prev ? TRUE : FALSE;
8252 left = list->next ? TRUE : FALSE;
8256 left = list->prev ? TRUE : FALSE;
8257 right = list->next ? TRUE : FALSE;
8260 if (column->tabbable
8261 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8262 found_column = column;
8266 list = rtl ? list->prev : list->next;
8268 list = rtl ? list->next : list->prev;
8273 tree_view->priv->focus_column = found_column;
8274 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8275 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8276 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8279 pspp_sheet_view_clamp_column_visible (tree_view,
8280 tree_view->priv->focus_column, TRUE);
8284 try_move_cursor_tab (PsppSheetView *tree_view,
8285 gboolean start_at_focus_column,
8288 PsppSheetViewColumn *column;
8290 int cursor_node = -1;
8291 GtkTreePath *cursor_path = NULL;
8295 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8296 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8300 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8301 if (cursor_node < 0)
8303 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8305 gtk_tree_path_free (cursor_path);
8308 gtk_tree_path_free (cursor_path);
8310 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
8311 if (start_at_focus_column)
8314 ? g_list_last (tree_view->priv->columns)
8315 : g_list_first (tree_view->priv->columns));
8316 if (tree_view->priv->focus_column)
8318 for (; list; list = (rtl ? list->prev : list->next))
8320 if (list->data == tree_view->priv->focus_column)
8327 list = (rtl ^ (count == 1)
8328 ? g_list_first (tree_view->priv->columns)
8329 : g_list_last (tree_view->priv->columns));
8334 gboolean left, right;
8336 column = list->data;
8337 if (column->visible == FALSE || !column->tabbable)
8340 pspp_sheet_view_column_cell_set_cell_data (column,
8341 tree_view->priv->model,
8346 right = list->prev ? TRUE : FALSE;
8347 left = list->next ? TRUE : FALSE;
8351 left = list->prev ? TRUE : FALSE;
8352 right = list->next ? TRUE : FALSE;
8355 if (column->tabbable
8356 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8358 tree_view->priv->focus_column = column;
8359 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8360 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8361 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8366 list = rtl ? list->prev : list->next;
8368 list = rtl ? list->next : list->prev;
8375 pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
8378 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8381 if (!try_move_cursor_tab (tree_view, TRUE, count))
8383 if (pspp_sheet_view_move_cursor_up_down (tree_view, count, 0)
8384 && !try_move_cursor_tab (tree_view, FALSE, count))
8385 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8388 pspp_sheet_view_clamp_column_visible (tree_view,
8389 tree_view->priv->focus_column, TRUE);
8393 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8395 PsppSheetSelectMode mode)
8399 GtkTreePath *old_path;
8401 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8404 g_return_if_fail (tree_view->priv->row_count > 0);
8406 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8410 /* Now go forward to find the first focusable row. */
8411 path = _pspp_sheet_view_find_path (tree_view, 0);
8412 search_first_focusable_path (tree_view, &path,
8413 TRUE, &cursor_node);
8417 /* Now go backwards to find last focusable row. */
8418 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8419 search_first_focusable_path (tree_view, &path,
8420 FALSE, &cursor_node);
8426 if (gtk_tree_path_compare (old_path, path))
8428 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
8429 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8433 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8437 gtk_tree_path_free (old_path);
8438 gtk_tree_path_free (path);
8442 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8444 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8447 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8448 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8451 pspp_sheet_selection_select_all (tree_view->priv->selection);
8457 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8459 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8462 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8463 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8466 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8472 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8473 gboolean start_editing,
8474 PsppSheetSelectMode mode)
8477 int cursor_node = -1;
8478 GtkTreePath *cursor_path = NULL;
8480 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8483 if (tree_view->priv->cursor)
8484 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8486 if (cursor_path == NULL)
8489 _pspp_sheet_view_find_node (tree_view, cursor_path,
8492 if (cursor_node < 0)
8494 gtk_tree_path_free (cursor_path);
8498 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND) && start_editing &&
8499 tree_view->priv->focus_column)
8501 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8503 gtk_tree_path_free (cursor_path);
8508 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8514 /* We bail out if the original (tree, node) don't exist anymore after
8515 * handling the selection-changed callback. We do return TRUE because
8516 * the key press has been handled at this point.
8518 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8520 if (cursor_node != new_node)
8523 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8525 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8526 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8528 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
8529 pspp_sheet_view_row_activated (tree_view, cursor_path,
8530 tree_view->priv->focus_column);
8532 gtk_tree_path_free (cursor_path);
8538 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8541 int cursor_node = -1;
8542 GtkTreePath *cursor_path = NULL;
8544 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8548 if (tree_view->priv->cursor)
8549 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8551 if (cursor_path == NULL)
8554 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8555 if (cursor_node < 0)
8557 gtk_tree_path_free (cursor_path);
8561 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8564 PSPP_SHEET_SELECT_MODE_TOGGLE,
8567 /* We bail out if the original (tree, node) don't exist anymore after
8568 * handling the selection-changed callback. We do return TRUE because
8569 * the key press has been handled at this point.
8571 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8573 if (cursor_node != new_node)
8576 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8578 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8579 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8580 gtk_tree_path_free (cursor_path);
8586 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8588 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8589 tree_view->priv->typeselect_flush_timeout = 0;
8594 /* Cut and paste from gtkwindow.c */
8596 send_focus_change (GtkWidget *widget,
8599 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8601 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8602 fevent->focus_change.window = g_object_ref (gtk_widget_get_window (widget));
8603 fevent->focus_change.in = in;
8605 gtk_widget_send_focus_change (widget, fevent);
8606 gdk_event_free (fevent);
8610 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8612 GtkWidget *frame, *vbox, *toplevel;
8615 if (tree_view->priv->search_custom_entry_set)
8618 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8619 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8621 if (tree_view->priv->search_window != NULL)
8623 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8624 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8625 GTK_WINDOW (tree_view->priv->search_window));
8626 else if (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)))
8627 gtk_window_group_remove_window (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)),
8628 GTK_WINDOW (tree_view->priv->search_window));
8629 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8633 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8634 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8636 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8637 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8638 GTK_WINDOW (tree_view->priv->search_window));
8640 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8641 GDK_WINDOW_TYPE_HINT_UTILITY);
8642 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8643 g_signal_connect (tree_view->priv->search_window, "delete-event",
8644 G_CALLBACK (pspp_sheet_view_search_delete_event),
8646 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8647 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8649 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8650 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8652 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8653 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8656 frame = gtk_frame_new (NULL);
8657 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8658 gtk_widget_show (frame);
8659 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8661 vbox = gtk_vbox_new (FALSE, 0);
8662 gtk_widget_show (vbox);
8663 gtk_container_add (GTK_CONTAINER (frame), vbox);
8664 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8667 tree_view->priv->search_entry = gtk_entry_new ();
8668 gtk_widget_show (tree_view->priv->search_entry);
8669 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8670 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8672 g_signal_connect (tree_view->priv->search_entry,
8673 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8677 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8679 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8683 gtk_container_add (GTK_CONTAINER (vbox),
8684 tree_view->priv->search_entry);
8686 gtk_widget_realize (tree_view->priv->search_entry);
8689 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8690 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8693 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8694 gboolean keybinding)
8696 /* We only start interactive search if we have focus or the columns
8697 * have focus. If one of our children have focus, we don't want to
8701 gboolean found_focus = FALSE;
8702 GtkWidgetClass *entry_parent_class;
8704 if (!tree_view->priv->enable_search && !keybinding)
8707 if (tree_view->priv->search_custom_entry_set)
8710 if (tree_view->priv->search_window != NULL &&
8711 gtk_widget_get_visible (tree_view->priv->search_window))
8714 for (list = tree_view->priv->columns; list; list = list->next)
8716 PsppSheetViewColumn *column;
8718 column = list->data;
8719 if (! column->visible)
8722 if (column->button && gtk_widget_has_focus (column->button))
8729 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8735 if (tree_view->priv->search_column < 0)
8738 pspp_sheet_view_ensure_interactive_directory (tree_view);
8741 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8744 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8745 gtk_widget_show (tree_view->priv->search_window);
8746 if (tree_view->priv->search_entry_changed_id == 0)
8748 tree_view->priv->search_entry_changed_id =
8749 g_signal_connect (tree_view->priv->search_entry, "changed",
8750 G_CALLBACK (pspp_sheet_view_search_init),
8754 tree_view->priv->typeselect_flush_timeout =
8755 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8756 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8759 /* Grab focus will select all the text. We don't want that to happen, so we
8760 * call the parent instance and bypass the selection change. This is probably
8761 * really non-kosher. */
8762 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8763 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8765 /* send focus-in event */
8766 send_focus_change (tree_view->priv->search_entry, TRUE);
8768 /* search first matching iter */
8769 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8775 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8777 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8780 /* this function returns the new width of the column being resized given
8781 * the column and x position of the cursor; the x cursor position is passed
8782 * in as a pointer and automagicly corrected if it's beyond min/max limits
8785 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8789 PsppSheetViewColumn *column;
8793 /* first translate the x position from gtk_widget_get_window (widget)
8794 * to clist->clist_window
8796 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8797 column = g_list_nth (tree_view->priv->columns, i)->data;
8798 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8800 /* Clamp down the value */
8801 if (column->min_width == -1)
8802 width = MAX (column->button_request, width);
8804 width = MAX (column->min_width, width);
8805 if (column->max_width != -1)
8806 width = MIN (width, column->max_width);
8808 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8814 /* FIXME this adjust_allocation is a big cut-and-paste from
8815 * GtkCList, needs to be some "official" way to do this
8825 /* The window to which gtk_widget_get_window (widget) is relative */
8826 #define ALLOCATION_WINDOW(widget) \
8827 (!gtk_widget_get_has_window (widget) ? \
8828 gtk_widget_get_window (widget) : \
8829 gdk_window_get_parent (gtk_widget_get_window (widget)))
8832 adjust_allocation_recurse (GtkWidget *widget,
8835 ScrollData *scroll_data = data;
8836 GtkAllocation allocation;
8837 gtk_widget_get_allocation (widget, &allocation);
8838 /* Need to really size allocate instead of just poking
8839 * into widget->allocation if the widget is not realized.
8840 * FIXME someone figure out why this was.
8842 if (!gtk_widget_get_realized (widget))
8844 if (gtk_widget_get_visible (widget))
8846 GdkRectangle tmp_rectangle = allocation;
8847 tmp_rectangle.x += scroll_data->dx;
8848 tmp_rectangle.y += scroll_data->dy;
8850 gtk_widget_size_allocate (widget, &tmp_rectangle);
8855 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8857 allocation.x += scroll_data->dx;
8858 allocation.y += scroll_data->dy;
8860 if (GTK_IS_CONTAINER (widget))
8861 gtk_container_forall (GTK_CONTAINER (widget),
8862 adjust_allocation_recurse,
8869 adjust_allocation (GtkWidget *widget,
8873 ScrollData scroll_data;
8875 if (gtk_widget_get_realized (widget))
8876 scroll_data.window = ALLOCATION_WINDOW (widget);
8878 scroll_data.window = NULL;
8880 scroll_data.dx = dx;
8881 scroll_data.dy = dy;
8883 adjust_allocation_recurse (widget, &scroll_data);
8887 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8891 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8892 PsppSheetView *tree_view)
8894 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8899 gdk_window_move (tree_view->priv->bin_window,
8900 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8901 TREE_VIEW_HEADER_HEIGHT (tree_view));
8902 gdk_window_move (tree_view->priv->header_window,
8903 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8905 dy = tree_view->priv->dy - (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8908 update_prelight (tree_view,
8909 tree_view->priv->event_last_x,
8910 tree_view->priv->event_last_y - dy);
8912 if (tree_view->priv->edited_column &&
8913 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8917 PsppSheetViewChild *child = NULL;
8919 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8920 adjust_allocation (widget, 0, dy);
8922 for (list = tree_view->priv->children; list; list = list->next)
8924 child = (PsppSheetViewChild *)list->data;
8925 if (child->widget == widget)
8933 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8935 if (tree_view->priv->dy != (int) gtk_adjustment_get_value (tree_view->priv->vadjustment))
8937 /* update our dy and top_row */
8938 tree_view->priv->dy = (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8940 if (!tree_view->priv->in_top_row_to_dy)
8941 pspp_sheet_view_dy_to_top_row (tree_view);
8944 for (list = tree_view->priv->columns; list; list = list->next)
8946 PsppSheetViewColumn *column = list->data;
8947 GtkAllocation *col_allocation = &column->allocation;
8948 GtkAllocation widget_allocation;
8949 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &widget_allocation);
8951 if (span_intersects (col_allocation->x, col_allocation->width,
8952 gtk_adjustment_get_value (tree_view->priv->hadjustment),
8953 widget_allocation.width))
8955 pspp_sheet_view_column_set_need_button (column, TRUE);
8956 if (!column->button)
8957 pspp_sheet_view_column_update_button (column);
8969 * pspp_sheet_view_new:
8971 * Creates a new #PsppSheetView widget.
8973 * Return value: A newly created #PsppSheetView widget.
8976 pspp_sheet_view_new (void)
8978 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8982 * pspp_sheet_view_new_with_model:
8983 * @model: the model.
8985 * Creates a new #PsppSheetView widget with the model initialized to @model.
8987 * Return value: A newly created #PsppSheetView widget.
8990 pspp_sheet_view_new_with_model (GtkTreeModel *model)
8992 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
8999 * pspp_sheet_view_get_model:
9000 * @tree_view: a #PsppSheetView
9002 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
9005 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
9008 pspp_sheet_view_get_model (PsppSheetView *tree_view)
9010 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9012 return tree_view->priv->model;
9016 * pspp_sheet_view_set_model:
9017 * @tree_view: A #GtkTreeNode.
9018 * @model: (allow-none): The model.
9020 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
9021 * set, it will remove it before setting the new model. If @model is %NULL,
9022 * then it will unset the old model.
9025 pspp_sheet_view_set_model (PsppSheetView *tree_view,
9026 GtkTreeModel *model)
9028 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9029 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
9031 if (model == tree_view->priv->model)
9034 if (tree_view->priv->scroll_to_path)
9036 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9037 tree_view->priv->scroll_to_path = NULL;
9040 if (tree_view->priv->model)
9042 GList *tmplist = tree_view->priv->columns;
9044 if (tree_view->priv->selected)
9045 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
9046 pspp_sheet_view_stop_editing (tree_view, TRUE);
9048 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9049 pspp_sheet_view_row_changed,
9051 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9052 pspp_sheet_view_row_inserted,
9054 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9055 pspp_sheet_view_row_deleted,
9057 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9058 pspp_sheet_view_rows_reordered,
9061 for (; tmplist; tmplist = tmplist->next)
9062 _pspp_sheet_view_column_unset_model (tmplist->data,
9063 tree_view->priv->model);
9065 tree_view->priv->prelight_node = -1;
9067 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
9068 tree_view->priv->drag_dest_row = NULL;
9069 gtk_tree_row_reference_free (tree_view->priv->cursor);
9070 tree_view->priv->cursor = NULL;
9071 gtk_tree_row_reference_free (tree_view->priv->anchor);
9072 tree_view->priv->anchor = NULL;
9073 gtk_tree_row_reference_free (tree_view->priv->top_row);
9074 tree_view->priv->top_row = NULL;
9075 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9076 tree_view->priv->scroll_to_path = NULL;
9078 tree_view->priv->scroll_to_column = NULL;
9080 g_object_unref (tree_view->priv->model);
9082 tree_view->priv->search_column = -1;
9083 tree_view->priv->fixed_height = -1;
9084 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
9085 tree_view->priv->last_button_x = -1;
9086 tree_view->priv->last_button_y = -1;
9089 tree_view->priv->model = model;
9091 if (tree_view->priv->model)
9095 if (tree_view->priv->search_column == -1)
9097 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
9099 GType type = gtk_tree_model_get_column_type (model, i);
9101 if (g_value_type_transformable (type, G_TYPE_STRING))
9103 tree_view->priv->search_column = i;
9109 g_object_ref (tree_view->priv->model);
9110 g_signal_connect (tree_view->priv->model,
9112 G_CALLBACK (pspp_sheet_view_row_changed),
9114 g_signal_connect (tree_view->priv->model,
9116 G_CALLBACK (pspp_sheet_view_row_inserted),
9118 g_signal_connect (tree_view->priv->model,
9120 G_CALLBACK (pspp_sheet_view_row_deleted),
9122 g_signal_connect (tree_view->priv->model,
9124 G_CALLBACK (pspp_sheet_view_rows_reordered),
9127 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
9129 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
9130 install_presize_handler (tree_view);
9133 g_object_notify (G_OBJECT (tree_view), "model");
9135 if (tree_view->priv->selection)
9136 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
9138 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9139 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9143 * pspp_sheet_view_get_selection:
9144 * @tree_view: A #PsppSheetView.
9146 * Gets the #PsppSheetSelection associated with @tree_view.
9148 * Return value: A #PsppSheetSelection object.
9150 PsppSheetSelection *
9151 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
9153 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9155 return tree_view->priv->selection;
9159 * pspp_sheet_view_get_hadjustment:
9160 * @tree_view: A #PsppSheetView
9162 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
9164 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9168 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
9170 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9172 if (tree_view->priv->hadjustment == NULL)
9173 pspp_sheet_view_set_hadjustment (tree_view, NULL);
9175 return tree_view->priv->hadjustment;
9179 * pspp_sheet_view_set_hadjustment:
9180 * @tree_view: A #PsppSheetView
9181 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9183 * Sets the #GtkAdjustment for the current horizontal aspect.
9186 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
9187 GtkAdjustment *adjustment)
9189 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9191 pspp_sheet_view_set_adjustments (tree_view,
9193 tree_view->priv->vadjustment);
9195 g_object_notify (G_OBJECT (tree_view), "hadjustment");
9199 * pspp_sheet_view_get_vadjustment:
9200 * @tree_view: A #PsppSheetView
9202 * Gets the #GtkAdjustment currently being used for the vertical aspect.
9204 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9208 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
9210 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9212 if (tree_view->priv->vadjustment == NULL)
9213 pspp_sheet_view_set_vadjustment (tree_view, NULL);
9215 return tree_view->priv->vadjustment;
9219 * pspp_sheet_view_set_vadjustment:
9220 * @tree_view: A #PsppSheetView
9221 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9223 * Sets the #GtkAdjustment for the current vertical aspect.
9226 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
9227 GtkAdjustment *adjustment)
9229 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9231 pspp_sheet_view_set_adjustments (tree_view,
9232 tree_view->priv->hadjustment,
9235 g_object_notify (G_OBJECT (tree_view), "vadjustment");
9238 /* Column and header operations */
9241 * pspp_sheet_view_get_headers_visible:
9242 * @tree_view: A #PsppSheetView.
9244 * Returns %TRUE if the headers on the @tree_view are visible.
9246 * Return value: Whether the headers are visible or not.
9249 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
9251 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9253 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9257 * pspp_sheet_view_set_headers_visible:
9258 * @tree_view: A #PsppSheetView.
9259 * @headers_visible: %TRUE if the headers are visible
9261 * Sets the visibility state of the headers.
9264 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
9265 gboolean headers_visible)
9269 PsppSheetViewColumn *column;
9270 GtkAllocation allocation;
9272 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9274 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
9276 headers_visible = !! headers_visible;
9278 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
9281 if (headers_visible)
9282 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9284 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9286 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9288 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
9289 if (headers_visible)
9291 gdk_window_move_resize (tree_view->priv->bin_window, x, y + TREE_VIEW_HEADER_HEIGHT (tree_view),
9292 tree_view->priv->width, allocation.height - + TREE_VIEW_HEADER_HEIGHT (tree_view));
9294 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9295 pspp_sheet_view_map_buttons (tree_view);
9299 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9301 for (list = tree_view->priv->columns; list; list = list->next)
9303 column = list->data;
9305 gtk_widget_unmap (column->button);
9307 gdk_window_hide (tree_view->priv->header_window);
9311 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view));
9312 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, (allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2);
9313 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
9314 gtk_adjustment_set_upper (tree_view->priv->vadjustment, tree_view->priv->height);
9315 gtk_adjustment_changed (tree_view->priv->vadjustment);
9317 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9319 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9323 * pspp_sheet_view_columns_autosize:
9324 * @tree_view: A #PsppSheetView.
9326 * Resizes all columns to their optimal width. Only works after the
9327 * treeview has been realized.
9330 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9332 gboolean dirty = FALSE;
9334 PsppSheetViewColumn *column;
9336 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9338 for (list = tree_view->priv->columns; list; list = list->next)
9340 column = list->data;
9341 _pspp_sheet_view_column_cell_set_dirty (column);
9346 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9350 * pspp_sheet_view_set_headers_clickable:
9351 * @tree_view: A #PsppSheetView.
9352 * @setting: %TRUE if the columns are clickable.
9354 * Allow the column title buttons to be clicked.
9357 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9362 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9364 for (list = tree_view->priv->columns; list; list = list->next)
9365 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9367 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9372 * pspp_sheet_view_get_headers_clickable:
9373 * @tree_view: A #PsppSheetView.
9375 * Returns whether all header columns are clickable.
9377 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9382 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9386 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9388 for (list = tree_view->priv->columns; list; list = list->next)
9389 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9396 * pspp_sheet_view_set_rules_hint
9397 * @tree_view: a #PsppSheetView
9398 * @setting: %TRUE if the tree requires reading across rows
9400 * This function tells GTK+ that the user interface for your
9401 * application requires users to read across tree rows and associate
9402 * cells with one another. By default, GTK+ will then render the tree
9403 * with alternating row colors. Do <emphasis>not</emphasis> use it
9404 * just because you prefer the appearance of the ruled tree; that's a
9405 * question for the theme. Some themes will draw tree rows in
9406 * alternating colors even when rules are turned off, and users who
9407 * prefer that appearance all the time can choose those themes. You
9408 * should call this function only as a <emphasis>semantic</emphasis>
9409 * hint to the theme engine that your tree makes alternating colors
9410 * useful from a functional standpoint (since it has lots of columns,
9415 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9418 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9420 setting = setting != FALSE;
9422 if (tree_view->priv->has_rules != setting)
9424 tree_view->priv->has_rules = setting;
9425 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9428 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9432 * pspp_sheet_view_get_rules_hint
9433 * @tree_view: a #PsppSheetView
9435 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9437 * Return value: %TRUE if rules are useful for the user of this tree
9440 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9442 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9444 return tree_view->priv->has_rules;
9447 /* Public Column functions
9451 * pspp_sheet_view_append_column:
9452 * @tree_view: A #PsppSheetView.
9453 * @column: The #PsppSheetViewColumn to add.
9455 * Appends @column to the list of columns.
9457 * Return value: The number of columns in @tree_view after appending.
9460 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9461 PsppSheetViewColumn *column)
9463 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9464 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9465 g_return_val_if_fail (column->tree_view == NULL, -1);
9467 return pspp_sheet_view_insert_column (tree_view, column, -1);
9472 * pspp_sheet_view_remove_column:
9473 * @tree_view: A #PsppSheetView.
9474 * @column: The #PsppSheetViewColumn to remove.
9476 * Removes @column from @tree_view.
9478 * Return value: The number of columns in @tree_view after removing.
9481 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9482 PsppSheetViewColumn *column)
9484 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9485 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9486 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9488 if (tree_view->priv->focus_column == column)
9489 tree_view->priv->focus_column = NULL;
9491 if (tree_view->priv->edited_column == column)
9493 pspp_sheet_view_stop_editing (tree_view, TRUE);
9495 /* no need to, but just to be sure ... */
9496 tree_view->priv->edited_column = NULL;
9499 _pspp_sheet_view_column_unset_tree_view (column);
9501 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9502 tree_view->priv->n_columns--;
9504 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9508 _pspp_sheet_view_column_unrealize_button (column);
9509 for (list = tree_view->priv->columns; list; list = list->next)
9511 PsppSheetViewColumn *tmp_column;
9513 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9514 if (tmp_column->visible)
9515 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9518 if (tree_view->priv->n_columns == 0 &&
9519 pspp_sheet_view_get_headers_visible (tree_view) &&
9520 tree_view->priv->header_window)
9521 gdk_window_hide (tree_view->priv->header_window);
9523 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9526 g_object_unref (column);
9527 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9529 return tree_view->priv->n_columns;
9533 * pspp_sheet_view_insert_column:
9534 * @tree_view: A #PsppSheetView.
9535 * @column: The #PsppSheetViewColumn to be inserted.
9536 * @position: The position to insert @column in.
9538 * This inserts the @column into the @tree_view at @position. If @position is
9539 * -1, then the column is inserted at the end.
9541 * Return value: The number of columns in @tree_view after insertion.
9544 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9545 PsppSheetViewColumn *column,
9548 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9549 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9550 g_return_val_if_fail (column->tree_view == NULL, -1);
9552 g_object_ref_sink (column);
9554 if (tree_view->priv->n_columns == 0 &&
9555 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9556 pspp_sheet_view_get_headers_visible (tree_view))
9558 gdk_window_show (tree_view->priv->header_window);
9561 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9563 tree_view->priv->n_columns++;
9565 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9567 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9571 _pspp_sheet_view_column_realize_button (column);
9573 for (list = tree_view->priv->columns; list; list = list->next)
9575 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9576 if (column->visible)
9577 _pspp_sheet_view_column_cell_set_dirty (column);
9579 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9582 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9584 return tree_view->priv->n_columns;
9588 * pspp_sheet_view_insert_column_with_attributes:
9589 * @tree_view: A #PsppSheetView
9590 * @position: The position to insert the new column in.
9591 * @title: The title to set the header to.
9592 * @cell: The #GtkCellRenderer.
9593 * @Varargs: A %NULL-terminated list of attributes.
9595 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9596 * @position. If @position is -1, then the newly created column is inserted at
9597 * the end. The column is initialized with the attributes given.
9599 * Return value: The number of columns in @tree_view after insertion.
9602 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9605 GtkCellRenderer *cell,
9608 PsppSheetViewColumn *column;
9613 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9615 column = pspp_sheet_view_column_new ();
9616 pspp_sheet_view_column_set_title (column, title);
9617 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9619 va_start (args, cell);
9621 attribute = va_arg (args, gchar *);
9623 while (attribute != NULL)
9625 column_id = va_arg (args, gint);
9626 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9627 attribute = va_arg (args, gchar *);
9632 pspp_sheet_view_insert_column (tree_view, column, position);
9634 return tree_view->priv->n_columns;
9638 * pspp_sheet_view_insert_column_with_data_func:
9639 * @tree_view: a #PsppSheetView
9640 * @position: Position to insert, -1 for append
9641 * @title: column title
9642 * @cell: cell renderer for column
9643 * @func: function to set attributes of cell renderer
9644 * @data: data for @func
9645 * @dnotify: destroy notifier for @data
9647 * Convenience function that inserts a new column into the #PsppSheetView
9648 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9649 * attributes (normally using data from the model). See also
9650 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9652 * Return value: number of columns in the tree view post-insert
9655 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9658 GtkCellRenderer *cell,
9659 PsppSheetCellDataFunc func,
9661 GDestroyNotify dnotify)
9663 PsppSheetViewColumn *column;
9665 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9667 column = pspp_sheet_view_column_new ();
9668 pspp_sheet_view_column_set_title (column, title);
9669 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9670 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9672 pspp_sheet_view_insert_column (tree_view, column, position);
9674 return tree_view->priv->n_columns;
9678 * pspp_sheet_view_get_column:
9679 * @tree_view: A #PsppSheetView.
9680 * @n: The position of the column, counting from 0.
9682 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9684 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9687 PsppSheetViewColumn *
9688 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9691 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9693 if (n < 0 || n >= tree_view->priv->n_columns)
9696 if (tree_view->priv->columns == NULL)
9699 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9703 * pspp_sheet_view_get_columns:
9704 * @tree_view: A #PsppSheetView
9706 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9707 * The returned list must be freed with g_list_free ().
9709 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9712 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9714 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9716 return g_list_copy (tree_view->priv->columns);
9720 * pspp_sheet_view_move_column_after:
9721 * @tree_view: A #PsppSheetView
9722 * @column: The #PsppSheetViewColumn to be moved.
9723 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9725 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9726 * @column is placed in the first position.
9729 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9730 PsppSheetViewColumn *column,
9731 PsppSheetViewColumn *base_column)
9733 GList *column_list_el, *base_el = NULL;
9735 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9737 column_list_el = g_list_find (tree_view->priv->columns, column);
9738 g_return_if_fail (column_list_el != NULL);
9742 base_el = g_list_find (tree_view->priv->columns, base_column);
9743 g_return_if_fail (base_el != NULL);
9746 if (column_list_el->prev == base_el)
9749 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9750 if (base_el == NULL)
9752 column_list_el->prev = NULL;
9753 column_list_el->next = tree_view->priv->columns;
9754 if (column_list_el->next)
9755 column_list_el->next->prev = column_list_el;
9756 tree_view->priv->columns = column_list_el;
9760 column_list_el->prev = base_el;
9761 column_list_el->next = base_el->next;
9762 if (column_list_el->next)
9763 column_list_el->next->prev = column_list_el;
9764 base_el->next = column_list_el;
9767 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9769 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9770 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9773 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9777 * pspp_sheet_view_set_column_drag_function:
9778 * @tree_view: A #PsppSheetView.
9779 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9780 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9781 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9783 * Sets a user function for determining where a column may be dropped when
9784 * dragged. This function is called on every column pair in turn at the
9785 * beginning of a column drag to determine where a drop can take place. The
9786 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9787 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9788 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9789 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9790 * @tree_view reverts to the default behavior of allowing all columns to be
9791 * dropped everywhere.
9794 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9795 PsppSheetViewColumnDropFunc func,
9797 GDestroyNotify destroy)
9799 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9801 if (tree_view->priv->column_drop_func_data_destroy)
9802 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9804 tree_view->priv->column_drop_func = func;
9805 tree_view->priv->column_drop_func_data = user_data;
9806 tree_view->priv->column_drop_func_data_destroy = destroy;
9810 * pspp_sheet_view_scroll_to_point:
9811 * @tree_view: a #PsppSheetView
9812 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9813 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9815 * Scrolls the tree view such that the top-left corner of the visible
9816 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9817 * in tree coordinates. The @tree_view must be realized before
9818 * this function is called. If it isn't, you probably want to be
9819 * using pspp_sheet_view_scroll_to_cell().
9821 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9824 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9828 GtkAdjustment *hadj;
9829 GtkAdjustment *vadj;
9831 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9832 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9834 hadj = tree_view->priv->hadjustment;
9835 vadj = tree_view->priv->vadjustment;
9838 gtk_adjustment_set_value (hadj, CLAMP (tree_x, gtk_adjustment_get_lower (hadj), gtk_adjustment_get_upper (hadj) - gtk_adjustment_get_page_size (hadj)));
9840 gtk_adjustment_set_value (vadj, CLAMP (tree_y, gtk_adjustment_get_lower (vadj), gtk_adjustment_get_upper (vadj) - gtk_adjustment_get_page_size (vadj)));
9844 * pspp_sheet_view_scroll_to_cell:
9845 * @tree_view: A #PsppSheetView.
9846 * @path: (allow-none): The path of the row to move to, or %NULL.
9847 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9848 * @use_align: whether to use alignment arguments, or %FALSE.
9849 * @row_align: The vertical alignment of the row specified by @path.
9850 * @col_align: The horizontal alignment of the column specified by @column.
9852 * Moves the alignments of @tree_view to the position specified by @column and
9853 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9854 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9855 * or @path need to be non-%NULL. @row_align determines where the row is
9856 * placed, and @col_align determines where @column is placed. Both are expected
9857 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9858 * right/bottom alignment, 0.5 means center.
9860 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9861 * tree does the minimum amount of work to scroll the cell onto the screen.
9862 * This means that the cell will be scrolled to the edge closest to its current
9863 * position. If the cell is currently visible on the screen, nothing is done.
9865 * This function only works if the model is set, and @path is a valid row on the
9866 * model. If the model changes before the @tree_view is realized, the centered
9867 * path will be modified to reflect this change.
9870 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9872 PsppSheetViewColumn *column,
9877 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9878 g_return_if_fail (tree_view->priv->model != NULL);
9879 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9880 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9881 g_return_if_fail (path != NULL || column != NULL);
9884 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9885 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9887 row_align = CLAMP (row_align, 0.0, 1.0);
9888 col_align = CLAMP (col_align, 0.0, 1.0);
9891 /* Note: Despite the benefits that come from having one code path for the
9892 * scrolling code, we short-circuit validate_visible_area's immplementation as
9893 * it is much slower than just going to the point.
9895 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9896 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9897 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9899 if (tree_view->priv->scroll_to_path)
9900 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9902 tree_view->priv->scroll_to_path = NULL;
9903 tree_view->priv->scroll_to_column = NULL;
9906 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9908 tree_view->priv->scroll_to_column = column;
9909 tree_view->priv->scroll_to_use_align = use_align;
9910 tree_view->priv->scroll_to_row_align = row_align;
9911 tree_view->priv->scroll_to_col_align = col_align;
9913 install_presize_handler (tree_view);
9917 GdkRectangle cell_rect;
9918 GdkRectangle vis_rect;
9919 gint dest_x, dest_y;
9921 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9922 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9924 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9926 dest_x = vis_rect.x;
9927 dest_y = vis_rect.y;
9933 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9937 if (cell_rect.x < vis_rect.x)
9938 dest_x = cell_rect.x;
9939 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9940 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9948 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9949 dest_y = MAX (dest_y, 0);
9953 if (cell_rect.y < vis_rect.y)
9954 dest_y = cell_rect.y;
9955 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9956 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9960 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9965 * pspp_sheet_view_row_activated:
9966 * @tree_view: A #PsppSheetView
9967 * @path: The #GtkTreePath to be activated.
9968 * @column: The #PsppSheetViewColumn to be activated.
9970 * Activates the cell determined by @path and @column.
9973 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9975 PsppSheetViewColumn *column)
9977 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9979 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
9984 * pspp_sheet_view_get_reorderable:
9985 * @tree_view: a #PsppSheetView
9987 * Retrieves whether the user can reorder the tree via drag-and-drop. See
9988 * pspp_sheet_view_set_reorderable().
9990 * Return value: %TRUE if the tree can be reordered.
9993 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
9995 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9997 return tree_view->priv->reorderable;
10001 * pspp_sheet_view_set_reorderable:
10002 * @tree_view: A #PsppSheetView.
10003 * @reorderable: %TRUE, if the tree can be reordered.
10005 * This function is a convenience function to allow you to reorder
10006 * models that support the #GtkDragSourceIface and the
10007 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
10008 * these. If @reorderable is %TRUE, then the user can reorder the
10009 * model by dragging and dropping rows. The developer can listen to
10010 * these changes by connecting to the model's row_inserted and
10011 * row_deleted signals. The reordering is implemented by setting up
10012 * the tree view as a drag source and destination. Therefore, drag and
10013 * drop can not be used in a reorderable view for any other purpose.
10015 * This function does not give you any degree of control over the order -- any
10016 * reordering is allowed. If more control is needed, you should probably
10017 * handle drag and drop manually.
10020 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
10021 gboolean reorderable)
10023 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10025 reorderable = reorderable != FALSE;
10027 if (tree_view->priv->reorderable == reorderable)
10032 const GtkTargetEntry row_targets[] = {
10033 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
10036 pspp_sheet_view_enable_model_drag_source (tree_view,
10039 G_N_ELEMENTS (row_targets),
10041 pspp_sheet_view_enable_model_drag_dest (tree_view,
10043 G_N_ELEMENTS (row_targets),
10048 pspp_sheet_view_unset_rows_drag_source (tree_view);
10049 pspp_sheet_view_unset_rows_drag_dest (tree_view);
10052 tree_view->priv->reorderable = reorderable;
10054 g_object_notify (G_OBJECT (tree_view), "reorderable");
10057 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
10058 is pressed, other rows will be unselected.
10060 If CLAMP_NODE is true, then the sheetview will scroll to make the row
10063 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
10065 gboolean clear_and_select,
10066 gboolean clamp_node,
10067 PsppSheetSelectMode mode)
10071 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10073 GtkTreePath *cursor_path;
10074 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10075 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
10076 gtk_tree_path_free (cursor_path);
10079 gtk_tree_row_reference_free (tree_view->priv->cursor);
10080 tree_view->priv->cursor = NULL;
10082 _pspp_sheet_view_find_node (tree_view, path, &node);
10083 tree_view->priv->cursor =
10084 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
10085 tree_view->priv->model,
10088 if (tree_view->priv->row_count > 0)
10092 if (clear_and_select && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
10093 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
10097 /* We have to re-find tree and node here again, somebody might have
10098 * cleared the node or the whole tree in the PsppSheetSelection::changed
10099 * callback. If the nodes differ we bail out here.
10101 _pspp_sheet_view_find_node (tree_view, path, &new_node);
10103 if (node != new_node)
10108 pspp_sheet_view_clamp_node_visible (tree_view, node);
10109 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10113 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
10117 * pspp_sheet_view_get_cursor:
10118 * @tree_view: A #PsppSheetView
10119 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
10120 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
10122 * Fills in @path and @focus_column with the current path and focus column. If
10123 * the cursor isn't currently set, then *@path will be %NULL. If no column
10124 * currently has focus, then *@focus_column will be %NULL.
10126 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
10127 * you are done with it.
10130 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
10131 GtkTreePath **path,
10132 PsppSheetViewColumn **focus_column)
10134 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10138 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10139 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10146 *focus_column = tree_view->priv->focus_column;
10151 * pspp_sheet_view_set_cursor:
10152 * @tree_view: A #PsppSheetView
10153 * @path: A #GtkTreePath
10154 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10155 * @start_editing: %TRUE if the specified cell should start being edited.
10157 * Sets the current keyboard focus to be at @path, and selects it. This is
10158 * useful when you want to focus the user's attention on a particular row. If
10159 * @focus_column is not %NULL, then focus is given to the column specified by
10160 * it. Additionally, if @focus_column is specified, and @start_editing is
10161 * %TRUE, then editing should be started in the specified cell.
10162 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
10163 * in order to give keyboard focus to the widget. Please note that editing
10164 * can only happen when the widget is realized.
10166 * If @path is invalid for @model, the current cursor (if any) will be unset
10167 * and the function will return without failing.
10170 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
10172 PsppSheetViewColumn *focus_column,
10173 gboolean start_editing)
10175 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
10176 NULL, start_editing);
10180 * pspp_sheet_view_set_cursor_on_cell:
10181 * @tree_view: A #PsppSheetView
10182 * @path: A #GtkTreePath
10183 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10184 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
10185 * @start_editing: %TRUE if the specified cell should start being edited.
10187 * Sets the current keyboard focus to be at @path, and selects it. This is
10188 * useful when you want to focus the user's attention on a particular row. If
10189 * @focus_column is not %NULL, then focus is given to the column specified by
10190 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
10191 * contains 2 or more editable or activatable cells, then focus is given to
10192 * the cell specified by @focus_cell. Additionally, if @focus_column is
10193 * specified, and @start_editing is %TRUE, then editing should be started in
10194 * the specified cell. This function is often followed by
10195 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
10196 * widget. Please note that editing can only happen when the widget is
10199 * If @path is invalid for @model, the current cursor (if any) will be unset
10200 * and the function will return without failing.
10205 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
10207 PsppSheetViewColumn *focus_column,
10208 GtkCellRenderer *focus_cell,
10209 gboolean start_editing)
10211 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10212 g_return_if_fail (path != NULL);
10213 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
10215 if (!tree_view->priv->model)
10220 g_return_if_fail (focus_column);
10221 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
10224 /* cancel the current editing, if it exists */
10225 if (tree_view->priv->edited_column &&
10226 tree_view->priv->edited_column->editable_widget)
10227 pspp_sheet_view_stop_editing (tree_view, TRUE);
10229 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
10231 if (focus_column && focus_column->visible)
10234 gboolean column_in_tree = FALSE;
10236 for (list = tree_view->priv->columns; list; list = list->next)
10237 if (list->data == focus_column)
10239 column_in_tree = TRUE;
10242 g_return_if_fail (column_in_tree);
10243 tree_view->priv->focus_column = focus_column;
10245 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
10247 pspp_sheet_view_start_editing (tree_view, path);
10249 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
10250 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
10256 * pspp_sheet_view_get_bin_window:
10257 * @tree_view: A #PsppSheetView
10259 * Returns the window that @tree_view renders to. This is used primarily to
10260 * compare to <literal>event->window</literal> to confirm that the event on
10261 * @tree_view is on the right window.
10263 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
10266 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
10268 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
10270 return tree_view->priv->bin_window;
10274 * pspp_sheet_view_get_path_at_pos:
10275 * @tree_view: A #PsppSheetView.
10276 * @x: The x position to be identified (relative to bin_window).
10277 * @y: The y position to be identified (relative to bin_window).
10278 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
10279 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
10280 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
10281 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
10283 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10284 * (please see pspp_sheet_view_get_bin_window()).
10285 * That is, @x and @y are relative to an events coordinates. @x and @y must
10286 * come from an event on the @tree_view only where <literal>event->window ==
10287 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10288 * things like popup menus. If @path is non-%NULL, then it will be filled
10289 * with the #GtkTreePath at that point. This path should be freed with
10290 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10291 * with the column at that point. @cell_x and @cell_y return the coordinates
10292 * relative to the cell background (i.e. the @background_area passed to
10293 * gtk_cell_renderer_render()). This function is only meaningful if
10294 * @tree_view is realized. Therefore this function will always return %FALSE
10295 * if @tree_view is not realized or does not have a model.
10297 * For converting widget coordinates (eg. the ones you get from
10298 * GtkWidget::query-tooltip), please see
10299 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10301 * Return value: %TRUE if a row exists at that coordinate.
10304 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10307 GtkTreePath **path,
10308 PsppSheetViewColumn **column,
10315 g_return_val_if_fail (tree_view != NULL, FALSE);
10322 if (tree_view->priv->bin_window == NULL)
10325 if (tree_view->priv->row_count == 0)
10328 if (x > gtk_adjustment_get_upper (tree_view->priv->hadjustment))
10331 if (x < 0 || y < 0)
10334 if (column || cell_x)
10336 PsppSheetViewColumn *tmp_column;
10337 PsppSheetViewColumn *last_column = NULL;
10339 gint remaining_x = x;
10340 gboolean found = FALSE;
10343 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10344 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10346 list = (rtl ? list->prev : list->next))
10348 tmp_column = list->data;
10350 if (tmp_column->visible == FALSE)
10353 last_column = tmp_column;
10354 if (remaining_x <= tmp_column->width)
10359 *column = tmp_column;
10362 *cell_x = remaining_x;
10366 remaining_x -= tmp_column->width;
10369 /* If found is FALSE and there is a last_column, then it the remainder
10370 * space is in that area
10377 *column = last_column;
10380 *cell_x = last_column->width + remaining_x;
10389 y_offset = pspp_sheet_view_find_offset (tree_view,
10390 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10397 *cell_y = y_offset;
10400 *path = _pspp_sheet_view_find_path (tree_view, node);
10405 /* Computes 'cell_area' from 'background_area', which must be the background
10406 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10407 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10408 the cell area as passed to _pspp_sheet_view_column_cell_render().
10410 'column' is required to properly adjust 'cell_area->x' and
10411 'cell_area->width'. It may be set to NULL if these values are not of
10412 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10415 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10416 PsppSheetViewColumn *column,
10417 const GdkRectangle *background_area,
10418 gboolean subtract_focus_rect,
10419 GdkRectangle *cell_area)
10421 gint vertical_separator;
10422 gint horizontal_separator;
10424 *cell_area = *background_area;
10426 gtk_widget_style_get (GTK_WIDGET (tree_view),
10427 "vertical-separator", &vertical_separator,
10428 "horizontal-separator", &horizontal_separator,
10430 cell_area->x += horizontal_separator / 2;
10431 cell_area->y += vertical_separator / 2;
10432 cell_area->width -= horizontal_separator;
10433 cell_area->height -= vertical_separator;
10435 if (subtract_focus_rect)
10437 int focus_line_width;
10439 gtk_widget_style_get (GTK_WIDGET (tree_view),
10440 "focus-line-width", &focus_line_width,
10442 cell_area->x += focus_line_width;
10443 cell_area->y += focus_line_width;
10444 cell_area->width -= 2 * focus_line_width;
10445 cell_area->height -= 2 * focus_line_width;
10448 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10450 gint grid_line_width;
10451 gtk_widget_style_get (GTK_WIDGET (tree_view),
10452 "grid-line-width", &grid_line_width,
10455 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10456 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10459 PsppSheetViewColumn *first_column, *last_column;
10462 /* Find the last visible column. */
10463 last_column = NULL;
10464 for (list = g_list_last (tree_view->priv->columns);
10468 PsppSheetViewColumn *c = list->data;
10476 /* Find the first visible column. */
10477 first_column = NULL;
10478 for (list = g_list_first (tree_view->priv->columns);
10482 PsppSheetViewColumn *c = list->data;
10490 if (column == first_column)
10492 cell_area->width -= grid_line_width / 2;
10494 else if (column == last_column)
10496 cell_area->x += grid_line_width / 2;
10497 cell_area->width -= grid_line_width / 2;
10501 cell_area->x += grid_line_width / 2;
10502 cell_area->width -= grid_line_width;
10506 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10507 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10509 cell_area->y += grid_line_width / 2;
10510 cell_area->height -= grid_line_width;
10514 if (column == NULL)
10517 cell_area->width = 0;
10522 * pspp_sheet_view_get_cell_area:
10523 * @tree_view: a #PsppSheetView
10524 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10525 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10526 * @rect: rectangle to fill with cell rect
10528 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10529 * row specified by @path and the column specified by @column. If @path is
10530 * %NULL, or points to a path not currently displayed, the @y and @height fields
10531 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10532 * fields will be filled with 0. The sum of all cell rects does not cover the
10533 * entire tree; there are extra pixels in between rows, for example. The
10534 * returned rectangle is equivalent to the @cell_area passed to
10535 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10539 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10541 PsppSheetViewColumn *column,
10542 GdkRectangle *rect)
10544 GdkRectangle background_area;
10546 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10547 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10548 g_return_if_fail (rect != NULL);
10549 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10550 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10552 pspp_sheet_view_get_background_area (tree_view, path, column,
10554 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10559 * pspp_sheet_view_get_background_area:
10560 * @tree_view: a #PsppSheetView
10561 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10562 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10563 * @rect: rectangle to fill with cell background rect
10565 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10566 * row specified by @path and the column specified by @column. If @path is
10567 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10568 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10569 * fields will be filled with 0. The returned rectangle is equivalent to the
10570 * @background_area passed to gtk_cell_renderer_render(). These background
10571 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10572 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10573 * itself, excluding surrounding borders.
10577 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10579 PsppSheetViewColumn *column,
10580 GdkRectangle *rect)
10584 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10585 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10586 g_return_if_fail (rect != NULL);
10595 /* Get vertical coords */
10597 _pspp_sheet_view_find_node (tree_view, path, &node);
10601 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10603 rect->height = ROW_HEIGHT (tree_view);
10610 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10611 rect->width = x2 - rect->x;
10616 * pspp_sheet_view_get_visible_rect:
10617 * @tree_view: a #PsppSheetView
10618 * @visible_rect: rectangle to fill
10620 * Fills @visible_rect with the currently-visible region of the
10621 * buffer, in tree coordinates. Convert to bin_window coordinates with
10622 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10623 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10624 * scrollable area of the tree.
10627 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10628 GdkRectangle *visible_rect)
10632 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10634 widget = GTK_WIDGET (tree_view);
10638 GtkAllocation allocation;
10639 gtk_widget_get_allocation (widget, &allocation);
10640 visible_rect->x = gtk_adjustment_get_value (tree_view->priv->hadjustment);
10641 visible_rect->y = gtk_adjustment_get_value (tree_view->priv->vadjustment);
10642 visible_rect->width = allocation.width;
10643 visible_rect->height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10648 * pspp_sheet_view_widget_to_tree_coords:
10649 * @tree_view: a #PsppSheetView
10650 * @wx: X coordinate relative to bin_window
10651 * @wy: Y coordinate relative to bin_window
10652 * @tx: return location for tree X coordinate
10653 * @ty: return location for tree Y coordinate
10655 * Converts bin_window coordinates to coordinates for the
10656 * tree (the full scrollable area of the tree).
10658 * Deprecated: 2.12: Due to historial reasons the name of this function is
10659 * incorrect. For converting coordinates relative to the widget to
10660 * bin_window coordinates, please see
10661 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10665 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10671 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10674 *tx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10676 *ty = wy + tree_view->priv->dy;
10680 * pspp_sheet_view_tree_to_widget_coords:
10681 * @tree_view: a #PsppSheetView
10682 * @tx: tree X coordinate
10683 * @ty: tree Y coordinate
10684 * @wx: return location for X coordinate relative to bin_window
10685 * @wy: return location for Y coordinate relative to bin_window
10687 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10688 * to bin_window coordinates.
10690 * Deprecated: 2.12: Due to historial reasons the name of this function is
10691 * incorrect. For converting bin_window coordinates to coordinates relative
10692 * to bin_window, please see
10693 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10697 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10703 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10706 *wx = tx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10708 *wy = ty - tree_view->priv->dy;
10713 * pspp_sheet_view_convert_widget_to_tree_coords:
10714 * @tree_view: a #PsppSheetView
10715 * @wx: X coordinate relative to the widget
10716 * @wy: Y coordinate relative to the widget
10717 * @tx: return location for tree X coordinate
10718 * @ty: return location for tree Y coordinate
10720 * Converts widget coordinates to coordinates for the
10721 * tree (the full scrollable area of the tree).
10726 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10734 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10736 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10739 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10745 * pspp_sheet_view_convert_tree_to_widget_coords:
10746 * @tree_view: a #PsppSheetView
10747 * @tx: X coordinate relative to the tree
10748 * @ty: Y coordinate relative to the tree
10749 * @wx: return location for widget X coordinate
10750 * @wy: return location for widget Y coordinate
10752 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10753 * to widget coordinates.
10758 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10766 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10768 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10771 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10777 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10778 * @tree_view: a #PsppSheetView
10779 * @wx: X coordinate relative to the widget
10780 * @wy: Y coordinate relative to the widget
10781 * @bx: return location for bin_window X coordinate
10782 * @by: return location for bin_window Y coordinate
10784 * Converts widget coordinates to coordinates for the bin_window
10785 * (see pspp_sheet_view_get_bin_window()).
10790 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10796 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10799 *bx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10801 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10805 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10806 * @tree_view: a #PsppSheetView
10807 * @bx: bin_window X coordinate
10808 * @by: bin_window Y coordinate
10809 * @wx: return location for widget X coordinate
10810 * @wy: return location for widget Y coordinate
10812 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10813 * to widget relative coordinates.
10818 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10824 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10827 *wx = bx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10829 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10833 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10834 * @tree_view: a #PsppSheetView
10835 * @tx: tree X coordinate
10836 * @ty: tree Y coordinate
10837 * @bx: return location for X coordinate relative to bin_window
10838 * @by: return location for Y coordinate relative to bin_window
10840 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10841 * to bin_window coordinates.
10846 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10852 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10857 *by = ty - tree_view->priv->dy;
10861 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10862 * @tree_view: a #PsppSheetView
10863 * @bx: X coordinate relative to bin_window
10864 * @by: Y coordinate relative to bin_window
10865 * @tx: return location for tree X coordinate
10866 * @ty: return location for tree Y coordinate
10868 * Converts bin_window coordinates to coordinates for the
10869 * tree (the full scrollable area of the tree).
10874 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10880 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10885 *ty = by + tree_view->priv->dy;
10891 * pspp_sheet_view_get_visible_range:
10892 * @tree_view: A #PsppSheetView
10893 * @start_path: (allow-none): Return location for start of region, or %NULL.
10894 * @end_path: (allow-none): Return location for end of region, or %NULL.
10896 * Sets @start_path and @end_path to be the first and last visible path.
10897 * Note that there may be invisible paths in between.
10899 * The paths should be freed with gtk_tree_path_free() after use.
10901 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10906 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10907 GtkTreePath **start_path,
10908 GtkTreePath **end_path)
10913 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10915 if (!tree_view->priv->row_count)
10922 pspp_sheet_view_find_offset (tree_view,
10923 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10926 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10935 if (tree_view->priv->height < gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
10936 y = tree_view->priv->height - 1;
10938 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, gtk_adjustment_get_page_size (tree_view->priv->vadjustment)) - 1;
10940 pspp_sheet_view_find_offset (tree_view, y, &node);
10942 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10951 unset_reorderable (PsppSheetView *tree_view)
10953 if (tree_view->priv->reorderable)
10955 tree_view->priv->reorderable = FALSE;
10956 g_object_notify (G_OBJECT (tree_view), "reorderable");
10961 * pspp_sheet_view_enable_model_drag_source:
10962 * @tree_view: a #PsppSheetView
10963 * @start_button_mask: Mask of allowed buttons to start drag
10964 * @targets: the table of targets that the drag will support
10965 * @n_targets: the number of items in @targets
10966 * @actions: the bitmask of possible actions for a drag from this
10969 * Turns @tree_view into a drag source for automatic DND. Calling this
10970 * method sets #PsppSheetView:reorderable to %FALSE.
10973 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10974 GdkModifierType start_button_mask,
10975 const GtkTargetEntry *targets,
10977 GdkDragAction actions)
10979 TreeViewDragInfo *di;
10981 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10983 gtk_drag_source_set (GTK_WIDGET (tree_view),
10989 di = ensure_info (tree_view);
10991 di->start_button_mask = start_button_mask;
10992 di->source_actions = actions;
10993 di->source_set = TRUE;
10995 unset_reorderable (tree_view);
10999 * pspp_sheet_view_enable_model_drag_dest:
11000 * @tree_view: a #PsppSheetView
11001 * @targets: the table of targets that the drag will support
11002 * @n_targets: the number of items in @targets
11003 * @actions: the bitmask of possible actions for a drag from this
11006 * Turns @tree_view into a drop destination for automatic DND. Calling
11007 * this method sets #PsppSheetView:reorderable to %FALSE.
11010 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
11011 const GtkTargetEntry *targets,
11013 GdkDragAction actions)
11015 TreeViewDragInfo *di;
11017 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11019 gtk_drag_dest_set (GTK_WIDGET (tree_view),
11025 di = ensure_info (tree_view);
11026 di->dest_set = TRUE;
11028 unset_reorderable (tree_view);
11032 * pspp_sheet_view_unset_rows_drag_source:
11033 * @tree_view: a #PsppSheetView
11035 * Undoes the effect of
11036 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
11037 * #PsppSheetView:reorderable to %FALSE.
11040 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
11042 TreeViewDragInfo *di;
11044 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11046 di = get_info (tree_view);
11050 if (di->source_set)
11052 gtk_drag_source_unset (GTK_WIDGET (tree_view));
11053 di->source_set = FALSE;
11056 if (!di->dest_set && !di->source_set)
11057 remove_info (tree_view);
11060 unset_reorderable (tree_view);
11064 * pspp_sheet_view_unset_rows_drag_dest:
11065 * @tree_view: a #PsppSheetView
11067 * Undoes the effect of
11068 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
11069 * #PsppSheetView:reorderable to %FALSE.
11072 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
11074 TreeViewDragInfo *di;
11076 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11078 di = get_info (tree_view);
11084 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
11085 di->dest_set = FALSE;
11088 if (!di->dest_set && !di->source_set)
11089 remove_info (tree_view);
11092 unset_reorderable (tree_view);
11096 * pspp_sheet_view_set_drag_dest_row:
11097 * @tree_view: a #PsppSheetView
11098 * @path: (allow-none): The path of the row to highlight, or %NULL.
11099 * @pos: Specifies whether to drop before, after or into the row
11101 * Sets the row that is highlighted for feedback.
11104 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
11106 PsppSheetViewDropPosition pos)
11108 GtkTreePath *current_dest;
11110 /* Note; this function is exported to allow a custom DND
11111 * implementation, so it can't touch TreeViewDragInfo
11114 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11116 current_dest = NULL;
11118 if (tree_view->priv->drag_dest_row)
11120 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11121 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
11124 /* special case a drop on an empty model */
11125 tree_view->priv->empty_view_drop = 0;
11127 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
11128 && gtk_tree_path_get_depth (path) == 1
11129 && gtk_tree_path_get_indices (path)[0] == 0)
11133 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
11137 tree_view->priv->empty_view_drop = 1;
11140 tree_view->priv->drag_dest_pos = pos;
11144 tree_view->priv->drag_dest_row =
11145 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
11146 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
11149 tree_view->priv->drag_dest_row = NULL;
11153 int node, new_node;
11155 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
11156 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
11160 new_node = pspp_sheet_view_node_next (tree_view, node);
11162 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11164 new_node = pspp_sheet_view_node_prev (tree_view, node);
11166 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11168 gtk_tree_path_free (current_dest);
11173 * pspp_sheet_view_get_drag_dest_row:
11174 * @tree_view: a #PsppSheetView
11175 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11176 * @pos: (allow-none): Return location for the drop position, or %NULL
11178 * Gets information about the row that is highlighted for feedback.
11181 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
11182 GtkTreePath **path,
11183 PsppSheetViewDropPosition *pos)
11185 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11189 if (tree_view->priv->drag_dest_row)
11190 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11193 if (tree_view->priv->empty_view_drop)
11194 *path = gtk_tree_path_new_from_indices (0, -1);
11201 *pos = tree_view->priv->drag_dest_pos;
11205 * pspp_sheet_view_get_dest_row_at_pos:
11206 * @tree_view: a #PsppSheetView
11207 * @drag_x: the position to determine the destination row for
11208 * @drag_y: the position to determine the destination row for
11209 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11210 * @pos: (allow-none): Return location for the drop position, or %NULL
11212 * Determines the destination row for a given position. @drag_x and
11213 * @drag_y are expected to be in widget coordinates. This function is only
11214 * meaningful if @tree_view is realized. Therefore this function will always
11215 * return %FALSE if @tree_view is not realized or does not have a model.
11217 * Return value: whether there is a row at the given position, %TRUE if this
11218 * is indeed the case.
11221 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
11224 GtkTreePath **path,
11225 PsppSheetViewDropPosition *pos)
11229 gdouble offset_into_row;
11232 PsppSheetViewColumn *column = NULL;
11233 GtkTreePath *tmp_path = NULL;
11235 /* Note; this function is exported to allow a custom DND
11236 * implementation, so it can't touch TreeViewDragInfo
11239 g_return_val_if_fail (tree_view != NULL, FALSE);
11240 g_return_val_if_fail (drag_x >= 0, FALSE);
11241 g_return_val_if_fail (drag_y >= 0, FALSE);
11246 if (tree_view->priv->bin_window == NULL)
11249 if (tree_view->priv->row_count == 0)
11252 /* If in the top third of a row, we drop before that row; if
11253 * in the bottom third, drop after that row; if in the middle,
11254 * and the row has children, drop into the row.
11256 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
11259 if (!pspp_sheet_view_get_path_at_pos (tree_view,
11268 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
11271 offset_into_row = cell_y;
11276 gtk_tree_path_free (tmp_path);
11280 third = cell.height / 3.0;
11284 if (offset_into_row < third)
11286 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11288 else if (offset_into_row < (cell.height / 2.0))
11290 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11292 else if (offset_into_row < third * 2.0)
11294 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11298 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11306 #if GTK3_TRANSITION
11307 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11309 * pspp_sheet_view_create_row_drag_icon:
11310 * @tree_view: a #PsppSheetView
11311 * @path: a #GtkTreePath in @tree_view
11313 * Creates a #GdkPixmap representation of the row at @path.
11314 * This image is used for a drag icon.
11316 * Return value: a newly-allocated pixmap of the drag icon.
11319 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11326 GdkRectangle background_area;
11327 GdkRectangle expose_area;
11329 /* start drawing inside the black outline */
11331 GdkDrawable *drawable;
11332 gint bin_window_width;
11335 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11336 g_return_val_if_fail (path != NULL, NULL);
11338 widget = GTK_WIDGET (tree_view);
11340 if (!gtk_widget_get_realized (widget))
11343 _pspp_sheet_view_find_node (tree_view,
11350 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11357 background_area.y = y;
11358 background_area.height = ROW_HEIGHT (tree_view);
11360 bin_window_width = gdk_window_get_width (tree_view->priv->bin_window);
11362 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11363 bin_window_width + 2,
11364 background_area.height + 2,
11369 expose_area.width = bin_window_width + 2;
11370 expose_area.height = background_area.height + 2;
11372 #if GTK3_TRANSITION
11373 gdk_draw_rectangle (drawable,
11374 widget->style->base_gc [gtk_widget_get_state (widget)],
11377 bin_window_width + 2,
11378 background_area.height + 2);
11381 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11383 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11385 list = (rtl ? list->prev : list->next))
11387 PsppSheetViewColumn *column = list->data;
11388 GdkRectangle cell_area;
11389 gint vertical_separator;
11391 if (!column->visible)
11394 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11396 background_area.x = cell_offset;
11397 background_area.width = column->width;
11399 gtk_widget_style_get (widget,
11400 "vertical-separator", &vertical_separator,
11403 cell_area = background_area;
11405 cell_area.y += vertical_separator / 2;
11406 cell_area.height -= vertical_separator;
11408 if (pspp_sheet_view_column_cell_is_visible (column))
11409 _pspp_sheet_view_column_cell_render (column,
11415 cell_offset += column->width;
11418 #if GTK3_TRANSITION
11419 gdk_draw_rectangle (drawable,
11420 widget->style->black_gc,
11423 bin_window_width + 1,
11424 background_area.height + 1);
11432 * pspp_sheet_view_set_destroy_count_func:
11433 * @tree_view: A #PsppSheetView
11434 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11435 * @data: (allow-none): User data to be passed to @func, or %NULL
11436 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11438 * This function should almost never be used. It is meant for private use by
11439 * ATK for determining the number of visible children that are removed when a row is deleted.
11442 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11443 PsppSheetDestroyCountFunc func,
11445 GDestroyNotify destroy)
11447 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11449 if (tree_view->priv->destroy_count_destroy)
11450 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11452 tree_view->priv->destroy_count_func = func;
11453 tree_view->priv->destroy_count_data = data;
11454 tree_view->priv->destroy_count_destroy = destroy;
11459 * Interactive search
11463 * pspp_sheet_view_set_enable_search:
11464 * @tree_view: A #PsppSheetView
11465 * @enable_search: %TRUE, if the user can search interactively
11467 * If @enable_search is set, then the user can type in text to search through
11468 * the tree interactively (this is sometimes called "typeahead find").
11470 * Note that even if this is %FALSE, the user can still initiate a search
11471 * using the "start-interactive-search" key binding.
11474 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11475 gboolean enable_search)
11477 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11479 enable_search = !!enable_search;
11481 if (tree_view->priv->enable_search != enable_search)
11483 tree_view->priv->enable_search = enable_search;
11484 g_object_notify (G_OBJECT (tree_view), "enable-search");
11489 * pspp_sheet_view_get_enable_search:
11490 * @tree_view: A #PsppSheetView
11492 * Returns whether or not the tree allows to start interactive searching
11493 * by typing in text.
11495 * Return value: whether or not to let the user search interactively
11498 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11500 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11502 return tree_view->priv->enable_search;
11507 * pspp_sheet_view_get_search_column:
11508 * @tree_view: A #PsppSheetView
11510 * Gets the column searched on by the interactive search code.
11512 * Return value: the column the interactive search code searches in.
11515 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11517 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11519 return (tree_view->priv->search_column);
11523 * pspp_sheet_view_set_search_column:
11524 * @tree_view: A #PsppSheetView
11525 * @column: the column of the model to search in, or -1 to disable searching
11527 * Sets @column as the column where the interactive search code should
11528 * search in for the current model.
11530 * If the search column is set, users can use the "start-interactive-search"
11531 * key binding to bring up search popup. The enable-search property controls
11532 * whether simply typing text will also start an interactive search.
11534 * Note that @column refers to a column of the current model. The search
11535 * column is reset to -1 when the model is changed.
11538 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11541 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11542 g_return_if_fail (column >= -1);
11544 if (tree_view->priv->search_column == column)
11547 tree_view->priv->search_column = column;
11548 g_object_notify (G_OBJECT (tree_view), "search-column");
11552 * pspp_sheet_view_get_search_equal_func:
11553 * @tree_view: A #PsppSheetView
11555 * Returns the compare function currently in use.
11557 * Return value: the currently used compare function for the search code.
11560 PsppSheetViewSearchEqualFunc
11561 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11563 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11565 return tree_view->priv->search_equal_func;
11569 * pspp_sheet_view_set_search_equal_func:
11570 * @tree_view: A #PsppSheetView
11571 * @search_equal_func: the compare function to use during the search
11572 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11573 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11575 * Sets the compare function for the interactive search capabilities; note
11576 * that somewhat like strcmp() returning 0 for equality
11577 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11580 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11581 PsppSheetViewSearchEqualFunc search_equal_func,
11582 gpointer search_user_data,
11583 GDestroyNotify search_destroy)
11585 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11586 g_return_if_fail (search_equal_func != NULL);
11588 if (tree_view->priv->search_destroy)
11589 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11591 tree_view->priv->search_equal_func = search_equal_func;
11592 tree_view->priv->search_user_data = search_user_data;
11593 tree_view->priv->search_destroy = search_destroy;
11594 if (tree_view->priv->search_equal_func == NULL)
11595 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11599 * pspp_sheet_view_get_search_entry:
11600 * @tree_view: A #PsppSheetView
11602 * Returns the #GtkEntry which is currently in use as interactive search
11603 * entry for @tree_view. In case the built-in entry is being used, %NULL
11604 * will be returned.
11606 * Return value: the entry currently in use as search entry.
11611 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11613 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11615 if (tree_view->priv->search_custom_entry_set)
11616 return GTK_ENTRY (tree_view->priv->search_entry);
11622 * pspp_sheet_view_set_search_entry:
11623 * @tree_view: A #PsppSheetView
11624 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11626 * Sets the entry which the interactive search code will use for this
11627 * @tree_view. This is useful when you want to provide a search entry
11628 * in our interface at all time at a fixed position. Passing %NULL for
11629 * @entry will make the interactive search code use the built-in popup
11635 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11638 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11639 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11641 if (tree_view->priv->search_custom_entry_set)
11643 if (tree_view->priv->search_entry_changed_id)
11645 g_signal_handler_disconnect (tree_view->priv->search_entry,
11646 tree_view->priv->search_entry_changed_id);
11647 tree_view->priv->search_entry_changed_id = 0;
11649 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11650 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11653 g_object_unref (tree_view->priv->search_entry);
11655 else if (tree_view->priv->search_window)
11657 gtk_widget_destroy (tree_view->priv->search_window);
11659 tree_view->priv->search_window = NULL;
11664 tree_view->priv->search_entry = g_object_ref (entry);
11665 tree_view->priv->search_custom_entry_set = TRUE;
11667 if (tree_view->priv->search_entry_changed_id == 0)
11669 tree_view->priv->search_entry_changed_id =
11670 g_signal_connect (tree_view->priv->search_entry, "changed",
11671 G_CALLBACK (pspp_sheet_view_search_init),
11675 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11676 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11679 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11683 tree_view->priv->search_entry = NULL;
11684 tree_view->priv->search_custom_entry_set = FALSE;
11689 * pspp_sheet_view_set_search_position_func:
11690 * @tree_view: A #PsppSheetView
11691 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11692 * to use the default search position function
11693 * @data: (allow-none): user data to pass to @func, or %NULL
11694 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11696 * Sets the function to use when positioning the search dialog.
11701 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11702 PsppSheetViewSearchPositionFunc func,
11703 gpointer user_data,
11704 GDestroyNotify destroy)
11706 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11708 if (tree_view->priv->search_position_destroy)
11709 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11711 tree_view->priv->search_position_func = func;
11712 tree_view->priv->search_position_user_data = user_data;
11713 tree_view->priv->search_position_destroy = destroy;
11714 if (tree_view->priv->search_position_func == NULL)
11715 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11719 * pspp_sheet_view_get_search_position_func:
11720 * @tree_view: A #PsppSheetView
11722 * Returns the positioning function currently in use.
11724 * Return value: the currently used function for positioning the search dialog.
11728 PsppSheetViewSearchPositionFunc
11729 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11731 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11733 return tree_view->priv->search_position_func;
11738 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11739 PsppSheetView *tree_view)
11741 if (tree_view->priv->disable_popdown)
11744 if (tree_view->priv->search_entry_changed_id)
11746 g_signal_handler_disconnect (tree_view->priv->search_entry,
11747 tree_view->priv->search_entry_changed_id);
11748 tree_view->priv->search_entry_changed_id = 0;
11750 if (tree_view->priv->typeselect_flush_timeout)
11752 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11753 tree_view->priv->typeselect_flush_timeout = 0;
11756 if (gtk_widget_get_visible (search_dialog))
11758 /* send focus-in event */
11759 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11760 gtk_widget_hide (search_dialog);
11761 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11762 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11767 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11768 GtkWidget *search_dialog,
11769 gpointer user_data)
11772 gint tree_x, tree_y;
11773 gint tree_width, tree_height;
11774 GdkWindow *tree_window = gtk_widget_get_window (GTK_WIDGET (tree_view));
11775 GdkScreen *screen = gdk_window_get_screen (tree_window);
11776 GtkRequisition requisition;
11778 GdkRectangle monitor;
11780 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11781 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11783 gtk_widget_realize (search_dialog);
11785 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11786 tree_width = gdk_window_get_width (tree_window);
11787 tree_height = gdk_window_get_height (tree_window);
11789 gtk_widget_size_request (search_dialog, &requisition);
11791 if (tree_x + tree_width > gdk_screen_get_width (screen))
11792 x = gdk_screen_get_width (screen) - requisition.width;
11793 else if (tree_x + tree_width - requisition.width < 0)
11796 x = tree_x + tree_width - requisition.width;
11798 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11799 y = gdk_screen_get_height (screen) - requisition.height;
11800 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11803 y = tree_y + tree_height;
11805 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11809 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11813 PsppSheetView *tree_view = (PsppSheetView *)data;
11815 tree_view->priv->disable_popdown = 1;
11816 g_signal_connect (menu, "hide",
11817 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11820 #if GTK3_TRANSITION
11821 /* Because we're visible but offscreen, we just set a flag in the preedit
11825 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11826 PsppSheetView *tree_view)
11828 tree_view->priv->imcontext_changed = 1;
11829 if (tree_view->priv->typeselect_flush_timeout)
11831 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11832 tree_view->priv->typeselect_flush_timeout =
11833 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11834 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11842 pspp_sheet_view_search_activate (GtkEntry *entry,
11843 PsppSheetView *tree_view)
11848 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11851 /* If we have a row selected and it's the cursor row, we activate
11853 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11855 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11857 _pspp_sheet_view_find_node (tree_view, path, &node);
11859 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11860 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11862 gtk_tree_path_free (path);
11867 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11869 PsppSheetView *tree_view = (PsppSheetView *)data;
11871 tree_view->priv->disable_popdown = 0;
11877 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11880 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11884 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11885 GdkEventAny *event,
11886 PsppSheetView *tree_view)
11888 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11890 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11896 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11897 GdkEventButton *event,
11898 PsppSheetView *tree_view)
11900 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11902 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11904 if (event->window == tree_view->priv->bin_window)
11905 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11911 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11912 GdkEventScroll *event,
11913 PsppSheetView *tree_view)
11915 gboolean retval = FALSE;
11917 if (event->direction == GDK_SCROLL_UP)
11919 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11922 else if (event->direction == GDK_SCROLL_DOWN)
11924 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11928 /* renew the flush timeout */
11929 if (retval && tree_view->priv->typeselect_flush_timeout
11930 && !tree_view->priv->search_custom_entry_set)
11932 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11933 tree_view->priv->typeselect_flush_timeout =
11934 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11935 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11943 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11944 GdkEventKey *event,
11945 PsppSheetView *tree_view)
11947 gboolean retval = FALSE;
11949 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11950 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11952 /* close window and cancel the search */
11953 if (!tree_view->priv->search_custom_entry_set
11954 && (event->keyval == GDK_Escape ||
11955 event->keyval == GDK_Tab ||
11956 event->keyval == GDK_KP_Tab ||
11957 event->keyval == GDK_ISO_Left_Tab))
11959 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11963 /* select previous matching iter */
11964 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11966 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11967 gtk_widget_error_bell (widget);
11972 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11973 && (event->keyval == GDK_g || event->keyval == GDK_G))
11975 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11976 gtk_widget_error_bell (widget);
11981 /* select next matching iter */
11982 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
11984 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11985 gtk_widget_error_bell (widget);
11990 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
11991 && (event->keyval == GDK_g || event->keyval == GDK_G))
11993 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11994 gtk_widget_error_bell (widget);
11999 /* renew the flush timeout */
12000 if (retval && tree_view->priv->typeselect_flush_timeout
12001 && !tree_view->priv->search_custom_entry_set)
12003 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12004 tree_view->priv->typeselect_flush_timeout =
12005 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12006 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12013 /* this function returns FALSE if there is a search string but
12014 * nothing was found, and TRUE otherwise.
12017 pspp_sheet_view_search_move (GtkWidget *window,
12018 PsppSheetView *tree_view,
12026 GtkTreeModel *model;
12027 PsppSheetSelection *selection;
12029 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
12031 g_return_val_if_fail (text != NULL, FALSE);
12033 len = strlen (text);
12035 if (up && tree_view->priv->selected_iter == 1)
12036 return strlen (text) < 1;
12038 len = strlen (text);
12043 model = pspp_sheet_view_get_model (tree_view);
12044 selection = pspp_sheet_view_get_selection (tree_view);
12047 pspp_sheet_selection_unselect_all (selection);
12048 if (!gtk_tree_model_get_iter_first (model, &iter))
12051 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
12052 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
12057 tree_view->priv->selected_iter += up?(-1):(1);
12062 /* return to old iter */
12064 gtk_tree_model_get_iter_first (model, &iter);
12065 pspp_sheet_view_search_iter (model, selection,
12067 &count, tree_view->priv->selected_iter);
12073 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
12077 gpointer search_data)
12079 gboolean retval = TRUE;
12081 gchar *normalized_string;
12082 gchar *normalized_key;
12083 gchar *case_normalized_string = NULL;
12084 gchar *case_normalized_key = NULL;
12085 GValue value = {0,};
12086 GValue transformed = {0,};
12088 gtk_tree_model_get_value (model, iter, column, &value);
12090 g_value_init (&transformed, G_TYPE_STRING);
12092 if (!g_value_transform (&value, &transformed))
12094 g_value_unset (&value);
12098 g_value_unset (&value);
12100 str = g_value_get_string (&transformed);
12103 g_value_unset (&transformed);
12107 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
12108 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
12110 if (normalized_string && normalized_key)
12112 case_normalized_string = g_utf8_casefold (normalized_string, -1);
12113 case_normalized_key = g_utf8_casefold (normalized_key, -1);
12115 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
12119 g_value_unset (&transformed);
12120 g_free (normalized_key);
12121 g_free (normalized_string);
12122 g_free (case_normalized_key);
12123 g_free (case_normalized_string);
12129 pspp_sheet_view_search_iter (GtkTreeModel *model,
12130 PsppSheetSelection *selection,
12139 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
12141 path = gtk_tree_model_get_path (model, iter);
12142 _pspp_sheet_view_find_node (tree_view, path, &node);
12146 gboolean done = FALSE;
12148 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
12153 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
12155 pspp_sheet_selection_select_iter (selection, iter);
12156 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12159 gtk_tree_path_free (path);
12168 node = pspp_sheet_view_node_next (tree_view, node);
12174 has_next = gtk_tree_model_iter_next (model, iter);
12177 gtk_tree_path_next (path);
12180 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
12185 gtk_tree_path_free (path);
12187 /* we've run out of tree, done with this func */
12199 pspp_sheet_view_search_init (GtkWidget *entry,
12200 PsppSheetView *tree_view)
12206 GtkTreeModel *model;
12207 PsppSheetSelection *selection;
12209 g_return_if_fail (GTK_IS_ENTRY (entry));
12210 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12212 text = gtk_entry_get_text (GTK_ENTRY (entry));
12214 model = pspp_sheet_view_get_model (tree_view);
12215 selection = pspp_sheet_view_get_selection (tree_view);
12218 pspp_sheet_selection_unselect_all (selection);
12219 if (tree_view->priv->typeselect_flush_timeout
12220 && !tree_view->priv->search_custom_entry_set)
12222 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12223 tree_view->priv->typeselect_flush_timeout =
12224 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12225 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12232 if (!gtk_tree_model_get_iter_first (model, &iter))
12235 ret = pspp_sheet_view_search_iter (model, selection,
12240 tree_view->priv->selected_iter = 1;
12244 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
12245 PsppSheetView *tree_view)
12247 if (tree_view->priv->edited_column == NULL)
12250 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
12251 tree_view->priv->edited_column = NULL;
12253 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
12254 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12256 g_signal_handlers_disconnect_by_func (cell_editable,
12257 pspp_sheet_view_remove_widget,
12259 g_signal_handlers_disconnect_by_func (cell_editable,
12260 pspp_sheet_view_editable_button_press_event,
12262 g_signal_handlers_disconnect_by_func (cell_editable,
12263 pspp_sheet_view_editable_clicked,
12266 gtk_container_remove (GTK_CONTAINER (tree_view),
12267 GTK_WIDGET (cell_editable));
12269 /* FIXME should only redraw a single node */
12270 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12274 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
12275 GtkTreePath *cursor_path)
12278 GdkRectangle background_area;
12279 GdkRectangle cell_area;
12280 GtkCellEditable *editable_widget = NULL;
12281 gchar *path_string;
12282 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
12283 gint retval = FALSE;
12286 g_assert (tree_view->priv->focus_column);
12288 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12291 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12292 if (cursor_node < 0)
12295 path_string = gtk_tree_path_to_string (cursor_path);
12296 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12298 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12299 tree_view->priv->model,
12301 pspp_sheet_view_get_background_area (tree_view,
12303 tree_view->priv->focus_column,
12305 pspp_sheet_view_get_cell_area (tree_view,
12307 tree_view->priv->focus_column,
12310 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12319 if (editable_widget != NULL)
12323 GtkCellRenderer *cell;
12326 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12328 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12331 area.width -= right + left;
12333 pspp_sheet_view_real_start_editing (tree_view,
12334 tree_view->priv->focus_column,
12343 g_free (path_string);
12348 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12349 GdkEventButton *event,
12350 PsppSheetView *sheet_view)
12354 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12355 "pspp-sheet-view-node"));
12356 return pspp_sheet_view_row_head_clicked (sheet_view,
12358 sheet_view->priv->edited_column,
12363 pspp_sheet_view_editable_clicked (GtkButton *button,
12364 PsppSheetView *sheet_view)
12366 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12371 is_all_selected (GtkWidget *widget)
12373 GtkEntryBuffer *buffer;
12374 gint start_pos, end_pos;
12376 if (!GTK_IS_ENTRY (widget))
12379 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12380 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12381 &start_pos, &end_pos)
12383 && end_pos == gtk_entry_buffer_get_length (buffer));
12387 is_at_left (GtkWidget *widget)
12389 return (GTK_IS_ENTRY (widget)
12390 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12394 is_at_right (GtkWidget *widget)
12396 GtkEntryBuffer *buffer;
12399 if (!GTK_IS_ENTRY (widget))
12402 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12403 length = gtk_entry_buffer_get_length (buffer);
12404 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12408 pspp_sheet_view_event (GtkWidget *widget,
12409 GdkEventKey *event,
12410 PsppSheetView *tree_view)
12412 PsppSheetViewColumn *column;
12419 /* Intercept only key press events.
12420 It would make sense to use "key-press-event" instead of "event", but
12421 GtkEntry attaches its own signal handler to "key-press-event" that runs
12422 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12424 if (event->type != GDK_KEY_PRESS)
12427 keyval = event->keyval;
12429 switch (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12432 switch (event->keyval)
12434 case GDK_Left: case GDK_KP_Left:
12435 case GDK_Home: case GDK_KP_Home:
12436 if (!is_all_selected (widget) && !is_at_left (widget))
12440 case GDK_Right: case GDK_KP_Right:
12441 case GDK_End: case GDK_KP_End:
12442 if (!is_all_selected (widget) && !is_at_right (widget))
12446 case GDK_Up: case GDK_KP_Up:
12447 case GDK_Down: case GDK_KP_Down:
12450 case GDK_Page_Up: case GDK_KP_Page_Up:
12451 case GDK_Page_Down: case GDK_KP_Page_Down:
12462 case GDK_Tab: case GDK_KP_Tab:
12463 case GDK_ISO_Left_Tab:
12472 case GDK_SHIFT_MASK:
12473 switch (event->keyval)
12476 case GDK_ISO_Left_Tab:
12485 case GDK_CONTROL_MASK:
12486 switch (event->keyval)
12488 case GDK_Left: case GDK_KP_Left:
12489 if (!is_all_selected (widget) && !is_at_left (widget))
12493 case GDK_Right: case GDK_KP_Right:
12494 if (!is_all_selected (widget) && !is_at_right (widget))
12498 case GDK_Up: case GDK_KP_Up:
12499 case GDK_Down: case GDK_KP_Down:
12511 row = tree_view->priv->edited_row;
12512 column = tree_view->priv->edited_column;
12513 path = gtk_tree_path_new_from_indices (row, -1);
12515 pspp_sheet_view_stop_editing (tree_view, cancel);
12516 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12518 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12519 gtk_tree_path_free (path);
12521 handled = gtk_binding_set_activate (edit_bindings, keyval, event->state,
12522 GTK_OBJECT (tree_view));
12524 g_signal_stop_emission_by_name (widget, "event");
12526 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12527 pspp_sheet_view_start_editing (tree_view, path);
12528 gtk_tree_path_free (path);
12534 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12537 PsppSheetView *sheet_view = data;
12539 g_signal_connect (widget, "event",
12540 G_CALLBACK (pspp_sheet_view_event),
12543 if (GTK_IS_CONTAINER (widget))
12544 gtk_container_foreach (GTK_CONTAINER (widget),
12545 pspp_sheet_view_override_cell_keypresses,
12550 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12551 PsppSheetViewColumn *column,
12553 GtkCellEditable *cell_editable,
12554 GdkRectangle *cell_area,
12558 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12559 gint pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
12560 GtkRequisition requisition;
12563 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12565 tree_view->priv->edited_column = column;
12566 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12568 row = gtk_tree_path_get_indices (path)[0];
12569 tree_view->priv->edited_row = row;
12570 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12571 cell_area->y += pre_val - (int)gtk_adjustment_get_value (tree_view->priv->vadjustment);
12573 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12574 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12575 tree_view->priv->anchor_column = column;
12577 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12579 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12581 if (requisition.height < cell_area->height)
12583 gint diff = cell_area->height - requisition.height;
12584 pspp_sheet_view_put (tree_view,
12585 GTK_WIDGET (cell_editable),
12586 cell_area->x, cell_area->y + diff/2,
12587 cell_area->width, requisition.height);
12591 pspp_sheet_view_put (tree_view,
12592 GTK_WIDGET (cell_editable),
12593 cell_area->x, cell_area->y,
12594 cell_area->width, cell_area->height);
12597 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12598 (GdkEvent *)event);
12600 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12601 g_signal_connect (cell_editable, "remove-widget",
12602 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12603 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12604 GTK_IS_BUTTON (cell_editable))
12606 g_signal_connect (cell_editable, "button-press-event",
12607 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12609 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12610 GINT_TO_POINTER (row));
12611 g_signal_connect (cell_editable, "clicked",
12612 G_CALLBACK (pspp_sheet_view_editable_clicked),
12616 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12621 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12622 gboolean cancel_editing)
12624 PsppSheetViewColumn *column;
12625 GtkCellRenderer *cell;
12627 if (tree_view->priv->edited_column == NULL)
12631 * This is very evil. We need to do this, because
12632 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12633 * later on. If pspp_sheet_view_row_changed notices
12634 * tree_view->priv->edited_column != NULL, it'll call
12635 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12637 * Please read that again if you intend to modify anything here.
12640 column = tree_view->priv->edited_column;
12641 tree_view->priv->edited_column = NULL;
12643 cell = _pspp_sheet_view_column_get_edited_cell (column);
12644 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12646 if (!cancel_editing)
12647 gtk_cell_editable_editing_done (column->editable_widget);
12649 tree_view->priv->edited_column = column;
12651 gtk_cell_editable_remove_widget (column->editable_widget);
12656 * pspp_sheet_view_set_hover_selection:
12657 * @tree_view: a #PsppSheetView
12658 * @hover: %TRUE to enable hover selection mode
12660 * Enables of disables the hover selection mode of @tree_view.
12661 * Hover selection makes the selected row follow the pointer.
12662 * Currently, this works only for the selection modes
12663 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12668 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12671 hover = hover != FALSE;
12673 if (hover != tree_view->priv->hover_selection)
12675 tree_view->priv->hover_selection = hover;
12677 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12682 * pspp_sheet_view_get_hover_selection:
12683 * @tree_view: a #PsppSheetView
12685 * Returns whether hover selection mode is turned on for @tree_view.
12687 * Return value: %TRUE if @tree_view is in hover selection mode
12692 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12694 return tree_view->priv->hover_selection;
12698 * pspp_sheet_view_set_rubber_banding:
12699 * @tree_view: a #PsppSheetView
12700 * @enable: %TRUE to enable rubber banding
12702 * Enables or disables rubber banding in @tree_view. If the selection mode is
12703 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12704 * banding will allow the user to select multiple rows by dragging the mouse.
12709 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12712 enable = enable != FALSE;
12714 if (enable != tree_view->priv->rubber_banding_enable)
12716 tree_view->priv->rubber_banding_enable = enable;
12718 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12723 * pspp_sheet_view_get_rubber_banding:
12724 * @tree_view: a #PsppSheetView
12726 * Returns whether rubber banding is turned on for @tree_view. If the
12727 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12728 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12729 * select multiple rows by dragging the mouse.
12731 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12736 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12738 return tree_view->priv->rubber_banding_enable;
12742 * pspp_sheet_view_is_rubber_banding_active:
12743 * @tree_view: a #PsppSheetView
12745 * Returns whether a rubber banding operation is currently being done
12748 * Return value: %TRUE if a rubber banding operation is currently being
12749 * done in @tree_view.
12754 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12756 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12758 if (tree_view->priv->rubber_banding_enable
12759 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12766 pspp_sheet_view_grab_notify (GtkWidget *widget,
12767 gboolean was_grabbed)
12769 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12771 tree_view->priv->in_grab = !was_grabbed;
12775 tree_view->priv->pressed_button = -1;
12777 if (tree_view->priv->rubber_band_status)
12778 pspp_sheet_view_stop_rubber_band (tree_view);
12783 pspp_sheet_view_state_changed (GtkWidget *widget,
12784 GtkStateType previous_state)
12786 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12788 if (gtk_widget_get_realized (widget))
12790 GtkStyle *style = gtk_widget_get_style (widget);
12791 gdk_window_set_back_pixmap (gtk_widget_get_window (widget), NULL, FALSE);
12792 gdk_window_set_background (tree_view->priv->bin_window, &style->base[gtk_widget_get_state (widget)]);
12795 gtk_widget_queue_draw (widget);
12799 * pspp_sheet_view_get_grid_lines:
12800 * @tree_view: a #PsppSheetView
12802 * Returns which grid lines are enabled in @tree_view.
12804 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12809 PsppSheetViewGridLines
12810 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12812 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12814 return tree_view->priv->grid_lines;
12818 * pspp_sheet_view_set_grid_lines:
12819 * @tree_view: a #PsppSheetView
12820 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12823 * Sets which grid lines to draw in @tree_view.
12828 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12829 PsppSheetViewGridLines grid_lines)
12831 PsppSheetViewPrivate *priv;
12832 PsppSheetViewGridLines old_grid_lines;
12834 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12836 priv = tree_view->priv;
12838 old_grid_lines = priv->grid_lines;
12839 priv->grid_lines = grid_lines;
12841 if (old_grid_lines != grid_lines)
12843 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12845 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12850 * pspp_sheet_view_get_special_cells:
12851 * @tree_view: a #PsppSheetView
12853 * Returns which grid lines are enabled in @tree_view.
12855 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12856 * the sheet view contain special cells.
12858 PsppSheetViewSpecialCells
12859 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12861 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12863 return tree_view->priv->special_cells;
12867 * pspp_sheet_view_set_special_cells:
12868 * @tree_view: a #PsppSheetView
12869 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12870 * the sheet view contain special cells.
12872 * Sets whether rows in the sheet view contain special cells, controlling the
12873 * rendering of row selections.
12876 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12877 PsppSheetViewSpecialCells special_cells)
12879 PsppSheetViewPrivate *priv;
12881 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12883 priv = tree_view->priv;
12885 if (priv->special_cells != special_cells)
12887 priv->special_cells = special_cells;
12888 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12889 g_object_notify (G_OBJECT (tree_view), "special-cells");
12894 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12896 /* XXX (re)calculate fixed_height if necessary */
12897 return tree_view->priv->fixed_height;
12901 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12904 g_return_if_fail (fixed_height > 0);
12906 if (tree_view->priv->fixed_height != fixed_height)
12908 tree_view->priv->fixed_height = fixed_height;
12909 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12911 if (!tree_view->priv->fixed_height_set)
12913 tree_view->priv->fixed_height_set = TRUE;
12914 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12919 * pspp_sheet_view_set_tooltip_row:
12920 * @tree_view: a #PsppSheetView
12921 * @tooltip: a #GtkTooltip
12922 * @path: a #GtkTreePath
12924 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12925 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12926 * See also gtk_tooltip_set_tip_area().
12931 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12932 GtkTooltip *tooltip,
12935 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12936 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12938 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12942 * pspp_sheet_view_set_tooltip_cell:
12943 * @tree_view: a #PsppSheetView
12944 * @tooltip: a #GtkTooltip
12945 * @path: (allow-none): a #GtkTreePath or %NULL
12946 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12947 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12949 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12950 * in common. For example if @path is %NULL and @column is set, the tip
12951 * area will be set to the full area covered by @column. See also
12952 * gtk_tooltip_set_tip_area().
12954 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12959 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12960 GtkTooltip *tooltip,
12962 PsppSheetViewColumn *column,
12963 GtkCellRenderer *cell)
12967 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12968 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12969 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12970 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12972 /* Determine x values. */
12973 if (column && cell)
12978 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12979 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12981 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12984 rect.width = width;
12990 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
12991 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12994 rect.width = tmp.width;
12998 GtkAllocation allocation;
12999 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
13001 rect.width = allocation.width;
13004 /* Determine y values. */
13009 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
13010 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13013 rect.height = tmp.height;
13018 rect.height = gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
13021 gtk_tooltip_set_tip_area (tooltip, &rect);
13025 * pspp_sheet_view_get_tooltip_context:
13026 * @tree_view: a #PsppSheetView
13027 * @x: the x coordinate (relative to widget coordinates)
13028 * @y: the y coordinate (relative to widget coordinates)
13029 * @keyboard_tip: whether this is a keyboard tooltip or not
13030 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
13031 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
13032 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
13034 * This function is supposed to be used in a #GtkWidget::query-tooltip
13035 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
13036 * which are received in the signal handler, should be passed to this
13037 * function without modification.
13039 * The return value indicates whether there is a tree view row at the given
13040 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
13041 * tooltips the row returned will be the cursor row. When %TRUE, then any of
13042 * @model, @path and @iter which have been provided will be set to point to
13043 * that row and the corresponding model. @x and @y will always be converted
13044 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
13046 * Return value: whether or not the given tooltip context points to a row.
13051 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
13054 gboolean keyboard_tip,
13055 GtkTreeModel **model,
13056 GtkTreePath **path,
13059 GtkTreePath *tmppath = NULL;
13061 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
13062 g_return_val_if_fail (x != NULL, FALSE);
13063 g_return_val_if_fail (y != NULL, FALSE);
13067 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
13074 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
13077 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
13078 &tmppath, NULL, NULL, NULL))
13083 *model = pspp_sheet_view_get_model (tree_view);
13086 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
13092 gtk_tree_path_free (tmppath);
13098 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
13101 gboolean keyboard_tip,
13102 GtkTooltip *tooltip,
13105 GValue value = { 0, };
13106 GValue transformed = { 0, };
13109 GtkTreeModel *model;
13110 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
13112 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
13115 &model, &path, &iter))
13118 gtk_tree_model_get_value (model, &iter,
13119 tree_view->priv->tooltip_column, &value);
13121 g_value_init (&transformed, G_TYPE_STRING);
13123 if (!g_value_transform (&value, &transformed))
13125 g_value_unset (&value);
13126 gtk_tree_path_free (path);
13131 g_value_unset (&value);
13133 if (!g_value_get_string (&transformed))
13135 g_value_unset (&transformed);
13136 gtk_tree_path_free (path);
13141 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
13142 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
13144 gtk_tree_path_free (path);
13145 g_value_unset (&transformed);
13151 * pspp_sheet_view_set_tooltip_column:
13152 * @tree_view: a #PsppSheetView
13153 * @column: an integer, which is a valid column number for @tree_view's model
13155 * If you only plan to have simple (text-only) tooltips on full rows, you
13156 * can use this function to have #PsppSheetView handle these automatically
13157 * for you. @column should be set to the column in @tree_view's model
13158 * containing the tooltip texts, or -1 to disable this feature.
13160 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
13161 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
13163 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
13164 * so &, <, etc have to be escaped in the text.
13169 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
13172 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13174 if (column == tree_view->priv->tooltip_column)
13179 g_signal_handlers_disconnect_by_func (tree_view,
13180 pspp_sheet_view_set_tooltip_query_cb,
13182 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
13186 if (tree_view->priv->tooltip_column == -1)
13188 g_signal_connect (tree_view, "query-tooltip",
13189 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
13190 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
13194 tree_view->priv->tooltip_column = column;
13195 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
13199 * pspp_sheet_view_get_tooltip_column:
13200 * @tree_view: a #PsppSheetView
13202 * Returns the column of @tree_view's model which is being used for
13203 * displaying tooltips on @tree_view's rows.
13205 * Return value: the index of the tooltip column that is currently being
13206 * used, or -1 if this is disabled.
13211 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
13213 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
13215 return tree_view->priv->tooltip_column;
13219 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
13220 GValue *return_accu,
13221 const GValue *handler_return,
13224 gboolean continue_emission;
13225 gboolean signal_handled;
13227 signal_handled = g_value_get_boolean (handler_return);
13228 g_value_set_boolean (return_accu, signal_handled);
13229 continue_emission = !signal_handled;
13231 return continue_emission;
13236 pspp_sheet_view_grid_lines_get_type (void)
13238 static GType etype = 0;
13239 if (G_UNLIKELY(etype == 0)) {
13240 static const GEnumValue values[] = {
13241 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
13242 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
13243 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
13244 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
13247 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
13253 pspp_sheet_view_special_cells_get_type (void)
13255 static GType etype = 0;
13256 if (G_UNLIKELY(etype == 0)) {
13257 static const GEnumValue values[] = {
13258 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
13259 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
13260 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
13263 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);