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>
43 #include <gdk/gdkkeysyms-compat.h>
46 #include "ui/gui/psppire-marshal.h"
47 #include "ui/gui/pspp-sheet-selection.h"
49 #define P_(STRING) STRING
50 #define GTK_PARAM_READABLE G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
51 #define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
53 /* Many keyboard shortcuts for Mac are the same as for X
54 * except they use Command key instead of Control (e.g. Cut,
55 * Copy, Paste). This symbol is for those simple cases. */
56 #ifndef GDK_WINDOWING_QUARTZ
57 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_CONTROL_MASK
59 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_META_MASK
62 #define PSPP_SHEET_VIEW_PRIORITY_VALIDATE (GDK_PRIORITY_REDRAW + 5)
63 #define PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC (PSPP_SHEET_VIEW_PRIORITY_VALIDATE + 2)
64 #define PSPP_SHEET_VIEW_TIME_MS_PER_IDLE 30
65 #define SCROLL_EDGE_SIZE 15
66 #define EXPANDER_EXTRA_PADDING 4
67 #define PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT 5000
69 /* The "background" areas of all rows/cells add up to cover the entire tree.
70 * The background includes all inter-row and inter-cell spacing.
71 * The "cell" areas are the cell_area passed in to gtk_cell_renderer_render(),
72 * i.e. just the cells, no spacing.
75 #define BACKGROUND_HEIGHT(tree_view) (tree_view->priv->fixed_height)
76 #define CELL_HEIGHT(tree_view, separator) ((BACKGROUND_HEIGHT (tree_view)) - (separator))
78 /* Translate from bin_window coordinates to rbtree (tree coordinates) and
81 #define TREE_WINDOW_Y_TO_RBTREE_Y(tree_view,y) ((y) + tree_view->priv->dy)
82 #define RBTREE_Y_TO_TREE_WINDOW_Y(tree_view,y) ((y) - tree_view->priv->dy)
84 /* This is in bin_window coordinates */
85 #define BACKGROUND_FIRST_PIXEL(tree_view,node) (RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, pspp_sheet_view_node_find_offset (tree_view, (node))))
86 #define CELL_FIRST_PIXEL(tree_view,node,separator) (BACKGROUND_FIRST_PIXEL (tree_view,node) + separator/2)
88 #define ROW_HEIGHT(tree_view) \
89 ((tree_view->priv->fixed_height > 0) ? (tree_view->priv->fixed_height) : (tree_view)->priv->expander_size)
92 typedef struct _PsppSheetViewChild PsppSheetViewChild;
93 struct _PsppSheetViewChild
103 typedef struct _TreeViewDragInfo TreeViewDragInfo;
104 struct _TreeViewDragInfo
106 GdkModifierType start_button_mask;
107 GtkTargetList *_unused_source_target_list;
108 GdkDragAction source_actions;
110 GtkTargetList *_unused_dest_target_list;
112 guint source_set : 1;
128 START_INTERACTIVE_SEARCH,
140 PROP_HEADERS_VISIBLE,
141 PROP_HEADERS_CLICKABLE,
146 PROP_HOVER_SELECTION,
148 PROP_ENABLE_GRID_LINES,
152 PROP_FIXED_HEIGHT_SET
156 static void pspp_sheet_view_finalize (GObject *object);
157 static void pspp_sheet_view_set_property (GObject *object,
161 static void pspp_sheet_view_get_property (GObject *object,
166 static void pspp_sheet_view_dispose (GObject *object);
168 /* gtkwidget signals */
169 static void pspp_sheet_view_realize (GtkWidget *widget);
170 static void pspp_sheet_view_unrealize (GtkWidget *widget);
171 static void pspp_sheet_view_map (GtkWidget *widget);
172 static void pspp_sheet_view_size_request (GtkWidget *widget,
173 GtkRequisition *requisition);
174 static void pspp_sheet_view_size_allocate (GtkWidget *widget,
175 GtkAllocation *allocation);
176 static gboolean pspp_sheet_view_draw (GtkWidget *widget,
178 static gboolean pspp_sheet_view_key_press (GtkWidget *widget,
180 static gboolean pspp_sheet_view_key_release (GtkWidget *widget,
182 static gboolean pspp_sheet_view_motion (GtkWidget *widget,
183 GdkEventMotion *event);
184 static gboolean pspp_sheet_view_enter_notify (GtkWidget *widget,
185 GdkEventCrossing *event);
186 static gboolean pspp_sheet_view_leave_notify (GtkWidget *widget,
187 GdkEventCrossing *event);
188 static gboolean pspp_sheet_view_button_press (GtkWidget *widget,
189 GdkEventButton *event);
190 static gboolean pspp_sheet_view_button_release (GtkWidget *widget,
191 GdkEventButton *event);
192 static gboolean pspp_sheet_view_grab_broken (GtkWidget *widget,
193 GdkEventGrabBroken *event);
195 static void pspp_sheet_view_set_focus_child (GtkContainer *container,
197 static gint pspp_sheet_view_focus_out (GtkWidget *widget,
198 GdkEventFocus *event);
199 static gint pspp_sheet_view_focus (GtkWidget *widget,
200 GtkDirectionType direction);
201 static void pspp_sheet_view_grab_focus (GtkWidget *widget);
202 static void pspp_sheet_view_style_set (GtkWidget *widget,
203 GtkStyle *previous_style);
204 static void pspp_sheet_view_grab_notify (GtkWidget *widget,
205 gboolean was_grabbed);
206 static void pspp_sheet_view_state_changed (GtkWidget *widget,
207 GtkStateType previous_state);
209 /* container signals */
210 static void pspp_sheet_view_remove (GtkContainer *container,
212 static void pspp_sheet_view_forall (GtkContainer *container,
213 gboolean include_internals,
214 GtkCallback callback,
215 gpointer callback_data);
217 /* Source side drag signals */
218 static void pspp_sheet_view_drag_begin (GtkWidget *widget,
219 GdkDragContext *context);
220 static void pspp_sheet_view_drag_end (GtkWidget *widget,
221 GdkDragContext *context);
222 static void pspp_sheet_view_drag_data_get (GtkWidget *widget,
223 GdkDragContext *context,
224 GtkSelectionData *selection_data,
227 static void pspp_sheet_view_drag_data_delete (GtkWidget *widget,
228 GdkDragContext *context);
230 /* Target side drag signals */
231 static void pspp_sheet_view_drag_leave (GtkWidget *widget,
232 GdkDragContext *context,
234 static gboolean pspp_sheet_view_drag_motion (GtkWidget *widget,
235 GdkDragContext *context,
239 static gboolean pspp_sheet_view_drag_drop (GtkWidget *widget,
240 GdkDragContext *context,
244 static void pspp_sheet_view_drag_data_received (GtkWidget *widget,
245 GdkDragContext *context,
248 GtkSelectionData *selection_data,
252 /* tree_model signals */
253 static void pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
255 GtkAdjustment *vadj);
256 static gboolean pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
257 GtkMovementStep step,
259 static gboolean pspp_sheet_view_real_select_all (PsppSheetView *tree_view);
260 static gboolean pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view);
261 static gboolean pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
262 gboolean start_editing,
263 PsppSheetSelectMode mode);
264 static gboolean pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view);
265 static void pspp_sheet_view_row_changed (GtkTreeModel *model,
269 static void pspp_sheet_view_row_inserted (GtkTreeModel *model,
273 static void pspp_sheet_view_row_deleted (GtkTreeModel *model,
276 static void pspp_sheet_view_rows_reordered (GtkTreeModel *model,
282 /* Incremental reflow */
283 static gint validate_row (PsppSheetView *tree_view,
287 static void validate_visible_area (PsppSheetView *tree_view);
288 static gboolean validate_rows_handler (PsppSheetView *tree_view);
289 static gboolean presize_handler_callback (gpointer data);
290 static void install_presize_handler (PsppSheetView *tree_view);
291 static void install_scroll_sync_handler (PsppSheetView *tree_view);
292 static void pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
295 static void pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view);
296 static void pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view);
297 static void invalidate_empty_focus (PsppSheetView *tree_view);
299 /* Internal functions */
300 static GtkAdjustment *pspp_sheet_view_do_get_hadjustment (PsppSheetView *);
301 static GtkAdjustment *pspp_sheet_view_do_get_vadjustment (PsppSheetView *);
302 static void pspp_sheet_view_do_set_hadjustment (PsppSheetView *tree_view,
303 GtkAdjustment *adjustment);
304 static void pspp_sheet_view_do_set_vadjustment (PsppSheetView *tree_view,
305 GtkAdjustment *adjustment);
306 static void pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
309 gboolean add_shifted_binding,
310 GtkMovementStep step,
312 static void pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
314 const GdkRectangle *clip_rect);
315 static gint pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
318 static void pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
319 PsppSheetView *tree_view);
320 static void pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
322 static void pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
323 PsppSheetViewColumn *column,
324 gboolean focus_to_cell);
325 static gboolean pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
326 GdkEventMotion *event);
327 static void pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view);
328 static gboolean pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
330 PsppSheetSelectMode mode);
331 static void pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
333 PsppSheetSelectMode mode);
334 static void pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
336 PsppSheetSelectMode mode);
337 static void pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
339 PsppSheetSelectMode mode);
340 static void pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
342 static void pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
344 PsppSheetSelectMode mode);
345 static void pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
347 gboolean clear_and_select,
349 PsppSheetSelectMode mode);
350 static gboolean pspp_sheet_view_has_special_cell (PsppSheetView *tree_view);
351 static void pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view);
352 static void update_prelight (PsppSheetView *tree_view,
355 static void initialize_fixed_height_mode (PsppSheetView *tree_view);
357 /* interactive search */
358 static void pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view);
359 static void pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
360 PsppSheetView *tree_view);
361 static void pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
362 GtkWidget *search_dialog,
364 static void pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
368 static void pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
369 PsppSheetView *tree_view);
371 static void pspp_sheet_view_search_activate (GtkEntry *entry,
372 PsppSheetView *tree_view);
373 static gboolean pspp_sheet_view_real_search_enable_popdown(gpointer data);
374 static void pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
376 static gboolean pspp_sheet_view_search_delete_event (GtkWidget *widget,
378 PsppSheetView *tree_view);
379 static gboolean pspp_sheet_view_search_button_press_event (GtkWidget *widget,
380 GdkEventButton *event,
381 PsppSheetView *tree_view);
382 static gboolean pspp_sheet_view_search_scroll_event (GtkWidget *entry,
383 GdkEventScroll *event,
384 PsppSheetView *tree_view);
385 static gboolean pspp_sheet_view_search_key_press_event (GtkWidget *entry,
387 PsppSheetView *tree_view);
388 static gboolean pspp_sheet_view_search_move (GtkWidget *window,
389 PsppSheetView *tree_view,
391 static gboolean pspp_sheet_view_search_equal_func (GtkTreeModel *model,
395 gpointer search_data);
396 static gboolean pspp_sheet_view_search_iter (GtkTreeModel *model,
397 PsppSheetSelection *selection,
402 static void pspp_sheet_view_search_init (GtkWidget *entry,
403 PsppSheetView *tree_view);
404 static void pspp_sheet_view_put (PsppSheetView *tree_view,
405 GtkWidget *child_widget,
410 static gboolean pspp_sheet_view_start_editing (PsppSheetView *tree_view,
411 GtkTreePath *cursor_path);
412 static gboolean pspp_sheet_view_editable_button_press_event (GtkWidget *,
415 static void pspp_sheet_view_editable_clicked (GtkButton *, PsppSheetView *);
416 static void pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
417 PsppSheetViewColumn *column,
419 GtkCellEditable *cell_editable,
420 GdkRectangle *cell_area,
423 static gboolean pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
424 gboolean keybinding);
425 static gboolean pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view);
426 static PsppSheetViewColumn *pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
427 PsppSheetViewColumn *column,
430 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
431 PsppSheetViewColumn *column,
432 const GdkRectangle *background_area,
433 gboolean subtract_focus_rect,
434 GdkRectangle *cell_area);
435 static gint pspp_sheet_view_find_offset (PsppSheetView *tree_view,
440 static void pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
444 static void pspp_sheet_view_buildable_init (GtkBuildableIface *iface);
447 static gboolean scroll_row_timeout (gpointer data);
448 static void add_scroll_timeout (PsppSheetView *tree_view);
449 static void remove_scroll_timeout (PsppSheetView *tree_view);
451 static guint tree_view_signals [LAST_SIGNAL] = { 0 };
453 static GtkBindingSet *edit_bindings;
460 G_DEFINE_TYPE_WITH_CODE (PsppSheetView, pspp_sheet_view, GTK_TYPE_CONTAINER,
461 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
462 pspp_sheet_view_buildable_init)
463 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
466 pspp_sheet_view_get_preferred_width (GtkWidget *widget,
470 GtkRequisition requisition;
472 pspp_sheet_view_size_request (widget, &requisition);
474 *minimal_width = *natural_width = requisition.width;
478 pspp_sheet_view_get_preferred_height (GtkWidget *widget,
479 gint *minimal_height,
480 gint *natural_height)
482 GtkRequisition requisition;
484 pspp_sheet_view_size_request (widget, &requisition);
486 *minimal_height = *natural_height = requisition.height;
490 pspp_sheet_view_class_init (PsppSheetViewClass *class)
492 GObjectClass *o_class;
493 GtkWidgetClass *widget_class;
494 GtkContainerClass *container_class;
495 GtkBindingSet *binding_set[2];
498 binding_set[0] = gtk_binding_set_by_class (class);
500 binding_set[1] = gtk_binding_set_new ("PsppSheetViewEditing");
501 edit_bindings = binding_set[1];
503 o_class = (GObjectClass *) class;
504 widget_class = (GtkWidgetClass *) class;
505 container_class = (GtkContainerClass *) class;
507 /* GObject signals */
508 o_class->set_property = pspp_sheet_view_set_property;
509 o_class->get_property = pspp_sheet_view_get_property;
510 o_class->finalize = pspp_sheet_view_finalize;
511 o_class->dispose = pspp_sheet_view_dispose;
513 /* GtkWidget signals */
514 widget_class->map = pspp_sheet_view_map;
515 widget_class->realize = pspp_sheet_view_realize;
516 widget_class->unrealize = pspp_sheet_view_unrealize;
517 widget_class->get_preferred_width = pspp_sheet_view_get_preferred_width;
518 widget_class->get_preferred_height = pspp_sheet_view_get_preferred_height;
519 widget_class->size_allocate = pspp_sheet_view_size_allocate;
520 widget_class->button_press_event = pspp_sheet_view_button_press;
521 widget_class->button_release_event = pspp_sheet_view_button_release;
522 widget_class->grab_broken_event = pspp_sheet_view_grab_broken;
523 /*widget_class->configure_event = pspp_sheet_view_configure;*/
524 widget_class->motion_notify_event = pspp_sheet_view_motion;
525 widget_class->draw = pspp_sheet_view_draw;
526 widget_class->key_press_event = pspp_sheet_view_key_press;
527 widget_class->key_release_event = pspp_sheet_view_key_release;
528 widget_class->enter_notify_event = pspp_sheet_view_enter_notify;
529 widget_class->leave_notify_event = pspp_sheet_view_leave_notify;
530 widget_class->focus_out_event = pspp_sheet_view_focus_out;
531 widget_class->drag_begin = pspp_sheet_view_drag_begin;
532 widget_class->drag_end = pspp_sheet_view_drag_end;
533 widget_class->drag_data_get = pspp_sheet_view_drag_data_get;
534 widget_class->drag_data_delete = pspp_sheet_view_drag_data_delete;
535 widget_class->drag_leave = pspp_sheet_view_drag_leave;
536 widget_class->drag_motion = pspp_sheet_view_drag_motion;
537 widget_class->drag_drop = pspp_sheet_view_drag_drop;
538 widget_class->drag_data_received = pspp_sheet_view_drag_data_received;
539 widget_class->focus = pspp_sheet_view_focus;
540 widget_class->grab_focus = pspp_sheet_view_grab_focus;
541 widget_class->style_set = pspp_sheet_view_style_set;
542 widget_class->grab_notify = pspp_sheet_view_grab_notify;
543 widget_class->state_changed = pspp_sheet_view_state_changed;
545 /* GtkContainer signals */
546 container_class->remove = pspp_sheet_view_remove;
547 container_class->forall = pspp_sheet_view_forall;
548 container_class->set_focus_child = pspp_sheet_view_set_focus_child;
550 class->set_scroll_adjustments = pspp_sheet_view_set_adjustments;
551 class->move_cursor = pspp_sheet_view_real_move_cursor;
552 class->select_all = pspp_sheet_view_real_select_all;
553 class->unselect_all = pspp_sheet_view_real_unselect_all;
554 class->select_cursor_row = pspp_sheet_view_real_select_cursor_row;
555 class->toggle_cursor_row = pspp_sheet_view_real_toggle_cursor_row;
556 class->start_interactive_search = pspp_sheet_view_start_interactive_search;
560 g_object_class_install_property (o_class,
562 g_param_spec_object ("model",
563 P_("TreeView Model"),
564 P_("The model for the tree view"),
566 GTK_PARAM_READWRITE));
568 g_object_class_override_property (o_class, PROP_HADJUSTMENT, "hadjustment");
569 g_object_class_override_property (o_class, PROP_VADJUSTMENT, "vadjustment");
570 g_object_class_override_property (o_class, PROP_HSCROLL_POLICY, "hscroll-policy");
571 g_object_class_override_property (o_class, PROP_VSCROLL_POLICY, "vscroll-policy");
573 g_object_class_install_property (o_class,
574 PROP_HEADERS_VISIBLE,
575 g_param_spec_boolean ("headers-visible",
576 P_("Headers Visible"),
577 P_("Show the column header buttons"),
579 GTK_PARAM_READWRITE));
581 g_object_class_install_property (o_class,
582 PROP_HEADERS_CLICKABLE,
583 g_param_spec_boolean ("headers-clickable",
584 P_("Headers Clickable"),
585 P_("Column headers respond to click events"),
587 GTK_PARAM_READWRITE));
589 g_object_class_install_property (o_class,
591 g_param_spec_boolean ("reorderable",
593 P_("View is reorderable"),
595 GTK_PARAM_READWRITE));
597 g_object_class_install_property (o_class,
599 g_param_spec_boolean ("rules-hint",
601 P_("Set a hint to the theme engine to draw rows in alternating colors"),
603 GTK_PARAM_READWRITE));
605 g_object_class_install_property (o_class,
607 g_param_spec_boolean ("enable-search",
609 P_("View allows user to search through columns interactively"),
611 GTK_PARAM_READWRITE));
613 g_object_class_install_property (o_class,
615 g_param_spec_int ("search-column",
617 P_("Model column to search through during interactive search"),
621 GTK_PARAM_READWRITE));
624 * PsppSheetView:hover-selection:
626 * Enables of disables the hover selection mode of @tree_view.
627 * Hover selection makes the selected row follow the pointer.
628 * Currently, this works only for the selection modes
629 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
631 * This mode is primarily intended for treeviews in popups, e.g.
632 * in #GtkComboBox or #GtkEntryCompletion.
636 g_object_class_install_property (o_class,
637 PROP_HOVER_SELECTION,
638 g_param_spec_boolean ("hover-selection",
639 P_("Hover Selection"),
640 P_("Whether the selection should follow the pointer"),
642 GTK_PARAM_READWRITE));
644 g_object_class_install_property (o_class,
646 g_param_spec_boolean ("rubber-banding",
647 P_("Rubber Banding"),
648 P_("Whether to enable selection of multiple items by dragging the mouse pointer"),
650 GTK_PARAM_READWRITE));
652 g_object_class_install_property (o_class,
653 PROP_ENABLE_GRID_LINES,
654 g_param_spec_enum ("enable-grid-lines",
655 P_("Enable Grid Lines"),
656 P_("Whether grid lines should be drawn in the tree view"),
657 PSPP_TYPE_SHEET_VIEW_GRID_LINES,
658 PSPP_SHEET_VIEW_GRID_LINES_NONE,
659 GTK_PARAM_READWRITE));
661 g_object_class_install_property (o_class,
663 g_param_spec_int ("tooltip-column",
664 P_("Tooltip Column"),
665 P_("The column in the model containing the tooltip texts for the rows"),
669 GTK_PARAM_READWRITE));
671 g_object_class_install_property (o_class,
673 g_param_spec_enum ("special-cells",
675 P_("Whether rows have special cells."),
676 PSPP_TYPE_SHEET_VIEW_SPECIAL_CELLS,
677 PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT,
678 GTK_PARAM_READWRITE));
680 g_object_class_install_property (o_class,
682 g_param_spec_int ("fixed-height",
684 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."),
688 GTK_PARAM_READWRITE));
690 g_object_class_install_property (o_class,
691 PROP_FIXED_HEIGHT_SET,
692 g_param_spec_boolean ("fixed-height-set",
693 P_("Fixed Height Set"),
694 P_("Whether fixed-height was set externally."),
696 GTK_PARAM_READWRITE));
698 /* Style properties */
699 #define _TREE_VIEW_EXPANDER_SIZE 12
700 #define _TREE_VIEW_VERTICAL_SEPARATOR 2
701 #define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
703 gtk_widget_class_install_style_property (widget_class,
704 g_param_spec_int ("expander-size",
706 P_("Size of the expander arrow"),
709 _TREE_VIEW_EXPANDER_SIZE,
710 GTK_PARAM_READABLE));
712 gtk_widget_class_install_style_property (widget_class,
713 g_param_spec_int ("vertical-separator",
714 P_("Vertical Separator Width"),
715 P_("Vertical space between cells. Must be an even number"),
718 _TREE_VIEW_VERTICAL_SEPARATOR,
719 GTK_PARAM_READABLE));
721 gtk_widget_class_install_style_property (widget_class,
722 g_param_spec_int ("horizontal-separator",
723 P_("Horizontal Separator Width"),
724 P_("Horizontal space between cells. Must be an even number"),
727 _TREE_VIEW_HORIZONTAL_SEPARATOR,
728 GTK_PARAM_READABLE));
730 gtk_widget_class_install_style_property (widget_class,
731 g_param_spec_boolean ("allow-rules",
733 P_("Allow drawing of alternating color rows"),
735 GTK_PARAM_READABLE));
737 gtk_widget_class_install_style_property (widget_class,
738 g_param_spec_boxed ("even-row-color",
739 P_("Even Row Color"),
740 P_("Color to use for even rows"),
742 GTK_PARAM_READABLE));
744 gtk_widget_class_install_style_property (widget_class,
745 g_param_spec_boxed ("odd-row-color",
747 P_("Color to use for odd rows"),
749 GTK_PARAM_READABLE));
751 gtk_widget_class_install_style_property (widget_class,
752 g_param_spec_boolean ("row-ending-details",
753 P_("Row Ending details"),
754 P_("Enable extended row background theming"),
756 GTK_PARAM_READABLE));
758 gtk_widget_class_install_style_property (widget_class,
759 g_param_spec_int ("grid-line-width",
760 P_("Grid line width"),
761 P_("Width, in pixels, of the tree view grid lines"),
763 GTK_PARAM_READABLE));
765 gtk_widget_class_install_style_property (widget_class,
766 g_param_spec_int ("tree-line-width",
767 P_("Tree line width"),
768 P_("Width, in pixels, of the tree view lines"),
770 GTK_PARAM_READABLE));
772 gtk_widget_class_install_style_property (widget_class,
773 g_param_spec_string ("tree-line-pattern",
774 P_("Tree line pattern"),
775 P_("Dash pattern used to draw the tree view lines"),
777 GTK_PARAM_READABLE));
782 * PsppSheetView::set-scroll-adjustments
783 * @horizontal: the horizontal #GtkAdjustment
784 * @vertical: the vertical #GtkAdjustment
786 * Set the scroll adjustments for the tree view. Usually scrolled containers
787 * like #GtkScrolledWindow will emit this signal to connect two instances
788 * of #GtkScrollbar to the scroll directions of the #PsppSheetView.
790 widget_class->set_scroll_adjustments_signal =
791 g_signal_new ("set-scroll-adjustments",
792 G_TYPE_FROM_CLASS (o_class),
793 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
794 G_STRUCT_OFFSET (PsppSheetViewClass, set_scroll_adjustments),
796 psppire_marshal_VOID__OBJECT_OBJECT,
799 GTK_TYPE_ADJUSTMENT);
803 * PsppSheetView::row-activated:
804 * @tree_view: the object on which the signal is emitted
805 * @path: the #GtkTreePath for the activated row
806 * @column: the #PsppSheetViewColumn in which the activation occurred
808 * The "row-activated" signal is emitted when the method
809 * pspp_sheet_view_row_activated() is called or the user double clicks
810 * a treeview row. It is also emitted when a non-editable row is
811 * selected and one of the keys: Space, Shift+Space, Return or
814 * For selection handling refer to the <link linkend="TreeWidget">tree
815 * widget conceptual overview</link> as well as #PsppSheetSelection.
817 tree_view_signals[ROW_ACTIVATED] =
818 g_signal_new ("row-activated",
819 G_TYPE_FROM_CLASS (o_class),
820 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
821 G_STRUCT_OFFSET (PsppSheetViewClass, row_activated),
823 psppire_marshal_VOID__BOXED_OBJECT,
826 PSPP_TYPE_SHEET_VIEW_COLUMN);
829 * PsppSheetView::columns-changed:
830 * @tree_view: the object on which the signal is emitted
832 * The number of columns of the treeview has changed.
834 tree_view_signals[COLUMNS_CHANGED] =
835 g_signal_new ("columns-changed",
836 G_TYPE_FROM_CLASS (o_class),
838 G_STRUCT_OFFSET (PsppSheetViewClass, columns_changed),
840 g_cclosure_marshal_VOID__VOID,
844 * PsppSheetView::cursor-changed:
845 * @tree_view: the object on which the signal is emitted
847 * The position of the cursor (focused cell) has changed.
849 tree_view_signals[CURSOR_CHANGED] =
850 g_signal_new ("cursor-changed",
851 G_TYPE_FROM_CLASS (o_class),
853 G_STRUCT_OFFSET (PsppSheetViewClass, cursor_changed),
855 g_cclosure_marshal_VOID__VOID,
858 tree_view_signals[MOVE_CURSOR] =
859 g_signal_new ("move-cursor",
860 G_TYPE_FROM_CLASS (o_class),
861 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
862 G_STRUCT_OFFSET (PsppSheetViewClass, move_cursor),
864 psppire_marshal_BOOLEAN__ENUM_INT,
866 GTK_TYPE_MOVEMENT_STEP,
869 tree_view_signals[SELECT_ALL] =
870 g_signal_new ("select-all",
871 G_TYPE_FROM_CLASS (o_class),
872 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
873 G_STRUCT_OFFSET (PsppSheetViewClass, select_all),
875 psppire_marshal_BOOLEAN__VOID,
878 tree_view_signals[UNSELECT_ALL] =
879 g_signal_new ("unselect-all",
880 G_TYPE_FROM_CLASS (o_class),
881 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
882 G_STRUCT_OFFSET (PsppSheetViewClass, unselect_all),
884 psppire_marshal_BOOLEAN__VOID,
887 tree_view_signals[SELECT_CURSOR_ROW] =
888 g_signal_new ("select-cursor-row",
889 G_TYPE_FROM_CLASS (o_class),
890 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
891 G_STRUCT_OFFSET (PsppSheetViewClass, select_cursor_row),
893 psppire_marshal_BOOLEAN__BOOLEAN,
895 G_TYPE_BOOLEAN, G_TYPE_INT);
897 tree_view_signals[TOGGLE_CURSOR_ROW] =
898 g_signal_new ("toggle-cursor-row",
899 G_TYPE_FROM_CLASS (o_class),
900 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
901 G_STRUCT_OFFSET (PsppSheetViewClass, toggle_cursor_row),
903 psppire_marshal_BOOLEAN__VOID,
906 tree_view_signals[START_INTERACTIVE_SEARCH] =
907 g_signal_new ("start-interactive-search",
908 G_TYPE_FROM_CLASS (o_class),
909 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
910 G_STRUCT_OFFSET (PsppSheetViewClass, start_interactive_search),
912 psppire_marshal_BOOLEAN__VOID,
916 for (i = 0; i < 2; i++)
918 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Up, 0, TRUE,
919 GTK_MOVEMENT_DISPLAY_LINES, -1);
920 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Up, 0, TRUE,
921 GTK_MOVEMENT_DISPLAY_LINES, -1);
923 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Down, 0, TRUE,
924 GTK_MOVEMENT_DISPLAY_LINES, 1);
925 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Down, 0, TRUE,
926 GTK_MOVEMENT_DISPLAY_LINES, 1);
928 pspp_sheet_view_add_move_binding (binding_set[i], GDK_p, GDK_CONTROL_MASK, FALSE,
929 GTK_MOVEMENT_DISPLAY_LINES, -1);
931 pspp_sheet_view_add_move_binding (binding_set[i], GDK_n, GDK_CONTROL_MASK, FALSE,
932 GTK_MOVEMENT_DISPLAY_LINES, 1);
934 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Home, 0, TRUE,
935 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
936 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Home, 0, TRUE,
937 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
939 pspp_sheet_view_add_move_binding (binding_set[i], GDK_End, 0, TRUE,
940 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
941 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_End, 0, TRUE,
942 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
944 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Up, 0, TRUE,
945 GTK_MOVEMENT_PAGES, -1);
946 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Up, 0, TRUE,
947 GTK_MOVEMENT_PAGES, -1);
949 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Down, 0, TRUE,
950 GTK_MOVEMENT_PAGES, 1);
951 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Down, 0, TRUE,
952 GTK_MOVEMENT_PAGES, 1);
955 gtk_binding_entry_add_signal (binding_set[i], GDK_Up, GDK_CONTROL_MASK, "move-cursor", 2,
956 G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
959 gtk_binding_entry_add_signal (binding_set[i], GDK_Down, GDK_CONTROL_MASK, "move-cursor", 2,
960 G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
963 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, 0, "move-cursor", 2,
964 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
967 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, 0, "move-cursor", 2,
968 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
971 gtk_binding_entry_add_signal (binding_set[i], GDK_Tab, 0, "move-cursor", 2,
972 G_TYPE_ENUM, GTK_MOVEMENT_LOGICAL_POSITIONS,
975 gtk_binding_entry_add_signal (binding_set[i], GDK_Tab, GDK_SHIFT_MASK, "move-cursor", 2,
976 G_TYPE_ENUM, GTK_MOVEMENT_LOGICAL_POSITIONS,
979 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, 0, "move-cursor", 2,
980 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
983 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, 0, "move-cursor", 2,
984 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
987 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, GDK_CONTROL_MASK,
989 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
992 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, GDK_CONTROL_MASK,
994 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
997 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, GDK_CONTROL_MASK,
999 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
1002 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, GDK_CONTROL_MASK,
1004 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
1007 gtk_binding_entry_add_signal (binding_set[i], GDK_f, GDK_CONTROL_MASK, "start-interactive-search", 0);
1009 gtk_binding_entry_add_signal (binding_set[i], GDK_F, GDK_CONTROL_MASK, "start-interactive-search", 0);
1012 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
1013 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
1015 gtk_binding_entry_add_signal (binding_set[0], GDK_a, GDK_CONTROL_MASK, "select-all", 0);
1016 gtk_binding_entry_add_signal (binding_set[0], GDK_slash, GDK_CONTROL_MASK, "select-all", 0);
1018 gtk_binding_entry_add_signal (binding_set[0], GDK_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0);
1019 gtk_binding_entry_add_signal (binding_set[0], GDK_backslash, GDK_CONTROL_MASK, "unselect-all", 0);
1021 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_SHIFT_MASK, "select-cursor-row", 1,
1022 G_TYPE_BOOLEAN, TRUE,
1023 G_TYPE_INT, PSPP_SHEET_SELECT_MODE_EXTEND);
1024 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", 1,
1025 G_TYPE_BOOLEAN, TRUE,
1026 G_TYPE_INT, PSPP_SHEET_SELECT_MODE_EXTEND);
1028 gtk_binding_entry_add_signal (binding_set[0], GDK_space, 0, "select-cursor-row", 1,
1029 G_TYPE_BOOLEAN, TRUE,
1031 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, 0, "select-cursor-row", 1,
1032 G_TYPE_BOOLEAN, TRUE,
1034 gtk_binding_entry_add_signal (binding_set[0], GDK_Return, 0, "select-cursor-row", 1,
1035 G_TYPE_BOOLEAN, TRUE,
1037 gtk_binding_entry_add_signal (binding_set[0], GDK_ISO_Enter, 0, "select-cursor-row", 1,
1038 G_TYPE_BOOLEAN, TRUE,
1040 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Enter, 0, "select-cursor-row", 1,
1041 G_TYPE_BOOLEAN, TRUE,
1044 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, 0, "select-cursor-parent", 0);
1045 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", 0);
1047 g_type_class_add_private (o_class, sizeof (PsppSheetViewPrivate));
1051 pspp_sheet_view_buildable_init (GtkBuildableIface *iface)
1053 iface->add_child = pspp_sheet_view_buildable_add_child;
1057 pspp_sheet_view_init (PsppSheetView *tree_view)
1059 tree_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (tree_view, PSPP_TYPE_SHEET_VIEW, PsppSheetViewPrivate);
1061 gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
1062 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (tree_view), FALSE);
1064 tree_view->priv->flags = PSPP_SHEET_VIEW_DRAW_KEYFOCUS
1065 | PSPP_SHEET_VIEW_HEADERS_VISIBLE;
1067 /* We need some padding */
1068 tree_view->priv->selected = range_tower_create ();
1069 tree_view->priv->dy = 0;
1070 tree_view->priv->cursor_offset = 0;
1071 tree_view->priv->n_columns = 0;
1072 tree_view->priv->header_height = 1;
1073 tree_view->priv->x_drag = 0;
1074 tree_view->priv->drag_pos = -1;
1075 tree_view->priv->header_has_focus = FALSE;
1076 tree_view->priv->pressed_button = -1;
1077 tree_view->priv->press_start_x = -1;
1078 tree_view->priv->press_start_y = -1;
1079 tree_view->priv->reorderable = FALSE;
1080 tree_view->priv->presize_handler_timer = 0;
1081 tree_view->priv->scroll_sync_timer = 0;
1082 tree_view->priv->fixed_height = -1;
1083 tree_view->priv->fixed_height_set = FALSE;
1084 pspp_sheet_view_set_adjustments (tree_view, NULL, NULL);
1085 tree_view->priv->selection = _pspp_sheet_selection_new_with_tree_view (tree_view);
1086 tree_view->priv->enable_search = TRUE;
1087 tree_view->priv->search_column = -1;
1088 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
1089 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
1090 tree_view->priv->search_custom_entry_set = FALSE;
1091 tree_view->priv->typeselect_flush_timeout = 0;
1092 tree_view->priv->init_hadjust_value = TRUE;
1093 tree_view->priv->width = 0;
1095 tree_view->priv->hover_selection = FALSE;
1097 tree_view->priv->rubber_banding_enable = FALSE;
1099 tree_view->priv->grid_lines = PSPP_SHEET_VIEW_GRID_LINES_NONE;
1101 tree_view->priv->tooltip_column = -1;
1103 tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT;
1105 tree_view->priv->post_validation_flag = FALSE;
1107 tree_view->priv->last_button_x = -1;
1108 tree_view->priv->last_button_y = -1;
1110 tree_view->priv->event_last_x = -10000;
1111 tree_view->priv->event_last_y = -10000;
1113 tree_view->priv->prelight_node = -1;
1114 tree_view->priv->rubber_band_start_node = -1;
1115 tree_view->priv->rubber_band_end_node = -1;
1117 tree_view->priv->anchor_column = NULL;
1119 tree_view->priv->button_style = NULL;
1121 tree_view->dispose_has_run = FALSE;
1123 pspp_sheet_view_do_set_vadjustment (tree_view, NULL);
1124 pspp_sheet_view_do_set_hadjustment (tree_view, NULL);
1133 pspp_sheet_view_set_property (GObject *object,
1135 const GValue *value,
1138 PsppSheetView *tree_view;
1140 tree_view = PSPP_SHEET_VIEW (object);
1145 pspp_sheet_view_set_model (tree_view, g_value_get_object (value));
1147 case PROP_HADJUSTMENT:
1148 pspp_sheet_view_do_set_hadjustment (tree_view, g_value_get_object (value));
1150 case PROP_VADJUSTMENT:
1151 pspp_sheet_view_do_set_vadjustment (tree_view, g_value_get_object (value));
1153 case PROP_HSCROLL_POLICY:
1154 tree_view->priv->hscroll_policy = g_value_get_enum (value);
1155 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
1157 case PROP_VSCROLL_POLICY:
1158 tree_view->priv->vscroll_policy = g_value_get_enum (value);
1159 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
1161 case PROP_HEADERS_VISIBLE:
1162 pspp_sheet_view_set_headers_visible (tree_view, g_value_get_boolean (value));
1164 case PROP_HEADERS_CLICKABLE:
1165 pspp_sheet_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
1167 case PROP_REORDERABLE:
1168 pspp_sheet_view_set_reorderable (tree_view, g_value_get_boolean (value));
1170 case PROP_RULES_HINT:
1171 pspp_sheet_view_set_rules_hint (tree_view, g_value_get_boolean (value));
1173 case PROP_ENABLE_SEARCH:
1174 pspp_sheet_view_set_enable_search (tree_view, g_value_get_boolean (value));
1176 case PROP_SEARCH_COLUMN:
1177 pspp_sheet_view_set_search_column (tree_view, g_value_get_int (value));
1179 case PROP_HOVER_SELECTION:
1180 tree_view->priv->hover_selection = g_value_get_boolean (value);
1182 case PROP_RUBBER_BANDING:
1183 tree_view->priv->rubber_banding_enable = g_value_get_boolean (value);
1185 case PROP_ENABLE_GRID_LINES:
1186 pspp_sheet_view_set_grid_lines (tree_view, g_value_get_enum (value));
1188 case PROP_TOOLTIP_COLUMN:
1189 pspp_sheet_view_set_tooltip_column (tree_view, g_value_get_int (value));
1191 case PROP_SPECIAL_CELLS:
1192 pspp_sheet_view_set_special_cells (tree_view, g_value_get_enum (value));
1194 case PROP_FIXED_HEIGHT:
1195 pspp_sheet_view_set_fixed_height (tree_view, g_value_get_int (value));
1197 case PROP_FIXED_HEIGHT_SET:
1198 if (g_value_get_boolean (value))
1200 if (!tree_view->priv->fixed_height_set
1201 && tree_view->priv->fixed_height >= 0)
1203 tree_view->priv->fixed_height_set = true;
1204 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1209 if (tree_view->priv->fixed_height_set)
1211 tree_view->priv->fixed_height_set = false;
1212 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1213 install_presize_handler (tree_view);
1218 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1224 pspp_sheet_view_get_property (GObject *object,
1229 PsppSheetView *tree_view;
1231 tree_view = PSPP_SHEET_VIEW (object);
1236 g_value_set_object (value, tree_view->priv->model);
1238 case PROP_HADJUSTMENT:
1239 g_value_set_object (value, tree_view->priv->hadjustment);
1241 case PROP_VADJUSTMENT:
1242 g_value_set_object (value, tree_view->priv->vadjustment);
1244 case PROP_HSCROLL_POLICY:
1245 g_value_set_enum (value, tree_view->priv->hscroll_policy);
1247 case PROP_VSCROLL_POLICY:
1248 g_value_set_enum (value, tree_view->priv->vscroll_policy);
1250 case PROP_HEADERS_VISIBLE:
1251 g_value_set_boolean (value, pspp_sheet_view_get_headers_visible (tree_view));
1253 case PROP_HEADERS_CLICKABLE:
1254 g_value_set_boolean (value, pspp_sheet_view_get_headers_clickable (tree_view));
1256 case PROP_REORDERABLE:
1257 g_value_set_boolean (value, tree_view->priv->reorderable);
1259 case PROP_RULES_HINT:
1260 g_value_set_boolean (value, tree_view->priv->has_rules);
1262 case PROP_ENABLE_SEARCH:
1263 g_value_set_boolean (value, tree_view->priv->enable_search);
1265 case PROP_SEARCH_COLUMN:
1266 g_value_set_int (value, tree_view->priv->search_column);
1268 case PROP_HOVER_SELECTION:
1269 g_value_set_boolean (value, tree_view->priv->hover_selection);
1271 case PROP_RUBBER_BANDING:
1272 g_value_set_boolean (value, tree_view->priv->rubber_banding_enable);
1274 case PROP_ENABLE_GRID_LINES:
1275 g_value_set_enum (value, tree_view->priv->grid_lines);
1277 case PROP_TOOLTIP_COLUMN:
1278 g_value_set_int (value, tree_view->priv->tooltip_column);
1280 case PROP_SPECIAL_CELLS:
1281 g_value_set_enum (value, tree_view->priv->special_cells);
1283 case PROP_FIXED_HEIGHT:
1284 g_value_set_int (value, pspp_sheet_view_get_fixed_height (tree_view));
1286 case PROP_FIXED_HEIGHT_SET:
1287 g_value_set_boolean (value, tree_view->priv->fixed_height_set);
1290 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1296 pspp_sheet_view_dispose (GObject *object)
1298 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1300 if (tree_view->dispose_has_run)
1303 tree_view->dispose_has_run = TRUE;
1305 if (tree_view->priv->selection != NULL)
1307 _pspp_sheet_selection_set_tree_view (tree_view->priv->selection, NULL);
1308 g_object_unref (tree_view->priv->selection);
1309 tree_view->priv->selection = NULL;
1312 if (tree_view->priv->hadjustment)
1314 g_object_unref (tree_view->priv->hadjustment);
1315 tree_view->priv->hadjustment = NULL;
1317 if (tree_view->priv->vadjustment)
1319 g_object_unref (tree_view->priv->vadjustment);
1320 tree_view->priv->vadjustment = NULL;
1323 if (tree_view->priv->button_style)
1325 g_object_unref (tree_view->priv->button_style);
1326 tree_view->priv->button_style = NULL;
1330 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->dispose (object);
1336 pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
1337 GtkBuilder *builder,
1341 pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), PSPP_SHEET_VIEW_COLUMN (child));
1345 pspp_sheet_view_finalize (GObject *object)
1347 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1349 pspp_sheet_view_stop_editing (tree_view, TRUE);
1351 if (tree_view->priv->selected != NULL)
1353 range_tower_destroy (tree_view->priv->selected);
1354 tree_view->priv->selected = NULL;
1358 tree_view->priv->prelight_node = -1;
1361 if (tree_view->priv->scroll_to_path != NULL)
1363 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1364 tree_view->priv->scroll_to_path = NULL;
1367 if (tree_view->priv->drag_dest_row != NULL)
1369 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
1370 tree_view->priv->drag_dest_row = NULL;
1373 if (tree_view->priv->top_row != NULL)
1375 gtk_tree_row_reference_free (tree_view->priv->top_row);
1376 tree_view->priv->top_row = NULL;
1379 if (tree_view->priv->column_drop_func_data &&
1380 tree_view->priv->column_drop_func_data_destroy)
1382 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
1383 tree_view->priv->column_drop_func_data = NULL;
1386 if (tree_view->priv->destroy_count_destroy &&
1387 tree_view->priv->destroy_count_data)
1389 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
1390 tree_view->priv->destroy_count_data = NULL;
1393 gtk_tree_row_reference_free (tree_view->priv->cursor);
1394 tree_view->priv->cursor = NULL;
1396 gtk_tree_row_reference_free (tree_view->priv->anchor);
1397 tree_view->priv->anchor = NULL;
1399 /* destroy interactive search dialog */
1400 if (tree_view->priv->search_window)
1402 gtk_widget_destroy (tree_view->priv->search_window);
1403 tree_view->priv->search_window = NULL;
1404 tree_view->priv->search_entry = NULL;
1405 if (tree_view->priv->typeselect_flush_timeout)
1407 g_source_remove (tree_view->priv->typeselect_flush_timeout);
1408 tree_view->priv->typeselect_flush_timeout = 0;
1412 if (tree_view->priv->search_destroy && tree_view->priv->search_user_data)
1414 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
1415 tree_view->priv->search_user_data = NULL;
1418 if (tree_view->priv->search_position_destroy && tree_view->priv->search_position_user_data)
1420 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
1421 tree_view->priv->search_position_user_data = NULL;
1424 pspp_sheet_view_set_model (tree_view, NULL);
1427 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->finalize (object);
1432 /* GtkWidget Methods
1435 /* GtkWidget::map helper */
1437 pspp_sheet_view_map_buttons (PsppSheetView *tree_view)
1441 g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (tree_view)));
1443 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
1445 PsppSheetViewColumn *column;
1447 for (list = tree_view->priv->columns; list; list = list->next)
1449 column = list->data;
1450 if (column->button != NULL &&
1451 gtk_widget_get_visible (column->button) &&
1452 !gtk_widget_get_mapped (column->button))
1453 gtk_widget_map (column->button);
1455 for (list = tree_view->priv->columns; list; list = list->next)
1457 column = list->data;
1458 if (column->visible == FALSE || column->window == NULL)
1460 if (column->resizable)
1462 gdk_window_raise (column->window);
1463 gdk_window_show (column->window);
1466 gdk_window_hide (column->window);
1468 gdk_window_show (tree_view->priv->header_window);
1473 pspp_sheet_view_map (GtkWidget *widget)
1475 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1478 gtk_widget_set_mapped (widget, TRUE);
1480 tmp_list = tree_view->priv->children;
1483 PsppSheetViewChild *child = tmp_list->data;
1484 tmp_list = tmp_list->next;
1486 if (gtk_widget_get_visible (child->widget))
1488 if (!gtk_widget_get_mapped (child->widget))
1489 gtk_widget_map (child->widget);
1492 gdk_window_show (tree_view->priv->bin_window);
1494 pspp_sheet_view_map_buttons (tree_view);
1496 gdk_window_show (gtk_widget_get_window (widget));
1500 pspp_sheet_view_realize (GtkWidget *widget)
1502 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1504 GdkWindowAttr attributes;
1505 gint attributes_mask;
1506 GtkAllocation allocation;
1507 GtkAllocation old_allocation;
1509 gtk_widget_set_realized (widget, TRUE);
1511 gtk_widget_get_allocation (widget, &allocation);
1512 gtk_widget_get_allocation (widget, &old_allocation);
1514 /* Make the main, clipping window */
1515 attributes.window_type = GDK_WINDOW_CHILD;
1516 attributes.x = allocation.x;
1517 attributes.y = allocation.y;
1518 attributes.width = allocation.width;
1519 attributes.height = allocation.height;
1520 attributes.wclass = GDK_INPUT_OUTPUT;
1521 attributes.visual = gtk_widget_get_visual (widget);
1522 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1524 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1526 gtk_widget_set_window (widget,
1527 gdk_window_new (gtk_widget_get_parent_window (widget),
1528 &attributes, attributes_mask));
1529 gdk_window_set_user_data (gtk_widget_get_window (widget), widget);
1531 /* Make the window for the tree */
1533 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1534 attributes.width = MAX (tree_view->priv->width, old_allocation.width);
1535 attributes.height = old_allocation.height;
1536 attributes.event_mask = (GDK_EXPOSURE_MASK |
1538 GDK_POINTER_MOTION_MASK |
1539 GDK_ENTER_NOTIFY_MASK |
1540 GDK_LEAVE_NOTIFY_MASK |
1541 GDK_BUTTON_PRESS_MASK |
1542 GDK_BUTTON_RELEASE_MASK |
1543 gtk_widget_get_events (widget));
1545 tree_view->priv->bin_window = gdk_window_new (gtk_widget_get_window (widget),
1546 &attributes, attributes_mask);
1547 gdk_window_set_user_data (tree_view->priv->bin_window, widget);
1549 /* Make the column header window */
1552 attributes.width = MAX (tree_view->priv->width, old_allocation.width);
1553 attributes.height = tree_view->priv->header_height;
1554 attributes.event_mask = (GDK_EXPOSURE_MASK |
1556 GDK_BUTTON_PRESS_MASK |
1557 GDK_BUTTON_RELEASE_MASK |
1558 GDK_KEY_PRESS_MASK |
1559 GDK_KEY_RELEASE_MASK |
1560 gtk_widget_get_events (widget));
1562 tree_view->priv->header_window = gdk_window_new (gtk_widget_get_window (widget),
1563 &attributes, attributes_mask);
1564 gdk_window_set_user_data (tree_view->priv->header_window, widget);
1566 /* Add them all up. */
1567 gtk_widget_set_style (widget,
1568 gtk_style_attach (gtk_widget_get_style (widget), gtk_widget_get_window (widget)));
1569 gdk_window_set_background (tree_view->priv->bin_window, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1570 gtk_style_set_background (gtk_widget_get_style (widget), tree_view->priv->header_window, GTK_STATE_NORMAL);
1572 tmp_list = tree_view->priv->children;
1575 PsppSheetViewChild *child = tmp_list->data;
1576 tmp_list = tmp_list->next;
1578 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1581 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1582 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1584 /* Need to call those here, since they create GCs */
1585 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1587 install_presize_handler (tree_view);
1591 pspp_sheet_view_unrealize (GtkWidget *widget)
1593 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1594 PsppSheetViewPrivate *priv = tree_view->priv;
1597 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1599 if (priv->scroll_timeout != 0)
1601 g_source_remove (priv->scroll_timeout);
1602 priv->scroll_timeout = 0;
1605 if (priv->open_dest_timeout != 0)
1607 g_source_remove (priv->open_dest_timeout);
1608 priv->open_dest_timeout = 0;
1611 if (priv->presize_handler_timer != 0)
1613 g_source_remove (priv->presize_handler_timer);
1614 priv->presize_handler_timer = 0;
1617 if (priv->validate_rows_timer != 0)
1619 g_source_remove (priv->validate_rows_timer);
1620 priv->validate_rows_timer = 0;
1623 if (priv->scroll_sync_timer != 0)
1625 g_source_remove (priv->scroll_sync_timer);
1626 priv->scroll_sync_timer = 0;
1629 if (priv->typeselect_flush_timeout)
1631 g_source_remove (priv->typeselect_flush_timeout);
1632 priv->typeselect_flush_timeout = 0;
1635 for (list = priv->columns; list; list = list->next)
1636 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1638 gdk_window_set_user_data (priv->bin_window, NULL);
1639 gdk_window_destroy (priv->bin_window);
1640 priv->bin_window = NULL;
1642 gdk_window_set_user_data (priv->header_window, NULL);
1643 gdk_window_destroy (priv->header_window);
1644 priv->header_window = NULL;
1646 if (priv->drag_window)
1648 gdk_window_set_user_data (priv->drag_window, NULL);
1649 gdk_window_destroy (priv->drag_window);
1650 priv->drag_window = NULL;
1653 if (priv->drag_highlight_window)
1655 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1656 gdk_window_destroy (priv->drag_highlight_window);
1657 priv->drag_highlight_window = NULL;
1660 if (tree_view->priv->columns != NULL)
1662 list = tree_view->priv->columns;
1665 PsppSheetViewColumn *column;
1666 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1668 pspp_sheet_view_remove_column (tree_view, column);
1670 tree_view->priv->columns = NULL;
1674 /* GtkWidget::size_request helper */
1676 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1680 tree_view->priv->header_height = 0;
1682 if (tree_view->priv->model)
1684 for (list = tree_view->priv->columns; list; list = list->next)
1686 GtkRequisition requisition;
1687 PsppSheetViewColumn *column = list->data;
1689 pspp_sheet_view_column_size_request (column, &requisition);
1690 column->button_request = requisition.width;
1691 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1697 /* Called only by ::size_request */
1699 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1702 PsppSheetViewColumn *column;
1705 if (tree_view->priv->model == NULL)
1707 tree_view->priv->width = 0;
1708 tree_view->priv->prev_width = 0;
1709 tree_view->priv->height = 0;
1713 tree_view->priv->prev_width = tree_view->priv->width;
1714 tree_view->priv->width = 0;
1716 /* keep this in sync with size_allocate below */
1717 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1719 gint real_requested_width = 0;
1720 column = list->data;
1721 if (!column->visible)
1724 if (column->use_resized_width)
1726 real_requested_width = column->resized_width;
1730 real_requested_width = column->fixed_width;
1733 if (column->min_width != -1)
1734 real_requested_width = MAX (real_requested_width, column->min_width);
1735 if (column->max_width != -1)
1736 real_requested_width = MIN (real_requested_width, column->max_width);
1738 tree_view->priv->width += real_requested_width;
1741 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1745 pspp_sheet_view_size_request (GtkWidget *widget,
1746 GtkRequisition *requisition)
1748 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1751 /* we validate some rows initially just to make sure we have some size.
1752 * In practice, with a lot of static lists, this should get a good width.
1754 initialize_fixed_height_mode (tree_view);
1755 pspp_sheet_view_size_request_columns (tree_view);
1756 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1758 requisition->width = tree_view->priv->width;
1759 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1761 tmp_list = tree_view->priv->children;
1765 PsppSheetViewChild *child = tmp_list->data;
1766 GtkRequisition child_requisition;
1768 tmp_list = tmp_list->next;
1770 if (gtk_widget_get_visible (child->widget))
1771 gtk_widget_size_request (child->widget, &child_requisition);
1776 invalidate_column (PsppSheetView *tree_view,
1777 PsppSheetViewColumn *column)
1779 gint column_offset = 0;
1781 GtkWidget *widget = GTK_WIDGET (tree_view);
1784 if (!gtk_widget_get_realized (widget))
1787 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1788 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1790 list = (rtl ? list->prev : list->next))
1792 PsppSheetViewColumn *tmpcolumn = list->data;
1793 if (tmpcolumn == column)
1795 GdkRectangle invalid_rect;
1796 GtkAllocation allocation;
1798 gtk_widget_get_allocation (widget, &allocation);
1799 invalid_rect.x = column_offset;
1801 invalid_rect.width = column->width;
1802 invalid_rect.height = allocation.height;
1804 gdk_window_invalidate_rect (gtk_widget_get_window (widget), &invalid_rect, TRUE);
1808 column_offset += tmpcolumn->width;
1813 invalidate_last_column (PsppSheetView *tree_view)
1818 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1820 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1822 last_column = (rtl ? last_column->next : last_column->prev))
1824 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1826 invalidate_column (tree_view, last_column->data);
1833 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1834 PsppSheetViewColumn *column)
1836 gint real_requested_width;
1838 if (column->use_resized_width)
1840 real_requested_width = column->resized_width;
1844 real_requested_width = column->fixed_width;
1847 if (column->min_width != -1)
1848 real_requested_width = MAX (real_requested_width, column->min_width);
1849 if (column->max_width != -1)
1850 real_requested_width = MIN (real_requested_width, column->max_width);
1852 return real_requested_width;
1856 span_intersects (int a0, int a_width,
1857 int b0, int b_width)
1859 int a1 = a0 + a_width;
1860 int b1 = b0 + b_width;
1861 return (a0 >= b0 && a0 < b1) || (b0 >= a0 && b0 < a1);
1864 /* GtkWidget::size_allocate helper */
1866 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1867 gboolean *width_changed)
1869 PsppSheetView *tree_view;
1870 GList *list, *first_column, *last_column;
1871 PsppSheetViewColumn *column;
1872 GtkAllocation col_allocation;
1873 GtkAllocation allocation;
1875 gint extra, extra_per_column;
1876 gint full_requested_width = 0;
1877 gint number_of_expand_columns = 0;
1878 gboolean column_changed = FALSE;
1881 tree_view = PSPP_SHEET_VIEW (widget);
1883 for (last_column = g_list_last (tree_view->priv->columns);
1884 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1885 last_column = last_column->prev)
1888 if (last_column == NULL)
1891 for (first_column = g_list_first (tree_view->priv->columns);
1892 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1893 first_column = first_column->next)
1896 col_allocation.y = 0;
1897 col_allocation.height = tree_view->priv->header_height;
1899 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1901 /* find out how many extra space and expandable columns we have */
1902 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1904 column = (PsppSheetViewColumn *)list->data;
1906 if (!column->visible)
1909 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1912 number_of_expand_columns++;
1915 gtk_widget_get_allocation (widget, &allocation);
1916 extra = MAX (allocation.width - full_requested_width, 0);
1917 if (number_of_expand_columns > 0)
1918 extra_per_column = extra/number_of_expand_columns;
1920 extra_per_column = 0;
1922 for (list = (rtl ? last_column : first_column);
1923 list != (rtl ? first_column->prev : last_column->next);
1924 list = (rtl ? list->prev : list->next))
1926 gint real_requested_width = 0;
1929 column = list->data;
1930 old_width = column->width;
1932 if (!column->visible)
1935 /* We need to handle the dragged button specially.
1937 if (column == tree_view->priv->drag_column)
1939 GtkAllocation drag_allocation;
1940 drag_allocation.width = gdk_window_get_width (tree_view->priv->drag_window);
1941 drag_allocation.height = gdk_window_get_height (tree_view->priv->drag_window);
1942 drag_allocation.x = 0;
1943 drag_allocation.y = 0;
1944 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1946 width += drag_allocation.width;
1950 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1952 col_allocation.x = width;
1953 column->width = real_requested_width;
1957 if (number_of_expand_columns == 1)
1959 /* We add the remander to the last column as
1961 column->width += extra;
1965 column->width += extra_per_column;
1966 extra -= extra_per_column;
1967 number_of_expand_columns --;
1971 if (column->width != old_width)
1972 g_object_notify (G_OBJECT (column), "width");
1974 col_allocation.width = column->width;
1975 width += column->width;
1977 if (column->width > old_width)
1978 column_changed = TRUE;
1980 pspp_sheet_view_column_size_allocate (column, &col_allocation);
1982 if (span_intersects (col_allocation.x, col_allocation.width,
1983 gtk_adjustment_get_value (tree_view->priv->hadjustment),
1985 && gtk_widget_get_realized (widget))
1986 pspp_sheet_view_column_set_need_button (column, TRUE);
1989 gdk_window_move_resize (column->window,
1990 col_allocation.x + (rtl ? 0 : col_allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1992 TREE_VIEW_DRAG_WIDTH, col_allocation.height);
1995 /* We change the width here. The user might have been resizing columns,
1996 * so the total width of the tree view changes.
1998 tree_view->priv->width = width;
2000 *width_changed = TRUE;
2003 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2007 pspp_sheet_view_size_allocate (GtkWidget *widget,
2008 GtkAllocation *allocation)
2010 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2012 gboolean width_changed = FALSE;
2013 GtkAllocation old_allocation;
2014 gtk_widget_get_allocation (widget, &old_allocation);
2016 if (allocation->width != old_allocation.width)
2017 width_changed = TRUE;
2020 gtk_widget_set_allocation (widget, allocation);
2022 tmp_list = tree_view->priv->children;
2026 GtkAllocation allocation;
2028 PsppSheetViewChild *child = tmp_list->data;
2029 tmp_list = tmp_list->next;
2031 /* totally ignore our child's requisition */
2032 allocation.x = child->x;
2033 allocation.y = child->y;
2034 allocation.width = child->width;
2035 allocation.height = child->height;
2036 gtk_widget_size_allocate (child->widget, &allocation);
2039 /* We size-allocate the columns first because the width of the
2040 * tree view (used in updating the adjustments below) might change.
2042 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
2044 gtk_adjustment_set_page_size (tree_view->priv->hadjustment, allocation->width);
2045 gtk_adjustment_set_page_increment (tree_view->priv->hadjustment, allocation->width * 0.9);
2046 gtk_adjustment_set_step_increment (tree_view->priv->hadjustment, allocation->width * 0.1);
2047 gtk_adjustment_set_lower (tree_view->priv->hadjustment, 0);
2048 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_page_size (tree_view->priv->hadjustment), tree_view->priv->width));
2050 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
2052 if (allocation->width < tree_view->priv->width)
2054 if (tree_view->priv->init_hadjust_value)
2056 gtk_adjustment_set_value (tree_view->priv->hadjustment, MAX (tree_view->priv->width - allocation->width, 0));
2057 tree_view->priv->init_hadjust_value = FALSE;
2059 else if (allocation->width != old_allocation.width)
2061 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));
2064 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));
2068 gtk_adjustment_set_value (tree_view->priv->hadjustment, 0);
2069 tree_view->priv->init_hadjust_value = TRUE;
2073 if (gtk_adjustment_get_value (tree_view->priv->hadjustment) + allocation->width > tree_view->priv->width)
2074 gtk_adjustment_set_value (tree_view->priv->hadjustment, MAX (tree_view->priv->width - allocation->width, 0));
2076 gtk_adjustment_changed (tree_view->priv->hadjustment);
2078 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2079 gtk_adjustment_set_step_increment (tree_view->priv->vadjustment, gtk_adjustment_get_page_size (tree_view->priv->vadjustment) * 0.1);
2080 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, gtk_adjustment_get_page_size (tree_view->priv->vadjustment) * 0.9);
2081 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
2082 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_page_size (tree_view->priv->vadjustment), tree_view->priv->height));
2084 gtk_adjustment_changed (tree_view->priv->vadjustment);
2086 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
2087 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
2088 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
2089 else if (gtk_adjustment_get_value (tree_view->priv->vadjustment) + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
2090 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
2091 tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
2092 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
2093 pspp_sheet_view_top_row_to_dy (tree_view);
2095 pspp_sheet_view_dy_to_top_row (tree_view);
2097 if (gtk_widget_get_realized (widget))
2099 gdk_window_move_resize (gtk_widget_get_window (widget),
2100 allocation->x, allocation->y,
2101 allocation->width, allocation->height);
2102 gdk_window_move_resize (tree_view->priv->header_window,
2103 - (gint) gtk_adjustment_get_value (tree_view->priv->hadjustment),
2105 MAX (tree_view->priv->width, allocation->width),
2106 tree_view->priv->header_height);
2107 gdk_window_move_resize (tree_view->priv->bin_window,
2108 - (gint) gtk_adjustment_get_value (tree_view->priv->hadjustment),
2109 TREE_VIEW_HEADER_HEIGHT (tree_view),
2110 MAX (tree_view->priv->width, allocation->width),
2111 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2114 if (tree_view->priv->row_count == 0)
2115 invalidate_empty_focus (tree_view);
2117 if (gtk_widget_get_realized (widget))
2119 gboolean has_expand_column = FALSE;
2120 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2122 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2124 has_expand_column = TRUE;
2129 /* This little hack only works if we have an LTR locale, and no column has the */
2132 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2133 ! has_expand_column)
2134 invalidate_last_column (tree_view);
2136 gtk_widget_queue_draw (widget);
2141 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2143 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2145 GtkWidget *widget = GTK_WIDGET (tree_view);
2147 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2148 gtk_widget_grab_focus (widget);
2149 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2153 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2156 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2160 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2163 range_tower_set1 (tree_view->priv->selected, node, 1);
2167 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2170 range_tower_set0 (tree_view->priv->selected, node, 1);
2174 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2177 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2181 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2184 return node > 0 ? node - 1 : -1;
2188 all_columns_selected (PsppSheetView *tree_view)
2192 for (list = tree_view->priv->columns; list; list = list->next)
2194 PsppSheetViewColumn *column = list->data;
2195 if (column->selectable && !column->selected)
2203 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2205 PsppSheetViewColumn *column,
2206 GdkEventButton *event)
2208 PsppSheetSelection *selection;
2209 PsppSheetSelectionMode mode;
2211 gboolean update_anchor;
2215 g_return_val_if_fail (tree_view != NULL, FALSE);
2216 g_return_val_if_fail (column != NULL, FALSE);
2218 selection = tree_view->priv->selection;
2219 mode = pspp_sheet_selection_get_mode (selection);
2220 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2223 if (!column->row_head)
2228 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2229 if (event->type != GDK_BUTTON_PRESS
2230 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2236 path = gtk_tree_path_new_from_indices (node, -1);
2239 pspp_sheet_selection_unselect_all (selection);
2240 pspp_sheet_selection_select_path (selection, path);
2241 pspp_sheet_selection_select_all_columns (selection);
2242 update_anchor = TRUE;
2245 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2247 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2248 || !all_columns_selected (tree_view))
2250 pspp_sheet_selection_unselect_all (selection);
2251 pspp_sheet_selection_select_path (selection, path);
2252 pspp_sheet_selection_select_all_columns (selection);
2253 update_anchor = TRUE;
2257 update_anchor = handled = FALSE;
2259 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2260 && modifiers == GDK_CONTROL_MASK)
2262 if (!all_columns_selected (tree_view))
2264 pspp_sheet_selection_unselect_all (selection);
2265 pspp_sheet_selection_select_all_columns (selection);
2268 if (pspp_sheet_selection_path_is_selected (selection, path))
2269 pspp_sheet_selection_unselect_path (selection, path);
2271 pspp_sheet_selection_select_path (selection, path);
2272 update_anchor = TRUE;
2275 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2276 && modifiers == GDK_SHIFT_MASK)
2278 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2279 GtkTreePath *anchor_path;
2281 if (all_columns_selected (tree_view)
2282 && gtk_tree_row_reference_valid (anchor))
2284 update_anchor = FALSE;
2285 anchor_path = gtk_tree_row_reference_get_path (anchor);
2289 update_anchor = TRUE;
2290 anchor_path = gtk_tree_path_copy (path);
2293 pspp_sheet_selection_unselect_all (selection);
2294 pspp_sheet_selection_select_range (selection, anchor_path, path);
2295 pspp_sheet_selection_select_all_columns (selection);
2297 gtk_tree_path_free (anchor_path);
2302 update_anchor = handled = FALSE;
2306 if (tree_view->priv->anchor)
2307 gtk_tree_row_reference_free (tree_view->priv->anchor);
2308 tree_view->priv->anchor =
2309 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2310 tree_view->priv->model,
2314 gtk_tree_path_free (path);
2319 find_click (PsppSheetView *tree_view,
2322 PsppSheetViewColumn **column,
2323 GdkRectangle *background_area,
2324 GdkRectangle *cell_area)
2331 /* find the node that was clicked */
2332 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2335 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2340 background_area->y = y_offset + y;
2341 background_area->height = ROW_HEIGHT (tree_view);
2342 background_area->x = 0;
2344 /* Let the column have a chance at selecting it. */
2345 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2346 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2347 list; list = (rtl ? list->prev : list->next))
2349 PsppSheetViewColumn *candidate = list->data;
2351 if (!candidate->visible)
2354 background_area->width = candidate->width;
2355 if ((background_area->x > x) ||
2356 (background_area->x + background_area->width <= x))
2358 background_area->x += background_area->width;
2362 /* we found the focus column */
2364 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2366 *column = candidate;
2374 pspp_sheet_view_button_press (GtkWidget *widget,
2375 GdkEventButton *event)
2377 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2379 PsppSheetViewColumn *column = NULL;
2381 GdkRectangle background_area;
2382 GdkRectangle cell_area;
2385 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2386 pspp_sheet_view_stop_editing (tree_view, FALSE);
2389 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2390 * we're done handling the button press.
2393 if (event->window == tree_view->priv->bin_window)
2398 gint pre_val, aft_val;
2399 PsppSheetViewColumn *column = NULL;
2400 GtkCellRenderer *focus_cell = NULL;
2401 gboolean row_double_click = FALSE;
2404 if (tree_view->priv->row_count == 0)
2406 grab_focus_and_unset_draw_keyfocus (tree_view);
2410 if (!find_click (tree_view, event->x, event->y, &node, &column,
2411 &background_area, &cell_area))
2413 grab_focus_and_unset_draw_keyfocus (tree_view);
2417 tree_view->priv->focus_column = column;
2419 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2423 pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
2425 path = _pspp_sheet_view_find_path (tree_view, node);
2427 /* we only handle selection modifications on the first button press
2429 if (event->type == GDK_BUTTON_PRESS)
2431 PsppSheetSelectionMode mode = 0;
2433 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2434 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
2435 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2436 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
2438 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2440 pspp_sheet_view_column_focus_cell (column, focus_cell);
2442 if (event->state & GDK_CONTROL_MASK)
2444 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, mode);
2445 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2447 else if (event->state & GDK_SHIFT_MASK)
2449 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
2450 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE, mode);
2454 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
2457 if (tree_view->priv->anchor_column == NULL ||
2458 !(event->state & GDK_SHIFT_MASK))
2459 tree_view->priv->anchor_column = column;
2460 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2461 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2462 tree_view->priv->anchor_column,
2466 /* the treeview may have been scrolled because of _set_cursor,
2470 aft_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
2471 dval = pre_val - aft_val;
2473 cell_area.y += dval;
2474 background_area.y += dval;
2476 /* Save press to possibly begin a drag
2478 if (!tree_view->priv->in_grab &&
2479 tree_view->priv->pressed_button < 0)
2481 tree_view->priv->pressed_button = event->button;
2482 tree_view->priv->press_start_x = event->x;
2483 tree_view->priv->press_start_y = event->y;
2484 tree_view->priv->press_start_node = node;
2486 if (tree_view->priv->rubber_banding_enable
2487 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2488 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2490 tree_view->priv->press_start_y += tree_view->priv->dy;
2491 tree_view->priv->rubber_band_x = event->x;
2492 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2493 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2495 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2496 tree_view->priv->rubber_band_ctrl = TRUE;
2497 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2498 tree_view->priv->rubber_band_shift = TRUE;
2503 /* Test if a double click happened on the same row. */
2504 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2506 int double_click_time, double_click_distance;
2508 g_object_get (gtk_settings_get_for_screen (
2509 gtk_widget_get_screen (widget)),
2510 "gtk-double-click-time", &double_click_time,
2511 "gtk-double-click-distance", &double_click_distance,
2514 /* Same conditions as _gdk_event_button_generate */
2515 if (tree_view->priv->last_button_x != -1 &&
2516 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2517 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2518 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2520 /* We do no longer compare paths of this row and the
2521 * row clicked previously. We use the double click
2522 * distance to decide whether this is a valid click,
2523 * allowing the mouse to slightly move over another row.
2525 row_double_click = TRUE;
2527 tree_view->priv->last_button_time = 0;
2528 tree_view->priv->last_button_x = -1;
2529 tree_view->priv->last_button_y = -1;
2533 tree_view->priv->last_button_time = event->time;
2534 tree_view->priv->last_button_x = event->x;
2535 tree_view->priv->last_button_y = event->y;
2539 if (row_double_click)
2541 gtk_grab_remove (widget);
2542 pspp_sheet_view_row_activated (tree_view, path, column);
2544 if (tree_view->priv->pressed_button == event->button)
2545 tree_view->priv->pressed_button = -1;
2548 gtk_tree_path_free (path);
2550 /* If we activated the row through a double click we don't want to grab
2551 * focus back, as moving focus to another widget is pretty common.
2553 if (!row_double_click)
2554 grab_focus_and_unset_draw_keyfocus (tree_view);
2559 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2561 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2563 column = list->data;
2564 if (event->window == column->window &&
2565 column->resizable &&
2570 if (gdk_pointer_grab (column->window, FALSE,
2571 GDK_POINTER_MOTION_HINT_MASK |
2572 GDK_BUTTON1_MOTION_MASK |
2573 GDK_BUTTON_RELEASE_MASK,
2574 NULL, NULL, event->time))
2577 gtk_grab_add (widget);
2578 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2579 column->resized_width = column->width;
2581 /* block attached dnd signal handler */
2582 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2584 g_signal_handlers_block_matched (widget,
2585 G_SIGNAL_MATCH_DATA,
2589 tree_view->priv->drag_pos = i;
2590 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2592 if (!gtk_widget_has_focus (widget))
2593 gtk_widget_grab_focus (widget);
2601 /* GtkWidget::button_release_event helper */
2603 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2604 GdkEventButton *event)
2606 PsppSheetView *tree_view;
2610 tree_view = PSPP_SHEET_VIEW (widget);
2612 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2613 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2614 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2616 /* Move the button back */
2617 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2619 g_object_ref (tree_view->priv->drag_column->button);
2620 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2621 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2622 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2623 g_object_unref (tree_view->priv->drag_column->button);
2624 gtk_widget_queue_resize (widget);
2625 if (tree_view->priv->drag_column->resizable)
2627 gdk_window_raise (tree_view->priv->drag_column->window);
2628 gdk_window_show (tree_view->priv->drag_column->window);
2631 gdk_window_hide (tree_view->priv->drag_column->window);
2633 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2637 if (tree_view->priv->cur_reorder &&
2638 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2639 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2640 tree_view->priv->cur_reorder->right_column);
2644 if (tree_view->priv->cur_reorder &&
2645 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2646 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2647 tree_view->priv->cur_reorder->left_column);
2649 tree_view->priv->drag_column = NULL;
2650 gdk_window_hide (tree_view->priv->drag_window);
2652 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2653 g_slice_free (PsppSheetViewColumnReorder, l->data);
2654 g_list_free (tree_view->priv->column_drag_info);
2655 tree_view->priv->column_drag_info = NULL;
2656 tree_view->priv->cur_reorder = NULL;
2658 if (tree_view->priv->drag_highlight_window)
2659 gdk_window_hide (tree_view->priv->drag_highlight_window);
2661 /* Reset our flags */
2662 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2663 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2668 /* GtkWidget::button_release_event helper */
2670 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2671 GdkEventButton *event)
2673 PsppSheetView *tree_view;
2676 tree_view = PSPP_SHEET_VIEW (widget);
2678 tree_view->priv->drag_pos = -1;
2680 /* unblock attached dnd signal handler */
2681 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2683 g_signal_handlers_unblock_matched (widget,
2684 G_SIGNAL_MATCH_DATA,
2688 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2689 gtk_grab_remove (widget);
2690 gdk_display_pointer_ungrab (gdk_window_get_display (event->window),
2696 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2697 GdkEventButton *event)
2699 GtkCellEditable *cell_editable;
2704 PsppSheetViewColumn *column;
2705 GdkRectangle background_area;
2706 GdkRectangle cell_area;
2712 if (event->window != tree_view->priv->bin_window)
2715 /* Ignore a released button, if that button wasn't depressed */
2716 if (tree_view->priv->pressed_button != event->button)
2719 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2723 /* decide if we edit */
2724 path = _pspp_sheet_view_find_path (tree_view, node);
2725 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2726 if (event->button != 1 || modifiers)
2729 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2730 pspp_sheet_view_column_cell_set_cell_data (column,
2731 tree_view->priv->model,
2734 if (!pspp_sheet_view_column_get_quick_edit (column)
2735 && _pspp_sheet_view_column_has_editable_cell (column))
2738 flags = 0; /* FIXME: get the right flags */
2739 path_string = gtk_tree_path_to_string (path);
2741 if (!_pspp_sheet_view_column_cell_event (column,
2749 if (cell_editable == NULL)
2752 pspp_sheet_view_real_set_cursor (tree_view, path,
2753 TRUE, TRUE, 0); /* XXX mode? */
2754 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2757 _pspp_sheet_view_column_get_neighbor_sizes (
2758 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2761 area.width -= right + left;
2763 pspp_sheet_view_real_start_editing (tree_view,
2770 g_free (path_string);
2771 gtk_tree_path_free (path);
2776 pspp_sheet_view_button_release (GtkWidget *widget,
2777 GdkEventButton *event)
2779 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2781 pspp_sheet_view_stop_editing (tree_view, FALSE);
2782 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2783 && pspp_sheet_view_button_release_edit (tree_view, event))
2785 if (tree_view->priv->pressed_button == event->button)
2786 tree_view->priv->pressed_button = -1;
2788 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2792 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2793 return pspp_sheet_view_button_release_drag_column (widget, event);
2795 if (tree_view->priv->rubber_band_status)
2796 pspp_sheet_view_stop_rubber_band (tree_view);
2798 if (tree_view->priv->pressed_button == event->button)
2799 tree_view->priv->pressed_button = -1;
2801 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2802 return pspp_sheet_view_button_release_column_resize (widget, event);
2808 pspp_sheet_view_grab_broken (GtkWidget *widget,
2809 GdkEventGrabBroken *event)
2811 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2813 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2814 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2816 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2817 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2822 /* GtkWidget::motion_event function set.
2826 do_prelight (PsppSheetView *tree_view,
2828 /* these are in bin_window coords */
2832 int prev_node = tree_view->priv->prelight_node;
2834 if (prev_node != node)
2836 tree_view->priv->prelight_node = node;
2839 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2842 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2848 prelight_or_select (PsppSheetView *tree_view,
2850 /* these are in bin_window coords */
2854 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2856 if (tree_view->priv->hover_selection &&
2857 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2858 !(tree_view->priv->edited_column &&
2859 tree_view->priv->edited_column->editable_widget))
2863 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2867 path = _pspp_sheet_view_find_path (tree_view, node);
2868 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2869 if (pspp_sheet_view_node_is_selected (tree_view, node))
2871 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2872 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE, 0); /* XXX mode? */
2874 gtk_tree_path_free (path);
2878 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2879 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2882 do_prelight (tree_view, node, x, y);
2886 ensure_unprelighted (PsppSheetView *tree_view)
2888 do_prelight (tree_view,
2890 -1000, -1000); /* coords not possibly over an arrow */
2892 g_assert (tree_view->priv->prelight_node < 0);
2896 update_prelight (PsppSheetView *tree_view,
2903 if (tree_view->priv->row_count == 0)
2908 ensure_unprelighted (tree_view);
2912 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2916 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2919 prelight_or_select (tree_view, node, x, y);
2925 /* Our motion arrow is either a box (in the case of the original spot)
2926 * or an arrow. It is expander_size wide.
2949 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2952 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2953 GtkWidget *widget = GTK_WIDGET (tree_view);
2954 GdkBitmap *mask = NULL;
2959 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2960 GdkWindowAttr attributes;
2961 guint attributes_mask;
2964 reorder->left_column == tree_view->priv->drag_column ||
2965 reorder->right_column == tree_view->priv->drag_column)
2966 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2967 else if (reorder->left_column || reorder->right_column)
2969 GdkRectangle visible_rect;
2970 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2971 if (reorder->left_column)
2972 x = reorder->left_column->allocation.x + reorder->left_column->allocation.width;
2974 x = reorder->right_column->allocation.x;
2976 if (x < visible_rect.x)
2977 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2978 else if (x > visible_rect.x + visible_rect.width)
2979 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2981 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2984 /* We want to draw the rectangle over the initial location. */
2985 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2990 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2992 if (tree_view->priv->drag_highlight_window)
2994 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2996 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2999 attributes.window_type = GDK_WINDOW_CHILD;
3000 attributes.wclass = GDK_INPUT_OUTPUT;
3001 attributes.x = tree_view->priv->drag_column_x;
3003 width = attributes.width = tree_view->priv->drag_column->allocation.width;
3004 height = attributes.height = tree_view->priv->drag_column->allocation.height;
3005 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3006 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3007 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3008 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3009 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
3010 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3012 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3013 gc = gdk_gc_new (mask);
3015 gdk_gc_set_foreground (gc, &col);
3016 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3018 gdk_gc_set_foreground(gc, &col);
3019 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
3020 g_object_unref (gc);
3022 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3024 if (mask) g_object_unref (mask);
3025 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
3028 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
3034 width = tree_view->priv->expander_size;
3036 /* Get x, y, width, height of arrow */
3037 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
3038 if (reorder->left_column)
3040 x += reorder->left_column->allocation.x + reorder->left_column->allocation.width - width/2;
3041 height = reorder->left_column->allocation.height;
3045 x += reorder->right_column->allocation.x - width/2;
3046 height = reorder->right_column->allocation.height;
3048 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
3049 height += tree_view->priv->expander_size;
3051 /* Create the new window */
3052 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
3054 if (tree_view->priv->drag_highlight_window)
3056 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3058 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3061 attributes.window_type = GDK_WINDOW_TEMP;
3062 attributes.wclass = GDK_INPUT_OUTPUT;
3063 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3064 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3065 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3066 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3069 attributes.width = width;
3070 attributes.height = height;
3071 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
3072 &attributes, attributes_mask);
3073 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3075 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3076 gc = gdk_gc_new (mask);
3078 gdk_gc_set_foreground (gc, &col);
3079 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3081 /* Draw the 2 arrows as per above */
3083 gdk_gc_set_foreground (gc, &col);
3084 for (i = 0; i < width; i ++)
3086 if (i == (width/2 - 1))
3088 gdk_draw_line (mask, gc, i, j, i, height - j);
3089 if (i < (width/2 - 1))
3094 g_object_unref (gc);
3095 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3097 if (mask) g_object_unref (mask);
3100 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
3101 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3103 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
3104 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3110 width = tree_view->priv->expander_size;
3112 /* Get x, y, width, height of arrow */
3113 width = width/2; /* remember, the arrow only takes half the available width */
3114 gdk_window_get_origin (gtk_widget_get_window (widget), &x, &y);
3115 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3116 x += widget->allocation.width - width;
3118 if (reorder->left_column)
3119 height = reorder->left_column->allocation.height;
3121 height = reorder->right_column->allocation.height;
3123 y -= tree_view->priv->expander_size;
3124 height += 2*tree_view->priv->expander_size;
3126 /* Create the new window */
3127 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
3128 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3130 if (tree_view->priv->drag_highlight_window)
3132 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3134 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3137 attributes.window_type = GDK_WINDOW_TEMP;
3138 attributes.wclass = GDK_INPUT_OUTPUT;
3139 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3140 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3141 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3142 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3145 attributes.width = width;
3146 attributes.height = height;
3147 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3148 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3150 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3151 gc = gdk_gc_new (mask);
3153 gdk_gc_set_foreground (gc, &col);
3154 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3156 /* Draw the 2 arrows as per above */
3158 gdk_gc_set_foreground (gc, &col);
3159 j = tree_view->priv->expander_size;
3160 for (i = 0; i < width; i ++)
3163 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3167 gdk_draw_line (mask, gc, k, j, k, height - j);
3168 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3169 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3172 g_object_unref (gc);
3173 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3175 if (mask) g_object_unref (mask);
3178 tree_view->priv->drag_column_window_state = arrow_type;
3179 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3183 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3184 gdk_window_hide (tree_view->priv->drag_highlight_window);
3188 gdk_window_show (tree_view->priv->drag_highlight_window);
3189 gdk_window_raise (tree_view->priv->drag_highlight_window);
3194 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3195 GdkEventMotion *event)
3199 PsppSheetViewColumn *column;
3200 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3202 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3204 if (event->is_hint || event->window != gtk_widget_get_window (widget))
3205 gtk_widget_get_pointer (widget, &x, NULL);
3209 if (tree_view->priv->hadjustment)
3210 x += gtk_adjustment_get_value (tree_view->priv->hadjustment);
3212 new_width = pspp_sheet_view_new_column_width (tree_view,
3213 tree_view->priv->drag_pos, &x);
3214 if (x != tree_view->priv->x_drag &&
3215 (new_width != column->fixed_width))
3217 column->use_resized_width = TRUE;
3218 column->resized_width = new_width;
3221 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3223 gtk_widget_queue_resize (widget);
3231 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3233 PsppSheetViewColumnReorder *reorder = NULL;
3237 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3238 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3240 reorder = (PsppSheetViewColumnReorder *) list->data;
3241 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3246 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3249 tree_view->priv->cur_reorder = reorder;
3250 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3254 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3256 GdkRectangle visible_rect;
3261 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3262 y += tree_view->priv->dy;
3264 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3266 /* see if we are near the edge. */
3267 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3270 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3275 value = CLAMP (gtk_adjustment_get_value (tree_view->priv->vadjustment) + offset, 0.0,
3276 gtk_adjustment_get_upper (tree_view->priv->vadjustment) - gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
3277 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3281 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3283 GdkRectangle visible_rect;
3288 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3290 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3292 /* See if we are near the edge. */
3293 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3296 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3302 value = CLAMP (gtk_adjustment_get_value (tree_view->priv->hadjustment) + offset,
3303 0.0, gtk_adjustment_get_upper (tree_view->priv->hadjustment) - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
3304 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3311 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3312 GdkEventMotion *event)
3314 PsppSheetView *tree_view = (PsppSheetView *) widget;
3315 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3317 GtkAllocation allocation;
3320 if ((column == NULL) ||
3321 (event->window != tree_view->priv->drag_window))
3324 /* Handle moving the header */
3325 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3326 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
3327 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3328 MAX (tree_view->priv->width, allocation.width) - column->allocation.width);
3329 gdk_window_move (tree_view->priv->drag_window, x, y);
3331 /* autoscroll, if needed */
3332 pspp_sheet_view_horizontal_autoscroll (tree_view);
3333 /* Update the current reorder position and arrow; */
3334 pspp_sheet_view_update_current_reorder (tree_view);
3340 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3342 remove_scroll_timeout (tree_view);
3343 gtk_grab_remove (GTK_WIDGET (tree_view));
3345 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3347 GtkTreePath *tmp_path;
3349 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3351 /* The anchor path should be set to the start path */
3352 tmp_path = _pspp_sheet_view_find_path (tree_view,
3353 tree_view->priv->rubber_band_start_node);
3355 if (tree_view->priv->anchor)
3356 gtk_tree_row_reference_free (tree_view->priv->anchor);
3358 tree_view->priv->anchor =
3359 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3360 tree_view->priv->model,
3363 gtk_tree_path_free (tmp_path);
3365 /* ... and the cursor to the end path */
3366 tmp_path = _pspp_sheet_view_find_path (tree_view,
3367 tree_view->priv->rubber_band_end_node);
3368 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE, 0); /* XXX mode? */
3369 gtk_tree_path_free (tmp_path);
3371 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3374 /* Clear status variables */
3375 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3376 tree_view->priv->rubber_band_shift = 0;
3377 tree_view->priv->rubber_band_ctrl = 0;
3379 tree_view->priv->rubber_band_start_node = -1;
3380 tree_view->priv->rubber_band_end_node = -1;
3384 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3388 gboolean skip_start,
3391 if (start_node == end_node)
3394 /* We skip the first node and jump inside the loop */
3400 /* Small optimization by assuming insensitive nodes are never
3405 if (tree_view->priv->rubber_band_shift)
3406 pspp_sheet_view_node_select (tree_view, start_node);
3407 else if (tree_view->priv->rubber_band_ctrl)
3409 /* Toggle the selection state */
3410 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3411 pspp_sheet_view_node_unselect (tree_view, start_node);
3413 pspp_sheet_view_node_select (tree_view, start_node);
3416 pspp_sheet_view_node_select (tree_view, start_node);
3420 /* Mirror the above */
3421 if (tree_view->priv->rubber_band_shift)
3422 pspp_sheet_view_node_unselect (tree_view, start_node);
3423 else if (tree_view->priv->rubber_band_ctrl)
3425 /* Toggle the selection state */
3426 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3427 pspp_sheet_view_node_unselect (tree_view, start_node);
3429 pspp_sheet_view_node_select (tree_view, start_node);
3432 pspp_sheet_view_node_unselect (tree_view, start_node);
3435 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3437 if (start_node == end_node)
3442 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3445 /* Ran out of tree */
3448 if (skip_end && start_node == end_node)
3455 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3458 return node * tree_view->priv->fixed_height;
3462 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3466 int fixed_height = tree_view->priv->fixed_height;
3467 if (fixed_height <= 0
3469 || height >= tree_view->priv->row_count * fixed_height)
3476 *new_node = height / fixed_height;
3477 return height % fixed_height;
3482 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3487 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3488 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3490 /* Handle the start area first */
3491 if (tree_view->priv->rubber_band_start_node < 0)
3493 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3500 else if (start_node < tree_view->priv->rubber_band_start_node)
3502 /* New node is above the old one; selection became bigger */
3503 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3505 tree_view->priv->rubber_band_start_node,
3510 else if (start_node > tree_view->priv->rubber_band_start_node)
3512 /* New node is below the old one; selection became smaller */
3513 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3514 tree_view->priv->rubber_band_start_node,
3521 tree_view->priv->rubber_band_start_node = start_node;
3523 /* Next, handle the end area */
3524 if (tree_view->priv->rubber_band_end_node < 0)
3526 /* In the event this happens, start_node was also -1; this case is
3530 else if (end_node < 0)
3532 /* Find the last node in the tree */
3533 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3536 /* Selection reached end of the tree */
3537 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3538 tree_view->priv->rubber_band_end_node,
3544 else if (end_node > tree_view->priv->rubber_band_end_node)
3546 /* New node is below the old one; selection became bigger */
3547 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3548 tree_view->priv->rubber_band_end_node,
3554 else if (end_node < tree_view->priv->rubber_band_end_node)
3556 /* New node is above the old one; selection became smaller */
3557 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3559 tree_view->priv->rubber_band_end_node,
3565 tree_view->priv->rubber_band_end_node = end_node;
3568 #define GDK_RECTANGLE_PTR(X) ((GdkRectangle *)(X))
3571 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3574 cairo_rectangle_int_t old_area;
3575 cairo_rectangle_int_t new_area;
3576 cairo_rectangle_int_t common;
3577 cairo_region_t *invalid_region;
3578 PsppSheetViewColumn *column;
3580 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3581 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3582 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3583 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3585 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3588 y = MAX (y, 0) + tree_view->priv->dy;
3590 new_area.x = MIN (tree_view->priv->press_start_x, x);
3591 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3592 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3593 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3595 invalid_region = cairo_region_create_rectangle (&old_area);
3596 cairo_region_union_rectangle (invalid_region, &new_area);
3598 gdk_rectangle_intersect (GDK_RECTANGLE_PTR (&old_area),
3599 GDK_RECTANGLE_PTR (&new_area), GDK_RECTANGLE_PTR (&common));
3600 if (common.width > 2 && common.height > 2)
3602 cairo_region_t *common_region;
3604 /* make sure the border is invalidated */
3610 common_region = cairo_region_create_rectangle (&common);
3612 cairo_region_subtract (invalid_region, common_region);
3613 cairo_region_destroy (common_region);
3616 #if GTK_MAJOR_VERSION == 3
3617 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3620 cairo_rectangle_int_t extents;
3622 cairo_region_get_extents (invalid_region, &extents);
3623 ereg = gdk_region_rectangle (GDK_RECTANGLE_PTR (&extents));
3624 gdk_window_invalidate_region (tree_view->priv->bin_window, ereg, TRUE);
3625 gdk_region_destroy (ereg);
3629 cairo_region_destroy (invalid_region);
3631 tree_view->priv->rubber_band_x = x;
3632 tree_view->priv->rubber_band_y = y;
3633 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3635 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3636 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3637 tree_view->priv->anchor_column,
3640 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3642 pspp_sheet_view_update_rubber_band_selection (tree_view);
3647 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3652 GdkRectangle rubber_rect;
3656 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3657 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3658 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3659 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3661 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3664 cr = gdk_cairo_create (tree_view->priv->bin_window);
3665 cairo_set_line_width (cr, 1.0);
3667 style = gtk_widget_get_style (GTK_WIDGET (tree_view));
3668 cairo_set_source_rgba (cr,
3669 style->fg[GTK_STATE_NORMAL].red / 65535.,
3670 style->fg[GTK_STATE_NORMAL].green / 65535.,
3671 style->fg[GTK_STATE_NORMAL].blue / 65535.,
3674 gdk_cairo_rectangle (cr, &rect);
3678 cairo_set_source_rgb (cr,
3679 style->fg[GTK_STATE_NORMAL].red / 65535.,
3680 style->fg[GTK_STATE_NORMAL].green / 65535.,
3681 style->fg[GTK_STATE_NORMAL].blue / 65535.);
3683 cairo_rectangle (cr,
3684 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3685 rubber_rect.width - 1, rubber_rect.height - 1);
3694 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3695 GdkEventMotion *event)
3697 PsppSheetView *tree_view;
3701 tree_view = (PsppSheetView *) widget;
3703 if (tree_view->priv->row_count == 0)
3706 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3708 GdkRectangle background_area, cell_area;
3709 PsppSheetViewColumn *column;
3711 if (find_click (tree_view, event->x, event->y, &node, &column,
3712 &background_area, &cell_area)
3713 && tree_view->priv->focus_column == column
3714 && tree_view->priv->press_start_node == node)
3717 gtk_grab_add (GTK_WIDGET (tree_view));
3718 pspp_sheet_view_update_rubber_band (tree_view);
3720 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3722 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3724 pspp_sheet_view_update_rubber_band (tree_view);
3726 add_scroll_timeout (tree_view);
3729 /* only check for an initiated drag when a button is pressed */
3730 if (tree_view->priv->pressed_button >= 0
3731 && !tree_view->priv->rubber_band_status)
3732 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3734 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3738 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3740 tree_view->priv->event_last_x = event->x;
3741 tree_view->priv->event_last_y = event->y;
3743 prelight_or_select (tree_view, node, event->x, event->y);
3749 pspp_sheet_view_motion (GtkWidget *widget,
3750 GdkEventMotion *event)
3752 PsppSheetView *tree_view;
3754 tree_view = (PsppSheetView *) widget;
3756 /* Resizing a column */
3757 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3758 return pspp_sheet_view_motion_resize_column (widget, event);
3761 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3762 return pspp_sheet_view_motion_drag_column (widget, event);
3764 /* Sanity check it */
3765 if (event->window == tree_view->priv->bin_window)
3766 return pspp_sheet_view_motion_bin_window (widget, event);
3771 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3772 * the tree is empty.
3775 invalidate_empty_focus (PsppSheetView *tree_view)
3779 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3784 area.width = gdk_window_get_width (tree_view->priv->bin_window);
3785 area.height = gdk_window_get_height (tree_view->priv->bin_window);
3786 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3789 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3793 draw_empty_focus (PsppSheetView *tree_view)
3795 GtkWidget *widget = GTK_WIDGET (tree_view);
3797 cairo_t *cr = gdk_cairo_create (tree_view->priv->bin_window);
3799 if (!gtk_widget_has_focus (widget))
3802 w = gdk_window_get_width (tree_view->priv->bin_window);
3803 h = gdk_window_get_height (tree_view->priv->bin_window);
3809 gtk_paint_focus (gtk_widget_get_style (widget),
3811 gtk_widget_get_state (widget),
3819 pspp_sheet_view_draw_vertical_grid_lines (PsppSheetView *tree_view,
3821 gint n_visible_columns,
3825 GList *list = tree_view->priv->columns;
3829 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3830 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3833 /* Only draw the lines for visible rows and columns */
3834 for (list = tree_view->priv->columns; list; list = list->next, i++)
3836 PsppSheetViewColumn *column = list->data;
3838 /* We don't want a line for the last column */
3839 if (i == n_visible_columns - 1)
3842 if (! column->visible)
3845 current_x += column->width;
3847 cairo_set_line_width (cr, 1.0);
3848 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
3849 cairo_move_to (cr, current_x - 0.5, min_y);
3850 cairo_line_to (cr, current_x - 0.5 , max_y - min_y);
3856 /* Warning: Very scary function.
3857 * Modify at your own risk
3859 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3860 * FIXME: It's not...
3863 pspp_sheet_view_bin_expose (GtkWidget *widget,
3866 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3871 int drag_highlight = -1;
3874 gint y_offset, cell_offset;
3876 GdkRectangle background_area;
3877 GdkRectangle cell_area;
3879 gint bin_window_width;
3880 gint bin_window_height;
3881 GtkTreePath *cursor_path;
3882 GtkTreePath *drag_dest_path;
3883 GList *first_column, *last_column;
3884 gint vertical_separator;
3885 gint horizontal_separator;
3886 gint focus_line_width;
3887 gboolean allow_rules;
3888 gboolean has_special_cell;
3890 gint n_visible_columns;
3891 gint grid_line_width;
3892 gboolean row_ending_details;
3893 gboolean draw_vgrid_lines, draw_hgrid_lines;
3897 GtkAllocation allocation;
3898 gtk_widget_get_allocation (widget, &allocation);
3902 Zarea.height = allocation.height;
3904 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3906 gtk_widget_style_get (widget,
3907 "horizontal-separator", &horizontal_separator,
3908 "vertical-separator", &vertical_separator,
3909 "allow-rules", &allow_rules,
3910 "focus-line-width", &focus_line_width,
3911 "row-ending-details", &row_ending_details,
3914 if (tree_view->priv->row_count == 0)
3916 draw_empty_focus (tree_view);
3921 /* clip event->area to the visible area */
3922 if (Zarea.height < 0.5)
3926 validate_visible_area (tree_view);
3928 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, Zarea.y);
3932 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3934 gdk_window_get_width (tree_view->priv->bin_window);
3937 gdk_window_get_height (tree_view->priv->bin_window);
3940 if (tree_view->priv->height < bin_window_height)
3942 gtk_paint_flat_box (gtk_widget_get_style (widget),
3944 gtk_widget_get_state (widget),
3948 0, tree_view->priv->height,
3950 bin_window_height - tree_view->priv->height);
3956 /* find the path for the node */
3957 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3958 gtk_tree_model_get_iter (tree_view->priv->model,
3961 gtk_tree_path_free (path);
3964 drag_dest_path = NULL;
3966 if (tree_view->priv->cursor)
3967 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3970 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3972 if (tree_view->priv->drag_dest_row)
3973 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3976 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3980 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3981 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3983 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3984 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3986 if (draw_vgrid_lines || draw_hgrid_lines)
3987 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3989 n_visible_columns = 0;
3990 for (list = tree_view->priv->columns; list; list = list->next)
3992 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3994 n_visible_columns ++;
3997 /* Find the last column */
3998 for (last_column = g_list_last (tree_view->priv->columns);
3999 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
4000 last_column = last_column->prev)
4004 for (first_column = g_list_first (tree_view->priv->columns);
4005 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
4006 first_column = first_column->next)
4009 /* Actually process the expose event. To do this, we want to
4010 * start at the first node of the event, and walk the tree in
4011 * order, drawing each successive node.
4018 gboolean is_first = FALSE;
4019 gboolean is_last = FALSE;
4020 gboolean done = FALSE;
4023 max_height = ROW_HEIGHT (tree_view);
4027 background_area.y = y_offset + Zarea.y;
4028 background_area.height = max_height;
4029 max_y = background_area.y + max_height;
4033 if (node == tree_view->priv->prelight_node)
4034 flags |= GTK_CELL_RENDERER_PRELIT;
4036 selected = pspp_sheet_view_node_is_selected (tree_view, node);
4040 if (tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
4042 /* we *need* to set cell data on all cells before the call
4043 * to _has_special_cell, else _has_special_cell() does not
4044 * return a correct value.
4046 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
4048 list = (rtl ? list->prev : list->next))
4050 PsppSheetViewColumn *column = list->data;
4051 pspp_sheet_view_column_cell_set_cell_data (column,
4052 tree_view->priv->model,
4056 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
4059 has_special_cell = tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
4061 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
4063 list = (rtl ? list->prev : list->next))
4065 PsppSheetViewColumn *column = list->data;
4066 const gchar *detail = NULL;
4067 gboolean selected_column;
4070 if (!column->visible)
4073 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
4074 selected_column = column->selected && column->selectable;
4076 selected_column = TRUE;
4079 if (cell_offset > Zarea.x + Zarea.width ||
4080 cell_offset + column->width < Zarea.x)
4082 cell_offset += column->width;
4087 if (selected && selected_column)
4088 flags |= GTK_CELL_RENDERER_SELECTED;
4090 flags &= ~GTK_CELL_RENDERER_SELECTED;
4092 if (column->show_sort_indicator)
4093 flags |= GTK_CELL_RENDERER_SORTED;
4095 flags &= ~GTK_CELL_RENDERER_SORTED;
4098 flags |= GTK_CELL_RENDERER_FOCUSED;
4100 flags &= ~GTK_CELL_RENDERER_FOCUSED;
4102 background_area.x = cell_offset;
4103 background_area.width = column->width;
4105 cell_area = background_area;
4106 cell_area.y += vertical_separator / 2;
4107 cell_area.x += horizontal_separator / 2;
4108 cell_area.height -= vertical_separator;
4109 cell_area.width -= horizontal_separator;
4111 if (draw_vgrid_lines)
4113 if (list == first_column)
4115 cell_area.width -= grid_line_width / 2;
4117 else if (list == last_column)
4119 cell_area.x += grid_line_width / 2;
4120 cell_area.width -= grid_line_width / 2;
4124 cell_area.x += grid_line_width / 2;
4125 cell_area.width -= grid_line_width;
4129 if (draw_hgrid_lines)
4131 cell_area.y += grid_line_width / 2;
4132 cell_area.height -= grid_line_width;
4136 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
4138 cell_offset += column->width;
4143 pspp_sheet_view_column_cell_set_cell_data (column,
4144 tree_view->priv->model,
4147 /* Select the detail for drawing the cell. relevant
4148 * factors are parity, sortedness, and whether to
4151 if (allow_rules && tree_view->priv->has_rules)
4153 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4154 n_visible_columns >= 3)
4157 detail = "cell_odd_ruled_sorted";
4159 detail = "cell_even_ruled_sorted";
4164 detail = "cell_odd_ruled";
4166 detail = "cell_even_ruled";
4171 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4172 n_visible_columns >= 3)
4175 detail = "cell_odd_sorted";
4177 detail = "cell_even_sorted";
4182 detail = "cell_odd";
4184 detail = "cell_even";
4190 if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE)
4191 state = GTK_STATE_INSENSITIVE;
4192 else if (flags & GTK_CELL_RENDERER_SELECTED)
4193 state = GTK_STATE_SELECTED;
4195 state = GTK_STATE_NORMAL;
4197 /* Draw background */
4198 if (row_ending_details)
4200 char new_detail[128];
4202 is_first = (rtl ? !list->next : !list->prev);
4203 is_last = (rtl ? !list->prev : !list->next);
4205 /* (I don't like the snprintfs either, but couldn't find a
4208 if (is_first && is_last)
4209 g_snprintf (new_detail, 127, "%s", detail);
4211 g_snprintf (new_detail, 127, "%s_start", detail);
4213 g_snprintf (new_detail, 127, "%s_end", detail);
4215 g_snprintf (new_detail, 128, "%s_middle", detail);
4217 gtk_paint_flat_box (gtk_widget_get_style (widget),
4225 background_area.width,
4226 background_area.height);
4230 gtk_paint_flat_box (gtk_widget_get_style (widget),
4238 background_area.width,
4239 background_area.height);
4242 if (draw_hgrid_lines)
4244 cairo_set_line_width (cr, 1.0);
4245 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
4247 if (background_area.y >= 0)
4250 gdk_draw_line (event->window,
4251 tree_view->priv->grid_line_gc[widget->state],
4252 background_area.x, background_area.y,
4253 background_area.x + background_area.width,
4256 cairo_move_to (cr, background_area.x, background_area.y - 0.5);
4257 cairo_line_to (cr, background_area.x + background_area.width,
4258 background_area.y - 0.5);
4262 if (y_offset + max_height >= Zarea.height - 0.5)
4265 gdk_draw_line (event->window,
4266 tree_view->priv->grid_line_gc[widget->state],
4267 background_area.x, background_area.y + max_height,
4268 background_area.x + background_area.width,
4269 background_area.y + max_height);
4272 cairo_move_to (cr, background_area.x, background_area.y + max_height - 0.5);
4273 cairo_line_to (cr, background_area.x + background_area.width,
4274 background_area.y + max_height - 0.5);
4280 _pspp_sheet_view_column_cell_render (column,
4286 if (node == cursor && has_special_cell &&
4287 ((column == tree_view->priv->focus_column &&
4288 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4289 gtk_widget_has_focus (widget)) ||
4290 (column == tree_view->priv->edited_column)))
4292 _pspp_sheet_view_column_cell_draw_focus (column,
4299 cell_offset += column->width;
4302 if (cell_offset < Zarea.x)
4304 gtk_paint_flat_box (gtk_widget_get_style (widget),
4312 Zarea.x - cell_offset,
4313 background_area.height);
4316 if (node == drag_highlight)
4318 /* Draw indicator for the drop
4320 gint highlight_y = -1;
4324 switch (tree_view->priv->drag_dest_pos)
4326 case PSPP_SHEET_VIEW_DROP_BEFORE:
4327 highlight_y = background_area.y - 1;
4328 if (highlight_y < 0)
4332 case PSPP_SHEET_VIEW_DROP_AFTER:
4333 highlight_y = background_area.y + background_area.height - 1;
4336 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4337 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4338 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4342 width = gdk_window_get_width (tree_view->priv->bin_window);
4344 if (row_ending_details)
4345 gtk_paint_focus (gtk_widget_get_style (widget),
4347 gtk_widget_get_state (widget),
4350 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4351 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4352 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4353 - focus_line_width / 2,
4354 width, ROW_HEIGHT (tree_view)
4355 - focus_line_width + 1);
4357 gtk_paint_focus (gtk_widget_get_style (widget),
4359 gtk_widget_get_state (widget),
4361 "treeview-drop-indicator",
4362 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4363 - focus_line_width / 2,
4364 width, ROW_HEIGHT (tree_view)
4365 - focus_line_width + 1);
4370 if (highlight_y >= 0)
4372 gdk_draw_line (event->window,
4373 widget->style->fg_gc[gtk_widget_get_state (widget)],
4376 rtl ? 0 : bin_window_width,
4382 /* draw the big row-spanning focus rectangle, if needed */
4383 if (!has_special_cell && node == cursor &&
4384 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4385 gtk_widget_has_focus (widget))
4387 gint tmp_y, tmp_height;
4389 GtkStateType focus_rect_state;
4392 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4393 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4394 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4397 width = gdk_window_get_width (tree_view->priv->bin_window);
4399 if (draw_hgrid_lines)
4401 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4402 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4406 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4407 tmp_height = ROW_HEIGHT (tree_view);
4410 if (row_ending_details)
4411 gtk_paint_focus (gtk_widget_get_style (widget),
4416 ? (is_last ? "treeview" : "treeview-left" )
4417 : (is_last ? "treeview-right" : "treeview-middle" )),
4421 gtk_paint_focus (gtk_widget_get_style (widget),
4430 y_offset += max_height;
4434 node = pspp_sheet_view_node_next (tree_view, node);
4437 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4441 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4448 while (y_offset < Zarea.height);
4451 pspp_sheet_view_draw_vertical_grid_lines (tree_view, cr, n_visible_columns,
4455 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4457 GdkRectangle *rectangles;
4460 gdk_region_get_rectangles (event->region,
4464 while (n_rectangles--)
4465 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4467 g_free (rectangles);
4472 gtk_tree_path_free (cursor_path);
4475 gtk_tree_path_free (drag_dest_path);
4482 pspp_sheet_view_draw (GtkWidget *widget,
4485 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4486 GtkAllocation allocation;
4487 gtk_widget_get_allocation (widget, &allocation);
4489 if (gtk_cairo_should_draw_window (cr, tree_view->priv->bin_window))
4495 cairo_translate (cr, 0, gdk_window_get_height (tree_view->priv->header_window));
4496 retval = pspp_sheet_view_bin_expose (widget, cr);
4499 /* We can't just chain up to Container::expose as it will try to send the
4500 * event to the headers, so we handle propagating it to our children
4501 * (eg. widgets being edited) ourselves.
4503 tmp_list = tree_view->priv->children;
4506 PsppSheetViewChild *child = tmp_list->data;
4507 tmp_list = tmp_list->next;
4509 gtk_container_propagate_draw (GTK_CONTAINER (tree_view), child->widget, cr);
4514 else if (gtk_cairo_should_draw_window (cr, tree_view->priv->header_window))
4516 gint n_visible_columns;
4519 gtk_paint_flat_box (gtk_widget_get_style (widget),
4531 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4533 PsppSheetViewColumn *column = list->data;
4535 if (column == tree_view->priv->drag_column || !column->visible)
4538 if (span_intersects (column->allocation.x, column->allocation.width,
4539 allocation.x, allocation.width)
4540 && column->button != NULL)
4541 gtk_container_propagate_draw (GTK_CONTAINER (tree_view),
4542 column->button, cr);
4545 n_visible_columns = 0;
4546 for (list = tree_view->priv->columns; list; list = list->next)
4548 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4550 n_visible_columns ++;
4552 pspp_sheet_view_draw_vertical_grid_lines (tree_view,
4560 else if (gtk_cairo_should_draw_window (cr, tree_view->priv->drag_window))
4562 gtk_container_propagate_draw (GTK_CONTAINER (tree_view),
4563 tree_view->priv->drag_column->button,
4580 /* returns 0x1 when no column has been found -- yes it's hackish */
4581 static PsppSheetViewColumn *
4582 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4583 PsppSheetViewColumn *column,
4586 PsppSheetViewColumn *left_column = NULL;
4587 PsppSheetViewColumn *cur_column = NULL;
4590 if (!column->reorderable)
4591 return (PsppSheetViewColumn *)0x1;
4593 switch (drop_position)
4596 /* find first column where we can drop */
4597 tmp_list = tree_view->priv->columns;
4598 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4599 return (PsppSheetViewColumn *)0x1;
4603 g_assert (tmp_list);
4605 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4606 tmp_list = tmp_list->next;
4608 if (left_column && left_column->visible == FALSE)
4611 if (!tree_view->priv->column_drop_func)
4614 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4616 left_column = cur_column;
4623 if (!tree_view->priv->column_drop_func)
4626 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4629 return (PsppSheetViewColumn *)0x1;
4633 /* find first column after column where we can drop */
4634 tmp_list = tree_view->priv->columns;
4636 for (; tmp_list; tmp_list = tmp_list->next)
4637 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4640 if (!tmp_list || !tmp_list->next)
4641 return (PsppSheetViewColumn *)0x1;
4643 tmp_list = tmp_list->next;
4644 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4645 tmp_list = tmp_list->next;
4649 g_assert (tmp_list);
4651 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4652 tmp_list = tmp_list->next;
4654 if (left_column && left_column->visible == FALSE)
4656 left_column = cur_column;
4658 tmp_list = tmp_list->next;
4662 if (!tree_view->priv->column_drop_func)
4665 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4667 left_column = cur_column;
4674 if (!tree_view->priv->column_drop_func)
4677 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4680 return (PsppSheetViewColumn *)0x1;
4684 /* find first column before column where we can drop */
4685 tmp_list = tree_view->priv->columns;
4687 for (; tmp_list; tmp_list = tmp_list->next)
4688 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4691 if (!tmp_list || !tmp_list->prev)
4692 return (PsppSheetViewColumn *)0x1;
4694 tmp_list = tmp_list->prev;
4695 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4696 tmp_list = tmp_list->prev;
4700 g_assert (tmp_list);
4702 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4704 if (left_column && !left_column->visible)
4706 /*if (!tmp_list->prev)
4707 return (PsppSheetViewColumn *)0x1;
4710 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4711 tmp_list = tmp_list->prev->prev;
4714 cur_column = left_column;
4716 tmp_list = tmp_list->prev;
4720 if (!tree_view->priv->column_drop_func)
4723 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4726 cur_column = left_column;
4727 tmp_list = tmp_list->prev;
4730 if (!tree_view->priv->column_drop_func)
4733 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4736 return (PsppSheetViewColumn *)0x1;
4740 /* same as DROP_HOME case, but doing it backwards */
4741 tmp_list = g_list_last (tree_view->priv->columns);
4744 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4745 return (PsppSheetViewColumn *)0x1;
4749 g_assert (tmp_list);
4751 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4753 if (left_column && !left_column->visible)
4755 cur_column = left_column;
4756 tmp_list = tmp_list->prev;
4759 if (!tree_view->priv->column_drop_func)
4762 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4765 cur_column = left_column;
4766 tmp_list = tmp_list->prev;
4769 if (!tree_view->priv->column_drop_func)
4772 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4775 return (PsppSheetViewColumn *)0x1;
4779 return (PsppSheetViewColumn *)0x1;
4783 pspp_sheet_view_key_press (GtkWidget *widget,
4786 PsppSheetView *tree_view = (PsppSheetView *) widget;
4788 if (tree_view->priv->rubber_band_status)
4790 if (event->keyval == GDK_Escape)
4791 pspp_sheet_view_stop_rubber_band (tree_view);
4796 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4798 if (event->keyval == GDK_Escape)
4800 tree_view->priv->cur_reorder = NULL;
4801 pspp_sheet_view_button_release_drag_column (widget, NULL);
4806 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4808 GList *focus_column;
4811 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4813 for (focus_column = tree_view->priv->columns;
4815 focus_column = focus_column->next)
4817 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4819 if (column->button && gtk_widget_has_focus (column->button))
4824 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4825 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4826 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4828 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4830 if (!column->resizable)
4832 gtk_widget_error_bell (widget);
4836 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4837 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4839 gint old_width = column->resized_width;
4841 column->resized_width = MAX (column->resized_width,
4843 column->resized_width -= 2;
4844 if (column->resized_width < 0)
4845 column->resized_width = 0;
4847 if (column->min_width == -1)
4848 column->resized_width = MAX (column->button_request,
4849 column->resized_width);
4851 column->resized_width = MAX (column->min_width,
4852 column->resized_width);
4854 if (column->max_width != -1)
4855 column->resized_width = MIN (column->resized_width,
4858 column->use_resized_width = TRUE;
4860 if (column->resized_width != old_width)
4861 gtk_widget_queue_resize (widget);
4863 gtk_widget_error_bell (widget);
4865 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4866 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4868 gint old_width = column->resized_width;
4870 column->resized_width = MAX (column->resized_width,
4872 column->resized_width += 2;
4874 if (column->max_width != -1)
4875 column->resized_width = MIN (column->resized_width,
4878 column->use_resized_width = TRUE;
4880 if (column->resized_width != old_width)
4881 gtk_widget_queue_resize (widget);
4883 gtk_widget_error_bell (widget);
4890 (event->state & GDK_MOD1_MASK) &&
4891 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4892 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4893 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4894 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4896 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4898 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4899 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4901 PsppSheetViewColumn *col;
4902 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4903 if (col != (PsppSheetViewColumn *)0x1)
4904 pspp_sheet_view_move_column_after (tree_view, column, col);
4906 gtk_widget_error_bell (widget);
4908 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4909 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4911 PsppSheetViewColumn *col;
4912 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4913 if (col != (PsppSheetViewColumn *)0x1)
4914 pspp_sheet_view_move_column_after (tree_view, column, col);
4916 gtk_widget_error_bell (widget);
4918 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4920 PsppSheetViewColumn *col;
4921 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4922 if (col != (PsppSheetViewColumn *)0x1)
4923 pspp_sheet_view_move_column_after (tree_view, column, col);
4925 gtk_widget_error_bell (widget);
4927 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4929 PsppSheetViewColumn *col;
4930 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4931 if (col != (PsppSheetViewColumn *)0x1)
4932 pspp_sheet_view_move_column_after (tree_view, column, col);
4934 gtk_widget_error_bell (widget);
4941 /* Chain up to the parent class. It handles the keybindings. */
4942 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4945 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4947 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4951 /* We pass the event to the search_entry. If its text changes, then we start
4952 * the typeahead find capabilities. */
4953 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4954 && tree_view->priv->enable_search
4955 && !tree_view->priv->search_custom_entry_set)
4957 GdkEvent *new_event;
4959 const char *new_text;
4962 gboolean text_modified;
4963 gulong popup_menu_id;
4965 pspp_sheet_view_ensure_interactive_directory (tree_view);
4967 /* Make a copy of the current text */
4968 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4969 new_event = gdk_event_copy ((GdkEvent *) event);
4970 g_object_unref (((GdkEventKey *) new_event)->window);
4971 ((GdkEventKey *) new_event)->window = g_object_ref (gtk_widget_get_window (tree_view->priv->search_window));
4972 gtk_widget_realize (tree_view->priv->search_window);
4974 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4975 "popup-menu", G_CALLBACK (gtk_true),
4978 /* Move the entry off screen */
4979 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4980 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4981 gdk_screen_get_width (screen) + 1,
4982 gdk_screen_get_height (screen) + 1);
4983 gtk_widget_show (tree_view->priv->search_window);
4985 /* Send the event to the window. If the preedit_changed signal is emitted
4986 * during this event, we will set priv->imcontext_changed */
4987 tree_view->priv->imcontext_changed = FALSE;
4988 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4989 gdk_event_free (new_event);
4990 gtk_widget_hide (tree_view->priv->search_window);
4992 g_signal_handler_disconnect (tree_view->priv->search_entry,
4995 /* We check to make sure that the entry tried to handle the text, and that
4996 * the text has changed.
4998 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4999 text_modified = strcmp (old_text, new_text) != 0;
5001 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
5002 (retval && text_modified)) /* ...or the text was modified */
5004 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
5006 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
5011 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
5021 pspp_sheet_view_key_release (GtkWidget *widget,
5024 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
5026 if (tree_view->priv->rubber_band_status)
5029 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
5032 /* FIXME Is this function necessary? Can I get an enter_notify event
5033 * w/o either an expose event or a mouse motion event?
5036 pspp_sheet_view_enter_notify (GtkWidget *widget,
5037 GdkEventCrossing *event)
5039 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
5043 /* Sanity check it */
5044 if (event->window != tree_view->priv->bin_window)
5047 if (tree_view->priv->row_count == 0)
5050 if (event->mode == GDK_CROSSING_GRAB ||
5051 event->mode == GDK_CROSSING_GTK_GRAB ||
5052 event->mode == GDK_CROSSING_GTK_UNGRAB ||
5053 event->mode == GDK_CROSSING_STATE_CHANGED)
5056 /* find the node internally */
5057 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
5060 pspp_sheet_view_find_offset (tree_view, new_y, &node);
5062 tree_view->priv->event_last_x = event->x;
5063 tree_view->priv->event_last_y = event->y;
5065 prelight_or_select (tree_view, node, event->x, event->y);
5071 pspp_sheet_view_leave_notify (GtkWidget *widget,
5072 GdkEventCrossing *event)
5074 PsppSheetView *tree_view;
5076 if (event->mode == GDK_CROSSING_GRAB)
5079 tree_view = PSPP_SHEET_VIEW (widget);
5081 if (tree_view->priv->prelight_node >= 0)
5082 _pspp_sheet_view_queue_draw_node (tree_view,
5083 tree_view->priv->prelight_node,
5086 tree_view->priv->event_last_x = -10000;
5087 tree_view->priv->event_last_y = -10000;
5089 prelight_or_select (tree_view,
5091 -1000, -1000); /* coords not possibly over an arrow */
5098 pspp_sheet_view_focus_out (GtkWidget *widget,
5099 GdkEventFocus *event)
5101 PsppSheetView *tree_view;
5103 tree_view = PSPP_SHEET_VIEW (widget);
5105 gtk_widget_queue_draw (widget);
5107 /* destroy interactive search dialog */
5108 if (tree_view->priv->search_window)
5109 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
5115 /* Incremental Reflow
5119 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
5122 GtkAllocation allocation;
5123 gint y = pspp_sheet_view_node_find_offset (tree_view, node)
5124 - gtk_adjustment_get_value (tree_view->priv->vadjustment)
5125 + TREE_VIEW_HEADER_HEIGHT (tree_view);
5127 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5129 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
5132 tree_view->priv->fixed_height);
5136 node_is_visible (PsppSheetView *tree_view,
5142 y = pspp_sheet_view_node_find_offset (tree_view, node);
5143 height = ROW_HEIGHT (tree_view);
5145 if (y >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5146 y + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5147 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5153 /* Returns the row height. */
5155 validate_row (PsppSheetView *tree_view,
5160 PsppSheetViewColumn *column;
5161 GList *list, *first_column, *last_column;
5163 gint horizontal_separator;
5164 gint vertical_separator;
5165 gint focus_line_width;
5166 gboolean draw_vgrid_lines, draw_hgrid_lines;
5168 gint grid_line_width;
5169 gboolean wide_separators;
5170 gint separator_height;
5172 gtk_widget_style_get (GTK_WIDGET (tree_view),
5173 "focus-padding", &focus_pad,
5174 "focus-line-width", &focus_line_width,
5175 "horizontal-separator", &horizontal_separator,
5176 "vertical-separator", &vertical_separator,
5177 "grid-line-width", &grid_line_width,
5178 "wide-separators", &wide_separators,
5179 "separator-height", &separator_height,
5183 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5184 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5186 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5187 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5189 for (last_column = g_list_last (tree_view->priv->columns);
5190 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5191 last_column = last_column->prev)
5194 for (first_column = g_list_first (tree_view->priv->columns);
5195 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5196 first_column = first_column->next)
5199 for (list = tree_view->priv->columns; list; list = list->next)
5204 column = list->data;
5206 if (! column->visible)
5209 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5210 pspp_sheet_view_column_cell_get_size (column,
5212 &tmp_width, &tmp_height);
5214 tmp_height += vertical_separator;
5215 height = MAX (height, tmp_height);
5217 tmp_width = tmp_width + horizontal_separator;
5219 if (draw_vgrid_lines)
5221 if (list->data == first_column || list->data == last_column)
5222 tmp_width += grid_line_width / 2.0;
5224 tmp_width += grid_line_width;
5227 if (tmp_width > column->requested_width)
5228 column->requested_width = tmp_width;
5231 if (draw_hgrid_lines)
5232 height += grid_line_width;
5234 tree_view->priv->post_validation_flag = TRUE;
5240 validate_visible_area (PsppSheetView *tree_view)
5242 GtkTreePath *path = NULL;
5243 GtkTreePath *above_path = NULL;
5246 gboolean size_changed = FALSE;
5248 gint area_above = 0;
5249 gint area_below = 0;
5250 GtkAllocation allocation;
5252 if (tree_view->priv->row_count == 0)
5255 if (tree_view->priv->scroll_to_path == NULL)
5258 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5260 total_height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5262 if (total_height == 0)
5265 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5268 /* we are going to scroll, and will update dy */
5269 _pspp_sheet_view_find_node (tree_view, path, &node);
5270 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5272 if (tree_view->priv->scroll_to_use_align)
5274 gint height = ROW_HEIGHT (tree_view);
5275 area_above = (total_height - height) *
5276 tree_view->priv->scroll_to_row_align;
5277 area_below = total_height - area_above - height;
5278 area_above = MAX (area_above, 0);
5279 area_below = MAX (area_below, 0);
5284 * 1) row not visible
5288 gint height = ROW_HEIGHT (tree_view);
5290 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5292 if (dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5293 dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5294 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5296 /* row visible: keep the row at the same position */
5297 area_above = dy - gtk_adjustment_get_value (tree_view->priv->vadjustment);
5298 area_below = (gtk_adjustment_get_value (tree_view->priv->vadjustment) +
5299 gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5304 /* row not visible */
5306 && dy + height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5308 /* row at the beginning -- fixed */
5310 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment)
5311 - area_above - height;
5313 else if (dy >= (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5314 gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5316 /* row at the end -- fixed */
5317 area_above = dy - (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5318 gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
5319 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) -
5320 area_above - height;
5324 area_above = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) - height;
5330 /* row somewhere in the middle, bring it to the top
5334 area_below = total_height - height;
5340 /* the scroll to isn't valid; ignore it.
5343 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5344 tree_view->priv->scroll_to_path = NULL;
5348 above_path = gtk_tree_path_copy (path);
5350 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5351 * backwards is much slower then forward, as there is no iter_prev function.
5352 * We go forwards first in case we run out of tree. Then we go backwards to
5355 while (node >= 0 && area_below > 0)
5357 gboolean done = FALSE;
5360 node = pspp_sheet_view_node_next (tree_view, node);
5363 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5365 gtk_tree_path_next (path);
5368 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5378 area_below -= ROW_HEIGHT (tree_view);
5380 gtk_tree_path_free (path);
5382 /* If we ran out of tree, and have extra area_below left, we need to add it
5385 area_above += area_below;
5387 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5389 /* We walk backwards */
5390 while (area_above > 0)
5392 node = pspp_sheet_view_node_prev (tree_view, node);
5394 /* Always find the new path in the tree. We cannot just assume
5395 * a gtk_tree_path_prev() is enough here, as there might be children
5396 * in between this node and the previous sibling node. If this
5397 * appears to be a performance hotspot in profiles, we can look into
5398 * intrigate logic for keeping path, node and iter in sync like
5399 * we do for forward walks. (Which will be hard because of the lacking
5406 gtk_tree_path_free (above_path);
5407 above_path = _pspp_sheet_view_find_path (tree_view, node);
5409 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5411 area_above -= ROW_HEIGHT (tree_view);
5414 /* set the dy here to scroll to the path,
5415 * and sync the top row accordingly
5417 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5418 pspp_sheet_view_top_row_to_dy (tree_view);
5420 /* update width/height and queue a resize */
5423 GtkRequisition requisition;
5425 /* We temporarily guess a size, under the assumption that it will be the
5426 * same when we get our next size_allocate. If we don't do this, we'll be
5427 * in an inconsistent state if we call top_row_to_dy. */
5429 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5430 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5431 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5432 gtk_adjustment_changed (tree_view->priv->hadjustment);
5433 gtk_adjustment_changed (tree_view->priv->vadjustment);
5434 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5437 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5438 tree_view->priv->scroll_to_path = NULL;
5441 gtk_tree_path_free (above_path);
5443 if (tree_view->priv->scroll_to_column)
5445 tree_view->priv->scroll_to_column = NULL;
5447 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5451 initialize_fixed_height_mode (PsppSheetView *tree_view)
5453 if (!tree_view->priv->row_count)
5456 if (tree_view->priv->fixed_height_set)
5459 if (tree_view->priv->fixed_height < 0)
5466 path = _pspp_sheet_view_find_path (tree_view, node);
5467 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5469 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5471 gtk_tree_path_free (path);
5473 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5477 /* Our strategy for finding nodes to validate is a little convoluted. We find
5478 * the left-most uninvalidated node. We then try walking right, validating
5479 * nodes. Once we find a valid node, we repeat the previous process of finding
5480 * the first invalid node.
5484 validate_rows_handler (PsppSheetView *tree_view)
5486 initialize_fixed_height_mode (tree_view);
5487 if (tree_view->priv->validate_rows_timer)
5489 g_source_remove (tree_view->priv->validate_rows_timer);
5490 tree_view->priv->validate_rows_timer = 0;
5497 do_presize_handler (PsppSheetView *tree_view)
5499 GtkRequisition requisition;
5501 validate_visible_area (tree_view);
5502 tree_view->priv->presize_handler_timer = 0;
5504 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5507 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5509 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5510 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5511 gtk_adjustment_changed (tree_view->priv->hadjustment);
5512 gtk_adjustment_changed (tree_view->priv->vadjustment);
5513 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5519 presize_handler_callback (gpointer data)
5521 do_presize_handler (PSPP_SHEET_VIEW (data));
5527 install_presize_handler (PsppSheetView *tree_view)
5529 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5532 if (! tree_view->priv->presize_handler_timer)
5534 tree_view->priv->presize_handler_timer =
5535 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5537 if (! tree_view->priv->validate_rows_timer)
5539 tree_view->priv->validate_rows_timer =
5540 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5545 scroll_sync_handler (PsppSheetView *tree_view)
5547 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5548 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5549 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5550 pspp_sheet_view_top_row_to_dy (tree_view);
5552 pspp_sheet_view_dy_to_top_row (tree_view);
5554 tree_view->priv->scroll_sync_timer = 0;
5560 install_scroll_sync_handler (PsppSheetView *tree_view)
5562 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5565 if (!tree_view->priv->scroll_sync_timer)
5567 tree_view->priv->scroll_sync_timer =
5568 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5573 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5577 gtk_tree_row_reference_free (tree_view->priv->top_row);
5581 tree_view->priv->top_row = NULL;
5582 tree_view->priv->top_row_dy = 0;
5586 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5587 tree_view->priv->top_row_dy = offset;
5591 /* Always call this iff dy is in the visible range. If the tree is empty, then
5592 * it's set to be NULL, and top_row_dy is 0;
5595 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5601 if (tree_view->priv->row_count == 0)
5603 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5607 offset = pspp_sheet_view_find_offset (tree_view,
5608 tree_view->priv->dy,
5613 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5617 path = _pspp_sheet_view_find_path (tree_view, node);
5618 pspp_sheet_view_set_top_row (tree_view, path, offset);
5619 gtk_tree_path_free (path);
5625 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5631 /* Avoid recursive calls */
5632 if (tree_view->priv->in_top_row_to_dy)
5635 if (tree_view->priv->top_row)
5636 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5643 _pspp_sheet_view_find_node (tree_view, path, &node);
5646 gtk_tree_path_free (path);
5650 /* keep dy and set new toprow */
5651 gtk_tree_row_reference_free (tree_view->priv->top_row);
5652 tree_view->priv->top_row = NULL;
5653 tree_view->priv->top_row_dy = 0;
5654 /* DO NOT install the idle handler */
5655 pspp_sheet_view_dy_to_top_row (tree_view);
5659 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5661 /* new top row -- do NOT install the idle handler */
5662 pspp_sheet_view_dy_to_top_row (tree_view);
5666 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5667 new_dy += tree_view->priv->top_row_dy;
5669 if (new_dy + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
5670 new_dy = tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
5672 new_dy = MAX (0, new_dy);
5674 tree_view->priv->in_top_row_to_dy = TRUE;
5675 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5676 tree_view->priv->in_top_row_to_dy = FALSE;
5681 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5683 install_presize_handler (tree_view);
5689 set_source_row (GdkDragContext *context,
5690 GtkTreeModel *model,
5691 GtkTreePath *source_row)
5693 g_object_set_data_full (G_OBJECT (context),
5694 "gtk-tree-view-source-row",
5695 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5696 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5700 get_source_row (GdkDragContext *context)
5702 GtkTreeRowReference *ref =
5703 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5706 return gtk_tree_row_reference_get_path (ref);
5713 GtkTreeRowReference *dest_row;
5714 guint path_down_mode : 1;
5715 guint empty_view_drop : 1;
5716 guint drop_append_mode : 1;
5721 dest_row_free (gpointer data)
5723 DestRow *dr = (DestRow *)data;
5725 gtk_tree_row_reference_free (dr->dest_row);
5726 g_slice_free (DestRow, dr);
5730 set_dest_row (GdkDragContext *context,
5731 GtkTreeModel *model,
5732 GtkTreePath *dest_row,
5733 gboolean path_down_mode,
5734 gboolean empty_view_drop,
5735 gboolean drop_append_mode)
5741 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5746 dr = g_slice_new (DestRow);
5748 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5749 dr->path_down_mode = path_down_mode != FALSE;
5750 dr->empty_view_drop = empty_view_drop != FALSE;
5751 dr->drop_append_mode = drop_append_mode != FALSE;
5753 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5754 dr, (GDestroyNotify) dest_row_free);
5758 get_dest_row (GdkDragContext *context,
5759 gboolean *path_down_mode)
5762 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5766 GtkTreePath *path = NULL;
5769 *path_down_mode = dr->path_down_mode;
5772 path = gtk_tree_row_reference_get_path (dr->dest_row);
5773 else if (dr->empty_view_drop)
5774 path = gtk_tree_path_new_from_indices (0, -1);
5778 if (path && dr->drop_append_mode)
5779 gtk_tree_path_next (path);
5787 /* Get/set whether drag_motion requested the drag data and
5788 * drag_data_received should thus not actually insert the data,
5789 * since the data doesn't result from a drop.
5792 set_status_pending (GdkDragContext *context,
5793 GdkDragAction suggested_action)
5795 g_object_set_data (G_OBJECT (context),
5796 "gtk-tree-view-status-pending",
5797 GINT_TO_POINTER (suggested_action));
5800 static GdkDragAction
5801 get_status_pending (GdkDragContext *context)
5803 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5804 "gtk-tree-view-status-pending"));
5807 static TreeViewDragInfo*
5808 get_info (PsppSheetView *tree_view)
5810 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5814 destroy_info (TreeViewDragInfo *di)
5816 g_slice_free (TreeViewDragInfo, di);
5819 static TreeViewDragInfo*
5820 ensure_info (PsppSheetView *tree_view)
5822 TreeViewDragInfo *di;
5824 di = get_info (tree_view);
5828 di = g_slice_new0 (TreeViewDragInfo);
5830 g_object_set_data_full (G_OBJECT (tree_view),
5831 "gtk-tree-view-drag-info",
5833 (GDestroyNotify) destroy_info);
5840 remove_info (PsppSheetView *tree_view)
5842 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5847 drag_scan_timeout (gpointer data)
5849 PsppSheetView *tree_view;
5851 GdkModifierType state;
5852 GtkTreePath *path = NULL;
5853 PsppSheetViewColumn *column = NULL;
5854 GdkRectangle visible_rect;
5856 GDK_THREADS_ENTER ();
5858 tree_view = PSPP_SHEET_VIEW (data);
5860 gdk_window_get_pointer (tree_view->priv->bin_window,
5863 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5865 /* See if we are near the edge. */
5866 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5867 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5868 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5869 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5871 pspp_sheet_view_get_path_at_pos (tree_view,
5872 tree_view->priv->bin_window,
5881 pspp_sheet_view_scroll_to_cell (tree_view,
5887 gtk_tree_path_free (path);
5891 GDK_THREADS_LEAVE ();
5898 add_scroll_timeout (PsppSheetView *tree_view)
5900 if (tree_view->priv->scroll_timeout == 0)
5902 tree_view->priv->scroll_timeout =
5903 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5908 remove_scroll_timeout (PsppSheetView *tree_view)
5910 if (tree_view->priv->scroll_timeout != 0)
5912 g_source_remove (tree_view->priv->scroll_timeout);
5913 tree_view->priv->scroll_timeout = 0;
5918 check_model_dnd (GtkTreeModel *model,
5919 GType required_iface,
5920 const gchar *signal)
5922 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5924 g_warning ("You must override the default '%s' handler "
5925 "on PsppSheetView when using models that don't support "
5926 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5927 "is to connect to '%s' and call "
5928 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5929 "the default handler from running. Look at the source code "
5930 "for the default handler in gtktreeview.c to get an idea what "
5931 "your handler should do. (gtktreeview.c is in the GTK source "
5932 "code.) If you're using GTK from a language other than C, "
5933 "there may be a more natural way to override default handlers, e.g. via derivation.",
5934 signal, g_type_name (required_iface), signal);
5942 scroll_row_timeout (gpointer data)
5944 PsppSheetView *tree_view = data;
5946 pspp_sheet_view_horizontal_autoscroll (tree_view);
5947 pspp_sheet_view_vertical_autoscroll (tree_view);
5949 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5950 pspp_sheet_view_update_rubber_band (tree_view);
5955 /* Returns TRUE if event should not be propagated to parent widgets */
5957 set_destination_row (PsppSheetView *tree_view,
5958 GdkDragContext *context,
5959 /* coordinates relative to the widget */
5962 GdkDragAction *suggested_action,
5965 GtkTreePath *path = NULL;
5966 PsppSheetViewDropPosition pos;
5967 PsppSheetViewDropPosition old_pos;
5968 TreeViewDragInfo *di;
5970 GtkTreePath *old_dest_path = NULL;
5971 gboolean can_drop = FALSE;
5973 *suggested_action = 0;
5976 widget = GTK_WIDGET (tree_view);
5978 di = get_info (tree_view);
5980 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5982 /* someone unset us as a drag dest, note that if
5983 * we return FALSE drag_leave isn't called
5986 pspp_sheet_view_set_drag_dest_row (tree_view,
5988 PSPP_SHEET_VIEW_DROP_BEFORE);
5990 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5992 return FALSE; /* no longer a drop site */
5995 *target = gtk_drag_dest_find_target (widget, context,
5996 gtk_drag_dest_get_target_list (widget));
5997 if (*target == GDK_NONE)
6002 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
6008 GtkTreeModel *model;
6010 /* the row got dropped on empty space, let's setup a special case
6014 gtk_tree_path_free (path);
6016 model = pspp_sheet_view_get_model (tree_view);
6018 n_children = gtk_tree_model_iter_n_children (model, NULL);
6021 pos = PSPP_SHEET_VIEW_DROP_AFTER;
6022 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6026 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
6027 path = gtk_tree_path_new_from_indices (0, -1);
6037 /* If we left the current row's "open" zone, unset the timeout for
6040 pspp_sheet_view_get_drag_dest_row (tree_view,
6045 gtk_tree_path_free (old_dest_path);
6047 if (TRUE /* FIXME if the location droppable predicate */)
6055 GtkWidget *source_widget;
6057 *suggested_action = gdk_drag_context_get_suggested_action (context);
6058 source_widget = gtk_drag_get_source_widget (context);
6060 if (source_widget == widget)
6062 /* Default to MOVE, unless the user has
6063 * pressed ctrl or shift to affect available actions
6065 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6066 *suggested_action = GDK_ACTION_MOVE;
6069 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6074 /* can't drop here */
6075 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6077 PSPP_SHEET_VIEW_DROP_BEFORE);
6081 gtk_tree_path_free (path);
6087 get_logical_dest_row (PsppSheetView *tree_view,
6088 gboolean *path_down_mode,
6089 gboolean *drop_append_mode)
6091 /* adjust path to point to the row the drop goes in front of */
6092 GtkTreePath *path = NULL;
6093 PsppSheetViewDropPosition pos;
6095 g_return_val_if_fail (path_down_mode != NULL, NULL);
6096 g_return_val_if_fail (drop_append_mode != NULL, NULL);
6098 *path_down_mode = FALSE;
6099 *drop_append_mode = 0;
6101 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6106 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
6108 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
6109 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
6110 *path_down_mode = TRUE;
6114 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
6116 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
6118 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6119 !gtk_tree_model_iter_next (model, &iter))
6120 *drop_append_mode = 1;
6123 *drop_append_mode = 0;
6124 gtk_tree_path_next (path);
6132 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
6133 GdkEventMotion *event)
6135 GtkWidget *widget = GTK_WIDGET (tree_view);
6136 GdkDragContext *context;
6137 TreeViewDragInfo *di;
6138 GtkTreePath *path = NULL;
6140 gint cell_x, cell_y;
6141 GtkTreeModel *model;
6142 gboolean retval = FALSE;
6144 di = get_info (tree_view);
6146 if (di == NULL || !di->source_set)
6149 if (tree_view->priv->pressed_button < 0)
6152 if (!gtk_drag_check_threshold (widget,
6153 tree_view->priv->press_start_x,
6154 tree_view->priv->press_start_y,
6155 event->x, event->y))
6158 model = pspp_sheet_view_get_model (tree_view);
6163 button = tree_view->priv->pressed_button;
6164 tree_view->priv->pressed_button = -1;
6166 pspp_sheet_view_get_path_at_pos (tree_view,
6167 tree_view->priv->press_start_x,
6168 tree_view->priv->press_start_y,
6177 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6178 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6182 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6185 /* Now we can begin the drag */
6189 context = gtk_drag_begin (widget,
6190 gtk_drag_source_get_target_list (widget),
6195 set_source_row (context, model, path);
6199 gtk_tree_path_free (path);
6207 pspp_sheet_view_drag_begin (GtkWidget *widget,
6208 GdkDragContext *context)
6211 PsppSheetView *tree_view;
6212 GtkTreePath *path = NULL;
6213 gint cell_x, cell_y;
6215 TreeViewDragInfo *di;
6217 tree_view = PSPP_SHEET_VIEW (widget);
6219 /* if the user uses a custom DND source impl, we don't set the icon here */
6220 di = get_info (tree_view);
6222 if (di == NULL || !di->source_set)
6225 pspp_sheet_view_get_path_at_pos (tree_view,
6226 tree_view->priv->press_start_x,
6227 tree_view->priv->press_start_y,
6233 g_return_if_fail (path != NULL);
6235 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6238 gtk_drag_set_icon_pixmap (context,
6239 gdk_drawable_get_colormap (row_pix),
6242 /* the + 1 is for the black border in the icon */
6243 tree_view->priv->press_start_x + 1,
6246 g_object_unref (row_pix);
6247 gtk_tree_path_free (path);
6253 pspp_sheet_view_drag_end (GtkWidget *widget,
6254 GdkDragContext *context)
6259 /* Default signal implementations for the drag signals */
6261 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6262 GdkDragContext *context,
6263 GtkSelectionData *selection_data,
6267 PsppSheetView *tree_view;
6268 GtkTreeModel *model;
6269 TreeViewDragInfo *di;
6270 GtkTreePath *source_row;
6272 tree_view = PSPP_SHEET_VIEW (widget);
6274 model = pspp_sheet_view_get_model (tree_view);
6279 di = get_info (PSPP_SHEET_VIEW (widget));
6284 source_row = get_source_row (context);
6286 if (source_row == NULL)
6289 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6290 * any model; for DragSource models there are some other targets
6294 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6295 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6300 /* If drag_data_get does nothing, try providing row data. */
6301 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6303 gtk_tree_set_row_drag_data (selection_data,
6309 gtk_tree_path_free (source_row);
6314 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6315 GdkDragContext *context)
6317 TreeViewDragInfo *di;
6318 GtkTreeModel *model;
6319 PsppSheetView *tree_view;
6320 GtkTreePath *source_row;
6322 tree_view = PSPP_SHEET_VIEW (widget);
6323 model = pspp_sheet_view_get_model (tree_view);
6325 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6328 di = get_info (tree_view);
6333 source_row = get_source_row (context);
6335 if (source_row == NULL)
6338 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6341 gtk_tree_path_free (source_row);
6343 set_source_row (context, NULL, NULL);
6347 pspp_sheet_view_drag_leave (GtkWidget *widget,
6348 GdkDragContext *context,
6351 /* unset any highlight row */
6352 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6354 PSPP_SHEET_VIEW_DROP_BEFORE);
6356 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6361 pspp_sheet_view_drag_motion (GtkWidget *widget,
6362 GdkDragContext *context,
6363 /* coordinates relative to the widget */
6369 GtkTreePath *path = NULL;
6370 PsppSheetViewDropPosition pos;
6371 PsppSheetView *tree_view;
6372 GdkDragAction suggested_action = 0;
6375 tree_view = PSPP_SHEET_VIEW (widget);
6377 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6380 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6382 /* we only know this *after* set_desination_row */
6383 empty = tree_view->priv->empty_view_drop;
6385 if (path == NULL && !empty)
6387 /* Can't drop here. */
6388 gdk_drag_status (context, 0, time);
6392 if (tree_view->priv->open_dest_timeout == 0 &&
6393 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6394 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6400 add_scroll_timeout (tree_view);
6403 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6405 /* Request data so we can use the source row when
6406 * determining whether to accept the drop
6408 set_status_pending (context, suggested_action);
6409 gtk_drag_get_data (widget, context, target, time);
6413 set_status_pending (context, 0);
6414 gdk_drag_status (context, suggested_action, time);
6419 gtk_tree_path_free (path);
6426 pspp_sheet_view_drag_drop (GtkWidget *widget,
6427 GdkDragContext *context,
6428 /* coordinates relative to the widget */
6433 PsppSheetView *tree_view;
6435 GdkDragAction suggested_action = 0;
6436 GdkAtom target = GDK_NONE;
6437 TreeViewDragInfo *di;
6438 GtkTreeModel *model;
6439 gboolean path_down_mode;
6440 gboolean drop_append_mode;
6442 tree_view = PSPP_SHEET_VIEW (widget);
6444 model = pspp_sheet_view_get_model (tree_view);
6446 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6448 di = get_info (tree_view);
6453 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6456 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6459 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6461 if (target != GDK_NONE && path != NULL)
6463 /* in case a motion had requested drag data, change things so we
6464 * treat drag data receives as a drop.
6466 set_status_pending (context, 0);
6467 set_dest_row (context, model, path,
6468 path_down_mode, tree_view->priv->empty_view_drop,
6473 gtk_tree_path_free (path);
6475 /* Unset this thing */
6476 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6478 PSPP_SHEET_VIEW_DROP_BEFORE);
6480 if (target != GDK_NONE)
6482 gtk_drag_get_data (widget, context, target, time);
6490 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6491 GdkDragContext *context,
6492 /* coordinates relative to the widget */
6495 GtkSelectionData *selection_data,
6500 TreeViewDragInfo *di;
6501 gboolean accepted = FALSE;
6502 GtkTreeModel *model;
6503 PsppSheetView *tree_view;
6504 GtkTreePath *dest_row;
6505 GdkDragAction suggested_action;
6506 gboolean path_down_mode;
6507 gboolean drop_append_mode;
6509 tree_view = PSPP_SHEET_VIEW (widget);
6511 model = pspp_sheet_view_get_model (tree_view);
6513 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6516 di = get_info (tree_view);
6521 suggested_action = get_status_pending (context);
6523 if (suggested_action)
6525 /* We are getting this data due to a request in drag_motion,
6526 * rather than due to a request in drag_drop, so we are just
6527 * supposed to call drag_status, not actually paste in the
6530 path = get_logical_dest_row (tree_view, &path_down_mode,
6534 suggested_action = 0;
6535 else if (path_down_mode)
6536 gtk_tree_path_down (path);
6538 if (suggested_action)
6540 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6546 path_down_mode = FALSE;
6547 gtk_tree_path_up (path);
6549 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6552 suggested_action = 0;
6555 suggested_action = 0;
6559 gdk_drag_status (context, suggested_action, time);
6562 gtk_tree_path_free (path);
6564 /* If you can't drop, remove user drop indicator until the next motion */
6565 if (suggested_action == 0)
6566 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6568 PSPP_SHEET_VIEW_DROP_BEFORE);
6573 dest_row = get_dest_row (context, &path_down_mode);
6575 if (dest_row == NULL)
6578 if (gtk_selection_data_get_length (selection_data) >= 0)
6582 gtk_tree_path_down (dest_row);
6583 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6584 dest_row, selection_data))
6585 gtk_tree_path_up (dest_row);
6589 if (gtk_selection_data_get_length (selection_data) >= 0)
6591 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6597 gtk_drag_finish (context,
6599 (gdk_drag_context_get_actions (context) == GDK_ACTION_MOVE),
6602 if (gtk_tree_path_get_depth (dest_row) == 1
6603 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6605 /* special special case drag to "0", scroll to first item */
6606 if (!tree_view->priv->scroll_to_path)
6607 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6610 gtk_tree_path_free (dest_row);
6613 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6618 /* GtkContainer Methods
6623 pspp_sheet_view_remove (GtkContainer *container,
6626 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6627 PsppSheetViewChild *child = NULL;
6630 tmp_list = tree_view->priv->children;
6633 child = tmp_list->data;
6634 if (child->widget == widget)
6636 gtk_widget_unparent (widget);
6638 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6639 g_list_free_1 (tmp_list);
6640 g_slice_free (PsppSheetViewChild, child);
6644 tmp_list = tmp_list->next;
6647 tmp_list = tree_view->priv->columns;
6651 PsppSheetViewColumn *column;
6652 column = tmp_list->data;
6653 if (column->button == widget)
6655 gtk_widget_unparent (widget);
6658 tmp_list = tmp_list->next;
6663 pspp_sheet_view_forall (GtkContainer *container,
6664 gboolean include_internals,
6665 GtkCallback callback,
6666 gpointer callback_data)
6668 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6669 PsppSheetViewChild *child = NULL;
6670 PsppSheetViewColumn *column;
6673 tmp_list = tree_view->priv->children;
6676 child = tmp_list->data;
6677 tmp_list = tmp_list->next;
6679 (* callback) (child->widget, callback_data);
6681 if (include_internals == FALSE)
6684 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6686 column = tmp_list->data;
6689 (* callback) (column->button, callback_data);
6693 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6694 * cells. If so we draw one big row-spanning focus rectangle.
6697 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6701 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6702 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6704 for (list = tree_view->priv->columns; list; list = list->next)
6706 if (!((PsppSheetViewColumn *)list->data)->visible)
6708 if (_pspp_sheet_view_column_count_special_cells (list->data))
6716 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6717 PsppSheetViewColumn *focus_column,
6718 gboolean clamp_column_visible)
6720 g_return_if_fail (focus_column != NULL);
6722 tree_view->priv->focus_column = focus_column;
6723 if (!focus_column->button)
6725 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6726 // g_return_if_fail (focus_column->button != NULL);
6727 if (focus_column->button == NULL)
6731 if (gtk_container_get_focus_child (GTK_CONTAINER (tree_view)) != focus_column->button)
6732 gtk_widget_grab_focus (focus_column->button);
6734 if (clamp_column_visible)
6735 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6738 /* Returns TRUE if the focus is within the headers, after the focus operation is
6742 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6743 GtkDirectionType dir,
6744 gboolean clamp_column_visible)
6746 GtkWidget *focus_child;
6747 PsppSheetViewColumn *focus_column;
6748 GList *last_column, *first_column;
6752 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6755 focus_child = gtk_container_get_focus_child (GTK_CONTAINER (tree_view));
6757 first_column = tree_view->priv->columns;
6758 while (first_column)
6760 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6762 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6764 first_column = first_column->next;
6767 /* No headers are visible, or are focusable. We can't focus in or out.
6769 if (first_column == NULL)
6772 last_column = g_list_last (tree_view->priv->columns);
6775 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6777 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6779 last_column = last_column->prev;
6783 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6787 case GTK_DIR_TAB_BACKWARD:
6788 case GTK_DIR_TAB_FORWARD:
6791 if (focus_child == NULL)
6793 if (tree_view->priv->focus_column != NULL &&
6794 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6795 focus_column = tree_view->priv->focus_column;
6797 focus_column = first_column->data;
6798 pspp_sheet_view_focus_column (tree_view, focus_column,
6799 clamp_column_visible);
6806 if (focus_child == NULL)
6808 if (tree_view->priv->focus_column != NULL)
6809 focus_column = tree_view->priv->focus_column;
6810 else if (dir == GTK_DIR_LEFT)
6811 focus_column = last_column->data;
6813 focus_column = first_column->data;
6814 pspp_sheet_view_focus_column (tree_view, focus_column,
6815 clamp_column_visible);
6819 if (gtk_widget_child_focus (focus_child, dir))
6821 /* The focus moves inside the button. */
6822 /* This is probably a great example of bad UI */
6823 if (clamp_column_visible)
6824 pspp_sheet_view_clamp_column_visible (tree_view,
6825 tree_view->priv->focus_column,
6830 /* We need to move the focus among the row of buttons. */
6831 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6832 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6835 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6836 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6838 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6844 PsppSheetViewColumn *column;
6846 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6847 tmp_list = tmp_list->next;
6849 tmp_list = tmp_list->prev;
6851 if (tmp_list == NULL)
6853 g_warning ("Internal button not found");
6856 column = tmp_list->data;
6857 if (column->visible &&
6858 pspp_sheet_view_column_can_focus (column))
6860 pspp_sheet_view_column_set_need_button (column, TRUE);
6863 pspp_sheet_view_focus_column (tree_view, column,
6864 clamp_column_visible);
6872 g_assert_not_reached ();
6879 /* This function returns in 'path' the first focusable path, if the given path
6880 * is already focusable, it's the returned one.
6884 search_first_focusable_path (PsppSheetView *tree_view,
6886 gboolean search_forward,
6889 /* XXX this function is trivial given that the sheetview doesn't support
6893 if (!path || !*path)
6896 _pspp_sheet_view_find_node (tree_view, *path, &node);
6904 return (*path != NULL);
6908 pspp_sheet_view_focus (GtkWidget *widget,
6909 GtkDirectionType direction)
6911 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6912 GtkContainer *container = GTK_CONTAINER (widget);
6913 GtkWidget *focus_child;
6915 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6918 focus_child = gtk_container_get_focus_child (container);
6920 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6921 /* Case 1. Headers currently have focus. */
6928 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6930 case GTK_DIR_TAB_BACKWARD:
6933 case GTK_DIR_TAB_FORWARD:
6935 gtk_widget_grab_focus (widget);
6938 g_assert_not_reached ();
6943 /* Case 2. We don't have focus at all. */
6944 if (!gtk_widget_has_focus (widget))
6946 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6947 gtk_widget_grab_focus (widget);
6951 /* Case 3. We have focus already. */
6952 if (direction == GTK_DIR_TAB_BACKWARD)
6953 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6954 else if (direction == GTK_DIR_TAB_FORWARD)
6957 /* Other directions caught by the keybindings */
6958 gtk_widget_grab_focus (widget);
6963 pspp_sheet_view_grab_focus (GtkWidget *widget)
6965 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6967 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6971 pspp_sheet_view_style_set (GtkWidget *widget,
6972 GtkStyle *previous_style)
6974 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6976 PsppSheetViewColumn *column;
6978 if (gtk_widget_get_realized (widget))
6980 gdk_window_set_background (tree_view->priv->bin_window, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
6981 gtk_style_set_background (gtk_widget_get_style (widget), tree_view->priv->header_window, GTK_STATE_NORMAL);
6982 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6985 gtk_widget_style_get (widget,
6986 "expander-size", &tree_view->priv->expander_size,
6988 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6990 for (list = tree_view->priv->columns; list; list = list->next)
6992 column = list->data;
6993 _pspp_sheet_view_column_cell_set_dirty (column);
6996 tree_view->priv->fixed_height = -1;
6998 /* Invalidate cached button style. */
6999 if (tree_view->priv->button_style)
7001 g_object_unref (tree_view->priv->button_style);
7002 tree_view->priv->button_style = NULL;
7005 gtk_widget_queue_resize (widget);
7010 pspp_sheet_view_set_focus_child (GtkContainer *container,
7013 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
7016 for (list = tree_view->priv->columns; list; list = list->next)
7018 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
7020 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7025 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
7029 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
7030 GtkAdjustment *hadj,
7031 GtkAdjustment *vadj)
7033 gboolean need_adjust = FALSE;
7035 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7038 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
7040 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
7042 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
7044 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
7046 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
7048 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
7049 pspp_sheet_view_adjustment_changed,
7051 g_object_unref (tree_view->priv->hadjustment);
7054 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
7056 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
7057 pspp_sheet_view_adjustment_changed,
7059 g_object_unref (tree_view->priv->vadjustment);
7062 if (tree_view->priv->hadjustment != hadj)
7064 tree_view->priv->hadjustment = hadj;
7065 g_object_ref_sink (tree_view->priv->hadjustment);
7067 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
7068 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7073 if (tree_view->priv->vadjustment != vadj)
7075 tree_view->priv->vadjustment = vadj;
7076 g_object_ref_sink (tree_view->priv->vadjustment);
7078 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
7079 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7085 pspp_sheet_view_adjustment_changed (NULL, tree_view);
7090 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
7091 GtkMovementStep step,
7094 PsppSheetSelectMode mode;
7095 GdkModifierType state;
7097 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
7098 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
7099 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
7100 step == GTK_MOVEMENT_DISPLAY_LINES ||
7101 step == GTK_MOVEMENT_PAGES ||
7102 step == GTK_MOVEMENT_BUFFER_ENDS ||
7103 step == GTK_MOVEMENT_DISPLAY_LINE_ENDS, FALSE);
7105 if (tree_view->priv->row_count == 0)
7107 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7110 pspp_sheet_view_stop_editing (tree_view, FALSE);
7111 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7112 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7115 if (gtk_get_current_event_state (&state))
7117 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7118 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
7119 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
7120 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
7122 /* else we assume not pressed */
7126 case GTK_MOVEMENT_LOGICAL_POSITIONS:
7127 pspp_sheet_view_move_cursor_tab (tree_view, count);
7129 case GTK_MOVEMENT_VISUAL_POSITIONS:
7130 pspp_sheet_view_move_cursor_left_right (tree_view, count, mode);
7132 case GTK_MOVEMENT_DISPLAY_LINES:
7133 pspp_sheet_view_move_cursor_up_down (tree_view, count, mode);
7135 case GTK_MOVEMENT_PAGES:
7136 pspp_sheet_view_move_cursor_page_up_down (tree_view, count, mode);
7138 case GTK_MOVEMENT_BUFFER_ENDS:
7139 pspp_sheet_view_move_cursor_start_end (tree_view, count, mode);
7141 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
7142 pspp_sheet_view_move_cursor_line_start_end (tree_view, count, mode);
7145 g_assert_not_reached ();
7152 pspp_sheet_view_put (PsppSheetView *tree_view,
7153 GtkWidget *child_widget,
7154 /* in bin_window coordinates */
7160 PsppSheetViewChild *child;
7162 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7163 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7165 child = g_slice_new (PsppSheetViewChild);
7167 child->widget = child_widget;
7170 child->width = width;
7171 child->height = height;
7173 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7175 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7176 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7178 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7182 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7184 /* in tree coordinates */
7190 PsppSheetViewChild *child = NULL;
7192 GdkRectangle allocation;
7194 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7195 g_return_if_fail (GTK_IS_WIDGET (widget));
7197 for (list = tree_view->priv->children; list; list = list->next)
7199 if (((PsppSheetViewChild *)list->data)->widget == widget)
7208 allocation.x = child->x = x;
7209 allocation.y = child->y = y;
7210 allocation.width = child->width = width;
7211 allocation.height = child->height = height;
7213 if (gtk_widget_get_realized (widget))
7214 gtk_widget_size_allocate (widget, &allocation);
7218 /* TreeModel Callbacks
7222 pspp_sheet_view_row_changed (GtkTreeModel *model,
7227 PsppSheetView *tree_view = (PsppSheetView *)data;
7229 gboolean free_path = FALSE;
7230 GtkTreePath *cursor_path;
7232 g_return_if_fail (path != NULL || iter != NULL);
7234 if (tree_view->priv->cursor != NULL)
7235 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7239 if (tree_view->priv->edited_column &&
7240 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7241 pspp_sheet_view_stop_editing (tree_view, TRUE);
7243 if (cursor_path != NULL)
7244 gtk_tree_path_free (cursor_path);
7248 path = gtk_tree_model_get_path (model, iter);
7251 else if (iter == NULL)
7252 gtk_tree_model_get_iter (model, iter, path);
7254 _pspp_sheet_view_find_node (tree_view,
7260 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7261 pspp_sheet_view_node_queue_redraw (tree_view, node);
7265 gtk_tree_path_free (path);
7269 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7274 PsppSheetView *tree_view = (PsppSheetView *) data;
7277 gint height = tree_view->priv->fixed_height;
7278 gboolean free_path = FALSE;
7279 gboolean node_visible = TRUE;
7281 g_return_if_fail (path != NULL || iter != NULL);
7285 path = gtk_tree_model_get_path (model, iter);
7288 else if (iter == NULL)
7289 gtk_tree_model_get_iter (model, iter, path);
7291 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7293 /* Update all row-references */
7294 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7295 indices = gtk_tree_path_get_indices (path);
7296 tmpnode = indices[0];
7298 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7302 if (node_visible && node_is_visible (tree_view, tmpnode))
7303 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7305 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7308 install_presize_handler (tree_view);
7310 gtk_tree_path_free (path);
7314 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7318 PsppSheetView *tree_view = (PsppSheetView *)data;
7321 g_return_if_fail (path != NULL);
7323 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7325 _pspp_sheet_view_find_node (tree_view, path, &node);
7330 range_tower_delete (tree_view->priv->selected, node, 1);
7332 /* Ensure we don't have a dangling pointer to a dead node */
7333 ensure_unprelighted (tree_view);
7335 /* Cancel editting if we've started */
7336 pspp_sheet_view_stop_editing (tree_view, TRUE);
7338 if (tree_view->priv->destroy_count_func)
7340 gint child_count = 0;
7341 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7344 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7346 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7348 gtk_tree_row_reference_free (tree_view->priv->top_row);
7349 tree_view->priv->top_row = NULL;
7352 install_scroll_sync_handler (tree_view);
7354 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7357 if (helper_data.changed)
7358 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7363 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7364 GtkTreePath *parent,
7369 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7372 /* XXX need to adjust selection */
7373 len = gtk_tree_model_iter_n_children (model, iter);
7378 gtk_tree_row_reference_reordered (G_OBJECT (data),
7383 if (gtk_tree_path_get_depth (parent) != 0)
7386 if (tree_view->priv->edited_column)
7387 pspp_sheet_view_stop_editing (tree_view, TRUE);
7389 /* we need to be unprelighted */
7390 ensure_unprelighted (tree_view);
7392 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7394 pspp_sheet_view_dy_to_top_row (tree_view);
7398 /* Internal tree functions
7403 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7404 PsppSheetViewColumn *column,
7408 PsppSheetViewColumn *tmp_column = NULL;
7419 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7422 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7424 list = (rtl ? list->prev : list->next))
7426 tmp_column = list->data;
7428 if (tmp_column == column)
7431 if (tmp_column->visible)
7432 total_width += tmp_column->width;
7435 if (tmp_column != column)
7437 g_warning (G_STRLOC": passed-in column isn't in the tree");
7446 if (column->visible)
7447 *x2 = total_width + column->width;
7449 *x2 = total_width; /* width of 0 */
7453 /* Make sure the node is visible vertically */
7455 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7458 gint node_dy, height;
7459 GtkTreePath *path = NULL;
7461 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7464 /* just return if the node is visible, avoiding a costly expose */
7465 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7466 height = ROW_HEIGHT (tree_view);
7467 if (node_dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment)
7468 && node_dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
7469 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
7472 path = _pspp_sheet_view_find_path (tree_view, node);
7475 /* We process updates because we want to clear old selected items when we scroll.
7476 * if this is removed, we get a "selection streak" at the bottom. */
7477 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7478 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7479 gtk_tree_path_free (path);
7484 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7485 PsppSheetViewColumn *column,
7486 gboolean focus_to_cell)
7493 x = column->allocation.x;
7494 width = column->allocation.width;
7496 if (width > gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7498 /* The column is larger than the horizontal page size. If the
7499 * column has cells which can be focussed individually, then we make
7500 * sure the cell which gets focus is fully visible (if even the
7501 * focus cell is bigger than the page size, we make sure the
7502 * left-hand side of the cell is visible).
7504 * If the column does not have those so-called special cells, we
7505 * make sure the left-hand side of the column is visible.
7508 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7510 GtkTreePath *cursor_path;
7511 GdkRectangle background_area, cell_area, focus_area;
7513 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7515 pspp_sheet_view_get_cell_area (tree_view,
7516 cursor_path, column, &cell_area);
7517 pspp_sheet_view_get_background_area (tree_view,
7518 cursor_path, column,
7521 gtk_tree_path_free (cursor_path);
7523 _pspp_sheet_view_column_get_focus_area (column,
7529 width = focus_area.width;
7531 if (width < gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7533 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7534 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7535 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7536 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7537 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7541 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7543 gtk_adjustment_get_lower (tree_view->priv->hadjustment),
7544 gtk_adjustment_get_upper (tree_view->priv->hadjustment)
7545 - gtk_adjustment_get_page_size (tree_view->priv->hadjustment)));
7549 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7550 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7551 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7552 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7553 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7558 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7563 path = gtk_tree_path_new ();
7565 gtk_tree_path_append_index (path, node);
7570 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7574 gint *indices = gtk_tree_path_get_indices (path);
7575 gint depth = gtk_tree_path_get_depth (path);
7578 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7584 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7587 gboolean add_shifted_binding,
7588 GtkMovementStep step,
7592 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7597 if (add_shifted_binding)
7598 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7603 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7606 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7611 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7618 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7619 PsppSheetViewColumn *column)
7621 PsppSheetViewColumn *left_column;
7622 PsppSheetViewColumn *cur_column = NULL;
7623 PsppSheetViewColumnReorder *reorder;
7628 /* We want to precalculate the motion list such that we know what column slots
7632 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7634 /* First, identify all possible drop spots */
7636 tmp_list = g_list_last (tree_view->priv->columns);
7638 tmp_list = g_list_first (tree_view->priv->columns);
7642 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7643 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7645 if (cur_column->visible == FALSE)
7648 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7649 if (left_column != column && cur_column != column &&
7650 tree_view->priv->column_drop_func &&
7651 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7653 left_column = cur_column;
7656 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7657 reorder->left_column = left_column;
7658 left_column = reorder->right_column = cur_column;
7660 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7663 /* Add the last one */
7664 if (tree_view->priv->column_drop_func == NULL ||
7665 ((left_column != column) &&
7666 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7668 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7669 reorder->left_column = left_column;
7670 reorder->right_column = NULL;
7671 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7674 /* We quickly check to see if it even makes sense to reorder columns. */
7675 /* If there is nothing that can be moved, then we return */
7677 if (tree_view->priv->column_drag_info == NULL)
7680 /* We know there are always 2 slots possbile, as you can always return column. */
7681 /* If that's all there is, return */
7682 if (tree_view->priv->column_drag_info->next == NULL ||
7683 (tree_view->priv->column_drag_info->next->next == NULL &&
7684 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7685 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7687 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7688 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7689 g_list_free (tree_view->priv->column_drag_info);
7690 tree_view->priv->column_drag_info = NULL;
7693 /* We fill in the ranges for the columns, now that we've isolated them */
7694 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7696 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7698 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7700 reorder->left_align = left;
7701 if (tmp_list->next != NULL)
7703 g_assert (tmp_list->next->data);
7704 left = reorder->right_align = (reorder->right_column->allocation.x +
7705 reorder->right_column->allocation.width +
7706 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7710 gint width = gdk_window_get_width (tree_view->priv->header_window);
7711 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7717 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7718 PsppSheetViewColumn *column)
7720 GdkEvent *send_event;
7721 GtkAllocation allocation;
7723 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7724 GdkDisplay *display = gdk_screen_get_display (screen);
7726 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7727 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7728 g_return_if_fail (column->button);
7730 pspp_sheet_view_set_column_drag_info (tree_view, column);
7732 if (tree_view->priv->column_drag_info == NULL)
7735 if (tree_view->priv->drag_window == NULL)
7737 GdkWindowAttr attributes;
7738 guint attributes_mask;
7740 attributes.window_type = GDK_WINDOW_CHILD;
7741 attributes.wclass = GDK_INPUT_OUTPUT;
7742 attributes.x = column->allocation.x;
7744 attributes.width = column->allocation.width;
7745 attributes.height = column->allocation.height;
7746 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7747 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7748 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL ;
7750 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7753 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7756 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7757 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7759 gtk_grab_remove (column->button);
7761 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7762 send_event->crossing.send_event = TRUE;
7763 send_event->crossing.window = g_object_ref (gtk_button_get_event_window (GTK_BUTTON (column->button)));
7764 send_event->crossing.subwindow = NULL;
7765 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7766 send_event->crossing.time = GDK_CURRENT_TIME;
7768 gtk_propagate_event (column->button, send_event);
7769 gdk_event_free (send_event);
7771 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7772 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7773 send_event->button.send_event = TRUE;
7774 send_event->button.time = GDK_CURRENT_TIME;
7775 send_event->button.x = -1;
7776 send_event->button.y = -1;
7777 send_event->button.axes = NULL;
7778 send_event->button.state = 0;
7779 send_event->button.button = 1;
7780 send_event->button.device =
7781 gdk_device_manager_get_client_pointer (gdk_display_get_device_manager (display));
7783 send_event->button.x_root = 0;
7784 send_event->button.y_root = 0;
7786 gtk_propagate_event (column->button, send_event);
7787 gdk_event_free (send_event);
7789 /* Kids, don't try this at home */
7790 g_object_ref (column->button);
7791 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7792 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7793 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7794 g_object_unref (column->button);
7796 tree_view->priv->drag_column_x = column->allocation.x;
7797 allocation = column->allocation;
7799 gtk_widget_size_allocate (column->button, &allocation);
7800 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7802 tree_view->priv->drag_column = column;
7803 gdk_window_show (tree_view->priv->drag_window);
7805 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7807 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7808 while (gtk_events_pending ())
7809 gtk_main_iteration ();
7811 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7812 gdk_pointer_grab (tree_view->priv->drag_window,
7814 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7815 NULL, NULL, GDK_CURRENT_TIME);
7816 gdk_keyboard_grab (tree_view->priv->drag_window,
7822 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7824 const GdkRectangle *clip_rect)
7827 GtkAllocation allocation;
7829 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7832 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
7834 rect.width = MAX (tree_view->priv->width, allocation.width);
7836 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7837 rect.height = ROW_HEIGHT (tree_view);
7841 GdkRectangle new_rect;
7843 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7845 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7849 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7854 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7856 const GdkRectangle *clip_rect)
7860 _pspp_sheet_view_find_node (tree_view, path, &node);
7863 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7867 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7870 GtkTreePath *cursor_path;
7872 if ((tree_view->priv->row_count == 0) ||
7873 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7877 if (tree_view->priv->cursor)
7878 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7880 if (cursor_path == NULL)
7882 /* There's no cursor. Move the cursor to the first selected row, if any
7883 * are selected, otherwise to the first row in the sheetview.
7885 GList *selected_rows;
7886 GtkTreeModel *model;
7887 PsppSheetSelection *selection;
7889 selection = pspp_sheet_view_get_selection (tree_view);
7890 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7894 /* XXX we could avoid doing O(n) work to get this result */
7895 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7896 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7897 g_list_free (selected_rows);
7901 cursor_path = gtk_tree_path_new_first ();
7902 search_first_focusable_path (tree_view, &cursor_path,
7906 gtk_tree_row_reference_free (tree_view->priv->cursor);
7907 tree_view->priv->cursor = NULL;
7911 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7912 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7913 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE, 0);
7915 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, 0);
7921 /* Now find a column for the cursor. */
7922 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7924 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7925 gtk_tree_path_free (cursor_path);
7927 if (tree_view->priv->focus_column == NULL)
7930 for (list = tree_view->priv->columns; list; list = list->next)
7932 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7934 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7935 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7936 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7946 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7948 PsppSheetSelectMode mode)
7950 gint selection_count;
7951 int cursor_node = -1;
7952 int new_cursor_node = -1;
7953 GtkTreePath *cursor_path = NULL;
7954 gboolean grab_focus = TRUE;
7956 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7960 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7961 /* FIXME: we lost the cursor; should we get the first? */
7964 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7965 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7967 if (cursor_node < 0)
7968 /* FIXME: we lost the cursor; should we get the first? */
7971 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7973 if (selection_count == 0
7974 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7975 && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
7977 /* Don't move the cursor, but just select the current node */
7978 new_cursor_node = cursor_node;
7983 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7985 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7988 gtk_tree_path_free (cursor_path);
7990 if (new_cursor_node)
7992 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7994 search_first_focusable_path (tree_view, &cursor_path,
7999 gtk_tree_path_free (cursor_path);
8003 * If the list has only one item and multi-selection is set then select
8004 * the row (if not yet selected).
8006 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
8007 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
8008 new_cursor_node < 0)
8011 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
8013 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
8015 if (new_cursor_node < 0
8016 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
8018 new_cursor_node = cursor_node;
8022 new_cursor_node = -1;
8026 if (new_cursor_node >= 0)
8028 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
8029 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE, mode);
8030 gtk_tree_path_free (cursor_path);
8034 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8036 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
8038 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
8040 GTK_DIR_UP : GTK_DIR_DOWN))
8042 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8045 gtk_widget_child_focus (toplevel,
8047 GTK_DIR_TAB_BACKWARD :
8048 GTK_DIR_TAB_FORWARD);
8055 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8060 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8062 return new_cursor_node >= 0;
8066 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
8068 PsppSheetSelectMode mode)
8070 int cursor_node = -1;
8071 GtkTreePath *old_cursor_path = NULL;
8072 GtkTreePath *cursor_path = NULL;
8073 int start_cursor_node = -1;
8076 gint vertical_separator;
8078 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8081 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8082 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8084 /* This is sorta weird. Focus in should give us a cursor */
8087 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
8088 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
8090 if (cursor_node < 0)
8092 /* FIXME: we lost the cursor. Should we try to get one? */
8093 gtk_tree_path_free (old_cursor_path);
8097 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8098 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
8099 y += tree_view->priv->cursor_offset;
8100 y += count * (int)gtk_adjustment_get_page_increment (tree_view->priv->vadjustment);
8101 y = CLAMP (y, (gint)gtk_adjustment_get_lower (tree_view->priv->vadjustment), (gint)gtk_adjustment_get_upper (tree_view->priv->vadjustment) - vertical_separator);
8103 if (y >= tree_view->priv->height)
8104 y = tree_view->priv->height - 1;
8106 tree_view->priv->cursor_offset =
8107 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
8109 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
8111 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
8112 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
8115 y -= tree_view->priv->cursor_offset;
8116 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8118 start_cursor_node = cursor_node;
8120 if (! search_first_focusable_path (tree_view, &cursor_path,
8124 /* It looks like we reached the end of the view without finding
8125 * a focusable row. We will step backwards to find the last
8128 cursor_node = start_cursor_node;
8129 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8131 search_first_focusable_path (tree_view, &cursor_path,
8140 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8142 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, mode);
8145 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
8146 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8147 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8149 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
8150 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8152 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8155 gtk_tree_path_free (old_cursor_path);
8156 gtk_tree_path_free (cursor_path);
8160 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
8162 PsppSheetSelectMode mode)
8164 int cursor_node = -1;
8165 GtkTreePath *cursor_path = NULL;
8166 PsppSheetViewColumn *column;
8169 gboolean found_column = FALSE;
8172 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8174 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8177 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8178 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8182 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8183 if (cursor_node < 0)
8185 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8187 gtk_tree_path_free (cursor_path);
8190 gtk_tree_path_free (cursor_path);
8192 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8193 if (tree_view->priv->focus_column)
8195 for (; list; list = (rtl ? list->prev : list->next))
8197 if (list->data == tree_view->priv->focus_column)
8204 gboolean left, right;
8206 column = list->data;
8207 if (column->visible == FALSE || column->row_head)
8210 pspp_sheet_view_column_cell_set_cell_data (column,
8211 tree_view->priv->model,
8216 right = list->prev ? TRUE : FALSE;
8217 left = list->next ? TRUE : FALSE;
8221 left = list->prev ? TRUE : FALSE;
8222 right = list->next ? TRUE : FALSE;
8225 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8227 tree_view->priv->focus_column = column;
8228 found_column = TRUE;
8233 list = rtl ? list->prev : list->next;
8235 list = rtl ? list->next : list->prev;
8240 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8241 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8242 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8246 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8249 pspp_sheet_view_clamp_column_visible (tree_view,
8250 tree_view->priv->focus_column, TRUE);
8254 pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
8256 PsppSheetSelectMode mode)
8258 int cursor_node = -1;
8259 GtkTreePath *cursor_path = NULL;
8260 PsppSheetViewColumn *column;
8261 PsppSheetViewColumn *found_column;
8266 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8268 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8271 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8272 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8276 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8277 if (cursor_node < 0)
8279 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8281 gtk_tree_path_free (cursor_path);
8284 gtk_tree_path_free (cursor_path);
8286 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8287 if (tree_view->priv->focus_column)
8289 for (; list; list = (rtl ? list->prev : list->next))
8291 if (list->data == tree_view->priv->focus_column)
8296 found_column = NULL;
8299 gboolean left, right;
8301 column = list->data;
8302 if (column->visible == FALSE || column->row_head)
8305 pspp_sheet_view_column_cell_set_cell_data (column,
8306 tree_view->priv->model,
8311 right = list->prev ? TRUE : FALSE;
8312 left = list->next ? TRUE : FALSE;
8316 left = list->prev ? TRUE : FALSE;
8317 right = list->next ? TRUE : FALSE;
8320 if (column->tabbable
8321 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8322 found_column = column;
8326 list = rtl ? list->prev : list->next;
8328 list = rtl ? list->next : list->prev;
8333 tree_view->priv->focus_column = found_column;
8334 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8335 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8336 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8339 pspp_sheet_view_clamp_column_visible (tree_view,
8340 tree_view->priv->focus_column, TRUE);
8344 try_move_cursor_tab (PsppSheetView *tree_view,
8345 gboolean start_at_focus_column,
8348 PsppSheetViewColumn *column;
8350 int cursor_node = -1;
8351 GtkTreePath *cursor_path = NULL;
8355 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8356 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8360 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8361 if (cursor_node < 0)
8363 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8365 gtk_tree_path_free (cursor_path);
8368 gtk_tree_path_free (cursor_path);
8370 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
8371 if (start_at_focus_column)
8374 ? g_list_last (tree_view->priv->columns)
8375 : g_list_first (tree_view->priv->columns));
8376 if (tree_view->priv->focus_column)
8378 for (; list; list = (rtl ? list->prev : list->next))
8380 if (list->data == tree_view->priv->focus_column)
8387 list = (rtl ^ (count == 1)
8388 ? g_list_first (tree_view->priv->columns)
8389 : g_list_last (tree_view->priv->columns));
8394 gboolean left, right;
8396 column = list->data;
8397 if (column->visible == FALSE || !column->tabbable)
8400 pspp_sheet_view_column_cell_set_cell_data (column,
8401 tree_view->priv->model,
8406 right = list->prev ? TRUE : FALSE;
8407 left = list->next ? TRUE : FALSE;
8411 left = list->prev ? TRUE : FALSE;
8412 right = list->next ? TRUE : FALSE;
8415 if (column->tabbable
8416 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8418 tree_view->priv->focus_column = column;
8419 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8420 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8421 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8426 list = rtl ? list->prev : list->next;
8428 list = rtl ? list->next : list->prev;
8435 pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
8438 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8441 if (!try_move_cursor_tab (tree_view, TRUE, count))
8443 if (pspp_sheet_view_move_cursor_up_down (tree_view, count, 0)
8444 && !try_move_cursor_tab (tree_view, FALSE, count))
8445 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8448 pspp_sheet_view_clamp_column_visible (tree_view,
8449 tree_view->priv->focus_column, TRUE);
8453 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8455 PsppSheetSelectMode mode)
8459 GtkTreePath *old_path;
8461 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8464 g_return_if_fail (tree_view->priv->row_count > 0);
8466 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8470 /* Now go forward to find the first focusable row. */
8471 path = _pspp_sheet_view_find_path (tree_view, 0);
8472 search_first_focusable_path (tree_view, &path,
8473 TRUE, &cursor_node);
8477 /* Now go backwards to find last focusable row. */
8478 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8479 search_first_focusable_path (tree_view, &path,
8480 FALSE, &cursor_node);
8486 if (gtk_tree_path_compare (old_path, path))
8488 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
8489 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8493 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8497 gtk_tree_path_free (old_path);
8498 gtk_tree_path_free (path);
8502 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8504 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8507 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8508 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8511 pspp_sheet_selection_select_all (tree_view->priv->selection);
8517 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8519 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8522 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8523 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8526 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8532 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8533 gboolean start_editing,
8534 PsppSheetSelectMode mode)
8537 int cursor_node = -1;
8538 GtkTreePath *cursor_path = NULL;
8540 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8543 if (tree_view->priv->cursor)
8544 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8546 if (cursor_path == NULL)
8549 _pspp_sheet_view_find_node (tree_view, cursor_path,
8552 if (cursor_node < 0)
8554 gtk_tree_path_free (cursor_path);
8558 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND) && start_editing &&
8559 tree_view->priv->focus_column)
8561 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8563 gtk_tree_path_free (cursor_path);
8568 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8574 /* We bail out if the original (tree, node) don't exist anymore after
8575 * handling the selection-changed callback. We do return TRUE because
8576 * the key press has been handled at this point.
8578 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8580 if (cursor_node != new_node)
8583 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8585 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8586 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8588 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
8589 pspp_sheet_view_row_activated (tree_view, cursor_path,
8590 tree_view->priv->focus_column);
8592 gtk_tree_path_free (cursor_path);
8598 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8601 int cursor_node = -1;
8602 GtkTreePath *cursor_path = NULL;
8604 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8608 if (tree_view->priv->cursor)
8609 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8611 if (cursor_path == NULL)
8614 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8615 if (cursor_node < 0)
8617 gtk_tree_path_free (cursor_path);
8621 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8624 PSPP_SHEET_SELECT_MODE_TOGGLE,
8627 /* We bail out if the original (tree, node) don't exist anymore after
8628 * handling the selection-changed callback. We do return TRUE because
8629 * the key press has been handled at this point.
8631 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8633 if (cursor_node != new_node)
8636 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8638 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8639 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8640 gtk_tree_path_free (cursor_path);
8646 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8648 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8649 tree_view->priv->typeselect_flush_timeout = 0;
8654 /* Cut and paste from gtkwindow.c */
8656 send_focus_change (GtkWidget *widget,
8659 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8661 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8662 fevent->focus_change.window = g_object_ref (gtk_widget_get_window (widget));
8663 fevent->focus_change.in = in;
8665 gtk_widget_send_focus_change (widget, fevent);
8666 gdk_event_free (fevent);
8670 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8672 GtkWidget *frame, *vbox, *toplevel;
8675 if (tree_view->priv->search_custom_entry_set)
8678 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8679 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8681 if (tree_view->priv->search_window != NULL)
8683 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8684 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8685 GTK_WINDOW (tree_view->priv->search_window));
8686 else if (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)))
8687 gtk_window_group_remove_window (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)),
8688 GTK_WINDOW (tree_view->priv->search_window));
8689 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8693 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8694 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8696 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8697 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8698 GTK_WINDOW (tree_view->priv->search_window));
8700 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8701 GDK_WINDOW_TYPE_HINT_UTILITY);
8702 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8703 g_signal_connect (tree_view->priv->search_window, "delete-event",
8704 G_CALLBACK (pspp_sheet_view_search_delete_event),
8706 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8707 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8709 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8710 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8712 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8713 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8716 frame = gtk_frame_new (NULL);
8717 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8718 gtk_widget_show (frame);
8719 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8721 vbox = gtk_vbox_new (FALSE, 0);
8722 gtk_widget_show (vbox);
8723 gtk_container_add (GTK_CONTAINER (frame), vbox);
8724 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8727 tree_view->priv->search_entry = gtk_entry_new ();
8728 gtk_widget_show (tree_view->priv->search_entry);
8729 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8730 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8732 g_signal_connect (tree_view->priv->search_entry,
8733 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8737 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8739 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8743 gtk_container_add (GTK_CONTAINER (vbox),
8744 tree_view->priv->search_entry);
8746 gtk_widget_realize (tree_view->priv->search_entry);
8749 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8750 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8753 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8754 gboolean keybinding)
8756 /* We only start interactive search if we have focus or the columns
8757 * have focus. If one of our children have focus, we don't want to
8761 gboolean found_focus = FALSE;
8762 GtkWidgetClass *entry_parent_class;
8764 if (!tree_view->priv->enable_search && !keybinding)
8767 if (tree_view->priv->search_custom_entry_set)
8770 if (tree_view->priv->search_window != NULL &&
8771 gtk_widget_get_visible (tree_view->priv->search_window))
8774 for (list = tree_view->priv->columns; list; list = list->next)
8776 PsppSheetViewColumn *column;
8778 column = list->data;
8779 if (! column->visible)
8782 if (column->button && gtk_widget_has_focus (column->button))
8789 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8795 if (tree_view->priv->search_column < 0)
8798 pspp_sheet_view_ensure_interactive_directory (tree_view);
8801 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8804 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8805 gtk_widget_show (tree_view->priv->search_window);
8806 if (tree_view->priv->search_entry_changed_id == 0)
8808 tree_view->priv->search_entry_changed_id =
8809 g_signal_connect (tree_view->priv->search_entry, "changed",
8810 G_CALLBACK (pspp_sheet_view_search_init),
8814 tree_view->priv->typeselect_flush_timeout =
8815 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8816 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8819 /* Grab focus will select all the text. We don't want that to happen, so we
8820 * call the parent instance and bypass the selection change. This is probably
8821 * really non-kosher. */
8822 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8823 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8825 /* send focus-in event */
8826 send_focus_change (tree_view->priv->search_entry, TRUE);
8828 /* search first matching iter */
8829 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8835 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8837 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8840 /* this function returns the new width of the column being resized given
8841 * the column and x position of the cursor; the x cursor position is passed
8842 * in as a pointer and automagicly corrected if it's beyond min/max limits
8845 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8849 PsppSheetViewColumn *column;
8853 /* first translate the x position from gtk_widget_get_window (widget)
8854 * to clist->clist_window
8856 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8857 column = g_list_nth (tree_view->priv->columns, i)->data;
8858 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8860 /* Clamp down the value */
8861 if (column->min_width == -1)
8862 width = MAX (column->button_request, width);
8864 width = MAX (column->min_width, width);
8865 if (column->max_width != -1)
8866 width = MIN (width, column->max_width);
8868 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8874 /* FIXME this adjust_allocation is a big cut-and-paste from
8875 * GtkCList, needs to be some "official" way to do this
8885 /* The window to which gtk_widget_get_window (widget) is relative */
8886 #define ALLOCATION_WINDOW(widget) \
8887 (!gtk_widget_get_has_window (widget) ? \
8888 gtk_widget_get_window (widget) : \
8889 gdk_window_get_parent (gtk_widget_get_window (widget)))
8892 adjust_allocation_recurse (GtkWidget *widget,
8895 ScrollData *scroll_data = data;
8896 GtkAllocation allocation;
8897 gtk_widget_get_allocation (widget, &allocation);
8898 /* Need to really size allocate instead of just poking
8899 * into widget->allocation if the widget is not realized.
8900 * FIXME someone figure out why this was.
8902 if (!gtk_widget_get_realized (widget))
8904 if (gtk_widget_get_visible (widget))
8906 GdkRectangle tmp_rectangle = allocation;
8907 tmp_rectangle.x += scroll_data->dx;
8908 tmp_rectangle.y += scroll_data->dy;
8910 gtk_widget_size_allocate (widget, &tmp_rectangle);
8915 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8917 allocation.x += scroll_data->dx;
8918 allocation.y += scroll_data->dy;
8920 if (GTK_IS_CONTAINER (widget))
8921 gtk_container_forall (GTK_CONTAINER (widget),
8922 adjust_allocation_recurse,
8929 adjust_allocation (GtkWidget *widget,
8933 ScrollData scroll_data;
8935 if (gtk_widget_get_realized (widget))
8936 scroll_data.window = ALLOCATION_WINDOW (widget);
8938 scroll_data.window = NULL;
8940 scroll_data.dx = dx;
8941 scroll_data.dy = dy;
8943 adjust_allocation_recurse (widget, &scroll_data);
8947 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8951 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8952 PsppSheetView *tree_view)
8954 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8959 gdk_window_move (tree_view->priv->bin_window,
8960 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8961 TREE_VIEW_HEADER_HEIGHT (tree_view));
8962 gdk_window_move (tree_view->priv->header_window,
8963 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8965 dy = tree_view->priv->dy - (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8968 update_prelight (tree_view,
8969 tree_view->priv->event_last_x,
8970 tree_view->priv->event_last_y - dy);
8972 if (tree_view->priv->edited_column &&
8973 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8977 PsppSheetViewChild *child = NULL;
8979 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8980 adjust_allocation (widget, 0, dy);
8982 for (list = tree_view->priv->children; list; list = list->next)
8984 child = (PsppSheetViewChild *)list->data;
8985 if (child->widget == widget)
8993 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8995 if (tree_view->priv->dy != (int) gtk_adjustment_get_value (tree_view->priv->vadjustment))
8997 /* update our dy and top_row */
8998 tree_view->priv->dy = (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
9000 if (!tree_view->priv->in_top_row_to_dy)
9001 pspp_sheet_view_dy_to_top_row (tree_view);
9004 for (list = tree_view->priv->columns; list; list = list->next)
9006 PsppSheetViewColumn *column = list->data;
9007 GtkAllocation *col_allocation = &column->allocation;
9008 GtkAllocation widget_allocation;
9009 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &widget_allocation);
9011 if (span_intersects (col_allocation->x, col_allocation->width,
9012 gtk_adjustment_get_value (tree_view->priv->hadjustment),
9013 widget_allocation.width))
9015 pspp_sheet_view_column_set_need_button (column, TRUE);
9016 if (!column->button)
9017 pspp_sheet_view_column_update_button (column);
9029 * pspp_sheet_view_new:
9031 * Creates a new #PsppSheetView widget.
9033 * Return value: A newly created #PsppSheetView widget.
9036 pspp_sheet_view_new (void)
9038 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
9042 * pspp_sheet_view_new_with_model:
9043 * @model: the model.
9045 * Creates a new #PsppSheetView widget with the model initialized to @model.
9047 * Return value: A newly created #PsppSheetView widget.
9050 pspp_sheet_view_new_with_model (GtkTreeModel *model)
9052 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
9059 * pspp_sheet_view_get_model:
9060 * @tree_view: a #PsppSheetView
9062 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
9065 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
9068 pspp_sheet_view_get_model (PsppSheetView *tree_view)
9070 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9072 return tree_view->priv->model;
9076 * pspp_sheet_view_set_model:
9077 * @tree_view: A #GtkTreeNode.
9078 * @model: (allow-none): The model.
9080 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
9081 * set, it will remove it before setting the new model. If @model is %NULL,
9082 * then it will unset the old model.
9085 pspp_sheet_view_set_model (PsppSheetView *tree_view,
9086 GtkTreeModel *model)
9088 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9089 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
9091 if (model == tree_view->priv->model)
9094 if (tree_view->priv->scroll_to_path)
9096 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9097 tree_view->priv->scroll_to_path = NULL;
9100 if (tree_view->priv->model)
9102 GList *tmplist = tree_view->priv->columns;
9104 if (tree_view->priv->selected)
9105 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
9106 pspp_sheet_view_stop_editing (tree_view, TRUE);
9108 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9109 pspp_sheet_view_row_changed,
9111 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9112 pspp_sheet_view_row_inserted,
9114 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9115 pspp_sheet_view_row_deleted,
9117 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9118 pspp_sheet_view_rows_reordered,
9121 for (; tmplist; tmplist = tmplist->next)
9122 _pspp_sheet_view_column_unset_model (tmplist->data,
9123 tree_view->priv->model);
9125 tree_view->priv->prelight_node = -1;
9127 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
9128 tree_view->priv->drag_dest_row = NULL;
9129 gtk_tree_row_reference_free (tree_view->priv->cursor);
9130 tree_view->priv->cursor = NULL;
9131 gtk_tree_row_reference_free (tree_view->priv->anchor);
9132 tree_view->priv->anchor = NULL;
9133 gtk_tree_row_reference_free (tree_view->priv->top_row);
9134 tree_view->priv->top_row = NULL;
9135 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9136 tree_view->priv->scroll_to_path = NULL;
9138 tree_view->priv->scroll_to_column = NULL;
9140 g_object_unref (tree_view->priv->model);
9142 tree_view->priv->search_column = -1;
9143 tree_view->priv->fixed_height = -1;
9144 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
9145 tree_view->priv->last_button_x = -1;
9146 tree_view->priv->last_button_y = -1;
9149 tree_view->priv->model = model;
9151 if (tree_view->priv->model)
9155 if (tree_view->priv->search_column == -1)
9157 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
9159 GType type = gtk_tree_model_get_column_type (model, i);
9161 if (g_value_type_transformable (type, G_TYPE_STRING))
9163 tree_view->priv->search_column = i;
9169 g_object_ref (tree_view->priv->model);
9170 g_signal_connect (tree_view->priv->model,
9172 G_CALLBACK (pspp_sheet_view_row_changed),
9174 g_signal_connect (tree_view->priv->model,
9176 G_CALLBACK (pspp_sheet_view_row_inserted),
9178 g_signal_connect (tree_view->priv->model,
9180 G_CALLBACK (pspp_sheet_view_row_deleted),
9182 g_signal_connect (tree_view->priv->model,
9184 G_CALLBACK (pspp_sheet_view_rows_reordered),
9187 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
9189 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
9190 install_presize_handler (tree_view);
9193 g_object_notify (G_OBJECT (tree_view), "model");
9195 if (tree_view->priv->selection)
9196 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
9198 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9199 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9203 * pspp_sheet_view_get_selection:
9204 * @tree_view: A #PsppSheetView.
9206 * Gets the #PsppSheetSelection associated with @tree_view.
9208 * Return value: A #PsppSheetSelection object.
9210 PsppSheetSelection *
9211 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
9213 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9215 return tree_view->priv->selection;
9219 * pspp_sheet_view_get_hadjustment:
9220 * @tree_view: A #PsppSheetView
9222 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
9224 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9228 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
9230 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9232 return pspp_sheet_view_do_get_hadjustment (tree_view);
9235 static GtkAdjustment *
9236 pspp_sheet_view_do_get_hadjustment (PsppSheetView *tree_view)
9238 return tree_view->priv->hadjustment;
9242 * pspp_sheet_view_set_hadjustment:
9243 * @tree_view: A #PsppSheetView
9244 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9246 * Sets the #GtkAdjustment for the current horizontal aspect.
9249 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
9250 GtkAdjustment *adjustment)
9252 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9254 pspp_sheet_view_set_adjustments (tree_view,
9256 tree_view->priv->vadjustment);
9258 g_object_notify (G_OBJECT (tree_view), "hadjustment");
9262 pspp_sheet_view_do_set_hadjustment (PsppSheetView *tree_view,
9263 GtkAdjustment *adjustment)
9265 PsppSheetViewPrivate *priv = tree_view->priv;
9267 if (adjustment && priv->hadjustment == adjustment)
9270 if (priv->hadjustment != NULL)
9272 g_signal_handlers_disconnect_by_func (priv->hadjustment,
9273 pspp_sheet_view_adjustment_changed,
9275 g_object_unref (priv->hadjustment);
9278 if (adjustment == NULL)
9279 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
9282 g_signal_connect (adjustment, "value-changed",
9283 G_CALLBACK (pspp_sheet_view_adjustment_changed), tree_view);
9284 priv->hadjustment = g_object_ref_sink (adjustment);
9285 /* FIXME: Adjustment should probably be populated here with fresh values, but
9286 * internal details are too complicated for me to decipher right now.
9288 pspp_sheet_view_adjustment_changed (NULL, tree_view);
9290 g_object_notify (G_OBJECT (tree_view), "hadjustment");
9294 * pspp_sheet_view_get_vadjustment:
9295 * @tree_view: A #PsppSheetView
9297 * Gets the #GtkAdjustment currently being used for the vertical aspect.
9299 * Return value: (transfer none): A #GtkAdjustment object, or %NULL
9300 * if none is currently being used.
9302 * Deprecated: 3.0: Use gtk_scrollable_get_vadjustment()
9305 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
9307 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9309 return pspp_sheet_view_do_get_vadjustment (tree_view);
9312 static GtkAdjustment *
9313 pspp_sheet_view_do_get_vadjustment (PsppSheetView *tree_view)
9315 return tree_view->priv->vadjustment;
9319 * pspp_sheet_view_set_vadjustment:
9320 * @tree_view: A #PsppSheetView
9321 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9323 * Sets the #GtkAdjustment for the current vertical aspect.
9325 * Deprecated: 3.0: Use gtk_scrollable_set_vadjustment()
9328 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
9329 GtkAdjustment *adjustment)
9331 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9332 g_return_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment));
9334 pspp_sheet_view_do_set_vadjustment (tree_view, adjustment);
9338 pspp_sheet_view_do_set_vadjustment (PsppSheetView *tree_view,
9339 GtkAdjustment *adjustment)
9341 PsppSheetViewPrivate *priv = tree_view->priv;
9343 if (adjustment && priv->vadjustment == adjustment)
9346 if (priv->vadjustment != NULL)
9348 g_signal_handlers_disconnect_by_func (priv->vadjustment,
9349 pspp_sheet_view_adjustment_changed,
9351 g_object_unref (priv->vadjustment);
9354 if (adjustment == NULL)
9355 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
9358 g_signal_connect (adjustment, "value-changed",
9359 G_CALLBACK (pspp_sheet_view_adjustment_changed), tree_view);
9360 priv->vadjustment = g_object_ref_sink (adjustment);
9361 /* FIXME: Adjustment should probably be populated here with fresh values, but
9362 * internal details are too complicated for me to decipher right now.
9364 pspp_sheet_view_adjustment_changed (NULL, tree_view);
9365 g_object_notify (G_OBJECT (tree_view), "vadjustment");
9368 /* Column and header operations */
9371 * pspp_sheet_view_get_headers_visible:
9372 * @tree_view: A #PsppSheetView.
9374 * Returns %TRUE if the headers on the @tree_view are visible.
9376 * Return value: Whether the headers are visible or not.
9379 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
9381 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9383 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9387 * pspp_sheet_view_set_headers_visible:
9388 * @tree_view: A #PsppSheetView.
9389 * @headers_visible: %TRUE if the headers are visible
9391 * Sets the visibility state of the headers.
9394 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
9395 gboolean headers_visible)
9399 PsppSheetViewColumn *column;
9400 GtkAllocation allocation;
9402 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9404 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
9406 headers_visible = !! headers_visible;
9408 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
9411 if (headers_visible)
9412 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9414 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9416 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9418 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
9419 if (headers_visible)
9421 gdk_window_move_resize (tree_view->priv->bin_window, x, y + TREE_VIEW_HEADER_HEIGHT (tree_view),
9422 tree_view->priv->width, allocation.height - + TREE_VIEW_HEADER_HEIGHT (tree_view));
9424 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9425 pspp_sheet_view_map_buttons (tree_view);
9429 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9431 for (list = tree_view->priv->columns; list; list = list->next)
9433 column = list->data;
9435 gtk_widget_unmap (column->button);
9437 gdk_window_hide (tree_view->priv->header_window);
9441 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view));
9442 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, (allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2);
9443 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
9444 gtk_adjustment_set_upper (tree_view->priv->vadjustment, tree_view->priv->height);
9445 gtk_adjustment_changed (tree_view->priv->vadjustment);
9447 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9449 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9453 * pspp_sheet_view_columns_autosize:
9454 * @tree_view: A #PsppSheetView.
9456 * Resizes all columns to their optimal width. Only works after the
9457 * treeview has been realized.
9460 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9462 gboolean dirty = FALSE;
9464 PsppSheetViewColumn *column;
9466 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9468 for (list = tree_view->priv->columns; list; list = list->next)
9470 column = list->data;
9471 _pspp_sheet_view_column_cell_set_dirty (column);
9476 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9480 * pspp_sheet_view_set_headers_clickable:
9481 * @tree_view: A #PsppSheetView.
9482 * @setting: %TRUE if the columns are clickable.
9484 * Allow the column title buttons to be clicked.
9487 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9492 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9494 for (list = tree_view->priv->columns; list; list = list->next)
9495 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9497 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9502 * pspp_sheet_view_get_headers_clickable:
9503 * @tree_view: A #PsppSheetView.
9505 * Returns whether all header columns are clickable.
9507 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9512 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9516 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9518 for (list = tree_view->priv->columns; list; list = list->next)
9519 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9526 * pspp_sheet_view_set_rules_hint
9527 * @tree_view: a #PsppSheetView
9528 * @setting: %TRUE if the tree requires reading across rows
9530 * This function tells GTK+ that the user interface for your
9531 * application requires users to read across tree rows and associate
9532 * cells with one another. By default, GTK+ will then render the tree
9533 * with alternating row colors. Do <emphasis>not</emphasis> use it
9534 * just because you prefer the appearance of the ruled tree; that's a
9535 * question for the theme. Some themes will draw tree rows in
9536 * alternating colors even when rules are turned off, and users who
9537 * prefer that appearance all the time can choose those themes. You
9538 * should call this function only as a <emphasis>semantic</emphasis>
9539 * hint to the theme engine that your tree makes alternating colors
9540 * useful from a functional standpoint (since it has lots of columns,
9545 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9548 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9550 setting = setting != FALSE;
9552 if (tree_view->priv->has_rules != setting)
9554 tree_view->priv->has_rules = setting;
9555 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9558 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9562 * pspp_sheet_view_get_rules_hint
9563 * @tree_view: a #PsppSheetView
9565 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9567 * Return value: %TRUE if rules are useful for the user of this tree
9570 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9572 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9574 return tree_view->priv->has_rules;
9577 /* Public Column functions
9581 * pspp_sheet_view_append_column:
9582 * @tree_view: A #PsppSheetView.
9583 * @column: The #PsppSheetViewColumn to add.
9585 * Appends @column to the list of columns.
9587 * Return value: The number of columns in @tree_view after appending.
9590 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9591 PsppSheetViewColumn *column)
9593 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9594 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9595 g_return_val_if_fail (column->tree_view == NULL, -1);
9597 return pspp_sheet_view_insert_column (tree_view, column, -1);
9602 * pspp_sheet_view_remove_column:
9603 * @tree_view: A #PsppSheetView.
9604 * @column: The #PsppSheetViewColumn to remove.
9606 * Removes @column from @tree_view.
9608 * Return value: The number of columns in @tree_view after removing.
9611 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9612 PsppSheetViewColumn *column)
9614 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9615 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9616 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9618 if (tree_view->priv->focus_column == column)
9619 tree_view->priv->focus_column = NULL;
9621 if (tree_view->priv->edited_column == column)
9623 pspp_sheet_view_stop_editing (tree_view, TRUE);
9625 /* no need to, but just to be sure ... */
9626 tree_view->priv->edited_column = NULL;
9629 _pspp_sheet_view_column_unset_tree_view (column);
9631 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9632 tree_view->priv->n_columns--;
9634 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9638 _pspp_sheet_view_column_unrealize_button (column);
9639 for (list = tree_view->priv->columns; list; list = list->next)
9641 PsppSheetViewColumn *tmp_column;
9643 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9644 if (tmp_column->visible)
9645 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9648 if (tree_view->priv->n_columns == 0 &&
9649 pspp_sheet_view_get_headers_visible (tree_view) &&
9650 tree_view->priv->header_window)
9651 gdk_window_hide (tree_view->priv->header_window);
9653 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9656 g_object_unref (column);
9657 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9659 return tree_view->priv->n_columns;
9663 * pspp_sheet_view_insert_column:
9664 * @tree_view: A #PsppSheetView.
9665 * @column: The #PsppSheetViewColumn to be inserted.
9666 * @position: The position to insert @column in.
9668 * This inserts the @column into the @tree_view at @position. If @position is
9669 * -1, then the column is inserted at the end.
9671 * Return value: The number of columns in @tree_view after insertion.
9674 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9675 PsppSheetViewColumn *column,
9678 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9679 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9680 g_return_val_if_fail (column->tree_view == NULL, -1);
9682 g_object_ref_sink (column);
9684 if (tree_view->priv->n_columns == 0 &&
9685 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9686 pspp_sheet_view_get_headers_visible (tree_view))
9688 gdk_window_show (tree_view->priv->header_window);
9691 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9693 tree_view->priv->n_columns++;
9695 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9697 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9701 _pspp_sheet_view_column_realize_button (column);
9703 for (list = tree_view->priv->columns; list; list = list->next)
9705 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9706 if (column->visible)
9707 _pspp_sheet_view_column_cell_set_dirty (column);
9709 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9712 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9714 return tree_view->priv->n_columns;
9718 * pspp_sheet_view_insert_column_with_attributes:
9719 * @tree_view: A #PsppSheetView
9720 * @position: The position to insert the new column in.
9721 * @title: The title to set the header to.
9722 * @cell: The #GtkCellRenderer.
9723 * @Varargs: A %NULL-terminated list of attributes.
9725 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9726 * @position. If @position is -1, then the newly created column is inserted at
9727 * the end. The column is initialized with the attributes given.
9729 * Return value: The number of columns in @tree_view after insertion.
9732 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9735 GtkCellRenderer *cell,
9738 PsppSheetViewColumn *column;
9743 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9745 column = pspp_sheet_view_column_new ();
9746 pspp_sheet_view_column_set_title (column, title);
9747 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9749 va_start (args, cell);
9751 attribute = va_arg (args, gchar *);
9753 while (attribute != NULL)
9755 column_id = va_arg (args, gint);
9756 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9757 attribute = va_arg (args, gchar *);
9762 pspp_sheet_view_insert_column (tree_view, column, position);
9764 return tree_view->priv->n_columns;
9768 * pspp_sheet_view_insert_column_with_data_func:
9769 * @tree_view: a #PsppSheetView
9770 * @position: Position to insert, -1 for append
9771 * @title: column title
9772 * @cell: cell renderer for column
9773 * @func: function to set attributes of cell renderer
9774 * @data: data for @func
9775 * @dnotify: destroy notifier for @data
9777 * Convenience function that inserts a new column into the #PsppSheetView
9778 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9779 * attributes (normally using data from the model). See also
9780 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9782 * Return value: number of columns in the tree view post-insert
9785 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9788 GtkCellRenderer *cell,
9789 PsppSheetCellDataFunc func,
9791 GDestroyNotify dnotify)
9793 PsppSheetViewColumn *column;
9795 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9797 column = pspp_sheet_view_column_new ();
9798 pspp_sheet_view_column_set_title (column, title);
9799 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9800 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9802 pspp_sheet_view_insert_column (tree_view, column, position);
9804 return tree_view->priv->n_columns;
9808 * pspp_sheet_view_get_column:
9809 * @tree_view: A #PsppSheetView.
9810 * @n: The position of the column, counting from 0.
9812 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9814 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9817 PsppSheetViewColumn *
9818 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9821 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9823 if (n < 0 || n >= tree_view->priv->n_columns)
9826 if (tree_view->priv->columns == NULL)
9829 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9833 * pspp_sheet_view_get_columns:
9834 * @tree_view: A #PsppSheetView
9836 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9837 * The returned list must be freed with g_list_free ().
9839 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9842 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9844 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9846 return g_list_copy (tree_view->priv->columns);
9850 * pspp_sheet_view_move_column_after:
9851 * @tree_view: A #PsppSheetView
9852 * @column: The #PsppSheetViewColumn to be moved.
9853 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9855 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9856 * @column is placed in the first position.
9859 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9860 PsppSheetViewColumn *column,
9861 PsppSheetViewColumn *base_column)
9863 GList *column_list_el, *base_el = NULL;
9865 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9867 column_list_el = g_list_find (tree_view->priv->columns, column);
9868 g_return_if_fail (column_list_el != NULL);
9872 base_el = g_list_find (tree_view->priv->columns, base_column);
9873 g_return_if_fail (base_el != NULL);
9876 if (column_list_el->prev == base_el)
9879 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9880 if (base_el == NULL)
9882 column_list_el->prev = NULL;
9883 column_list_el->next = tree_view->priv->columns;
9884 if (column_list_el->next)
9885 column_list_el->next->prev = column_list_el;
9886 tree_view->priv->columns = column_list_el;
9890 column_list_el->prev = base_el;
9891 column_list_el->next = base_el->next;
9892 if (column_list_el->next)
9893 column_list_el->next->prev = column_list_el;
9894 base_el->next = column_list_el;
9897 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9899 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9900 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9903 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9907 * pspp_sheet_view_set_column_drag_function:
9908 * @tree_view: A #PsppSheetView.
9909 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9910 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9911 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9913 * Sets a user function for determining where a column may be dropped when
9914 * dragged. This function is called on every column pair in turn at the
9915 * beginning of a column drag to determine where a drop can take place. The
9916 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9917 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9918 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9919 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9920 * @tree_view reverts to the default behavior of allowing all columns to be
9921 * dropped everywhere.
9924 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9925 PsppSheetViewColumnDropFunc func,
9927 GDestroyNotify destroy)
9929 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9931 if (tree_view->priv->column_drop_func_data_destroy)
9932 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9934 tree_view->priv->column_drop_func = func;
9935 tree_view->priv->column_drop_func_data = user_data;
9936 tree_view->priv->column_drop_func_data_destroy = destroy;
9940 * pspp_sheet_view_scroll_to_point:
9941 * @tree_view: a #PsppSheetView
9942 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9943 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9945 * Scrolls the tree view such that the top-left corner of the visible
9946 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9947 * in tree coordinates. The @tree_view must be realized before
9948 * this function is called. If it isn't, you probably want to be
9949 * using pspp_sheet_view_scroll_to_cell().
9951 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9954 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9958 GtkAdjustment *hadj;
9959 GtkAdjustment *vadj;
9961 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9962 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9964 hadj = tree_view->priv->hadjustment;
9965 vadj = tree_view->priv->vadjustment;
9968 gtk_adjustment_set_value (hadj, CLAMP (tree_x, gtk_adjustment_get_lower (hadj), gtk_adjustment_get_upper (hadj) - gtk_adjustment_get_page_size (hadj)));
9970 gtk_adjustment_set_value (vadj, CLAMP (tree_y, gtk_adjustment_get_lower (vadj), gtk_adjustment_get_upper (vadj) - gtk_adjustment_get_page_size (vadj)));
9974 * pspp_sheet_view_scroll_to_cell:
9975 * @tree_view: A #PsppSheetView.
9976 * @path: (allow-none): The path of the row to move to, or %NULL.
9977 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9978 * @use_align: whether to use alignment arguments, or %FALSE.
9979 * @row_align: The vertical alignment of the row specified by @path.
9980 * @col_align: The horizontal alignment of the column specified by @column.
9982 * Moves the alignments of @tree_view to the position specified by @column and
9983 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9984 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9985 * or @path need to be non-%NULL. @row_align determines where the row is
9986 * placed, and @col_align determines where @column is placed. Both are expected
9987 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9988 * right/bottom alignment, 0.5 means center.
9990 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9991 * tree does the minimum amount of work to scroll the cell onto the screen.
9992 * This means that the cell will be scrolled to the edge closest to its current
9993 * position. If the cell is currently visible on the screen, nothing is done.
9995 * This function only works if the model is set, and @path is a valid row on the
9996 * model. If the model changes before the @tree_view is realized, the centered
9997 * path will be modified to reflect this change.
10000 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
10002 PsppSheetViewColumn *column,
10003 gboolean use_align,
10007 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10008 g_return_if_fail (tree_view->priv->model != NULL);
10009 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
10010 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
10011 g_return_if_fail (path != NULL || column != NULL);
10014 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
10015 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
10017 row_align = CLAMP (row_align, 0.0, 1.0);
10018 col_align = CLAMP (col_align, 0.0, 1.0);
10021 /* Note: Despite the benefits that come from having one code path for the
10022 * scrolling code, we short-circuit validate_visible_area's immplementation as
10023 * it is much slower than just going to the point.
10025 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
10026 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
10027 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
10029 if (tree_view->priv->scroll_to_path)
10030 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
10032 tree_view->priv->scroll_to_path = NULL;
10033 tree_view->priv->scroll_to_column = NULL;
10036 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
10038 tree_view->priv->scroll_to_column = column;
10039 tree_view->priv->scroll_to_use_align = use_align;
10040 tree_view->priv->scroll_to_row_align = row_align;
10041 tree_view->priv->scroll_to_col_align = col_align;
10043 install_presize_handler (tree_view);
10047 GdkRectangle cell_rect;
10048 GdkRectangle vis_rect;
10049 gint dest_x, dest_y;
10051 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
10052 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
10054 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
10056 dest_x = vis_rect.x;
10057 dest_y = vis_rect.y;
10063 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
10067 if (cell_rect.x < vis_rect.x)
10068 dest_x = cell_rect.x;
10069 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
10070 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
10078 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
10079 dest_y = MAX (dest_y, 0);
10083 if (cell_rect.y < vis_rect.y)
10084 dest_y = cell_rect.y;
10085 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
10086 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
10090 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
10095 * pspp_sheet_view_row_activated:
10096 * @tree_view: A #PsppSheetView
10097 * @path: The #GtkTreePath to be activated.
10098 * @column: The #PsppSheetViewColumn to be activated.
10100 * Activates the cell determined by @path and @column.
10103 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
10105 PsppSheetViewColumn *column)
10107 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10109 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
10114 * pspp_sheet_view_get_reorderable:
10115 * @tree_view: a #PsppSheetView
10117 * Retrieves whether the user can reorder the tree via drag-and-drop. See
10118 * pspp_sheet_view_set_reorderable().
10120 * Return value: %TRUE if the tree can be reordered.
10123 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
10125 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10127 return tree_view->priv->reorderable;
10131 * pspp_sheet_view_set_reorderable:
10132 * @tree_view: A #PsppSheetView.
10133 * @reorderable: %TRUE, if the tree can be reordered.
10135 * This function is a convenience function to allow you to reorder
10136 * models that support the #GtkDragSourceIface and the
10137 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
10138 * these. If @reorderable is %TRUE, then the user can reorder the
10139 * model by dragging and dropping rows. The developer can listen to
10140 * these changes by connecting to the model's row_inserted and
10141 * row_deleted signals. The reordering is implemented by setting up
10142 * the tree view as a drag source and destination. Therefore, drag and
10143 * drop can not be used in a reorderable view for any other purpose.
10145 * This function does not give you any degree of control over the order -- any
10146 * reordering is allowed. If more control is needed, you should probably
10147 * handle drag and drop manually.
10150 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
10151 gboolean reorderable)
10153 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10155 reorderable = reorderable != FALSE;
10157 if (tree_view->priv->reorderable == reorderable)
10162 const GtkTargetEntry row_targets[] = {
10163 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
10166 pspp_sheet_view_enable_model_drag_source (tree_view,
10169 G_N_ELEMENTS (row_targets),
10171 pspp_sheet_view_enable_model_drag_dest (tree_view,
10173 G_N_ELEMENTS (row_targets),
10178 pspp_sheet_view_unset_rows_drag_source (tree_view);
10179 pspp_sheet_view_unset_rows_drag_dest (tree_view);
10182 tree_view->priv->reorderable = reorderable;
10184 g_object_notify (G_OBJECT (tree_view), "reorderable");
10187 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
10188 is pressed, other rows will be unselected.
10190 If CLAMP_NODE is true, then the sheetview will scroll to make the row
10193 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
10195 gboolean clear_and_select,
10196 gboolean clamp_node,
10197 PsppSheetSelectMode mode)
10201 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10203 GtkTreePath *cursor_path;
10204 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10205 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
10206 gtk_tree_path_free (cursor_path);
10209 gtk_tree_row_reference_free (tree_view->priv->cursor);
10210 tree_view->priv->cursor = NULL;
10212 _pspp_sheet_view_find_node (tree_view, path, &node);
10213 tree_view->priv->cursor =
10214 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
10215 tree_view->priv->model,
10218 if (tree_view->priv->row_count > 0)
10222 if (clear_and_select && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
10223 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
10227 /* We have to re-find tree and node here again, somebody might have
10228 * cleared the node or the whole tree in the PsppSheetSelection::changed
10229 * callback. If the nodes differ we bail out here.
10231 _pspp_sheet_view_find_node (tree_view, path, &new_node);
10233 if (node != new_node)
10238 pspp_sheet_view_clamp_node_visible (tree_view, node);
10239 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10243 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
10247 * pspp_sheet_view_get_cursor:
10248 * @tree_view: A #PsppSheetView
10249 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
10250 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
10252 * Fills in @path and @focus_column with the current path and focus column. If
10253 * the cursor isn't currently set, then *@path will be %NULL. If no column
10254 * currently has focus, then *@focus_column will be %NULL.
10256 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
10257 * you are done with it.
10260 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
10261 GtkTreePath **path,
10262 PsppSheetViewColumn **focus_column)
10264 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10268 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10269 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10276 *focus_column = tree_view->priv->focus_column;
10281 * pspp_sheet_view_set_cursor:
10282 * @tree_view: A #PsppSheetView
10283 * @path: A #GtkTreePath
10284 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10285 * @start_editing: %TRUE if the specified cell should start being edited.
10287 * Sets the current keyboard focus to be at @path, and selects it. This is
10288 * useful when you want to focus the user's attention on a particular row. If
10289 * @focus_column is not %NULL, then focus is given to the column specified by
10290 * it. Additionally, if @focus_column is specified, and @start_editing is
10291 * %TRUE, then editing should be started in the specified cell.
10292 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
10293 * in order to give keyboard focus to the widget. Please note that editing
10294 * can only happen when the widget is realized.
10296 * If @path is invalid for @model, the current cursor (if any) will be unset
10297 * and the function will return without failing.
10300 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
10302 PsppSheetViewColumn *focus_column,
10303 gboolean start_editing)
10305 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
10306 NULL, start_editing);
10310 * pspp_sheet_view_set_cursor_on_cell:
10311 * @tree_view: A #PsppSheetView
10312 * @path: A #GtkTreePath
10313 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10314 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
10315 * @start_editing: %TRUE if the specified cell should start being edited.
10317 * Sets the current keyboard focus to be at @path, and selects it. This is
10318 * useful when you want to focus the user's attention on a particular row. If
10319 * @focus_column is not %NULL, then focus is given to the column specified by
10320 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
10321 * contains 2 or more editable or activatable cells, then focus is given to
10322 * the cell specified by @focus_cell. Additionally, if @focus_column is
10323 * specified, and @start_editing is %TRUE, then editing should be started in
10324 * the specified cell. This function is often followed by
10325 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
10326 * widget. Please note that editing can only happen when the widget is
10329 * If @path is invalid for @model, the current cursor (if any) will be unset
10330 * and the function will return without failing.
10335 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
10337 PsppSheetViewColumn *focus_column,
10338 GtkCellRenderer *focus_cell,
10339 gboolean start_editing)
10341 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10342 g_return_if_fail (path != NULL);
10343 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
10345 if (!tree_view->priv->model)
10350 g_return_if_fail (focus_column);
10351 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
10354 /* cancel the current editing, if it exists */
10355 if (tree_view->priv->edited_column &&
10356 tree_view->priv->edited_column->editable_widget)
10357 pspp_sheet_view_stop_editing (tree_view, TRUE);
10359 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
10361 if (focus_column && focus_column->visible)
10364 gboolean column_in_tree = FALSE;
10366 for (list = tree_view->priv->columns; list; list = list->next)
10367 if (list->data == focus_column)
10369 column_in_tree = TRUE;
10372 g_return_if_fail (column_in_tree);
10373 tree_view->priv->focus_column = focus_column;
10375 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
10377 pspp_sheet_view_start_editing (tree_view, path);
10379 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
10380 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
10386 * pspp_sheet_view_get_bin_window:
10387 * @tree_view: A #PsppSheetView
10389 * Returns the window that @tree_view renders to. This is used primarily to
10390 * compare to <literal>event->window</literal> to confirm that the event on
10391 * @tree_view is on the right window.
10393 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
10396 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
10398 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
10400 return tree_view->priv->bin_window;
10404 * pspp_sheet_view_get_path_at_pos:
10405 * @tree_view: A #PsppSheetView.
10406 * @x: The x position to be identified (relative to bin_window).
10407 * @y: The y position to be identified (relative to bin_window).
10408 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
10409 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
10410 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
10411 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
10413 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10414 * (please see pspp_sheet_view_get_bin_window()).
10415 * That is, @x and @y are relative to an events coordinates. @x and @y must
10416 * come from an event on the @tree_view only where <literal>event->window ==
10417 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10418 * things like popup menus. If @path is non-%NULL, then it will be filled
10419 * with the #GtkTreePath at that point. This path should be freed with
10420 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10421 * with the column at that point. @cell_x and @cell_y return the coordinates
10422 * relative to the cell background (i.e. the @background_area passed to
10423 * gtk_cell_renderer_render()). This function is only meaningful if
10424 * @tree_view is realized. Therefore this function will always return %FALSE
10425 * if @tree_view is not realized or does not have a model.
10427 * For converting widget coordinates (eg. the ones you get from
10428 * GtkWidget::query-tooltip), please see
10429 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10431 * Return value: %TRUE if a row exists at that coordinate.
10434 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10437 GtkTreePath **path,
10438 PsppSheetViewColumn **column,
10445 g_return_val_if_fail (tree_view != NULL, FALSE);
10452 if (tree_view->priv->bin_window == NULL)
10455 if (tree_view->priv->row_count == 0)
10458 if (x > gtk_adjustment_get_upper (tree_view->priv->hadjustment))
10461 if (x < 0 || y < 0)
10464 if (column || cell_x)
10466 PsppSheetViewColumn *tmp_column;
10467 PsppSheetViewColumn *last_column = NULL;
10469 gint remaining_x = x;
10470 gboolean found = FALSE;
10473 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10474 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10476 list = (rtl ? list->prev : list->next))
10478 tmp_column = list->data;
10480 if (tmp_column->visible == FALSE)
10483 last_column = tmp_column;
10484 if (remaining_x <= tmp_column->width)
10489 *column = tmp_column;
10492 *cell_x = remaining_x;
10496 remaining_x -= tmp_column->width;
10499 /* If found is FALSE and there is a last_column, then it the remainder
10500 * space is in that area
10507 *column = last_column;
10510 *cell_x = last_column->width + remaining_x;
10519 y_offset = pspp_sheet_view_find_offset (tree_view,
10520 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10527 *cell_y = y_offset;
10530 *path = _pspp_sheet_view_find_path (tree_view, node);
10535 /* Computes 'cell_area' from 'background_area', which must be the background
10536 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10537 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10538 the cell area as passed to _pspp_sheet_view_column_cell_render().
10540 'column' is required to properly adjust 'cell_area->x' and
10541 'cell_area->width'. It may be set to NULL if these values are not of
10542 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10545 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10546 PsppSheetViewColumn *column,
10547 const GdkRectangle *background_area,
10548 gboolean subtract_focus_rect,
10549 GdkRectangle *cell_area)
10551 gint vertical_separator;
10552 gint horizontal_separator;
10554 *cell_area = *background_area;
10556 gtk_widget_style_get (GTK_WIDGET (tree_view),
10557 "vertical-separator", &vertical_separator,
10558 "horizontal-separator", &horizontal_separator,
10560 cell_area->x += horizontal_separator / 2;
10561 cell_area->y += vertical_separator / 2;
10562 cell_area->width -= horizontal_separator;
10563 cell_area->height -= vertical_separator;
10565 if (subtract_focus_rect)
10567 int focus_line_width;
10569 gtk_widget_style_get (GTK_WIDGET (tree_view),
10570 "focus-line-width", &focus_line_width,
10572 cell_area->x += focus_line_width;
10573 cell_area->y += focus_line_width;
10574 cell_area->width -= 2 * focus_line_width;
10575 cell_area->height -= 2 * focus_line_width;
10578 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10580 gint grid_line_width;
10581 gtk_widget_style_get (GTK_WIDGET (tree_view),
10582 "grid-line-width", &grid_line_width,
10585 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10586 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10589 PsppSheetViewColumn *first_column, *last_column;
10592 /* Find the last visible column. */
10593 last_column = NULL;
10594 for (list = g_list_last (tree_view->priv->columns);
10598 PsppSheetViewColumn *c = list->data;
10606 /* Find the first visible column. */
10607 first_column = NULL;
10608 for (list = g_list_first (tree_view->priv->columns);
10612 PsppSheetViewColumn *c = list->data;
10620 if (column == first_column)
10622 cell_area->width -= grid_line_width / 2;
10624 else if (column == last_column)
10626 cell_area->x += grid_line_width / 2;
10627 cell_area->width -= grid_line_width / 2;
10631 cell_area->x += grid_line_width / 2;
10632 cell_area->width -= grid_line_width;
10636 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10637 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10639 cell_area->y += grid_line_width / 2;
10640 cell_area->height -= grid_line_width;
10644 if (column == NULL)
10647 cell_area->width = 0;
10652 * pspp_sheet_view_get_cell_area:
10653 * @tree_view: a #PsppSheetView
10654 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10655 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10656 * @rect: rectangle to fill with cell rect
10658 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10659 * row specified by @path and the column specified by @column. If @path is
10660 * %NULL, or points to a path not currently displayed, the @y and @height fields
10661 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10662 * fields will be filled with 0. The sum of all cell rects does not cover the
10663 * entire tree; there are extra pixels in between rows, for example. The
10664 * returned rectangle is equivalent to the @cell_area passed to
10665 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10669 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10671 PsppSheetViewColumn *column,
10672 GdkRectangle *rect)
10674 GdkRectangle background_area;
10676 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10677 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10678 g_return_if_fail (rect != NULL);
10679 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10680 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10682 pspp_sheet_view_get_background_area (tree_view, path, column,
10684 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10689 * pspp_sheet_view_get_background_area:
10690 * @tree_view: a #PsppSheetView
10691 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10692 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10693 * @rect: rectangle to fill with cell background rect
10695 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10696 * row specified by @path and the column specified by @column. If @path is
10697 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10698 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10699 * fields will be filled with 0. The returned rectangle is equivalent to the
10700 * @background_area passed to gtk_cell_renderer_render(). These background
10701 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10702 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10703 * itself, excluding surrounding borders.
10707 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10709 PsppSheetViewColumn *column,
10710 GdkRectangle *rect)
10714 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10715 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10716 g_return_if_fail (rect != NULL);
10725 /* Get vertical coords */
10727 _pspp_sheet_view_find_node (tree_view, path, &node);
10731 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10733 rect->height = ROW_HEIGHT (tree_view);
10740 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10741 rect->width = x2 - rect->x;
10746 * pspp_sheet_view_get_visible_rect:
10747 * @tree_view: a #PsppSheetView
10748 * @visible_rect: rectangle to fill
10750 * Fills @visible_rect with the currently-visible region of the
10751 * buffer, in tree coordinates. Convert to bin_window coordinates with
10752 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10753 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10754 * scrollable area of the tree.
10757 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10758 GdkRectangle *visible_rect)
10762 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10764 widget = GTK_WIDGET (tree_view);
10768 GtkAllocation allocation;
10769 gtk_widget_get_allocation (widget, &allocation);
10770 visible_rect->x = gtk_adjustment_get_value (tree_view->priv->hadjustment);
10771 visible_rect->y = gtk_adjustment_get_value (tree_view->priv->vadjustment);
10772 visible_rect->width = allocation.width;
10773 visible_rect->height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10778 * pspp_sheet_view_widget_to_tree_coords:
10779 * @tree_view: a #PsppSheetView
10780 * @wx: X coordinate relative to bin_window
10781 * @wy: Y coordinate relative to bin_window
10782 * @tx: return location for tree X coordinate
10783 * @ty: return location for tree Y coordinate
10785 * Converts bin_window coordinates to coordinates for the
10786 * tree (the full scrollable area of the tree).
10788 * Deprecated: 2.12: Due to historial reasons the name of this function is
10789 * incorrect. For converting coordinates relative to the widget to
10790 * bin_window coordinates, please see
10791 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10795 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10801 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10804 *tx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10806 *ty = wy + tree_view->priv->dy;
10810 * pspp_sheet_view_tree_to_widget_coords:
10811 * @tree_view: a #PsppSheetView
10812 * @tx: tree X coordinate
10813 * @ty: tree Y coordinate
10814 * @wx: return location for X coordinate relative to bin_window
10815 * @wy: return location for Y coordinate relative to bin_window
10817 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10818 * to bin_window coordinates.
10820 * Deprecated: 2.12: Due to historial reasons the name of this function is
10821 * incorrect. For converting bin_window coordinates to coordinates relative
10822 * to bin_window, please see
10823 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10827 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10833 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10836 *wx = tx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10838 *wy = ty - tree_view->priv->dy;
10843 * pspp_sheet_view_convert_widget_to_tree_coords:
10844 * @tree_view: a #PsppSheetView
10845 * @wx: X coordinate relative to the widget
10846 * @wy: Y coordinate relative to the widget
10847 * @tx: return location for tree X coordinate
10848 * @ty: return location for tree Y coordinate
10850 * Converts widget coordinates to coordinates for the
10851 * tree (the full scrollable area of the tree).
10856 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10864 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10866 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10869 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10875 * pspp_sheet_view_convert_tree_to_widget_coords:
10876 * @tree_view: a #PsppSheetView
10877 * @tx: X coordinate relative to the tree
10878 * @ty: Y coordinate relative to the tree
10879 * @wx: return location for widget X coordinate
10880 * @wy: return location for widget Y coordinate
10882 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10883 * to widget coordinates.
10888 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10896 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10898 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10901 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10907 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10908 * @tree_view: a #PsppSheetView
10909 * @wx: X coordinate relative to the widget
10910 * @wy: Y coordinate relative to the widget
10911 * @bx: return location for bin_window X coordinate
10912 * @by: return location for bin_window Y coordinate
10914 * Converts widget coordinates to coordinates for the bin_window
10915 * (see pspp_sheet_view_get_bin_window()).
10920 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10926 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10929 *bx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10931 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10935 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10936 * @tree_view: a #PsppSheetView
10937 * @bx: bin_window X coordinate
10938 * @by: bin_window Y coordinate
10939 * @wx: return location for widget X coordinate
10940 * @wy: return location for widget Y coordinate
10942 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10943 * to widget relative coordinates.
10948 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10954 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10957 *wx = bx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10959 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10963 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10964 * @tree_view: a #PsppSheetView
10965 * @tx: tree X coordinate
10966 * @ty: tree Y coordinate
10967 * @bx: return location for X coordinate relative to bin_window
10968 * @by: return location for Y coordinate relative to bin_window
10970 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10971 * to bin_window coordinates.
10976 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10982 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10987 *by = ty - tree_view->priv->dy;
10991 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10992 * @tree_view: a #PsppSheetView
10993 * @bx: X coordinate relative to bin_window
10994 * @by: Y coordinate relative to bin_window
10995 * @tx: return location for tree X coordinate
10996 * @ty: return location for tree Y coordinate
10998 * Converts bin_window coordinates to coordinates for the
10999 * tree (the full scrollable area of the tree).
11004 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
11010 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11015 *ty = by + tree_view->priv->dy;
11021 * pspp_sheet_view_get_visible_range:
11022 * @tree_view: A #PsppSheetView
11023 * @start_path: (allow-none): Return location for start of region, or %NULL.
11024 * @end_path: (allow-none): Return location for end of region, or %NULL.
11026 * Sets @start_path and @end_path to be the first and last visible path.
11027 * Note that there may be invisible paths in between.
11029 * The paths should be freed with gtk_tree_path_free() after use.
11031 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
11036 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
11037 GtkTreePath **start_path,
11038 GtkTreePath **end_path)
11043 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11045 if (!tree_view->priv->row_count)
11052 pspp_sheet_view_find_offset (tree_view,
11053 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
11056 *start_path = _pspp_sheet_view_find_path (tree_view, node);
11065 if (tree_view->priv->height < gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
11066 y = tree_view->priv->height - 1;
11068 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, gtk_adjustment_get_page_size (tree_view->priv->vadjustment)) - 1;
11070 pspp_sheet_view_find_offset (tree_view, y, &node);
11072 *end_path = _pspp_sheet_view_find_path (tree_view, node);
11081 unset_reorderable (PsppSheetView *tree_view)
11083 if (tree_view->priv->reorderable)
11085 tree_view->priv->reorderable = FALSE;
11086 g_object_notify (G_OBJECT (tree_view), "reorderable");
11091 * pspp_sheet_view_enable_model_drag_source:
11092 * @tree_view: a #PsppSheetView
11093 * @start_button_mask: Mask of allowed buttons to start drag
11094 * @targets: the table of targets that the drag will support
11095 * @n_targets: the number of items in @targets
11096 * @actions: the bitmask of possible actions for a drag from this
11099 * Turns @tree_view into a drag source for automatic DND. Calling this
11100 * method sets #PsppSheetView:reorderable to %FALSE.
11103 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
11104 GdkModifierType start_button_mask,
11105 const GtkTargetEntry *targets,
11107 GdkDragAction actions)
11109 TreeViewDragInfo *di;
11111 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11113 gtk_drag_source_set (GTK_WIDGET (tree_view),
11119 di = ensure_info (tree_view);
11121 di->start_button_mask = start_button_mask;
11122 di->source_actions = actions;
11123 di->source_set = TRUE;
11125 unset_reorderable (tree_view);
11129 * pspp_sheet_view_enable_model_drag_dest:
11130 * @tree_view: a #PsppSheetView
11131 * @targets: the table of targets that the drag will support
11132 * @n_targets: the number of items in @targets
11133 * @actions: the bitmask of possible actions for a drag from this
11136 * Turns @tree_view into a drop destination for automatic DND. Calling
11137 * this method sets #PsppSheetView:reorderable to %FALSE.
11140 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
11141 const GtkTargetEntry *targets,
11143 GdkDragAction actions)
11145 TreeViewDragInfo *di;
11147 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11149 gtk_drag_dest_set (GTK_WIDGET (tree_view),
11155 di = ensure_info (tree_view);
11156 di->dest_set = TRUE;
11158 unset_reorderable (tree_view);
11162 * pspp_sheet_view_unset_rows_drag_source:
11163 * @tree_view: a #PsppSheetView
11165 * Undoes the effect of
11166 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
11167 * #PsppSheetView:reorderable to %FALSE.
11170 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
11172 TreeViewDragInfo *di;
11174 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11176 di = get_info (tree_view);
11180 if (di->source_set)
11182 gtk_drag_source_unset (GTK_WIDGET (tree_view));
11183 di->source_set = FALSE;
11186 if (!di->dest_set && !di->source_set)
11187 remove_info (tree_view);
11190 unset_reorderable (tree_view);
11194 * pspp_sheet_view_unset_rows_drag_dest:
11195 * @tree_view: a #PsppSheetView
11197 * Undoes the effect of
11198 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
11199 * #PsppSheetView:reorderable to %FALSE.
11202 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
11204 TreeViewDragInfo *di;
11206 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11208 di = get_info (tree_view);
11214 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
11215 di->dest_set = FALSE;
11218 if (!di->dest_set && !di->source_set)
11219 remove_info (tree_view);
11222 unset_reorderable (tree_view);
11226 * pspp_sheet_view_set_drag_dest_row:
11227 * @tree_view: a #PsppSheetView
11228 * @path: (allow-none): The path of the row to highlight, or %NULL.
11229 * @pos: Specifies whether to drop before, after or into the row
11231 * Sets the row that is highlighted for feedback.
11234 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
11236 PsppSheetViewDropPosition pos)
11238 GtkTreePath *current_dest;
11240 /* Note; this function is exported to allow a custom DND
11241 * implementation, so it can't touch TreeViewDragInfo
11244 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11246 current_dest = NULL;
11248 if (tree_view->priv->drag_dest_row)
11250 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11251 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
11254 /* special case a drop on an empty model */
11255 tree_view->priv->empty_view_drop = 0;
11257 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
11258 && gtk_tree_path_get_depth (path) == 1
11259 && gtk_tree_path_get_indices (path)[0] == 0)
11263 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
11267 tree_view->priv->empty_view_drop = 1;
11270 tree_view->priv->drag_dest_pos = pos;
11274 tree_view->priv->drag_dest_row =
11275 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
11276 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
11279 tree_view->priv->drag_dest_row = NULL;
11283 int node, new_node;
11285 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
11286 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
11290 new_node = pspp_sheet_view_node_next (tree_view, node);
11292 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11294 new_node = pspp_sheet_view_node_prev (tree_view, node);
11296 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11298 gtk_tree_path_free (current_dest);
11303 * pspp_sheet_view_get_drag_dest_row:
11304 * @tree_view: a #PsppSheetView
11305 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11306 * @pos: (allow-none): Return location for the drop position, or %NULL
11308 * Gets information about the row that is highlighted for feedback.
11311 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
11312 GtkTreePath **path,
11313 PsppSheetViewDropPosition *pos)
11315 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11319 if (tree_view->priv->drag_dest_row)
11320 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11323 if (tree_view->priv->empty_view_drop)
11324 *path = gtk_tree_path_new_from_indices (0, -1);
11331 *pos = tree_view->priv->drag_dest_pos;
11335 * pspp_sheet_view_get_dest_row_at_pos:
11336 * @tree_view: a #PsppSheetView
11337 * @drag_x: the position to determine the destination row for
11338 * @drag_y: the position to determine the destination row for
11339 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11340 * @pos: (allow-none): Return location for the drop position, or %NULL
11342 * Determines the destination row for a given position. @drag_x and
11343 * @drag_y are expected to be in widget coordinates. This function is only
11344 * meaningful if @tree_view is realized. Therefore this function will always
11345 * return %FALSE if @tree_view is not realized or does not have a model.
11347 * Return value: whether there is a row at the given position, %TRUE if this
11348 * is indeed the case.
11351 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
11354 GtkTreePath **path,
11355 PsppSheetViewDropPosition *pos)
11359 gdouble offset_into_row;
11362 PsppSheetViewColumn *column = NULL;
11363 GtkTreePath *tmp_path = NULL;
11365 /* Note; this function is exported to allow a custom DND
11366 * implementation, so it can't touch TreeViewDragInfo
11369 g_return_val_if_fail (tree_view != NULL, FALSE);
11370 g_return_val_if_fail (drag_x >= 0, FALSE);
11371 g_return_val_if_fail (drag_y >= 0, FALSE);
11376 if (tree_view->priv->bin_window == NULL)
11379 if (tree_view->priv->row_count == 0)
11382 /* If in the top third of a row, we drop before that row; if
11383 * in the bottom third, drop after that row; if in the middle,
11384 * and the row has children, drop into the row.
11386 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
11389 if (!pspp_sheet_view_get_path_at_pos (tree_view,
11398 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
11401 offset_into_row = cell_y;
11406 gtk_tree_path_free (tmp_path);
11410 third = cell.height / 3.0;
11414 if (offset_into_row < third)
11416 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11418 else if (offset_into_row < (cell.height / 2.0))
11420 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11422 else if (offset_into_row < third * 2.0)
11424 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11428 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11436 #if GTK3_TRANSITION
11437 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11439 * pspp_sheet_view_create_row_drag_icon:
11440 * @tree_view: a #PsppSheetView
11441 * @path: a #GtkTreePath in @tree_view
11443 * Creates a #GdkPixmap representation of the row at @path.
11444 * This image is used for a drag icon.
11446 * Return value: a newly-allocated pixmap of the drag icon.
11449 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11456 GdkRectangle background_area;
11457 GdkRectangle expose_area;
11459 /* start drawing inside the black outline */
11461 GdkDrawable *drawable;
11462 gint bin_window_width;
11465 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11466 g_return_val_if_fail (path != NULL, NULL);
11468 widget = GTK_WIDGET (tree_view);
11470 if (!gtk_widget_get_realized (widget))
11473 _pspp_sheet_view_find_node (tree_view,
11480 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11487 background_area.y = y;
11488 background_area.height = ROW_HEIGHT (tree_view);
11490 bin_window_width = gdk_window_get_width (tree_view->priv->bin_window);
11492 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11493 bin_window_width + 2,
11494 background_area.height + 2,
11499 expose_area.width = bin_window_width + 2;
11500 expose_area.height = background_area.height + 2;
11502 #if GTK3_TRANSITION
11503 gdk_draw_rectangle (drawable,
11504 widget->style->base_gc [gtk_widget_get_state (widget)],
11507 bin_window_width + 2,
11508 background_area.height + 2);
11511 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11513 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11515 list = (rtl ? list->prev : list->next))
11517 PsppSheetViewColumn *column = list->data;
11518 GdkRectangle cell_area;
11519 gint vertical_separator;
11521 if (!column->visible)
11524 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11526 background_area.x = cell_offset;
11527 background_area.width = column->width;
11529 gtk_widget_style_get (widget,
11530 "vertical-separator", &vertical_separator,
11533 cell_area = background_area;
11535 cell_area.y += vertical_separator / 2;
11536 cell_area.height -= vertical_separator;
11538 if (pspp_sheet_view_column_cell_is_visible (column))
11539 _pspp_sheet_view_column_cell_render (column,
11545 cell_offset += column->width;
11548 #if GTK3_TRANSITION
11549 gdk_draw_rectangle (drawable,
11550 widget->style->black_gc,
11553 bin_window_width + 1,
11554 background_area.height + 1);
11562 * pspp_sheet_view_set_destroy_count_func:
11563 * @tree_view: A #PsppSheetView
11564 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11565 * @data: (allow-none): User data to be passed to @func, or %NULL
11566 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11568 * This function should almost never be used. It is meant for private use by
11569 * ATK for determining the number of visible children that are removed when a row is deleted.
11572 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11573 PsppSheetDestroyCountFunc func,
11575 GDestroyNotify destroy)
11577 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11579 if (tree_view->priv->destroy_count_destroy)
11580 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11582 tree_view->priv->destroy_count_func = func;
11583 tree_view->priv->destroy_count_data = data;
11584 tree_view->priv->destroy_count_destroy = destroy;
11589 * Interactive search
11593 * pspp_sheet_view_set_enable_search:
11594 * @tree_view: A #PsppSheetView
11595 * @enable_search: %TRUE, if the user can search interactively
11597 * If @enable_search is set, then the user can type in text to search through
11598 * the tree interactively (this is sometimes called "typeahead find").
11600 * Note that even if this is %FALSE, the user can still initiate a search
11601 * using the "start-interactive-search" key binding.
11604 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11605 gboolean enable_search)
11607 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11609 enable_search = !!enable_search;
11611 if (tree_view->priv->enable_search != enable_search)
11613 tree_view->priv->enable_search = enable_search;
11614 g_object_notify (G_OBJECT (tree_view), "enable-search");
11619 * pspp_sheet_view_get_enable_search:
11620 * @tree_view: A #PsppSheetView
11622 * Returns whether or not the tree allows to start interactive searching
11623 * by typing in text.
11625 * Return value: whether or not to let the user search interactively
11628 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11630 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11632 return tree_view->priv->enable_search;
11637 * pspp_sheet_view_get_search_column:
11638 * @tree_view: A #PsppSheetView
11640 * Gets the column searched on by the interactive search code.
11642 * Return value: the column the interactive search code searches in.
11645 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11647 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11649 return (tree_view->priv->search_column);
11653 * pspp_sheet_view_set_search_column:
11654 * @tree_view: A #PsppSheetView
11655 * @column: the column of the model to search in, or -1 to disable searching
11657 * Sets @column as the column where the interactive search code should
11658 * search in for the current model.
11660 * If the search column is set, users can use the "start-interactive-search"
11661 * key binding to bring up search popup. The enable-search property controls
11662 * whether simply typing text will also start an interactive search.
11664 * Note that @column refers to a column of the current model. The search
11665 * column is reset to -1 when the model is changed.
11668 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11671 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11672 g_return_if_fail (column >= -1);
11674 if (tree_view->priv->search_column == column)
11677 tree_view->priv->search_column = column;
11678 g_object_notify (G_OBJECT (tree_view), "search-column");
11682 * pspp_sheet_view_get_search_equal_func:
11683 * @tree_view: A #PsppSheetView
11685 * Returns the compare function currently in use.
11687 * Return value: the currently used compare function for the search code.
11690 PsppSheetViewSearchEqualFunc
11691 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11693 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11695 return tree_view->priv->search_equal_func;
11699 * pspp_sheet_view_set_search_equal_func:
11700 * @tree_view: A #PsppSheetView
11701 * @search_equal_func: the compare function to use during the search
11702 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11703 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11705 * Sets the compare function for the interactive search capabilities; note
11706 * that somewhat like strcmp() returning 0 for equality
11707 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11710 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11711 PsppSheetViewSearchEqualFunc search_equal_func,
11712 gpointer search_user_data,
11713 GDestroyNotify search_destroy)
11715 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11716 g_return_if_fail (search_equal_func != NULL);
11718 if (tree_view->priv->search_destroy)
11719 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11721 tree_view->priv->search_equal_func = search_equal_func;
11722 tree_view->priv->search_user_data = search_user_data;
11723 tree_view->priv->search_destroy = search_destroy;
11724 if (tree_view->priv->search_equal_func == NULL)
11725 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11729 * pspp_sheet_view_get_search_entry:
11730 * @tree_view: A #PsppSheetView
11732 * Returns the #GtkEntry which is currently in use as interactive search
11733 * entry for @tree_view. In case the built-in entry is being used, %NULL
11734 * will be returned.
11736 * Return value: the entry currently in use as search entry.
11741 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11743 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11745 if (tree_view->priv->search_custom_entry_set)
11746 return GTK_ENTRY (tree_view->priv->search_entry);
11752 * pspp_sheet_view_set_search_entry:
11753 * @tree_view: A #PsppSheetView
11754 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11756 * Sets the entry which the interactive search code will use for this
11757 * @tree_view. This is useful when you want to provide a search entry
11758 * in our interface at all time at a fixed position. Passing %NULL for
11759 * @entry will make the interactive search code use the built-in popup
11765 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11768 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11769 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11771 if (tree_view->priv->search_custom_entry_set)
11773 if (tree_view->priv->search_entry_changed_id)
11775 g_signal_handler_disconnect (tree_view->priv->search_entry,
11776 tree_view->priv->search_entry_changed_id);
11777 tree_view->priv->search_entry_changed_id = 0;
11779 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11780 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11783 g_object_unref (tree_view->priv->search_entry);
11785 else if (tree_view->priv->search_window)
11787 gtk_widget_destroy (tree_view->priv->search_window);
11789 tree_view->priv->search_window = NULL;
11794 tree_view->priv->search_entry = g_object_ref (entry);
11795 tree_view->priv->search_custom_entry_set = TRUE;
11797 if (tree_view->priv->search_entry_changed_id == 0)
11799 tree_view->priv->search_entry_changed_id =
11800 g_signal_connect (tree_view->priv->search_entry, "changed",
11801 G_CALLBACK (pspp_sheet_view_search_init),
11805 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11806 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11809 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11813 tree_view->priv->search_entry = NULL;
11814 tree_view->priv->search_custom_entry_set = FALSE;
11819 * pspp_sheet_view_set_search_position_func:
11820 * @tree_view: A #PsppSheetView
11821 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11822 * to use the default search position function
11823 * @data: (allow-none): user data to pass to @func, or %NULL
11824 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11826 * Sets the function to use when positioning the search dialog.
11831 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11832 PsppSheetViewSearchPositionFunc func,
11833 gpointer user_data,
11834 GDestroyNotify destroy)
11836 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11838 if (tree_view->priv->search_position_destroy)
11839 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11841 tree_view->priv->search_position_func = func;
11842 tree_view->priv->search_position_user_data = user_data;
11843 tree_view->priv->search_position_destroy = destroy;
11844 if (tree_view->priv->search_position_func == NULL)
11845 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11849 * pspp_sheet_view_get_search_position_func:
11850 * @tree_view: A #PsppSheetView
11852 * Returns the positioning function currently in use.
11854 * Return value: the currently used function for positioning the search dialog.
11858 PsppSheetViewSearchPositionFunc
11859 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11861 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11863 return tree_view->priv->search_position_func;
11868 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11869 PsppSheetView *tree_view)
11871 if (tree_view->priv->disable_popdown)
11874 if (tree_view->priv->search_entry_changed_id)
11876 g_signal_handler_disconnect (tree_view->priv->search_entry,
11877 tree_view->priv->search_entry_changed_id);
11878 tree_view->priv->search_entry_changed_id = 0;
11880 if (tree_view->priv->typeselect_flush_timeout)
11882 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11883 tree_view->priv->typeselect_flush_timeout = 0;
11886 if (gtk_widget_get_visible (search_dialog))
11888 /* send focus-in event */
11889 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11890 gtk_widget_hide (search_dialog);
11891 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11892 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11897 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11898 GtkWidget *search_dialog,
11899 gpointer user_data)
11902 gint tree_x, tree_y;
11903 gint tree_width, tree_height;
11904 GdkWindow *tree_window = gtk_widget_get_window (GTK_WIDGET (tree_view));
11905 GdkScreen *screen = gdk_window_get_screen (tree_window);
11906 GtkRequisition requisition;
11908 GdkRectangle monitor;
11910 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11911 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11913 gtk_widget_realize (search_dialog);
11915 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11916 tree_width = gdk_window_get_width (tree_window);
11917 tree_height = gdk_window_get_height (tree_window);
11919 gtk_widget_size_request (search_dialog, &requisition);
11921 if (tree_x + tree_width > gdk_screen_get_width (screen))
11922 x = gdk_screen_get_width (screen) - requisition.width;
11923 else if (tree_x + tree_width - requisition.width < 0)
11926 x = tree_x + tree_width - requisition.width;
11928 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11929 y = gdk_screen_get_height (screen) - requisition.height;
11930 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11933 y = tree_y + tree_height;
11935 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11939 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11943 PsppSheetView *tree_view = (PsppSheetView *)data;
11945 tree_view->priv->disable_popdown = 1;
11946 g_signal_connect (menu, "hide",
11947 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11950 #if GTK3_TRANSITION
11951 /* Because we're visible but offscreen, we just set a flag in the preedit
11955 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11956 PsppSheetView *tree_view)
11958 tree_view->priv->imcontext_changed = 1;
11959 if (tree_view->priv->typeselect_flush_timeout)
11961 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11962 tree_view->priv->typeselect_flush_timeout =
11963 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11964 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11972 pspp_sheet_view_search_activate (GtkEntry *entry,
11973 PsppSheetView *tree_view)
11978 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11981 /* If we have a row selected and it's the cursor row, we activate
11983 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11985 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11987 _pspp_sheet_view_find_node (tree_view, path, &node);
11989 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11990 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11992 gtk_tree_path_free (path);
11997 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11999 PsppSheetView *tree_view = (PsppSheetView *)data;
12001 tree_view->priv->disable_popdown = 0;
12007 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
12010 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
12014 pspp_sheet_view_search_delete_event (GtkWidget *widget,
12015 GdkEventAny *event,
12016 PsppSheetView *tree_view)
12018 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12020 pspp_sheet_view_search_dialog_hide (widget, tree_view);
12026 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
12027 GdkEventButton *event,
12028 PsppSheetView *tree_view)
12030 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12032 pspp_sheet_view_search_dialog_hide (widget, tree_view);
12034 if (event->window == tree_view->priv->bin_window)
12035 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
12041 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
12042 GdkEventScroll *event,
12043 PsppSheetView *tree_view)
12045 gboolean retval = FALSE;
12047 if (event->direction == GDK_SCROLL_UP)
12049 pspp_sheet_view_search_move (widget, tree_view, TRUE);
12052 else if (event->direction == GDK_SCROLL_DOWN)
12054 pspp_sheet_view_search_move (widget, tree_view, FALSE);
12058 /* renew the flush timeout */
12059 if (retval && tree_view->priv->typeselect_flush_timeout
12060 && !tree_view->priv->search_custom_entry_set)
12062 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12063 tree_view->priv->typeselect_flush_timeout =
12064 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12065 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12073 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
12074 GdkEventKey *event,
12075 PsppSheetView *tree_view)
12077 gboolean retval = FALSE;
12079 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12080 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12082 /* close window and cancel the search */
12083 if (!tree_view->priv->search_custom_entry_set
12084 && (event->keyval == GDK_Escape ||
12085 event->keyval == GDK_Tab ||
12086 event->keyval == GDK_KP_Tab ||
12087 event->keyval == GDK_ISO_Left_Tab))
12089 pspp_sheet_view_search_dialog_hide (widget, tree_view);
12093 /* select previous matching iter */
12094 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
12096 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
12097 gtk_widget_error_bell (widget);
12102 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
12103 && (event->keyval == GDK_g || event->keyval == GDK_G))
12105 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
12106 gtk_widget_error_bell (widget);
12111 /* select next matching iter */
12112 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
12114 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
12115 gtk_widget_error_bell (widget);
12120 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
12121 && (event->keyval == GDK_g || event->keyval == GDK_G))
12123 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
12124 gtk_widget_error_bell (widget);
12129 /* renew the flush timeout */
12130 if (retval && tree_view->priv->typeselect_flush_timeout
12131 && !tree_view->priv->search_custom_entry_set)
12133 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12134 tree_view->priv->typeselect_flush_timeout =
12135 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12136 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12143 /* this function returns FALSE if there is a search string but
12144 * nothing was found, and TRUE otherwise.
12147 pspp_sheet_view_search_move (GtkWidget *window,
12148 PsppSheetView *tree_view,
12156 GtkTreeModel *model;
12157 PsppSheetSelection *selection;
12159 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
12161 g_return_val_if_fail (text != NULL, FALSE);
12163 len = strlen (text);
12165 if (up && tree_view->priv->selected_iter == 1)
12166 return strlen (text) < 1;
12168 len = strlen (text);
12173 model = pspp_sheet_view_get_model (tree_view);
12174 selection = pspp_sheet_view_get_selection (tree_view);
12177 pspp_sheet_selection_unselect_all (selection);
12178 if (!gtk_tree_model_get_iter_first (model, &iter))
12181 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
12182 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
12187 tree_view->priv->selected_iter += up?(-1):(1);
12192 /* return to old iter */
12194 gtk_tree_model_get_iter_first (model, &iter);
12195 pspp_sheet_view_search_iter (model, selection,
12197 &count, tree_view->priv->selected_iter);
12203 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
12207 gpointer search_data)
12209 gboolean retval = TRUE;
12211 gchar *normalized_string;
12212 gchar *normalized_key;
12213 gchar *case_normalized_string = NULL;
12214 gchar *case_normalized_key = NULL;
12215 GValue value = {0,};
12216 GValue transformed = {0,};
12218 gtk_tree_model_get_value (model, iter, column, &value);
12220 g_value_init (&transformed, G_TYPE_STRING);
12222 if (!g_value_transform (&value, &transformed))
12224 g_value_unset (&value);
12228 g_value_unset (&value);
12230 str = g_value_get_string (&transformed);
12233 g_value_unset (&transformed);
12237 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
12238 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
12240 if (normalized_string && normalized_key)
12242 case_normalized_string = g_utf8_casefold (normalized_string, -1);
12243 case_normalized_key = g_utf8_casefold (normalized_key, -1);
12245 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
12249 g_value_unset (&transformed);
12250 g_free (normalized_key);
12251 g_free (normalized_string);
12252 g_free (case_normalized_key);
12253 g_free (case_normalized_string);
12259 pspp_sheet_view_search_iter (GtkTreeModel *model,
12260 PsppSheetSelection *selection,
12269 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
12271 path = gtk_tree_model_get_path (model, iter);
12272 _pspp_sheet_view_find_node (tree_view, path, &node);
12276 gboolean done = FALSE;
12278 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
12283 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
12285 pspp_sheet_selection_select_iter (selection, iter);
12286 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12289 gtk_tree_path_free (path);
12298 node = pspp_sheet_view_node_next (tree_view, node);
12304 has_next = gtk_tree_model_iter_next (model, iter);
12307 gtk_tree_path_next (path);
12310 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
12315 gtk_tree_path_free (path);
12317 /* we've run out of tree, done with this func */
12329 pspp_sheet_view_search_init (GtkWidget *entry,
12330 PsppSheetView *tree_view)
12336 GtkTreeModel *model;
12337 PsppSheetSelection *selection;
12339 g_return_if_fail (GTK_IS_ENTRY (entry));
12340 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12342 text = gtk_entry_get_text (GTK_ENTRY (entry));
12344 model = pspp_sheet_view_get_model (tree_view);
12345 selection = pspp_sheet_view_get_selection (tree_view);
12348 pspp_sheet_selection_unselect_all (selection);
12349 if (tree_view->priv->typeselect_flush_timeout
12350 && !tree_view->priv->search_custom_entry_set)
12352 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12353 tree_view->priv->typeselect_flush_timeout =
12354 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12355 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12362 if (!gtk_tree_model_get_iter_first (model, &iter))
12365 ret = pspp_sheet_view_search_iter (model, selection,
12370 tree_view->priv->selected_iter = 1;
12374 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
12375 PsppSheetView *tree_view)
12377 if (tree_view->priv->edited_column == NULL)
12380 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
12381 tree_view->priv->edited_column = NULL;
12383 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
12384 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12386 g_signal_handlers_disconnect_by_func (cell_editable,
12387 pspp_sheet_view_remove_widget,
12389 g_signal_handlers_disconnect_by_func (cell_editable,
12390 pspp_sheet_view_editable_button_press_event,
12392 g_signal_handlers_disconnect_by_func (cell_editable,
12393 pspp_sheet_view_editable_clicked,
12396 gtk_container_remove (GTK_CONTAINER (tree_view),
12397 GTK_WIDGET (cell_editable));
12399 /* FIXME should only redraw a single node */
12400 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12404 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
12405 GtkTreePath *cursor_path)
12408 GdkRectangle background_area;
12409 GdkRectangle cell_area;
12410 GtkCellEditable *editable_widget = NULL;
12411 gchar *path_string;
12412 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
12413 gint retval = FALSE;
12416 g_assert (tree_view->priv->focus_column);
12418 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12421 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12422 if (cursor_node < 0)
12425 path_string = gtk_tree_path_to_string (cursor_path);
12426 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12428 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12429 tree_view->priv->model,
12431 pspp_sheet_view_get_background_area (tree_view,
12433 tree_view->priv->focus_column,
12435 pspp_sheet_view_get_cell_area (tree_view,
12437 tree_view->priv->focus_column,
12440 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12449 if (editable_widget != NULL)
12453 GtkCellRenderer *cell;
12456 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12458 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12461 area.width -= right + left;
12463 pspp_sheet_view_real_start_editing (tree_view,
12464 tree_view->priv->focus_column,
12473 g_free (path_string);
12478 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12479 GdkEventButton *event,
12480 PsppSheetView *sheet_view)
12484 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12485 "pspp-sheet-view-node"));
12486 return pspp_sheet_view_row_head_clicked (sheet_view,
12488 sheet_view->priv->edited_column,
12493 pspp_sheet_view_editable_clicked (GtkButton *button,
12494 PsppSheetView *sheet_view)
12496 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12501 is_all_selected (GtkWidget *widget)
12503 GtkEntryBuffer *buffer;
12504 gint start_pos, end_pos;
12506 if (!GTK_IS_ENTRY (widget))
12509 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12510 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12511 &start_pos, &end_pos)
12513 && end_pos == gtk_entry_buffer_get_length (buffer));
12517 is_at_left (GtkWidget *widget)
12519 return (GTK_IS_ENTRY (widget)
12520 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12524 is_at_right (GtkWidget *widget)
12526 GtkEntryBuffer *buffer;
12529 if (!GTK_IS_ENTRY (widget))
12532 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12533 length = gtk_entry_buffer_get_length (buffer);
12534 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12538 pspp_sheet_view_event (GtkWidget *widget,
12539 GdkEventKey *event,
12540 PsppSheetView *tree_view)
12542 PsppSheetViewColumn *column;
12549 /* Intercept only key press events.
12550 It would make sense to use "key-press-event" instead of "event", but
12551 GtkEntry attaches its own signal handler to "key-press-event" that runs
12552 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12554 if (event->type != GDK_KEY_PRESS)
12557 keyval = event->keyval;
12559 switch (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12562 switch (event->keyval)
12564 case GDK_Left: case GDK_KP_Left:
12565 case GDK_Home: case GDK_KP_Home:
12566 if (!is_all_selected (widget) && !is_at_left (widget))
12570 case GDK_Right: case GDK_KP_Right:
12571 case GDK_End: case GDK_KP_End:
12572 if (!is_all_selected (widget) && !is_at_right (widget))
12576 case GDK_Up: case GDK_KP_Up:
12577 case GDK_Down: case GDK_KP_Down:
12580 case GDK_Page_Up: case GDK_KP_Page_Up:
12581 case GDK_Page_Down: case GDK_KP_Page_Down:
12592 case GDK_Tab: case GDK_KP_Tab:
12593 case GDK_ISO_Left_Tab:
12602 case GDK_SHIFT_MASK:
12603 switch (event->keyval)
12606 case GDK_ISO_Left_Tab:
12615 case GDK_CONTROL_MASK:
12616 switch (event->keyval)
12618 case GDK_Left: case GDK_KP_Left:
12619 if (!is_all_selected (widget) && !is_at_left (widget))
12623 case GDK_Right: case GDK_KP_Right:
12624 if (!is_all_selected (widget) && !is_at_right (widget))
12628 case GDK_Up: case GDK_KP_Up:
12629 case GDK_Down: case GDK_KP_Down:
12641 row = tree_view->priv->edited_row;
12642 column = tree_view->priv->edited_column;
12643 path = gtk_tree_path_new_from_indices (row, -1);
12645 pspp_sheet_view_stop_editing (tree_view, cancel);
12646 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12648 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12649 gtk_tree_path_free (path);
12651 handled = gtk_binding_set_activate (edit_bindings, keyval, event->state,
12652 G_OBJECT (tree_view));
12654 g_signal_stop_emission_by_name (widget, "event");
12656 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12657 pspp_sheet_view_start_editing (tree_view, path);
12658 gtk_tree_path_free (path);
12664 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12667 PsppSheetView *sheet_view = data;
12669 g_signal_connect (widget, "event",
12670 G_CALLBACK (pspp_sheet_view_event),
12673 if (GTK_IS_CONTAINER (widget))
12674 gtk_container_foreach (GTK_CONTAINER (widget),
12675 pspp_sheet_view_override_cell_keypresses,
12680 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12681 PsppSheetViewColumn *column,
12683 GtkCellEditable *cell_editable,
12684 GdkRectangle *cell_area,
12688 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12689 gint pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
12690 GtkRequisition requisition;
12693 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12695 tree_view->priv->edited_column = column;
12696 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12698 row = gtk_tree_path_get_indices (path)[0];
12699 tree_view->priv->edited_row = row;
12700 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12701 cell_area->y += pre_val - (int)gtk_adjustment_get_value (tree_view->priv->vadjustment);
12703 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12704 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12705 tree_view->priv->anchor_column = column;
12707 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12709 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12711 if (requisition.height < cell_area->height)
12713 gint diff = cell_area->height - requisition.height;
12714 pspp_sheet_view_put (tree_view,
12715 GTK_WIDGET (cell_editable),
12716 cell_area->x, cell_area->y + diff/2,
12717 cell_area->width, requisition.height);
12721 pspp_sheet_view_put (tree_view,
12722 GTK_WIDGET (cell_editable),
12723 cell_area->x, cell_area->y,
12724 cell_area->width, cell_area->height);
12727 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12728 (GdkEvent *)event);
12730 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12731 g_signal_connect (cell_editable, "remove-widget",
12732 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12733 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12734 GTK_IS_BUTTON (cell_editable))
12736 g_signal_connect (cell_editable, "button-press-event",
12737 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12739 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12740 GINT_TO_POINTER (row));
12741 g_signal_connect (cell_editable, "clicked",
12742 G_CALLBACK (pspp_sheet_view_editable_clicked),
12746 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12751 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12752 gboolean cancel_editing)
12754 PsppSheetViewColumn *column;
12755 GtkCellRenderer *cell;
12757 if (tree_view->priv->edited_column == NULL)
12761 * This is very evil. We need to do this, because
12762 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12763 * later on. If pspp_sheet_view_row_changed notices
12764 * tree_view->priv->edited_column != NULL, it'll call
12765 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12767 * Please read that again if you intend to modify anything here.
12770 column = tree_view->priv->edited_column;
12771 tree_view->priv->edited_column = NULL;
12773 cell = _pspp_sheet_view_column_get_edited_cell (column);
12774 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12776 if (!cancel_editing)
12777 gtk_cell_editable_editing_done (column->editable_widget);
12779 tree_view->priv->edited_column = column;
12781 gtk_cell_editable_remove_widget (column->editable_widget);
12786 * pspp_sheet_view_set_hover_selection:
12787 * @tree_view: a #PsppSheetView
12788 * @hover: %TRUE to enable hover selection mode
12790 * Enables of disables the hover selection mode of @tree_view.
12791 * Hover selection makes the selected row follow the pointer.
12792 * Currently, this works only for the selection modes
12793 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12798 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12801 hover = hover != FALSE;
12803 if (hover != tree_view->priv->hover_selection)
12805 tree_view->priv->hover_selection = hover;
12807 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12812 * pspp_sheet_view_get_hover_selection:
12813 * @tree_view: a #PsppSheetView
12815 * Returns whether hover selection mode is turned on for @tree_view.
12817 * Return value: %TRUE if @tree_view is in hover selection mode
12822 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12824 return tree_view->priv->hover_selection;
12828 * pspp_sheet_view_set_rubber_banding:
12829 * @tree_view: a #PsppSheetView
12830 * @enable: %TRUE to enable rubber banding
12832 * Enables or disables rubber banding in @tree_view. If the selection mode is
12833 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12834 * banding will allow the user to select multiple rows by dragging the mouse.
12839 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12842 enable = enable != FALSE;
12844 if (enable != tree_view->priv->rubber_banding_enable)
12846 tree_view->priv->rubber_banding_enable = enable;
12848 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12853 * pspp_sheet_view_get_rubber_banding:
12854 * @tree_view: a #PsppSheetView
12856 * Returns whether rubber banding is turned on for @tree_view. If the
12857 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12858 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12859 * select multiple rows by dragging the mouse.
12861 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12866 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12868 return tree_view->priv->rubber_banding_enable;
12872 * pspp_sheet_view_is_rubber_banding_active:
12873 * @tree_view: a #PsppSheetView
12875 * Returns whether a rubber banding operation is currently being done
12878 * Return value: %TRUE if a rubber banding operation is currently being
12879 * done in @tree_view.
12884 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12886 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12888 if (tree_view->priv->rubber_banding_enable
12889 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12896 pspp_sheet_view_grab_notify (GtkWidget *widget,
12897 gboolean was_grabbed)
12899 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12901 tree_view->priv->in_grab = !was_grabbed;
12905 tree_view->priv->pressed_button = -1;
12907 if (tree_view->priv->rubber_band_status)
12908 pspp_sheet_view_stop_rubber_band (tree_view);
12913 pspp_sheet_view_state_changed (GtkWidget *widget,
12914 GtkStateType previous_state)
12916 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12918 if (gtk_widget_get_realized (widget))
12920 GtkStyle *style = gtk_widget_get_style (widget);
12921 gdk_window_set_background (tree_view->priv->bin_window, &style->base[gtk_widget_get_state (widget)]);
12924 gtk_widget_queue_draw (widget);
12928 * pspp_sheet_view_get_grid_lines:
12929 * @tree_view: a #PsppSheetView
12931 * Returns which grid lines are enabled in @tree_view.
12933 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12938 PsppSheetViewGridLines
12939 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12941 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12943 return tree_view->priv->grid_lines;
12947 * pspp_sheet_view_set_grid_lines:
12948 * @tree_view: a #PsppSheetView
12949 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12952 * Sets which grid lines to draw in @tree_view.
12957 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12958 PsppSheetViewGridLines grid_lines)
12960 PsppSheetViewPrivate *priv;
12961 PsppSheetViewGridLines old_grid_lines;
12963 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12965 priv = tree_view->priv;
12967 old_grid_lines = priv->grid_lines;
12968 priv->grid_lines = grid_lines;
12970 if (old_grid_lines != grid_lines)
12972 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12974 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12979 * pspp_sheet_view_get_special_cells:
12980 * @tree_view: a #PsppSheetView
12982 * Returns which grid lines are enabled in @tree_view.
12984 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12985 * the sheet view contain special cells.
12987 PsppSheetViewSpecialCells
12988 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12990 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12992 return tree_view->priv->special_cells;
12996 * pspp_sheet_view_set_special_cells:
12997 * @tree_view: a #PsppSheetView
12998 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12999 * the sheet view contain special cells.
13001 * Sets whether rows in the sheet view contain special cells, controlling the
13002 * rendering of row selections.
13005 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
13006 PsppSheetViewSpecialCells special_cells)
13008 PsppSheetViewPrivate *priv;
13010 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13012 priv = tree_view->priv;
13014 if (priv->special_cells != special_cells)
13016 priv->special_cells = special_cells;
13017 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
13018 g_object_notify (G_OBJECT (tree_view), "special-cells");
13023 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
13025 /* XXX (re)calculate fixed_height if necessary */
13026 return tree_view->priv->fixed_height;
13030 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
13033 g_return_if_fail (fixed_height > 0);
13035 if (tree_view->priv->fixed_height != fixed_height)
13037 tree_view->priv->fixed_height = fixed_height;
13038 g_object_notify (G_OBJECT (tree_view), "fixed-height");
13040 if (!tree_view->priv->fixed_height_set)
13042 tree_view->priv->fixed_height_set = TRUE;
13043 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
13048 * pspp_sheet_view_set_tooltip_row:
13049 * @tree_view: a #PsppSheetView
13050 * @tooltip: a #GtkTooltip
13051 * @path: a #GtkTreePath
13053 * Sets the tip area of @tooltip to be the area covered by the row at @path.
13054 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
13055 * See also gtk_tooltip_set_tip_area().
13060 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
13061 GtkTooltip *tooltip,
13064 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13065 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
13067 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
13071 * pspp_sheet_view_set_tooltip_cell:
13072 * @tree_view: a #PsppSheetView
13073 * @tooltip: a #GtkTooltip
13074 * @path: (allow-none): a #GtkTreePath or %NULL
13075 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
13076 * @cell: (allow-none): a #GtkCellRenderer or %NULL
13078 * Sets the tip area of @tooltip to the area @path, @column and @cell have
13079 * in common. For example if @path is %NULL and @column is set, the tip
13080 * area will be set to the full area covered by @column. See also
13081 * gtk_tooltip_set_tip_area().
13083 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
13088 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
13089 GtkTooltip *tooltip,
13091 PsppSheetViewColumn *column,
13092 GtkCellRenderer *cell)
13096 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13097 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
13098 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
13099 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
13101 /* Determine x values. */
13102 if (column && cell)
13107 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
13108 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
13110 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13113 rect.width = width;
13119 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
13120 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13123 rect.width = tmp.width;
13127 GtkAllocation allocation;
13128 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
13130 rect.width = allocation.width;
13133 /* Determine y values. */
13138 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
13139 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13142 rect.height = tmp.height;
13147 rect.height = gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
13150 gtk_tooltip_set_tip_area (tooltip, &rect);
13154 * pspp_sheet_view_get_tooltip_context:
13155 * @tree_view: a #PsppSheetView
13156 * @x: the x coordinate (relative to widget coordinates)
13157 * @y: the y coordinate (relative to widget coordinates)
13158 * @keyboard_tip: whether this is a keyboard tooltip or not
13159 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
13160 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
13161 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
13163 * This function is supposed to be used in a #GtkWidget::query-tooltip
13164 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
13165 * which are received in the signal handler, should be passed to this
13166 * function without modification.
13168 * The return value indicates whether there is a tree view row at the given
13169 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
13170 * tooltips the row returned will be the cursor row. When %TRUE, then any of
13171 * @model, @path and @iter which have been provided will be set to point to
13172 * that row and the corresponding model. @x and @y will always be converted
13173 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
13175 * Return value: whether or not the given tooltip context points to a row.
13180 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
13183 gboolean keyboard_tip,
13184 GtkTreeModel **model,
13185 GtkTreePath **path,
13188 GtkTreePath *tmppath = NULL;
13190 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
13191 g_return_val_if_fail (x != NULL, FALSE);
13192 g_return_val_if_fail (y != NULL, FALSE);
13196 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
13203 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
13206 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
13207 &tmppath, NULL, NULL, NULL))
13212 *model = pspp_sheet_view_get_model (tree_view);
13215 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
13221 gtk_tree_path_free (tmppath);
13227 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
13230 gboolean keyboard_tip,
13231 GtkTooltip *tooltip,
13234 GValue value = { 0, };
13235 GValue transformed = { 0, };
13238 GtkTreeModel *model;
13239 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
13241 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
13244 &model, &path, &iter))
13247 gtk_tree_model_get_value (model, &iter,
13248 tree_view->priv->tooltip_column, &value);
13250 g_value_init (&transformed, G_TYPE_STRING);
13252 if (!g_value_transform (&value, &transformed))
13254 g_value_unset (&value);
13255 gtk_tree_path_free (path);
13260 g_value_unset (&value);
13262 if (!g_value_get_string (&transformed))
13264 g_value_unset (&transformed);
13265 gtk_tree_path_free (path);
13270 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
13271 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
13273 gtk_tree_path_free (path);
13274 g_value_unset (&transformed);
13280 * pspp_sheet_view_set_tooltip_column:
13281 * @tree_view: a #PsppSheetView
13282 * @column: an integer, which is a valid column number for @tree_view's model
13284 * If you only plan to have simple (text-only) tooltips on full rows, you
13285 * can use this function to have #PsppSheetView handle these automatically
13286 * for you. @column should be set to the column in @tree_view's model
13287 * containing the tooltip texts, or -1 to disable this feature.
13289 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
13290 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
13292 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
13293 * so &, <, etc have to be escaped in the text.
13298 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
13301 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13303 if (column == tree_view->priv->tooltip_column)
13308 g_signal_handlers_disconnect_by_func (tree_view,
13309 pspp_sheet_view_set_tooltip_query_cb,
13311 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
13315 if (tree_view->priv->tooltip_column == -1)
13317 g_signal_connect (tree_view, "query-tooltip",
13318 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
13319 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
13323 tree_view->priv->tooltip_column = column;
13324 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
13328 * pspp_sheet_view_get_tooltip_column:
13329 * @tree_view: a #PsppSheetView
13331 * Returns the column of @tree_view's model which is being used for
13332 * displaying tooltips on @tree_view's rows.
13334 * Return value: the index of the tooltip column that is currently being
13335 * used, or -1 if this is disabled.
13340 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
13342 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
13344 return tree_view->priv->tooltip_column;
13348 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
13349 GValue *return_accu,
13350 const GValue *handler_return,
13353 gboolean continue_emission;
13354 gboolean signal_handled;
13356 signal_handled = g_value_get_boolean (handler_return);
13357 g_value_set_boolean (return_accu, signal_handled);
13358 continue_emission = !signal_handled;
13360 return continue_emission;
13365 pspp_sheet_view_grid_lines_get_type (void)
13367 static GType etype = 0;
13368 if (G_UNLIKELY(etype == 0)) {
13369 static const GEnumValue values[] = {
13370 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
13371 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
13372 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
13373 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
13376 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
13382 pspp_sheet_view_special_cells_get_type (void)
13384 static GType etype = 0;
13385 if (G_UNLIKELY(etype == 0)) {
13386 static const GEnumValue values[] = {
13387 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
13388 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
13389 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
13392 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);