1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011, 2012 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Library General Public
22 * License as published by the Free Software Foundation; either
23 * version 2 of the License, or (at your option) any later version.
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Library General Public License for more details.
30 * You should have received a copy of the GNU Library General Public
31 * License along with this library; if not, write to the
32 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
33 * Boston, MA 02111-1307, USA.
38 #include "ui/gui/pspp-sheet-private.h"
42 #include <gdk/gdkkeysyms.h>
45 #include "ui/gui/psppire-marshal.h"
46 #include "ui/gui/pspp-sheet-selection.h"
48 #define P_(STRING) STRING
49 #define GTK_PARAM_READABLE G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
50 #define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
52 /* Many keyboard shortcuts for Mac are the same as for X
53 * except they use Command key instead of Control (e.g. Cut,
54 * Copy, Paste). This symbol is for those simple cases. */
55 #ifndef GDK_WINDOWING_QUARTZ
56 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_CONTROL_MASK
58 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_META_MASK
61 #define PSPP_SHEET_VIEW_PRIORITY_VALIDATE (GDK_PRIORITY_REDRAW + 5)
62 #define PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC (PSPP_SHEET_VIEW_PRIORITY_VALIDATE + 2)
63 #define PSPP_SHEET_VIEW_TIME_MS_PER_IDLE 30
64 #define SCROLL_EDGE_SIZE 15
65 #define EXPANDER_EXTRA_PADDING 4
66 #define PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT 5000
68 /* The "background" areas of all rows/cells add up to cover the entire tree.
69 * The background includes all inter-row and inter-cell spacing.
70 * The "cell" areas are the cell_area passed in to gtk_cell_renderer_render(),
71 * i.e. just the cells, no spacing.
74 #define BACKGROUND_HEIGHT(tree_view) (tree_view->priv->fixed_height)
75 #define CELL_HEIGHT(tree_view, separator) ((BACKGROUND_HEIGHT (tree_view)) - (separator))
77 /* Translate from bin_window coordinates to rbtree (tree coordinates) and
80 #define TREE_WINDOW_Y_TO_RBTREE_Y(tree_view,y) ((y) + tree_view->priv->dy)
81 #define RBTREE_Y_TO_TREE_WINDOW_Y(tree_view,y) ((y) - tree_view->priv->dy)
83 /* This is in bin_window coordinates */
84 #define BACKGROUND_FIRST_PIXEL(tree_view,node) (RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, pspp_sheet_view_node_find_offset (tree_view, (node))))
85 #define CELL_FIRST_PIXEL(tree_view,node,separator) (BACKGROUND_FIRST_PIXEL (tree_view,node) + separator/2)
87 #define ROW_HEIGHT(tree_view) \
88 ((tree_view->priv->fixed_height > 0) ? (tree_view->priv->fixed_height) : (tree_view)->priv->expander_size)
91 typedef struct _PsppSheetViewChild PsppSheetViewChild;
92 struct _PsppSheetViewChild
102 typedef struct _TreeViewDragInfo TreeViewDragInfo;
103 struct _TreeViewDragInfo
105 GdkModifierType start_button_mask;
106 GtkTargetList *_unused_source_target_list;
107 GdkDragAction source_actions;
109 GtkTargetList *_unused_dest_target_list;
111 guint source_set : 1;
127 START_INTERACTIVE_SEARCH,
137 PROP_HEADERS_VISIBLE,
138 PROP_HEADERS_CLICKABLE,
143 PROP_HOVER_SELECTION,
145 PROP_ENABLE_GRID_LINES,
149 PROP_FIXED_HEIGHT_SET
153 static void pspp_sheet_view_finalize (GObject *object);
154 static void pspp_sheet_view_set_property (GObject *object,
158 static void pspp_sheet_view_get_property (GObject *object,
163 /* gtkobject signals */
164 static void pspp_sheet_view_destroy (GtkObject *object);
166 /* gtkwidget signals */
167 static void pspp_sheet_view_realize (GtkWidget *widget);
168 static void pspp_sheet_view_unrealize (GtkWidget *widget);
169 static void pspp_sheet_view_map (GtkWidget *widget);
170 static void pspp_sheet_view_size_request (GtkWidget *widget,
171 GtkRequisition *requisition);
172 static void pspp_sheet_view_size_allocate (GtkWidget *widget,
173 GtkAllocation *allocation);
174 static gboolean pspp_sheet_view_expose (GtkWidget *widget,
175 GdkEventExpose *event);
176 static gboolean pspp_sheet_view_key_press (GtkWidget *widget,
178 static gboolean pspp_sheet_view_key_release (GtkWidget *widget,
180 static gboolean pspp_sheet_view_motion (GtkWidget *widget,
181 GdkEventMotion *event);
182 static gboolean pspp_sheet_view_enter_notify (GtkWidget *widget,
183 GdkEventCrossing *event);
184 static gboolean pspp_sheet_view_leave_notify (GtkWidget *widget,
185 GdkEventCrossing *event);
186 static gboolean pspp_sheet_view_button_press (GtkWidget *widget,
187 GdkEventButton *event);
188 static gboolean pspp_sheet_view_button_release (GtkWidget *widget,
189 GdkEventButton *event);
190 static gboolean pspp_sheet_view_grab_broken (GtkWidget *widget,
191 GdkEventGrabBroken *event);
193 static void pspp_sheet_view_set_focus_child (GtkContainer *container,
195 static gint pspp_sheet_view_focus_out (GtkWidget *widget,
196 GdkEventFocus *event);
197 static gint pspp_sheet_view_focus (GtkWidget *widget,
198 GtkDirectionType direction);
199 static void pspp_sheet_view_grab_focus (GtkWidget *widget);
200 static void pspp_sheet_view_style_set (GtkWidget *widget,
201 GtkStyle *previous_style);
202 static void pspp_sheet_view_grab_notify (GtkWidget *widget,
203 gboolean was_grabbed);
204 static void pspp_sheet_view_state_changed (GtkWidget *widget,
205 GtkStateType previous_state);
207 /* container signals */
208 static void pspp_sheet_view_remove (GtkContainer *container,
210 static void pspp_sheet_view_forall (GtkContainer *container,
211 gboolean include_internals,
212 GtkCallback callback,
213 gpointer callback_data);
215 /* Source side drag signals */
216 static void pspp_sheet_view_drag_begin (GtkWidget *widget,
217 GdkDragContext *context);
218 static void pspp_sheet_view_drag_end (GtkWidget *widget,
219 GdkDragContext *context);
220 static void pspp_sheet_view_drag_data_get (GtkWidget *widget,
221 GdkDragContext *context,
222 GtkSelectionData *selection_data,
225 static void pspp_sheet_view_drag_data_delete (GtkWidget *widget,
226 GdkDragContext *context);
228 /* Target side drag signals */
229 static void pspp_sheet_view_drag_leave (GtkWidget *widget,
230 GdkDragContext *context,
232 static gboolean pspp_sheet_view_drag_motion (GtkWidget *widget,
233 GdkDragContext *context,
237 static gboolean pspp_sheet_view_drag_drop (GtkWidget *widget,
238 GdkDragContext *context,
242 static void pspp_sheet_view_drag_data_received (GtkWidget *widget,
243 GdkDragContext *context,
246 GtkSelectionData *selection_data,
250 /* tree_model signals */
251 static void pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
253 GtkAdjustment *vadj);
254 static gboolean pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
255 GtkMovementStep step,
257 static gboolean pspp_sheet_view_real_select_all (PsppSheetView *tree_view);
258 static gboolean pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view);
259 static gboolean pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
260 gboolean start_editing);
261 static gboolean pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view);
262 static void pspp_sheet_view_row_changed (GtkTreeModel *model,
266 static void pspp_sheet_view_row_inserted (GtkTreeModel *model,
270 static void pspp_sheet_view_row_deleted (GtkTreeModel *model,
273 static void pspp_sheet_view_rows_reordered (GtkTreeModel *model,
279 /* Incremental reflow */
280 static gint validate_row (PsppSheetView *tree_view,
284 static void validate_visible_area (PsppSheetView *tree_view);
285 static gboolean validate_rows_handler (PsppSheetView *tree_view);
286 static gboolean presize_handler_callback (gpointer data);
287 static void install_presize_handler (PsppSheetView *tree_view);
288 static void install_scroll_sync_handler (PsppSheetView *tree_view);
289 static void pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
292 static void pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view);
293 static void pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view);
294 static void invalidate_empty_focus (PsppSheetView *tree_view);
296 /* Internal functions */
297 static void pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
300 gboolean add_shifted_binding,
301 GtkMovementStep step,
303 static void pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
305 const GdkRectangle *clip_rect);
306 static gint pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
309 static void pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
310 PsppSheetView *tree_view);
311 static void pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
313 static void pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
314 PsppSheetViewColumn *column,
315 gboolean focus_to_cell);
316 static gboolean pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
317 GdkEventMotion *event);
318 static void pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view);
319 static void pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
321 static void pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
323 static void pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
325 static void pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
327 static void pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
329 gboolean clear_and_select,
330 gboolean clamp_node);
331 static gboolean pspp_sheet_view_has_special_cell (PsppSheetView *tree_view);
332 static void pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view);
333 static void update_prelight (PsppSheetView *tree_view,
336 static void initialize_fixed_height_mode (PsppSheetView *tree_view);
338 /* interactive search */
339 static void pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view);
340 static void pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
341 PsppSheetView *tree_view);
342 static void pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
343 GtkWidget *search_dialog,
345 static void pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
348 static void pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
349 PsppSheetView *tree_view);
350 static void pspp_sheet_view_search_activate (GtkEntry *entry,
351 PsppSheetView *tree_view);
352 static gboolean pspp_sheet_view_real_search_enable_popdown(gpointer data);
353 static void pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
355 static gboolean pspp_sheet_view_search_delete_event (GtkWidget *widget,
357 PsppSheetView *tree_view);
358 static gboolean pspp_sheet_view_search_button_press_event (GtkWidget *widget,
359 GdkEventButton *event,
360 PsppSheetView *tree_view);
361 static gboolean pspp_sheet_view_search_scroll_event (GtkWidget *entry,
362 GdkEventScroll *event,
363 PsppSheetView *tree_view);
364 static gboolean pspp_sheet_view_search_key_press_event (GtkWidget *entry,
366 PsppSheetView *tree_view);
367 static gboolean pspp_sheet_view_search_move (GtkWidget *window,
368 PsppSheetView *tree_view,
370 static gboolean pspp_sheet_view_search_equal_func (GtkTreeModel *model,
374 gpointer search_data);
375 static gboolean pspp_sheet_view_search_iter (GtkTreeModel *model,
376 PsppSheetSelection *selection,
381 static void pspp_sheet_view_search_init (GtkWidget *entry,
382 PsppSheetView *tree_view);
383 static void pspp_sheet_view_put (PsppSheetView *tree_view,
384 GtkWidget *child_widget,
389 static gboolean pspp_sheet_view_start_editing (PsppSheetView *tree_view,
390 GtkTreePath *cursor_path);
391 static gboolean pspp_sheet_view_editable_button_press_event (GtkWidget *,
394 static void pspp_sheet_view_editable_clicked (GtkButton *, PsppSheetView *);
395 static void pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
396 PsppSheetViewColumn *column,
398 GtkCellEditable *cell_editable,
399 GdkRectangle *cell_area,
402 static gboolean pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
403 gboolean keybinding);
404 static gboolean pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view);
405 static PsppSheetViewColumn *pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
406 PsppSheetViewColumn *column,
409 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
410 PsppSheetViewColumn *column,
411 const GdkRectangle *background_area,
412 gboolean subtract_focus_rect,
413 GdkRectangle *cell_area);
414 static gint pspp_sheet_view_find_offset (PsppSheetView *tree_view,
419 static void pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
423 static void pspp_sheet_view_buildable_init (GtkBuildableIface *iface);
426 static gboolean scroll_row_timeout (gpointer data);
427 static void add_scroll_timeout (PsppSheetView *tree_view);
428 static void remove_scroll_timeout (PsppSheetView *tree_view);
430 static guint tree_view_signals [LAST_SIGNAL] = { 0 };
437 G_DEFINE_TYPE_WITH_CODE (PsppSheetView, pspp_sheet_view, GTK_TYPE_CONTAINER,
438 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
439 pspp_sheet_view_buildable_init))
442 pspp_sheet_view_class_init (PsppSheetViewClass *class)
444 GObjectClass *o_class;
445 GtkObjectClass *object_class;
446 GtkWidgetClass *widget_class;
447 GtkContainerClass *container_class;
448 GtkBindingSet *binding_set;
450 binding_set = gtk_binding_set_by_class (class);
452 o_class = (GObjectClass *) class;
453 object_class = (GtkObjectClass *) class;
454 widget_class = (GtkWidgetClass *) class;
455 container_class = (GtkContainerClass *) class;
457 /* GObject signals */
458 o_class->set_property = pspp_sheet_view_set_property;
459 o_class->get_property = pspp_sheet_view_get_property;
460 o_class->finalize = pspp_sheet_view_finalize;
462 /* GtkObject signals */
463 object_class->destroy = pspp_sheet_view_destroy;
465 /* GtkWidget signals */
466 widget_class->map = pspp_sheet_view_map;
467 widget_class->realize = pspp_sheet_view_realize;
468 widget_class->unrealize = pspp_sheet_view_unrealize;
469 widget_class->size_request = pspp_sheet_view_size_request;
470 widget_class->size_allocate = pspp_sheet_view_size_allocate;
471 widget_class->button_press_event = pspp_sheet_view_button_press;
472 widget_class->button_release_event = pspp_sheet_view_button_release;
473 widget_class->grab_broken_event = pspp_sheet_view_grab_broken;
474 /*widget_class->configure_event = pspp_sheet_view_configure;*/
475 widget_class->motion_notify_event = pspp_sheet_view_motion;
476 widget_class->expose_event = pspp_sheet_view_expose;
477 widget_class->key_press_event = pspp_sheet_view_key_press;
478 widget_class->key_release_event = pspp_sheet_view_key_release;
479 widget_class->enter_notify_event = pspp_sheet_view_enter_notify;
480 widget_class->leave_notify_event = pspp_sheet_view_leave_notify;
481 widget_class->focus_out_event = pspp_sheet_view_focus_out;
482 widget_class->drag_begin = pspp_sheet_view_drag_begin;
483 widget_class->drag_end = pspp_sheet_view_drag_end;
484 widget_class->drag_data_get = pspp_sheet_view_drag_data_get;
485 widget_class->drag_data_delete = pspp_sheet_view_drag_data_delete;
486 widget_class->drag_leave = pspp_sheet_view_drag_leave;
487 widget_class->drag_motion = pspp_sheet_view_drag_motion;
488 widget_class->drag_drop = pspp_sheet_view_drag_drop;
489 widget_class->drag_data_received = pspp_sheet_view_drag_data_received;
490 widget_class->focus = pspp_sheet_view_focus;
491 widget_class->grab_focus = pspp_sheet_view_grab_focus;
492 widget_class->style_set = pspp_sheet_view_style_set;
493 widget_class->grab_notify = pspp_sheet_view_grab_notify;
494 widget_class->state_changed = pspp_sheet_view_state_changed;
496 /* GtkContainer signals */
497 container_class->remove = pspp_sheet_view_remove;
498 container_class->forall = pspp_sheet_view_forall;
499 container_class->set_focus_child = pspp_sheet_view_set_focus_child;
501 class->set_scroll_adjustments = pspp_sheet_view_set_adjustments;
502 class->move_cursor = pspp_sheet_view_real_move_cursor;
503 class->select_all = pspp_sheet_view_real_select_all;
504 class->unselect_all = pspp_sheet_view_real_unselect_all;
505 class->select_cursor_row = pspp_sheet_view_real_select_cursor_row;
506 class->toggle_cursor_row = pspp_sheet_view_real_toggle_cursor_row;
507 class->start_interactive_search = pspp_sheet_view_start_interactive_search;
511 g_object_class_install_property (o_class,
513 g_param_spec_object ("model",
514 P_("TreeView Model"),
515 P_("The model for the tree view"),
517 GTK_PARAM_READWRITE));
519 g_object_class_install_property (o_class,
521 g_param_spec_object ("hadjustment",
522 P_("Horizontal Adjustment"),
523 P_("Horizontal Adjustment for the widget"),
525 GTK_PARAM_READWRITE));
527 g_object_class_install_property (o_class,
529 g_param_spec_object ("vadjustment",
530 P_("Vertical Adjustment"),
531 P_("Vertical Adjustment for the widget"),
533 GTK_PARAM_READWRITE));
535 g_object_class_install_property (o_class,
536 PROP_HEADERS_VISIBLE,
537 g_param_spec_boolean ("headers-visible",
538 P_("Headers Visible"),
539 P_("Show the column header buttons"),
541 GTK_PARAM_READWRITE));
543 g_object_class_install_property (o_class,
544 PROP_HEADERS_CLICKABLE,
545 g_param_spec_boolean ("headers-clickable",
546 P_("Headers Clickable"),
547 P_("Column headers respond to click events"),
549 GTK_PARAM_READWRITE));
551 g_object_class_install_property (o_class,
553 g_param_spec_boolean ("reorderable",
555 P_("View is reorderable"),
557 GTK_PARAM_READWRITE));
559 g_object_class_install_property (o_class,
561 g_param_spec_boolean ("rules-hint",
563 P_("Set a hint to the theme engine to draw rows in alternating colors"),
565 GTK_PARAM_READWRITE));
567 g_object_class_install_property (o_class,
569 g_param_spec_boolean ("enable-search",
571 P_("View allows user to search through columns interactively"),
573 GTK_PARAM_READWRITE));
575 g_object_class_install_property (o_class,
577 g_param_spec_int ("search-column",
579 P_("Model column to search through during interactive search"),
583 GTK_PARAM_READWRITE));
586 * PsppSheetView:hover-selection:
588 * Enables of disables the hover selection mode of @tree_view.
589 * Hover selection makes the selected row follow the pointer.
590 * Currently, this works only for the selection modes
591 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
593 * This mode is primarily intended for treeviews in popups, e.g.
594 * in #GtkComboBox or #GtkEntryCompletion.
598 g_object_class_install_property (o_class,
599 PROP_HOVER_SELECTION,
600 g_param_spec_boolean ("hover-selection",
601 P_("Hover Selection"),
602 P_("Whether the selection should follow the pointer"),
604 GTK_PARAM_READWRITE));
606 g_object_class_install_property (o_class,
608 g_param_spec_boolean ("rubber-banding",
609 P_("Rubber Banding"),
610 P_("Whether to enable selection of multiple items by dragging the mouse pointer"),
612 GTK_PARAM_READWRITE));
614 g_object_class_install_property (o_class,
615 PROP_ENABLE_GRID_LINES,
616 g_param_spec_enum ("enable-grid-lines",
617 P_("Enable Grid Lines"),
618 P_("Whether grid lines should be drawn in the tree view"),
619 PSPP_TYPE_SHEET_VIEW_GRID_LINES,
620 PSPP_SHEET_VIEW_GRID_LINES_NONE,
621 GTK_PARAM_READWRITE));
623 g_object_class_install_property (o_class,
625 g_param_spec_int ("tooltip-column",
626 P_("Tooltip Column"),
627 P_("The column in the model containing the tooltip texts for the rows"),
631 GTK_PARAM_READWRITE));
633 g_object_class_install_property (o_class,
635 g_param_spec_enum ("special-cells",
637 P_("Whether rows have special cells."),
638 PSPP_TYPE_SHEET_VIEW_SPECIAL_CELLS,
639 PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT,
640 GTK_PARAM_READWRITE));
642 g_object_class_install_property (o_class,
644 g_param_spec_int ("fixed-height",
646 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."),
650 GTK_PARAM_READWRITE));
652 g_object_class_install_property (o_class,
653 PROP_FIXED_HEIGHT_SET,
654 g_param_spec_boolean ("fixed-height-set",
655 P_("Fixed Height Set"),
656 P_("Whether fixed-height was set externally."),
658 GTK_PARAM_READWRITE));
660 /* Style properties */
661 #define _TREE_VIEW_EXPANDER_SIZE 12
662 #define _TREE_VIEW_VERTICAL_SEPARATOR 2
663 #define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
665 gtk_widget_class_install_style_property (widget_class,
666 g_param_spec_int ("expander-size",
668 P_("Size of the expander arrow"),
671 _TREE_VIEW_EXPANDER_SIZE,
672 GTK_PARAM_READABLE));
674 gtk_widget_class_install_style_property (widget_class,
675 g_param_spec_int ("vertical-separator",
676 P_("Vertical Separator Width"),
677 P_("Vertical space between cells. Must be an even number"),
680 _TREE_VIEW_VERTICAL_SEPARATOR,
681 GTK_PARAM_READABLE));
683 gtk_widget_class_install_style_property (widget_class,
684 g_param_spec_int ("horizontal-separator",
685 P_("Horizontal Separator Width"),
686 P_("Horizontal space between cells. Must be an even number"),
689 _TREE_VIEW_HORIZONTAL_SEPARATOR,
690 GTK_PARAM_READABLE));
692 gtk_widget_class_install_style_property (widget_class,
693 g_param_spec_boolean ("allow-rules",
695 P_("Allow drawing of alternating color rows"),
697 GTK_PARAM_READABLE));
699 gtk_widget_class_install_style_property (widget_class,
700 g_param_spec_boxed ("even-row-color",
701 P_("Even Row Color"),
702 P_("Color to use for even rows"),
704 GTK_PARAM_READABLE));
706 gtk_widget_class_install_style_property (widget_class,
707 g_param_spec_boxed ("odd-row-color",
709 P_("Color to use for odd rows"),
711 GTK_PARAM_READABLE));
713 gtk_widget_class_install_style_property (widget_class,
714 g_param_spec_boolean ("row-ending-details",
715 P_("Row Ending details"),
716 P_("Enable extended row background theming"),
718 GTK_PARAM_READABLE));
720 gtk_widget_class_install_style_property (widget_class,
721 g_param_spec_int ("grid-line-width",
722 P_("Grid line width"),
723 P_("Width, in pixels, of the tree view grid lines"),
725 GTK_PARAM_READABLE));
727 gtk_widget_class_install_style_property (widget_class,
728 g_param_spec_int ("tree-line-width",
729 P_("Tree line width"),
730 P_("Width, in pixels, of the tree view lines"),
732 GTK_PARAM_READABLE));
734 gtk_widget_class_install_style_property (widget_class,
735 g_param_spec_string ("tree-line-pattern",
736 P_("Tree line pattern"),
737 P_("Dash pattern used to draw the tree view lines"),
739 GTK_PARAM_READABLE));
743 * PsppSheetView::set-scroll-adjustments
744 * @horizontal: the horizontal #GtkAdjustment
745 * @vertical: the vertical #GtkAdjustment
747 * Set the scroll adjustments for the tree view. Usually scrolled containers
748 * like #GtkScrolledWindow will emit this signal to connect two instances
749 * of #GtkScrollbar to the scroll directions of the #PsppSheetView.
751 widget_class->set_scroll_adjustments_signal =
752 g_signal_new ("set-scroll-adjustments",
753 G_TYPE_FROM_CLASS (o_class),
754 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
755 G_STRUCT_OFFSET (PsppSheetViewClass, set_scroll_adjustments),
757 psppire_marshal_VOID__OBJECT_OBJECT,
760 GTK_TYPE_ADJUSTMENT);
763 * PsppSheetView::row-activated:
764 * @tree_view: the object on which the signal is emitted
765 * @path: the #GtkTreePath for the activated row
766 * @column: the #PsppSheetViewColumn in which the activation occurred
768 * The "row-activated" signal is emitted when the method
769 * pspp_sheet_view_row_activated() is called or the user double clicks
770 * a treeview row. It is also emitted when a non-editable row is
771 * selected and one of the keys: Space, Shift+Space, Return or
774 * For selection handling refer to the <link linkend="TreeWidget">tree
775 * widget conceptual overview</link> as well as #PsppSheetSelection.
777 tree_view_signals[ROW_ACTIVATED] =
778 g_signal_new ("row-activated",
779 G_TYPE_FROM_CLASS (o_class),
780 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
781 G_STRUCT_OFFSET (PsppSheetViewClass, row_activated),
783 psppire_marshal_VOID__BOXED_OBJECT,
786 PSPP_TYPE_SHEET_VIEW_COLUMN);
789 * PsppSheetView::columns-changed:
790 * @tree_view: the object on which the signal is emitted
792 * The number of columns of the treeview has changed.
794 tree_view_signals[COLUMNS_CHANGED] =
795 g_signal_new ("columns-changed",
796 G_TYPE_FROM_CLASS (o_class),
798 G_STRUCT_OFFSET (PsppSheetViewClass, columns_changed),
800 g_cclosure_marshal_VOID__VOID,
804 * PsppSheetView::cursor-changed:
805 * @tree_view: the object on which the signal is emitted
807 * The position of the cursor (focused cell) has changed.
809 tree_view_signals[CURSOR_CHANGED] =
810 g_signal_new ("cursor-changed",
811 G_TYPE_FROM_CLASS (o_class),
813 G_STRUCT_OFFSET (PsppSheetViewClass, cursor_changed),
815 g_cclosure_marshal_VOID__VOID,
818 tree_view_signals[MOVE_CURSOR] =
819 g_signal_new ("move-cursor",
820 G_TYPE_FROM_CLASS (object_class),
821 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
822 G_STRUCT_OFFSET (PsppSheetViewClass, move_cursor),
824 psppire_marshal_BOOLEAN__ENUM_INT,
826 GTK_TYPE_MOVEMENT_STEP,
829 tree_view_signals[SELECT_ALL] =
830 g_signal_new ("select-all",
831 G_TYPE_FROM_CLASS (object_class),
832 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
833 G_STRUCT_OFFSET (PsppSheetViewClass, select_all),
835 psppire_marshal_BOOLEAN__VOID,
838 tree_view_signals[UNSELECT_ALL] =
839 g_signal_new ("unselect-all",
840 G_TYPE_FROM_CLASS (object_class),
841 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
842 G_STRUCT_OFFSET (PsppSheetViewClass, unselect_all),
844 psppire_marshal_BOOLEAN__VOID,
847 tree_view_signals[SELECT_CURSOR_ROW] =
848 g_signal_new ("select-cursor-row",
849 G_TYPE_FROM_CLASS (object_class),
850 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
851 G_STRUCT_OFFSET (PsppSheetViewClass, select_cursor_row),
853 psppire_marshal_BOOLEAN__BOOLEAN,
857 tree_view_signals[TOGGLE_CURSOR_ROW] =
858 g_signal_new ("toggle-cursor-row",
859 G_TYPE_FROM_CLASS (object_class),
860 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
861 G_STRUCT_OFFSET (PsppSheetViewClass, toggle_cursor_row),
863 psppire_marshal_BOOLEAN__VOID,
866 tree_view_signals[START_INTERACTIVE_SEARCH] =
867 g_signal_new ("start-interactive-search",
868 G_TYPE_FROM_CLASS (object_class),
869 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
870 G_STRUCT_OFFSET (PsppSheetViewClass, start_interactive_search),
872 psppire_marshal_BOOLEAN__VOID,
876 pspp_sheet_view_add_move_binding (binding_set, GDK_Up, 0, TRUE,
877 GTK_MOVEMENT_DISPLAY_LINES, -1);
878 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_Up, 0, TRUE,
879 GTK_MOVEMENT_DISPLAY_LINES, -1);
881 pspp_sheet_view_add_move_binding (binding_set, GDK_Down, 0, TRUE,
882 GTK_MOVEMENT_DISPLAY_LINES, 1);
883 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_Down, 0, TRUE,
884 GTK_MOVEMENT_DISPLAY_LINES, 1);
886 pspp_sheet_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK, FALSE,
887 GTK_MOVEMENT_DISPLAY_LINES, -1);
889 pspp_sheet_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK, FALSE,
890 GTK_MOVEMENT_DISPLAY_LINES, 1);
892 pspp_sheet_view_add_move_binding (binding_set, GDK_Home, 0, TRUE,
893 GTK_MOVEMENT_BUFFER_ENDS, -1);
894 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_Home, 0, TRUE,
895 GTK_MOVEMENT_BUFFER_ENDS, -1);
897 pspp_sheet_view_add_move_binding (binding_set, GDK_End, 0, TRUE,
898 GTK_MOVEMENT_BUFFER_ENDS, 1);
899 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_End, 0, TRUE,
900 GTK_MOVEMENT_BUFFER_ENDS, 1);
902 pspp_sheet_view_add_move_binding (binding_set, GDK_Page_Up, 0, TRUE,
903 GTK_MOVEMENT_PAGES, -1);
904 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0, TRUE,
905 GTK_MOVEMENT_PAGES, -1);
907 pspp_sheet_view_add_move_binding (binding_set, GDK_Page_Down, 0, TRUE,
908 GTK_MOVEMENT_PAGES, 1);
909 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0, TRUE,
910 GTK_MOVEMENT_PAGES, 1);
913 gtk_binding_entry_add_signal (binding_set, GDK_Right, 0, "move-cursor", 2,
914 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
917 gtk_binding_entry_add_signal (binding_set, GDK_Left, 0, "move-cursor", 2,
918 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
921 gtk_binding_entry_add_signal (binding_set, GDK_KP_Right, 0, "move-cursor", 2,
922 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
925 gtk_binding_entry_add_signal (binding_set, GDK_KP_Left, 0, "move-cursor", 2,
926 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
929 gtk_binding_entry_add_signal (binding_set, GDK_Right, GDK_CONTROL_MASK,
931 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
934 gtk_binding_entry_add_signal (binding_set, GDK_Left, GDK_CONTROL_MASK,
936 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
939 gtk_binding_entry_add_signal (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
941 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
944 gtk_binding_entry_add_signal (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
946 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
949 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
950 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
952 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK, "select-all", 0);
953 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK, "select-all", 0);
955 gtk_binding_entry_add_signal (binding_set, GDK_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0);
956 gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK, "unselect-all", 0);
958 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_SHIFT_MASK, "select-cursor-row", 1,
959 G_TYPE_BOOLEAN, TRUE);
960 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", 1,
961 G_TYPE_BOOLEAN, TRUE);
963 gtk_binding_entry_add_signal (binding_set, GDK_space, 0, "select-cursor-row", 1,
964 G_TYPE_BOOLEAN, TRUE);
965 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0, "select-cursor-row", 1,
966 G_TYPE_BOOLEAN, TRUE);
967 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0, "select-cursor-row", 1,
968 G_TYPE_BOOLEAN, TRUE);
969 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0, "select-cursor-row", 1,
970 G_TYPE_BOOLEAN, TRUE);
971 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, "select-cursor-row", 1,
972 G_TYPE_BOOLEAN, TRUE);
974 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0, "select-cursor-parent", 0);
975 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", 0);
977 gtk_binding_entry_add_signal (binding_set, GDK_f, GDK_CONTROL_MASK, "start-interactive-search", 0);
979 gtk_binding_entry_add_signal (binding_set, GDK_F, GDK_CONTROL_MASK, "start-interactive-search", 0);
981 g_type_class_add_private (o_class, sizeof (PsppSheetViewPrivate));
985 pspp_sheet_view_buildable_init (GtkBuildableIface *iface)
987 iface->add_child = pspp_sheet_view_buildable_add_child;
991 pspp_sheet_view_init (PsppSheetView *tree_view)
993 tree_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (tree_view, PSPP_TYPE_SHEET_VIEW, PsppSheetViewPrivate);
995 gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
996 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (tree_view), FALSE);
998 tree_view->priv->flags = PSPP_SHEET_VIEW_DRAW_KEYFOCUS
999 | PSPP_SHEET_VIEW_HEADERS_VISIBLE;
1001 /* We need some padding */
1002 tree_view->priv->selected = range_tower_create ();
1003 tree_view->priv->dy = 0;
1004 tree_view->priv->cursor_offset = 0;
1005 tree_view->priv->n_columns = 0;
1006 tree_view->priv->header_height = 1;
1007 tree_view->priv->x_drag = 0;
1008 tree_view->priv->drag_pos = -1;
1009 tree_view->priv->header_has_focus = FALSE;
1010 tree_view->priv->pressed_button = -1;
1011 tree_view->priv->press_start_x = -1;
1012 tree_view->priv->press_start_y = -1;
1013 tree_view->priv->reorderable = FALSE;
1014 tree_view->priv->presize_handler_timer = 0;
1015 tree_view->priv->scroll_sync_timer = 0;
1016 tree_view->priv->fixed_height = -1;
1017 tree_view->priv->fixed_height_set = FALSE;
1018 pspp_sheet_view_set_adjustments (tree_view, NULL, NULL);
1019 tree_view->priv->selection = _pspp_sheet_selection_new_with_tree_view (tree_view);
1020 tree_view->priv->enable_search = TRUE;
1021 tree_view->priv->search_column = -1;
1022 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
1023 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
1024 tree_view->priv->search_custom_entry_set = FALSE;
1025 tree_view->priv->typeselect_flush_timeout = 0;
1026 tree_view->priv->init_hadjust_value = TRUE;
1027 tree_view->priv->width = 0;
1029 tree_view->priv->hover_selection = FALSE;
1031 tree_view->priv->rubber_banding_enable = FALSE;
1033 tree_view->priv->grid_lines = PSPP_SHEET_VIEW_GRID_LINES_NONE;
1035 tree_view->priv->tooltip_column = -1;
1037 tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT;
1039 tree_view->priv->post_validation_flag = FALSE;
1041 tree_view->priv->last_button_x = -1;
1042 tree_view->priv->last_button_y = -1;
1044 tree_view->priv->event_last_x = -10000;
1045 tree_view->priv->event_last_y = -10000;
1047 tree_view->priv->prelight_node = -1;
1048 tree_view->priv->rubber_band_start_node = -1;
1049 tree_view->priv->rubber_band_end_node = -1;
1051 tree_view->priv->anchor_column = NULL;
1053 tree_view->priv->button_style = NULL;
1062 pspp_sheet_view_set_property (GObject *object,
1064 const GValue *value,
1067 PsppSheetView *tree_view;
1069 tree_view = PSPP_SHEET_VIEW (object);
1074 pspp_sheet_view_set_model (tree_view, g_value_get_object (value));
1076 case PROP_HADJUSTMENT:
1077 pspp_sheet_view_set_hadjustment (tree_view, g_value_get_object (value));
1079 case PROP_VADJUSTMENT:
1080 pspp_sheet_view_set_vadjustment (tree_view, g_value_get_object (value));
1082 case PROP_HEADERS_VISIBLE:
1083 pspp_sheet_view_set_headers_visible (tree_view, g_value_get_boolean (value));
1085 case PROP_HEADERS_CLICKABLE:
1086 pspp_sheet_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
1088 case PROP_REORDERABLE:
1089 pspp_sheet_view_set_reorderable (tree_view, g_value_get_boolean (value));
1091 case PROP_RULES_HINT:
1092 pspp_sheet_view_set_rules_hint (tree_view, g_value_get_boolean (value));
1094 case PROP_ENABLE_SEARCH:
1095 pspp_sheet_view_set_enable_search (tree_view, g_value_get_boolean (value));
1097 case PROP_SEARCH_COLUMN:
1098 pspp_sheet_view_set_search_column (tree_view, g_value_get_int (value));
1100 case PROP_HOVER_SELECTION:
1101 tree_view->priv->hover_selection = g_value_get_boolean (value);
1103 case PROP_RUBBER_BANDING:
1104 tree_view->priv->rubber_banding_enable = g_value_get_boolean (value);
1106 case PROP_ENABLE_GRID_LINES:
1107 pspp_sheet_view_set_grid_lines (tree_view, g_value_get_enum (value));
1109 case PROP_TOOLTIP_COLUMN:
1110 pspp_sheet_view_set_tooltip_column (tree_view, g_value_get_int (value));
1112 case PROP_SPECIAL_CELLS:
1113 pspp_sheet_view_set_special_cells (tree_view, g_value_get_enum (value));
1115 case PROP_FIXED_HEIGHT:
1116 pspp_sheet_view_set_fixed_height (tree_view, g_value_get_int (value));
1118 case PROP_FIXED_HEIGHT_SET:
1119 if (g_value_get_boolean (value))
1121 if (!tree_view->priv->fixed_height_set
1122 && tree_view->priv->fixed_height >= 0)
1124 tree_view->priv->fixed_height_set = true;
1125 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1130 if (tree_view->priv->fixed_height_set)
1132 tree_view->priv->fixed_height_set = false;
1133 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1134 install_presize_handler (tree_view);
1139 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1145 pspp_sheet_view_get_property (GObject *object,
1150 PsppSheetView *tree_view;
1152 tree_view = PSPP_SHEET_VIEW (object);
1157 g_value_set_object (value, tree_view->priv->model);
1159 case PROP_HADJUSTMENT:
1160 g_value_set_object (value, tree_view->priv->hadjustment);
1162 case PROP_VADJUSTMENT:
1163 g_value_set_object (value, tree_view->priv->vadjustment);
1165 case PROP_HEADERS_VISIBLE:
1166 g_value_set_boolean (value, pspp_sheet_view_get_headers_visible (tree_view));
1168 case PROP_HEADERS_CLICKABLE:
1169 g_value_set_boolean (value, pspp_sheet_view_get_headers_clickable (tree_view));
1171 case PROP_REORDERABLE:
1172 g_value_set_boolean (value, tree_view->priv->reorderable);
1174 case PROP_RULES_HINT:
1175 g_value_set_boolean (value, tree_view->priv->has_rules);
1177 case PROP_ENABLE_SEARCH:
1178 g_value_set_boolean (value, tree_view->priv->enable_search);
1180 case PROP_SEARCH_COLUMN:
1181 g_value_set_int (value, tree_view->priv->search_column);
1183 case PROP_HOVER_SELECTION:
1184 g_value_set_boolean (value, tree_view->priv->hover_selection);
1186 case PROP_RUBBER_BANDING:
1187 g_value_set_boolean (value, tree_view->priv->rubber_banding_enable);
1189 case PROP_ENABLE_GRID_LINES:
1190 g_value_set_enum (value, tree_view->priv->grid_lines);
1192 case PROP_TOOLTIP_COLUMN:
1193 g_value_set_int (value, tree_view->priv->tooltip_column);
1195 case PROP_SPECIAL_CELLS:
1196 g_value_set_enum (value, tree_view->priv->special_cells);
1198 case PROP_FIXED_HEIGHT:
1199 g_value_set_int (value, pspp_sheet_view_get_fixed_height (tree_view));
1201 case PROP_FIXED_HEIGHT_SET:
1202 g_value_set_boolean (value, tree_view->priv->fixed_height_set);
1205 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1211 pspp_sheet_view_finalize (GObject *object)
1213 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->finalize (object);
1219 pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
1220 GtkBuilder *builder,
1224 pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), PSPP_SHEET_VIEW_COLUMN (child));
1227 /* GtkObject Methods
1231 pspp_sheet_view_destroy (GtkObject *object)
1233 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1236 pspp_sheet_view_stop_editing (tree_view, TRUE);
1238 if (tree_view->priv->selected != NULL)
1240 range_tower_destroy (tree_view->priv->selected);
1241 tree_view->priv->selected = NULL;
1244 if (tree_view->priv->columns != NULL)
1246 list = tree_view->priv->columns;
1249 PsppSheetViewColumn *column;
1250 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1252 pspp_sheet_view_remove_column (tree_view, column);
1254 tree_view->priv->columns = NULL;
1257 tree_view->priv->prelight_node = -1;
1259 if (tree_view->priv->selection != NULL)
1261 _pspp_sheet_selection_set_tree_view (tree_view->priv->selection, NULL);
1262 g_object_unref (tree_view->priv->selection);
1263 tree_view->priv->selection = NULL;
1266 if (tree_view->priv->scroll_to_path != NULL)
1268 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1269 tree_view->priv->scroll_to_path = NULL;
1272 if (tree_view->priv->drag_dest_row != NULL)
1274 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
1275 tree_view->priv->drag_dest_row = NULL;
1278 if (tree_view->priv->top_row != NULL)
1280 gtk_tree_row_reference_free (tree_view->priv->top_row);
1281 tree_view->priv->top_row = NULL;
1284 if (tree_view->priv->column_drop_func_data &&
1285 tree_view->priv->column_drop_func_data_destroy)
1287 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
1288 tree_view->priv->column_drop_func_data = NULL;
1291 if (tree_view->priv->destroy_count_destroy &&
1292 tree_view->priv->destroy_count_data)
1294 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
1295 tree_view->priv->destroy_count_data = NULL;
1298 gtk_tree_row_reference_free (tree_view->priv->cursor);
1299 tree_view->priv->cursor = NULL;
1301 gtk_tree_row_reference_free (tree_view->priv->anchor);
1302 tree_view->priv->anchor = NULL;
1304 /* destroy interactive search dialog */
1305 if (tree_view->priv->search_window)
1307 gtk_widget_destroy (tree_view->priv->search_window);
1308 tree_view->priv->search_window = NULL;
1309 tree_view->priv->search_entry = NULL;
1310 if (tree_view->priv->typeselect_flush_timeout)
1312 g_source_remove (tree_view->priv->typeselect_flush_timeout);
1313 tree_view->priv->typeselect_flush_timeout = 0;
1317 if (tree_view->priv->search_destroy && tree_view->priv->search_user_data)
1319 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
1320 tree_view->priv->search_user_data = NULL;
1323 if (tree_view->priv->search_position_destroy && tree_view->priv->search_position_user_data)
1325 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
1326 tree_view->priv->search_position_user_data = NULL;
1329 pspp_sheet_view_set_model (tree_view, NULL);
1331 if (tree_view->priv->hadjustment)
1333 g_object_unref (tree_view->priv->hadjustment);
1334 tree_view->priv->hadjustment = NULL;
1336 if (tree_view->priv->vadjustment)
1338 g_object_unref (tree_view->priv->vadjustment);
1339 tree_view->priv->vadjustment = NULL;
1342 if (tree_view->priv->button_style)
1344 g_object_unref (tree_view->priv->button_style);
1345 tree_view->priv->button_style = NULL;
1348 GTK_OBJECT_CLASS (pspp_sheet_view_parent_class)->destroy (object);
1353 /* GtkWidget Methods
1356 /* GtkWidget::map helper */
1358 pspp_sheet_view_map_buttons (PsppSheetView *tree_view)
1362 g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (tree_view)));
1364 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
1366 PsppSheetViewColumn *column;
1368 for (list = tree_view->priv->columns; list; list = list->next)
1370 column = list->data;
1371 if (column->button != NULL &&
1372 gtk_widget_get_visible (column->button) &&
1373 !gtk_widget_get_mapped (column->button))
1374 gtk_widget_map (column->button);
1376 for (list = tree_view->priv->columns; list; list = list->next)
1378 column = list->data;
1379 if (column->visible == FALSE || column->window == NULL)
1381 if (column->resizable)
1383 gdk_window_raise (column->window);
1384 gdk_window_show (column->window);
1387 gdk_window_hide (column->window);
1389 gdk_window_show (tree_view->priv->header_window);
1394 pspp_sheet_view_map (GtkWidget *widget)
1396 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1399 gtk_widget_set_mapped (widget, TRUE);
1401 tmp_list = tree_view->priv->children;
1404 PsppSheetViewChild *child = tmp_list->data;
1405 tmp_list = tmp_list->next;
1407 if (gtk_widget_get_visible (child->widget))
1409 if (!gtk_widget_get_mapped (child->widget))
1410 gtk_widget_map (child->widget);
1413 gdk_window_show (tree_view->priv->bin_window);
1415 pspp_sheet_view_map_buttons (tree_view);
1417 gdk_window_show (widget->window);
1421 pspp_sheet_view_realize (GtkWidget *widget)
1423 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1425 GdkWindowAttr attributes;
1426 gint attributes_mask;
1428 gtk_widget_set_realized (widget, TRUE);
1430 /* Make the main, clipping window */
1431 attributes.window_type = GDK_WINDOW_CHILD;
1432 attributes.x = widget->allocation.x;
1433 attributes.y = widget->allocation.y;
1434 attributes.width = widget->allocation.width;
1435 attributes.height = widget->allocation.height;
1436 attributes.wclass = GDK_INPUT_OUTPUT;
1437 attributes.visual = gtk_widget_get_visual (widget);
1438 attributes.colormap = gtk_widget_get_colormap (widget);
1439 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1441 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1443 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1444 &attributes, attributes_mask);
1445 gdk_window_set_user_data (widget->window, widget);
1447 /* Make the window for the tree */
1449 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1450 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1451 attributes.height = widget->allocation.height;
1452 attributes.event_mask = (GDK_EXPOSURE_MASK |
1454 GDK_POINTER_MOTION_MASK |
1455 GDK_ENTER_NOTIFY_MASK |
1456 GDK_LEAVE_NOTIFY_MASK |
1457 GDK_BUTTON_PRESS_MASK |
1458 GDK_BUTTON_RELEASE_MASK |
1459 gtk_widget_get_events (widget));
1461 tree_view->priv->bin_window = gdk_window_new (widget->window,
1462 &attributes, attributes_mask);
1463 gdk_window_set_user_data (tree_view->priv->bin_window, widget);
1465 /* Make the column header window */
1468 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1469 attributes.height = tree_view->priv->header_height;
1470 attributes.event_mask = (GDK_EXPOSURE_MASK |
1472 GDK_BUTTON_PRESS_MASK |
1473 GDK_BUTTON_RELEASE_MASK |
1474 GDK_KEY_PRESS_MASK |
1475 GDK_KEY_RELEASE_MASK |
1476 gtk_widget_get_events (widget));
1478 tree_view->priv->header_window = gdk_window_new (widget->window,
1479 &attributes, attributes_mask);
1480 gdk_window_set_user_data (tree_view->priv->header_window, widget);
1482 /* Add them all up. */
1483 widget->style = gtk_style_attach (widget->style, widget->window);
1484 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1485 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
1486 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
1488 tmp_list = tree_view->priv->children;
1491 PsppSheetViewChild *child = tmp_list->data;
1492 tmp_list = tmp_list->next;
1494 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1497 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1498 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1500 /* Need to call those here, since they create GCs */
1501 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1503 install_presize_handler (tree_view);
1507 pspp_sheet_view_unrealize (GtkWidget *widget)
1509 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1510 PsppSheetViewPrivate *priv = tree_view->priv;
1513 if (priv->scroll_timeout != 0)
1515 g_source_remove (priv->scroll_timeout);
1516 priv->scroll_timeout = 0;
1519 if (priv->open_dest_timeout != 0)
1521 g_source_remove (priv->open_dest_timeout);
1522 priv->open_dest_timeout = 0;
1525 if (priv->presize_handler_timer != 0)
1527 g_source_remove (priv->presize_handler_timer);
1528 priv->presize_handler_timer = 0;
1531 if (priv->validate_rows_timer != 0)
1533 g_source_remove (priv->validate_rows_timer);
1534 priv->validate_rows_timer = 0;
1537 if (priv->scroll_sync_timer != 0)
1539 g_source_remove (priv->scroll_sync_timer);
1540 priv->scroll_sync_timer = 0;
1543 if (priv->typeselect_flush_timeout)
1545 g_source_remove (priv->typeselect_flush_timeout);
1546 priv->typeselect_flush_timeout = 0;
1549 for (list = priv->columns; list; list = list->next)
1550 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1552 gdk_window_set_user_data (priv->bin_window, NULL);
1553 gdk_window_destroy (priv->bin_window);
1554 priv->bin_window = NULL;
1556 gdk_window_set_user_data (priv->header_window, NULL);
1557 gdk_window_destroy (priv->header_window);
1558 priv->header_window = NULL;
1560 if (priv->drag_window)
1562 gdk_window_set_user_data (priv->drag_window, NULL);
1563 gdk_window_destroy (priv->drag_window);
1564 priv->drag_window = NULL;
1567 if (priv->drag_highlight_window)
1569 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1570 gdk_window_destroy (priv->drag_highlight_window);
1571 priv->drag_highlight_window = NULL;
1574 if (priv->grid_line_gc)
1576 g_object_unref (priv->grid_line_gc);
1577 priv->grid_line_gc = NULL;
1580 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1583 /* GtkWidget::size_request helper */
1585 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1589 tree_view->priv->header_height = 0;
1591 if (tree_view->priv->model)
1593 for (list = tree_view->priv->columns; list; list = list->next)
1595 GtkRequisition requisition;
1596 PsppSheetViewColumn *column = list->data;
1598 pspp_sheet_view_column_size_request (column, &requisition);
1599 column->button_request = requisition.width;
1600 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1606 /* Called only by ::size_request */
1608 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1611 PsppSheetViewColumn *column;
1614 if (tree_view->priv->model == NULL)
1616 tree_view->priv->width = 0;
1617 tree_view->priv->prev_width = 0;
1618 tree_view->priv->height = 0;
1622 tree_view->priv->prev_width = tree_view->priv->width;
1623 tree_view->priv->width = 0;
1625 /* keep this in sync with size_allocate below */
1626 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1628 gint real_requested_width = 0;
1629 column = list->data;
1630 if (!column->visible)
1633 if (column->use_resized_width)
1635 real_requested_width = column->resized_width;
1639 real_requested_width = column->fixed_width;
1642 if (column->min_width != -1)
1643 real_requested_width = MAX (real_requested_width, column->min_width);
1644 if (column->max_width != -1)
1645 real_requested_width = MIN (real_requested_width, column->max_width);
1647 tree_view->priv->width += real_requested_width;
1650 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1654 pspp_sheet_view_size_request (GtkWidget *widget,
1655 GtkRequisition *requisition)
1657 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1660 /* we validate some rows initially just to make sure we have some size.
1661 * In practice, with a lot of static lists, this should get a good width.
1663 initialize_fixed_height_mode (tree_view);
1664 pspp_sheet_view_size_request_columns (tree_view);
1665 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1667 requisition->width = tree_view->priv->width;
1668 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1670 tmp_list = tree_view->priv->children;
1674 PsppSheetViewChild *child = tmp_list->data;
1675 GtkRequisition child_requisition;
1677 tmp_list = tmp_list->next;
1679 if (gtk_widget_get_visible (child->widget))
1680 gtk_widget_size_request (child->widget, &child_requisition);
1685 invalidate_column (PsppSheetView *tree_view,
1686 PsppSheetViewColumn *column)
1688 gint column_offset = 0;
1690 GtkWidget *widget = GTK_WIDGET (tree_view);
1693 if (!gtk_widget_get_realized (widget))
1696 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1697 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1699 list = (rtl ? list->prev : list->next))
1701 PsppSheetViewColumn *tmpcolumn = list->data;
1702 if (tmpcolumn == column)
1704 GdkRectangle invalid_rect;
1706 invalid_rect.x = column_offset;
1708 invalid_rect.width = column->width;
1709 invalid_rect.height = widget->allocation.height;
1711 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
1715 column_offset += tmpcolumn->width;
1720 invalidate_last_column (PsppSheetView *tree_view)
1725 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1727 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1729 last_column = (rtl ? last_column->next : last_column->prev))
1731 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1733 invalidate_column (tree_view, last_column->data);
1740 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1741 PsppSheetViewColumn *column)
1743 gint real_requested_width;
1745 if (column->use_resized_width)
1747 real_requested_width = column->resized_width;
1751 real_requested_width = column->fixed_width;
1754 if (column->min_width != -1)
1755 real_requested_width = MAX (real_requested_width, column->min_width);
1756 if (column->max_width != -1)
1757 real_requested_width = MIN (real_requested_width, column->max_width);
1759 return real_requested_width;
1763 span_intersects (int a0, int a_width,
1764 int b0, int b_width)
1766 int a1 = a0 + a_width;
1767 int b1 = b0 + b_width;
1768 return (a0 >= b0 && a0 < b1) || (b0 >= a0 && b0 < a1);
1771 /* GtkWidget::size_allocate helper */
1773 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1774 gboolean *width_changed)
1776 PsppSheetView *tree_view;
1777 GList *list, *first_column, *last_column;
1778 PsppSheetViewColumn *column;
1779 GtkAllocation allocation;
1781 gint extra, extra_per_column;
1782 gint full_requested_width = 0;
1783 gint number_of_expand_columns = 0;
1784 gboolean column_changed = FALSE;
1787 tree_view = PSPP_SHEET_VIEW (widget);
1789 for (last_column = g_list_last (tree_view->priv->columns);
1790 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1791 last_column = last_column->prev)
1793 if (last_column == NULL)
1796 for (first_column = g_list_first (tree_view->priv->columns);
1797 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1798 first_column = first_column->next)
1802 allocation.height = tree_view->priv->header_height;
1804 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1806 /* find out how many extra space and expandable columns we have */
1807 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1809 column = (PsppSheetViewColumn *)list->data;
1811 if (!column->visible)
1814 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1817 number_of_expand_columns++;
1820 extra = MAX (widget->allocation.width - full_requested_width, 0);
1821 if (number_of_expand_columns > 0)
1822 extra_per_column = extra/number_of_expand_columns;
1824 extra_per_column = 0;
1826 for (list = (rtl ? last_column : first_column);
1827 list != (rtl ? first_column->prev : last_column->next);
1828 list = (rtl ? list->prev : list->next))
1830 gint real_requested_width = 0;
1833 column = list->data;
1834 old_width = column->width;
1836 if (!column->visible)
1839 /* We need to handle the dragged button specially.
1841 if (column == tree_view->priv->drag_column)
1843 GtkAllocation drag_allocation;
1844 gdk_drawable_get_size (tree_view->priv->drag_window,
1845 &(drag_allocation.width),
1846 &(drag_allocation.height));
1847 drag_allocation.x = 0;
1848 drag_allocation.y = 0;
1849 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1851 width += drag_allocation.width;
1855 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1857 allocation.x = width;
1858 column->width = real_requested_width;
1862 if (number_of_expand_columns == 1)
1864 /* We add the remander to the last column as
1866 column->width += extra;
1870 column->width += extra_per_column;
1871 extra -= extra_per_column;
1872 number_of_expand_columns --;
1876 if (column->width != old_width)
1877 g_object_notify (G_OBJECT (column), "width");
1879 allocation.width = column->width;
1880 width += column->width;
1882 if (column->width > old_width)
1883 column_changed = TRUE;
1885 pspp_sheet_view_column_size_allocate (column, &allocation);
1887 if (span_intersects (allocation.x, allocation.width,
1888 tree_view->priv->hadjustment->value,
1889 widget->allocation.width)
1890 && gtk_widget_get_realized (widget))
1891 pspp_sheet_view_column_set_need_button (column, TRUE);
1894 gdk_window_move_resize (column->window,
1895 allocation.x + (rtl ? 0 : allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1897 TREE_VIEW_DRAG_WIDTH, allocation.height);
1900 /* We change the width here. The user might have been resizing columns,
1901 * so the total width of the tree view changes.
1903 tree_view->priv->width = width;
1905 *width_changed = TRUE;
1908 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
1913 pspp_sheet_view_size_allocate (GtkWidget *widget,
1914 GtkAllocation *allocation)
1916 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1918 gboolean width_changed = FALSE;
1919 gint old_width = widget->allocation.width;
1921 if (allocation->width != widget->allocation.width)
1922 width_changed = TRUE;
1924 widget->allocation = *allocation;
1926 tmp_list = tree_view->priv->children;
1930 GtkAllocation allocation;
1932 PsppSheetViewChild *child = tmp_list->data;
1933 tmp_list = tmp_list->next;
1935 /* totally ignore our child's requisition */
1936 allocation.x = child->x;
1937 allocation.y = child->y;
1938 allocation.width = child->width;
1939 allocation.height = child->height;
1940 gtk_widget_size_allocate (child->widget, &allocation);
1943 /* We size-allocate the columns first because the width of the
1944 * tree view (used in updating the adjustments below) might change.
1946 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
1948 tree_view->priv->hadjustment->page_size = allocation->width;
1949 tree_view->priv->hadjustment->page_increment = allocation->width * 0.9;
1950 tree_view->priv->hadjustment->step_increment = allocation->width * 0.1;
1951 tree_view->priv->hadjustment->lower = 0;
1952 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->page_size, tree_view->priv->width);
1954 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
1956 if (allocation->width < tree_view->priv->width)
1958 if (tree_view->priv->init_hadjust_value)
1960 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
1961 tree_view->priv->init_hadjust_value = FALSE;
1963 else if (allocation->width != old_width)
1965 tree_view->priv->hadjustment->value = CLAMP (tree_view->priv->hadjustment->value - allocation->width + old_width, 0, tree_view->priv->width - allocation->width);
1968 tree_view->priv->hadjustment->value = CLAMP (tree_view->priv->width - (tree_view->priv->prev_width - tree_view->priv->hadjustment->value), 0, tree_view->priv->width - allocation->width);
1972 tree_view->priv->hadjustment->value = 0;
1973 tree_view->priv->init_hadjust_value = TRUE;
1977 if (tree_view->priv->hadjustment->value + allocation->width > tree_view->priv->width)
1978 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
1980 gtk_adjustment_changed (tree_view->priv->hadjustment);
1982 tree_view->priv->vadjustment->page_size = allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view);
1983 tree_view->priv->vadjustment->step_increment = tree_view->priv->vadjustment->page_size * 0.1;
1984 tree_view->priv->vadjustment->page_increment = tree_view->priv->vadjustment->page_size * 0.9;
1985 tree_view->priv->vadjustment->lower = 0;
1986 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->page_size, tree_view->priv->height);
1988 gtk_adjustment_changed (tree_view->priv->vadjustment);
1990 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
1991 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
1992 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
1993 else if (tree_view->priv->vadjustment->value + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
1994 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
1995 tree_view->priv->height - tree_view->priv->vadjustment->page_size);
1996 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
1997 pspp_sheet_view_top_row_to_dy (tree_view);
1999 pspp_sheet_view_dy_to_top_row (tree_view);
2001 if (gtk_widget_get_realized (widget))
2003 gdk_window_move_resize (widget->window,
2004 allocation->x, allocation->y,
2005 allocation->width, allocation->height);
2006 gdk_window_move_resize (tree_view->priv->header_window,
2007 - (gint) tree_view->priv->hadjustment->value,
2009 MAX (tree_view->priv->width, allocation->width),
2010 tree_view->priv->header_height);
2011 gdk_window_move_resize (tree_view->priv->bin_window,
2012 - (gint) tree_view->priv->hadjustment->value,
2013 TREE_VIEW_HEADER_HEIGHT (tree_view),
2014 MAX (tree_view->priv->width, allocation->width),
2015 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2018 if (tree_view->priv->row_count == 0)
2019 invalidate_empty_focus (tree_view);
2021 if (gtk_widget_get_realized (widget))
2023 gboolean has_expand_column = FALSE;
2024 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2026 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2028 has_expand_column = TRUE;
2033 /* This little hack only works if we have an LTR locale, and no column has the */
2036 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2037 ! has_expand_column)
2038 invalidate_last_column (tree_view);
2040 gtk_widget_queue_draw (widget);
2045 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2047 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2049 GtkWidget *widget = GTK_WIDGET (tree_view);
2051 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2052 gtk_widget_grab_focus (widget);
2053 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2057 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2060 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2064 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2067 range_tower_set1 (tree_view->priv->selected, node, 1);
2071 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2074 range_tower_set0 (tree_view->priv->selected, node, 1);
2078 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2081 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2085 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2088 return node > 0 ? node - 1 : -1;
2092 all_columns_selected (PsppSheetView *tree_view)
2096 for (list = tree_view->priv->columns; list; list = list->next)
2098 PsppSheetViewColumn *column = list->data;
2099 if (column->selectable && !column->selected)
2107 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2109 PsppSheetViewColumn *column,
2110 GdkEventButton *event)
2112 PsppSheetSelection *selection;
2113 PsppSheetSelectionMode mode;
2115 gboolean update_anchor;
2119 g_return_val_if_fail (tree_view != NULL, FALSE);
2120 g_return_val_if_fail (column != NULL, FALSE);
2122 selection = tree_view->priv->selection;
2123 mode = pspp_sheet_selection_get_mode (selection);
2124 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2127 if (!column->row_head)
2132 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2133 if (event->type != GDK_BUTTON_PRESS
2134 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2140 path = gtk_tree_path_new_from_indices (node, -1);
2143 pspp_sheet_selection_unselect_all (selection);
2144 pspp_sheet_selection_select_path (selection, path);
2145 pspp_sheet_selection_select_all_columns (selection);
2146 update_anchor = TRUE;
2149 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2151 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2152 || !all_columns_selected (tree_view))
2154 pspp_sheet_selection_unselect_all (selection);
2155 pspp_sheet_selection_select_path (selection, path);
2156 pspp_sheet_selection_select_all_columns (selection);
2157 update_anchor = TRUE;
2161 update_anchor = handled = FALSE;
2163 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2164 && modifiers == GDK_CONTROL_MASK)
2166 if (!all_columns_selected (tree_view))
2168 pspp_sheet_selection_unselect_all (selection);
2169 pspp_sheet_selection_select_all_columns (selection);
2172 if (pspp_sheet_selection_path_is_selected (selection, path))
2173 pspp_sheet_selection_unselect_path (selection, path);
2175 pspp_sheet_selection_select_path (selection, path);
2176 update_anchor = TRUE;
2179 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2180 && modifiers == GDK_SHIFT_MASK)
2182 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2183 GtkTreePath *anchor_path;
2185 if (all_columns_selected (tree_view)
2186 && gtk_tree_row_reference_valid (anchor))
2188 update_anchor = FALSE;
2189 anchor_path = gtk_tree_row_reference_get_path (anchor);
2193 update_anchor = TRUE;
2194 anchor_path = gtk_tree_path_copy (path);
2197 pspp_sheet_selection_unselect_all (selection);
2198 pspp_sheet_selection_select_range (selection, anchor_path, path);
2199 pspp_sheet_selection_select_all_columns (selection);
2201 gtk_tree_path_free (anchor_path);
2206 update_anchor = handled = FALSE;
2210 if (tree_view->priv->anchor)
2211 gtk_tree_row_reference_free (tree_view->priv->anchor);
2212 tree_view->priv->anchor =
2213 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2214 tree_view->priv->model,
2218 gtk_tree_path_free (path);
2223 find_click (PsppSheetView *tree_view,
2226 PsppSheetViewColumn **column,
2227 GdkRectangle *background_area,
2228 GdkRectangle *cell_area)
2235 /* find the node that was clicked */
2236 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2239 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2244 background_area->y = y_offset + y;
2245 background_area->height = ROW_HEIGHT (tree_view);
2246 background_area->x = 0;
2248 /* Let the column have a chance at selecting it. */
2249 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2250 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2251 list; list = (rtl ? list->prev : list->next))
2253 PsppSheetViewColumn *candidate = list->data;
2255 if (!candidate->visible)
2258 background_area->width = candidate->width;
2259 if ((background_area->x > x) ||
2260 (background_area->x + background_area->width <= x))
2262 background_area->x += background_area->width;
2266 /* we found the focus column */
2268 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2270 *column = candidate;
2278 pspp_sheet_view_button_press (GtkWidget *widget,
2279 GdkEventButton *event)
2281 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2283 PsppSheetViewColumn *column = NULL;
2285 GdkRectangle background_area;
2286 GdkRectangle cell_area;
2289 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2290 pspp_sheet_view_stop_editing (tree_view, FALSE);
2293 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2294 * we're done handling the button press.
2297 if (event->window == tree_view->priv->bin_window)
2302 gint pre_val, aft_val;
2303 PsppSheetViewColumn *column = NULL;
2304 GtkCellRenderer *focus_cell = NULL;
2305 gboolean row_double_click = FALSE;
2306 gboolean node_selected;
2309 if (tree_view->priv->row_count == 0)
2311 grab_focus_and_unset_draw_keyfocus (tree_view);
2315 if (!find_click (tree_view, event->x, event->y, &node, &column,
2316 &background_area, &cell_area))
2318 grab_focus_and_unset_draw_keyfocus (tree_view);
2322 tree_view->priv->focus_column = column;
2324 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2328 node_selected = pspp_sheet_view_node_is_selected (tree_view, node);
2329 pre_val = tree_view->priv->vadjustment->value;
2331 path = _pspp_sheet_view_find_path (tree_view, node);
2333 /* we only handle selection modifications on the first button press
2335 if (event->type == GDK_BUTTON_PRESS)
2337 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2338 tree_view->priv->ctrl_pressed = TRUE;
2339 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2340 tree_view->priv->shift_pressed = TRUE;
2342 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2344 pspp_sheet_view_column_focus_cell (column, focus_cell);
2346 if (event->state & GDK_CONTROL_MASK)
2348 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
2349 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2351 else if (event->state & GDK_SHIFT_MASK)
2353 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
2354 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE);
2358 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
2361 if (tree_view->priv->anchor_column == NULL ||
2362 !(event->state & GDK_SHIFT_MASK))
2363 tree_view->priv->anchor_column = column;
2364 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2365 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2366 tree_view->priv->anchor_column,
2369 tree_view->priv->ctrl_pressed = FALSE;
2370 tree_view->priv->shift_pressed = FALSE;
2373 /* the treeview may have been scrolled because of _set_cursor,
2377 aft_val = tree_view->priv->vadjustment->value;
2378 dval = pre_val - aft_val;
2380 cell_area.y += dval;
2381 background_area.y += dval;
2383 /* Save press to possibly begin a drag
2385 if (!tree_view->priv->in_grab &&
2386 tree_view->priv->pressed_button < 0)
2388 tree_view->priv->pressed_button = event->button;
2389 tree_view->priv->press_start_x = event->x;
2390 tree_view->priv->press_start_y = event->y;
2391 tree_view->priv->press_start_node = node;
2393 if (tree_view->priv->rubber_banding_enable
2395 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2396 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2398 tree_view->priv->press_start_y += tree_view->priv->dy;
2399 tree_view->priv->rubber_band_x = event->x;
2400 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2401 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2403 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2404 tree_view->priv->rubber_band_ctrl = TRUE;
2405 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2406 tree_view->priv->rubber_band_shift = TRUE;
2411 /* Test if a double click happened on the same row. */
2412 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2414 int double_click_time, double_click_distance;
2416 g_object_get (gtk_settings_get_for_screen (
2417 gtk_widget_get_screen (widget)),
2418 "gtk-double-click-time", &double_click_time,
2419 "gtk-double-click-distance", &double_click_distance,
2422 /* Same conditions as _gdk_event_button_generate */
2423 if (tree_view->priv->last_button_x != -1 &&
2424 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2425 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2426 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2428 /* We do no longer compare paths of this row and the
2429 * row clicked previously. We use the double click
2430 * distance to decide whether this is a valid click,
2431 * allowing the mouse to slightly move over another row.
2433 row_double_click = TRUE;
2435 tree_view->priv->last_button_time = 0;
2436 tree_view->priv->last_button_x = -1;
2437 tree_view->priv->last_button_y = -1;
2441 tree_view->priv->last_button_time = event->time;
2442 tree_view->priv->last_button_x = event->x;
2443 tree_view->priv->last_button_y = event->y;
2447 if (row_double_click)
2449 gtk_grab_remove (widget);
2450 pspp_sheet_view_row_activated (tree_view, path, column);
2452 if (tree_view->priv->pressed_button == event->button)
2453 tree_view->priv->pressed_button = -1;
2456 gtk_tree_path_free (path);
2458 /* If we activated the row through a double click we don't want to grab
2459 * focus back, as moving focus to another widget is pretty common.
2461 if (!row_double_click)
2462 grab_focus_and_unset_draw_keyfocus (tree_view);
2467 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2469 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2471 column = list->data;
2472 if (event->window == column->window &&
2473 column->resizable &&
2478 if (gdk_pointer_grab (column->window, FALSE,
2479 GDK_POINTER_MOTION_HINT_MASK |
2480 GDK_BUTTON1_MOTION_MASK |
2481 GDK_BUTTON_RELEASE_MASK,
2482 NULL, NULL, event->time))
2485 gtk_grab_add (widget);
2486 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2487 column->resized_width = column->width;
2489 /* block attached dnd signal handler */
2490 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2492 g_signal_handlers_block_matched (widget,
2493 G_SIGNAL_MATCH_DATA,
2497 tree_view->priv->drag_pos = i;
2498 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2500 if (!gtk_widget_has_focus (widget))
2501 gtk_widget_grab_focus (widget);
2509 /* GtkWidget::button_release_event helper */
2511 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2512 GdkEventButton *event)
2514 PsppSheetView *tree_view;
2518 tree_view = PSPP_SHEET_VIEW (widget);
2520 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2521 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2522 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2524 /* Move the button back */
2525 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2527 g_object_ref (tree_view->priv->drag_column->button);
2528 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2529 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2530 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2531 g_object_unref (tree_view->priv->drag_column->button);
2532 gtk_widget_queue_resize (widget);
2533 if (tree_view->priv->drag_column->resizable)
2535 gdk_window_raise (tree_view->priv->drag_column->window);
2536 gdk_window_show (tree_view->priv->drag_column->window);
2539 gdk_window_hide (tree_view->priv->drag_column->window);
2541 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2545 if (tree_view->priv->cur_reorder &&
2546 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2547 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2548 tree_view->priv->cur_reorder->right_column);
2552 if (tree_view->priv->cur_reorder &&
2553 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2554 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2555 tree_view->priv->cur_reorder->left_column);
2557 tree_view->priv->drag_column = NULL;
2558 gdk_window_hide (tree_view->priv->drag_window);
2560 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2561 g_slice_free (PsppSheetViewColumnReorder, l->data);
2562 g_list_free (tree_view->priv->column_drag_info);
2563 tree_view->priv->column_drag_info = NULL;
2564 tree_view->priv->cur_reorder = NULL;
2566 if (tree_view->priv->drag_highlight_window)
2567 gdk_window_hide (tree_view->priv->drag_highlight_window);
2569 /* Reset our flags */
2570 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2571 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2576 /* GtkWidget::button_release_event helper */
2578 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2579 GdkEventButton *event)
2581 PsppSheetView *tree_view;
2584 tree_view = PSPP_SHEET_VIEW (widget);
2586 tree_view->priv->drag_pos = -1;
2588 /* unblock attached dnd signal handler */
2589 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2591 g_signal_handlers_unblock_matched (widget,
2592 G_SIGNAL_MATCH_DATA,
2596 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2597 gtk_grab_remove (widget);
2598 gdk_display_pointer_ungrab (gdk_drawable_get_display (event->window),
2604 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2605 GdkEventButton *event)
2607 GtkCellEditable *cell_editable;
2612 PsppSheetViewColumn *column;
2613 GdkRectangle background_area;
2614 GdkRectangle cell_area;
2620 if (event->window != tree_view->priv->bin_window)
2623 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2627 /* decide if we edit */
2628 path = _pspp_sheet_view_find_path (tree_view, node);
2629 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2630 if (event->button != 1 || modifiers)
2633 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2634 pspp_sheet_view_column_cell_set_cell_data (column,
2635 tree_view->priv->model,
2638 if (!pspp_sheet_view_column_get_quick_edit (column)
2639 && _pspp_sheet_view_column_has_editable_cell (column))
2642 flags = 0; /* FIXME: get the right flags */
2643 path_string = gtk_tree_path_to_string (path);
2645 if (!_pspp_sheet_view_column_cell_event (column,
2653 if (cell_editable == NULL)
2656 pspp_sheet_view_real_set_cursor (tree_view, path,
2658 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2661 _pspp_sheet_view_column_get_neighbor_sizes (
2662 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2665 area.width -= right + left;
2667 pspp_sheet_view_real_start_editing (tree_view,
2674 g_free (path_string);
2675 gtk_tree_path_free (path);
2680 pspp_sheet_view_button_release (GtkWidget *widget,
2681 GdkEventButton *event)
2683 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2685 pspp_sheet_view_stop_editing (tree_view, FALSE);
2686 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2687 && pspp_sheet_view_button_release_edit (tree_view, event))
2689 if (tree_view->priv->pressed_button == event->button)
2690 tree_view->priv->pressed_button = -1;
2692 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2696 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2697 return pspp_sheet_view_button_release_drag_column (widget, event);
2699 if (tree_view->priv->rubber_band_status)
2700 pspp_sheet_view_stop_rubber_band (tree_view);
2702 if (tree_view->priv->pressed_button == event->button)
2703 tree_view->priv->pressed_button = -1;
2705 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2706 return pspp_sheet_view_button_release_column_resize (widget, event);
2712 pspp_sheet_view_grab_broken (GtkWidget *widget,
2713 GdkEventGrabBroken *event)
2715 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2717 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2718 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2720 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2721 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2726 /* GtkWidget::motion_event function set.
2730 do_prelight (PsppSheetView *tree_view,
2732 /* these are in bin_window coords */
2736 int prev_node = tree_view->priv->prelight_node;
2738 if (prev_node != node)
2740 tree_view->priv->prelight_node = node;
2743 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2746 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2751 prelight_or_select (PsppSheetView *tree_view,
2753 /* these are in bin_window coords */
2757 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2759 if (tree_view->priv->hover_selection &&
2760 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2761 !(tree_view->priv->edited_column &&
2762 tree_view->priv->edited_column->editable_widget))
2766 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2770 path = _pspp_sheet_view_find_path (tree_view, node);
2771 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2772 if (pspp_sheet_view_node_is_selected (tree_view, node))
2774 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2775 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE);
2777 gtk_tree_path_free (path);
2781 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2782 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2785 do_prelight (tree_view, node, x, y);
2789 ensure_unprelighted (PsppSheetView *tree_view)
2791 do_prelight (tree_view,
2793 -1000, -1000); /* coords not possibly over an arrow */
2795 g_assert (tree_view->priv->prelight_node < 0);
2799 update_prelight (PsppSheetView *tree_view,
2806 if (tree_view->priv->row_count == 0)
2811 ensure_unprelighted (tree_view);
2815 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2819 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2822 prelight_or_select (tree_view, node, x, y);
2828 /* Our motion arrow is either a box (in the case of the original spot)
2829 * or an arrow. It is expander_size wide.
2852 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2854 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2855 GtkWidget *widget = GTK_WIDGET (tree_view);
2856 GdkBitmap *mask = NULL;
2861 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2862 GdkWindowAttr attributes;
2863 guint attributes_mask;
2866 reorder->left_column == tree_view->priv->drag_column ||
2867 reorder->right_column == tree_view->priv->drag_column)
2868 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2869 else if (reorder->left_column || reorder->right_column)
2871 GdkRectangle visible_rect;
2872 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2873 if (reorder->left_column)
2874 x = reorder->left_column->allocation.x + reorder->left_column->allocation.width;
2876 x = reorder->right_column->allocation.x;
2878 if (x < visible_rect.x)
2879 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2880 else if (x > visible_rect.x + visible_rect.width)
2881 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2883 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2886 /* We want to draw the rectangle over the initial location. */
2887 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2892 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2894 if (tree_view->priv->drag_highlight_window)
2896 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2898 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2901 attributes.window_type = GDK_WINDOW_CHILD;
2902 attributes.wclass = GDK_INPUT_OUTPUT;
2903 attributes.x = tree_view->priv->drag_column_x;
2905 width = attributes.width = tree_view->priv->drag_column->allocation.width;
2906 height = attributes.height = tree_view->priv->drag_column->allocation.height;
2907 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2908 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2909 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2910 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2911 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
2912 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2914 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2915 gc = gdk_gc_new (mask);
2917 gdk_gc_set_foreground (gc, &col);
2918 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2920 gdk_gc_set_foreground(gc, &col);
2921 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
2922 g_object_unref (gc);
2924 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
2926 if (mask) g_object_unref (mask);
2927 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2930 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
2936 width = tree_view->priv->expander_size;
2938 /* Get x, y, width, height of arrow */
2939 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
2940 if (reorder->left_column)
2942 x += reorder->left_column->allocation.x + reorder->left_column->allocation.width - width/2;
2943 height = reorder->left_column->allocation.height;
2947 x += reorder->right_column->allocation.x - width/2;
2948 height = reorder->right_column->allocation.height;
2950 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
2951 height += tree_view->priv->expander_size;
2953 /* Create the new window */
2954 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
2956 if (tree_view->priv->drag_highlight_window)
2958 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2960 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2963 attributes.window_type = GDK_WINDOW_TEMP;
2964 attributes.wclass = GDK_INPUT_OUTPUT;
2965 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2966 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2967 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2968 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2971 attributes.width = width;
2972 attributes.height = height;
2973 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
2974 &attributes, attributes_mask);
2975 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2977 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2978 gc = gdk_gc_new (mask);
2980 gdk_gc_set_foreground (gc, &col);
2981 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2983 /* Draw the 2 arrows as per above */
2985 gdk_gc_set_foreground (gc, &col);
2986 for (i = 0; i < width; i ++)
2988 if (i == (width/2 - 1))
2990 gdk_draw_line (mask, gc, i, j, i, height - j);
2991 if (i < (width/2 - 1))
2996 g_object_unref (gc);
2997 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
2999 if (mask) g_object_unref (mask);
3002 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
3003 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3005 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
3006 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3012 width = tree_view->priv->expander_size;
3014 /* Get x, y, width, height of arrow */
3015 width = width/2; /* remember, the arrow only takes half the available width */
3016 gdk_window_get_origin (widget->window, &x, &y);
3017 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3018 x += widget->allocation.width - width;
3020 if (reorder->left_column)
3021 height = reorder->left_column->allocation.height;
3023 height = reorder->right_column->allocation.height;
3025 y -= tree_view->priv->expander_size;
3026 height += 2*tree_view->priv->expander_size;
3028 /* Create the new window */
3029 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
3030 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3032 if (tree_view->priv->drag_highlight_window)
3034 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3036 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3039 attributes.window_type = GDK_WINDOW_TEMP;
3040 attributes.wclass = GDK_INPUT_OUTPUT;
3041 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3042 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3043 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3044 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3047 attributes.width = width;
3048 attributes.height = height;
3049 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3050 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3052 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3053 gc = gdk_gc_new (mask);
3055 gdk_gc_set_foreground (gc, &col);
3056 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3058 /* Draw the 2 arrows as per above */
3060 gdk_gc_set_foreground (gc, &col);
3061 j = tree_view->priv->expander_size;
3062 for (i = 0; i < width; i ++)
3065 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3069 gdk_draw_line (mask, gc, k, j, k, height - j);
3070 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3071 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3074 g_object_unref (gc);
3075 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3077 if (mask) g_object_unref (mask);
3080 tree_view->priv->drag_column_window_state = arrow_type;
3081 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3085 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3086 gdk_window_hide (tree_view->priv->drag_highlight_window);
3090 gdk_window_show (tree_view->priv->drag_highlight_window);
3091 gdk_window_raise (tree_view->priv->drag_highlight_window);
3095 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3096 GdkEventMotion *event)
3100 PsppSheetViewColumn *column;
3101 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3103 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3105 if (event->is_hint || event->window != widget->window)
3106 gtk_widget_get_pointer (widget, &x, NULL);
3110 if (tree_view->priv->hadjustment)
3111 x += tree_view->priv->hadjustment->value;
3113 new_width = pspp_sheet_view_new_column_width (tree_view,
3114 tree_view->priv->drag_pos, &x);
3115 if (x != tree_view->priv->x_drag &&
3116 (new_width != column->fixed_width))
3118 column->use_resized_width = TRUE;
3119 column->resized_width = new_width;
3122 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3124 gtk_widget_queue_resize (widget);
3132 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3134 PsppSheetViewColumnReorder *reorder = NULL;
3138 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3139 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3141 reorder = (PsppSheetViewColumnReorder *) list->data;
3142 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3147 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3150 tree_view->priv->cur_reorder = reorder;
3151 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3155 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3157 GdkRectangle visible_rect;
3162 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3163 y += tree_view->priv->dy;
3165 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3167 /* see if we are near the edge. */
3168 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3171 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3176 value = CLAMP (tree_view->priv->vadjustment->value + offset, 0.0,
3177 tree_view->priv->vadjustment->upper - tree_view->priv->vadjustment->page_size);
3178 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3182 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3184 GdkRectangle visible_rect;
3189 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3191 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3193 /* See if we are near the edge. */
3194 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3197 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3203 value = CLAMP (tree_view->priv->hadjustment->value + offset,
3204 0.0, tree_view->priv->hadjustment->upper - tree_view->priv->hadjustment->page_size);
3205 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3212 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3213 GdkEventMotion *event)
3215 PsppSheetView *tree_view = (PsppSheetView *) widget;
3216 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3220 if ((column == NULL) ||
3221 (event->window != tree_view->priv->drag_window))
3224 /* Handle moving the header */
3225 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3226 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3227 MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width) - column->allocation.width);
3228 gdk_window_move (tree_view->priv->drag_window, x, y);
3230 /* autoscroll, if needed */
3231 pspp_sheet_view_horizontal_autoscroll (tree_view);
3232 /* Update the current reorder position and arrow; */
3233 pspp_sheet_view_update_current_reorder (tree_view);
3239 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3241 remove_scroll_timeout (tree_view);
3242 gtk_grab_remove (GTK_WIDGET (tree_view));
3244 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3246 GtkTreePath *tmp_path;
3248 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3250 /* The anchor path should be set to the start path */
3251 tmp_path = _pspp_sheet_view_find_path (tree_view,
3252 tree_view->priv->rubber_band_start_node);
3254 if (tree_view->priv->anchor)
3255 gtk_tree_row_reference_free (tree_view->priv->anchor);
3257 tree_view->priv->anchor =
3258 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3259 tree_view->priv->model,
3262 gtk_tree_path_free (tmp_path);
3264 /* ... and the cursor to the end path */
3265 tmp_path = _pspp_sheet_view_find_path (tree_view,
3266 tree_view->priv->rubber_band_end_node);
3267 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE);
3268 gtk_tree_path_free (tmp_path);
3270 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3273 /* Clear status variables */
3274 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3275 tree_view->priv->rubber_band_shift = 0;
3276 tree_view->priv->rubber_band_ctrl = 0;
3278 tree_view->priv->rubber_band_start_node = -1;
3279 tree_view->priv->rubber_band_end_node = -1;
3283 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3287 gboolean skip_start,
3290 if (start_node == end_node)
3293 /* We skip the first node and jump inside the loop */
3299 /* Small optimization by assuming insensitive nodes are never
3304 if (tree_view->priv->rubber_band_shift)
3305 pspp_sheet_view_node_select (tree_view, start_node);
3306 else if (tree_view->priv->rubber_band_ctrl)
3308 /* Toggle the selection state */
3309 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3310 pspp_sheet_view_node_unselect (tree_view, start_node);
3312 pspp_sheet_view_node_select (tree_view, start_node);
3315 pspp_sheet_view_node_select (tree_view, start_node);
3319 /* Mirror the above */
3320 if (tree_view->priv->rubber_band_shift)
3321 pspp_sheet_view_node_unselect (tree_view, start_node);
3322 else if (tree_view->priv->rubber_band_ctrl)
3324 /* Toggle the selection state */
3325 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3326 pspp_sheet_view_node_unselect (tree_view, start_node);
3328 pspp_sheet_view_node_select (tree_view, start_node);
3331 pspp_sheet_view_node_unselect (tree_view, start_node);
3334 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3336 if (start_node == end_node)
3341 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3344 /* Ran out of tree */
3347 if (skip_end && start_node == end_node)
3354 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3357 return node * tree_view->priv->fixed_height;
3361 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3365 int fixed_height = tree_view->priv->fixed_height;
3366 if (fixed_height <= 0
3368 || height >= tree_view->priv->row_count * fixed_height)
3375 *new_node = height / fixed_height;
3376 return height % fixed_height;
3381 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3386 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3387 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3389 /* Handle the start area first */
3390 if (tree_view->priv->rubber_band_start_node < 0)
3392 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3399 else if (start_node < tree_view->priv->rubber_band_start_node)
3401 /* New node is above the old one; selection became bigger */
3402 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3404 tree_view->priv->rubber_band_start_node,
3409 else if (start_node > tree_view->priv->rubber_band_start_node)
3411 /* New node is below the old one; selection became smaller */
3412 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3413 tree_view->priv->rubber_band_start_node,
3420 tree_view->priv->rubber_band_start_node = start_node;
3422 /* Next, handle the end area */
3423 if (tree_view->priv->rubber_band_end_node < 0)
3425 /* In the event this happens, start_node was also -1; this case is
3429 else if (end_node < 0)
3431 /* Find the last node in the tree */
3432 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3435 /* Selection reached end of the tree */
3436 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3437 tree_view->priv->rubber_band_end_node,
3443 else if (end_node > tree_view->priv->rubber_band_end_node)
3445 /* New node is below the old one; selection became bigger */
3446 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3447 tree_view->priv->rubber_band_end_node,
3453 else if (end_node < tree_view->priv->rubber_band_end_node)
3455 /* New node is above the old one; selection became smaller */
3456 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3458 tree_view->priv->rubber_band_end_node,
3464 tree_view->priv->rubber_band_end_node = end_node;
3468 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3471 GdkRectangle old_area;
3472 GdkRectangle new_area;
3473 GdkRectangle common;
3474 GdkRegion *invalid_region;
3475 PsppSheetViewColumn *column;
3477 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3478 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3479 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3480 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3482 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3485 y = MAX (y, 0) + tree_view->priv->dy;
3487 new_area.x = MIN (tree_view->priv->press_start_x, x);
3488 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3489 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3490 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3492 invalid_region = gdk_region_rectangle (&old_area);
3493 gdk_region_union_with_rect (invalid_region, &new_area);
3495 gdk_rectangle_intersect (&old_area, &new_area, &common);
3496 if (common.width > 2 && common.height > 2)
3498 GdkRegion *common_region;
3500 /* make sure the border is invalidated */
3506 common_region = gdk_region_rectangle (&common);
3508 gdk_region_subtract (invalid_region, common_region);
3509 gdk_region_destroy (common_region);
3512 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3514 gdk_region_destroy (invalid_region);
3516 tree_view->priv->rubber_band_x = x;
3517 tree_view->priv->rubber_band_y = y;
3518 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3520 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3521 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3522 tree_view->priv->anchor_column,
3525 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3527 pspp_sheet_view_update_rubber_band_selection (tree_view);
3531 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3536 GdkRectangle rubber_rect;
3539 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3540 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3541 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3542 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3544 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3547 cr = gdk_cairo_create (tree_view->priv->bin_window);
3548 cairo_set_line_width (cr, 1.0);
3550 cairo_set_source_rgba (cr,
3551 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3552 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3553 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.,
3556 gdk_cairo_rectangle (cr, &rect);
3560 cairo_set_source_rgb (cr,
3561 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3562 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3563 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.);
3565 cairo_rectangle (cr,
3566 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3567 rubber_rect.width - 1, rubber_rect.height - 1);
3574 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3575 GdkEventMotion *event)
3577 PsppSheetView *tree_view;
3581 tree_view = (PsppSheetView *) widget;
3583 if (tree_view->priv->row_count == 0)
3586 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3588 GdkRectangle background_area, cell_area;
3589 PsppSheetViewColumn *column;
3591 if (find_click (tree_view, event->x, event->y, &node, &column,
3592 &background_area, &cell_area)
3593 && tree_view->priv->focus_column == column
3594 && tree_view->priv->press_start_node == node)
3597 gtk_grab_add (GTK_WIDGET (tree_view));
3598 pspp_sheet_view_update_rubber_band (tree_view);
3600 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3602 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3604 pspp_sheet_view_update_rubber_band (tree_view);
3606 add_scroll_timeout (tree_view);
3609 /* only check for an initiated drag when a button is pressed */
3610 if (tree_view->priv->pressed_button >= 0
3611 && !tree_view->priv->rubber_band_status)
3612 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3614 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3618 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3620 tree_view->priv->event_last_x = event->x;
3621 tree_view->priv->event_last_y = event->y;
3623 prelight_or_select (tree_view, node, event->x, event->y);
3629 pspp_sheet_view_motion (GtkWidget *widget,
3630 GdkEventMotion *event)
3632 PsppSheetView *tree_view;
3634 tree_view = (PsppSheetView *) widget;
3636 /* Resizing a column */
3637 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3638 return pspp_sheet_view_motion_resize_column (widget, event);
3641 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3642 return pspp_sheet_view_motion_drag_column (widget, event);
3644 /* Sanity check it */
3645 if (event->window == tree_view->priv->bin_window)
3646 return pspp_sheet_view_motion_bin_window (widget, event);
3651 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3652 * the tree is empty.
3655 invalidate_empty_focus (PsppSheetView *tree_view)
3659 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3664 gdk_drawable_get_size (tree_view->priv->bin_window, &area.width, &area.height);
3665 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3668 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3672 draw_empty_focus (PsppSheetView *tree_view, GdkRectangle *clip_area)
3674 GtkWidget *widget = GTK_WIDGET (tree_view);
3677 if (!gtk_widget_has_focus (widget))
3680 gdk_drawable_get_size (tree_view->priv->bin_window, &w, &h);
3686 gtk_paint_focus (gtk_widget_get_style (widget),
3687 tree_view->priv->bin_window,
3688 gtk_widget_get_state (widget),
3696 pspp_sheet_view_draw_grid_lines (PsppSheetView *tree_view,
3697 GdkEventExpose *event,
3698 gint n_visible_columns,
3702 GList *list = tree_view->priv->columns;
3707 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3708 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3711 gdk_drawable_get_size (event->window, NULL, &height);
3713 /* Only draw the lines for visible rows and columns */
3714 for (list = tree_view->priv->columns; list; list = list->next, i++)
3716 PsppSheetViewColumn *column = list->data;
3718 /* We don't want a line for the last column */
3719 if (i == n_visible_columns - 1)
3722 if (! column->visible)
3725 current_x += column->width;
3727 if (current_x - 1 >= event->area.x
3728 && current_x - 1 < event->area.x + event->area.width)
3729 gdk_draw_line (event->window,
3730 tree_view->priv->grid_line_gc,
3731 current_x - 1, min_y,
3732 current_x - 1, max_y - min_y);
3736 /* Warning: Very scary function.
3737 * Modify at your own risk
3739 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3740 * FIXME: It's not...
3743 pspp_sheet_view_bin_expose (GtkWidget *widget,
3744 GdkEventExpose *event)
3746 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3751 int drag_highlight = -1;
3754 gint y_offset, cell_offset;
3757 GdkRectangle background_area;
3758 GdkRectangle cell_area;
3760 gint bin_window_width;
3761 gint bin_window_height;
3762 GtkTreePath *cursor_path;
3763 GtkTreePath *drag_dest_path;
3764 GList *first_column, *last_column;
3765 gint vertical_separator;
3766 gint horizontal_separator;
3767 gint focus_line_width;
3768 gboolean allow_rules;
3769 gboolean has_special_cell;
3771 gint n_visible_columns;
3772 gint grid_line_width;
3773 gboolean row_ending_details;
3774 gboolean draw_vgrid_lines, draw_hgrid_lines;
3777 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3779 gtk_widget_style_get (widget,
3780 "horizontal-separator", &horizontal_separator,
3781 "vertical-separator", &vertical_separator,
3782 "allow-rules", &allow_rules,
3783 "focus-line-width", &focus_line_width,
3784 "row-ending-details", &row_ending_details,
3787 if (tree_view->priv->row_count == 0)
3789 draw_empty_focus (tree_view, &event->area);
3793 /* clip event->area to the visible area */
3794 if (event->area.height < 0)
3797 validate_visible_area (tree_view);
3799 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, event->area.y);
3803 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3804 gdk_drawable_get_size (tree_view->priv->bin_window,
3805 &bin_window_width, &bin_window_height);
3807 if (tree_view->priv->height < bin_window_height)
3809 gtk_paint_flat_box (widget->style,
3816 0, tree_view->priv->height,
3818 bin_window_height - tree_view->priv->height);
3824 /* find the path for the node */
3825 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3826 gtk_tree_model_get_iter (tree_view->priv->model,
3829 depth = gtk_tree_path_get_depth (path);
3830 gtk_tree_path_free (path);
3833 drag_dest_path = NULL;
3835 if (tree_view->priv->cursor)
3836 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3839 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3841 if (tree_view->priv->drag_dest_row)
3842 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3845 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3849 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3850 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3852 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3853 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3855 if (draw_vgrid_lines || draw_hgrid_lines)
3856 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3858 n_visible_columns = 0;
3859 for (list = tree_view->priv->columns; list; list = list->next)
3861 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3863 n_visible_columns ++;
3866 /* Find the last column */
3867 for (last_column = g_list_last (tree_view->priv->columns);
3868 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
3869 last_column = last_column->prev)
3873 for (first_column = g_list_first (tree_view->priv->columns);
3874 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
3875 first_column = first_column->next)
3878 /* Actually process the expose event. To do this, we want to
3879 * start at the first node of the event, and walk the tree in
3880 * order, drawing each successive node.
3887 gboolean is_first = FALSE;
3888 gboolean is_last = FALSE;
3889 gboolean done = FALSE;
3892 max_height = ROW_HEIGHT (tree_view);
3896 background_area.y = y_offset + event->area.y;
3897 background_area.height = max_height;
3898 max_y = background_area.y + max_height;
3902 if (node == tree_view->priv->prelight_node)
3903 flags |= GTK_CELL_RENDERER_PRELIT;
3905 selected = pspp_sheet_view_node_is_selected (tree_view, node);
3909 if (tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
3911 /* we *need* to set cell data on all cells before the call
3912 * to _has_special_cell, else _has_special_cell() does not
3913 * return a correct value.
3915 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3917 list = (rtl ? list->prev : list->next))
3919 PsppSheetViewColumn *column = list->data;
3920 pspp_sheet_view_column_cell_set_cell_data (column,
3921 tree_view->priv->model,
3925 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
3928 has_special_cell = tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
3930 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3932 list = (rtl ? list->prev : list->next))
3934 PsppSheetViewColumn *column = list->data;
3935 const gchar *detail = NULL;
3936 gboolean selected_column;
3939 if (!column->visible)
3942 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
3943 selected_column = column->selected && column->selectable;
3945 selected_column = TRUE;
3947 if (cell_offset > event->area.x + event->area.width ||
3948 cell_offset + column->width < event->area.x)
3950 cell_offset += column->width;
3954 if (selected && selected_column)
3955 flags |= GTK_CELL_RENDERER_SELECTED;
3957 flags &= ~GTK_CELL_RENDERER_SELECTED;
3959 if (column->show_sort_indicator)
3960 flags |= GTK_CELL_RENDERER_SORTED;
3962 flags &= ~GTK_CELL_RENDERER_SORTED;
3965 flags |= GTK_CELL_RENDERER_FOCUSED;
3967 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3969 background_area.x = cell_offset;
3970 background_area.width = column->width;
3972 cell_area = background_area;
3973 cell_area.y += vertical_separator / 2;
3974 cell_area.x += horizontal_separator / 2;
3975 cell_area.height -= vertical_separator;
3976 cell_area.width -= horizontal_separator;
3978 if (draw_vgrid_lines)
3980 if (list == first_column)
3982 cell_area.width -= grid_line_width / 2;
3984 else if (list == last_column)
3986 cell_area.x += grid_line_width / 2;
3987 cell_area.width -= grid_line_width / 2;
3991 cell_area.x += grid_line_width / 2;
3992 cell_area.width -= grid_line_width;
3996 if (draw_hgrid_lines)
3998 cell_area.y += grid_line_width / 2;
3999 cell_area.height -= grid_line_width;
4002 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
4004 cell_offset += column->width;
4008 pspp_sheet_view_column_cell_set_cell_data (column,
4009 tree_view->priv->model,
4012 /* Select the detail for drawing the cell. relevant
4013 * factors are parity, sortedness, and whether to
4016 if (allow_rules && tree_view->priv->has_rules)
4018 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4019 n_visible_columns >= 3)
4022 detail = "cell_odd_ruled_sorted";
4024 detail = "cell_even_ruled_sorted";
4029 detail = "cell_odd_ruled";
4031 detail = "cell_even_ruled";
4036 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4037 n_visible_columns >= 3)
4040 detail = "cell_odd_sorted";
4042 detail = "cell_even_sorted";
4047 detail = "cell_odd";
4049 detail = "cell_even";
4055 if (widget->state == GTK_STATE_INSENSITIVE)
4056 state = GTK_STATE_INSENSITIVE;
4057 else if (flags & GTK_CELL_RENDERER_SELECTED)
4058 state = GTK_STATE_SELECTED;
4060 state = GTK_STATE_NORMAL;
4062 /* Draw background */
4063 if (row_ending_details)
4065 char new_detail[128];
4067 is_first = (rtl ? !list->next : !list->prev);
4068 is_last = (rtl ? !list->prev : !list->next);
4070 /* (I don't like the snprintfs either, but couldn't find a
4073 if (is_first && is_last)
4074 g_snprintf (new_detail, 127, "%s", detail);
4076 g_snprintf (new_detail, 127, "%s_start", detail);
4078 g_snprintf (new_detail, 127, "%s_end", detail);
4080 g_snprintf (new_detail, 128, "%s_middle", detail);
4082 gtk_paint_flat_box (widget->style,
4091 background_area.width,
4092 background_area.height);
4096 gtk_paint_flat_box (widget->style,
4105 background_area.width,
4106 background_area.height);
4109 if (draw_hgrid_lines)
4111 if (background_area.y > 0)
4112 gdk_draw_line (event->window,
4113 tree_view->priv->grid_line_gc,
4114 background_area.x, background_area.y,
4115 background_area.x + background_area.width,
4118 if (y_offset + max_height >= event->area.height)
4119 gdk_draw_line (event->window,
4120 tree_view->priv->grid_line_gc,
4121 background_area.x, background_area.y + max_height,
4122 background_area.x + background_area.width,
4123 background_area.y + max_height);
4126 _pspp_sheet_view_column_cell_render (column,
4133 if (node == cursor && has_special_cell &&
4134 ((column == tree_view->priv->focus_column &&
4135 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4136 gtk_widget_has_focus (widget)) ||
4137 (column == tree_view->priv->edited_column)))
4139 _pspp_sheet_view_column_cell_draw_focus (column,
4147 cell_offset += column->width;
4150 if (cell_offset < event->area.x)
4152 gtk_paint_flat_box (widget->style,
4161 event->area.x - cell_offset,
4162 background_area.height);
4165 if (node == drag_highlight)
4167 /* Draw indicator for the drop
4169 gint highlight_y = -1;
4173 switch (tree_view->priv->drag_dest_pos)
4175 case PSPP_SHEET_VIEW_DROP_BEFORE:
4176 highlight_y = background_area.y - 1;
4177 if (highlight_y < 0)
4181 case PSPP_SHEET_VIEW_DROP_AFTER:
4182 highlight_y = background_area.y + background_area.height - 1;
4185 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4186 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4187 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4191 gdk_drawable_get_size (tree_view->priv->bin_window,
4194 if (row_ending_details)
4195 gtk_paint_focus (widget->style,
4196 tree_view->priv->bin_window,
4197 gtk_widget_get_state (widget),
4201 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4202 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4203 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4204 - focus_line_width / 2,
4205 width, ROW_HEIGHT (tree_view)
4206 - focus_line_width + 1);
4208 gtk_paint_focus (widget->style,
4209 tree_view->priv->bin_window,
4210 gtk_widget_get_state (widget),
4213 "treeview-drop-indicator",
4214 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4215 - focus_line_width / 2,
4216 width, ROW_HEIGHT (tree_view)
4217 - focus_line_width + 1);
4221 if (highlight_y >= 0)
4223 gdk_draw_line (event->window,
4224 widget->style->fg_gc[gtk_widget_get_state (widget)],
4227 rtl ? 0 : bin_window_width,
4232 /* draw the big row-spanning focus rectangle, if needed */
4233 if (!has_special_cell && node == cursor &&
4234 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4235 gtk_widget_has_focus (widget))
4237 gint tmp_y, tmp_height;
4239 GtkStateType focus_rect_state;
4242 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4243 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4244 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4247 gdk_drawable_get_size (tree_view->priv->bin_window,
4250 if (draw_hgrid_lines)
4252 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4253 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4257 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4258 tmp_height = ROW_HEIGHT (tree_view);
4261 if (row_ending_details)
4262 gtk_paint_focus (widget->style,
4263 tree_view->priv->bin_window,
4268 ? (is_last ? "treeview" : "treeview-left" )
4269 : (is_last ? "treeview-right" : "treeview-middle" )),
4273 gtk_paint_focus (widget->style,
4274 tree_view->priv->bin_window,
4283 y_offset += max_height;
4287 node = pspp_sheet_view_node_next (tree_view, node);
4290 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4294 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4301 while (y_offset < event->area.height);
4304 pspp_sheet_view_draw_grid_lines (tree_view, event, n_visible_columns,
4307 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4309 GdkRectangle *rectangles;
4312 gdk_region_get_rectangles (event->region,
4316 while (n_rectangles--)
4317 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4319 g_free (rectangles);
4323 gtk_tree_path_free (cursor_path);
4326 gtk_tree_path_free (drag_dest_path);
4332 pspp_sheet_view_expose (GtkWidget *widget,
4333 GdkEventExpose *event)
4335 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4337 if (event->window == tree_view->priv->bin_window)
4342 retval = pspp_sheet_view_bin_expose (widget, event);
4344 /* We can't just chain up to Container::expose as it will try to send the
4345 * event to the headers, so we handle propagating it to our children
4346 * (eg. widgets being edited) ourselves.
4348 tmp_list = tree_view->priv->children;
4351 PsppSheetViewChild *child = tmp_list->data;
4352 tmp_list = tmp_list->next;
4354 gtk_container_propagate_expose (GTK_CONTAINER (tree_view), child->widget, event);
4360 else if (event->window == tree_view->priv->header_window)
4362 gint n_visible_columns;
4365 gtk_paint_flat_box (widget->style,
4375 event->area.height);
4377 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4379 PsppSheetViewColumn *column = list->data;
4381 if (column == tree_view->priv->drag_column || !column->visible)
4384 if (span_intersects (column->allocation.x, column->allocation.width,
4385 event->area.x, event->area.width)
4386 && column->button != NULL)
4387 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4388 column->button, event);
4391 n_visible_columns = 0;
4392 for (list = tree_view->priv->columns; list; list = list->next)
4394 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4396 n_visible_columns ++;
4398 pspp_sheet_view_draw_grid_lines (tree_view,
4402 event->area.height);
4404 else if (event->window == tree_view->priv->drag_window)
4406 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4407 tree_view->priv->drag_column->button,
4421 /* returns 0x1 when no column has been found -- yes it's hackish */
4422 static PsppSheetViewColumn *
4423 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4424 PsppSheetViewColumn *column,
4427 PsppSheetViewColumn *left_column = NULL;
4428 PsppSheetViewColumn *cur_column = NULL;
4431 if (!column->reorderable)
4432 return (PsppSheetViewColumn *)0x1;
4434 switch (drop_position)
4437 /* find first column where we can drop */
4438 tmp_list = tree_view->priv->columns;
4439 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4440 return (PsppSheetViewColumn *)0x1;
4444 g_assert (tmp_list);
4446 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4447 tmp_list = tmp_list->next;
4449 if (left_column && left_column->visible == FALSE)
4452 if (!tree_view->priv->column_drop_func)
4455 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4457 left_column = cur_column;
4464 if (!tree_view->priv->column_drop_func)
4467 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4470 return (PsppSheetViewColumn *)0x1;
4474 /* find first column after column where we can drop */
4475 tmp_list = tree_view->priv->columns;
4477 for (; tmp_list; tmp_list = tmp_list->next)
4478 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4481 if (!tmp_list || !tmp_list->next)
4482 return (PsppSheetViewColumn *)0x1;
4484 tmp_list = tmp_list->next;
4485 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4486 tmp_list = tmp_list->next;
4490 g_assert (tmp_list);
4492 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4493 tmp_list = tmp_list->next;
4495 if (left_column && left_column->visible == FALSE)
4497 left_column = cur_column;
4499 tmp_list = tmp_list->next;
4503 if (!tree_view->priv->column_drop_func)
4506 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4508 left_column = cur_column;
4515 if (!tree_view->priv->column_drop_func)
4518 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4521 return (PsppSheetViewColumn *)0x1;
4525 /* find first column before column where we can drop */
4526 tmp_list = tree_view->priv->columns;
4528 for (; tmp_list; tmp_list = tmp_list->next)
4529 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4532 if (!tmp_list || !tmp_list->prev)
4533 return (PsppSheetViewColumn *)0x1;
4535 tmp_list = tmp_list->prev;
4536 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4537 tmp_list = tmp_list->prev;
4541 g_assert (tmp_list);
4543 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4545 if (left_column && !left_column->visible)
4547 /*if (!tmp_list->prev)
4548 return (PsppSheetViewColumn *)0x1;
4551 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4552 tmp_list = tmp_list->prev->prev;
4555 cur_column = left_column;
4557 tmp_list = tmp_list->prev;
4561 if (!tree_view->priv->column_drop_func)
4564 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4567 cur_column = left_column;
4568 tmp_list = tmp_list->prev;
4571 if (!tree_view->priv->column_drop_func)
4574 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4577 return (PsppSheetViewColumn *)0x1;
4581 /* same as DROP_HOME case, but doing it backwards */
4582 tmp_list = g_list_last (tree_view->priv->columns);
4585 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4586 return (PsppSheetViewColumn *)0x1;
4590 g_assert (tmp_list);
4592 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4594 if (left_column && !left_column->visible)
4596 cur_column = left_column;
4597 tmp_list = tmp_list->prev;
4600 if (!tree_view->priv->column_drop_func)
4603 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4606 cur_column = left_column;
4607 tmp_list = tmp_list->prev;
4610 if (!tree_view->priv->column_drop_func)
4613 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4616 return (PsppSheetViewColumn *)0x1;
4620 return (PsppSheetViewColumn *)0x1;
4624 pspp_sheet_view_key_press (GtkWidget *widget,
4627 PsppSheetView *tree_view = (PsppSheetView *) widget;
4629 if (tree_view->priv->rubber_band_status)
4631 if (event->keyval == GDK_Escape)
4632 pspp_sheet_view_stop_rubber_band (tree_view);
4637 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4639 if (event->keyval == GDK_Escape)
4641 tree_view->priv->cur_reorder = NULL;
4642 pspp_sheet_view_button_release_drag_column (widget, NULL);
4647 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4649 GList *focus_column;
4652 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4654 for (focus_column = tree_view->priv->columns;
4656 focus_column = focus_column->next)
4658 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4660 if (column->button && gtk_widget_has_focus (column->button))
4665 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4666 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4667 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4669 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4671 if (!column->resizable)
4673 gtk_widget_error_bell (widget);
4677 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4678 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4680 gint old_width = column->resized_width;
4682 column->resized_width = MAX (column->resized_width,
4684 column->resized_width -= 2;
4685 if (column->resized_width < 0)
4686 column->resized_width = 0;
4688 if (column->min_width == -1)
4689 column->resized_width = MAX (column->button_request,
4690 column->resized_width);
4692 column->resized_width = MAX (column->min_width,
4693 column->resized_width);
4695 if (column->max_width != -1)
4696 column->resized_width = MIN (column->resized_width,
4699 column->use_resized_width = TRUE;
4701 if (column->resized_width != old_width)
4702 gtk_widget_queue_resize (widget);
4704 gtk_widget_error_bell (widget);
4706 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4707 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4709 gint old_width = column->resized_width;
4711 column->resized_width = MAX (column->resized_width,
4713 column->resized_width += 2;
4715 if (column->max_width != -1)
4716 column->resized_width = MIN (column->resized_width,
4719 column->use_resized_width = TRUE;
4721 if (column->resized_width != old_width)
4722 gtk_widget_queue_resize (widget);
4724 gtk_widget_error_bell (widget);
4731 (event->state & GDK_MOD1_MASK) &&
4732 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4733 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4734 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4735 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4737 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4739 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4740 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4742 PsppSheetViewColumn *col;
4743 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4744 if (col != (PsppSheetViewColumn *)0x1)
4745 pspp_sheet_view_move_column_after (tree_view, column, col);
4747 gtk_widget_error_bell (widget);
4749 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4750 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4752 PsppSheetViewColumn *col;
4753 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4754 if (col != (PsppSheetViewColumn *)0x1)
4755 pspp_sheet_view_move_column_after (tree_view, column, col);
4757 gtk_widget_error_bell (widget);
4759 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4761 PsppSheetViewColumn *col;
4762 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4763 if (col != (PsppSheetViewColumn *)0x1)
4764 pspp_sheet_view_move_column_after (tree_view, column, col);
4766 gtk_widget_error_bell (widget);
4768 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4770 PsppSheetViewColumn *col;
4771 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4772 if (col != (PsppSheetViewColumn *)0x1)
4773 pspp_sheet_view_move_column_after (tree_view, column, col);
4775 gtk_widget_error_bell (widget);
4782 /* Chain up to the parent class. It handles the keybindings. */
4783 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4786 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4788 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4792 /* We pass the event to the search_entry. If its text changes, then we start
4793 * the typeahead find capabilities. */
4794 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4795 && tree_view->priv->enable_search
4796 && !tree_view->priv->search_custom_entry_set)
4798 GdkEvent *new_event;
4800 const char *new_text;
4803 gboolean text_modified;
4804 gulong popup_menu_id;
4806 pspp_sheet_view_ensure_interactive_directory (tree_view);
4808 /* Make a copy of the current text */
4809 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4810 new_event = gdk_event_copy ((GdkEvent *) event);
4811 g_object_unref (((GdkEventKey *) new_event)->window);
4812 ((GdkEventKey *) new_event)->window = g_object_ref (tree_view->priv->search_window->window);
4813 gtk_widget_realize (tree_view->priv->search_window);
4815 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4816 "popup-menu", G_CALLBACK (gtk_true),
4819 /* Move the entry off screen */
4820 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4821 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4822 gdk_screen_get_width (screen) + 1,
4823 gdk_screen_get_height (screen) + 1);
4824 gtk_widget_show (tree_view->priv->search_window);
4826 /* Send the event to the window. If the preedit_changed signal is emitted
4827 * during this event, we will set priv->imcontext_changed */
4828 tree_view->priv->imcontext_changed = FALSE;
4829 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4830 gdk_event_free (new_event);
4831 gtk_widget_hide (tree_view->priv->search_window);
4833 g_signal_handler_disconnect (tree_view->priv->search_entry,
4836 /* We check to make sure that the entry tried to handle the text, and that
4837 * the text has changed.
4839 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4840 text_modified = strcmp (old_text, new_text) != 0;
4842 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4843 (retval && text_modified)) /* ...or the text was modified */
4845 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4847 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4852 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
4862 pspp_sheet_view_key_release (GtkWidget *widget,
4865 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4867 if (tree_view->priv->rubber_band_status)
4870 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
4873 /* FIXME Is this function necessary? Can I get an enter_notify event
4874 * w/o either an expose event or a mouse motion event?
4877 pspp_sheet_view_enter_notify (GtkWidget *widget,
4878 GdkEventCrossing *event)
4880 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4884 /* Sanity check it */
4885 if (event->window != tree_view->priv->bin_window)
4888 if (tree_view->priv->row_count == 0)
4891 if (event->mode == GDK_CROSSING_GRAB ||
4892 event->mode == GDK_CROSSING_GTK_GRAB ||
4893 event->mode == GDK_CROSSING_GTK_UNGRAB ||
4894 event->mode == GDK_CROSSING_STATE_CHANGED)
4897 /* find the node internally */
4898 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
4901 pspp_sheet_view_find_offset (tree_view, new_y, &node);
4903 tree_view->priv->event_last_x = event->x;
4904 tree_view->priv->event_last_y = event->y;
4906 prelight_or_select (tree_view, node, event->x, event->y);
4912 pspp_sheet_view_leave_notify (GtkWidget *widget,
4913 GdkEventCrossing *event)
4915 PsppSheetView *tree_view;
4917 if (event->mode == GDK_CROSSING_GRAB)
4920 tree_view = PSPP_SHEET_VIEW (widget);
4922 if (tree_view->priv->prelight_node >= 0)
4923 _pspp_sheet_view_queue_draw_node (tree_view,
4924 tree_view->priv->prelight_node,
4927 tree_view->priv->event_last_x = -10000;
4928 tree_view->priv->event_last_y = -10000;
4930 prelight_or_select (tree_view,
4932 -1000, -1000); /* coords not possibly over an arrow */
4939 pspp_sheet_view_focus_out (GtkWidget *widget,
4940 GdkEventFocus *event)
4942 PsppSheetView *tree_view;
4944 tree_view = PSPP_SHEET_VIEW (widget);
4946 gtk_widget_queue_draw (widget);
4948 /* destroy interactive search dialog */
4949 if (tree_view->priv->search_window)
4950 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
4956 /* Incremental Reflow
4960 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
4965 y = pspp_sheet_view_node_find_offset (tree_view, node)
4966 - tree_view->priv->vadjustment->value
4967 + TREE_VIEW_HEADER_HEIGHT (tree_view);
4969 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
4971 GTK_WIDGET (tree_view)->allocation.width,
4972 tree_view->priv->fixed_height);
4976 node_is_visible (PsppSheetView *tree_view,
4982 y = pspp_sheet_view_node_find_offset (tree_view, node);
4983 height = ROW_HEIGHT (tree_view);
4985 if (y >= tree_view->priv->vadjustment->value &&
4986 y + height <= (tree_view->priv->vadjustment->value
4987 + tree_view->priv->vadjustment->page_size))
4993 /* Returns the row height. */
4995 validate_row (PsppSheetView *tree_view,
5000 PsppSheetViewColumn *column;
5001 GList *list, *first_column, *last_column;
5003 gint horizontal_separator;
5004 gint vertical_separator;
5005 gint focus_line_width;
5006 gboolean retval = FALSE;
5007 gboolean draw_vgrid_lines, draw_hgrid_lines;
5009 gint grid_line_width;
5010 gboolean wide_separators;
5011 gint separator_height;
5013 gtk_widget_style_get (GTK_WIDGET (tree_view),
5014 "focus-padding", &focus_pad,
5015 "focus-line-width", &focus_line_width,
5016 "horizontal-separator", &horizontal_separator,
5017 "vertical-separator", &vertical_separator,
5018 "grid-line-width", &grid_line_width,
5019 "wide-separators", &wide_separators,
5020 "separator-height", &separator_height,
5024 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5025 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5027 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5028 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5030 for (last_column = g_list_last (tree_view->priv->columns);
5031 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5032 last_column = last_column->prev)
5035 for (first_column = g_list_first (tree_view->priv->columns);
5036 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5037 first_column = first_column->next)
5040 for (list = tree_view->priv->columns; list; list = list->next)
5045 column = list->data;
5047 if (! column->visible)
5050 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5051 pspp_sheet_view_column_cell_get_size (column,
5053 &tmp_width, &tmp_height);
5055 tmp_height += vertical_separator;
5056 height = MAX (height, tmp_height);
5058 tmp_width = tmp_width + horizontal_separator;
5060 if (draw_vgrid_lines)
5062 if (list->data == first_column || list->data == last_column)
5063 tmp_width += grid_line_width / 2.0;
5065 tmp_width += grid_line_width;
5068 if (tmp_width > column->requested_width)
5071 column->requested_width = tmp_width;
5075 if (draw_hgrid_lines)
5076 height += grid_line_width;
5078 tree_view->priv->post_validation_flag = TRUE;
5084 validate_visible_area (PsppSheetView *tree_view)
5086 GtkTreePath *path = NULL;
5087 GtkTreePath *above_path = NULL;
5090 gboolean size_changed = FALSE;
5092 gint area_above = 0;
5093 gint area_below = 0;
5095 if (tree_view->priv->row_count == 0)
5098 if (tree_view->priv->scroll_to_path == NULL)
5101 total_height = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5103 if (total_height == 0)
5106 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5109 /* we are going to scroll, and will update dy */
5110 _pspp_sheet_view_find_node (tree_view, path, &node);
5111 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5113 if (tree_view->priv->scroll_to_use_align)
5115 gint height = ROW_HEIGHT (tree_view);
5116 area_above = (total_height - height) *
5117 tree_view->priv->scroll_to_row_align;
5118 area_below = total_height - area_above - height;
5119 area_above = MAX (area_above, 0);
5120 area_below = MAX (area_below, 0);
5125 * 1) row not visible
5129 gint height = ROW_HEIGHT (tree_view);
5131 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5133 if (dy >= tree_view->priv->vadjustment->value &&
5134 dy + height <= (tree_view->priv->vadjustment->value
5135 + tree_view->priv->vadjustment->page_size))
5137 /* row visible: keep the row at the same position */
5138 area_above = dy - tree_view->priv->vadjustment->value;
5139 area_below = (tree_view->priv->vadjustment->value +
5140 tree_view->priv->vadjustment->page_size)
5145 /* row not visible */
5147 && dy + height <= tree_view->priv->vadjustment->page_size)
5149 /* row at the beginning -- fixed */
5151 area_below = tree_view->priv->vadjustment->page_size
5152 - area_above - height;
5154 else if (dy >= (tree_view->priv->vadjustment->upper -
5155 tree_view->priv->vadjustment->page_size))
5157 /* row at the end -- fixed */
5158 area_above = dy - (tree_view->priv->vadjustment->upper -
5159 tree_view->priv->vadjustment->page_size);
5160 area_below = tree_view->priv->vadjustment->page_size -
5161 area_above - height;
5165 area_above = tree_view->priv->vadjustment->page_size - height;
5171 /* row somewhere in the middle, bring it to the top
5175 area_below = total_height - height;
5181 /* the scroll to isn't valid; ignore it.
5184 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5185 tree_view->priv->scroll_to_path = NULL;
5189 above_path = gtk_tree_path_copy (path);
5191 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5192 * backwards is much slower then forward, as there is no iter_prev function.
5193 * We go forwards first in case we run out of tree. Then we go backwards to
5196 while (node >= 0 && area_below > 0)
5198 gboolean done = FALSE;
5201 node = pspp_sheet_view_node_next (tree_view, node);
5204 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5206 gtk_tree_path_next (path);
5209 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5219 area_below -= ROW_HEIGHT (tree_view);
5221 gtk_tree_path_free (path);
5223 /* If we ran out of tree, and have extra area_below left, we need to add it
5226 area_above += area_below;
5228 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5230 /* We walk backwards */
5231 while (area_above > 0)
5233 node = pspp_sheet_view_node_prev (tree_view, node);
5235 /* Always find the new path in the tree. We cannot just assume
5236 * a gtk_tree_path_prev() is enough here, as there might be children
5237 * in between this node and the previous sibling node. If this
5238 * appears to be a performance hotspot in profiles, we can look into
5239 * intrigate logic for keeping path, node and iter in sync like
5240 * we do for forward walks. (Which will be hard because of the lacking
5247 gtk_tree_path_free (above_path);
5248 above_path = _pspp_sheet_view_find_path (tree_view, node);
5250 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5252 area_above -= ROW_HEIGHT (tree_view);
5255 /* set the dy here to scroll to the path,
5256 * and sync the top row accordingly
5258 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5259 pspp_sheet_view_top_row_to_dy (tree_view);
5261 /* update width/height and queue a resize */
5264 GtkRequisition requisition;
5266 /* We temporarily guess a size, under the assumption that it will be the
5267 * same when we get our next size_allocate. If we don't do this, we'll be
5268 * in an inconsistent state if we call top_row_to_dy. */
5270 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5271 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5272 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5273 gtk_adjustment_changed (tree_view->priv->hadjustment);
5274 gtk_adjustment_changed (tree_view->priv->vadjustment);
5275 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5278 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5279 tree_view->priv->scroll_to_path = NULL;
5282 gtk_tree_path_free (above_path);
5284 if (tree_view->priv->scroll_to_column)
5286 tree_view->priv->scroll_to_column = NULL;
5288 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5292 initialize_fixed_height_mode (PsppSheetView *tree_view)
5294 if (!tree_view->priv->row_count)
5297 if (tree_view->priv->fixed_height_set)
5300 if (tree_view->priv->fixed_height < 0)
5307 path = _pspp_sheet_view_find_path (tree_view, node);
5308 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5310 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5312 gtk_tree_path_free (path);
5314 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5318 /* Our strategy for finding nodes to validate is a little convoluted. We find
5319 * the left-most uninvalidated node. We then try walking right, validating
5320 * nodes. Once we find a valid node, we repeat the previous process of finding
5321 * the first invalid node.
5325 validate_rows_handler (PsppSheetView *tree_view)
5327 initialize_fixed_height_mode (tree_view);
5328 if (tree_view->priv->validate_rows_timer)
5330 g_source_remove (tree_view->priv->validate_rows_timer);
5331 tree_view->priv->validate_rows_timer = 0;
5338 do_presize_handler (PsppSheetView *tree_view)
5340 GtkRequisition requisition;
5342 validate_visible_area (tree_view);
5343 tree_view->priv->presize_handler_timer = 0;
5345 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5347 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5348 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5349 gtk_adjustment_changed (tree_view->priv->hadjustment);
5350 gtk_adjustment_changed (tree_view->priv->vadjustment);
5351 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5357 presize_handler_callback (gpointer data)
5359 do_presize_handler (PSPP_SHEET_VIEW (data));
5365 install_presize_handler (PsppSheetView *tree_view)
5367 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5370 if (! tree_view->priv->presize_handler_timer)
5372 tree_view->priv->presize_handler_timer =
5373 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5375 if (! tree_view->priv->validate_rows_timer)
5377 tree_view->priv->validate_rows_timer =
5378 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5383 scroll_sync_handler (PsppSheetView *tree_view)
5385 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
5386 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5387 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5388 pspp_sheet_view_top_row_to_dy (tree_view);
5390 pspp_sheet_view_dy_to_top_row (tree_view);
5392 tree_view->priv->scroll_sync_timer = 0;
5398 install_scroll_sync_handler (PsppSheetView *tree_view)
5400 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5403 if (!tree_view->priv->scroll_sync_timer)
5405 tree_view->priv->scroll_sync_timer =
5406 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5411 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5415 gtk_tree_row_reference_free (tree_view->priv->top_row);
5419 tree_view->priv->top_row = NULL;
5420 tree_view->priv->top_row_dy = 0;
5424 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5425 tree_view->priv->top_row_dy = offset;
5429 /* Always call this iff dy is in the visible range. If the tree is empty, then
5430 * it's set to be NULL, and top_row_dy is 0;
5433 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5439 if (tree_view->priv->row_count == 0)
5441 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5445 offset = pspp_sheet_view_find_offset (tree_view,
5446 tree_view->priv->dy,
5451 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5455 path = _pspp_sheet_view_find_path (tree_view, node);
5456 pspp_sheet_view_set_top_row (tree_view, path, offset);
5457 gtk_tree_path_free (path);
5463 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5469 /* Avoid recursive calls */
5470 if (tree_view->priv->in_top_row_to_dy)
5473 if (tree_view->priv->top_row)
5474 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5481 _pspp_sheet_view_find_node (tree_view, path, &node);
5484 gtk_tree_path_free (path);
5488 /* keep dy and set new toprow */
5489 gtk_tree_row_reference_free (tree_view->priv->top_row);
5490 tree_view->priv->top_row = NULL;
5491 tree_view->priv->top_row_dy = 0;
5492 /* DO NOT install the idle handler */
5493 pspp_sheet_view_dy_to_top_row (tree_view);
5497 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5499 /* new top row -- do NOT install the idle handler */
5500 pspp_sheet_view_dy_to_top_row (tree_view);
5504 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5505 new_dy += tree_view->priv->top_row_dy;
5507 if (new_dy + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
5508 new_dy = tree_view->priv->height - tree_view->priv->vadjustment->page_size;
5510 new_dy = MAX (0, new_dy);
5512 tree_view->priv->in_top_row_to_dy = TRUE;
5513 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5514 tree_view->priv->in_top_row_to_dy = FALSE;
5519 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5521 install_presize_handler (tree_view);
5527 set_source_row (GdkDragContext *context,
5528 GtkTreeModel *model,
5529 GtkTreePath *source_row)
5531 g_object_set_data_full (G_OBJECT (context),
5532 "gtk-tree-view-source-row",
5533 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5534 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5538 get_source_row (GdkDragContext *context)
5540 GtkTreeRowReference *ref =
5541 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5544 return gtk_tree_row_reference_get_path (ref);
5551 GtkTreeRowReference *dest_row;
5552 guint path_down_mode : 1;
5553 guint empty_view_drop : 1;
5554 guint drop_append_mode : 1;
5559 dest_row_free (gpointer data)
5561 DestRow *dr = (DestRow *)data;
5563 gtk_tree_row_reference_free (dr->dest_row);
5564 g_slice_free (DestRow, dr);
5568 set_dest_row (GdkDragContext *context,
5569 GtkTreeModel *model,
5570 GtkTreePath *dest_row,
5571 gboolean path_down_mode,
5572 gboolean empty_view_drop,
5573 gboolean drop_append_mode)
5579 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5584 dr = g_slice_new (DestRow);
5586 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5587 dr->path_down_mode = path_down_mode != FALSE;
5588 dr->empty_view_drop = empty_view_drop != FALSE;
5589 dr->drop_append_mode = drop_append_mode != FALSE;
5591 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5592 dr, (GDestroyNotify) dest_row_free);
5596 get_dest_row (GdkDragContext *context,
5597 gboolean *path_down_mode)
5600 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5604 GtkTreePath *path = NULL;
5607 *path_down_mode = dr->path_down_mode;
5610 path = gtk_tree_row_reference_get_path (dr->dest_row);
5611 else if (dr->empty_view_drop)
5612 path = gtk_tree_path_new_from_indices (0, -1);
5616 if (path && dr->drop_append_mode)
5617 gtk_tree_path_next (path);
5625 /* Get/set whether drag_motion requested the drag data and
5626 * drag_data_received should thus not actually insert the data,
5627 * since the data doesn't result from a drop.
5630 set_status_pending (GdkDragContext *context,
5631 GdkDragAction suggested_action)
5633 g_object_set_data (G_OBJECT (context),
5634 "gtk-tree-view-status-pending",
5635 GINT_TO_POINTER (suggested_action));
5638 static GdkDragAction
5639 get_status_pending (GdkDragContext *context)
5641 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5642 "gtk-tree-view-status-pending"));
5645 static TreeViewDragInfo*
5646 get_info (PsppSheetView *tree_view)
5648 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5652 destroy_info (TreeViewDragInfo *di)
5654 g_slice_free (TreeViewDragInfo, di);
5657 static TreeViewDragInfo*
5658 ensure_info (PsppSheetView *tree_view)
5660 TreeViewDragInfo *di;
5662 di = get_info (tree_view);
5666 di = g_slice_new0 (TreeViewDragInfo);
5668 g_object_set_data_full (G_OBJECT (tree_view),
5669 "gtk-tree-view-drag-info",
5671 (GDestroyNotify) destroy_info);
5678 remove_info (PsppSheetView *tree_view)
5680 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5685 drag_scan_timeout (gpointer data)
5687 PsppSheetView *tree_view;
5689 GdkModifierType state;
5690 GtkTreePath *path = NULL;
5691 PsppSheetViewColumn *column = NULL;
5692 GdkRectangle visible_rect;
5694 GDK_THREADS_ENTER ();
5696 tree_view = PSPP_SHEET_VIEW (data);
5698 gdk_window_get_pointer (tree_view->priv->bin_window,
5701 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5703 /* See if we are near the edge. */
5704 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5705 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5706 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5707 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5709 pspp_sheet_view_get_path_at_pos (tree_view,
5710 tree_view->priv->bin_window,
5719 pspp_sheet_view_scroll_to_cell (tree_view,
5725 gtk_tree_path_free (path);
5729 GDK_THREADS_LEAVE ();
5736 add_scroll_timeout (PsppSheetView *tree_view)
5738 if (tree_view->priv->scroll_timeout == 0)
5740 tree_view->priv->scroll_timeout =
5741 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5746 remove_scroll_timeout (PsppSheetView *tree_view)
5748 if (tree_view->priv->scroll_timeout != 0)
5750 g_source_remove (tree_view->priv->scroll_timeout);
5751 tree_view->priv->scroll_timeout = 0;
5756 check_model_dnd (GtkTreeModel *model,
5757 GType required_iface,
5758 const gchar *signal)
5760 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5762 g_warning ("You must override the default '%s' handler "
5763 "on PsppSheetView when using models that don't support "
5764 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5765 "is to connect to '%s' and call "
5766 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5767 "the default handler from running. Look at the source code "
5768 "for the default handler in gtktreeview.c to get an idea what "
5769 "your handler should do. (gtktreeview.c is in the GTK source "
5770 "code.) If you're using GTK from a language other than C, "
5771 "there may be a more natural way to override default handlers, e.g. via derivation.",
5772 signal, g_type_name (required_iface), signal);
5780 scroll_row_timeout (gpointer data)
5782 PsppSheetView *tree_view = data;
5784 pspp_sheet_view_horizontal_autoscroll (tree_view);
5785 pspp_sheet_view_vertical_autoscroll (tree_view);
5787 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5788 pspp_sheet_view_update_rubber_band (tree_view);
5793 /* Returns TRUE if event should not be propagated to parent widgets */
5795 set_destination_row (PsppSheetView *tree_view,
5796 GdkDragContext *context,
5797 /* coordinates relative to the widget */
5800 GdkDragAction *suggested_action,
5803 GtkTreePath *path = NULL;
5804 PsppSheetViewDropPosition pos;
5805 PsppSheetViewDropPosition old_pos;
5806 TreeViewDragInfo *di;
5808 GtkTreePath *old_dest_path = NULL;
5809 gboolean can_drop = FALSE;
5811 *suggested_action = 0;
5814 widget = GTK_WIDGET (tree_view);
5816 di = get_info (tree_view);
5818 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5820 /* someone unset us as a drag dest, note that if
5821 * we return FALSE drag_leave isn't called
5824 pspp_sheet_view_set_drag_dest_row (tree_view,
5826 PSPP_SHEET_VIEW_DROP_BEFORE);
5828 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5830 return FALSE; /* no longer a drop site */
5833 *target = gtk_drag_dest_find_target (widget, context,
5834 gtk_drag_dest_get_target_list (widget));
5835 if (*target == GDK_NONE)
5840 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5846 GtkTreeModel *model;
5848 /* the row got dropped on empty space, let's setup a special case
5852 gtk_tree_path_free (path);
5854 model = pspp_sheet_view_get_model (tree_view);
5856 n_children = gtk_tree_model_iter_n_children (model, NULL);
5859 pos = PSPP_SHEET_VIEW_DROP_AFTER;
5860 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5864 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
5865 path = gtk_tree_path_new_from_indices (0, -1);
5875 /* If we left the current row's "open" zone, unset the timeout for
5878 pspp_sheet_view_get_drag_dest_row (tree_view,
5883 gtk_tree_path_free (old_dest_path);
5885 if (TRUE /* FIXME if the location droppable predicate */)
5893 GtkWidget *source_widget;
5895 *suggested_action = context->suggested_action;
5896 source_widget = gtk_drag_get_source_widget (context);
5898 if (source_widget == widget)
5900 /* Default to MOVE, unless the user has
5901 * pressed ctrl or shift to affect available actions
5903 if ((context->actions & GDK_ACTION_MOVE) != 0)
5904 *suggested_action = GDK_ACTION_MOVE;
5907 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5912 /* can't drop here */
5913 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5915 PSPP_SHEET_VIEW_DROP_BEFORE);
5919 gtk_tree_path_free (path);
5925 get_logical_dest_row (PsppSheetView *tree_view,
5926 gboolean *path_down_mode,
5927 gboolean *drop_append_mode)
5929 /* adjust path to point to the row the drop goes in front of */
5930 GtkTreePath *path = NULL;
5931 PsppSheetViewDropPosition pos;
5933 g_return_val_if_fail (path_down_mode != NULL, NULL);
5934 g_return_val_if_fail (drop_append_mode != NULL, NULL);
5936 *path_down_mode = FALSE;
5937 *drop_append_mode = 0;
5939 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
5944 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
5946 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
5947 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
5948 *path_down_mode = TRUE;
5952 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
5954 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
5956 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5957 !gtk_tree_model_iter_next (model, &iter))
5958 *drop_append_mode = 1;
5961 *drop_append_mode = 0;
5962 gtk_tree_path_next (path);
5970 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
5971 GdkEventMotion *event)
5973 GtkWidget *widget = GTK_WIDGET (tree_view);
5974 GdkDragContext *context;
5975 TreeViewDragInfo *di;
5976 GtkTreePath *path = NULL;
5978 gint cell_x, cell_y;
5979 GtkTreeModel *model;
5980 gboolean retval = FALSE;
5982 di = get_info (tree_view);
5984 if (di == NULL || !di->source_set)
5987 if (tree_view->priv->pressed_button < 0)
5990 if (!gtk_drag_check_threshold (widget,
5991 tree_view->priv->press_start_x,
5992 tree_view->priv->press_start_y,
5993 event->x, event->y))
5996 model = pspp_sheet_view_get_model (tree_view);
6001 button = tree_view->priv->pressed_button;
6002 tree_view->priv->pressed_button = -1;
6004 pspp_sheet_view_get_path_at_pos (tree_view,
6005 tree_view->priv->press_start_x,
6006 tree_view->priv->press_start_y,
6015 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6016 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6020 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6023 /* Now we can begin the drag */
6027 context = gtk_drag_begin (widget,
6028 gtk_drag_source_get_target_list (widget),
6033 set_source_row (context, model, path);
6037 gtk_tree_path_free (path);
6044 pspp_sheet_view_drag_begin (GtkWidget *widget,
6045 GdkDragContext *context)
6047 PsppSheetView *tree_view;
6048 GtkTreePath *path = NULL;
6049 gint cell_x, cell_y;
6051 TreeViewDragInfo *di;
6053 tree_view = PSPP_SHEET_VIEW (widget);
6055 /* if the user uses a custom DND source impl, we don't set the icon here */
6056 di = get_info (tree_view);
6058 if (di == NULL || !di->source_set)
6061 pspp_sheet_view_get_path_at_pos (tree_view,
6062 tree_view->priv->press_start_x,
6063 tree_view->priv->press_start_y,
6069 g_return_if_fail (path != NULL);
6071 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6074 gtk_drag_set_icon_pixmap (context,
6075 gdk_drawable_get_colormap (row_pix),
6078 /* the + 1 is for the black border in the icon */
6079 tree_view->priv->press_start_x + 1,
6082 g_object_unref (row_pix);
6083 gtk_tree_path_free (path);
6087 pspp_sheet_view_drag_end (GtkWidget *widget,
6088 GdkDragContext *context)
6093 /* Default signal implementations for the drag signals */
6095 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6096 GdkDragContext *context,
6097 GtkSelectionData *selection_data,
6101 PsppSheetView *tree_view;
6102 GtkTreeModel *model;
6103 TreeViewDragInfo *di;
6104 GtkTreePath *source_row;
6106 tree_view = PSPP_SHEET_VIEW (widget);
6108 model = pspp_sheet_view_get_model (tree_view);
6113 di = get_info (PSPP_SHEET_VIEW (widget));
6118 source_row = get_source_row (context);
6120 if (source_row == NULL)
6123 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6124 * any model; for DragSource models there are some other targets
6128 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6129 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6134 /* If drag_data_get does nothing, try providing row data. */
6135 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6137 gtk_tree_set_row_drag_data (selection_data,
6143 gtk_tree_path_free (source_row);
6148 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6149 GdkDragContext *context)
6151 TreeViewDragInfo *di;
6152 GtkTreeModel *model;
6153 PsppSheetView *tree_view;
6154 GtkTreePath *source_row;
6156 tree_view = PSPP_SHEET_VIEW (widget);
6157 model = pspp_sheet_view_get_model (tree_view);
6159 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6162 di = get_info (tree_view);
6167 source_row = get_source_row (context);
6169 if (source_row == NULL)
6172 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6175 gtk_tree_path_free (source_row);
6177 set_source_row (context, NULL, NULL);
6181 pspp_sheet_view_drag_leave (GtkWidget *widget,
6182 GdkDragContext *context,
6185 /* unset any highlight row */
6186 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6188 PSPP_SHEET_VIEW_DROP_BEFORE);
6190 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6195 pspp_sheet_view_drag_motion (GtkWidget *widget,
6196 GdkDragContext *context,
6197 /* coordinates relative to the widget */
6203 GtkTreePath *path = NULL;
6204 PsppSheetViewDropPosition pos;
6205 PsppSheetView *tree_view;
6206 GdkDragAction suggested_action = 0;
6209 tree_view = PSPP_SHEET_VIEW (widget);
6211 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6214 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6216 /* we only know this *after* set_desination_row */
6217 empty = tree_view->priv->empty_view_drop;
6219 if (path == NULL && !empty)
6221 /* Can't drop here. */
6222 gdk_drag_status (context, 0, time);
6226 if (tree_view->priv->open_dest_timeout == 0 &&
6227 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6228 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6234 add_scroll_timeout (tree_view);
6237 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6239 /* Request data so we can use the source row when
6240 * determining whether to accept the drop
6242 set_status_pending (context, suggested_action);
6243 gtk_drag_get_data (widget, context, target, time);
6247 set_status_pending (context, 0);
6248 gdk_drag_status (context, suggested_action, time);
6253 gtk_tree_path_free (path);
6260 pspp_sheet_view_drag_drop (GtkWidget *widget,
6261 GdkDragContext *context,
6262 /* coordinates relative to the widget */
6267 PsppSheetView *tree_view;
6269 GdkDragAction suggested_action = 0;
6270 GdkAtom target = GDK_NONE;
6271 TreeViewDragInfo *di;
6272 GtkTreeModel *model;
6273 gboolean path_down_mode;
6274 gboolean drop_append_mode;
6276 tree_view = PSPP_SHEET_VIEW (widget);
6278 model = pspp_sheet_view_get_model (tree_view);
6280 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6282 di = get_info (tree_view);
6287 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6290 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6293 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6295 if (target != GDK_NONE && path != NULL)
6297 /* in case a motion had requested drag data, change things so we
6298 * treat drag data receives as a drop.
6300 set_status_pending (context, 0);
6301 set_dest_row (context, model, path,
6302 path_down_mode, tree_view->priv->empty_view_drop,
6307 gtk_tree_path_free (path);
6309 /* Unset this thing */
6310 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6312 PSPP_SHEET_VIEW_DROP_BEFORE);
6314 if (target != GDK_NONE)
6316 gtk_drag_get_data (widget, context, target, time);
6324 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6325 GdkDragContext *context,
6326 /* coordinates relative to the widget */
6329 GtkSelectionData *selection_data,
6334 TreeViewDragInfo *di;
6335 gboolean accepted = FALSE;
6336 GtkTreeModel *model;
6337 PsppSheetView *tree_view;
6338 GtkTreePath *dest_row;
6339 GdkDragAction suggested_action;
6340 gboolean path_down_mode;
6341 gboolean drop_append_mode;
6343 tree_view = PSPP_SHEET_VIEW (widget);
6345 model = pspp_sheet_view_get_model (tree_view);
6347 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6350 di = get_info (tree_view);
6355 suggested_action = get_status_pending (context);
6357 if (suggested_action)
6359 /* We are getting this data due to a request in drag_motion,
6360 * rather than due to a request in drag_drop, so we are just
6361 * supposed to call drag_status, not actually paste in the
6364 path = get_logical_dest_row (tree_view, &path_down_mode,
6368 suggested_action = 0;
6369 else if (path_down_mode)
6370 gtk_tree_path_down (path);
6372 if (suggested_action)
6374 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6380 path_down_mode = FALSE;
6381 gtk_tree_path_up (path);
6383 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6386 suggested_action = 0;
6389 suggested_action = 0;
6393 gdk_drag_status (context, suggested_action, time);
6396 gtk_tree_path_free (path);
6398 /* If you can't drop, remove user drop indicator until the next motion */
6399 if (suggested_action == 0)
6400 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6402 PSPP_SHEET_VIEW_DROP_BEFORE);
6407 dest_row = get_dest_row (context, &path_down_mode);
6409 if (dest_row == NULL)
6412 if (selection_data->length >= 0)
6416 gtk_tree_path_down (dest_row);
6417 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6418 dest_row, selection_data))
6419 gtk_tree_path_up (dest_row);
6423 if (selection_data->length >= 0)
6425 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6431 gtk_drag_finish (context,
6433 (context->action == GDK_ACTION_MOVE),
6436 if (gtk_tree_path_get_depth (dest_row) == 1
6437 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6439 /* special special case drag to "0", scroll to first item */
6440 if (!tree_view->priv->scroll_to_path)
6441 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6444 gtk_tree_path_free (dest_row);
6447 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6452 /* GtkContainer Methods
6457 pspp_sheet_view_remove (GtkContainer *container,
6460 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6461 PsppSheetViewChild *child = NULL;
6464 tmp_list = tree_view->priv->children;
6467 child = tmp_list->data;
6468 if (child->widget == widget)
6470 gtk_widget_unparent (widget);
6472 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6473 g_list_free_1 (tmp_list);
6474 g_slice_free (PsppSheetViewChild, child);
6478 tmp_list = tmp_list->next;
6481 tmp_list = tree_view->priv->columns;
6485 PsppSheetViewColumn *column;
6486 column = tmp_list->data;
6487 if (column->button == widget)
6489 gtk_widget_unparent (widget);
6492 tmp_list = tmp_list->next;
6497 pspp_sheet_view_forall (GtkContainer *container,
6498 gboolean include_internals,
6499 GtkCallback callback,
6500 gpointer callback_data)
6502 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6503 PsppSheetViewChild *child = NULL;
6504 PsppSheetViewColumn *column;
6507 tmp_list = tree_view->priv->children;
6510 child = tmp_list->data;
6511 tmp_list = tmp_list->next;
6513 (* callback) (child->widget, callback_data);
6515 if (include_internals == FALSE)
6518 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6520 column = tmp_list->data;
6523 (* callback) (column->button, callback_data);
6527 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6528 * cells. If so we draw one big row-spanning focus rectangle.
6531 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6535 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6536 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6538 for (list = tree_view->priv->columns; list; list = list->next)
6540 if (!((PsppSheetViewColumn *)list->data)->visible)
6542 if (_pspp_sheet_view_column_count_special_cells (list->data))
6550 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6551 PsppSheetViewColumn *focus_column,
6552 gboolean clamp_column_visible)
6554 g_return_if_fail (focus_column != NULL);
6556 tree_view->priv->focus_column = focus_column;
6557 if (!focus_column->button)
6559 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6560 g_return_if_fail (focus_column->button != NULL);
6563 if (GTK_CONTAINER (tree_view)->focus_child != focus_column->button)
6564 gtk_widget_grab_focus (focus_column->button);
6566 if (clamp_column_visible)
6567 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6570 /* Returns TRUE if the focus is within the headers, after the focus operation is
6574 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6575 GtkDirectionType dir,
6576 gboolean clamp_column_visible)
6578 GtkWidget *focus_child;
6579 PsppSheetViewColumn *focus_column;
6580 GList *last_column, *first_column;
6584 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6587 focus_child = GTK_CONTAINER (tree_view)->focus_child;
6589 first_column = tree_view->priv->columns;
6590 while (first_column)
6592 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6594 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6596 first_column = first_column->next;
6599 /* No headers are visible, or are focusable. We can't focus in or out.
6601 if (first_column == NULL)
6604 last_column = g_list_last (tree_view->priv->columns);
6607 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6609 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6611 last_column = last_column->prev;
6615 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6619 case GTK_DIR_TAB_BACKWARD:
6620 case GTK_DIR_TAB_FORWARD:
6623 if (focus_child == NULL)
6625 if (tree_view->priv->focus_column != NULL &&
6626 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6627 focus_column = tree_view->priv->focus_column;
6629 focus_column = first_column->data;
6630 pspp_sheet_view_focus_column (tree_view, focus_column,
6631 clamp_column_visible);
6638 if (focus_child == NULL)
6640 if (tree_view->priv->focus_column != NULL)
6641 focus_column = tree_view->priv->focus_column;
6642 else if (dir == GTK_DIR_LEFT)
6643 focus_column = last_column->data;
6645 focus_column = first_column->data;
6646 pspp_sheet_view_focus_column (tree_view, focus_column,
6647 clamp_column_visible);
6651 if (gtk_widget_child_focus (focus_child, dir))
6653 /* The focus moves inside the button. */
6654 /* This is probably a great example of bad UI */
6655 if (clamp_column_visible)
6656 pspp_sheet_view_clamp_column_visible (tree_view,
6657 tree_view->priv->focus_column,
6662 /* We need to move the focus among the row of buttons. */
6663 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6664 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6667 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6668 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6670 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6676 PsppSheetViewColumn *column;
6678 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6679 tmp_list = tmp_list->next;
6681 tmp_list = tmp_list->prev;
6683 if (tmp_list == NULL)
6685 g_warning ("Internal button not found");
6688 column = tmp_list->data;
6689 if (column->button &&
6691 pspp_sheet_view_column_can_focus (column))
6693 pspp_sheet_view_focus_column (tree_view, column,
6694 clamp_column_visible);
6701 g_assert_not_reached ();
6708 /* This function returns in 'path' the first focusable path, if the given path
6709 * is already focusable, it's the returned one.
6713 search_first_focusable_path (PsppSheetView *tree_view,
6715 gboolean search_forward,
6718 /* XXX this function is trivial given that the sheetview doesn't support
6722 if (!path || !*path)
6725 _pspp_sheet_view_find_node (tree_view, *path, &node);
6733 return (*path != NULL);
6737 pspp_sheet_view_focus (GtkWidget *widget,
6738 GtkDirectionType direction)
6740 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6741 GtkContainer *container = GTK_CONTAINER (widget);
6742 GtkWidget *focus_child;
6744 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6747 focus_child = container->focus_child;
6749 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6750 /* Case 1. Headers currently have focus. */
6757 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6759 case GTK_DIR_TAB_BACKWARD:
6762 case GTK_DIR_TAB_FORWARD:
6764 gtk_widget_grab_focus (widget);
6767 g_assert_not_reached ();
6772 /* Case 2. We don't have focus at all. */
6773 if (!gtk_widget_has_focus (widget))
6775 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6776 gtk_widget_grab_focus (widget);
6780 /* Case 3. We have focus already. */
6781 if (direction == GTK_DIR_TAB_BACKWARD)
6782 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6783 else if (direction == GTK_DIR_TAB_FORWARD)
6786 /* Other directions caught by the keybindings */
6787 gtk_widget_grab_focus (widget);
6792 pspp_sheet_view_grab_focus (GtkWidget *widget)
6794 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6796 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6800 pspp_sheet_view_style_set (GtkWidget *widget,
6801 GtkStyle *previous_style)
6803 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6805 PsppSheetViewColumn *column;
6807 if (gtk_widget_get_realized (widget))
6809 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
6810 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
6811 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
6813 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6816 gtk_widget_style_get (widget,
6817 "expander-size", &tree_view->priv->expander_size,
6819 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6821 for (list = tree_view->priv->columns; list; list = list->next)
6823 column = list->data;
6824 _pspp_sheet_view_column_cell_set_dirty (column);
6827 tree_view->priv->fixed_height = -1;
6829 /* Invalidate cached button style. */
6830 if (tree_view->priv->button_style)
6832 g_object_unref (tree_view->priv->button_style);
6833 tree_view->priv->button_style = NULL;
6836 gtk_widget_queue_resize (widget);
6841 pspp_sheet_view_set_focus_child (GtkContainer *container,
6844 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6847 for (list = tree_view->priv->columns; list; list = list->next)
6849 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6851 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6856 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6860 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6861 GtkAdjustment *hadj,
6862 GtkAdjustment *vadj)
6864 gboolean need_adjust = FALSE;
6866 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6869 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6871 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6873 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
6875 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6877 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
6879 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
6880 pspp_sheet_view_adjustment_changed,
6882 g_object_unref (tree_view->priv->hadjustment);
6885 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
6887 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
6888 pspp_sheet_view_adjustment_changed,
6890 g_object_unref (tree_view->priv->vadjustment);
6893 if (tree_view->priv->hadjustment != hadj)
6895 tree_view->priv->hadjustment = hadj;
6896 g_object_ref_sink (tree_view->priv->hadjustment);
6898 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
6899 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6904 if (tree_view->priv->vadjustment != vadj)
6906 tree_view->priv->vadjustment = vadj;
6907 g_object_ref_sink (tree_view->priv->vadjustment);
6909 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
6910 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6916 pspp_sheet_view_adjustment_changed (NULL, tree_view);
6921 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
6922 GtkMovementStep step,
6925 GdkModifierType state;
6927 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
6928 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
6929 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
6930 step == GTK_MOVEMENT_DISPLAY_LINES ||
6931 step == GTK_MOVEMENT_PAGES ||
6932 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
6934 if (tree_view->priv->row_count == 0)
6936 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
6939 pspp_sheet_view_stop_editing (tree_view, FALSE);
6940 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
6941 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
6943 if (gtk_get_current_event_state (&state))
6945 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
6946 tree_view->priv->ctrl_pressed = TRUE;
6947 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
6948 tree_view->priv->shift_pressed = TRUE;
6950 /* else we assume not pressed */
6954 /* currently we make no distinction. When we go bi-di, we need to */
6955 case GTK_MOVEMENT_LOGICAL_POSITIONS:
6956 case GTK_MOVEMENT_VISUAL_POSITIONS:
6957 pspp_sheet_view_move_cursor_left_right (tree_view, count);
6959 case GTK_MOVEMENT_DISPLAY_LINES:
6960 pspp_sheet_view_move_cursor_up_down (tree_view, count);
6962 case GTK_MOVEMENT_PAGES:
6963 pspp_sheet_view_move_cursor_page_up_down (tree_view, count);
6965 case GTK_MOVEMENT_BUFFER_ENDS:
6966 pspp_sheet_view_move_cursor_start_end (tree_view, count);
6969 g_assert_not_reached ();
6972 tree_view->priv->ctrl_pressed = FALSE;
6973 tree_view->priv->shift_pressed = FALSE;
6979 pspp_sheet_view_put (PsppSheetView *tree_view,
6980 GtkWidget *child_widget,
6981 /* in bin_window coordinates */
6987 PsppSheetViewChild *child;
6989 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6990 g_return_if_fail (GTK_IS_WIDGET (child_widget));
6992 child = g_slice_new (PsppSheetViewChild);
6994 child->widget = child_widget;
6997 child->width = width;
6998 child->height = height;
7000 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7002 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7003 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7005 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7009 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7011 /* in tree coordinates */
7017 PsppSheetViewChild *child = NULL;
7019 GdkRectangle allocation;
7021 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7022 g_return_if_fail (GTK_IS_WIDGET (widget));
7024 for (list = tree_view->priv->children; list; list = list->next)
7026 if (((PsppSheetViewChild *)list->data)->widget == widget)
7035 allocation.x = child->x = x;
7036 allocation.y = child->y = y;
7037 allocation.width = child->width = width;
7038 allocation.height = child->height = height;
7040 if (gtk_widget_get_realized (widget))
7041 gtk_widget_size_allocate (widget, &allocation);
7045 /* TreeModel Callbacks
7049 pspp_sheet_view_row_changed (GtkTreeModel *model,
7054 PsppSheetView *tree_view = (PsppSheetView *)data;
7056 gboolean free_path = FALSE;
7057 GtkTreePath *cursor_path;
7059 g_return_if_fail (path != NULL || iter != NULL);
7061 if (tree_view->priv->cursor != NULL)
7062 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7066 if (tree_view->priv->edited_column &&
7067 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7068 pspp_sheet_view_stop_editing (tree_view, TRUE);
7070 if (cursor_path != NULL)
7071 gtk_tree_path_free (cursor_path);
7075 path = gtk_tree_model_get_path (model, iter);
7078 else if (iter == NULL)
7079 gtk_tree_model_get_iter (model, iter, path);
7081 _pspp_sheet_view_find_node (tree_view,
7087 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7088 pspp_sheet_view_node_queue_redraw (tree_view, node);
7092 gtk_tree_path_free (path);
7096 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7101 PsppSheetView *tree_view = (PsppSheetView *) data;
7104 gint height = tree_view->priv->fixed_height;
7105 gboolean free_path = FALSE;
7106 gboolean node_visible = TRUE;
7108 g_return_if_fail (path != NULL || iter != NULL);
7112 path = gtk_tree_model_get_path (model, iter);
7115 else if (iter == NULL)
7116 gtk_tree_model_get_iter (model, iter, path);
7118 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7120 /* Update all row-references */
7121 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7122 indices = gtk_tree_path_get_indices (path);
7123 tmpnode = indices[0];
7125 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7129 if (node_visible && node_is_visible (tree_view, tmpnode))
7130 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7132 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7135 install_presize_handler (tree_view);
7137 gtk_tree_path_free (path);
7141 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7145 PsppSheetView *tree_view = (PsppSheetView *)data;
7148 g_return_if_fail (path != NULL);
7150 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7152 _pspp_sheet_view_find_node (tree_view, path, &node);
7157 range_tower_delete (tree_view->priv->selected, node, 1);
7159 /* Ensure we don't have a dangling pointer to a dead node */
7160 ensure_unprelighted (tree_view);
7162 /* Cancel editting if we've started */
7163 pspp_sheet_view_stop_editing (tree_view, TRUE);
7165 if (tree_view->priv->destroy_count_func)
7167 gint child_count = 0;
7168 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7171 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7173 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7175 gtk_tree_row_reference_free (tree_view->priv->top_row);
7176 tree_view->priv->top_row = NULL;
7179 install_scroll_sync_handler (tree_view);
7181 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7184 if (helper_data.changed)
7185 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7190 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7191 GtkTreePath *parent,
7196 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7199 /* XXX need to adjust selection */
7200 len = gtk_tree_model_iter_n_children (model, iter);
7205 gtk_tree_row_reference_reordered (G_OBJECT (data),
7210 if (gtk_tree_path_get_depth (parent) != 0)
7213 if (tree_view->priv->edited_column)
7214 pspp_sheet_view_stop_editing (tree_view, TRUE);
7216 /* we need to be unprelighted */
7217 ensure_unprelighted (tree_view);
7219 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7221 pspp_sheet_view_dy_to_top_row (tree_view);
7225 /* Internal tree functions
7230 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7231 PsppSheetViewColumn *column,
7235 PsppSheetViewColumn *tmp_column = NULL;
7246 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7249 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7251 list = (rtl ? list->prev : list->next))
7253 tmp_column = list->data;
7255 if (tmp_column == column)
7258 if (tmp_column->visible)
7259 total_width += tmp_column->width;
7262 if (tmp_column != column)
7264 g_warning (G_STRLOC": passed-in column isn't in the tree");
7273 if (column->visible)
7274 *x2 = total_width + column->width;
7276 *x2 = total_width; /* width of 0 */
7280 /* Make sure the node is visible vertically */
7282 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7285 gint node_dy, height;
7286 GtkTreePath *path = NULL;
7288 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7291 /* just return if the node is visible, avoiding a costly expose */
7292 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7293 height = ROW_HEIGHT (tree_view);
7294 if (node_dy >= tree_view->priv->vadjustment->value
7295 && node_dy + height <= (tree_view->priv->vadjustment->value
7296 + tree_view->priv->vadjustment->page_size))
7299 path = _pspp_sheet_view_find_path (tree_view, node);
7302 /* We process updates because we want to clear old selected items when we scroll.
7303 * if this is removed, we get a "selection streak" at the bottom. */
7304 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7305 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7306 gtk_tree_path_free (path);
7311 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7312 PsppSheetViewColumn *column,
7313 gboolean focus_to_cell)
7320 x = column->allocation.x;
7321 width = column->allocation.width;
7323 if (width > tree_view->priv->hadjustment->page_size)
7325 /* The column is larger than the horizontal page size. If the
7326 * column has cells which can be focussed individually, then we make
7327 * sure the cell which gets focus is fully visible (if even the
7328 * focus cell is bigger than the page size, we make sure the
7329 * left-hand side of the cell is visible).
7331 * If the column does not have those so-called special cells, we
7332 * make sure the left-hand side of the column is visible.
7335 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7337 GtkTreePath *cursor_path;
7338 GdkRectangle background_area, cell_area, focus_area;
7340 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7342 pspp_sheet_view_get_cell_area (tree_view,
7343 cursor_path, column, &cell_area);
7344 pspp_sheet_view_get_background_area (tree_view,
7345 cursor_path, column,
7348 gtk_tree_path_free (cursor_path);
7350 _pspp_sheet_view_column_get_focus_area (column,
7356 width = focus_area.width;
7358 if (width < tree_view->priv->hadjustment->page_size)
7360 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7361 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7362 x + width - tree_view->priv->hadjustment->page_size);
7363 else if (tree_view->priv->hadjustment->value > x)
7364 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7368 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7370 tree_view->priv->hadjustment->lower,
7371 tree_view->priv->hadjustment->upper
7372 - tree_view->priv->hadjustment->page_size));
7376 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7377 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7378 x + width - tree_view->priv->hadjustment->page_size);
7379 else if (tree_view->priv->hadjustment->value > x)
7380 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7385 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7390 path = gtk_tree_path_new ();
7392 gtk_tree_path_append_index (path, node);
7397 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7401 gint *indices = gtk_tree_path_get_indices (path);
7402 gint depth = gtk_tree_path_get_depth (path);
7405 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7411 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7414 gboolean add_shifted_binding,
7415 GtkMovementStep step,
7419 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7424 if (add_shifted_binding)
7425 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7430 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7433 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7438 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7445 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7446 PsppSheetViewColumn *column)
7448 PsppSheetViewColumn *left_column;
7449 PsppSheetViewColumn *cur_column = NULL;
7450 PsppSheetViewColumnReorder *reorder;
7455 /* We want to precalculate the motion list such that we know what column slots
7459 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7461 /* First, identify all possible drop spots */
7463 tmp_list = g_list_last (tree_view->priv->columns);
7465 tmp_list = g_list_first (tree_view->priv->columns);
7469 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7470 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7472 if (cur_column->visible == FALSE)
7475 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7476 if (left_column != column && cur_column != column &&
7477 tree_view->priv->column_drop_func &&
7478 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7480 left_column = cur_column;
7483 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7484 reorder->left_column = left_column;
7485 left_column = reorder->right_column = cur_column;
7487 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7490 /* Add the last one */
7491 if (tree_view->priv->column_drop_func == NULL ||
7492 ((left_column != column) &&
7493 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7495 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7496 reorder->left_column = left_column;
7497 reorder->right_column = NULL;
7498 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7501 /* We quickly check to see if it even makes sense to reorder columns. */
7502 /* If there is nothing that can be moved, then we return */
7504 if (tree_view->priv->column_drag_info == NULL)
7507 /* We know there are always 2 slots possbile, as you can always return column. */
7508 /* If that's all there is, return */
7509 if (tree_view->priv->column_drag_info->next == NULL ||
7510 (tree_view->priv->column_drag_info->next->next == NULL &&
7511 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7512 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7514 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7515 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7516 g_list_free (tree_view->priv->column_drag_info);
7517 tree_view->priv->column_drag_info = NULL;
7520 /* We fill in the ranges for the columns, now that we've isolated them */
7521 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7523 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7525 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7527 reorder->left_align = left;
7528 if (tmp_list->next != NULL)
7530 g_assert (tmp_list->next->data);
7531 left = reorder->right_align = (reorder->right_column->allocation.x +
7532 reorder->right_column->allocation.width +
7533 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7539 gdk_drawable_get_size (tree_view->priv->header_window, &width, NULL);
7540 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7546 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7547 PsppSheetViewColumn *column)
7549 GdkEvent *send_event;
7550 GtkAllocation allocation;
7551 gint x, y, width, height;
7552 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7553 GdkDisplay *display = gdk_screen_get_display (screen);
7555 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7556 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7557 g_return_if_fail (column->button);
7559 pspp_sheet_view_set_column_drag_info (tree_view, column);
7561 if (tree_view->priv->column_drag_info == NULL)
7564 if (tree_view->priv->drag_window == NULL)
7566 GdkWindowAttr attributes;
7567 guint attributes_mask;
7569 attributes.window_type = GDK_WINDOW_CHILD;
7570 attributes.wclass = GDK_INPUT_OUTPUT;
7571 attributes.x = column->allocation.x;
7573 attributes.width = column->allocation.width;
7574 attributes.height = column->allocation.height;
7575 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7576 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
7577 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7578 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
7580 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7583 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7586 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7587 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7589 gtk_grab_remove (column->button);
7591 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7592 send_event->crossing.send_event = TRUE;
7593 send_event->crossing.window = g_object_ref (GTK_BUTTON (column->button)->event_window);
7594 send_event->crossing.subwindow = NULL;
7595 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7596 send_event->crossing.time = GDK_CURRENT_TIME;
7598 gtk_propagate_event (column->button, send_event);
7599 gdk_event_free (send_event);
7601 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7602 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7603 send_event->button.send_event = TRUE;
7604 send_event->button.time = GDK_CURRENT_TIME;
7605 send_event->button.x = -1;
7606 send_event->button.y = -1;
7607 send_event->button.axes = NULL;
7608 send_event->button.state = 0;
7609 send_event->button.button = 1;
7610 send_event->button.device = gdk_display_get_core_pointer (display);
7611 send_event->button.x_root = 0;
7612 send_event->button.y_root = 0;
7614 gtk_propagate_event (column->button, send_event);
7615 gdk_event_free (send_event);
7617 /* Kids, don't try this at home */
7618 g_object_ref (column->button);
7619 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7620 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7621 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7622 g_object_unref (column->button);
7624 tree_view->priv->drag_column_x = column->allocation.x;
7625 allocation = column->allocation;
7627 gtk_widget_size_allocate (column->button, &allocation);
7628 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7630 tree_view->priv->drag_column = column;
7631 gdk_window_show (tree_view->priv->drag_window);
7633 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7634 gdk_drawable_get_size (tree_view->priv->header_window, &width, &height);
7636 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7637 while (gtk_events_pending ())
7638 gtk_main_iteration ();
7640 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7641 gdk_pointer_grab (tree_view->priv->drag_window,
7643 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7644 NULL, NULL, GDK_CURRENT_TIME);
7645 gdk_keyboard_grab (tree_view->priv->drag_window,
7651 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7653 const GdkRectangle *clip_rect)
7657 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7661 rect.width = MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width);
7663 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7664 rect.height = ROW_HEIGHT (tree_view);
7668 GdkRectangle new_rect;
7670 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7672 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7676 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7681 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7683 const GdkRectangle *clip_rect)
7687 _pspp_sheet_view_find_node (tree_view, path, &node);
7690 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7694 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7697 GtkTreePath *cursor_path;
7699 if ((tree_view->priv->row_count == 0) ||
7700 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7704 if (tree_view->priv->cursor)
7705 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7707 if (cursor_path == NULL)
7709 /* There's no cursor. Move the cursor to the first selected row, if any
7710 * are selected, otherwise to the first row in the sheetview.
7712 GList *selected_rows;
7713 GtkTreeModel *model;
7714 PsppSheetSelection *selection;
7716 selection = pspp_sheet_view_get_selection (tree_view);
7717 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7721 /* XXX we could avoid doing O(n) work to get this result */
7722 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7723 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7724 g_list_free (selected_rows);
7728 cursor_path = gtk_tree_path_new_first ();
7729 search_first_focusable_path (tree_view, &cursor_path,
7733 gtk_tree_row_reference_free (tree_view->priv->cursor);
7734 tree_view->priv->cursor = NULL;
7738 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7739 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7740 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE);
7742 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
7748 /* Now find a column for the cursor. */
7749 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7751 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7752 gtk_tree_path_free (cursor_path);
7754 if (tree_view->priv->focus_column == NULL)
7757 for (list = tree_view->priv->columns; list; list = list->next)
7759 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7761 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7762 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7763 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7773 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7776 gint selection_count;
7777 int cursor_node = -1;
7778 int new_cursor_node = -1;
7779 GtkTreePath *cursor_path = NULL;
7780 gboolean grab_focus = TRUE;
7782 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7786 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7787 /* FIXME: we lost the cursor; should we get the first? */
7790 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7791 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7793 if (cursor_node < 0)
7794 /* FIXME: we lost the cursor; should we get the first? */
7797 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7799 if (selection_count == 0
7800 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7801 && !tree_view->priv->ctrl_pressed)
7803 /* Don't move the cursor, but just select the current node */
7804 new_cursor_node = cursor_node;
7809 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7811 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7814 gtk_tree_path_free (cursor_path);
7816 if (new_cursor_node)
7818 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7820 search_first_focusable_path (tree_view, &cursor_path,
7825 gtk_tree_path_free (cursor_path);
7829 * If the list has only one item and multi-selection is set then select
7830 * the row (if not yet selected).
7832 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7833 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7834 new_cursor_node < 0)
7837 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7839 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7841 if (new_cursor_node < 0
7842 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7844 new_cursor_node = cursor_node;
7848 new_cursor_node = -1;
7852 if (new_cursor_node >= 0)
7854 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7855 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE);
7856 gtk_tree_path_free (cursor_path);
7860 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7862 if (!tree_view->priv->shift_pressed)
7864 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7866 GTK_DIR_UP : GTK_DIR_DOWN))
7868 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
7871 gtk_widget_child_focus (toplevel,
7873 GTK_DIR_TAB_BACKWARD :
7874 GTK_DIR_TAB_FORWARD);
7881 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7886 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7890 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
7893 int cursor_node = -1;
7894 GtkTreePath *old_cursor_path = NULL;
7895 GtkTreePath *cursor_path = NULL;
7896 int start_cursor_node = -1;
7899 gint vertical_separator;
7901 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7904 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
7905 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7907 /* This is sorta weird. Focus in should give us a cursor */
7910 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
7911 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
7913 if (cursor_node < 0)
7915 /* FIXME: we lost the cursor. Should we try to get one? */
7916 gtk_tree_path_free (old_cursor_path);
7920 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7921 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
7922 y += tree_view->priv->cursor_offset;
7923 y += count * (int)tree_view->priv->vadjustment->page_increment;
7924 y = CLAMP (y, (gint)tree_view->priv->vadjustment->lower, (gint)tree_view->priv->vadjustment->upper - vertical_separator);
7926 if (y >= tree_view->priv->height)
7927 y = tree_view->priv->height - 1;
7929 tree_view->priv->cursor_offset =
7930 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
7932 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
7934 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7935 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
7938 y -= tree_view->priv->cursor_offset;
7939 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7941 start_cursor_node = cursor_node;
7943 if (! search_first_focusable_path (tree_view, &cursor_path,
7947 /* It looks like we reached the end of the view without finding
7948 * a focusable row. We will step backwards to find the last
7951 cursor_node = start_cursor_node;
7952 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7954 search_first_focusable_path (tree_view, &cursor_path,
7963 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7965 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
7968 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
7969 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7970 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
7972 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
7973 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7975 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7978 gtk_tree_path_free (old_cursor_path);
7979 gtk_tree_path_free (cursor_path);
7983 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
7986 int cursor_node = -1;
7987 GtkTreePath *cursor_path = NULL;
7988 PsppSheetViewColumn *column;
7991 gboolean found_column = FALSE;
7994 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7996 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7999 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8000 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8004 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8005 if (cursor_node < 0)
8007 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8009 gtk_tree_path_free (cursor_path);
8012 gtk_tree_path_free (cursor_path);
8014 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8015 if (tree_view->priv->focus_column)
8017 for (; list; list = (rtl ? list->prev : list->next))
8019 if (list->data == tree_view->priv->focus_column)
8026 gboolean left, right;
8028 column = list->data;
8029 if (column->visible == FALSE)
8032 pspp_sheet_view_column_cell_set_cell_data (column,
8033 tree_view->priv->model,
8038 right = list->prev ? TRUE : FALSE;
8039 left = list->next ? TRUE : FALSE;
8043 left = list->prev ? TRUE : FALSE;
8044 right = list->next ? TRUE : FALSE;
8047 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8049 tree_view->priv->focus_column = column;
8050 found_column = TRUE;
8055 list = rtl ? list->prev : list->next;
8057 list = rtl ? list->next : list->prev;
8062 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8063 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8064 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8068 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8071 pspp_sheet_view_clamp_column_visible (tree_view,
8072 tree_view->priv->focus_column, TRUE);
8076 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8081 GtkTreePath *old_path;
8083 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8086 g_return_if_fail (tree_view->priv->row_count > 0);
8088 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8092 /* Now go forward to find the first focusable row. */
8093 path = _pspp_sheet_view_find_path (tree_view, 0);
8094 search_first_focusable_path (tree_view, &path,
8095 TRUE, &cursor_node);
8099 /* Now go backwards to find last focusable row. */
8100 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8101 search_first_focusable_path (tree_view, &path,
8102 FALSE, &cursor_node);
8108 if (gtk_tree_path_compare (old_path, path))
8110 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
8111 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8115 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8119 gtk_tree_path_free (old_path);
8120 gtk_tree_path_free (path);
8124 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8126 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8129 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8130 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8133 pspp_sheet_selection_select_all (tree_view->priv->selection);
8139 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8141 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8144 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8145 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8148 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8154 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8155 gboolean start_editing)
8158 int cursor_node = -1;
8159 GtkTreePath *cursor_path = NULL;
8160 GtkTreeSelectMode mode = 0;
8162 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8165 if (tree_view->priv->cursor)
8166 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8168 if (cursor_path == NULL)
8171 _pspp_sheet_view_find_node (tree_view, cursor_path,
8174 if (cursor_node < 0)
8176 gtk_tree_path_free (cursor_path);
8180 if (!tree_view->priv->shift_pressed && start_editing &&
8181 tree_view->priv->focus_column)
8183 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8185 gtk_tree_path_free (cursor_path);
8190 if (tree_view->priv->ctrl_pressed)
8191 mode |= GTK_TREE_SELECT_MODE_TOGGLE;
8192 if (tree_view->priv->shift_pressed)
8193 mode |= GTK_TREE_SELECT_MODE_EXTEND;
8195 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8201 /* We bail out if the original (tree, node) don't exist anymore after
8202 * handling the selection-changed callback. We do return TRUE because
8203 * the key press has been handled at this point.
8205 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8207 if (cursor_node != new_node)
8210 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8212 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8213 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8215 if (!tree_view->priv->shift_pressed)
8216 pspp_sheet_view_row_activated (tree_view, cursor_path,
8217 tree_view->priv->focus_column);
8219 gtk_tree_path_free (cursor_path);
8225 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8228 int cursor_node = -1;
8229 GtkTreePath *cursor_path = NULL;
8231 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8235 if (tree_view->priv->cursor)
8236 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8238 if (cursor_path == NULL)
8241 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8242 if (cursor_node < 0)
8244 gtk_tree_path_free (cursor_path);
8248 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8251 GTK_TREE_SELECT_MODE_TOGGLE,
8254 /* We bail out if the original (tree, node) don't exist anymore after
8255 * handling the selection-changed callback. We do return TRUE because
8256 * the key press has been handled at this point.
8258 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8260 if (cursor_node != new_node)
8263 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8265 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8266 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8267 gtk_tree_path_free (cursor_path);
8273 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8275 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8276 tree_view->priv->typeselect_flush_timeout = 0;
8281 /* Cut and paste from gtkwindow.c */
8283 send_focus_change (GtkWidget *widget,
8286 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8288 g_object_ref (widget);
8291 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
8293 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
8295 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8296 fevent->focus_change.window = g_object_ref (widget->window);
8297 fevent->focus_change.in = in;
8299 gtk_widget_event (widget, fevent);
8301 g_object_notify (G_OBJECT (widget), "has-focus");
8303 g_object_unref (widget);
8304 gdk_event_free (fevent);
8308 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8310 GtkWidget *frame, *vbox, *toplevel;
8313 if (tree_view->priv->search_custom_entry_set)
8316 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8317 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8319 if (tree_view->priv->search_window != NULL)
8321 if (GTK_WINDOW (toplevel)->group)
8322 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8323 GTK_WINDOW (tree_view->priv->search_window));
8324 else if (GTK_WINDOW (tree_view->priv->search_window)->group)
8325 gtk_window_group_remove_window (GTK_WINDOW (tree_view->priv->search_window)->group,
8326 GTK_WINDOW (tree_view->priv->search_window));
8327 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8331 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8332 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8334 if (GTK_WINDOW (toplevel)->group)
8335 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8336 GTK_WINDOW (tree_view->priv->search_window));
8338 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8339 GDK_WINDOW_TYPE_HINT_UTILITY);
8340 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8341 g_signal_connect (tree_view->priv->search_window, "delete-event",
8342 G_CALLBACK (pspp_sheet_view_search_delete_event),
8344 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8345 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8347 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8348 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8350 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8351 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8354 frame = gtk_frame_new (NULL);
8355 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8356 gtk_widget_show (frame);
8357 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8359 vbox = gtk_vbox_new (FALSE, 0);
8360 gtk_widget_show (vbox);
8361 gtk_container_add (GTK_CONTAINER (frame), vbox);
8362 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8365 tree_view->priv->search_entry = gtk_entry_new ();
8366 gtk_widget_show (tree_view->priv->search_entry);
8367 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8368 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8370 g_signal_connect (tree_view->priv->search_entry,
8371 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8373 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8375 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8377 gtk_container_add (GTK_CONTAINER (vbox),
8378 tree_view->priv->search_entry);
8380 gtk_widget_realize (tree_view->priv->search_entry);
8383 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8384 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8387 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8388 gboolean keybinding)
8390 /* We only start interactive search if we have focus or the columns
8391 * have focus. If one of our children have focus, we don't want to
8395 gboolean found_focus = FALSE;
8396 GtkWidgetClass *entry_parent_class;
8398 if (!tree_view->priv->enable_search && !keybinding)
8401 if (tree_view->priv->search_custom_entry_set)
8404 if (tree_view->priv->search_window != NULL &&
8405 gtk_widget_get_visible (tree_view->priv->search_window))
8408 for (list = tree_view->priv->columns; list; list = list->next)
8410 PsppSheetViewColumn *column;
8412 column = list->data;
8413 if (! column->visible)
8416 if (column->button && gtk_widget_has_focus (column->button))
8423 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8429 if (tree_view->priv->search_column < 0)
8432 pspp_sheet_view_ensure_interactive_directory (tree_view);
8435 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8438 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8439 gtk_widget_show (tree_view->priv->search_window);
8440 if (tree_view->priv->search_entry_changed_id == 0)
8442 tree_view->priv->search_entry_changed_id =
8443 g_signal_connect (tree_view->priv->search_entry, "changed",
8444 G_CALLBACK (pspp_sheet_view_search_init),
8448 tree_view->priv->typeselect_flush_timeout =
8449 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8450 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8453 /* Grab focus will select all the text. We don't want that to happen, so we
8454 * call the parent instance and bypass the selection change. This is probably
8455 * really non-kosher. */
8456 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8457 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8459 /* send focus-in event */
8460 send_focus_change (tree_view->priv->search_entry, TRUE);
8462 /* search first matching iter */
8463 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8469 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8471 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8474 /* this function returns the new width of the column being resized given
8475 * the column and x position of the cursor; the x cursor position is passed
8476 * in as a pointer and automagicly corrected if it's beyond min/max limits
8479 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8483 PsppSheetViewColumn *column;
8487 /* first translate the x position from widget->window
8488 * to clist->clist_window
8490 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8491 column = g_list_nth (tree_view->priv->columns, i)->data;
8492 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8494 /* Clamp down the value */
8495 if (column->min_width == -1)
8496 width = MAX (column->button_request, width);
8498 width = MAX (column->min_width, width);
8499 if (column->max_width != -1)
8500 width = MIN (width, column->max_width);
8502 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8508 /* FIXME this adjust_allocation is a big cut-and-paste from
8509 * GtkCList, needs to be some "official" way to do this
8519 /* The window to which widget->window is relative */
8520 #define ALLOCATION_WINDOW(widget) \
8521 (!gtk_widget_get_has_window (widget) ? \
8522 (widget)->window : \
8523 gdk_window_get_parent ((widget)->window))
8526 adjust_allocation_recurse (GtkWidget *widget,
8529 ScrollData *scroll_data = data;
8531 /* Need to really size allocate instead of just poking
8532 * into widget->allocation if the widget is not realized.
8533 * FIXME someone figure out why this was.
8535 if (!gtk_widget_get_realized (widget))
8537 if (gtk_widget_get_visible (widget))
8539 GdkRectangle tmp_rectangle = widget->allocation;
8540 tmp_rectangle.x += scroll_data->dx;
8541 tmp_rectangle.y += scroll_data->dy;
8543 gtk_widget_size_allocate (widget, &tmp_rectangle);
8548 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8550 widget->allocation.x += scroll_data->dx;
8551 widget->allocation.y += scroll_data->dy;
8553 if (GTK_IS_CONTAINER (widget))
8554 gtk_container_forall (GTK_CONTAINER (widget),
8555 adjust_allocation_recurse,
8562 adjust_allocation (GtkWidget *widget,
8566 ScrollData scroll_data;
8568 if (gtk_widget_get_realized (widget))
8569 scroll_data.window = ALLOCATION_WINDOW (widget);
8571 scroll_data.window = NULL;
8573 scroll_data.dx = dx;
8574 scroll_data.dy = dy;
8576 adjust_allocation_recurse (widget, &scroll_data);
8580 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8584 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8585 PsppSheetView *tree_view)
8587 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8592 gdk_window_move (tree_view->priv->bin_window,
8593 - tree_view->priv->hadjustment->value,
8594 TREE_VIEW_HEADER_HEIGHT (tree_view));
8595 gdk_window_move (tree_view->priv->header_window,
8596 - tree_view->priv->hadjustment->value,
8598 dy = tree_view->priv->dy - (int) tree_view->priv->vadjustment->value;
8601 update_prelight (tree_view,
8602 tree_view->priv->event_last_x,
8603 tree_view->priv->event_last_y - dy);
8605 if (tree_view->priv->edited_column &&
8606 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8610 PsppSheetViewChild *child = NULL;
8612 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8613 adjust_allocation (widget, 0, dy);
8615 for (list = tree_view->priv->children; list; list = list->next)
8617 child = (PsppSheetViewChild *)list->data;
8618 if (child->widget == widget)
8626 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8628 if (tree_view->priv->dy != (int) tree_view->priv->vadjustment->value)
8630 /* update our dy and top_row */
8631 tree_view->priv->dy = (int) tree_view->priv->vadjustment->value;
8633 if (!tree_view->priv->in_top_row_to_dy)
8634 pspp_sheet_view_dy_to_top_row (tree_view);
8637 for (list = tree_view->priv->columns; list; list = list->next)
8639 PsppSheetViewColumn *column = list->data;
8640 GtkAllocation *allocation = &column->allocation;
8642 if (span_intersects (allocation->x, allocation->width,
8643 tree_view->priv->hadjustment->value,
8644 GTK_WIDGET (tree_view)->allocation.width))
8646 pspp_sheet_view_column_set_need_button (column, TRUE);
8647 if (!column->button)
8648 pspp_sheet_view_column_update_button (column);
8660 * pspp_sheet_view_new:
8662 * Creates a new #PsppSheetView widget.
8664 * Return value: A newly created #PsppSheetView widget.
8667 pspp_sheet_view_new (void)
8669 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8673 * pspp_sheet_view_new_with_model:
8674 * @model: the model.
8676 * Creates a new #PsppSheetView widget with the model initialized to @model.
8678 * Return value: A newly created #PsppSheetView widget.
8681 pspp_sheet_view_new_with_model (GtkTreeModel *model)
8683 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
8690 * pspp_sheet_view_get_model:
8691 * @tree_view: a #PsppSheetView
8693 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
8696 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
8699 pspp_sheet_view_get_model (PsppSheetView *tree_view)
8701 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8703 return tree_view->priv->model;
8707 * pspp_sheet_view_set_model:
8708 * @tree_view: A #GtkTreeNode.
8709 * @model: (allow-none): The model.
8711 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
8712 * set, it will remove it before setting the new model. If @model is %NULL,
8713 * then it will unset the old model.
8716 pspp_sheet_view_set_model (PsppSheetView *tree_view,
8717 GtkTreeModel *model)
8719 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8720 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
8722 if (model == tree_view->priv->model)
8725 if (tree_view->priv->scroll_to_path)
8727 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8728 tree_view->priv->scroll_to_path = NULL;
8731 if (tree_view->priv->model)
8733 GList *tmplist = tree_view->priv->columns;
8735 if (tree_view->priv->selected)
8736 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
8737 pspp_sheet_view_stop_editing (tree_view, TRUE);
8739 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8740 pspp_sheet_view_row_changed,
8742 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8743 pspp_sheet_view_row_inserted,
8745 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8746 pspp_sheet_view_row_deleted,
8748 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8749 pspp_sheet_view_rows_reordered,
8752 for (; tmplist; tmplist = tmplist->next)
8753 _pspp_sheet_view_column_unset_model (tmplist->data,
8754 tree_view->priv->model);
8756 tree_view->priv->prelight_node = -1;
8758 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
8759 tree_view->priv->drag_dest_row = NULL;
8760 gtk_tree_row_reference_free (tree_view->priv->cursor);
8761 tree_view->priv->cursor = NULL;
8762 gtk_tree_row_reference_free (tree_view->priv->anchor);
8763 tree_view->priv->anchor = NULL;
8764 gtk_tree_row_reference_free (tree_view->priv->top_row);
8765 tree_view->priv->top_row = NULL;
8766 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8767 tree_view->priv->scroll_to_path = NULL;
8769 tree_view->priv->scroll_to_column = NULL;
8771 g_object_unref (tree_view->priv->model);
8773 tree_view->priv->search_column = -1;
8774 tree_view->priv->fixed_height = -1;
8775 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
8776 tree_view->priv->last_button_x = -1;
8777 tree_view->priv->last_button_y = -1;
8780 tree_view->priv->model = model;
8782 if (tree_view->priv->model)
8785 GtkTreeModelFlags flags;
8787 if (tree_view->priv->search_column == -1)
8789 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
8791 GType type = gtk_tree_model_get_column_type (model, i);
8793 if (g_value_type_transformable (type, G_TYPE_STRING))
8795 tree_view->priv->search_column = i;
8801 g_object_ref (tree_view->priv->model);
8802 g_signal_connect (tree_view->priv->model,
8804 G_CALLBACK (pspp_sheet_view_row_changed),
8806 g_signal_connect (tree_view->priv->model,
8808 G_CALLBACK (pspp_sheet_view_row_inserted),
8810 g_signal_connect (tree_view->priv->model,
8812 G_CALLBACK (pspp_sheet_view_row_deleted),
8814 g_signal_connect (tree_view->priv->model,
8816 G_CALLBACK (pspp_sheet_view_rows_reordered),
8819 flags = gtk_tree_model_get_flags (tree_view->priv->model);
8821 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
8823 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
8824 install_presize_handler (tree_view);
8827 g_object_notify (G_OBJECT (tree_view), "model");
8829 if (tree_view->priv->selection)
8830 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
8832 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8833 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
8837 * pspp_sheet_view_get_selection:
8838 * @tree_view: A #PsppSheetView.
8840 * Gets the #PsppSheetSelection associated with @tree_view.
8842 * Return value: A #PsppSheetSelection object.
8844 PsppSheetSelection *
8845 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
8847 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8849 return tree_view->priv->selection;
8853 * pspp_sheet_view_get_hadjustment:
8854 * @tree_view: A #PsppSheetView
8856 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
8858 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8862 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
8864 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8866 if (tree_view->priv->hadjustment == NULL)
8867 pspp_sheet_view_set_hadjustment (tree_view, NULL);
8869 return tree_view->priv->hadjustment;
8873 * pspp_sheet_view_set_hadjustment:
8874 * @tree_view: A #PsppSheetView
8875 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8877 * Sets the #GtkAdjustment for the current horizontal aspect.
8880 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
8881 GtkAdjustment *adjustment)
8883 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8885 pspp_sheet_view_set_adjustments (tree_view,
8887 tree_view->priv->vadjustment);
8889 g_object_notify (G_OBJECT (tree_view), "hadjustment");
8893 * pspp_sheet_view_get_vadjustment:
8894 * @tree_view: A #PsppSheetView
8896 * Gets the #GtkAdjustment currently being used for the vertical aspect.
8898 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8902 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
8904 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8906 if (tree_view->priv->vadjustment == NULL)
8907 pspp_sheet_view_set_vadjustment (tree_view, NULL);
8909 return tree_view->priv->vadjustment;
8913 * pspp_sheet_view_set_vadjustment:
8914 * @tree_view: A #PsppSheetView
8915 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8917 * Sets the #GtkAdjustment for the current vertical aspect.
8920 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
8921 GtkAdjustment *adjustment)
8923 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8925 pspp_sheet_view_set_adjustments (tree_view,
8926 tree_view->priv->hadjustment,
8929 g_object_notify (G_OBJECT (tree_view), "vadjustment");
8932 /* Column and header operations */
8935 * pspp_sheet_view_get_headers_visible:
8936 * @tree_view: A #PsppSheetView.
8938 * Returns %TRUE if the headers on the @tree_view are visible.
8940 * Return value: Whether the headers are visible or not.
8943 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
8945 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
8947 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8951 * pspp_sheet_view_set_headers_visible:
8952 * @tree_view: A #PsppSheetView.
8953 * @headers_visible: %TRUE if the headers are visible
8955 * Sets the visibility state of the headers.
8958 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
8959 gboolean headers_visible)
8963 PsppSheetViewColumn *column;
8965 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8967 headers_visible = !! headers_visible;
8969 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
8972 if (headers_visible)
8973 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8975 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8977 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8979 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
8980 if (headers_visible)
8982 gdk_window_move_resize (tree_view->priv->bin_window, x, y + TREE_VIEW_HEADER_HEIGHT (tree_view), tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.height - + TREE_VIEW_HEADER_HEIGHT (tree_view));
8984 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
8985 pspp_sheet_view_map_buttons (tree_view);
8989 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
8991 for (list = tree_view->priv->columns; list; list = list->next)
8993 column = list->data;
8995 gtk_widget_unmap (column->button);
8997 gdk_window_hide (tree_view->priv->header_window);
9001 tree_view->priv->vadjustment->page_size = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
9002 tree_view->priv->vadjustment->page_increment = (GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2;
9003 tree_view->priv->vadjustment->lower = 0;
9004 tree_view->priv->vadjustment->upper = tree_view->priv->height;
9005 gtk_adjustment_changed (tree_view->priv->vadjustment);
9007 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9009 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9013 * pspp_sheet_view_columns_autosize:
9014 * @tree_view: A #PsppSheetView.
9016 * Resizes all columns to their optimal width. Only works after the
9017 * treeview has been realized.
9020 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9022 gboolean dirty = FALSE;
9024 PsppSheetViewColumn *column;
9026 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9028 for (list = tree_view->priv->columns; list; list = list->next)
9030 column = list->data;
9031 _pspp_sheet_view_column_cell_set_dirty (column);
9036 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9040 * pspp_sheet_view_set_headers_clickable:
9041 * @tree_view: A #PsppSheetView.
9042 * @setting: %TRUE if the columns are clickable.
9044 * Allow the column title buttons to be clicked.
9047 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9052 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9054 for (list = tree_view->priv->columns; list; list = list->next)
9055 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9057 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9062 * pspp_sheet_view_get_headers_clickable:
9063 * @tree_view: A #PsppSheetView.
9065 * Returns whether all header columns are clickable.
9067 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9072 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9076 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9078 for (list = tree_view->priv->columns; list; list = list->next)
9079 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9086 * pspp_sheet_view_set_rules_hint
9087 * @tree_view: a #PsppSheetView
9088 * @setting: %TRUE if the tree requires reading across rows
9090 * This function tells GTK+ that the user interface for your
9091 * application requires users to read across tree rows and associate
9092 * cells with one another. By default, GTK+ will then render the tree
9093 * with alternating row colors. Do <emphasis>not</emphasis> use it
9094 * just because you prefer the appearance of the ruled tree; that's a
9095 * question for the theme. Some themes will draw tree rows in
9096 * alternating colors even when rules are turned off, and users who
9097 * prefer that appearance all the time can choose those themes. You
9098 * should call this function only as a <emphasis>semantic</emphasis>
9099 * hint to the theme engine that your tree makes alternating colors
9100 * useful from a functional standpoint (since it has lots of columns,
9105 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9108 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9110 setting = setting != FALSE;
9112 if (tree_view->priv->has_rules != setting)
9114 tree_view->priv->has_rules = setting;
9115 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9118 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9122 * pspp_sheet_view_get_rules_hint
9123 * @tree_view: a #PsppSheetView
9125 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9127 * Return value: %TRUE if rules are useful for the user of this tree
9130 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9132 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9134 return tree_view->priv->has_rules;
9137 /* Public Column functions
9141 * pspp_sheet_view_append_column:
9142 * @tree_view: A #PsppSheetView.
9143 * @column: The #PsppSheetViewColumn to add.
9145 * Appends @column to the list of columns.
9147 * Return value: The number of columns in @tree_view after appending.
9150 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9151 PsppSheetViewColumn *column)
9153 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9154 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9155 g_return_val_if_fail (column->tree_view == NULL, -1);
9157 return pspp_sheet_view_insert_column (tree_view, column, -1);
9162 * pspp_sheet_view_remove_column:
9163 * @tree_view: A #PsppSheetView.
9164 * @column: The #PsppSheetViewColumn to remove.
9166 * Removes @column from @tree_view.
9168 * Return value: The number of columns in @tree_view after removing.
9171 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9172 PsppSheetViewColumn *column)
9174 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9175 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9176 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9178 if (tree_view->priv->focus_column == column)
9179 tree_view->priv->focus_column = NULL;
9181 if (tree_view->priv->edited_column == column)
9183 pspp_sheet_view_stop_editing (tree_view, TRUE);
9185 /* no need to, but just to be sure ... */
9186 tree_view->priv->edited_column = NULL;
9189 _pspp_sheet_view_column_unset_tree_view (column);
9191 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9192 tree_view->priv->n_columns--;
9194 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9198 _pspp_sheet_view_column_unrealize_button (column);
9199 for (list = tree_view->priv->columns; list; list = list->next)
9201 PsppSheetViewColumn *tmp_column;
9203 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9204 if (tmp_column->visible)
9205 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9208 if (tree_view->priv->n_columns == 0 &&
9209 pspp_sheet_view_get_headers_visible (tree_view))
9210 gdk_window_hide (tree_view->priv->header_window);
9212 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9215 g_object_unref (column);
9216 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9218 return tree_view->priv->n_columns;
9222 * pspp_sheet_view_insert_column:
9223 * @tree_view: A #PsppSheetView.
9224 * @column: The #PsppSheetViewColumn to be inserted.
9225 * @position: The position to insert @column in.
9227 * This inserts the @column into the @tree_view at @position. If @position is
9228 * -1, then the column is inserted at the end.
9230 * Return value: The number of columns in @tree_view after insertion.
9233 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9234 PsppSheetViewColumn *column,
9237 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9238 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9239 g_return_val_if_fail (column->tree_view == NULL, -1);
9241 g_object_ref_sink (column);
9243 if (tree_view->priv->n_columns == 0 &&
9244 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9245 pspp_sheet_view_get_headers_visible (tree_view))
9247 gdk_window_show (tree_view->priv->header_window);
9250 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9252 tree_view->priv->n_columns++;
9254 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9256 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9260 _pspp_sheet_view_column_realize_button (column);
9262 for (list = tree_view->priv->columns; list; list = list->next)
9264 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9265 if (column->visible)
9266 _pspp_sheet_view_column_cell_set_dirty (column);
9268 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9271 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9273 return tree_view->priv->n_columns;
9277 * pspp_sheet_view_insert_column_with_attributes:
9278 * @tree_view: A #PsppSheetView
9279 * @position: The position to insert the new column in.
9280 * @title: The title to set the header to.
9281 * @cell: The #GtkCellRenderer.
9282 * @Varargs: A %NULL-terminated list of attributes.
9284 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9285 * @position. If @position is -1, then the newly created column is inserted at
9286 * the end. The column is initialized with the attributes given.
9288 * Return value: The number of columns in @tree_view after insertion.
9291 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9294 GtkCellRenderer *cell,
9297 PsppSheetViewColumn *column;
9302 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9304 column = pspp_sheet_view_column_new ();
9305 pspp_sheet_view_column_set_title (column, title);
9306 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9308 va_start (args, cell);
9310 attribute = va_arg (args, gchar *);
9312 while (attribute != NULL)
9314 column_id = va_arg (args, gint);
9315 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9316 attribute = va_arg (args, gchar *);
9321 pspp_sheet_view_insert_column (tree_view, column, position);
9323 return tree_view->priv->n_columns;
9327 * pspp_sheet_view_insert_column_with_data_func:
9328 * @tree_view: a #PsppSheetView
9329 * @position: Position to insert, -1 for append
9330 * @title: column title
9331 * @cell: cell renderer for column
9332 * @func: function to set attributes of cell renderer
9333 * @data: data for @func
9334 * @dnotify: destroy notifier for @data
9336 * Convenience function that inserts a new column into the #PsppSheetView
9337 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9338 * attributes (normally using data from the model). See also
9339 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9341 * Return value: number of columns in the tree view post-insert
9344 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9347 GtkCellRenderer *cell,
9348 PsppSheetCellDataFunc func,
9350 GDestroyNotify dnotify)
9352 PsppSheetViewColumn *column;
9354 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9356 column = pspp_sheet_view_column_new ();
9357 pspp_sheet_view_column_set_title (column, title);
9358 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9359 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9361 pspp_sheet_view_insert_column (tree_view, column, position);
9363 return tree_view->priv->n_columns;
9367 * pspp_sheet_view_get_column:
9368 * @tree_view: A #PsppSheetView.
9369 * @n: The position of the column, counting from 0.
9371 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9373 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9376 PsppSheetViewColumn *
9377 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9380 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9382 if (n < 0 || n >= tree_view->priv->n_columns)
9385 if (tree_view->priv->columns == NULL)
9388 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9392 * pspp_sheet_view_get_columns:
9393 * @tree_view: A #PsppSheetView
9395 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9396 * The returned list must be freed with g_list_free ().
9398 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9401 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9403 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9405 return g_list_copy (tree_view->priv->columns);
9409 * pspp_sheet_view_move_column_after:
9410 * @tree_view: A #PsppSheetView
9411 * @column: The #PsppSheetViewColumn to be moved.
9412 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9414 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9415 * @column is placed in the first position.
9418 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9419 PsppSheetViewColumn *column,
9420 PsppSheetViewColumn *base_column)
9422 GList *column_list_el, *base_el = NULL;
9424 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9426 column_list_el = g_list_find (tree_view->priv->columns, column);
9427 g_return_if_fail (column_list_el != NULL);
9431 base_el = g_list_find (tree_view->priv->columns, base_column);
9432 g_return_if_fail (base_el != NULL);
9435 if (column_list_el->prev == base_el)
9438 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9439 if (base_el == NULL)
9441 column_list_el->prev = NULL;
9442 column_list_el->next = tree_view->priv->columns;
9443 if (column_list_el->next)
9444 column_list_el->next->prev = column_list_el;
9445 tree_view->priv->columns = column_list_el;
9449 column_list_el->prev = base_el;
9450 column_list_el->next = base_el->next;
9451 if (column_list_el->next)
9452 column_list_el->next->prev = column_list_el;
9453 base_el->next = column_list_el;
9456 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9458 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9459 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9462 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9466 * pspp_sheet_view_set_column_drag_function:
9467 * @tree_view: A #PsppSheetView.
9468 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9469 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9470 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9472 * Sets a user function for determining where a column may be dropped when
9473 * dragged. This function is called on every column pair in turn at the
9474 * beginning of a column drag to determine where a drop can take place. The
9475 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9476 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9477 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9478 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9479 * @tree_view reverts to the default behavior of allowing all columns to be
9480 * dropped everywhere.
9483 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9484 PsppSheetViewColumnDropFunc func,
9486 GDestroyNotify destroy)
9488 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9490 if (tree_view->priv->column_drop_func_data_destroy)
9491 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9493 tree_view->priv->column_drop_func = func;
9494 tree_view->priv->column_drop_func_data = user_data;
9495 tree_view->priv->column_drop_func_data_destroy = destroy;
9499 * pspp_sheet_view_scroll_to_point:
9500 * @tree_view: a #PsppSheetView
9501 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9502 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9504 * Scrolls the tree view such that the top-left corner of the visible
9505 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9506 * in tree coordinates. The @tree_view must be realized before
9507 * this function is called. If it isn't, you probably want to be
9508 * using pspp_sheet_view_scroll_to_cell().
9510 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9513 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9517 GtkAdjustment *hadj;
9518 GtkAdjustment *vadj;
9520 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9521 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9523 hadj = tree_view->priv->hadjustment;
9524 vadj = tree_view->priv->vadjustment;
9527 gtk_adjustment_set_value (hadj, CLAMP (tree_x, hadj->lower, hadj->upper - hadj->page_size));
9529 gtk_adjustment_set_value (vadj, CLAMP (tree_y, vadj->lower, vadj->upper - vadj->page_size));
9533 * pspp_sheet_view_scroll_to_cell:
9534 * @tree_view: A #PsppSheetView.
9535 * @path: (allow-none): The path of the row to move to, or %NULL.
9536 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9537 * @use_align: whether to use alignment arguments, or %FALSE.
9538 * @row_align: The vertical alignment of the row specified by @path.
9539 * @col_align: The horizontal alignment of the column specified by @column.
9541 * Moves the alignments of @tree_view to the position specified by @column and
9542 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9543 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9544 * or @path need to be non-%NULL. @row_align determines where the row is
9545 * placed, and @col_align determines where @column is placed. Both are expected
9546 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9547 * right/bottom alignment, 0.5 means center.
9549 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9550 * tree does the minimum amount of work to scroll the cell onto the screen.
9551 * This means that the cell will be scrolled to the edge closest to its current
9552 * position. If the cell is currently visible on the screen, nothing is done.
9554 * This function only works if the model is set, and @path is a valid row on the
9555 * model. If the model changes before the @tree_view is realized, the centered
9556 * path will be modified to reflect this change.
9559 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9561 PsppSheetViewColumn *column,
9566 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9567 g_return_if_fail (tree_view->priv->model != NULL);
9568 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9569 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9570 g_return_if_fail (path != NULL || column != NULL);
9573 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9574 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9576 row_align = CLAMP (row_align, 0.0, 1.0);
9577 col_align = CLAMP (col_align, 0.0, 1.0);
9580 /* Note: Despite the benefits that come from having one code path for the
9581 * scrolling code, we short-circuit validate_visible_area's immplementation as
9582 * it is much slower than just going to the point.
9584 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9585 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9586 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9588 if (tree_view->priv->scroll_to_path)
9589 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9591 tree_view->priv->scroll_to_path = NULL;
9592 tree_view->priv->scroll_to_column = NULL;
9595 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9597 tree_view->priv->scroll_to_column = column;
9598 tree_view->priv->scroll_to_use_align = use_align;
9599 tree_view->priv->scroll_to_row_align = row_align;
9600 tree_view->priv->scroll_to_col_align = col_align;
9602 install_presize_handler (tree_view);
9606 GdkRectangle cell_rect;
9607 GdkRectangle vis_rect;
9608 gint dest_x, dest_y;
9610 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9611 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9613 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9615 dest_x = vis_rect.x;
9616 dest_y = vis_rect.y;
9622 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9626 if (cell_rect.x < vis_rect.x)
9627 dest_x = cell_rect.x;
9628 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9629 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9637 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9638 dest_y = MAX (dest_y, 0);
9642 if (cell_rect.y < vis_rect.y)
9643 dest_y = cell_rect.y;
9644 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9645 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9649 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9654 * pspp_sheet_view_row_activated:
9655 * @tree_view: A #PsppSheetView
9656 * @path: The #GtkTreePath to be activated.
9657 * @column: The #PsppSheetViewColumn to be activated.
9659 * Activates the cell determined by @path and @column.
9662 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9664 PsppSheetViewColumn *column)
9666 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9668 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
9673 * pspp_sheet_view_get_reorderable:
9674 * @tree_view: a #PsppSheetView
9676 * Retrieves whether the user can reorder the tree via drag-and-drop. See
9677 * pspp_sheet_view_set_reorderable().
9679 * Return value: %TRUE if the tree can be reordered.
9682 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
9684 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9686 return tree_view->priv->reorderable;
9690 * pspp_sheet_view_set_reorderable:
9691 * @tree_view: A #PsppSheetView.
9692 * @reorderable: %TRUE, if the tree can be reordered.
9694 * This function is a convenience function to allow you to reorder
9695 * models that support the #GtkDragSourceIface and the
9696 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
9697 * these. If @reorderable is %TRUE, then the user can reorder the
9698 * model by dragging and dropping rows. The developer can listen to
9699 * these changes by connecting to the model's row_inserted and
9700 * row_deleted signals. The reordering is implemented by setting up
9701 * the tree view as a drag source and destination. Therefore, drag and
9702 * drop can not be used in a reorderable view for any other purpose.
9704 * This function does not give you any degree of control over the order -- any
9705 * reordering is allowed. If more control is needed, you should probably
9706 * handle drag and drop manually.
9709 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
9710 gboolean reorderable)
9712 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9714 reorderable = reorderable != FALSE;
9716 if (tree_view->priv->reorderable == reorderable)
9721 const GtkTargetEntry row_targets[] = {
9722 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
9725 pspp_sheet_view_enable_model_drag_source (tree_view,
9728 G_N_ELEMENTS (row_targets),
9730 pspp_sheet_view_enable_model_drag_dest (tree_view,
9732 G_N_ELEMENTS (row_targets),
9737 pspp_sheet_view_unset_rows_drag_source (tree_view);
9738 pspp_sheet_view_unset_rows_drag_dest (tree_view);
9741 tree_view->priv->reorderable = reorderable;
9743 g_object_notify (G_OBJECT (tree_view), "reorderable");
9746 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
9747 is pressed, other rows will be unselected.
9749 If CLAMP_NODE is true, then the sheetview will scroll to make the row
9752 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
9754 gboolean clear_and_select,
9755 gboolean clamp_node)
9759 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9761 GtkTreePath *cursor_path;
9762 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9763 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
9764 gtk_tree_path_free (cursor_path);
9767 gtk_tree_row_reference_free (tree_view->priv->cursor);
9768 tree_view->priv->cursor = NULL;
9770 _pspp_sheet_view_find_node (tree_view, path, &node);
9771 tree_view->priv->cursor =
9772 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
9773 tree_view->priv->model,
9776 if (tree_view->priv->row_count > 0)
9780 if (clear_and_select && !tree_view->priv->ctrl_pressed)
9782 GtkTreeSelectMode mode = 0;
9784 if (tree_view->priv->ctrl_pressed)
9785 mode |= GTK_TREE_SELECT_MODE_TOGGLE;
9786 if (tree_view->priv->shift_pressed)
9787 mode |= GTK_TREE_SELECT_MODE_EXTEND;
9789 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
9794 /* We have to re-find tree and node here again, somebody might have
9795 * cleared the node or the whole tree in the PsppSheetSelection::changed
9796 * callback. If the nodes differ we bail out here.
9798 _pspp_sheet_view_find_node (tree_view, path, &new_node);
9800 if (node != new_node)
9805 pspp_sheet_view_clamp_node_visible (tree_view, node);
9806 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
9810 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
9814 * pspp_sheet_view_get_cursor:
9815 * @tree_view: A #PsppSheetView
9816 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
9817 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
9819 * Fills in @path and @focus_column with the current path and focus column. If
9820 * the cursor isn't currently set, then *@path will be %NULL. If no column
9821 * currently has focus, then *@focus_column will be %NULL.
9823 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
9824 * you are done with it.
9827 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
9829 PsppSheetViewColumn **focus_column)
9831 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9835 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9836 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9843 *focus_column = tree_view->priv->focus_column;
9848 * pspp_sheet_view_set_cursor:
9849 * @tree_view: A #PsppSheetView
9850 * @path: A #GtkTreePath
9851 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9852 * @start_editing: %TRUE if the specified cell should start being edited.
9854 * Sets the current keyboard focus to be at @path, and selects it. This is
9855 * useful when you want to focus the user's attention on a particular row. If
9856 * @focus_column is not %NULL, then focus is given to the column specified by
9857 * it. Additionally, if @focus_column is specified, and @start_editing is
9858 * %TRUE, then editing should be started in the specified cell.
9859 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
9860 * in order to give keyboard focus to the widget. Please note that editing
9861 * can only happen when the widget is realized.
9863 * If @path is invalid for @model, the current cursor (if any) will be unset
9864 * and the function will return without failing.
9867 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
9869 PsppSheetViewColumn *focus_column,
9870 gboolean start_editing)
9872 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
9873 NULL, start_editing);
9877 * pspp_sheet_view_set_cursor_on_cell:
9878 * @tree_view: A #PsppSheetView
9879 * @path: A #GtkTreePath
9880 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9881 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
9882 * @start_editing: %TRUE if the specified cell should start being edited.
9884 * Sets the current keyboard focus to be at @path, and selects it. This is
9885 * useful when you want to focus the user's attention on a particular row. If
9886 * @focus_column is not %NULL, then focus is given to the column specified by
9887 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
9888 * contains 2 or more editable or activatable cells, then focus is given to
9889 * the cell specified by @focus_cell. Additionally, if @focus_column is
9890 * specified, and @start_editing is %TRUE, then editing should be started in
9891 * the specified cell. This function is often followed by
9892 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
9893 * widget. Please note that editing can only happen when the widget is
9896 * If @path is invalid for @model, the current cursor (if any) will be unset
9897 * and the function will return without failing.
9902 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
9904 PsppSheetViewColumn *focus_column,
9905 GtkCellRenderer *focus_cell,
9906 gboolean start_editing)
9908 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9909 g_return_if_fail (path != NULL);
9910 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
9912 if (!tree_view->priv->model)
9917 g_return_if_fail (focus_column);
9918 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
9921 /* cancel the current editing, if it exists */
9922 if (tree_view->priv->edited_column &&
9923 tree_view->priv->edited_column->editable_widget)
9924 pspp_sheet_view_stop_editing (tree_view, TRUE);
9926 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
9928 if (focus_column && focus_column->visible)
9931 gboolean column_in_tree = FALSE;
9933 for (list = tree_view->priv->columns; list; list = list->next)
9934 if (list->data == focus_column)
9936 column_in_tree = TRUE;
9939 g_return_if_fail (column_in_tree);
9940 tree_view->priv->focus_column = focus_column;
9942 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
9944 pspp_sheet_view_start_editing (tree_view, path);
9946 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
9947 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
9953 * pspp_sheet_view_get_bin_window:
9954 * @tree_view: A #PsppSheetView
9956 * Returns the window that @tree_view renders to. This is used primarily to
9957 * compare to <literal>event->window</literal> to confirm that the event on
9958 * @tree_view is on the right window.
9960 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
9963 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
9965 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9967 return tree_view->priv->bin_window;
9971 * pspp_sheet_view_get_path_at_pos:
9972 * @tree_view: A #PsppSheetView.
9973 * @x: The x position to be identified (relative to bin_window).
9974 * @y: The y position to be identified (relative to bin_window).
9975 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
9976 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
9977 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
9978 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
9980 * Finds the path at the point (@x, @y), relative to bin_window coordinates
9981 * (please see pspp_sheet_view_get_bin_window()).
9982 * That is, @x and @y are relative to an events coordinates. @x and @y must
9983 * come from an event on the @tree_view only where <literal>event->window ==
9984 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
9985 * things like popup menus. If @path is non-%NULL, then it will be filled
9986 * with the #GtkTreePath at that point. This path should be freed with
9987 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
9988 * with the column at that point. @cell_x and @cell_y return the coordinates
9989 * relative to the cell background (i.e. the @background_area passed to
9990 * gtk_cell_renderer_render()). This function is only meaningful if
9991 * @tree_view is realized. Therefore this function will always return %FALSE
9992 * if @tree_view is not realized or does not have a model.
9994 * For converting widget coordinates (eg. the ones you get from
9995 * GtkWidget::query-tooltip), please see
9996 * pspp_sheet_view_convert_widget_to_bin_window_coords().
9998 * Return value: %TRUE if a row exists at that coordinate.
10001 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10004 GtkTreePath **path,
10005 PsppSheetViewColumn **column,
10012 g_return_val_if_fail (tree_view != NULL, FALSE);
10019 if (tree_view->priv->bin_window == NULL)
10022 if (tree_view->priv->row_count == 0)
10025 if (x > tree_view->priv->hadjustment->upper)
10028 if (x < 0 || y < 0)
10031 if (column || cell_x)
10033 PsppSheetViewColumn *tmp_column;
10034 PsppSheetViewColumn *last_column = NULL;
10036 gint remaining_x = x;
10037 gboolean found = FALSE;
10040 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10041 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10043 list = (rtl ? list->prev : list->next))
10045 tmp_column = list->data;
10047 if (tmp_column->visible == FALSE)
10050 last_column = tmp_column;
10051 if (remaining_x <= tmp_column->width)
10056 *column = tmp_column;
10059 *cell_x = remaining_x;
10063 remaining_x -= tmp_column->width;
10066 /* If found is FALSE and there is a last_column, then it the remainder
10067 * space is in that area
10074 *column = last_column;
10077 *cell_x = last_column->width + remaining_x;
10086 y_offset = pspp_sheet_view_find_offset (tree_view,
10087 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10094 *cell_y = y_offset;
10097 *path = _pspp_sheet_view_find_path (tree_view, node);
10102 /* Computes 'cell_area' from 'background_area', which must be the background
10103 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10104 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10105 the cell area as passed to _pspp_sheet_view_column_cell_render().
10107 'column' is required to properly adjust 'cell_area->x' and
10108 'cell_area->width'. It may be set to NULL if these values are not of
10109 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10112 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10113 PsppSheetViewColumn *column,
10114 const GdkRectangle *background_area,
10115 gboolean subtract_focus_rect,
10116 GdkRectangle *cell_area)
10118 gint vertical_separator;
10119 gint horizontal_separator;
10121 *cell_area = *background_area;
10123 gtk_widget_style_get (GTK_WIDGET (tree_view),
10124 "vertical-separator", &vertical_separator,
10125 "horizontal-separator", &horizontal_separator,
10127 cell_area->x += horizontal_separator / 2;
10128 cell_area->y += vertical_separator / 2;
10129 cell_area->width -= horizontal_separator;
10130 cell_area->height -= vertical_separator;
10132 if (subtract_focus_rect)
10134 int focus_line_width;
10136 gtk_widget_style_get (GTK_WIDGET (tree_view),
10137 "focus-line-width", &focus_line_width,
10139 cell_area->x += focus_line_width;
10140 cell_area->y += focus_line_width;
10141 cell_area->width -= 2 * focus_line_width;
10142 cell_area->height -= 2 * focus_line_width;
10145 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10147 gint grid_line_width;
10148 gtk_widget_style_get (GTK_WIDGET (tree_view),
10149 "grid-line-width", &grid_line_width,
10152 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10153 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10156 PsppSheetViewColumn *first_column, *last_column;
10159 /* Find the last visible column. */
10160 last_column = NULL;
10161 for (list = g_list_last (tree_view->priv->columns);
10165 PsppSheetViewColumn *c = list->data;
10173 /* Find the first visible column. */
10174 first_column = NULL;
10175 for (list = g_list_first (tree_view->priv->columns);
10179 PsppSheetViewColumn *c = list->data;
10187 if (column == first_column)
10189 cell_area->width -= grid_line_width / 2;
10191 else if (column == last_column)
10193 cell_area->x += grid_line_width / 2;
10194 cell_area->width -= grid_line_width / 2;
10198 cell_area->x += grid_line_width / 2;
10199 cell_area->width -= grid_line_width;
10203 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10204 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10206 cell_area->y += grid_line_width / 2;
10207 cell_area->height -= grid_line_width;
10211 if (column == NULL)
10214 cell_area->width = 0;
10219 * pspp_sheet_view_get_cell_area:
10220 * @tree_view: a #PsppSheetView
10221 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10222 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10223 * @rect: rectangle to fill with cell rect
10225 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10226 * row specified by @path and the column specified by @column. If @path is
10227 * %NULL, or points to a path not currently displayed, the @y and @height fields
10228 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10229 * fields will be filled with 0. The sum of all cell rects does not cover the
10230 * entire tree; there are extra pixels in between rows, for example. The
10231 * returned rectangle is equivalent to the @cell_area passed to
10232 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10236 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10238 PsppSheetViewColumn *column,
10239 GdkRectangle *rect)
10241 GdkRectangle background_area;
10243 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10244 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10245 g_return_if_fail (rect != NULL);
10246 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10247 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10249 pspp_sheet_view_get_background_area (tree_view, path, column,
10251 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10256 * pspp_sheet_view_get_background_area:
10257 * @tree_view: a #PsppSheetView
10258 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10259 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10260 * @rect: rectangle to fill with cell background rect
10262 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10263 * row specified by @path and the column specified by @column. If @path is
10264 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10265 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10266 * fields will be filled with 0. The returned rectangle is equivalent to the
10267 * @background_area passed to gtk_cell_renderer_render(). These background
10268 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10269 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10270 * itself, excluding surrounding borders.
10274 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10276 PsppSheetViewColumn *column,
10277 GdkRectangle *rect)
10281 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10282 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10283 g_return_if_fail (rect != NULL);
10292 /* Get vertical coords */
10294 _pspp_sheet_view_find_node (tree_view, path, &node);
10298 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10300 rect->height = ROW_HEIGHT (tree_view);
10307 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10308 rect->width = x2 - rect->x;
10313 * pspp_sheet_view_get_visible_rect:
10314 * @tree_view: a #PsppSheetView
10315 * @visible_rect: rectangle to fill
10317 * Fills @visible_rect with the currently-visible region of the
10318 * buffer, in tree coordinates. Convert to bin_window coordinates with
10319 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10320 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10321 * scrollable area of the tree.
10324 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10325 GdkRectangle *visible_rect)
10329 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10331 widget = GTK_WIDGET (tree_view);
10335 visible_rect->x = tree_view->priv->hadjustment->value;
10336 visible_rect->y = tree_view->priv->vadjustment->value;
10337 visible_rect->width = widget->allocation.width;
10338 visible_rect->height = widget->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10343 * pspp_sheet_view_widget_to_tree_coords:
10344 * @tree_view: a #PsppSheetView
10345 * @wx: X coordinate relative to bin_window
10346 * @wy: Y coordinate relative to bin_window
10347 * @tx: return location for tree X coordinate
10348 * @ty: return location for tree Y coordinate
10350 * Converts bin_window coordinates to coordinates for the
10351 * tree (the full scrollable area of the tree).
10353 * Deprecated: 2.12: Due to historial reasons the name of this function is
10354 * incorrect. For converting coordinates relative to the widget to
10355 * bin_window coordinates, please see
10356 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10360 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10366 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10369 *tx = wx + tree_view->priv->hadjustment->value;
10371 *ty = wy + tree_view->priv->dy;
10375 * pspp_sheet_view_tree_to_widget_coords:
10376 * @tree_view: a #PsppSheetView
10377 * @tx: tree X coordinate
10378 * @ty: tree Y coordinate
10379 * @wx: return location for X coordinate relative to bin_window
10380 * @wy: return location for Y coordinate relative to bin_window
10382 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10383 * to bin_window coordinates.
10385 * Deprecated: 2.12: Due to historial reasons the name of this function is
10386 * incorrect. For converting bin_window coordinates to coordinates relative
10387 * to bin_window, please see
10388 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10392 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10398 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10401 *wx = tx - tree_view->priv->hadjustment->value;
10403 *wy = ty - tree_view->priv->dy;
10408 * pspp_sheet_view_convert_widget_to_tree_coords:
10409 * @tree_view: a #PsppSheetView
10410 * @wx: X coordinate relative to the widget
10411 * @wy: Y coordinate relative to the widget
10412 * @tx: return location for tree X coordinate
10413 * @ty: return location for tree Y coordinate
10415 * Converts widget coordinates to coordinates for the
10416 * tree (the full scrollable area of the tree).
10421 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10429 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10431 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10434 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10440 * pspp_sheet_view_convert_tree_to_widget_coords:
10441 * @tree_view: a #PsppSheetView
10442 * @tx: X coordinate relative to the tree
10443 * @ty: Y coordinate relative to the tree
10444 * @wx: return location for widget X coordinate
10445 * @wy: return location for widget Y coordinate
10447 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10448 * to widget coordinates.
10453 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10461 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10463 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10466 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10472 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10473 * @tree_view: a #PsppSheetView
10474 * @wx: X coordinate relative to the widget
10475 * @wy: Y coordinate relative to the widget
10476 * @bx: return location for bin_window X coordinate
10477 * @by: return location for bin_window Y coordinate
10479 * Converts widget coordinates to coordinates for the bin_window
10480 * (see pspp_sheet_view_get_bin_window()).
10485 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10491 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10494 *bx = wx + tree_view->priv->hadjustment->value;
10496 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10500 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10501 * @tree_view: a #PsppSheetView
10502 * @bx: bin_window X coordinate
10503 * @by: bin_window Y coordinate
10504 * @wx: return location for widget X coordinate
10505 * @wy: return location for widget Y coordinate
10507 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10508 * to widget relative coordinates.
10513 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10519 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10522 *wx = bx - tree_view->priv->hadjustment->value;
10524 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10528 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10529 * @tree_view: a #PsppSheetView
10530 * @tx: tree X coordinate
10531 * @ty: tree Y coordinate
10532 * @bx: return location for X coordinate relative to bin_window
10533 * @by: return location for Y coordinate relative to bin_window
10535 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10536 * to bin_window coordinates.
10541 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10547 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10552 *by = ty - tree_view->priv->dy;
10556 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10557 * @tree_view: a #PsppSheetView
10558 * @bx: X coordinate relative to bin_window
10559 * @by: Y coordinate relative to bin_window
10560 * @tx: return location for tree X coordinate
10561 * @ty: return location for tree Y coordinate
10563 * Converts bin_window coordinates to coordinates for the
10564 * tree (the full scrollable area of the tree).
10569 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10575 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10580 *ty = by + tree_view->priv->dy;
10586 * pspp_sheet_view_get_visible_range:
10587 * @tree_view: A #PsppSheetView
10588 * @start_path: (allow-none): Return location for start of region, or %NULL.
10589 * @end_path: (allow-none): Return location for end of region, or %NULL.
10591 * Sets @start_path and @end_path to be the first and last visible path.
10592 * Note that there may be invisible paths in between.
10594 * The paths should be freed with gtk_tree_path_free() after use.
10596 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10601 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10602 GtkTreePath **start_path,
10603 GtkTreePath **end_path)
10608 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10610 if (!tree_view->priv->row_count)
10617 pspp_sheet_view_find_offset (tree_view,
10618 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10621 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10630 if (tree_view->priv->height < tree_view->priv->vadjustment->page_size)
10631 y = tree_view->priv->height - 1;
10633 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, tree_view->priv->vadjustment->page_size) - 1;
10635 pspp_sheet_view_find_offset (tree_view, y, &node);
10637 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10646 unset_reorderable (PsppSheetView *tree_view)
10648 if (tree_view->priv->reorderable)
10650 tree_view->priv->reorderable = FALSE;
10651 g_object_notify (G_OBJECT (tree_view), "reorderable");
10656 * pspp_sheet_view_enable_model_drag_source:
10657 * @tree_view: a #PsppSheetView
10658 * @start_button_mask: Mask of allowed buttons to start drag
10659 * @targets: the table of targets that the drag will support
10660 * @n_targets: the number of items in @targets
10661 * @actions: the bitmask of possible actions for a drag from this
10664 * Turns @tree_view into a drag source for automatic DND. Calling this
10665 * method sets #PsppSheetView:reorderable to %FALSE.
10668 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10669 GdkModifierType start_button_mask,
10670 const GtkTargetEntry *targets,
10672 GdkDragAction actions)
10674 TreeViewDragInfo *di;
10676 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10678 gtk_drag_source_set (GTK_WIDGET (tree_view),
10684 di = ensure_info (tree_view);
10686 di->start_button_mask = start_button_mask;
10687 di->source_actions = actions;
10688 di->source_set = TRUE;
10690 unset_reorderable (tree_view);
10694 * pspp_sheet_view_enable_model_drag_dest:
10695 * @tree_view: a #PsppSheetView
10696 * @targets: the table of targets that the drag will support
10697 * @n_targets: the number of items in @targets
10698 * @actions: the bitmask of possible actions for a drag from this
10701 * Turns @tree_view into a drop destination for automatic DND. Calling
10702 * this method sets #PsppSheetView:reorderable to %FALSE.
10705 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
10706 const GtkTargetEntry *targets,
10708 GdkDragAction actions)
10710 TreeViewDragInfo *di;
10712 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10714 gtk_drag_dest_set (GTK_WIDGET (tree_view),
10720 di = ensure_info (tree_view);
10721 di->dest_set = TRUE;
10723 unset_reorderable (tree_view);
10727 * pspp_sheet_view_unset_rows_drag_source:
10728 * @tree_view: a #PsppSheetView
10730 * Undoes the effect of
10731 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
10732 * #PsppSheetView:reorderable to %FALSE.
10735 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
10737 TreeViewDragInfo *di;
10739 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10741 di = get_info (tree_view);
10745 if (di->source_set)
10747 gtk_drag_source_unset (GTK_WIDGET (tree_view));
10748 di->source_set = FALSE;
10751 if (!di->dest_set && !di->source_set)
10752 remove_info (tree_view);
10755 unset_reorderable (tree_view);
10759 * pspp_sheet_view_unset_rows_drag_dest:
10760 * @tree_view: a #PsppSheetView
10762 * Undoes the effect of
10763 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
10764 * #PsppSheetView:reorderable to %FALSE.
10767 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
10769 TreeViewDragInfo *di;
10771 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10773 di = get_info (tree_view);
10779 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
10780 di->dest_set = FALSE;
10783 if (!di->dest_set && !di->source_set)
10784 remove_info (tree_view);
10787 unset_reorderable (tree_view);
10791 * pspp_sheet_view_set_drag_dest_row:
10792 * @tree_view: a #PsppSheetView
10793 * @path: (allow-none): The path of the row to highlight, or %NULL.
10794 * @pos: Specifies whether to drop before, after or into the row
10796 * Sets the row that is highlighted for feedback.
10799 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
10801 PsppSheetViewDropPosition pos)
10803 GtkTreePath *current_dest;
10805 /* Note; this function is exported to allow a custom DND
10806 * implementation, so it can't touch TreeViewDragInfo
10809 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10811 current_dest = NULL;
10813 if (tree_view->priv->drag_dest_row)
10815 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10816 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
10819 /* special case a drop on an empty model */
10820 tree_view->priv->empty_view_drop = 0;
10822 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
10823 && gtk_tree_path_get_depth (path) == 1
10824 && gtk_tree_path_get_indices (path)[0] == 0)
10828 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
10832 tree_view->priv->empty_view_drop = 1;
10835 tree_view->priv->drag_dest_pos = pos;
10839 tree_view->priv->drag_dest_row =
10840 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
10841 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
10844 tree_view->priv->drag_dest_row = NULL;
10848 int node, new_node;
10850 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
10851 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10855 new_node = pspp_sheet_view_node_next (tree_view, node);
10857 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
10859 new_node = pspp_sheet_view_node_prev (tree_view, node);
10861 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
10863 gtk_tree_path_free (current_dest);
10868 * pspp_sheet_view_get_drag_dest_row:
10869 * @tree_view: a #PsppSheetView
10870 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
10871 * @pos: (allow-none): Return location for the drop position, or %NULL
10873 * Gets information about the row that is highlighted for feedback.
10876 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
10877 GtkTreePath **path,
10878 PsppSheetViewDropPosition *pos)
10880 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10884 if (tree_view->priv->drag_dest_row)
10885 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10888 if (tree_view->priv->empty_view_drop)
10889 *path = gtk_tree_path_new_from_indices (0, -1);
10896 *pos = tree_view->priv->drag_dest_pos;
10900 * pspp_sheet_view_get_dest_row_at_pos:
10901 * @tree_view: a #PsppSheetView
10902 * @drag_x: the position to determine the destination row for
10903 * @drag_y: the position to determine the destination row for
10904 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
10905 * @pos: (allow-none): Return location for the drop position, or %NULL
10907 * Determines the destination row for a given position. @drag_x and
10908 * @drag_y are expected to be in widget coordinates. This function is only
10909 * meaningful if @tree_view is realized. Therefore this function will always
10910 * return %FALSE if @tree_view is not realized or does not have a model.
10912 * Return value: whether there is a row at the given position, %TRUE if this
10913 * is indeed the case.
10916 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
10919 GtkTreePath **path,
10920 PsppSheetViewDropPosition *pos)
10924 gdouble offset_into_row;
10927 PsppSheetViewColumn *column = NULL;
10928 GtkTreePath *tmp_path = NULL;
10930 /* Note; this function is exported to allow a custom DND
10931 * implementation, so it can't touch TreeViewDragInfo
10934 g_return_val_if_fail (tree_view != NULL, FALSE);
10935 g_return_val_if_fail (drag_x >= 0, FALSE);
10936 g_return_val_if_fail (drag_y >= 0, FALSE);
10941 if (tree_view->priv->bin_window == NULL)
10944 if (tree_view->priv->row_count == 0)
10947 /* If in the top third of a row, we drop before that row; if
10948 * in the bottom third, drop after that row; if in the middle,
10949 * and the row has children, drop into the row.
10951 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
10954 if (!pspp_sheet_view_get_path_at_pos (tree_view,
10963 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
10966 offset_into_row = cell_y;
10971 gtk_tree_path_free (tmp_path);
10975 third = cell.height / 3.0;
10979 if (offset_into_row < third)
10981 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
10983 else if (offset_into_row < (cell.height / 2.0))
10985 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
10987 else if (offset_into_row < third * 2.0)
10989 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
10993 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11002 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11004 * pspp_sheet_view_create_row_drag_icon:
11005 * @tree_view: a #PsppSheetView
11006 * @path: a #GtkTreePath in @tree_view
11008 * Creates a #GdkPixmap representation of the row at @path.
11009 * This image is used for a drag icon.
11011 * Return value: a newly-allocated pixmap of the drag icon.
11014 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11021 GdkRectangle background_area;
11022 GdkRectangle expose_area;
11025 /* start drawing inside the black outline */
11027 GdkDrawable *drawable;
11028 gint bin_window_width;
11031 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11032 g_return_val_if_fail (path != NULL, NULL);
11034 widget = GTK_WIDGET (tree_view);
11036 if (!gtk_widget_get_realized (widget))
11039 depth = gtk_tree_path_get_depth (path);
11041 _pspp_sheet_view_find_node (tree_view,
11048 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11055 background_area.y = y;
11056 background_area.height = ROW_HEIGHT (tree_view);
11058 gdk_drawable_get_size (tree_view->priv->bin_window,
11059 &bin_window_width, NULL);
11061 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11062 bin_window_width + 2,
11063 background_area.height + 2,
11068 expose_area.width = bin_window_width + 2;
11069 expose_area.height = background_area.height + 2;
11071 gdk_draw_rectangle (drawable,
11072 widget->style->base_gc [gtk_widget_get_state (widget)],
11075 bin_window_width + 2,
11076 background_area.height + 2);
11078 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11080 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11082 list = (rtl ? list->prev : list->next))
11084 PsppSheetViewColumn *column = list->data;
11085 GdkRectangle cell_area;
11086 gint vertical_separator;
11088 if (!column->visible)
11091 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11093 background_area.x = cell_offset;
11094 background_area.width = column->width;
11096 gtk_widget_style_get (widget,
11097 "vertical-separator", &vertical_separator,
11100 cell_area = background_area;
11102 cell_area.y += vertical_separator / 2;
11103 cell_area.height -= vertical_separator;
11105 if (pspp_sheet_view_column_cell_is_visible (column))
11106 _pspp_sheet_view_column_cell_render (column,
11112 cell_offset += column->width;
11115 gdk_draw_rectangle (drawable,
11116 widget->style->black_gc,
11119 bin_window_width + 1,
11120 background_area.height + 1);
11127 * pspp_sheet_view_set_destroy_count_func:
11128 * @tree_view: A #PsppSheetView
11129 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11130 * @data: (allow-none): User data to be passed to @func, or %NULL
11131 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11133 * This function should almost never be used. It is meant for private use by
11134 * ATK for determining the number of visible children that are removed when a row is deleted.
11137 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11138 PsppSheetDestroyCountFunc func,
11140 GDestroyNotify destroy)
11142 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11144 if (tree_view->priv->destroy_count_destroy)
11145 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11147 tree_view->priv->destroy_count_func = func;
11148 tree_view->priv->destroy_count_data = data;
11149 tree_view->priv->destroy_count_destroy = destroy;
11154 * Interactive search
11158 * pspp_sheet_view_set_enable_search:
11159 * @tree_view: A #PsppSheetView
11160 * @enable_search: %TRUE, if the user can search interactively
11162 * If @enable_search is set, then the user can type in text to search through
11163 * the tree interactively (this is sometimes called "typeahead find").
11165 * Note that even if this is %FALSE, the user can still initiate a search
11166 * using the "start-interactive-search" key binding.
11169 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11170 gboolean enable_search)
11172 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11174 enable_search = !!enable_search;
11176 if (tree_view->priv->enable_search != enable_search)
11178 tree_view->priv->enable_search = enable_search;
11179 g_object_notify (G_OBJECT (tree_view), "enable-search");
11184 * pspp_sheet_view_get_enable_search:
11185 * @tree_view: A #PsppSheetView
11187 * Returns whether or not the tree allows to start interactive searching
11188 * by typing in text.
11190 * Return value: whether or not to let the user search interactively
11193 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11195 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11197 return tree_view->priv->enable_search;
11202 * pspp_sheet_view_get_search_column:
11203 * @tree_view: A #PsppSheetView
11205 * Gets the column searched on by the interactive search code.
11207 * Return value: the column the interactive search code searches in.
11210 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11212 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11214 return (tree_view->priv->search_column);
11218 * pspp_sheet_view_set_search_column:
11219 * @tree_view: A #PsppSheetView
11220 * @column: the column of the model to search in, or -1 to disable searching
11222 * Sets @column as the column where the interactive search code should
11223 * search in for the current model.
11225 * If the search column is set, users can use the "start-interactive-search"
11226 * key binding to bring up search popup. The enable-search property controls
11227 * whether simply typing text will also start an interactive search.
11229 * Note that @column refers to a column of the current model. The search
11230 * column is reset to -1 when the model is changed.
11233 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11236 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11237 g_return_if_fail (column >= -1);
11239 if (tree_view->priv->search_column == column)
11242 tree_view->priv->search_column = column;
11243 g_object_notify (G_OBJECT (tree_view), "search-column");
11247 * pspp_sheet_view_get_search_equal_func:
11248 * @tree_view: A #PsppSheetView
11250 * Returns the compare function currently in use.
11252 * Return value: the currently used compare function for the search code.
11255 PsppSheetViewSearchEqualFunc
11256 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11258 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11260 return tree_view->priv->search_equal_func;
11264 * pspp_sheet_view_set_search_equal_func:
11265 * @tree_view: A #PsppSheetView
11266 * @search_equal_func: the compare function to use during the search
11267 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11268 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11270 * Sets the compare function for the interactive search capabilities; note
11271 * that somewhat like strcmp() returning 0 for equality
11272 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11275 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11276 PsppSheetViewSearchEqualFunc search_equal_func,
11277 gpointer search_user_data,
11278 GDestroyNotify search_destroy)
11280 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11281 g_return_if_fail (search_equal_func != NULL);
11283 if (tree_view->priv->search_destroy)
11284 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11286 tree_view->priv->search_equal_func = search_equal_func;
11287 tree_view->priv->search_user_data = search_user_data;
11288 tree_view->priv->search_destroy = search_destroy;
11289 if (tree_view->priv->search_equal_func == NULL)
11290 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11294 * pspp_sheet_view_get_search_entry:
11295 * @tree_view: A #PsppSheetView
11297 * Returns the #GtkEntry which is currently in use as interactive search
11298 * entry for @tree_view. In case the built-in entry is being used, %NULL
11299 * will be returned.
11301 * Return value: the entry currently in use as search entry.
11306 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11308 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11310 if (tree_view->priv->search_custom_entry_set)
11311 return GTK_ENTRY (tree_view->priv->search_entry);
11317 * pspp_sheet_view_set_search_entry:
11318 * @tree_view: A #PsppSheetView
11319 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11321 * Sets the entry which the interactive search code will use for this
11322 * @tree_view. This is useful when you want to provide a search entry
11323 * in our interface at all time at a fixed position. Passing %NULL for
11324 * @entry will make the interactive search code use the built-in popup
11330 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11333 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11334 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11336 if (tree_view->priv->search_custom_entry_set)
11338 if (tree_view->priv->search_entry_changed_id)
11340 g_signal_handler_disconnect (tree_view->priv->search_entry,
11341 tree_view->priv->search_entry_changed_id);
11342 tree_view->priv->search_entry_changed_id = 0;
11344 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11345 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11348 g_object_unref (tree_view->priv->search_entry);
11350 else if (tree_view->priv->search_window)
11352 gtk_widget_destroy (tree_view->priv->search_window);
11354 tree_view->priv->search_window = NULL;
11359 tree_view->priv->search_entry = g_object_ref (entry);
11360 tree_view->priv->search_custom_entry_set = TRUE;
11362 if (tree_view->priv->search_entry_changed_id == 0)
11364 tree_view->priv->search_entry_changed_id =
11365 g_signal_connect (tree_view->priv->search_entry, "changed",
11366 G_CALLBACK (pspp_sheet_view_search_init),
11370 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11371 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11374 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11378 tree_view->priv->search_entry = NULL;
11379 tree_view->priv->search_custom_entry_set = FALSE;
11384 * pspp_sheet_view_set_search_position_func:
11385 * @tree_view: A #PsppSheetView
11386 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11387 * to use the default search position function
11388 * @data: (allow-none): user data to pass to @func, or %NULL
11389 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11391 * Sets the function to use when positioning the search dialog.
11396 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11397 PsppSheetViewSearchPositionFunc func,
11398 gpointer user_data,
11399 GDestroyNotify destroy)
11401 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11403 if (tree_view->priv->search_position_destroy)
11404 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11406 tree_view->priv->search_position_func = func;
11407 tree_view->priv->search_position_user_data = user_data;
11408 tree_view->priv->search_position_destroy = destroy;
11409 if (tree_view->priv->search_position_func == NULL)
11410 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11414 * pspp_sheet_view_get_search_position_func:
11415 * @tree_view: A #PsppSheetView
11417 * Returns the positioning function currently in use.
11419 * Return value: the currently used function for positioning the search dialog.
11423 PsppSheetViewSearchPositionFunc
11424 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11426 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11428 return tree_view->priv->search_position_func;
11433 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11434 PsppSheetView *tree_view)
11436 if (tree_view->priv->disable_popdown)
11439 if (tree_view->priv->search_entry_changed_id)
11441 g_signal_handler_disconnect (tree_view->priv->search_entry,
11442 tree_view->priv->search_entry_changed_id);
11443 tree_view->priv->search_entry_changed_id = 0;
11445 if (tree_view->priv->typeselect_flush_timeout)
11447 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11448 tree_view->priv->typeselect_flush_timeout = 0;
11451 if (gtk_widget_get_visible (search_dialog))
11453 /* send focus-in event */
11454 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11455 gtk_widget_hide (search_dialog);
11456 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11457 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11462 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11463 GtkWidget *search_dialog,
11464 gpointer user_data)
11467 gint tree_x, tree_y;
11468 gint tree_width, tree_height;
11469 GdkWindow *tree_window = GTK_WIDGET (tree_view)->window;
11470 GdkScreen *screen = gdk_drawable_get_screen (tree_window);
11471 GtkRequisition requisition;
11473 GdkRectangle monitor;
11475 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11476 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11478 gtk_widget_realize (search_dialog);
11480 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11481 gdk_drawable_get_size (tree_window,
11484 gtk_widget_size_request (search_dialog, &requisition);
11486 if (tree_x + tree_width > gdk_screen_get_width (screen))
11487 x = gdk_screen_get_width (screen) - requisition.width;
11488 else if (tree_x + tree_width - requisition.width < 0)
11491 x = tree_x + tree_width - requisition.width;
11493 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11494 y = gdk_screen_get_height (screen) - requisition.height;
11495 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11498 y = tree_y + tree_height;
11500 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11504 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11508 PsppSheetView *tree_view = (PsppSheetView *)data;
11510 tree_view->priv->disable_popdown = 1;
11511 g_signal_connect (menu, "hide",
11512 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11515 /* Because we're visible but offscreen, we just set a flag in the preedit
11519 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11520 PsppSheetView *tree_view)
11522 tree_view->priv->imcontext_changed = 1;
11523 if (tree_view->priv->typeselect_flush_timeout)
11525 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11526 tree_view->priv->typeselect_flush_timeout =
11527 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11528 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11535 pspp_sheet_view_search_activate (GtkEntry *entry,
11536 PsppSheetView *tree_view)
11541 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11544 /* If we have a row selected and it's the cursor row, we activate
11546 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11548 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11550 _pspp_sheet_view_find_node (tree_view, path, &node);
11552 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11553 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11555 gtk_tree_path_free (path);
11560 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11562 PsppSheetView *tree_view = (PsppSheetView *)data;
11564 tree_view->priv->disable_popdown = 0;
11570 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11573 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11577 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11578 GdkEventAny *event,
11579 PsppSheetView *tree_view)
11581 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11583 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11589 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11590 GdkEventButton *event,
11591 PsppSheetView *tree_view)
11593 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11595 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11597 if (event->window == tree_view->priv->bin_window)
11598 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11604 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11605 GdkEventScroll *event,
11606 PsppSheetView *tree_view)
11608 gboolean retval = FALSE;
11610 if (event->direction == GDK_SCROLL_UP)
11612 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11615 else if (event->direction == GDK_SCROLL_DOWN)
11617 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11621 /* renew the flush timeout */
11622 if (retval && tree_view->priv->typeselect_flush_timeout
11623 && !tree_view->priv->search_custom_entry_set)
11625 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11626 tree_view->priv->typeselect_flush_timeout =
11627 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11628 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11636 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11637 GdkEventKey *event,
11638 PsppSheetView *tree_view)
11640 gboolean retval = FALSE;
11642 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11643 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11645 /* close window and cancel the search */
11646 if (!tree_view->priv->search_custom_entry_set
11647 && (event->keyval == GDK_Escape ||
11648 event->keyval == GDK_Tab ||
11649 event->keyval == GDK_KP_Tab ||
11650 event->keyval == GDK_ISO_Left_Tab))
11652 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11656 /* select previous matching iter */
11657 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11659 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11660 gtk_widget_error_bell (widget);
11665 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11666 && (event->keyval == GDK_g || event->keyval == GDK_G))
11668 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11669 gtk_widget_error_bell (widget);
11674 /* select next matching iter */
11675 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
11677 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11678 gtk_widget_error_bell (widget);
11683 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
11684 && (event->keyval == GDK_g || event->keyval == GDK_G))
11686 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11687 gtk_widget_error_bell (widget);
11692 /* renew the flush timeout */
11693 if (retval && tree_view->priv->typeselect_flush_timeout
11694 && !tree_view->priv->search_custom_entry_set)
11696 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11697 tree_view->priv->typeselect_flush_timeout =
11698 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11699 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11706 /* this function returns FALSE if there is a search string but
11707 * nothing was found, and TRUE otherwise.
11710 pspp_sheet_view_search_move (GtkWidget *window,
11711 PsppSheetView *tree_view,
11719 GtkTreeModel *model;
11720 PsppSheetSelection *selection;
11722 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
11724 g_return_val_if_fail (text != NULL, FALSE);
11726 len = strlen (text);
11728 if (up && tree_view->priv->selected_iter == 1)
11729 return strlen (text) < 1;
11731 len = strlen (text);
11736 model = pspp_sheet_view_get_model (tree_view);
11737 selection = pspp_sheet_view_get_selection (tree_view);
11740 pspp_sheet_selection_unselect_all (selection);
11741 if (!gtk_tree_model_get_iter_first (model, &iter))
11744 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
11745 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
11750 tree_view->priv->selected_iter += up?(-1):(1);
11755 /* return to old iter */
11757 gtk_tree_model_get_iter_first (model, &iter);
11758 pspp_sheet_view_search_iter (model, selection,
11760 &count, tree_view->priv->selected_iter);
11766 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
11770 gpointer search_data)
11772 gboolean retval = TRUE;
11774 gchar *normalized_string;
11775 gchar *normalized_key;
11776 gchar *case_normalized_string = NULL;
11777 gchar *case_normalized_key = NULL;
11778 GValue value = {0,};
11779 GValue transformed = {0,};
11781 gtk_tree_model_get_value (model, iter, column, &value);
11783 g_value_init (&transformed, G_TYPE_STRING);
11785 if (!g_value_transform (&value, &transformed))
11787 g_value_unset (&value);
11791 g_value_unset (&value);
11793 str = g_value_get_string (&transformed);
11796 g_value_unset (&transformed);
11800 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
11801 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
11803 if (normalized_string && normalized_key)
11805 case_normalized_string = g_utf8_casefold (normalized_string, -1);
11806 case_normalized_key = g_utf8_casefold (normalized_key, -1);
11808 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
11812 g_value_unset (&transformed);
11813 g_free (normalized_key);
11814 g_free (normalized_string);
11815 g_free (case_normalized_key);
11816 g_free (case_normalized_string);
11822 pspp_sheet_view_search_iter (GtkTreeModel *model,
11823 PsppSheetSelection *selection,
11832 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
11834 path = gtk_tree_model_get_path (model, iter);
11835 _pspp_sheet_view_find_node (tree_view, path, &node);
11839 gboolean done = FALSE;
11841 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
11846 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
11848 pspp_sheet_selection_select_iter (selection, iter);
11849 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
11852 gtk_tree_path_free (path);
11861 node = pspp_sheet_view_node_next (tree_view, node);
11867 has_next = gtk_tree_model_iter_next (model, iter);
11870 gtk_tree_path_next (path);
11873 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
11878 gtk_tree_path_free (path);
11880 /* we've run out of tree, done with this func */
11892 pspp_sheet_view_search_init (GtkWidget *entry,
11893 PsppSheetView *tree_view)
11899 GtkTreeModel *model;
11900 PsppSheetSelection *selection;
11902 g_return_if_fail (GTK_IS_ENTRY (entry));
11903 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11905 text = gtk_entry_get_text (GTK_ENTRY (entry));
11907 model = pspp_sheet_view_get_model (tree_view);
11908 selection = pspp_sheet_view_get_selection (tree_view);
11911 pspp_sheet_selection_unselect_all (selection);
11912 if (tree_view->priv->typeselect_flush_timeout
11913 && !tree_view->priv->search_custom_entry_set)
11915 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11916 tree_view->priv->typeselect_flush_timeout =
11917 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11918 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11925 if (!gtk_tree_model_get_iter_first (model, &iter))
11928 ret = pspp_sheet_view_search_iter (model, selection,
11933 tree_view->priv->selected_iter = 1;
11937 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
11938 PsppSheetView *tree_view)
11940 if (tree_view->priv->edited_column == NULL)
11943 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
11944 tree_view->priv->edited_column = NULL;
11946 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
11947 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
11949 g_signal_handlers_disconnect_by_func (cell_editable,
11950 pspp_sheet_view_remove_widget,
11952 g_signal_handlers_disconnect_by_func (cell_editable,
11953 pspp_sheet_view_editable_button_press_event,
11955 g_signal_handlers_disconnect_by_func (cell_editable,
11956 pspp_sheet_view_editable_clicked,
11959 gtk_container_remove (GTK_CONTAINER (tree_view),
11960 GTK_WIDGET (cell_editable));
11962 /* FIXME should only redraw a single node */
11963 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
11967 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
11968 GtkTreePath *cursor_path)
11971 GdkRectangle background_area;
11972 GdkRectangle cell_area;
11973 GtkCellEditable *editable_widget = NULL;
11974 gchar *path_string;
11975 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
11976 gint retval = FALSE;
11979 g_assert (tree_view->priv->focus_column);
11981 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
11984 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
11985 if (cursor_node < 0)
11988 path_string = gtk_tree_path_to_string (cursor_path);
11989 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
11991 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
11992 tree_view->priv->model,
11994 pspp_sheet_view_get_background_area (tree_view,
11996 tree_view->priv->focus_column,
11998 pspp_sheet_view_get_cell_area (tree_view,
12000 tree_view->priv->focus_column,
12003 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12012 if (editable_widget != NULL)
12016 GtkCellRenderer *cell;
12019 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12021 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12024 area.width -= right + left;
12026 pspp_sheet_view_real_start_editing (tree_view,
12027 tree_view->priv->focus_column,
12036 g_free (path_string);
12041 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12042 GdkEventButton *event,
12043 PsppSheetView *sheet_view)
12047 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12048 "pspp-sheet-view-node"));
12049 return pspp_sheet_view_row_head_clicked (sheet_view,
12051 sheet_view->priv->edited_column,
12056 pspp_sheet_view_editable_clicked (GtkButton *button,
12057 PsppSheetView *sheet_view)
12059 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12064 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12065 PsppSheetViewColumn *column,
12067 GtkCellEditable *cell_editable,
12068 GdkRectangle *cell_area,
12072 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12073 gint pre_val = tree_view->priv->vadjustment->value;
12074 GtkRequisition requisition;
12076 tree_view->priv->edited_column = column;
12077 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12079 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
12080 cell_area->y += pre_val - (int)tree_view->priv->vadjustment->value;
12082 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12083 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12084 tree_view->priv->anchor_column = column;
12086 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12088 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12090 if (requisition.height < cell_area->height)
12092 gint diff = cell_area->height - requisition.height;
12093 pspp_sheet_view_put (tree_view,
12094 GTK_WIDGET (cell_editable),
12095 cell_area->x, cell_area->y + diff/2,
12096 cell_area->width, requisition.height);
12100 pspp_sheet_view_put (tree_view,
12101 GTK_WIDGET (cell_editable),
12102 cell_area->x, cell_area->y,
12103 cell_area->width, cell_area->height);
12106 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12107 (GdkEvent *)event);
12109 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12110 g_signal_connect (cell_editable, "remove-widget",
12111 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12112 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12113 GTK_IS_BUTTON (cell_editable))
12115 g_signal_connect (cell_editable, "button-press-event",
12116 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12118 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12119 GINT_TO_POINTER (gtk_tree_path_get_indices (path)[0]));
12120 g_signal_connect (cell_editable, "clicked",
12121 G_CALLBACK (pspp_sheet_view_editable_clicked),
12127 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12128 gboolean cancel_editing)
12130 PsppSheetViewColumn *column;
12131 GtkCellRenderer *cell;
12133 if (tree_view->priv->edited_column == NULL)
12137 * This is very evil. We need to do this, because
12138 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12139 * later on. If pspp_sheet_view_row_changed notices
12140 * tree_view->priv->edited_column != NULL, it'll call
12141 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12143 * Please read that again if you intend to modify anything here.
12146 column = tree_view->priv->edited_column;
12147 tree_view->priv->edited_column = NULL;
12149 cell = _pspp_sheet_view_column_get_edited_cell (column);
12150 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12152 if (!cancel_editing)
12153 gtk_cell_editable_editing_done (column->editable_widget);
12155 tree_view->priv->edited_column = column;
12157 gtk_cell_editable_remove_widget (column->editable_widget);
12162 * pspp_sheet_view_set_hover_selection:
12163 * @tree_view: a #PsppSheetView
12164 * @hover: %TRUE to enable hover selection mode
12166 * Enables of disables the hover selection mode of @tree_view.
12167 * Hover selection makes the selected row follow the pointer.
12168 * Currently, this works only for the selection modes
12169 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12174 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12177 hover = hover != FALSE;
12179 if (hover != tree_view->priv->hover_selection)
12181 tree_view->priv->hover_selection = hover;
12183 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12188 * pspp_sheet_view_get_hover_selection:
12189 * @tree_view: a #PsppSheetView
12191 * Returns whether hover selection mode is turned on for @tree_view.
12193 * Return value: %TRUE if @tree_view is in hover selection mode
12198 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12200 return tree_view->priv->hover_selection;
12204 * pspp_sheet_view_set_rubber_banding:
12205 * @tree_view: a #PsppSheetView
12206 * @enable: %TRUE to enable rubber banding
12208 * Enables or disables rubber banding in @tree_view. If the selection mode is
12209 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12210 * banding will allow the user to select multiple rows by dragging the mouse.
12215 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12218 enable = enable != FALSE;
12220 if (enable != tree_view->priv->rubber_banding_enable)
12222 tree_view->priv->rubber_banding_enable = enable;
12224 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12229 * pspp_sheet_view_get_rubber_banding:
12230 * @tree_view: a #PsppSheetView
12232 * Returns whether rubber banding is turned on for @tree_view. If the
12233 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12234 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12235 * select multiple rows by dragging the mouse.
12237 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12242 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12244 return tree_view->priv->rubber_banding_enable;
12248 * pspp_sheet_view_is_rubber_banding_active:
12249 * @tree_view: a #PsppSheetView
12251 * Returns whether a rubber banding operation is currently being done
12254 * Return value: %TRUE if a rubber banding operation is currently being
12255 * done in @tree_view.
12260 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12262 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12264 if (tree_view->priv->rubber_banding_enable
12265 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12272 pspp_sheet_view_grab_notify (GtkWidget *widget,
12273 gboolean was_grabbed)
12275 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12277 tree_view->priv->in_grab = !was_grabbed;
12281 tree_view->priv->pressed_button = -1;
12283 if (tree_view->priv->rubber_band_status)
12284 pspp_sheet_view_stop_rubber_band (tree_view);
12289 pspp_sheet_view_state_changed (GtkWidget *widget,
12290 GtkStateType previous_state)
12292 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12294 if (gtk_widget_get_realized (widget))
12296 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
12297 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
12300 gtk_widget_queue_draw (widget);
12304 * pspp_sheet_view_get_grid_lines:
12305 * @tree_view: a #PsppSheetView
12307 * Returns which grid lines are enabled in @tree_view.
12309 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12314 PsppSheetViewGridLines
12315 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12317 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12319 return tree_view->priv->grid_lines;
12323 * pspp_sheet_view_set_grid_lines:
12324 * @tree_view: a #PsppSheetView
12325 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12328 * Sets which grid lines to draw in @tree_view.
12333 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12334 PsppSheetViewGridLines grid_lines)
12336 PsppSheetViewPrivate *priv;
12338 PsppSheetViewGridLines old_grid_lines;
12340 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12342 priv = tree_view->priv;
12343 widget = GTK_WIDGET (tree_view);
12345 old_grid_lines = priv->grid_lines;
12346 priv->grid_lines = grid_lines;
12348 if (gtk_widget_get_realized (widget))
12350 if (grid_lines == PSPP_SHEET_VIEW_GRID_LINES_NONE &&
12351 priv->grid_line_gc)
12353 g_object_unref (priv->grid_line_gc);
12354 priv->grid_line_gc = NULL;
12357 if (grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE &&
12358 !priv->grid_line_gc)
12362 gtk_widget_style_get (widget,
12363 "grid-line-width", &line_width,
12366 priv->grid_line_gc = gdk_gc_new (widget->window);
12367 gdk_gc_copy (priv->grid_line_gc, widget->style->black_gc);
12371 if (old_grid_lines != grid_lines)
12373 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12375 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12380 * pspp_sheet_view_get_special_cells:
12381 * @tree_view: a #PsppSheetView
12383 * Returns which grid lines are enabled in @tree_view.
12385 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12386 * the sheet view contain special cells.
12388 PsppSheetViewSpecialCells
12389 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12391 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12393 return tree_view->priv->special_cells;
12397 * pspp_sheet_view_set_special_cells:
12398 * @tree_view: a #PsppSheetView
12399 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12400 * the sheet view contain special cells.
12402 * Sets whether rows in the sheet view contain special cells, controlling the
12403 * rendering of row selections.
12406 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12407 PsppSheetViewSpecialCells special_cells)
12409 PsppSheetViewPrivate *priv;
12412 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12414 priv = tree_view->priv;
12415 widget = GTK_WIDGET (tree_view);
12417 if (priv->special_cells != special_cells)
12419 priv->special_cells = special_cells;
12420 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12421 g_object_notify (G_OBJECT (tree_view), "special-cells");
12426 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12428 /* XXX (re)calculate fixed_height if necessary */
12429 return tree_view->priv->fixed_height;
12433 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12436 g_return_if_fail (fixed_height > 0);
12438 if (tree_view->priv->fixed_height != fixed_height)
12440 tree_view->priv->fixed_height = fixed_height;
12441 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12443 if (!tree_view->priv->fixed_height_set)
12445 tree_view->priv->fixed_height_set = TRUE;
12446 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12451 * pspp_sheet_view_set_tooltip_row:
12452 * @tree_view: a #PsppSheetView
12453 * @tooltip: a #GtkTooltip
12454 * @path: a #GtkTreePath
12456 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12457 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12458 * See also gtk_tooltip_set_tip_area().
12463 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12464 GtkTooltip *tooltip,
12467 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12468 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12470 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12474 * pspp_sheet_view_set_tooltip_cell:
12475 * @tree_view: a #PsppSheetView
12476 * @tooltip: a #GtkTooltip
12477 * @path: (allow-none): a #GtkTreePath or %NULL
12478 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12479 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12481 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12482 * in common. For example if @path is %NULL and @column is set, the tip
12483 * area will be set to the full area covered by @column. See also
12484 * gtk_tooltip_set_tip_area().
12486 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12491 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12492 GtkTooltip *tooltip,
12494 PsppSheetViewColumn *column,
12495 GtkCellRenderer *cell)
12499 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12500 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12501 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12502 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12504 /* Determine x values. */
12505 if (column && cell)
12510 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12511 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12513 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12516 rect.width = width;
12522 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
12523 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12526 rect.width = tmp.width;
12531 rect.width = GTK_WIDGET (tree_view)->allocation.width;
12534 /* Determine y values. */
12539 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
12540 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12543 rect.height = tmp.height;
12548 rect.height = tree_view->priv->vadjustment->page_size;
12551 gtk_tooltip_set_tip_area (tooltip, &rect);
12555 * pspp_sheet_view_get_tooltip_context:
12556 * @tree_view: a #PsppSheetView
12557 * @x: the x coordinate (relative to widget coordinates)
12558 * @y: the y coordinate (relative to widget coordinates)
12559 * @keyboard_tip: whether this is a keyboard tooltip or not
12560 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
12561 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
12562 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
12564 * This function is supposed to be used in a #GtkWidget::query-tooltip
12565 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
12566 * which are received in the signal handler, should be passed to this
12567 * function without modification.
12569 * The return value indicates whether there is a tree view row at the given
12570 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
12571 * tooltips the row returned will be the cursor row. When %TRUE, then any of
12572 * @model, @path and @iter which have been provided will be set to point to
12573 * that row and the corresponding model. @x and @y will always be converted
12574 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
12576 * Return value: whether or not the given tooltip context points to a row.
12581 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
12584 gboolean keyboard_tip,
12585 GtkTreeModel **model,
12586 GtkTreePath **path,
12589 GtkTreePath *tmppath = NULL;
12591 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12592 g_return_val_if_fail (x != NULL, FALSE);
12593 g_return_val_if_fail (y != NULL, FALSE);
12597 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
12604 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
12607 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
12608 &tmppath, NULL, NULL, NULL))
12613 *model = pspp_sheet_view_get_model (tree_view);
12616 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
12622 gtk_tree_path_free (tmppath);
12628 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
12631 gboolean keyboard_tip,
12632 GtkTooltip *tooltip,
12635 GValue value = { 0, };
12636 GValue transformed = { 0, };
12639 GtkTreeModel *model;
12640 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12642 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
12645 &model, &path, &iter))
12648 gtk_tree_model_get_value (model, &iter,
12649 tree_view->priv->tooltip_column, &value);
12651 g_value_init (&transformed, G_TYPE_STRING);
12653 if (!g_value_transform (&value, &transformed))
12655 g_value_unset (&value);
12656 gtk_tree_path_free (path);
12661 g_value_unset (&value);
12663 if (!g_value_get_string (&transformed))
12665 g_value_unset (&transformed);
12666 gtk_tree_path_free (path);
12671 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
12672 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
12674 gtk_tree_path_free (path);
12675 g_value_unset (&transformed);
12681 * pspp_sheet_view_set_tooltip_column:
12682 * @tree_view: a #PsppSheetView
12683 * @column: an integer, which is a valid column number for @tree_view's model
12685 * If you only plan to have simple (text-only) tooltips on full rows, you
12686 * can use this function to have #PsppSheetView handle these automatically
12687 * for you. @column should be set to the column in @tree_view's model
12688 * containing the tooltip texts, or -1 to disable this feature.
12690 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
12691 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
12693 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
12694 * so &, <, etc have to be escaped in the text.
12699 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
12702 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12704 if (column == tree_view->priv->tooltip_column)
12709 g_signal_handlers_disconnect_by_func (tree_view,
12710 pspp_sheet_view_set_tooltip_query_cb,
12712 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
12716 if (tree_view->priv->tooltip_column == -1)
12718 g_signal_connect (tree_view, "query-tooltip",
12719 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
12720 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
12724 tree_view->priv->tooltip_column = column;
12725 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
12729 * pspp_sheet_view_get_tooltip_column:
12730 * @tree_view: a #PsppSheetView
12732 * Returns the column of @tree_view's model which is being used for
12733 * displaying tooltips on @tree_view's rows.
12735 * Return value: the index of the tooltip column that is currently being
12736 * used, or -1 if this is disabled.
12741 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
12743 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12745 return tree_view->priv->tooltip_column;
12749 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
12750 GValue *return_accu,
12751 const GValue *handler_return,
12754 gboolean continue_emission;
12755 gboolean signal_handled;
12757 signal_handled = g_value_get_boolean (handler_return);
12758 g_value_set_boolean (return_accu, signal_handled);
12759 continue_emission = !signal_handled;
12761 return continue_emission;
12765 pspp_sheet_view_grid_lines_get_type (void)
12767 static GType etype = 0;
12768 if (G_UNLIKELY(etype == 0)) {
12769 static const GEnumValue values[] = {
12770 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
12771 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
12772 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
12773 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
12776 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
12782 pspp_sheet_view_special_cells_get_type (void)
12784 static GType etype = 0;
12785 if (G_UNLIKELY(etype == 0)) {
12786 static const GEnumValue values[] = {
12787 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
12788 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
12789 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
12792 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);