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 };
432 static GtkBindingSet *edit_bindings;
439 G_DEFINE_TYPE_WITH_CODE (PsppSheetView, pspp_sheet_view, GTK_TYPE_CONTAINER,
440 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
441 pspp_sheet_view_buildable_init))
444 pspp_sheet_view_class_init (PsppSheetViewClass *class)
446 GObjectClass *o_class;
447 GtkObjectClass *object_class;
448 GtkWidgetClass *widget_class;
449 GtkContainerClass *container_class;
450 GtkBindingSet *binding_set[2];
453 binding_set[0] = gtk_binding_set_by_class (class);
455 binding_set[1] = gtk_binding_set_new ("PsppSheetViewEditing");
456 edit_bindings = binding_set[1];
458 o_class = (GObjectClass *) class;
459 object_class = (GtkObjectClass *) class;
460 widget_class = (GtkWidgetClass *) class;
461 container_class = (GtkContainerClass *) class;
463 /* GObject signals */
464 o_class->set_property = pspp_sheet_view_set_property;
465 o_class->get_property = pspp_sheet_view_get_property;
466 o_class->finalize = pspp_sheet_view_finalize;
468 /* GtkObject signals */
469 object_class->destroy = pspp_sheet_view_destroy;
471 /* GtkWidget signals */
472 widget_class->map = pspp_sheet_view_map;
473 widget_class->realize = pspp_sheet_view_realize;
474 widget_class->unrealize = pspp_sheet_view_unrealize;
475 widget_class->size_request = pspp_sheet_view_size_request;
476 widget_class->size_allocate = pspp_sheet_view_size_allocate;
477 widget_class->button_press_event = pspp_sheet_view_button_press;
478 widget_class->button_release_event = pspp_sheet_view_button_release;
479 widget_class->grab_broken_event = pspp_sheet_view_grab_broken;
480 /*widget_class->configure_event = pspp_sheet_view_configure;*/
481 widget_class->motion_notify_event = pspp_sheet_view_motion;
482 widget_class->expose_event = pspp_sheet_view_expose;
483 widget_class->key_press_event = pspp_sheet_view_key_press;
484 widget_class->key_release_event = pspp_sheet_view_key_release;
485 widget_class->enter_notify_event = pspp_sheet_view_enter_notify;
486 widget_class->leave_notify_event = pspp_sheet_view_leave_notify;
487 widget_class->focus_out_event = pspp_sheet_view_focus_out;
488 widget_class->drag_begin = pspp_sheet_view_drag_begin;
489 widget_class->drag_end = pspp_sheet_view_drag_end;
490 widget_class->drag_data_get = pspp_sheet_view_drag_data_get;
491 widget_class->drag_data_delete = pspp_sheet_view_drag_data_delete;
492 widget_class->drag_leave = pspp_sheet_view_drag_leave;
493 widget_class->drag_motion = pspp_sheet_view_drag_motion;
494 widget_class->drag_drop = pspp_sheet_view_drag_drop;
495 widget_class->drag_data_received = pspp_sheet_view_drag_data_received;
496 widget_class->focus = pspp_sheet_view_focus;
497 widget_class->grab_focus = pspp_sheet_view_grab_focus;
498 widget_class->style_set = pspp_sheet_view_style_set;
499 widget_class->grab_notify = pspp_sheet_view_grab_notify;
500 widget_class->state_changed = pspp_sheet_view_state_changed;
502 /* GtkContainer signals */
503 container_class->remove = pspp_sheet_view_remove;
504 container_class->forall = pspp_sheet_view_forall;
505 container_class->set_focus_child = pspp_sheet_view_set_focus_child;
507 class->set_scroll_adjustments = pspp_sheet_view_set_adjustments;
508 class->move_cursor = pspp_sheet_view_real_move_cursor;
509 class->select_all = pspp_sheet_view_real_select_all;
510 class->unselect_all = pspp_sheet_view_real_unselect_all;
511 class->select_cursor_row = pspp_sheet_view_real_select_cursor_row;
512 class->toggle_cursor_row = pspp_sheet_view_real_toggle_cursor_row;
513 class->start_interactive_search = pspp_sheet_view_start_interactive_search;
517 g_object_class_install_property (o_class,
519 g_param_spec_object ("model",
520 P_("TreeView Model"),
521 P_("The model for the tree view"),
523 GTK_PARAM_READWRITE));
525 g_object_class_install_property (o_class,
527 g_param_spec_object ("hadjustment",
528 P_("Horizontal Adjustment"),
529 P_("Horizontal Adjustment for the widget"),
531 GTK_PARAM_READWRITE));
533 g_object_class_install_property (o_class,
535 g_param_spec_object ("vadjustment",
536 P_("Vertical Adjustment"),
537 P_("Vertical Adjustment for the widget"),
539 GTK_PARAM_READWRITE));
541 g_object_class_install_property (o_class,
542 PROP_HEADERS_VISIBLE,
543 g_param_spec_boolean ("headers-visible",
544 P_("Headers Visible"),
545 P_("Show the column header buttons"),
547 GTK_PARAM_READWRITE));
549 g_object_class_install_property (o_class,
550 PROP_HEADERS_CLICKABLE,
551 g_param_spec_boolean ("headers-clickable",
552 P_("Headers Clickable"),
553 P_("Column headers respond to click events"),
555 GTK_PARAM_READWRITE));
557 g_object_class_install_property (o_class,
559 g_param_spec_boolean ("reorderable",
561 P_("View is reorderable"),
563 GTK_PARAM_READWRITE));
565 g_object_class_install_property (o_class,
567 g_param_spec_boolean ("rules-hint",
569 P_("Set a hint to the theme engine to draw rows in alternating colors"),
571 GTK_PARAM_READWRITE));
573 g_object_class_install_property (o_class,
575 g_param_spec_boolean ("enable-search",
577 P_("View allows user to search through columns interactively"),
579 GTK_PARAM_READWRITE));
581 g_object_class_install_property (o_class,
583 g_param_spec_int ("search-column",
585 P_("Model column to search through during interactive search"),
589 GTK_PARAM_READWRITE));
592 * PsppSheetView:hover-selection:
594 * Enables of disables the hover selection mode of @tree_view.
595 * Hover selection makes the selected row follow the pointer.
596 * Currently, this works only for the selection modes
597 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
599 * This mode is primarily intended for treeviews in popups, e.g.
600 * in #GtkComboBox or #GtkEntryCompletion.
604 g_object_class_install_property (o_class,
605 PROP_HOVER_SELECTION,
606 g_param_spec_boolean ("hover-selection",
607 P_("Hover Selection"),
608 P_("Whether the selection should follow the pointer"),
610 GTK_PARAM_READWRITE));
612 g_object_class_install_property (o_class,
614 g_param_spec_boolean ("rubber-banding",
615 P_("Rubber Banding"),
616 P_("Whether to enable selection of multiple items by dragging the mouse pointer"),
618 GTK_PARAM_READWRITE));
620 g_object_class_install_property (o_class,
621 PROP_ENABLE_GRID_LINES,
622 g_param_spec_enum ("enable-grid-lines",
623 P_("Enable Grid Lines"),
624 P_("Whether grid lines should be drawn in the tree view"),
625 PSPP_TYPE_SHEET_VIEW_GRID_LINES,
626 PSPP_SHEET_VIEW_GRID_LINES_NONE,
627 GTK_PARAM_READWRITE));
629 g_object_class_install_property (o_class,
631 g_param_spec_int ("tooltip-column",
632 P_("Tooltip Column"),
633 P_("The column in the model containing the tooltip texts for the rows"),
637 GTK_PARAM_READWRITE));
639 g_object_class_install_property (o_class,
641 g_param_spec_enum ("special-cells",
643 P_("Whether rows have special cells."),
644 PSPP_TYPE_SHEET_VIEW_SPECIAL_CELLS,
645 PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT,
646 GTK_PARAM_READWRITE));
648 g_object_class_install_property (o_class,
650 g_param_spec_int ("fixed-height",
652 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."),
656 GTK_PARAM_READWRITE));
658 g_object_class_install_property (o_class,
659 PROP_FIXED_HEIGHT_SET,
660 g_param_spec_boolean ("fixed-height-set",
661 P_("Fixed Height Set"),
662 P_("Whether fixed-height was set externally."),
664 GTK_PARAM_READWRITE));
666 /* Style properties */
667 #define _TREE_VIEW_EXPANDER_SIZE 12
668 #define _TREE_VIEW_VERTICAL_SEPARATOR 2
669 #define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
671 gtk_widget_class_install_style_property (widget_class,
672 g_param_spec_int ("expander-size",
674 P_("Size of the expander arrow"),
677 _TREE_VIEW_EXPANDER_SIZE,
678 GTK_PARAM_READABLE));
680 gtk_widget_class_install_style_property (widget_class,
681 g_param_spec_int ("vertical-separator",
682 P_("Vertical Separator Width"),
683 P_("Vertical space between cells. Must be an even number"),
686 _TREE_VIEW_VERTICAL_SEPARATOR,
687 GTK_PARAM_READABLE));
689 gtk_widget_class_install_style_property (widget_class,
690 g_param_spec_int ("horizontal-separator",
691 P_("Horizontal Separator Width"),
692 P_("Horizontal space between cells. Must be an even number"),
695 _TREE_VIEW_HORIZONTAL_SEPARATOR,
696 GTK_PARAM_READABLE));
698 gtk_widget_class_install_style_property (widget_class,
699 g_param_spec_boolean ("allow-rules",
701 P_("Allow drawing of alternating color rows"),
703 GTK_PARAM_READABLE));
705 gtk_widget_class_install_style_property (widget_class,
706 g_param_spec_boxed ("even-row-color",
707 P_("Even Row Color"),
708 P_("Color to use for even rows"),
710 GTK_PARAM_READABLE));
712 gtk_widget_class_install_style_property (widget_class,
713 g_param_spec_boxed ("odd-row-color",
715 P_("Color to use for odd rows"),
717 GTK_PARAM_READABLE));
719 gtk_widget_class_install_style_property (widget_class,
720 g_param_spec_boolean ("row-ending-details",
721 P_("Row Ending details"),
722 P_("Enable extended row background theming"),
724 GTK_PARAM_READABLE));
726 gtk_widget_class_install_style_property (widget_class,
727 g_param_spec_int ("grid-line-width",
728 P_("Grid line width"),
729 P_("Width, in pixels, of the tree view grid lines"),
731 GTK_PARAM_READABLE));
733 gtk_widget_class_install_style_property (widget_class,
734 g_param_spec_int ("tree-line-width",
735 P_("Tree line width"),
736 P_("Width, in pixels, of the tree view lines"),
738 GTK_PARAM_READABLE));
740 gtk_widget_class_install_style_property (widget_class,
741 g_param_spec_string ("tree-line-pattern",
742 P_("Tree line pattern"),
743 P_("Dash pattern used to draw the tree view lines"),
745 GTK_PARAM_READABLE));
749 * PsppSheetView::set-scroll-adjustments
750 * @horizontal: the horizontal #GtkAdjustment
751 * @vertical: the vertical #GtkAdjustment
753 * Set the scroll adjustments for the tree view. Usually scrolled containers
754 * like #GtkScrolledWindow will emit this signal to connect two instances
755 * of #GtkScrollbar to the scroll directions of the #PsppSheetView.
757 widget_class->set_scroll_adjustments_signal =
758 g_signal_new ("set-scroll-adjustments",
759 G_TYPE_FROM_CLASS (o_class),
760 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
761 G_STRUCT_OFFSET (PsppSheetViewClass, set_scroll_adjustments),
763 psppire_marshal_VOID__OBJECT_OBJECT,
766 GTK_TYPE_ADJUSTMENT);
769 * PsppSheetView::row-activated:
770 * @tree_view: the object on which the signal is emitted
771 * @path: the #GtkTreePath for the activated row
772 * @column: the #PsppSheetViewColumn in which the activation occurred
774 * The "row-activated" signal is emitted when the method
775 * pspp_sheet_view_row_activated() is called or the user double clicks
776 * a treeview row. It is also emitted when a non-editable row is
777 * selected and one of the keys: Space, Shift+Space, Return or
780 * For selection handling refer to the <link linkend="TreeWidget">tree
781 * widget conceptual overview</link> as well as #PsppSheetSelection.
783 tree_view_signals[ROW_ACTIVATED] =
784 g_signal_new ("row-activated",
785 G_TYPE_FROM_CLASS (o_class),
786 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
787 G_STRUCT_OFFSET (PsppSheetViewClass, row_activated),
789 psppire_marshal_VOID__BOXED_OBJECT,
792 PSPP_TYPE_SHEET_VIEW_COLUMN);
795 * PsppSheetView::columns-changed:
796 * @tree_view: the object on which the signal is emitted
798 * The number of columns of the treeview has changed.
800 tree_view_signals[COLUMNS_CHANGED] =
801 g_signal_new ("columns-changed",
802 G_TYPE_FROM_CLASS (o_class),
804 G_STRUCT_OFFSET (PsppSheetViewClass, columns_changed),
806 g_cclosure_marshal_VOID__VOID,
810 * PsppSheetView::cursor-changed:
811 * @tree_view: the object on which the signal is emitted
813 * The position of the cursor (focused cell) has changed.
815 tree_view_signals[CURSOR_CHANGED] =
816 g_signal_new ("cursor-changed",
817 G_TYPE_FROM_CLASS (o_class),
819 G_STRUCT_OFFSET (PsppSheetViewClass, cursor_changed),
821 g_cclosure_marshal_VOID__VOID,
824 tree_view_signals[MOVE_CURSOR] =
825 g_signal_new ("move-cursor",
826 G_TYPE_FROM_CLASS (object_class),
827 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
828 G_STRUCT_OFFSET (PsppSheetViewClass, move_cursor),
830 psppire_marshal_BOOLEAN__ENUM_INT,
832 GTK_TYPE_MOVEMENT_STEP,
835 tree_view_signals[SELECT_ALL] =
836 g_signal_new ("select-all",
837 G_TYPE_FROM_CLASS (object_class),
838 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
839 G_STRUCT_OFFSET (PsppSheetViewClass, select_all),
841 psppire_marshal_BOOLEAN__VOID,
844 tree_view_signals[UNSELECT_ALL] =
845 g_signal_new ("unselect-all",
846 G_TYPE_FROM_CLASS (object_class),
847 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
848 G_STRUCT_OFFSET (PsppSheetViewClass, unselect_all),
850 psppire_marshal_BOOLEAN__VOID,
853 tree_view_signals[SELECT_CURSOR_ROW] =
854 g_signal_new ("select-cursor-row",
855 G_TYPE_FROM_CLASS (object_class),
856 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
857 G_STRUCT_OFFSET (PsppSheetViewClass, select_cursor_row),
859 psppire_marshal_BOOLEAN__BOOLEAN,
863 tree_view_signals[TOGGLE_CURSOR_ROW] =
864 g_signal_new ("toggle-cursor-row",
865 G_TYPE_FROM_CLASS (object_class),
866 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
867 G_STRUCT_OFFSET (PsppSheetViewClass, toggle_cursor_row),
869 psppire_marshal_BOOLEAN__VOID,
872 tree_view_signals[START_INTERACTIVE_SEARCH] =
873 g_signal_new ("start-interactive-search",
874 G_TYPE_FROM_CLASS (object_class),
875 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
876 G_STRUCT_OFFSET (PsppSheetViewClass, start_interactive_search),
878 psppire_marshal_BOOLEAN__VOID,
882 for (i = 0; i < 2; i++)
884 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Up, 0, TRUE,
885 GTK_MOVEMENT_DISPLAY_LINES, -1);
886 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Up, 0, TRUE,
887 GTK_MOVEMENT_DISPLAY_LINES, -1);
889 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Down, 0, TRUE,
890 GTK_MOVEMENT_DISPLAY_LINES, 1);
891 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Down, 0, TRUE,
892 GTK_MOVEMENT_DISPLAY_LINES, 1);
894 pspp_sheet_view_add_move_binding (binding_set[i], GDK_p, GDK_CONTROL_MASK, FALSE,
895 GTK_MOVEMENT_DISPLAY_LINES, -1);
897 pspp_sheet_view_add_move_binding (binding_set[i], GDK_n, GDK_CONTROL_MASK, FALSE,
898 GTK_MOVEMENT_DISPLAY_LINES, 1);
900 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Home, 0, TRUE,
901 GTK_MOVEMENT_BUFFER_ENDS, -1);
902 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Home, 0, TRUE,
903 GTK_MOVEMENT_BUFFER_ENDS, -1);
905 pspp_sheet_view_add_move_binding (binding_set[i], GDK_End, 0, TRUE,
906 GTK_MOVEMENT_BUFFER_ENDS, 1);
907 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_End, 0, TRUE,
908 GTK_MOVEMENT_BUFFER_ENDS, 1);
910 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Up, 0, TRUE,
911 GTK_MOVEMENT_PAGES, -1);
912 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Up, 0, TRUE,
913 GTK_MOVEMENT_PAGES, -1);
915 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Down, 0, TRUE,
916 GTK_MOVEMENT_PAGES, 1);
917 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Down, 0, TRUE,
918 GTK_MOVEMENT_PAGES, 1);
921 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, 0, "move-cursor", 2,
922 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
925 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, 0, "move-cursor", 2,
926 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
929 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, 0, "move-cursor", 2,
930 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
933 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, 0, "move-cursor", 2,
934 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
937 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, GDK_CONTROL_MASK,
939 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
942 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, GDK_CONTROL_MASK,
944 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
947 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, GDK_CONTROL_MASK,
949 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
952 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, GDK_CONTROL_MASK,
954 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
957 gtk_binding_entry_add_signal (binding_set[i], GDK_f, GDK_CONTROL_MASK, "start-interactive-search", 0);
959 gtk_binding_entry_add_signal (binding_set[i], GDK_F, GDK_CONTROL_MASK, "start-interactive-search", 0);
962 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
963 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
965 gtk_binding_entry_add_signal (binding_set[0], GDK_a, GDK_CONTROL_MASK, "select-all", 0);
966 gtk_binding_entry_add_signal (binding_set[0], GDK_slash, GDK_CONTROL_MASK, "select-all", 0);
968 gtk_binding_entry_add_signal (binding_set[0], GDK_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0);
969 gtk_binding_entry_add_signal (binding_set[0], GDK_backslash, GDK_CONTROL_MASK, "unselect-all", 0);
971 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_SHIFT_MASK, "select-cursor-row", 1,
972 G_TYPE_BOOLEAN, TRUE);
973 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", 1,
974 G_TYPE_BOOLEAN, TRUE);
976 gtk_binding_entry_add_signal (binding_set[0], GDK_space, 0, "select-cursor-row", 1,
977 G_TYPE_BOOLEAN, TRUE);
978 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, 0, "select-cursor-row", 1,
979 G_TYPE_BOOLEAN, TRUE);
980 gtk_binding_entry_add_signal (binding_set[0], GDK_Return, 0, "select-cursor-row", 1,
981 G_TYPE_BOOLEAN, TRUE);
982 gtk_binding_entry_add_signal (binding_set[0], GDK_ISO_Enter, 0, "select-cursor-row", 1,
983 G_TYPE_BOOLEAN, TRUE);
984 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Enter, 0, "select-cursor-row", 1,
985 G_TYPE_BOOLEAN, TRUE);
987 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, 0, "select-cursor-parent", 0);
988 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", 0);
990 g_type_class_add_private (o_class, sizeof (PsppSheetViewPrivate));
994 pspp_sheet_view_buildable_init (GtkBuildableIface *iface)
996 iface->add_child = pspp_sheet_view_buildable_add_child;
1000 pspp_sheet_view_init (PsppSheetView *tree_view)
1002 tree_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (tree_view, PSPP_TYPE_SHEET_VIEW, PsppSheetViewPrivate);
1004 gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
1005 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (tree_view), FALSE);
1007 tree_view->priv->flags = PSPP_SHEET_VIEW_DRAW_KEYFOCUS
1008 | PSPP_SHEET_VIEW_HEADERS_VISIBLE;
1010 /* We need some padding */
1011 tree_view->priv->selected = range_tower_create ();
1012 tree_view->priv->dy = 0;
1013 tree_view->priv->cursor_offset = 0;
1014 tree_view->priv->n_columns = 0;
1015 tree_view->priv->header_height = 1;
1016 tree_view->priv->x_drag = 0;
1017 tree_view->priv->drag_pos = -1;
1018 tree_view->priv->header_has_focus = FALSE;
1019 tree_view->priv->pressed_button = -1;
1020 tree_view->priv->press_start_x = -1;
1021 tree_view->priv->press_start_y = -1;
1022 tree_view->priv->reorderable = FALSE;
1023 tree_view->priv->presize_handler_timer = 0;
1024 tree_view->priv->scroll_sync_timer = 0;
1025 tree_view->priv->fixed_height = -1;
1026 tree_view->priv->fixed_height_set = FALSE;
1027 pspp_sheet_view_set_adjustments (tree_view, NULL, NULL);
1028 tree_view->priv->selection = _pspp_sheet_selection_new_with_tree_view (tree_view);
1029 tree_view->priv->enable_search = TRUE;
1030 tree_view->priv->search_column = -1;
1031 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
1032 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
1033 tree_view->priv->search_custom_entry_set = FALSE;
1034 tree_view->priv->typeselect_flush_timeout = 0;
1035 tree_view->priv->init_hadjust_value = TRUE;
1036 tree_view->priv->width = 0;
1038 tree_view->priv->hover_selection = FALSE;
1040 tree_view->priv->rubber_banding_enable = FALSE;
1042 tree_view->priv->grid_lines = PSPP_SHEET_VIEW_GRID_LINES_NONE;
1044 tree_view->priv->tooltip_column = -1;
1046 tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT;
1048 tree_view->priv->post_validation_flag = FALSE;
1050 tree_view->priv->last_button_x = -1;
1051 tree_view->priv->last_button_y = -1;
1053 tree_view->priv->event_last_x = -10000;
1054 tree_view->priv->event_last_y = -10000;
1056 tree_view->priv->prelight_node = -1;
1057 tree_view->priv->rubber_band_start_node = -1;
1058 tree_view->priv->rubber_band_end_node = -1;
1060 tree_view->priv->anchor_column = NULL;
1062 tree_view->priv->button_style = NULL;
1071 pspp_sheet_view_set_property (GObject *object,
1073 const GValue *value,
1076 PsppSheetView *tree_view;
1078 tree_view = PSPP_SHEET_VIEW (object);
1083 pspp_sheet_view_set_model (tree_view, g_value_get_object (value));
1085 case PROP_HADJUSTMENT:
1086 pspp_sheet_view_set_hadjustment (tree_view, g_value_get_object (value));
1088 case PROP_VADJUSTMENT:
1089 pspp_sheet_view_set_vadjustment (tree_view, g_value_get_object (value));
1091 case PROP_HEADERS_VISIBLE:
1092 pspp_sheet_view_set_headers_visible (tree_view, g_value_get_boolean (value));
1094 case PROP_HEADERS_CLICKABLE:
1095 pspp_sheet_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
1097 case PROP_REORDERABLE:
1098 pspp_sheet_view_set_reorderable (tree_view, g_value_get_boolean (value));
1100 case PROP_RULES_HINT:
1101 pspp_sheet_view_set_rules_hint (tree_view, g_value_get_boolean (value));
1103 case PROP_ENABLE_SEARCH:
1104 pspp_sheet_view_set_enable_search (tree_view, g_value_get_boolean (value));
1106 case PROP_SEARCH_COLUMN:
1107 pspp_sheet_view_set_search_column (tree_view, g_value_get_int (value));
1109 case PROP_HOVER_SELECTION:
1110 tree_view->priv->hover_selection = g_value_get_boolean (value);
1112 case PROP_RUBBER_BANDING:
1113 tree_view->priv->rubber_banding_enable = g_value_get_boolean (value);
1115 case PROP_ENABLE_GRID_LINES:
1116 pspp_sheet_view_set_grid_lines (tree_view, g_value_get_enum (value));
1118 case PROP_TOOLTIP_COLUMN:
1119 pspp_sheet_view_set_tooltip_column (tree_view, g_value_get_int (value));
1121 case PROP_SPECIAL_CELLS:
1122 pspp_sheet_view_set_special_cells (tree_view, g_value_get_enum (value));
1124 case PROP_FIXED_HEIGHT:
1125 pspp_sheet_view_set_fixed_height (tree_view, g_value_get_int (value));
1127 case PROP_FIXED_HEIGHT_SET:
1128 if (g_value_get_boolean (value))
1130 if (!tree_view->priv->fixed_height_set
1131 && tree_view->priv->fixed_height >= 0)
1133 tree_view->priv->fixed_height_set = true;
1134 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1139 if (tree_view->priv->fixed_height_set)
1141 tree_view->priv->fixed_height_set = false;
1142 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1143 install_presize_handler (tree_view);
1148 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1154 pspp_sheet_view_get_property (GObject *object,
1159 PsppSheetView *tree_view;
1161 tree_view = PSPP_SHEET_VIEW (object);
1166 g_value_set_object (value, tree_view->priv->model);
1168 case PROP_HADJUSTMENT:
1169 g_value_set_object (value, tree_view->priv->hadjustment);
1171 case PROP_VADJUSTMENT:
1172 g_value_set_object (value, tree_view->priv->vadjustment);
1174 case PROP_HEADERS_VISIBLE:
1175 g_value_set_boolean (value, pspp_sheet_view_get_headers_visible (tree_view));
1177 case PROP_HEADERS_CLICKABLE:
1178 g_value_set_boolean (value, pspp_sheet_view_get_headers_clickable (tree_view));
1180 case PROP_REORDERABLE:
1181 g_value_set_boolean (value, tree_view->priv->reorderable);
1183 case PROP_RULES_HINT:
1184 g_value_set_boolean (value, tree_view->priv->has_rules);
1186 case PROP_ENABLE_SEARCH:
1187 g_value_set_boolean (value, tree_view->priv->enable_search);
1189 case PROP_SEARCH_COLUMN:
1190 g_value_set_int (value, tree_view->priv->search_column);
1192 case PROP_HOVER_SELECTION:
1193 g_value_set_boolean (value, tree_view->priv->hover_selection);
1195 case PROP_RUBBER_BANDING:
1196 g_value_set_boolean (value, tree_view->priv->rubber_banding_enable);
1198 case PROP_ENABLE_GRID_LINES:
1199 g_value_set_enum (value, tree_view->priv->grid_lines);
1201 case PROP_TOOLTIP_COLUMN:
1202 g_value_set_int (value, tree_view->priv->tooltip_column);
1204 case PROP_SPECIAL_CELLS:
1205 g_value_set_enum (value, tree_view->priv->special_cells);
1207 case PROP_FIXED_HEIGHT:
1208 g_value_set_int (value, pspp_sheet_view_get_fixed_height (tree_view));
1210 case PROP_FIXED_HEIGHT_SET:
1211 g_value_set_boolean (value, tree_view->priv->fixed_height_set);
1214 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1220 pspp_sheet_view_finalize (GObject *object)
1222 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->finalize (object);
1228 pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
1229 GtkBuilder *builder,
1233 pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), PSPP_SHEET_VIEW_COLUMN (child));
1236 /* GtkObject Methods
1240 pspp_sheet_view_destroy (GtkObject *object)
1242 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1245 pspp_sheet_view_stop_editing (tree_view, TRUE);
1247 if (tree_view->priv->selected != NULL)
1249 range_tower_destroy (tree_view->priv->selected);
1250 tree_view->priv->selected = NULL;
1253 if (tree_view->priv->columns != NULL)
1255 list = tree_view->priv->columns;
1258 PsppSheetViewColumn *column;
1259 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1261 pspp_sheet_view_remove_column (tree_view, column);
1263 tree_view->priv->columns = NULL;
1266 tree_view->priv->prelight_node = -1;
1268 if (tree_view->priv->selection != NULL)
1270 _pspp_sheet_selection_set_tree_view (tree_view->priv->selection, NULL);
1271 g_object_unref (tree_view->priv->selection);
1272 tree_view->priv->selection = NULL;
1275 if (tree_view->priv->scroll_to_path != NULL)
1277 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1278 tree_view->priv->scroll_to_path = NULL;
1281 if (tree_view->priv->drag_dest_row != NULL)
1283 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
1284 tree_view->priv->drag_dest_row = NULL;
1287 if (tree_view->priv->top_row != NULL)
1289 gtk_tree_row_reference_free (tree_view->priv->top_row);
1290 tree_view->priv->top_row = NULL;
1293 if (tree_view->priv->column_drop_func_data &&
1294 tree_view->priv->column_drop_func_data_destroy)
1296 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
1297 tree_view->priv->column_drop_func_data = NULL;
1300 if (tree_view->priv->destroy_count_destroy &&
1301 tree_view->priv->destroy_count_data)
1303 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
1304 tree_view->priv->destroy_count_data = NULL;
1307 gtk_tree_row_reference_free (tree_view->priv->cursor);
1308 tree_view->priv->cursor = NULL;
1310 gtk_tree_row_reference_free (tree_view->priv->anchor);
1311 tree_view->priv->anchor = NULL;
1313 /* destroy interactive search dialog */
1314 if (tree_view->priv->search_window)
1316 gtk_widget_destroy (tree_view->priv->search_window);
1317 tree_view->priv->search_window = NULL;
1318 tree_view->priv->search_entry = NULL;
1319 if (tree_view->priv->typeselect_flush_timeout)
1321 g_source_remove (tree_view->priv->typeselect_flush_timeout);
1322 tree_view->priv->typeselect_flush_timeout = 0;
1326 if (tree_view->priv->search_destroy && tree_view->priv->search_user_data)
1328 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
1329 tree_view->priv->search_user_data = NULL;
1332 if (tree_view->priv->search_position_destroy && tree_view->priv->search_position_user_data)
1334 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
1335 tree_view->priv->search_position_user_data = NULL;
1338 pspp_sheet_view_set_model (tree_view, NULL);
1340 if (tree_view->priv->hadjustment)
1342 g_object_unref (tree_view->priv->hadjustment);
1343 tree_view->priv->hadjustment = NULL;
1345 if (tree_view->priv->vadjustment)
1347 g_object_unref (tree_view->priv->vadjustment);
1348 tree_view->priv->vadjustment = NULL;
1351 if (tree_view->priv->button_style)
1353 g_object_unref (tree_view->priv->button_style);
1354 tree_view->priv->button_style = NULL;
1357 GTK_OBJECT_CLASS (pspp_sheet_view_parent_class)->destroy (object);
1362 /* GtkWidget Methods
1365 /* GtkWidget::map helper */
1367 pspp_sheet_view_map_buttons (PsppSheetView *tree_view)
1371 g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (tree_view)));
1373 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
1375 PsppSheetViewColumn *column;
1377 for (list = tree_view->priv->columns; list; list = list->next)
1379 column = list->data;
1380 if (column->button != NULL &&
1381 gtk_widget_get_visible (column->button) &&
1382 !gtk_widget_get_mapped (column->button))
1383 gtk_widget_map (column->button);
1385 for (list = tree_view->priv->columns; list; list = list->next)
1387 column = list->data;
1388 if (column->visible == FALSE || column->window == NULL)
1390 if (column->resizable)
1392 gdk_window_raise (column->window);
1393 gdk_window_show (column->window);
1396 gdk_window_hide (column->window);
1398 gdk_window_show (tree_view->priv->header_window);
1403 pspp_sheet_view_map (GtkWidget *widget)
1405 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1408 gtk_widget_set_mapped (widget, TRUE);
1410 tmp_list = tree_view->priv->children;
1413 PsppSheetViewChild *child = tmp_list->data;
1414 tmp_list = tmp_list->next;
1416 if (gtk_widget_get_visible (child->widget))
1418 if (!gtk_widget_get_mapped (child->widget))
1419 gtk_widget_map (child->widget);
1422 gdk_window_show (tree_view->priv->bin_window);
1424 pspp_sheet_view_map_buttons (tree_view);
1426 gdk_window_show (widget->window);
1430 pspp_sheet_view_realize (GtkWidget *widget)
1432 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1434 GdkWindowAttr attributes;
1435 gint attributes_mask;
1437 gtk_widget_set_realized (widget, TRUE);
1439 /* Make the main, clipping window */
1440 attributes.window_type = GDK_WINDOW_CHILD;
1441 attributes.x = widget->allocation.x;
1442 attributes.y = widget->allocation.y;
1443 attributes.width = widget->allocation.width;
1444 attributes.height = widget->allocation.height;
1445 attributes.wclass = GDK_INPUT_OUTPUT;
1446 attributes.visual = gtk_widget_get_visual (widget);
1447 attributes.colormap = gtk_widget_get_colormap (widget);
1448 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1450 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1452 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1453 &attributes, attributes_mask);
1454 gdk_window_set_user_data (widget->window, widget);
1456 /* Make the window for the tree */
1458 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1459 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1460 attributes.height = widget->allocation.height;
1461 attributes.event_mask = (GDK_EXPOSURE_MASK |
1463 GDK_POINTER_MOTION_MASK |
1464 GDK_ENTER_NOTIFY_MASK |
1465 GDK_LEAVE_NOTIFY_MASK |
1466 GDK_BUTTON_PRESS_MASK |
1467 GDK_BUTTON_RELEASE_MASK |
1468 gtk_widget_get_events (widget));
1470 tree_view->priv->bin_window = gdk_window_new (widget->window,
1471 &attributes, attributes_mask);
1472 gdk_window_set_user_data (tree_view->priv->bin_window, widget);
1474 /* Make the column header window */
1477 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1478 attributes.height = tree_view->priv->header_height;
1479 attributes.event_mask = (GDK_EXPOSURE_MASK |
1481 GDK_BUTTON_PRESS_MASK |
1482 GDK_BUTTON_RELEASE_MASK |
1483 GDK_KEY_PRESS_MASK |
1484 GDK_KEY_RELEASE_MASK |
1485 gtk_widget_get_events (widget));
1487 tree_view->priv->header_window = gdk_window_new (widget->window,
1488 &attributes, attributes_mask);
1489 gdk_window_set_user_data (tree_view->priv->header_window, widget);
1491 /* Add them all up. */
1492 widget->style = gtk_style_attach (widget->style, widget->window);
1493 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1494 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
1495 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
1497 tmp_list = tree_view->priv->children;
1500 PsppSheetViewChild *child = tmp_list->data;
1501 tmp_list = tmp_list->next;
1503 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1506 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1507 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1509 /* Need to call those here, since they create GCs */
1510 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1512 install_presize_handler (tree_view);
1516 pspp_sheet_view_unrealize (GtkWidget *widget)
1518 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1519 PsppSheetViewPrivate *priv = tree_view->priv;
1522 if (priv->scroll_timeout != 0)
1524 g_source_remove (priv->scroll_timeout);
1525 priv->scroll_timeout = 0;
1528 if (priv->open_dest_timeout != 0)
1530 g_source_remove (priv->open_dest_timeout);
1531 priv->open_dest_timeout = 0;
1534 if (priv->presize_handler_timer != 0)
1536 g_source_remove (priv->presize_handler_timer);
1537 priv->presize_handler_timer = 0;
1540 if (priv->validate_rows_timer != 0)
1542 g_source_remove (priv->validate_rows_timer);
1543 priv->validate_rows_timer = 0;
1546 if (priv->scroll_sync_timer != 0)
1548 g_source_remove (priv->scroll_sync_timer);
1549 priv->scroll_sync_timer = 0;
1552 if (priv->typeselect_flush_timeout)
1554 g_source_remove (priv->typeselect_flush_timeout);
1555 priv->typeselect_flush_timeout = 0;
1558 for (list = priv->columns; list; list = list->next)
1559 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1561 gdk_window_set_user_data (priv->bin_window, NULL);
1562 gdk_window_destroy (priv->bin_window);
1563 priv->bin_window = NULL;
1565 gdk_window_set_user_data (priv->header_window, NULL);
1566 gdk_window_destroy (priv->header_window);
1567 priv->header_window = NULL;
1569 if (priv->drag_window)
1571 gdk_window_set_user_data (priv->drag_window, NULL);
1572 gdk_window_destroy (priv->drag_window);
1573 priv->drag_window = NULL;
1576 if (priv->drag_highlight_window)
1578 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1579 gdk_window_destroy (priv->drag_highlight_window);
1580 priv->drag_highlight_window = NULL;
1583 if (priv->grid_line_gc)
1585 g_object_unref (priv->grid_line_gc);
1586 priv->grid_line_gc = NULL;
1589 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1592 /* GtkWidget::size_request helper */
1594 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1598 tree_view->priv->header_height = 0;
1600 if (tree_view->priv->model)
1602 for (list = tree_view->priv->columns; list; list = list->next)
1604 GtkRequisition requisition;
1605 PsppSheetViewColumn *column = list->data;
1607 pspp_sheet_view_column_size_request (column, &requisition);
1608 column->button_request = requisition.width;
1609 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1615 /* Called only by ::size_request */
1617 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1620 PsppSheetViewColumn *column;
1623 if (tree_view->priv->model == NULL)
1625 tree_view->priv->width = 0;
1626 tree_view->priv->prev_width = 0;
1627 tree_view->priv->height = 0;
1631 tree_view->priv->prev_width = tree_view->priv->width;
1632 tree_view->priv->width = 0;
1634 /* keep this in sync with size_allocate below */
1635 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1637 gint real_requested_width = 0;
1638 column = list->data;
1639 if (!column->visible)
1642 if (column->use_resized_width)
1644 real_requested_width = column->resized_width;
1648 real_requested_width = column->fixed_width;
1651 if (column->min_width != -1)
1652 real_requested_width = MAX (real_requested_width, column->min_width);
1653 if (column->max_width != -1)
1654 real_requested_width = MIN (real_requested_width, column->max_width);
1656 tree_view->priv->width += real_requested_width;
1659 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1663 pspp_sheet_view_size_request (GtkWidget *widget,
1664 GtkRequisition *requisition)
1666 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1669 /* we validate some rows initially just to make sure we have some size.
1670 * In practice, with a lot of static lists, this should get a good width.
1672 initialize_fixed_height_mode (tree_view);
1673 pspp_sheet_view_size_request_columns (tree_view);
1674 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1676 requisition->width = tree_view->priv->width;
1677 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1679 tmp_list = tree_view->priv->children;
1683 PsppSheetViewChild *child = tmp_list->data;
1684 GtkRequisition child_requisition;
1686 tmp_list = tmp_list->next;
1688 if (gtk_widget_get_visible (child->widget))
1689 gtk_widget_size_request (child->widget, &child_requisition);
1694 invalidate_column (PsppSheetView *tree_view,
1695 PsppSheetViewColumn *column)
1697 gint column_offset = 0;
1699 GtkWidget *widget = GTK_WIDGET (tree_view);
1702 if (!gtk_widget_get_realized (widget))
1705 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1706 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1708 list = (rtl ? list->prev : list->next))
1710 PsppSheetViewColumn *tmpcolumn = list->data;
1711 if (tmpcolumn == column)
1713 GdkRectangle invalid_rect;
1715 invalid_rect.x = column_offset;
1717 invalid_rect.width = column->width;
1718 invalid_rect.height = widget->allocation.height;
1720 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
1724 column_offset += tmpcolumn->width;
1729 invalidate_last_column (PsppSheetView *tree_view)
1734 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1736 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1738 last_column = (rtl ? last_column->next : last_column->prev))
1740 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1742 invalidate_column (tree_view, last_column->data);
1749 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1750 PsppSheetViewColumn *column)
1752 gint real_requested_width;
1754 if (column->use_resized_width)
1756 real_requested_width = column->resized_width;
1760 real_requested_width = column->fixed_width;
1763 if (column->min_width != -1)
1764 real_requested_width = MAX (real_requested_width, column->min_width);
1765 if (column->max_width != -1)
1766 real_requested_width = MIN (real_requested_width, column->max_width);
1768 return real_requested_width;
1772 span_intersects (int a0, int a_width,
1773 int b0, int b_width)
1775 int a1 = a0 + a_width;
1776 int b1 = b0 + b_width;
1777 return (a0 >= b0 && a0 < b1) || (b0 >= a0 && b0 < a1);
1780 /* GtkWidget::size_allocate helper */
1782 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1783 gboolean *width_changed)
1785 PsppSheetView *tree_view;
1786 GList *list, *first_column, *last_column;
1787 PsppSheetViewColumn *column;
1788 GtkAllocation allocation;
1790 gint extra, extra_per_column;
1791 gint full_requested_width = 0;
1792 gint number_of_expand_columns = 0;
1793 gboolean column_changed = FALSE;
1796 tree_view = PSPP_SHEET_VIEW (widget);
1798 for (last_column = g_list_last (tree_view->priv->columns);
1799 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1800 last_column = last_column->prev)
1802 if (last_column == NULL)
1805 for (first_column = g_list_first (tree_view->priv->columns);
1806 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1807 first_column = first_column->next)
1811 allocation.height = tree_view->priv->header_height;
1813 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1815 /* find out how many extra space and expandable columns we have */
1816 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1818 column = (PsppSheetViewColumn *)list->data;
1820 if (!column->visible)
1823 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1826 number_of_expand_columns++;
1829 extra = MAX (widget->allocation.width - full_requested_width, 0);
1830 if (number_of_expand_columns > 0)
1831 extra_per_column = extra/number_of_expand_columns;
1833 extra_per_column = 0;
1835 for (list = (rtl ? last_column : first_column);
1836 list != (rtl ? first_column->prev : last_column->next);
1837 list = (rtl ? list->prev : list->next))
1839 gint real_requested_width = 0;
1842 column = list->data;
1843 old_width = column->width;
1845 if (!column->visible)
1848 /* We need to handle the dragged button specially.
1850 if (column == tree_view->priv->drag_column)
1852 GtkAllocation drag_allocation;
1853 gdk_drawable_get_size (tree_view->priv->drag_window,
1854 &(drag_allocation.width),
1855 &(drag_allocation.height));
1856 drag_allocation.x = 0;
1857 drag_allocation.y = 0;
1858 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1860 width += drag_allocation.width;
1864 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1866 allocation.x = width;
1867 column->width = real_requested_width;
1871 if (number_of_expand_columns == 1)
1873 /* We add the remander to the last column as
1875 column->width += extra;
1879 column->width += extra_per_column;
1880 extra -= extra_per_column;
1881 number_of_expand_columns --;
1885 if (column->width != old_width)
1886 g_object_notify (G_OBJECT (column), "width");
1888 allocation.width = column->width;
1889 width += column->width;
1891 if (column->width > old_width)
1892 column_changed = TRUE;
1894 pspp_sheet_view_column_size_allocate (column, &allocation);
1896 if (span_intersects (allocation.x, allocation.width,
1897 tree_view->priv->hadjustment->value,
1898 widget->allocation.width)
1899 && gtk_widget_get_realized (widget))
1900 pspp_sheet_view_column_set_need_button (column, TRUE);
1903 gdk_window_move_resize (column->window,
1904 allocation.x + (rtl ? 0 : allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1906 TREE_VIEW_DRAG_WIDTH, allocation.height);
1909 /* We change the width here. The user might have been resizing columns,
1910 * so the total width of the tree view changes.
1912 tree_view->priv->width = width;
1914 *width_changed = TRUE;
1917 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
1922 pspp_sheet_view_size_allocate (GtkWidget *widget,
1923 GtkAllocation *allocation)
1925 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1927 gboolean width_changed = FALSE;
1928 gint old_width = widget->allocation.width;
1930 if (allocation->width != widget->allocation.width)
1931 width_changed = TRUE;
1933 widget->allocation = *allocation;
1935 tmp_list = tree_view->priv->children;
1939 GtkAllocation allocation;
1941 PsppSheetViewChild *child = tmp_list->data;
1942 tmp_list = tmp_list->next;
1944 /* totally ignore our child's requisition */
1945 allocation.x = child->x;
1946 allocation.y = child->y;
1947 allocation.width = child->width;
1948 allocation.height = child->height;
1949 gtk_widget_size_allocate (child->widget, &allocation);
1952 /* We size-allocate the columns first because the width of the
1953 * tree view (used in updating the adjustments below) might change.
1955 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
1957 tree_view->priv->hadjustment->page_size = allocation->width;
1958 tree_view->priv->hadjustment->page_increment = allocation->width * 0.9;
1959 tree_view->priv->hadjustment->step_increment = allocation->width * 0.1;
1960 tree_view->priv->hadjustment->lower = 0;
1961 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->page_size, tree_view->priv->width);
1963 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
1965 if (allocation->width < tree_view->priv->width)
1967 if (tree_view->priv->init_hadjust_value)
1969 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
1970 tree_view->priv->init_hadjust_value = FALSE;
1972 else if (allocation->width != old_width)
1974 tree_view->priv->hadjustment->value = CLAMP (tree_view->priv->hadjustment->value - allocation->width + old_width, 0, tree_view->priv->width - allocation->width);
1977 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);
1981 tree_view->priv->hadjustment->value = 0;
1982 tree_view->priv->init_hadjust_value = TRUE;
1986 if (tree_view->priv->hadjustment->value + allocation->width > tree_view->priv->width)
1987 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
1989 gtk_adjustment_changed (tree_view->priv->hadjustment);
1991 tree_view->priv->vadjustment->page_size = allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view);
1992 tree_view->priv->vadjustment->step_increment = tree_view->priv->vadjustment->page_size * 0.1;
1993 tree_view->priv->vadjustment->page_increment = tree_view->priv->vadjustment->page_size * 0.9;
1994 tree_view->priv->vadjustment->lower = 0;
1995 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->page_size, tree_view->priv->height);
1997 gtk_adjustment_changed (tree_view->priv->vadjustment);
1999 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
2000 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
2001 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
2002 else if (tree_view->priv->vadjustment->value + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
2003 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
2004 tree_view->priv->height - tree_view->priv->vadjustment->page_size);
2005 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
2006 pspp_sheet_view_top_row_to_dy (tree_view);
2008 pspp_sheet_view_dy_to_top_row (tree_view);
2010 if (gtk_widget_get_realized (widget))
2012 gdk_window_move_resize (widget->window,
2013 allocation->x, allocation->y,
2014 allocation->width, allocation->height);
2015 gdk_window_move_resize (tree_view->priv->header_window,
2016 - (gint) tree_view->priv->hadjustment->value,
2018 MAX (tree_view->priv->width, allocation->width),
2019 tree_view->priv->header_height);
2020 gdk_window_move_resize (tree_view->priv->bin_window,
2021 - (gint) tree_view->priv->hadjustment->value,
2022 TREE_VIEW_HEADER_HEIGHT (tree_view),
2023 MAX (tree_view->priv->width, allocation->width),
2024 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2027 if (tree_view->priv->row_count == 0)
2028 invalidate_empty_focus (tree_view);
2030 if (gtk_widget_get_realized (widget))
2032 gboolean has_expand_column = FALSE;
2033 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2035 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2037 has_expand_column = TRUE;
2042 /* This little hack only works if we have an LTR locale, and no column has the */
2045 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2046 ! has_expand_column)
2047 invalidate_last_column (tree_view);
2049 gtk_widget_queue_draw (widget);
2054 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2056 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2058 GtkWidget *widget = GTK_WIDGET (tree_view);
2060 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2061 gtk_widget_grab_focus (widget);
2062 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2066 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2069 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2073 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2076 range_tower_set1 (tree_view->priv->selected, node, 1);
2080 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2083 range_tower_set0 (tree_view->priv->selected, node, 1);
2087 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2090 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2094 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2097 return node > 0 ? node - 1 : -1;
2101 all_columns_selected (PsppSheetView *tree_view)
2105 for (list = tree_view->priv->columns; list; list = list->next)
2107 PsppSheetViewColumn *column = list->data;
2108 if (column->selectable && !column->selected)
2116 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2118 PsppSheetViewColumn *column,
2119 GdkEventButton *event)
2121 PsppSheetSelection *selection;
2122 PsppSheetSelectionMode mode;
2124 gboolean update_anchor;
2128 g_return_val_if_fail (tree_view != NULL, FALSE);
2129 g_return_val_if_fail (column != NULL, FALSE);
2131 selection = tree_view->priv->selection;
2132 mode = pspp_sheet_selection_get_mode (selection);
2133 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2136 if (!column->row_head)
2141 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2142 if (event->type != GDK_BUTTON_PRESS
2143 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2149 path = gtk_tree_path_new_from_indices (node, -1);
2152 pspp_sheet_selection_unselect_all (selection);
2153 pspp_sheet_selection_select_path (selection, path);
2154 pspp_sheet_selection_select_all_columns (selection);
2155 update_anchor = TRUE;
2158 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2160 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2161 || !all_columns_selected (tree_view))
2163 pspp_sheet_selection_unselect_all (selection);
2164 pspp_sheet_selection_select_path (selection, path);
2165 pspp_sheet_selection_select_all_columns (selection);
2166 update_anchor = TRUE;
2170 update_anchor = handled = FALSE;
2172 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2173 && modifiers == GDK_CONTROL_MASK)
2175 if (!all_columns_selected (tree_view))
2177 pspp_sheet_selection_unselect_all (selection);
2178 pspp_sheet_selection_select_all_columns (selection);
2181 if (pspp_sheet_selection_path_is_selected (selection, path))
2182 pspp_sheet_selection_unselect_path (selection, path);
2184 pspp_sheet_selection_select_path (selection, path);
2185 update_anchor = TRUE;
2188 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2189 && modifiers == GDK_SHIFT_MASK)
2191 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2192 GtkTreePath *anchor_path;
2194 if (all_columns_selected (tree_view)
2195 && gtk_tree_row_reference_valid (anchor))
2197 update_anchor = FALSE;
2198 anchor_path = gtk_tree_row_reference_get_path (anchor);
2202 update_anchor = TRUE;
2203 anchor_path = gtk_tree_path_copy (path);
2206 pspp_sheet_selection_unselect_all (selection);
2207 pspp_sheet_selection_select_range (selection, anchor_path, path);
2208 pspp_sheet_selection_select_all_columns (selection);
2210 gtk_tree_path_free (anchor_path);
2215 update_anchor = handled = FALSE;
2219 if (tree_view->priv->anchor)
2220 gtk_tree_row_reference_free (tree_view->priv->anchor);
2221 tree_view->priv->anchor =
2222 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2223 tree_view->priv->model,
2227 gtk_tree_path_free (path);
2232 find_click (PsppSheetView *tree_view,
2235 PsppSheetViewColumn **column,
2236 GdkRectangle *background_area,
2237 GdkRectangle *cell_area)
2244 /* find the node that was clicked */
2245 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2248 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2253 background_area->y = y_offset + y;
2254 background_area->height = ROW_HEIGHT (tree_view);
2255 background_area->x = 0;
2257 /* Let the column have a chance at selecting it. */
2258 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2259 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2260 list; list = (rtl ? list->prev : list->next))
2262 PsppSheetViewColumn *candidate = list->data;
2264 if (!candidate->visible)
2267 background_area->width = candidate->width;
2268 if ((background_area->x > x) ||
2269 (background_area->x + background_area->width <= x))
2271 background_area->x += background_area->width;
2275 /* we found the focus column */
2277 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2279 *column = candidate;
2287 pspp_sheet_view_button_press (GtkWidget *widget,
2288 GdkEventButton *event)
2290 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2292 PsppSheetViewColumn *column = NULL;
2294 GdkRectangle background_area;
2295 GdkRectangle cell_area;
2298 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2299 pspp_sheet_view_stop_editing (tree_view, FALSE);
2302 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2303 * we're done handling the button press.
2306 if (event->window == tree_view->priv->bin_window)
2311 gint pre_val, aft_val;
2312 PsppSheetViewColumn *column = NULL;
2313 GtkCellRenderer *focus_cell = NULL;
2314 gboolean row_double_click = FALSE;
2315 gboolean node_selected;
2318 if (tree_view->priv->row_count == 0)
2320 grab_focus_and_unset_draw_keyfocus (tree_view);
2324 if (!find_click (tree_view, event->x, event->y, &node, &column,
2325 &background_area, &cell_area))
2327 grab_focus_and_unset_draw_keyfocus (tree_view);
2331 tree_view->priv->focus_column = column;
2333 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2337 node_selected = pspp_sheet_view_node_is_selected (tree_view, node);
2338 pre_val = tree_view->priv->vadjustment->value;
2340 path = _pspp_sheet_view_find_path (tree_view, node);
2342 /* we only handle selection modifications on the first button press
2344 if (event->type == GDK_BUTTON_PRESS)
2346 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2347 tree_view->priv->ctrl_pressed = TRUE;
2348 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2349 tree_view->priv->shift_pressed = TRUE;
2351 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2353 pspp_sheet_view_column_focus_cell (column, focus_cell);
2355 if (event->state & GDK_CONTROL_MASK)
2357 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
2358 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2360 else if (event->state & GDK_SHIFT_MASK)
2362 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
2363 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE);
2367 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
2370 if (tree_view->priv->anchor_column == NULL ||
2371 !(event->state & GDK_SHIFT_MASK))
2372 tree_view->priv->anchor_column = column;
2373 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2374 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2375 tree_view->priv->anchor_column,
2378 tree_view->priv->ctrl_pressed = FALSE;
2379 tree_view->priv->shift_pressed = FALSE;
2382 /* the treeview may have been scrolled because of _set_cursor,
2386 aft_val = tree_view->priv->vadjustment->value;
2387 dval = pre_val - aft_val;
2389 cell_area.y += dval;
2390 background_area.y += dval;
2392 /* Save press to possibly begin a drag
2394 if (!tree_view->priv->in_grab &&
2395 tree_view->priv->pressed_button < 0)
2397 tree_view->priv->pressed_button = event->button;
2398 tree_view->priv->press_start_x = event->x;
2399 tree_view->priv->press_start_y = event->y;
2400 tree_view->priv->press_start_node = node;
2402 if (tree_view->priv->rubber_banding_enable
2404 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2405 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2407 tree_view->priv->press_start_y += tree_view->priv->dy;
2408 tree_view->priv->rubber_band_x = event->x;
2409 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2410 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2412 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2413 tree_view->priv->rubber_band_ctrl = TRUE;
2414 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2415 tree_view->priv->rubber_band_shift = TRUE;
2420 /* Test if a double click happened on the same row. */
2421 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2423 int double_click_time, double_click_distance;
2425 g_object_get (gtk_settings_get_for_screen (
2426 gtk_widget_get_screen (widget)),
2427 "gtk-double-click-time", &double_click_time,
2428 "gtk-double-click-distance", &double_click_distance,
2431 /* Same conditions as _gdk_event_button_generate */
2432 if (tree_view->priv->last_button_x != -1 &&
2433 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2434 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2435 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2437 /* We do no longer compare paths of this row and the
2438 * row clicked previously. We use the double click
2439 * distance to decide whether this is a valid click,
2440 * allowing the mouse to slightly move over another row.
2442 row_double_click = TRUE;
2444 tree_view->priv->last_button_time = 0;
2445 tree_view->priv->last_button_x = -1;
2446 tree_view->priv->last_button_y = -1;
2450 tree_view->priv->last_button_time = event->time;
2451 tree_view->priv->last_button_x = event->x;
2452 tree_view->priv->last_button_y = event->y;
2456 if (row_double_click)
2458 gtk_grab_remove (widget);
2459 pspp_sheet_view_row_activated (tree_view, path, column);
2461 if (tree_view->priv->pressed_button == event->button)
2462 tree_view->priv->pressed_button = -1;
2465 gtk_tree_path_free (path);
2467 /* If we activated the row through a double click we don't want to grab
2468 * focus back, as moving focus to another widget is pretty common.
2470 if (!row_double_click)
2471 grab_focus_and_unset_draw_keyfocus (tree_view);
2476 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2478 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2480 column = list->data;
2481 if (event->window == column->window &&
2482 column->resizable &&
2487 if (gdk_pointer_grab (column->window, FALSE,
2488 GDK_POINTER_MOTION_HINT_MASK |
2489 GDK_BUTTON1_MOTION_MASK |
2490 GDK_BUTTON_RELEASE_MASK,
2491 NULL, NULL, event->time))
2494 gtk_grab_add (widget);
2495 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2496 column->resized_width = column->width;
2498 /* block attached dnd signal handler */
2499 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2501 g_signal_handlers_block_matched (widget,
2502 G_SIGNAL_MATCH_DATA,
2506 tree_view->priv->drag_pos = i;
2507 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2509 if (!gtk_widget_has_focus (widget))
2510 gtk_widget_grab_focus (widget);
2518 /* GtkWidget::button_release_event helper */
2520 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2521 GdkEventButton *event)
2523 PsppSheetView *tree_view;
2527 tree_view = PSPP_SHEET_VIEW (widget);
2529 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2530 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2531 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2533 /* Move the button back */
2534 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2536 g_object_ref (tree_view->priv->drag_column->button);
2537 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2538 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2539 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2540 g_object_unref (tree_view->priv->drag_column->button);
2541 gtk_widget_queue_resize (widget);
2542 if (tree_view->priv->drag_column->resizable)
2544 gdk_window_raise (tree_view->priv->drag_column->window);
2545 gdk_window_show (tree_view->priv->drag_column->window);
2548 gdk_window_hide (tree_view->priv->drag_column->window);
2550 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2554 if (tree_view->priv->cur_reorder &&
2555 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2556 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2557 tree_view->priv->cur_reorder->right_column);
2561 if (tree_view->priv->cur_reorder &&
2562 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2563 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2564 tree_view->priv->cur_reorder->left_column);
2566 tree_view->priv->drag_column = NULL;
2567 gdk_window_hide (tree_view->priv->drag_window);
2569 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2570 g_slice_free (PsppSheetViewColumnReorder, l->data);
2571 g_list_free (tree_view->priv->column_drag_info);
2572 tree_view->priv->column_drag_info = NULL;
2573 tree_view->priv->cur_reorder = NULL;
2575 if (tree_view->priv->drag_highlight_window)
2576 gdk_window_hide (tree_view->priv->drag_highlight_window);
2578 /* Reset our flags */
2579 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2580 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2585 /* GtkWidget::button_release_event helper */
2587 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2588 GdkEventButton *event)
2590 PsppSheetView *tree_view;
2593 tree_view = PSPP_SHEET_VIEW (widget);
2595 tree_view->priv->drag_pos = -1;
2597 /* unblock attached dnd signal handler */
2598 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2600 g_signal_handlers_unblock_matched (widget,
2601 G_SIGNAL_MATCH_DATA,
2605 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2606 gtk_grab_remove (widget);
2607 gdk_display_pointer_ungrab (gdk_drawable_get_display (event->window),
2613 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2614 GdkEventButton *event)
2616 GtkCellEditable *cell_editable;
2621 PsppSheetViewColumn *column;
2622 GdkRectangle background_area;
2623 GdkRectangle cell_area;
2629 if (event->window != tree_view->priv->bin_window)
2632 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2636 /* decide if we edit */
2637 path = _pspp_sheet_view_find_path (tree_view, node);
2638 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2639 if (event->button != 1 || modifiers)
2642 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2643 pspp_sheet_view_column_cell_set_cell_data (column,
2644 tree_view->priv->model,
2647 if (!pspp_sheet_view_column_get_quick_edit (column)
2648 && _pspp_sheet_view_column_has_editable_cell (column))
2651 flags = 0; /* FIXME: get the right flags */
2652 path_string = gtk_tree_path_to_string (path);
2654 if (!_pspp_sheet_view_column_cell_event (column,
2662 if (cell_editable == NULL)
2665 pspp_sheet_view_real_set_cursor (tree_view, path,
2667 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2670 _pspp_sheet_view_column_get_neighbor_sizes (
2671 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2674 area.width -= right + left;
2676 pspp_sheet_view_real_start_editing (tree_view,
2683 g_free (path_string);
2684 gtk_tree_path_free (path);
2689 pspp_sheet_view_button_release (GtkWidget *widget,
2690 GdkEventButton *event)
2692 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2694 pspp_sheet_view_stop_editing (tree_view, FALSE);
2695 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2696 && pspp_sheet_view_button_release_edit (tree_view, event))
2698 if (tree_view->priv->pressed_button == event->button)
2699 tree_view->priv->pressed_button = -1;
2701 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2705 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2706 return pspp_sheet_view_button_release_drag_column (widget, event);
2708 if (tree_view->priv->rubber_band_status)
2709 pspp_sheet_view_stop_rubber_band (tree_view);
2711 if (tree_view->priv->pressed_button == event->button)
2712 tree_view->priv->pressed_button = -1;
2714 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2715 return pspp_sheet_view_button_release_column_resize (widget, event);
2721 pspp_sheet_view_grab_broken (GtkWidget *widget,
2722 GdkEventGrabBroken *event)
2724 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2726 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2727 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2729 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2730 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2735 /* GtkWidget::motion_event function set.
2739 do_prelight (PsppSheetView *tree_view,
2741 /* these are in bin_window coords */
2745 int prev_node = tree_view->priv->prelight_node;
2747 if (prev_node != node)
2749 tree_view->priv->prelight_node = node;
2752 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2755 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2760 prelight_or_select (PsppSheetView *tree_view,
2762 /* these are in bin_window coords */
2766 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2768 if (tree_view->priv->hover_selection &&
2769 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2770 !(tree_view->priv->edited_column &&
2771 tree_view->priv->edited_column->editable_widget))
2775 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2779 path = _pspp_sheet_view_find_path (tree_view, node);
2780 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2781 if (pspp_sheet_view_node_is_selected (tree_view, node))
2783 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2784 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE);
2786 gtk_tree_path_free (path);
2790 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2791 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2794 do_prelight (tree_view, node, x, y);
2798 ensure_unprelighted (PsppSheetView *tree_view)
2800 do_prelight (tree_view,
2802 -1000, -1000); /* coords not possibly over an arrow */
2804 g_assert (tree_view->priv->prelight_node < 0);
2808 update_prelight (PsppSheetView *tree_view,
2815 if (tree_view->priv->row_count == 0)
2820 ensure_unprelighted (tree_view);
2824 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2828 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2831 prelight_or_select (tree_view, node, x, y);
2837 /* Our motion arrow is either a box (in the case of the original spot)
2838 * or an arrow. It is expander_size wide.
2861 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2863 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2864 GtkWidget *widget = GTK_WIDGET (tree_view);
2865 GdkBitmap *mask = NULL;
2870 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2871 GdkWindowAttr attributes;
2872 guint attributes_mask;
2875 reorder->left_column == tree_view->priv->drag_column ||
2876 reorder->right_column == tree_view->priv->drag_column)
2877 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2878 else if (reorder->left_column || reorder->right_column)
2880 GdkRectangle visible_rect;
2881 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2882 if (reorder->left_column)
2883 x = reorder->left_column->allocation.x + reorder->left_column->allocation.width;
2885 x = reorder->right_column->allocation.x;
2887 if (x < visible_rect.x)
2888 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2889 else if (x > visible_rect.x + visible_rect.width)
2890 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2892 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2895 /* We want to draw the rectangle over the initial location. */
2896 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2901 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2903 if (tree_view->priv->drag_highlight_window)
2905 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2907 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2910 attributes.window_type = GDK_WINDOW_CHILD;
2911 attributes.wclass = GDK_INPUT_OUTPUT;
2912 attributes.x = tree_view->priv->drag_column_x;
2914 width = attributes.width = tree_view->priv->drag_column->allocation.width;
2915 height = attributes.height = tree_view->priv->drag_column->allocation.height;
2916 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2917 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2918 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2919 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2920 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
2921 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2923 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2924 gc = gdk_gc_new (mask);
2926 gdk_gc_set_foreground (gc, &col);
2927 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2929 gdk_gc_set_foreground(gc, &col);
2930 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
2931 g_object_unref (gc);
2933 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
2935 if (mask) g_object_unref (mask);
2936 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2939 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
2945 width = tree_view->priv->expander_size;
2947 /* Get x, y, width, height of arrow */
2948 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
2949 if (reorder->left_column)
2951 x += reorder->left_column->allocation.x + reorder->left_column->allocation.width - width/2;
2952 height = reorder->left_column->allocation.height;
2956 x += reorder->right_column->allocation.x - width/2;
2957 height = reorder->right_column->allocation.height;
2959 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
2960 height += tree_view->priv->expander_size;
2962 /* Create the new window */
2963 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
2965 if (tree_view->priv->drag_highlight_window)
2967 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2969 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2972 attributes.window_type = GDK_WINDOW_TEMP;
2973 attributes.wclass = GDK_INPUT_OUTPUT;
2974 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2975 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2976 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2977 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2980 attributes.width = width;
2981 attributes.height = height;
2982 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
2983 &attributes, attributes_mask);
2984 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2986 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2987 gc = gdk_gc_new (mask);
2989 gdk_gc_set_foreground (gc, &col);
2990 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2992 /* Draw the 2 arrows as per above */
2994 gdk_gc_set_foreground (gc, &col);
2995 for (i = 0; i < width; i ++)
2997 if (i == (width/2 - 1))
2999 gdk_draw_line (mask, gc, i, j, i, height - j);
3000 if (i < (width/2 - 1))
3005 g_object_unref (gc);
3006 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3008 if (mask) g_object_unref (mask);
3011 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
3012 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3014 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
3015 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3021 width = tree_view->priv->expander_size;
3023 /* Get x, y, width, height of arrow */
3024 width = width/2; /* remember, the arrow only takes half the available width */
3025 gdk_window_get_origin (widget->window, &x, &y);
3026 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3027 x += widget->allocation.width - width;
3029 if (reorder->left_column)
3030 height = reorder->left_column->allocation.height;
3032 height = reorder->right_column->allocation.height;
3034 y -= tree_view->priv->expander_size;
3035 height += 2*tree_view->priv->expander_size;
3037 /* Create the new window */
3038 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
3039 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3041 if (tree_view->priv->drag_highlight_window)
3043 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3045 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3048 attributes.window_type = GDK_WINDOW_TEMP;
3049 attributes.wclass = GDK_INPUT_OUTPUT;
3050 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3051 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3052 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3053 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3056 attributes.width = width;
3057 attributes.height = height;
3058 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3059 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3061 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3062 gc = gdk_gc_new (mask);
3064 gdk_gc_set_foreground (gc, &col);
3065 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3067 /* Draw the 2 arrows as per above */
3069 gdk_gc_set_foreground (gc, &col);
3070 j = tree_view->priv->expander_size;
3071 for (i = 0; i < width; i ++)
3074 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3078 gdk_draw_line (mask, gc, k, j, k, height - j);
3079 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3080 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3083 g_object_unref (gc);
3084 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3086 if (mask) g_object_unref (mask);
3089 tree_view->priv->drag_column_window_state = arrow_type;
3090 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3094 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3095 gdk_window_hide (tree_view->priv->drag_highlight_window);
3099 gdk_window_show (tree_view->priv->drag_highlight_window);
3100 gdk_window_raise (tree_view->priv->drag_highlight_window);
3104 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3105 GdkEventMotion *event)
3109 PsppSheetViewColumn *column;
3110 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3112 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3114 if (event->is_hint || event->window != widget->window)
3115 gtk_widget_get_pointer (widget, &x, NULL);
3119 if (tree_view->priv->hadjustment)
3120 x += tree_view->priv->hadjustment->value;
3122 new_width = pspp_sheet_view_new_column_width (tree_view,
3123 tree_view->priv->drag_pos, &x);
3124 if (x != tree_view->priv->x_drag &&
3125 (new_width != column->fixed_width))
3127 column->use_resized_width = TRUE;
3128 column->resized_width = new_width;
3131 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3133 gtk_widget_queue_resize (widget);
3141 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3143 PsppSheetViewColumnReorder *reorder = NULL;
3147 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3148 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3150 reorder = (PsppSheetViewColumnReorder *) list->data;
3151 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3156 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3159 tree_view->priv->cur_reorder = reorder;
3160 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3164 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3166 GdkRectangle visible_rect;
3171 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3172 y += tree_view->priv->dy;
3174 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3176 /* see if we are near the edge. */
3177 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3180 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3185 value = CLAMP (tree_view->priv->vadjustment->value + offset, 0.0,
3186 tree_view->priv->vadjustment->upper - tree_view->priv->vadjustment->page_size);
3187 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3191 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3193 GdkRectangle visible_rect;
3198 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3200 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3202 /* See if we are near the edge. */
3203 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3206 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3212 value = CLAMP (tree_view->priv->hadjustment->value + offset,
3213 0.0, tree_view->priv->hadjustment->upper - tree_view->priv->hadjustment->page_size);
3214 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3221 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3222 GdkEventMotion *event)
3224 PsppSheetView *tree_view = (PsppSheetView *) widget;
3225 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3229 if ((column == NULL) ||
3230 (event->window != tree_view->priv->drag_window))
3233 /* Handle moving the header */
3234 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3235 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3236 MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width) - column->allocation.width);
3237 gdk_window_move (tree_view->priv->drag_window, x, y);
3239 /* autoscroll, if needed */
3240 pspp_sheet_view_horizontal_autoscroll (tree_view);
3241 /* Update the current reorder position and arrow; */
3242 pspp_sheet_view_update_current_reorder (tree_view);
3248 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3250 remove_scroll_timeout (tree_view);
3251 gtk_grab_remove (GTK_WIDGET (tree_view));
3253 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3255 GtkTreePath *tmp_path;
3257 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3259 /* The anchor path should be set to the start path */
3260 tmp_path = _pspp_sheet_view_find_path (tree_view,
3261 tree_view->priv->rubber_band_start_node);
3263 if (tree_view->priv->anchor)
3264 gtk_tree_row_reference_free (tree_view->priv->anchor);
3266 tree_view->priv->anchor =
3267 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3268 tree_view->priv->model,
3271 gtk_tree_path_free (tmp_path);
3273 /* ... and the cursor to the end path */
3274 tmp_path = _pspp_sheet_view_find_path (tree_view,
3275 tree_view->priv->rubber_band_end_node);
3276 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE);
3277 gtk_tree_path_free (tmp_path);
3279 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3282 /* Clear status variables */
3283 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3284 tree_view->priv->rubber_band_shift = 0;
3285 tree_view->priv->rubber_band_ctrl = 0;
3287 tree_view->priv->rubber_band_start_node = -1;
3288 tree_view->priv->rubber_band_end_node = -1;
3292 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3296 gboolean skip_start,
3299 if (start_node == end_node)
3302 /* We skip the first node and jump inside the loop */
3308 /* Small optimization by assuming insensitive nodes are never
3313 if (tree_view->priv->rubber_band_shift)
3314 pspp_sheet_view_node_select (tree_view, start_node);
3315 else if (tree_view->priv->rubber_band_ctrl)
3317 /* Toggle the selection state */
3318 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3319 pspp_sheet_view_node_unselect (tree_view, start_node);
3321 pspp_sheet_view_node_select (tree_view, start_node);
3324 pspp_sheet_view_node_select (tree_view, start_node);
3328 /* Mirror the above */
3329 if (tree_view->priv->rubber_band_shift)
3330 pspp_sheet_view_node_unselect (tree_view, start_node);
3331 else if (tree_view->priv->rubber_band_ctrl)
3333 /* Toggle the selection state */
3334 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3335 pspp_sheet_view_node_unselect (tree_view, start_node);
3337 pspp_sheet_view_node_select (tree_view, start_node);
3340 pspp_sheet_view_node_unselect (tree_view, start_node);
3343 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3345 if (start_node == end_node)
3350 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3353 /* Ran out of tree */
3356 if (skip_end && start_node == end_node)
3363 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3366 return node * tree_view->priv->fixed_height;
3370 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3374 int fixed_height = tree_view->priv->fixed_height;
3375 if (fixed_height <= 0
3377 || height >= tree_view->priv->row_count * fixed_height)
3384 *new_node = height / fixed_height;
3385 return height % fixed_height;
3390 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3395 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3396 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3398 /* Handle the start area first */
3399 if (tree_view->priv->rubber_band_start_node < 0)
3401 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3408 else if (start_node < tree_view->priv->rubber_band_start_node)
3410 /* New node is above the old one; selection became bigger */
3411 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3413 tree_view->priv->rubber_band_start_node,
3418 else if (start_node > tree_view->priv->rubber_band_start_node)
3420 /* New node is below the old one; selection became smaller */
3421 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3422 tree_view->priv->rubber_band_start_node,
3429 tree_view->priv->rubber_band_start_node = start_node;
3431 /* Next, handle the end area */
3432 if (tree_view->priv->rubber_band_end_node < 0)
3434 /* In the event this happens, start_node was also -1; this case is
3438 else if (end_node < 0)
3440 /* Find the last node in the tree */
3441 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3444 /* Selection reached end of the tree */
3445 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3446 tree_view->priv->rubber_band_end_node,
3452 else if (end_node > tree_view->priv->rubber_band_end_node)
3454 /* New node is below the old one; selection became bigger */
3455 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3456 tree_view->priv->rubber_band_end_node,
3462 else if (end_node < tree_view->priv->rubber_band_end_node)
3464 /* New node is above the old one; selection became smaller */
3465 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3467 tree_view->priv->rubber_band_end_node,
3473 tree_view->priv->rubber_band_end_node = end_node;
3477 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3480 GdkRectangle old_area;
3481 GdkRectangle new_area;
3482 GdkRectangle common;
3483 GdkRegion *invalid_region;
3484 PsppSheetViewColumn *column;
3486 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3487 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3488 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3489 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3491 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3494 y = MAX (y, 0) + tree_view->priv->dy;
3496 new_area.x = MIN (tree_view->priv->press_start_x, x);
3497 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3498 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3499 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3501 invalid_region = gdk_region_rectangle (&old_area);
3502 gdk_region_union_with_rect (invalid_region, &new_area);
3504 gdk_rectangle_intersect (&old_area, &new_area, &common);
3505 if (common.width > 2 && common.height > 2)
3507 GdkRegion *common_region;
3509 /* make sure the border is invalidated */
3515 common_region = gdk_region_rectangle (&common);
3517 gdk_region_subtract (invalid_region, common_region);
3518 gdk_region_destroy (common_region);
3521 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3523 gdk_region_destroy (invalid_region);
3525 tree_view->priv->rubber_band_x = x;
3526 tree_view->priv->rubber_band_y = y;
3527 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3529 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3530 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3531 tree_view->priv->anchor_column,
3534 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3536 pspp_sheet_view_update_rubber_band_selection (tree_view);
3540 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3545 GdkRectangle rubber_rect;
3548 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3549 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3550 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3551 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3553 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3556 cr = gdk_cairo_create (tree_view->priv->bin_window);
3557 cairo_set_line_width (cr, 1.0);
3559 cairo_set_source_rgba (cr,
3560 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3561 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3562 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.,
3565 gdk_cairo_rectangle (cr, &rect);
3569 cairo_set_source_rgb (cr,
3570 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3571 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3572 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.);
3574 cairo_rectangle (cr,
3575 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3576 rubber_rect.width - 1, rubber_rect.height - 1);
3583 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3584 GdkEventMotion *event)
3586 PsppSheetView *tree_view;
3590 tree_view = (PsppSheetView *) widget;
3592 if (tree_view->priv->row_count == 0)
3595 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3597 GdkRectangle background_area, cell_area;
3598 PsppSheetViewColumn *column;
3600 if (find_click (tree_view, event->x, event->y, &node, &column,
3601 &background_area, &cell_area)
3602 && tree_view->priv->focus_column == column
3603 && tree_view->priv->press_start_node == node)
3606 gtk_grab_add (GTK_WIDGET (tree_view));
3607 pspp_sheet_view_update_rubber_band (tree_view);
3609 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3611 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3613 pspp_sheet_view_update_rubber_band (tree_view);
3615 add_scroll_timeout (tree_view);
3618 /* only check for an initiated drag when a button is pressed */
3619 if (tree_view->priv->pressed_button >= 0
3620 && !tree_view->priv->rubber_band_status)
3621 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3623 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3627 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3629 tree_view->priv->event_last_x = event->x;
3630 tree_view->priv->event_last_y = event->y;
3632 prelight_or_select (tree_view, node, event->x, event->y);
3638 pspp_sheet_view_motion (GtkWidget *widget,
3639 GdkEventMotion *event)
3641 PsppSheetView *tree_view;
3643 tree_view = (PsppSheetView *) widget;
3645 /* Resizing a column */
3646 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3647 return pspp_sheet_view_motion_resize_column (widget, event);
3650 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3651 return pspp_sheet_view_motion_drag_column (widget, event);
3653 /* Sanity check it */
3654 if (event->window == tree_view->priv->bin_window)
3655 return pspp_sheet_view_motion_bin_window (widget, event);
3660 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3661 * the tree is empty.
3664 invalidate_empty_focus (PsppSheetView *tree_view)
3668 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3673 gdk_drawable_get_size (tree_view->priv->bin_window, &area.width, &area.height);
3674 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3677 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3681 draw_empty_focus (PsppSheetView *tree_view, GdkRectangle *clip_area)
3683 GtkWidget *widget = GTK_WIDGET (tree_view);
3686 if (!gtk_widget_has_focus (widget))
3689 gdk_drawable_get_size (tree_view->priv->bin_window, &w, &h);
3695 gtk_paint_focus (gtk_widget_get_style (widget),
3696 tree_view->priv->bin_window,
3697 gtk_widget_get_state (widget),
3705 pspp_sheet_view_draw_grid_lines (PsppSheetView *tree_view,
3706 GdkEventExpose *event,
3707 gint n_visible_columns,
3711 GList *list = tree_view->priv->columns;
3716 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3717 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3720 gdk_drawable_get_size (event->window, NULL, &height);
3722 /* Only draw the lines for visible rows and columns */
3723 for (list = tree_view->priv->columns; list; list = list->next, i++)
3725 PsppSheetViewColumn *column = list->data;
3727 /* We don't want a line for the last column */
3728 if (i == n_visible_columns - 1)
3731 if (! column->visible)
3734 current_x += column->width;
3736 if (current_x - 1 >= event->area.x
3737 && current_x - 1 < event->area.x + event->area.width)
3738 gdk_draw_line (event->window,
3739 tree_view->priv->grid_line_gc,
3740 current_x - 1, min_y,
3741 current_x - 1, max_y - min_y);
3745 /* Warning: Very scary function.
3746 * Modify at your own risk
3748 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3749 * FIXME: It's not...
3752 pspp_sheet_view_bin_expose (GtkWidget *widget,
3753 GdkEventExpose *event)
3755 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3760 int drag_highlight = -1;
3763 gint y_offset, cell_offset;
3766 GdkRectangle background_area;
3767 GdkRectangle cell_area;
3769 gint bin_window_width;
3770 gint bin_window_height;
3771 GtkTreePath *cursor_path;
3772 GtkTreePath *drag_dest_path;
3773 GList *first_column, *last_column;
3774 gint vertical_separator;
3775 gint horizontal_separator;
3776 gint focus_line_width;
3777 gboolean allow_rules;
3778 gboolean has_special_cell;
3780 gint n_visible_columns;
3781 gint grid_line_width;
3782 gboolean row_ending_details;
3783 gboolean draw_vgrid_lines, draw_hgrid_lines;
3786 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3788 gtk_widget_style_get (widget,
3789 "horizontal-separator", &horizontal_separator,
3790 "vertical-separator", &vertical_separator,
3791 "allow-rules", &allow_rules,
3792 "focus-line-width", &focus_line_width,
3793 "row-ending-details", &row_ending_details,
3796 if (tree_view->priv->row_count == 0)
3798 draw_empty_focus (tree_view, &event->area);
3802 /* clip event->area to the visible area */
3803 if (event->area.height < 0)
3806 validate_visible_area (tree_view);
3808 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, event->area.y);
3812 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3813 gdk_drawable_get_size (tree_view->priv->bin_window,
3814 &bin_window_width, &bin_window_height);
3816 if (tree_view->priv->height < bin_window_height)
3818 gtk_paint_flat_box (widget->style,
3825 0, tree_view->priv->height,
3827 bin_window_height - tree_view->priv->height);
3833 /* find the path for the node */
3834 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3835 gtk_tree_model_get_iter (tree_view->priv->model,
3838 depth = gtk_tree_path_get_depth (path);
3839 gtk_tree_path_free (path);
3842 drag_dest_path = NULL;
3844 if (tree_view->priv->cursor)
3845 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3848 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3850 if (tree_view->priv->drag_dest_row)
3851 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3854 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3858 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3859 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3861 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3862 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3864 if (draw_vgrid_lines || draw_hgrid_lines)
3865 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3867 n_visible_columns = 0;
3868 for (list = tree_view->priv->columns; list; list = list->next)
3870 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3872 n_visible_columns ++;
3875 /* Find the last column */
3876 for (last_column = g_list_last (tree_view->priv->columns);
3877 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
3878 last_column = last_column->prev)
3882 for (first_column = g_list_first (tree_view->priv->columns);
3883 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
3884 first_column = first_column->next)
3887 /* Actually process the expose event. To do this, we want to
3888 * start at the first node of the event, and walk the tree in
3889 * order, drawing each successive node.
3896 gboolean is_first = FALSE;
3897 gboolean is_last = FALSE;
3898 gboolean done = FALSE;
3901 max_height = ROW_HEIGHT (tree_view);
3905 background_area.y = y_offset + event->area.y;
3906 background_area.height = max_height;
3907 max_y = background_area.y + max_height;
3911 if (node == tree_view->priv->prelight_node)
3912 flags |= GTK_CELL_RENDERER_PRELIT;
3914 selected = pspp_sheet_view_node_is_selected (tree_view, node);
3918 if (tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
3920 /* we *need* to set cell data on all cells before the call
3921 * to _has_special_cell, else _has_special_cell() does not
3922 * return a correct value.
3924 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3926 list = (rtl ? list->prev : list->next))
3928 PsppSheetViewColumn *column = list->data;
3929 pspp_sheet_view_column_cell_set_cell_data (column,
3930 tree_view->priv->model,
3934 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
3937 has_special_cell = tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
3939 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3941 list = (rtl ? list->prev : list->next))
3943 PsppSheetViewColumn *column = list->data;
3944 const gchar *detail = NULL;
3945 gboolean selected_column;
3948 if (!column->visible)
3951 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
3952 selected_column = column->selected && column->selectable;
3954 selected_column = TRUE;
3956 if (cell_offset > event->area.x + event->area.width ||
3957 cell_offset + column->width < event->area.x)
3959 cell_offset += column->width;
3963 if (selected && selected_column)
3964 flags |= GTK_CELL_RENDERER_SELECTED;
3966 flags &= ~GTK_CELL_RENDERER_SELECTED;
3968 if (column->show_sort_indicator)
3969 flags |= GTK_CELL_RENDERER_SORTED;
3971 flags &= ~GTK_CELL_RENDERER_SORTED;
3974 flags |= GTK_CELL_RENDERER_FOCUSED;
3976 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3978 background_area.x = cell_offset;
3979 background_area.width = column->width;
3981 cell_area = background_area;
3982 cell_area.y += vertical_separator / 2;
3983 cell_area.x += horizontal_separator / 2;
3984 cell_area.height -= vertical_separator;
3985 cell_area.width -= horizontal_separator;
3987 if (draw_vgrid_lines)
3989 if (list == first_column)
3991 cell_area.width -= grid_line_width / 2;
3993 else if (list == last_column)
3995 cell_area.x += grid_line_width / 2;
3996 cell_area.width -= grid_line_width / 2;
4000 cell_area.x += grid_line_width / 2;
4001 cell_area.width -= grid_line_width;
4005 if (draw_hgrid_lines)
4007 cell_area.y += grid_line_width / 2;
4008 cell_area.height -= grid_line_width;
4011 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
4013 cell_offset += column->width;
4017 pspp_sheet_view_column_cell_set_cell_data (column,
4018 tree_view->priv->model,
4021 /* Select the detail for drawing the cell. relevant
4022 * factors are parity, sortedness, and whether to
4025 if (allow_rules && tree_view->priv->has_rules)
4027 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4028 n_visible_columns >= 3)
4031 detail = "cell_odd_ruled_sorted";
4033 detail = "cell_even_ruled_sorted";
4038 detail = "cell_odd_ruled";
4040 detail = "cell_even_ruled";
4045 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4046 n_visible_columns >= 3)
4049 detail = "cell_odd_sorted";
4051 detail = "cell_even_sorted";
4056 detail = "cell_odd";
4058 detail = "cell_even";
4064 if (widget->state == GTK_STATE_INSENSITIVE)
4065 state = GTK_STATE_INSENSITIVE;
4066 else if (flags & GTK_CELL_RENDERER_SELECTED)
4067 state = GTK_STATE_SELECTED;
4069 state = GTK_STATE_NORMAL;
4071 /* Draw background */
4072 if (row_ending_details)
4074 char new_detail[128];
4076 is_first = (rtl ? !list->next : !list->prev);
4077 is_last = (rtl ? !list->prev : !list->next);
4079 /* (I don't like the snprintfs either, but couldn't find a
4082 if (is_first && is_last)
4083 g_snprintf (new_detail, 127, "%s", detail);
4085 g_snprintf (new_detail, 127, "%s_start", detail);
4087 g_snprintf (new_detail, 127, "%s_end", detail);
4089 g_snprintf (new_detail, 128, "%s_middle", detail);
4091 gtk_paint_flat_box (widget->style,
4100 background_area.width,
4101 background_area.height);
4105 gtk_paint_flat_box (widget->style,
4114 background_area.width,
4115 background_area.height);
4118 if (draw_hgrid_lines)
4120 if (background_area.y > 0)
4121 gdk_draw_line (event->window,
4122 tree_view->priv->grid_line_gc,
4123 background_area.x, background_area.y,
4124 background_area.x + background_area.width,
4127 if (y_offset + max_height >= event->area.height)
4128 gdk_draw_line (event->window,
4129 tree_view->priv->grid_line_gc,
4130 background_area.x, background_area.y + max_height,
4131 background_area.x + background_area.width,
4132 background_area.y + max_height);
4135 _pspp_sheet_view_column_cell_render (column,
4142 if (node == cursor && has_special_cell &&
4143 ((column == tree_view->priv->focus_column &&
4144 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4145 gtk_widget_has_focus (widget)) ||
4146 (column == tree_view->priv->edited_column)))
4148 _pspp_sheet_view_column_cell_draw_focus (column,
4156 cell_offset += column->width;
4159 if (cell_offset < event->area.x)
4161 gtk_paint_flat_box (widget->style,
4170 event->area.x - cell_offset,
4171 background_area.height);
4174 if (node == drag_highlight)
4176 /* Draw indicator for the drop
4178 gint highlight_y = -1;
4182 switch (tree_view->priv->drag_dest_pos)
4184 case PSPP_SHEET_VIEW_DROP_BEFORE:
4185 highlight_y = background_area.y - 1;
4186 if (highlight_y < 0)
4190 case PSPP_SHEET_VIEW_DROP_AFTER:
4191 highlight_y = background_area.y + background_area.height - 1;
4194 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4195 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4196 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4200 gdk_drawable_get_size (tree_view->priv->bin_window,
4203 if (row_ending_details)
4204 gtk_paint_focus (widget->style,
4205 tree_view->priv->bin_window,
4206 gtk_widget_get_state (widget),
4210 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4211 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4212 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4213 - focus_line_width / 2,
4214 width, ROW_HEIGHT (tree_view)
4215 - focus_line_width + 1);
4217 gtk_paint_focus (widget->style,
4218 tree_view->priv->bin_window,
4219 gtk_widget_get_state (widget),
4222 "treeview-drop-indicator",
4223 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4224 - focus_line_width / 2,
4225 width, ROW_HEIGHT (tree_view)
4226 - focus_line_width + 1);
4230 if (highlight_y >= 0)
4232 gdk_draw_line (event->window,
4233 widget->style->fg_gc[gtk_widget_get_state (widget)],
4236 rtl ? 0 : bin_window_width,
4241 /* draw the big row-spanning focus rectangle, if needed */
4242 if (!has_special_cell && node == cursor &&
4243 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4244 gtk_widget_has_focus (widget))
4246 gint tmp_y, tmp_height;
4248 GtkStateType focus_rect_state;
4251 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4252 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4253 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4256 gdk_drawable_get_size (tree_view->priv->bin_window,
4259 if (draw_hgrid_lines)
4261 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4262 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4266 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4267 tmp_height = ROW_HEIGHT (tree_view);
4270 if (row_ending_details)
4271 gtk_paint_focus (widget->style,
4272 tree_view->priv->bin_window,
4277 ? (is_last ? "treeview" : "treeview-left" )
4278 : (is_last ? "treeview-right" : "treeview-middle" )),
4282 gtk_paint_focus (widget->style,
4283 tree_view->priv->bin_window,
4292 y_offset += max_height;
4296 node = pspp_sheet_view_node_next (tree_view, node);
4299 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4303 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4310 while (y_offset < event->area.height);
4313 pspp_sheet_view_draw_grid_lines (tree_view, event, n_visible_columns,
4316 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4318 GdkRectangle *rectangles;
4321 gdk_region_get_rectangles (event->region,
4325 while (n_rectangles--)
4326 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4328 g_free (rectangles);
4332 gtk_tree_path_free (cursor_path);
4335 gtk_tree_path_free (drag_dest_path);
4341 pspp_sheet_view_expose (GtkWidget *widget,
4342 GdkEventExpose *event)
4344 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4346 if (event->window == tree_view->priv->bin_window)
4351 retval = pspp_sheet_view_bin_expose (widget, event);
4353 /* We can't just chain up to Container::expose as it will try to send the
4354 * event to the headers, so we handle propagating it to our children
4355 * (eg. widgets being edited) ourselves.
4357 tmp_list = tree_view->priv->children;
4360 PsppSheetViewChild *child = tmp_list->data;
4361 tmp_list = tmp_list->next;
4363 gtk_container_propagate_expose (GTK_CONTAINER (tree_view), child->widget, event);
4369 else if (event->window == tree_view->priv->header_window)
4371 gint n_visible_columns;
4374 gtk_paint_flat_box (widget->style,
4384 event->area.height);
4386 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4388 PsppSheetViewColumn *column = list->data;
4390 if (column == tree_view->priv->drag_column || !column->visible)
4393 if (span_intersects (column->allocation.x, column->allocation.width,
4394 event->area.x, event->area.width)
4395 && column->button != NULL)
4396 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4397 column->button, event);
4400 n_visible_columns = 0;
4401 for (list = tree_view->priv->columns; list; list = list->next)
4403 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4405 n_visible_columns ++;
4407 pspp_sheet_view_draw_grid_lines (tree_view,
4411 event->area.height);
4413 else if (event->window == tree_view->priv->drag_window)
4415 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4416 tree_view->priv->drag_column->button,
4430 /* returns 0x1 when no column has been found -- yes it's hackish */
4431 static PsppSheetViewColumn *
4432 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4433 PsppSheetViewColumn *column,
4436 PsppSheetViewColumn *left_column = NULL;
4437 PsppSheetViewColumn *cur_column = NULL;
4440 if (!column->reorderable)
4441 return (PsppSheetViewColumn *)0x1;
4443 switch (drop_position)
4446 /* find first column where we can drop */
4447 tmp_list = tree_view->priv->columns;
4448 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4449 return (PsppSheetViewColumn *)0x1;
4453 g_assert (tmp_list);
4455 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4456 tmp_list = tmp_list->next;
4458 if (left_column && left_column->visible == FALSE)
4461 if (!tree_view->priv->column_drop_func)
4464 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4466 left_column = cur_column;
4473 if (!tree_view->priv->column_drop_func)
4476 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4479 return (PsppSheetViewColumn *)0x1;
4483 /* find first column after column where we can drop */
4484 tmp_list = tree_view->priv->columns;
4486 for (; tmp_list; tmp_list = tmp_list->next)
4487 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4490 if (!tmp_list || !tmp_list->next)
4491 return (PsppSheetViewColumn *)0x1;
4493 tmp_list = tmp_list->next;
4494 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4495 tmp_list = tmp_list->next;
4499 g_assert (tmp_list);
4501 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4502 tmp_list = tmp_list->next;
4504 if (left_column && left_column->visible == FALSE)
4506 left_column = cur_column;
4508 tmp_list = tmp_list->next;
4512 if (!tree_view->priv->column_drop_func)
4515 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4517 left_column = cur_column;
4524 if (!tree_view->priv->column_drop_func)
4527 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4530 return (PsppSheetViewColumn *)0x1;
4534 /* find first column before column where we can drop */
4535 tmp_list = tree_view->priv->columns;
4537 for (; tmp_list; tmp_list = tmp_list->next)
4538 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4541 if (!tmp_list || !tmp_list->prev)
4542 return (PsppSheetViewColumn *)0x1;
4544 tmp_list = tmp_list->prev;
4545 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4546 tmp_list = tmp_list->prev;
4550 g_assert (tmp_list);
4552 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4554 if (left_column && !left_column->visible)
4556 /*if (!tmp_list->prev)
4557 return (PsppSheetViewColumn *)0x1;
4560 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4561 tmp_list = tmp_list->prev->prev;
4564 cur_column = left_column;
4566 tmp_list = tmp_list->prev;
4570 if (!tree_view->priv->column_drop_func)
4573 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4576 cur_column = left_column;
4577 tmp_list = tmp_list->prev;
4580 if (!tree_view->priv->column_drop_func)
4583 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4586 return (PsppSheetViewColumn *)0x1;
4590 /* same as DROP_HOME case, but doing it backwards */
4591 tmp_list = g_list_last (tree_view->priv->columns);
4594 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4595 return (PsppSheetViewColumn *)0x1;
4599 g_assert (tmp_list);
4601 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4603 if (left_column && !left_column->visible)
4605 cur_column = left_column;
4606 tmp_list = tmp_list->prev;
4609 if (!tree_view->priv->column_drop_func)
4612 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4615 cur_column = left_column;
4616 tmp_list = tmp_list->prev;
4619 if (!tree_view->priv->column_drop_func)
4622 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4625 return (PsppSheetViewColumn *)0x1;
4629 return (PsppSheetViewColumn *)0x1;
4633 pspp_sheet_view_key_press (GtkWidget *widget,
4636 PsppSheetView *tree_view = (PsppSheetView *) widget;
4638 if (tree_view->priv->rubber_band_status)
4640 if (event->keyval == GDK_Escape)
4641 pspp_sheet_view_stop_rubber_band (tree_view);
4646 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4648 if (event->keyval == GDK_Escape)
4650 tree_view->priv->cur_reorder = NULL;
4651 pspp_sheet_view_button_release_drag_column (widget, NULL);
4656 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4658 GList *focus_column;
4661 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4663 for (focus_column = tree_view->priv->columns;
4665 focus_column = focus_column->next)
4667 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4669 if (column->button && gtk_widget_has_focus (column->button))
4674 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4675 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4676 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4678 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4680 if (!column->resizable)
4682 gtk_widget_error_bell (widget);
4686 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4687 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4689 gint old_width = column->resized_width;
4691 column->resized_width = MAX (column->resized_width,
4693 column->resized_width -= 2;
4694 if (column->resized_width < 0)
4695 column->resized_width = 0;
4697 if (column->min_width == -1)
4698 column->resized_width = MAX (column->button_request,
4699 column->resized_width);
4701 column->resized_width = MAX (column->min_width,
4702 column->resized_width);
4704 if (column->max_width != -1)
4705 column->resized_width = MIN (column->resized_width,
4708 column->use_resized_width = TRUE;
4710 if (column->resized_width != old_width)
4711 gtk_widget_queue_resize (widget);
4713 gtk_widget_error_bell (widget);
4715 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4716 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4718 gint old_width = column->resized_width;
4720 column->resized_width = MAX (column->resized_width,
4722 column->resized_width += 2;
4724 if (column->max_width != -1)
4725 column->resized_width = MIN (column->resized_width,
4728 column->use_resized_width = TRUE;
4730 if (column->resized_width != old_width)
4731 gtk_widget_queue_resize (widget);
4733 gtk_widget_error_bell (widget);
4740 (event->state & GDK_MOD1_MASK) &&
4741 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4742 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4743 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4744 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4746 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4748 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4749 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4751 PsppSheetViewColumn *col;
4752 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4753 if (col != (PsppSheetViewColumn *)0x1)
4754 pspp_sheet_view_move_column_after (tree_view, column, col);
4756 gtk_widget_error_bell (widget);
4758 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4759 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4761 PsppSheetViewColumn *col;
4762 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
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_Home || event->keyval == GDK_KP_Home)
4770 PsppSheetViewColumn *col;
4771 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4772 if (col != (PsppSheetViewColumn *)0x1)
4773 pspp_sheet_view_move_column_after (tree_view, column, col);
4775 gtk_widget_error_bell (widget);
4777 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4779 PsppSheetViewColumn *col;
4780 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4781 if (col != (PsppSheetViewColumn *)0x1)
4782 pspp_sheet_view_move_column_after (tree_view, column, col);
4784 gtk_widget_error_bell (widget);
4791 /* Chain up to the parent class. It handles the keybindings. */
4792 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4795 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4797 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4801 /* We pass the event to the search_entry. If its text changes, then we start
4802 * the typeahead find capabilities. */
4803 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4804 && tree_view->priv->enable_search
4805 && !tree_view->priv->search_custom_entry_set)
4807 GdkEvent *new_event;
4809 const char *new_text;
4812 gboolean text_modified;
4813 gulong popup_menu_id;
4815 pspp_sheet_view_ensure_interactive_directory (tree_view);
4817 /* Make a copy of the current text */
4818 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4819 new_event = gdk_event_copy ((GdkEvent *) event);
4820 g_object_unref (((GdkEventKey *) new_event)->window);
4821 ((GdkEventKey *) new_event)->window = g_object_ref (tree_view->priv->search_window->window);
4822 gtk_widget_realize (tree_view->priv->search_window);
4824 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4825 "popup-menu", G_CALLBACK (gtk_true),
4828 /* Move the entry off screen */
4829 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4830 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4831 gdk_screen_get_width (screen) + 1,
4832 gdk_screen_get_height (screen) + 1);
4833 gtk_widget_show (tree_view->priv->search_window);
4835 /* Send the event to the window. If the preedit_changed signal is emitted
4836 * during this event, we will set priv->imcontext_changed */
4837 tree_view->priv->imcontext_changed = FALSE;
4838 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4839 gdk_event_free (new_event);
4840 gtk_widget_hide (tree_view->priv->search_window);
4842 g_signal_handler_disconnect (tree_view->priv->search_entry,
4845 /* We check to make sure that the entry tried to handle the text, and that
4846 * the text has changed.
4848 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4849 text_modified = strcmp (old_text, new_text) != 0;
4851 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4852 (retval && text_modified)) /* ...or the text was modified */
4854 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4856 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4861 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
4871 pspp_sheet_view_key_release (GtkWidget *widget,
4874 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4876 if (tree_view->priv->rubber_band_status)
4879 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
4882 /* FIXME Is this function necessary? Can I get an enter_notify event
4883 * w/o either an expose event or a mouse motion event?
4886 pspp_sheet_view_enter_notify (GtkWidget *widget,
4887 GdkEventCrossing *event)
4889 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4893 /* Sanity check it */
4894 if (event->window != tree_view->priv->bin_window)
4897 if (tree_view->priv->row_count == 0)
4900 if (event->mode == GDK_CROSSING_GRAB ||
4901 event->mode == GDK_CROSSING_GTK_GRAB ||
4902 event->mode == GDK_CROSSING_GTK_UNGRAB ||
4903 event->mode == GDK_CROSSING_STATE_CHANGED)
4906 /* find the node internally */
4907 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
4910 pspp_sheet_view_find_offset (tree_view, new_y, &node);
4912 tree_view->priv->event_last_x = event->x;
4913 tree_view->priv->event_last_y = event->y;
4915 prelight_or_select (tree_view, node, event->x, event->y);
4921 pspp_sheet_view_leave_notify (GtkWidget *widget,
4922 GdkEventCrossing *event)
4924 PsppSheetView *tree_view;
4926 if (event->mode == GDK_CROSSING_GRAB)
4929 tree_view = PSPP_SHEET_VIEW (widget);
4931 if (tree_view->priv->prelight_node >= 0)
4932 _pspp_sheet_view_queue_draw_node (tree_view,
4933 tree_view->priv->prelight_node,
4936 tree_view->priv->event_last_x = -10000;
4937 tree_view->priv->event_last_y = -10000;
4939 prelight_or_select (tree_view,
4941 -1000, -1000); /* coords not possibly over an arrow */
4948 pspp_sheet_view_focus_out (GtkWidget *widget,
4949 GdkEventFocus *event)
4951 PsppSheetView *tree_view;
4953 tree_view = PSPP_SHEET_VIEW (widget);
4955 gtk_widget_queue_draw (widget);
4957 /* destroy interactive search dialog */
4958 if (tree_view->priv->search_window)
4959 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
4965 /* Incremental Reflow
4969 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
4974 y = pspp_sheet_view_node_find_offset (tree_view, node)
4975 - tree_view->priv->vadjustment->value
4976 + TREE_VIEW_HEADER_HEIGHT (tree_view);
4978 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
4980 GTK_WIDGET (tree_view)->allocation.width,
4981 tree_view->priv->fixed_height);
4985 node_is_visible (PsppSheetView *tree_view,
4991 y = pspp_sheet_view_node_find_offset (tree_view, node);
4992 height = ROW_HEIGHT (tree_view);
4994 if (y >= tree_view->priv->vadjustment->value &&
4995 y + height <= (tree_view->priv->vadjustment->value
4996 + tree_view->priv->vadjustment->page_size))
5002 /* Returns the row height. */
5004 validate_row (PsppSheetView *tree_view,
5009 PsppSheetViewColumn *column;
5010 GList *list, *first_column, *last_column;
5012 gint horizontal_separator;
5013 gint vertical_separator;
5014 gint focus_line_width;
5015 gboolean retval = FALSE;
5016 gboolean draw_vgrid_lines, draw_hgrid_lines;
5018 gint grid_line_width;
5019 gboolean wide_separators;
5020 gint separator_height;
5022 gtk_widget_style_get (GTK_WIDGET (tree_view),
5023 "focus-padding", &focus_pad,
5024 "focus-line-width", &focus_line_width,
5025 "horizontal-separator", &horizontal_separator,
5026 "vertical-separator", &vertical_separator,
5027 "grid-line-width", &grid_line_width,
5028 "wide-separators", &wide_separators,
5029 "separator-height", &separator_height,
5033 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5034 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5036 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5037 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5039 for (last_column = g_list_last (tree_view->priv->columns);
5040 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5041 last_column = last_column->prev)
5044 for (first_column = g_list_first (tree_view->priv->columns);
5045 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5046 first_column = first_column->next)
5049 for (list = tree_view->priv->columns; list; list = list->next)
5054 column = list->data;
5056 if (! column->visible)
5059 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5060 pspp_sheet_view_column_cell_get_size (column,
5062 &tmp_width, &tmp_height);
5064 tmp_height += vertical_separator;
5065 height = MAX (height, tmp_height);
5067 tmp_width = tmp_width + horizontal_separator;
5069 if (draw_vgrid_lines)
5071 if (list->data == first_column || list->data == last_column)
5072 tmp_width += grid_line_width / 2.0;
5074 tmp_width += grid_line_width;
5077 if (tmp_width > column->requested_width)
5080 column->requested_width = tmp_width;
5084 if (draw_hgrid_lines)
5085 height += grid_line_width;
5087 tree_view->priv->post_validation_flag = TRUE;
5093 validate_visible_area (PsppSheetView *tree_view)
5095 GtkTreePath *path = NULL;
5096 GtkTreePath *above_path = NULL;
5099 gboolean size_changed = FALSE;
5101 gint area_above = 0;
5102 gint area_below = 0;
5104 if (tree_view->priv->row_count == 0)
5107 if (tree_view->priv->scroll_to_path == NULL)
5110 total_height = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5112 if (total_height == 0)
5115 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5118 /* we are going to scroll, and will update dy */
5119 _pspp_sheet_view_find_node (tree_view, path, &node);
5120 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5122 if (tree_view->priv->scroll_to_use_align)
5124 gint height = ROW_HEIGHT (tree_view);
5125 area_above = (total_height - height) *
5126 tree_view->priv->scroll_to_row_align;
5127 area_below = total_height - area_above - height;
5128 area_above = MAX (area_above, 0);
5129 area_below = MAX (area_below, 0);
5134 * 1) row not visible
5138 gint height = ROW_HEIGHT (tree_view);
5140 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5142 if (dy >= tree_view->priv->vadjustment->value &&
5143 dy + height <= (tree_view->priv->vadjustment->value
5144 + tree_view->priv->vadjustment->page_size))
5146 /* row visible: keep the row at the same position */
5147 area_above = dy - tree_view->priv->vadjustment->value;
5148 area_below = (tree_view->priv->vadjustment->value +
5149 tree_view->priv->vadjustment->page_size)
5154 /* row not visible */
5156 && dy + height <= tree_view->priv->vadjustment->page_size)
5158 /* row at the beginning -- fixed */
5160 area_below = tree_view->priv->vadjustment->page_size
5161 - area_above - height;
5163 else if (dy >= (tree_view->priv->vadjustment->upper -
5164 tree_view->priv->vadjustment->page_size))
5166 /* row at the end -- fixed */
5167 area_above = dy - (tree_view->priv->vadjustment->upper -
5168 tree_view->priv->vadjustment->page_size);
5169 area_below = tree_view->priv->vadjustment->page_size -
5170 area_above - height;
5174 area_above = tree_view->priv->vadjustment->page_size - height;
5180 /* row somewhere in the middle, bring it to the top
5184 area_below = total_height - height;
5190 /* the scroll to isn't valid; ignore it.
5193 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5194 tree_view->priv->scroll_to_path = NULL;
5198 above_path = gtk_tree_path_copy (path);
5200 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5201 * backwards is much slower then forward, as there is no iter_prev function.
5202 * We go forwards first in case we run out of tree. Then we go backwards to
5205 while (node >= 0 && area_below > 0)
5207 gboolean done = FALSE;
5210 node = pspp_sheet_view_node_next (tree_view, node);
5213 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5215 gtk_tree_path_next (path);
5218 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5228 area_below -= ROW_HEIGHT (tree_view);
5230 gtk_tree_path_free (path);
5232 /* If we ran out of tree, and have extra area_below left, we need to add it
5235 area_above += area_below;
5237 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5239 /* We walk backwards */
5240 while (area_above > 0)
5242 node = pspp_sheet_view_node_prev (tree_view, node);
5244 /* Always find the new path in the tree. We cannot just assume
5245 * a gtk_tree_path_prev() is enough here, as there might be children
5246 * in between this node and the previous sibling node. If this
5247 * appears to be a performance hotspot in profiles, we can look into
5248 * intrigate logic for keeping path, node and iter in sync like
5249 * we do for forward walks. (Which will be hard because of the lacking
5256 gtk_tree_path_free (above_path);
5257 above_path = _pspp_sheet_view_find_path (tree_view, node);
5259 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5261 area_above -= ROW_HEIGHT (tree_view);
5264 /* set the dy here to scroll to the path,
5265 * and sync the top row accordingly
5267 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5268 pspp_sheet_view_top_row_to_dy (tree_view);
5270 /* update width/height and queue a resize */
5273 GtkRequisition requisition;
5275 /* We temporarily guess a size, under the assumption that it will be the
5276 * same when we get our next size_allocate. If we don't do this, we'll be
5277 * in an inconsistent state if we call top_row_to_dy. */
5279 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5280 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5281 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5282 gtk_adjustment_changed (tree_view->priv->hadjustment);
5283 gtk_adjustment_changed (tree_view->priv->vadjustment);
5284 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5287 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5288 tree_view->priv->scroll_to_path = NULL;
5291 gtk_tree_path_free (above_path);
5293 if (tree_view->priv->scroll_to_column)
5295 tree_view->priv->scroll_to_column = NULL;
5297 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5301 initialize_fixed_height_mode (PsppSheetView *tree_view)
5303 if (!tree_view->priv->row_count)
5306 if (tree_view->priv->fixed_height_set)
5309 if (tree_view->priv->fixed_height < 0)
5316 path = _pspp_sheet_view_find_path (tree_view, node);
5317 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5319 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5321 gtk_tree_path_free (path);
5323 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5327 /* Our strategy for finding nodes to validate is a little convoluted. We find
5328 * the left-most uninvalidated node. We then try walking right, validating
5329 * nodes. Once we find a valid node, we repeat the previous process of finding
5330 * the first invalid node.
5334 validate_rows_handler (PsppSheetView *tree_view)
5336 initialize_fixed_height_mode (tree_view);
5337 if (tree_view->priv->validate_rows_timer)
5339 g_source_remove (tree_view->priv->validate_rows_timer);
5340 tree_view->priv->validate_rows_timer = 0;
5347 do_presize_handler (PsppSheetView *tree_view)
5349 GtkRequisition requisition;
5351 validate_visible_area (tree_view);
5352 tree_view->priv->presize_handler_timer = 0;
5354 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5356 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5357 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5358 gtk_adjustment_changed (tree_view->priv->hadjustment);
5359 gtk_adjustment_changed (tree_view->priv->vadjustment);
5360 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5366 presize_handler_callback (gpointer data)
5368 do_presize_handler (PSPP_SHEET_VIEW (data));
5374 install_presize_handler (PsppSheetView *tree_view)
5376 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5379 if (! tree_view->priv->presize_handler_timer)
5381 tree_view->priv->presize_handler_timer =
5382 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5384 if (! tree_view->priv->validate_rows_timer)
5386 tree_view->priv->validate_rows_timer =
5387 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5392 scroll_sync_handler (PsppSheetView *tree_view)
5394 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
5395 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5396 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5397 pspp_sheet_view_top_row_to_dy (tree_view);
5399 pspp_sheet_view_dy_to_top_row (tree_view);
5401 tree_view->priv->scroll_sync_timer = 0;
5407 install_scroll_sync_handler (PsppSheetView *tree_view)
5409 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5412 if (!tree_view->priv->scroll_sync_timer)
5414 tree_view->priv->scroll_sync_timer =
5415 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5420 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5424 gtk_tree_row_reference_free (tree_view->priv->top_row);
5428 tree_view->priv->top_row = NULL;
5429 tree_view->priv->top_row_dy = 0;
5433 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5434 tree_view->priv->top_row_dy = offset;
5438 /* Always call this iff dy is in the visible range. If the tree is empty, then
5439 * it's set to be NULL, and top_row_dy is 0;
5442 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5448 if (tree_view->priv->row_count == 0)
5450 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5454 offset = pspp_sheet_view_find_offset (tree_view,
5455 tree_view->priv->dy,
5460 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5464 path = _pspp_sheet_view_find_path (tree_view, node);
5465 pspp_sheet_view_set_top_row (tree_view, path, offset);
5466 gtk_tree_path_free (path);
5472 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5478 /* Avoid recursive calls */
5479 if (tree_view->priv->in_top_row_to_dy)
5482 if (tree_view->priv->top_row)
5483 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5490 _pspp_sheet_view_find_node (tree_view, path, &node);
5493 gtk_tree_path_free (path);
5497 /* keep dy and set new toprow */
5498 gtk_tree_row_reference_free (tree_view->priv->top_row);
5499 tree_view->priv->top_row = NULL;
5500 tree_view->priv->top_row_dy = 0;
5501 /* DO NOT install the idle handler */
5502 pspp_sheet_view_dy_to_top_row (tree_view);
5506 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5508 /* new top row -- do NOT install the idle handler */
5509 pspp_sheet_view_dy_to_top_row (tree_view);
5513 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5514 new_dy += tree_view->priv->top_row_dy;
5516 if (new_dy + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
5517 new_dy = tree_view->priv->height - tree_view->priv->vadjustment->page_size;
5519 new_dy = MAX (0, new_dy);
5521 tree_view->priv->in_top_row_to_dy = TRUE;
5522 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5523 tree_view->priv->in_top_row_to_dy = FALSE;
5528 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5530 install_presize_handler (tree_view);
5536 set_source_row (GdkDragContext *context,
5537 GtkTreeModel *model,
5538 GtkTreePath *source_row)
5540 g_object_set_data_full (G_OBJECT (context),
5541 "gtk-tree-view-source-row",
5542 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5543 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5547 get_source_row (GdkDragContext *context)
5549 GtkTreeRowReference *ref =
5550 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5553 return gtk_tree_row_reference_get_path (ref);
5560 GtkTreeRowReference *dest_row;
5561 guint path_down_mode : 1;
5562 guint empty_view_drop : 1;
5563 guint drop_append_mode : 1;
5568 dest_row_free (gpointer data)
5570 DestRow *dr = (DestRow *)data;
5572 gtk_tree_row_reference_free (dr->dest_row);
5573 g_slice_free (DestRow, dr);
5577 set_dest_row (GdkDragContext *context,
5578 GtkTreeModel *model,
5579 GtkTreePath *dest_row,
5580 gboolean path_down_mode,
5581 gboolean empty_view_drop,
5582 gboolean drop_append_mode)
5588 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5593 dr = g_slice_new (DestRow);
5595 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5596 dr->path_down_mode = path_down_mode != FALSE;
5597 dr->empty_view_drop = empty_view_drop != FALSE;
5598 dr->drop_append_mode = drop_append_mode != FALSE;
5600 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5601 dr, (GDestroyNotify) dest_row_free);
5605 get_dest_row (GdkDragContext *context,
5606 gboolean *path_down_mode)
5609 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5613 GtkTreePath *path = NULL;
5616 *path_down_mode = dr->path_down_mode;
5619 path = gtk_tree_row_reference_get_path (dr->dest_row);
5620 else if (dr->empty_view_drop)
5621 path = gtk_tree_path_new_from_indices (0, -1);
5625 if (path && dr->drop_append_mode)
5626 gtk_tree_path_next (path);
5634 /* Get/set whether drag_motion requested the drag data and
5635 * drag_data_received should thus not actually insert the data,
5636 * since the data doesn't result from a drop.
5639 set_status_pending (GdkDragContext *context,
5640 GdkDragAction suggested_action)
5642 g_object_set_data (G_OBJECT (context),
5643 "gtk-tree-view-status-pending",
5644 GINT_TO_POINTER (suggested_action));
5647 static GdkDragAction
5648 get_status_pending (GdkDragContext *context)
5650 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5651 "gtk-tree-view-status-pending"));
5654 static TreeViewDragInfo*
5655 get_info (PsppSheetView *tree_view)
5657 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5661 destroy_info (TreeViewDragInfo *di)
5663 g_slice_free (TreeViewDragInfo, di);
5666 static TreeViewDragInfo*
5667 ensure_info (PsppSheetView *tree_view)
5669 TreeViewDragInfo *di;
5671 di = get_info (tree_view);
5675 di = g_slice_new0 (TreeViewDragInfo);
5677 g_object_set_data_full (G_OBJECT (tree_view),
5678 "gtk-tree-view-drag-info",
5680 (GDestroyNotify) destroy_info);
5687 remove_info (PsppSheetView *tree_view)
5689 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5694 drag_scan_timeout (gpointer data)
5696 PsppSheetView *tree_view;
5698 GdkModifierType state;
5699 GtkTreePath *path = NULL;
5700 PsppSheetViewColumn *column = NULL;
5701 GdkRectangle visible_rect;
5703 GDK_THREADS_ENTER ();
5705 tree_view = PSPP_SHEET_VIEW (data);
5707 gdk_window_get_pointer (tree_view->priv->bin_window,
5710 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5712 /* See if we are near the edge. */
5713 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5714 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5715 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5716 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5718 pspp_sheet_view_get_path_at_pos (tree_view,
5719 tree_view->priv->bin_window,
5728 pspp_sheet_view_scroll_to_cell (tree_view,
5734 gtk_tree_path_free (path);
5738 GDK_THREADS_LEAVE ();
5745 add_scroll_timeout (PsppSheetView *tree_view)
5747 if (tree_view->priv->scroll_timeout == 0)
5749 tree_view->priv->scroll_timeout =
5750 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5755 remove_scroll_timeout (PsppSheetView *tree_view)
5757 if (tree_view->priv->scroll_timeout != 0)
5759 g_source_remove (tree_view->priv->scroll_timeout);
5760 tree_view->priv->scroll_timeout = 0;
5765 check_model_dnd (GtkTreeModel *model,
5766 GType required_iface,
5767 const gchar *signal)
5769 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5771 g_warning ("You must override the default '%s' handler "
5772 "on PsppSheetView when using models that don't support "
5773 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5774 "is to connect to '%s' and call "
5775 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5776 "the default handler from running. Look at the source code "
5777 "for the default handler in gtktreeview.c to get an idea what "
5778 "your handler should do. (gtktreeview.c is in the GTK source "
5779 "code.) If you're using GTK from a language other than C, "
5780 "there may be a more natural way to override default handlers, e.g. via derivation.",
5781 signal, g_type_name (required_iface), signal);
5789 scroll_row_timeout (gpointer data)
5791 PsppSheetView *tree_view = data;
5793 pspp_sheet_view_horizontal_autoscroll (tree_view);
5794 pspp_sheet_view_vertical_autoscroll (tree_view);
5796 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5797 pspp_sheet_view_update_rubber_band (tree_view);
5802 /* Returns TRUE if event should not be propagated to parent widgets */
5804 set_destination_row (PsppSheetView *tree_view,
5805 GdkDragContext *context,
5806 /* coordinates relative to the widget */
5809 GdkDragAction *suggested_action,
5812 GtkTreePath *path = NULL;
5813 PsppSheetViewDropPosition pos;
5814 PsppSheetViewDropPosition old_pos;
5815 TreeViewDragInfo *di;
5817 GtkTreePath *old_dest_path = NULL;
5818 gboolean can_drop = FALSE;
5820 *suggested_action = 0;
5823 widget = GTK_WIDGET (tree_view);
5825 di = get_info (tree_view);
5827 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5829 /* someone unset us as a drag dest, note that if
5830 * we return FALSE drag_leave isn't called
5833 pspp_sheet_view_set_drag_dest_row (tree_view,
5835 PSPP_SHEET_VIEW_DROP_BEFORE);
5837 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5839 return FALSE; /* no longer a drop site */
5842 *target = gtk_drag_dest_find_target (widget, context,
5843 gtk_drag_dest_get_target_list (widget));
5844 if (*target == GDK_NONE)
5849 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5855 GtkTreeModel *model;
5857 /* the row got dropped on empty space, let's setup a special case
5861 gtk_tree_path_free (path);
5863 model = pspp_sheet_view_get_model (tree_view);
5865 n_children = gtk_tree_model_iter_n_children (model, NULL);
5868 pos = PSPP_SHEET_VIEW_DROP_AFTER;
5869 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5873 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
5874 path = gtk_tree_path_new_from_indices (0, -1);
5884 /* If we left the current row's "open" zone, unset the timeout for
5887 pspp_sheet_view_get_drag_dest_row (tree_view,
5892 gtk_tree_path_free (old_dest_path);
5894 if (TRUE /* FIXME if the location droppable predicate */)
5902 GtkWidget *source_widget;
5904 *suggested_action = context->suggested_action;
5905 source_widget = gtk_drag_get_source_widget (context);
5907 if (source_widget == widget)
5909 /* Default to MOVE, unless the user has
5910 * pressed ctrl or shift to affect available actions
5912 if ((context->actions & GDK_ACTION_MOVE) != 0)
5913 *suggested_action = GDK_ACTION_MOVE;
5916 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5921 /* can't drop here */
5922 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5924 PSPP_SHEET_VIEW_DROP_BEFORE);
5928 gtk_tree_path_free (path);
5934 get_logical_dest_row (PsppSheetView *tree_view,
5935 gboolean *path_down_mode,
5936 gboolean *drop_append_mode)
5938 /* adjust path to point to the row the drop goes in front of */
5939 GtkTreePath *path = NULL;
5940 PsppSheetViewDropPosition pos;
5942 g_return_val_if_fail (path_down_mode != NULL, NULL);
5943 g_return_val_if_fail (drop_append_mode != NULL, NULL);
5945 *path_down_mode = FALSE;
5946 *drop_append_mode = 0;
5948 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
5953 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
5955 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
5956 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
5957 *path_down_mode = TRUE;
5961 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
5963 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
5965 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5966 !gtk_tree_model_iter_next (model, &iter))
5967 *drop_append_mode = 1;
5970 *drop_append_mode = 0;
5971 gtk_tree_path_next (path);
5979 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
5980 GdkEventMotion *event)
5982 GtkWidget *widget = GTK_WIDGET (tree_view);
5983 GdkDragContext *context;
5984 TreeViewDragInfo *di;
5985 GtkTreePath *path = NULL;
5987 gint cell_x, cell_y;
5988 GtkTreeModel *model;
5989 gboolean retval = FALSE;
5991 di = get_info (tree_view);
5993 if (di == NULL || !di->source_set)
5996 if (tree_view->priv->pressed_button < 0)
5999 if (!gtk_drag_check_threshold (widget,
6000 tree_view->priv->press_start_x,
6001 tree_view->priv->press_start_y,
6002 event->x, event->y))
6005 model = pspp_sheet_view_get_model (tree_view);
6010 button = tree_view->priv->pressed_button;
6011 tree_view->priv->pressed_button = -1;
6013 pspp_sheet_view_get_path_at_pos (tree_view,
6014 tree_view->priv->press_start_x,
6015 tree_view->priv->press_start_y,
6024 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6025 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6029 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6032 /* Now we can begin the drag */
6036 context = gtk_drag_begin (widget,
6037 gtk_drag_source_get_target_list (widget),
6042 set_source_row (context, model, path);
6046 gtk_tree_path_free (path);
6053 pspp_sheet_view_drag_begin (GtkWidget *widget,
6054 GdkDragContext *context)
6056 PsppSheetView *tree_view;
6057 GtkTreePath *path = NULL;
6058 gint cell_x, cell_y;
6060 TreeViewDragInfo *di;
6062 tree_view = PSPP_SHEET_VIEW (widget);
6064 /* if the user uses a custom DND source impl, we don't set the icon here */
6065 di = get_info (tree_view);
6067 if (di == NULL || !di->source_set)
6070 pspp_sheet_view_get_path_at_pos (tree_view,
6071 tree_view->priv->press_start_x,
6072 tree_view->priv->press_start_y,
6078 g_return_if_fail (path != NULL);
6080 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6083 gtk_drag_set_icon_pixmap (context,
6084 gdk_drawable_get_colormap (row_pix),
6087 /* the + 1 is for the black border in the icon */
6088 tree_view->priv->press_start_x + 1,
6091 g_object_unref (row_pix);
6092 gtk_tree_path_free (path);
6096 pspp_sheet_view_drag_end (GtkWidget *widget,
6097 GdkDragContext *context)
6102 /* Default signal implementations for the drag signals */
6104 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6105 GdkDragContext *context,
6106 GtkSelectionData *selection_data,
6110 PsppSheetView *tree_view;
6111 GtkTreeModel *model;
6112 TreeViewDragInfo *di;
6113 GtkTreePath *source_row;
6115 tree_view = PSPP_SHEET_VIEW (widget);
6117 model = pspp_sheet_view_get_model (tree_view);
6122 di = get_info (PSPP_SHEET_VIEW (widget));
6127 source_row = get_source_row (context);
6129 if (source_row == NULL)
6132 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6133 * any model; for DragSource models there are some other targets
6137 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6138 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6143 /* If drag_data_get does nothing, try providing row data. */
6144 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6146 gtk_tree_set_row_drag_data (selection_data,
6152 gtk_tree_path_free (source_row);
6157 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6158 GdkDragContext *context)
6160 TreeViewDragInfo *di;
6161 GtkTreeModel *model;
6162 PsppSheetView *tree_view;
6163 GtkTreePath *source_row;
6165 tree_view = PSPP_SHEET_VIEW (widget);
6166 model = pspp_sheet_view_get_model (tree_view);
6168 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6171 di = get_info (tree_view);
6176 source_row = get_source_row (context);
6178 if (source_row == NULL)
6181 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6184 gtk_tree_path_free (source_row);
6186 set_source_row (context, NULL, NULL);
6190 pspp_sheet_view_drag_leave (GtkWidget *widget,
6191 GdkDragContext *context,
6194 /* unset any highlight row */
6195 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6197 PSPP_SHEET_VIEW_DROP_BEFORE);
6199 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6204 pspp_sheet_view_drag_motion (GtkWidget *widget,
6205 GdkDragContext *context,
6206 /* coordinates relative to the widget */
6212 GtkTreePath *path = NULL;
6213 PsppSheetViewDropPosition pos;
6214 PsppSheetView *tree_view;
6215 GdkDragAction suggested_action = 0;
6218 tree_view = PSPP_SHEET_VIEW (widget);
6220 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6223 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6225 /* we only know this *after* set_desination_row */
6226 empty = tree_view->priv->empty_view_drop;
6228 if (path == NULL && !empty)
6230 /* Can't drop here. */
6231 gdk_drag_status (context, 0, time);
6235 if (tree_view->priv->open_dest_timeout == 0 &&
6236 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6237 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6243 add_scroll_timeout (tree_view);
6246 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6248 /* Request data so we can use the source row when
6249 * determining whether to accept the drop
6251 set_status_pending (context, suggested_action);
6252 gtk_drag_get_data (widget, context, target, time);
6256 set_status_pending (context, 0);
6257 gdk_drag_status (context, suggested_action, time);
6262 gtk_tree_path_free (path);
6269 pspp_sheet_view_drag_drop (GtkWidget *widget,
6270 GdkDragContext *context,
6271 /* coordinates relative to the widget */
6276 PsppSheetView *tree_view;
6278 GdkDragAction suggested_action = 0;
6279 GdkAtom target = GDK_NONE;
6280 TreeViewDragInfo *di;
6281 GtkTreeModel *model;
6282 gboolean path_down_mode;
6283 gboolean drop_append_mode;
6285 tree_view = PSPP_SHEET_VIEW (widget);
6287 model = pspp_sheet_view_get_model (tree_view);
6289 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6291 di = get_info (tree_view);
6296 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6299 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6302 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6304 if (target != GDK_NONE && path != NULL)
6306 /* in case a motion had requested drag data, change things so we
6307 * treat drag data receives as a drop.
6309 set_status_pending (context, 0);
6310 set_dest_row (context, model, path,
6311 path_down_mode, tree_view->priv->empty_view_drop,
6316 gtk_tree_path_free (path);
6318 /* Unset this thing */
6319 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6321 PSPP_SHEET_VIEW_DROP_BEFORE);
6323 if (target != GDK_NONE)
6325 gtk_drag_get_data (widget, context, target, time);
6333 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6334 GdkDragContext *context,
6335 /* coordinates relative to the widget */
6338 GtkSelectionData *selection_data,
6343 TreeViewDragInfo *di;
6344 gboolean accepted = FALSE;
6345 GtkTreeModel *model;
6346 PsppSheetView *tree_view;
6347 GtkTreePath *dest_row;
6348 GdkDragAction suggested_action;
6349 gboolean path_down_mode;
6350 gboolean drop_append_mode;
6352 tree_view = PSPP_SHEET_VIEW (widget);
6354 model = pspp_sheet_view_get_model (tree_view);
6356 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6359 di = get_info (tree_view);
6364 suggested_action = get_status_pending (context);
6366 if (suggested_action)
6368 /* We are getting this data due to a request in drag_motion,
6369 * rather than due to a request in drag_drop, so we are just
6370 * supposed to call drag_status, not actually paste in the
6373 path = get_logical_dest_row (tree_view, &path_down_mode,
6377 suggested_action = 0;
6378 else if (path_down_mode)
6379 gtk_tree_path_down (path);
6381 if (suggested_action)
6383 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6389 path_down_mode = FALSE;
6390 gtk_tree_path_up (path);
6392 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6395 suggested_action = 0;
6398 suggested_action = 0;
6402 gdk_drag_status (context, suggested_action, time);
6405 gtk_tree_path_free (path);
6407 /* If you can't drop, remove user drop indicator until the next motion */
6408 if (suggested_action == 0)
6409 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6411 PSPP_SHEET_VIEW_DROP_BEFORE);
6416 dest_row = get_dest_row (context, &path_down_mode);
6418 if (dest_row == NULL)
6421 if (selection_data->length >= 0)
6425 gtk_tree_path_down (dest_row);
6426 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6427 dest_row, selection_data))
6428 gtk_tree_path_up (dest_row);
6432 if (selection_data->length >= 0)
6434 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6440 gtk_drag_finish (context,
6442 (context->action == GDK_ACTION_MOVE),
6445 if (gtk_tree_path_get_depth (dest_row) == 1
6446 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6448 /* special special case drag to "0", scroll to first item */
6449 if (!tree_view->priv->scroll_to_path)
6450 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6453 gtk_tree_path_free (dest_row);
6456 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6461 /* GtkContainer Methods
6466 pspp_sheet_view_remove (GtkContainer *container,
6469 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6470 PsppSheetViewChild *child = NULL;
6473 tmp_list = tree_view->priv->children;
6476 child = tmp_list->data;
6477 if (child->widget == widget)
6479 gtk_widget_unparent (widget);
6481 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6482 g_list_free_1 (tmp_list);
6483 g_slice_free (PsppSheetViewChild, child);
6487 tmp_list = tmp_list->next;
6490 tmp_list = tree_view->priv->columns;
6494 PsppSheetViewColumn *column;
6495 column = tmp_list->data;
6496 if (column->button == widget)
6498 gtk_widget_unparent (widget);
6501 tmp_list = tmp_list->next;
6506 pspp_sheet_view_forall (GtkContainer *container,
6507 gboolean include_internals,
6508 GtkCallback callback,
6509 gpointer callback_data)
6511 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6512 PsppSheetViewChild *child = NULL;
6513 PsppSheetViewColumn *column;
6516 tmp_list = tree_view->priv->children;
6519 child = tmp_list->data;
6520 tmp_list = tmp_list->next;
6522 (* callback) (child->widget, callback_data);
6524 if (include_internals == FALSE)
6527 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6529 column = tmp_list->data;
6532 (* callback) (column->button, callback_data);
6536 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6537 * cells. If so we draw one big row-spanning focus rectangle.
6540 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6544 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6545 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6547 for (list = tree_view->priv->columns; list; list = list->next)
6549 if (!((PsppSheetViewColumn *)list->data)->visible)
6551 if (_pspp_sheet_view_column_count_special_cells (list->data))
6559 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6560 PsppSheetViewColumn *focus_column,
6561 gboolean clamp_column_visible)
6563 g_return_if_fail (focus_column != NULL);
6565 tree_view->priv->focus_column = focus_column;
6566 if (!focus_column->button)
6568 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6569 g_return_if_fail (focus_column->button != NULL);
6572 if (GTK_CONTAINER (tree_view)->focus_child != focus_column->button)
6573 gtk_widget_grab_focus (focus_column->button);
6575 if (clamp_column_visible)
6576 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6579 /* Returns TRUE if the focus is within the headers, after the focus operation is
6583 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6584 GtkDirectionType dir,
6585 gboolean clamp_column_visible)
6587 GtkWidget *focus_child;
6588 PsppSheetViewColumn *focus_column;
6589 GList *last_column, *first_column;
6593 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6596 focus_child = GTK_CONTAINER (tree_view)->focus_child;
6598 first_column = tree_view->priv->columns;
6599 while (first_column)
6601 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6603 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6605 first_column = first_column->next;
6608 /* No headers are visible, or are focusable. We can't focus in or out.
6610 if (first_column == NULL)
6613 last_column = g_list_last (tree_view->priv->columns);
6616 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6618 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6620 last_column = last_column->prev;
6624 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6628 case GTK_DIR_TAB_BACKWARD:
6629 case GTK_DIR_TAB_FORWARD:
6632 if (focus_child == NULL)
6634 if (tree_view->priv->focus_column != NULL &&
6635 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6636 focus_column = tree_view->priv->focus_column;
6638 focus_column = first_column->data;
6639 pspp_sheet_view_focus_column (tree_view, focus_column,
6640 clamp_column_visible);
6647 if (focus_child == NULL)
6649 if (tree_view->priv->focus_column != NULL)
6650 focus_column = tree_view->priv->focus_column;
6651 else if (dir == GTK_DIR_LEFT)
6652 focus_column = last_column->data;
6654 focus_column = first_column->data;
6655 pspp_sheet_view_focus_column (tree_view, focus_column,
6656 clamp_column_visible);
6660 if (gtk_widget_child_focus (focus_child, dir))
6662 /* The focus moves inside the button. */
6663 /* This is probably a great example of bad UI */
6664 if (clamp_column_visible)
6665 pspp_sheet_view_clamp_column_visible (tree_view,
6666 tree_view->priv->focus_column,
6671 /* We need to move the focus among the row of buttons. */
6672 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6673 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6676 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6677 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6679 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6685 PsppSheetViewColumn *column;
6687 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6688 tmp_list = tmp_list->next;
6690 tmp_list = tmp_list->prev;
6692 if (tmp_list == NULL)
6694 g_warning ("Internal button not found");
6697 column = tmp_list->data;
6698 if (column->button &&
6700 pspp_sheet_view_column_can_focus (column))
6702 pspp_sheet_view_focus_column (tree_view, column,
6703 clamp_column_visible);
6710 g_assert_not_reached ();
6717 /* This function returns in 'path' the first focusable path, if the given path
6718 * is already focusable, it's the returned one.
6722 search_first_focusable_path (PsppSheetView *tree_view,
6724 gboolean search_forward,
6727 /* XXX this function is trivial given that the sheetview doesn't support
6731 if (!path || !*path)
6734 _pspp_sheet_view_find_node (tree_view, *path, &node);
6742 return (*path != NULL);
6746 pspp_sheet_view_focus (GtkWidget *widget,
6747 GtkDirectionType direction)
6749 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6750 GtkContainer *container = GTK_CONTAINER (widget);
6751 GtkWidget *focus_child;
6753 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6756 focus_child = container->focus_child;
6758 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6759 /* Case 1. Headers currently have focus. */
6766 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6768 case GTK_DIR_TAB_BACKWARD:
6771 case GTK_DIR_TAB_FORWARD:
6773 gtk_widget_grab_focus (widget);
6776 g_assert_not_reached ();
6781 /* Case 2. We don't have focus at all. */
6782 if (!gtk_widget_has_focus (widget))
6784 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6785 gtk_widget_grab_focus (widget);
6789 /* Case 3. We have focus already. */
6790 if (direction == GTK_DIR_TAB_BACKWARD)
6791 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6792 else if (direction == GTK_DIR_TAB_FORWARD)
6795 /* Other directions caught by the keybindings */
6796 gtk_widget_grab_focus (widget);
6801 pspp_sheet_view_grab_focus (GtkWidget *widget)
6803 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6805 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6809 pspp_sheet_view_style_set (GtkWidget *widget,
6810 GtkStyle *previous_style)
6812 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6814 PsppSheetViewColumn *column;
6816 if (gtk_widget_get_realized (widget))
6818 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
6819 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
6820 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
6822 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6825 gtk_widget_style_get (widget,
6826 "expander-size", &tree_view->priv->expander_size,
6828 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6830 for (list = tree_view->priv->columns; list; list = list->next)
6832 column = list->data;
6833 _pspp_sheet_view_column_cell_set_dirty (column);
6836 tree_view->priv->fixed_height = -1;
6838 /* Invalidate cached button style. */
6839 if (tree_view->priv->button_style)
6841 g_object_unref (tree_view->priv->button_style);
6842 tree_view->priv->button_style = NULL;
6845 gtk_widget_queue_resize (widget);
6850 pspp_sheet_view_set_focus_child (GtkContainer *container,
6853 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6856 for (list = tree_view->priv->columns; list; list = list->next)
6858 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6860 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6865 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6869 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6870 GtkAdjustment *hadj,
6871 GtkAdjustment *vadj)
6873 gboolean need_adjust = FALSE;
6875 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6878 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6880 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6882 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
6884 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6886 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
6888 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
6889 pspp_sheet_view_adjustment_changed,
6891 g_object_unref (tree_view->priv->hadjustment);
6894 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
6896 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
6897 pspp_sheet_view_adjustment_changed,
6899 g_object_unref (tree_view->priv->vadjustment);
6902 if (tree_view->priv->hadjustment != hadj)
6904 tree_view->priv->hadjustment = hadj;
6905 g_object_ref_sink (tree_view->priv->hadjustment);
6907 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
6908 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6913 if (tree_view->priv->vadjustment != vadj)
6915 tree_view->priv->vadjustment = vadj;
6916 g_object_ref_sink (tree_view->priv->vadjustment);
6918 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
6919 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6925 pspp_sheet_view_adjustment_changed (NULL, tree_view);
6930 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
6931 GtkMovementStep step,
6934 GdkModifierType state;
6936 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
6937 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
6938 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
6939 step == GTK_MOVEMENT_DISPLAY_LINES ||
6940 step == GTK_MOVEMENT_PAGES ||
6941 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
6943 if (tree_view->priv->row_count == 0)
6945 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
6948 pspp_sheet_view_stop_editing (tree_view, FALSE);
6949 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
6950 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
6952 if (gtk_get_current_event_state (&state))
6954 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
6955 tree_view->priv->ctrl_pressed = TRUE;
6956 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
6957 tree_view->priv->shift_pressed = TRUE;
6959 /* else we assume not pressed */
6963 /* currently we make no distinction. When we go bi-di, we need to */
6964 case GTK_MOVEMENT_LOGICAL_POSITIONS:
6965 case GTK_MOVEMENT_VISUAL_POSITIONS:
6966 pspp_sheet_view_move_cursor_left_right (tree_view, count);
6968 case GTK_MOVEMENT_DISPLAY_LINES:
6969 pspp_sheet_view_move_cursor_up_down (tree_view, count);
6971 case GTK_MOVEMENT_PAGES:
6972 pspp_sheet_view_move_cursor_page_up_down (tree_view, count);
6974 case GTK_MOVEMENT_BUFFER_ENDS:
6975 pspp_sheet_view_move_cursor_start_end (tree_view, count);
6978 g_assert_not_reached ();
6981 tree_view->priv->ctrl_pressed = FALSE;
6982 tree_view->priv->shift_pressed = FALSE;
6988 pspp_sheet_view_put (PsppSheetView *tree_view,
6989 GtkWidget *child_widget,
6990 /* in bin_window coordinates */
6996 PsppSheetViewChild *child;
6998 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6999 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7001 child = g_slice_new (PsppSheetViewChild);
7003 child->widget = child_widget;
7006 child->width = width;
7007 child->height = height;
7009 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7011 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7012 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7014 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7018 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7020 /* in tree coordinates */
7026 PsppSheetViewChild *child = NULL;
7028 GdkRectangle allocation;
7030 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7031 g_return_if_fail (GTK_IS_WIDGET (widget));
7033 for (list = tree_view->priv->children; list; list = list->next)
7035 if (((PsppSheetViewChild *)list->data)->widget == widget)
7044 allocation.x = child->x = x;
7045 allocation.y = child->y = y;
7046 allocation.width = child->width = width;
7047 allocation.height = child->height = height;
7049 if (gtk_widget_get_realized (widget))
7050 gtk_widget_size_allocate (widget, &allocation);
7054 /* TreeModel Callbacks
7058 pspp_sheet_view_row_changed (GtkTreeModel *model,
7063 PsppSheetView *tree_view = (PsppSheetView *)data;
7065 gboolean free_path = FALSE;
7066 GtkTreePath *cursor_path;
7068 g_return_if_fail (path != NULL || iter != NULL);
7070 if (tree_view->priv->cursor != NULL)
7071 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7075 if (tree_view->priv->edited_column &&
7076 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7077 pspp_sheet_view_stop_editing (tree_view, TRUE);
7079 if (cursor_path != NULL)
7080 gtk_tree_path_free (cursor_path);
7084 path = gtk_tree_model_get_path (model, iter);
7087 else if (iter == NULL)
7088 gtk_tree_model_get_iter (model, iter, path);
7090 _pspp_sheet_view_find_node (tree_view,
7096 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7097 pspp_sheet_view_node_queue_redraw (tree_view, node);
7101 gtk_tree_path_free (path);
7105 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7110 PsppSheetView *tree_view = (PsppSheetView *) data;
7113 gint height = tree_view->priv->fixed_height;
7114 gboolean free_path = FALSE;
7115 gboolean node_visible = TRUE;
7117 g_return_if_fail (path != NULL || iter != NULL);
7121 path = gtk_tree_model_get_path (model, iter);
7124 else if (iter == NULL)
7125 gtk_tree_model_get_iter (model, iter, path);
7127 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7129 /* Update all row-references */
7130 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7131 indices = gtk_tree_path_get_indices (path);
7132 tmpnode = indices[0];
7134 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7138 if (node_visible && node_is_visible (tree_view, tmpnode))
7139 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7141 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7144 install_presize_handler (tree_view);
7146 gtk_tree_path_free (path);
7150 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7154 PsppSheetView *tree_view = (PsppSheetView *)data;
7157 g_return_if_fail (path != NULL);
7159 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7161 _pspp_sheet_view_find_node (tree_view, path, &node);
7166 range_tower_delete (tree_view->priv->selected, node, 1);
7168 /* Ensure we don't have a dangling pointer to a dead node */
7169 ensure_unprelighted (tree_view);
7171 /* Cancel editting if we've started */
7172 pspp_sheet_view_stop_editing (tree_view, TRUE);
7174 if (tree_view->priv->destroy_count_func)
7176 gint child_count = 0;
7177 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7180 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7182 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7184 gtk_tree_row_reference_free (tree_view->priv->top_row);
7185 tree_view->priv->top_row = NULL;
7188 install_scroll_sync_handler (tree_view);
7190 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7193 if (helper_data.changed)
7194 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7199 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7200 GtkTreePath *parent,
7205 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7208 /* XXX need to adjust selection */
7209 len = gtk_tree_model_iter_n_children (model, iter);
7214 gtk_tree_row_reference_reordered (G_OBJECT (data),
7219 if (gtk_tree_path_get_depth (parent) != 0)
7222 if (tree_view->priv->edited_column)
7223 pspp_sheet_view_stop_editing (tree_view, TRUE);
7225 /* we need to be unprelighted */
7226 ensure_unprelighted (tree_view);
7228 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7230 pspp_sheet_view_dy_to_top_row (tree_view);
7234 /* Internal tree functions
7239 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7240 PsppSheetViewColumn *column,
7244 PsppSheetViewColumn *tmp_column = NULL;
7255 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7258 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7260 list = (rtl ? list->prev : list->next))
7262 tmp_column = list->data;
7264 if (tmp_column == column)
7267 if (tmp_column->visible)
7268 total_width += tmp_column->width;
7271 if (tmp_column != column)
7273 g_warning (G_STRLOC": passed-in column isn't in the tree");
7282 if (column->visible)
7283 *x2 = total_width + column->width;
7285 *x2 = total_width; /* width of 0 */
7289 /* Make sure the node is visible vertically */
7291 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7294 gint node_dy, height;
7295 GtkTreePath *path = NULL;
7297 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7300 /* just return if the node is visible, avoiding a costly expose */
7301 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7302 height = ROW_HEIGHT (tree_view);
7303 if (node_dy >= tree_view->priv->vadjustment->value
7304 && node_dy + height <= (tree_view->priv->vadjustment->value
7305 + tree_view->priv->vadjustment->page_size))
7308 path = _pspp_sheet_view_find_path (tree_view, node);
7311 /* We process updates because we want to clear old selected items when we scroll.
7312 * if this is removed, we get a "selection streak" at the bottom. */
7313 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7314 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7315 gtk_tree_path_free (path);
7320 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7321 PsppSheetViewColumn *column,
7322 gboolean focus_to_cell)
7329 x = column->allocation.x;
7330 width = column->allocation.width;
7332 if (width > tree_view->priv->hadjustment->page_size)
7334 /* The column is larger than the horizontal page size. If the
7335 * column has cells which can be focussed individually, then we make
7336 * sure the cell which gets focus is fully visible (if even the
7337 * focus cell is bigger than the page size, we make sure the
7338 * left-hand side of the cell is visible).
7340 * If the column does not have those so-called special cells, we
7341 * make sure the left-hand side of the column is visible.
7344 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7346 GtkTreePath *cursor_path;
7347 GdkRectangle background_area, cell_area, focus_area;
7349 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7351 pspp_sheet_view_get_cell_area (tree_view,
7352 cursor_path, column, &cell_area);
7353 pspp_sheet_view_get_background_area (tree_view,
7354 cursor_path, column,
7357 gtk_tree_path_free (cursor_path);
7359 _pspp_sheet_view_column_get_focus_area (column,
7365 width = focus_area.width;
7367 if (width < tree_view->priv->hadjustment->page_size)
7369 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7370 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7371 x + width - tree_view->priv->hadjustment->page_size);
7372 else if (tree_view->priv->hadjustment->value > x)
7373 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7377 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7379 tree_view->priv->hadjustment->lower,
7380 tree_view->priv->hadjustment->upper
7381 - tree_view->priv->hadjustment->page_size));
7385 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7386 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7387 x + width - tree_view->priv->hadjustment->page_size);
7388 else if (tree_view->priv->hadjustment->value > x)
7389 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7394 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7399 path = gtk_tree_path_new ();
7401 gtk_tree_path_append_index (path, node);
7406 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7410 gint *indices = gtk_tree_path_get_indices (path);
7411 gint depth = gtk_tree_path_get_depth (path);
7414 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7420 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7423 gboolean add_shifted_binding,
7424 GtkMovementStep step,
7428 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7433 if (add_shifted_binding)
7434 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7439 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7442 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7447 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7454 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7455 PsppSheetViewColumn *column)
7457 PsppSheetViewColumn *left_column;
7458 PsppSheetViewColumn *cur_column = NULL;
7459 PsppSheetViewColumnReorder *reorder;
7464 /* We want to precalculate the motion list such that we know what column slots
7468 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7470 /* First, identify all possible drop spots */
7472 tmp_list = g_list_last (tree_view->priv->columns);
7474 tmp_list = g_list_first (tree_view->priv->columns);
7478 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7479 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7481 if (cur_column->visible == FALSE)
7484 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7485 if (left_column != column && cur_column != column &&
7486 tree_view->priv->column_drop_func &&
7487 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7489 left_column = cur_column;
7492 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7493 reorder->left_column = left_column;
7494 left_column = reorder->right_column = cur_column;
7496 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7499 /* Add the last one */
7500 if (tree_view->priv->column_drop_func == NULL ||
7501 ((left_column != column) &&
7502 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7504 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7505 reorder->left_column = left_column;
7506 reorder->right_column = NULL;
7507 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7510 /* We quickly check to see if it even makes sense to reorder columns. */
7511 /* If there is nothing that can be moved, then we return */
7513 if (tree_view->priv->column_drag_info == NULL)
7516 /* We know there are always 2 slots possbile, as you can always return column. */
7517 /* If that's all there is, return */
7518 if (tree_view->priv->column_drag_info->next == NULL ||
7519 (tree_view->priv->column_drag_info->next->next == NULL &&
7520 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7521 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7523 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7524 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7525 g_list_free (tree_view->priv->column_drag_info);
7526 tree_view->priv->column_drag_info = NULL;
7529 /* We fill in the ranges for the columns, now that we've isolated them */
7530 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7532 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7534 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7536 reorder->left_align = left;
7537 if (tmp_list->next != NULL)
7539 g_assert (tmp_list->next->data);
7540 left = reorder->right_align = (reorder->right_column->allocation.x +
7541 reorder->right_column->allocation.width +
7542 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7548 gdk_drawable_get_size (tree_view->priv->header_window, &width, NULL);
7549 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7555 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7556 PsppSheetViewColumn *column)
7558 GdkEvent *send_event;
7559 GtkAllocation allocation;
7560 gint x, y, width, height;
7561 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7562 GdkDisplay *display = gdk_screen_get_display (screen);
7564 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7565 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7566 g_return_if_fail (column->button);
7568 pspp_sheet_view_set_column_drag_info (tree_view, column);
7570 if (tree_view->priv->column_drag_info == NULL)
7573 if (tree_view->priv->drag_window == NULL)
7575 GdkWindowAttr attributes;
7576 guint attributes_mask;
7578 attributes.window_type = GDK_WINDOW_CHILD;
7579 attributes.wclass = GDK_INPUT_OUTPUT;
7580 attributes.x = column->allocation.x;
7582 attributes.width = column->allocation.width;
7583 attributes.height = column->allocation.height;
7584 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7585 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
7586 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7587 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
7589 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7592 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7595 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7596 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7598 gtk_grab_remove (column->button);
7600 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7601 send_event->crossing.send_event = TRUE;
7602 send_event->crossing.window = g_object_ref (GTK_BUTTON (column->button)->event_window);
7603 send_event->crossing.subwindow = NULL;
7604 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7605 send_event->crossing.time = GDK_CURRENT_TIME;
7607 gtk_propagate_event (column->button, send_event);
7608 gdk_event_free (send_event);
7610 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7611 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7612 send_event->button.send_event = TRUE;
7613 send_event->button.time = GDK_CURRENT_TIME;
7614 send_event->button.x = -1;
7615 send_event->button.y = -1;
7616 send_event->button.axes = NULL;
7617 send_event->button.state = 0;
7618 send_event->button.button = 1;
7619 send_event->button.device = gdk_display_get_core_pointer (display);
7620 send_event->button.x_root = 0;
7621 send_event->button.y_root = 0;
7623 gtk_propagate_event (column->button, send_event);
7624 gdk_event_free (send_event);
7626 /* Kids, don't try this at home */
7627 g_object_ref (column->button);
7628 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7629 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7630 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7631 g_object_unref (column->button);
7633 tree_view->priv->drag_column_x = column->allocation.x;
7634 allocation = column->allocation;
7636 gtk_widget_size_allocate (column->button, &allocation);
7637 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7639 tree_view->priv->drag_column = column;
7640 gdk_window_show (tree_view->priv->drag_window);
7642 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7643 gdk_drawable_get_size (tree_view->priv->header_window, &width, &height);
7645 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7646 while (gtk_events_pending ())
7647 gtk_main_iteration ();
7649 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7650 gdk_pointer_grab (tree_view->priv->drag_window,
7652 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7653 NULL, NULL, GDK_CURRENT_TIME);
7654 gdk_keyboard_grab (tree_view->priv->drag_window,
7660 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7662 const GdkRectangle *clip_rect)
7666 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7670 rect.width = MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width);
7672 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7673 rect.height = ROW_HEIGHT (tree_view);
7677 GdkRectangle new_rect;
7679 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7681 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7685 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7690 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7692 const GdkRectangle *clip_rect)
7696 _pspp_sheet_view_find_node (tree_view, path, &node);
7699 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7703 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7706 GtkTreePath *cursor_path;
7708 if ((tree_view->priv->row_count == 0) ||
7709 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7713 if (tree_view->priv->cursor)
7714 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7716 if (cursor_path == NULL)
7718 /* There's no cursor. Move the cursor to the first selected row, if any
7719 * are selected, otherwise to the first row in the sheetview.
7721 GList *selected_rows;
7722 GtkTreeModel *model;
7723 PsppSheetSelection *selection;
7725 selection = pspp_sheet_view_get_selection (tree_view);
7726 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7730 /* XXX we could avoid doing O(n) work to get this result */
7731 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7732 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7733 g_list_free (selected_rows);
7737 cursor_path = gtk_tree_path_new_first ();
7738 search_first_focusable_path (tree_view, &cursor_path,
7742 gtk_tree_row_reference_free (tree_view->priv->cursor);
7743 tree_view->priv->cursor = NULL;
7747 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7748 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7749 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE);
7751 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
7757 /* Now find a column for the cursor. */
7758 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7760 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7761 gtk_tree_path_free (cursor_path);
7763 if (tree_view->priv->focus_column == NULL)
7766 for (list = tree_view->priv->columns; list; list = list->next)
7768 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7770 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7771 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7772 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7782 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7785 gint selection_count;
7786 int cursor_node = -1;
7787 int new_cursor_node = -1;
7788 GtkTreePath *cursor_path = NULL;
7789 gboolean grab_focus = TRUE;
7791 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7795 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7796 /* FIXME: we lost the cursor; should we get the first? */
7799 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7800 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7802 if (cursor_node < 0)
7803 /* FIXME: we lost the cursor; should we get the first? */
7806 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7808 if (selection_count == 0
7809 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7810 && !tree_view->priv->ctrl_pressed)
7812 /* Don't move the cursor, but just select the current node */
7813 new_cursor_node = cursor_node;
7818 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7820 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7823 gtk_tree_path_free (cursor_path);
7825 if (new_cursor_node)
7827 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7829 search_first_focusable_path (tree_view, &cursor_path,
7834 gtk_tree_path_free (cursor_path);
7838 * If the list has only one item and multi-selection is set then select
7839 * the row (if not yet selected).
7841 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7842 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7843 new_cursor_node < 0)
7846 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7848 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7850 if (new_cursor_node < 0
7851 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7853 new_cursor_node = cursor_node;
7857 new_cursor_node = -1;
7861 if (new_cursor_node >= 0)
7863 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7864 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE);
7865 gtk_tree_path_free (cursor_path);
7869 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7871 if (!tree_view->priv->shift_pressed)
7873 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7875 GTK_DIR_UP : GTK_DIR_DOWN))
7877 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
7880 gtk_widget_child_focus (toplevel,
7882 GTK_DIR_TAB_BACKWARD :
7883 GTK_DIR_TAB_FORWARD);
7890 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7895 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7899 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
7902 int cursor_node = -1;
7903 GtkTreePath *old_cursor_path = NULL;
7904 GtkTreePath *cursor_path = NULL;
7905 int start_cursor_node = -1;
7908 gint vertical_separator;
7910 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7913 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
7914 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7916 /* This is sorta weird. Focus in should give us a cursor */
7919 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
7920 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
7922 if (cursor_node < 0)
7924 /* FIXME: we lost the cursor. Should we try to get one? */
7925 gtk_tree_path_free (old_cursor_path);
7929 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7930 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
7931 y += tree_view->priv->cursor_offset;
7932 y += count * (int)tree_view->priv->vadjustment->page_increment;
7933 y = CLAMP (y, (gint)tree_view->priv->vadjustment->lower, (gint)tree_view->priv->vadjustment->upper - vertical_separator);
7935 if (y >= tree_view->priv->height)
7936 y = tree_view->priv->height - 1;
7938 tree_view->priv->cursor_offset =
7939 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
7941 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
7943 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7944 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
7947 y -= tree_view->priv->cursor_offset;
7948 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7950 start_cursor_node = cursor_node;
7952 if (! search_first_focusable_path (tree_view, &cursor_path,
7956 /* It looks like we reached the end of the view without finding
7957 * a focusable row. We will step backwards to find the last
7960 cursor_node = start_cursor_node;
7961 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7963 search_first_focusable_path (tree_view, &cursor_path,
7972 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7974 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
7977 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
7978 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7979 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
7981 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
7982 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7984 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7987 gtk_tree_path_free (old_cursor_path);
7988 gtk_tree_path_free (cursor_path);
7992 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
7995 int cursor_node = -1;
7996 GtkTreePath *cursor_path = NULL;
7997 PsppSheetViewColumn *column;
8000 gboolean found_column = FALSE;
8003 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8005 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8008 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8009 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8013 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8014 if (cursor_node < 0)
8016 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8018 gtk_tree_path_free (cursor_path);
8021 gtk_tree_path_free (cursor_path);
8023 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8024 if (tree_view->priv->focus_column)
8026 for (; list; list = (rtl ? list->prev : list->next))
8028 if (list->data == tree_view->priv->focus_column)
8035 gboolean left, right;
8037 column = list->data;
8038 if (column->visible == FALSE || column->row_head)
8041 pspp_sheet_view_column_cell_set_cell_data (column,
8042 tree_view->priv->model,
8047 right = list->prev ? TRUE : FALSE;
8048 left = list->next ? TRUE : FALSE;
8052 left = list->prev ? TRUE : FALSE;
8053 right = list->next ? TRUE : FALSE;
8056 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8058 tree_view->priv->focus_column = column;
8059 found_column = TRUE;
8064 list = rtl ? list->prev : list->next;
8066 list = rtl ? list->next : list->prev;
8071 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8072 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8073 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8077 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8080 pspp_sheet_view_clamp_column_visible (tree_view,
8081 tree_view->priv->focus_column, TRUE);
8085 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8090 GtkTreePath *old_path;
8092 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8095 g_return_if_fail (tree_view->priv->row_count > 0);
8097 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8101 /* Now go forward to find the first focusable row. */
8102 path = _pspp_sheet_view_find_path (tree_view, 0);
8103 search_first_focusable_path (tree_view, &path,
8104 TRUE, &cursor_node);
8108 /* Now go backwards to find last focusable row. */
8109 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8110 search_first_focusable_path (tree_view, &path,
8111 FALSE, &cursor_node);
8117 if (gtk_tree_path_compare (old_path, path))
8119 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
8120 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8124 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8128 gtk_tree_path_free (old_path);
8129 gtk_tree_path_free (path);
8133 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8135 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8138 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8139 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8142 pspp_sheet_selection_select_all (tree_view->priv->selection);
8148 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8150 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8153 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8154 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8157 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8163 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8164 gboolean start_editing)
8167 int cursor_node = -1;
8168 GtkTreePath *cursor_path = NULL;
8169 GtkTreeSelectMode mode = 0;
8171 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8174 if (tree_view->priv->cursor)
8175 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8177 if (cursor_path == NULL)
8180 _pspp_sheet_view_find_node (tree_view, cursor_path,
8183 if (cursor_node < 0)
8185 gtk_tree_path_free (cursor_path);
8189 if (!tree_view->priv->shift_pressed && start_editing &&
8190 tree_view->priv->focus_column)
8192 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8194 gtk_tree_path_free (cursor_path);
8199 if (tree_view->priv->ctrl_pressed)
8200 mode |= GTK_TREE_SELECT_MODE_TOGGLE;
8201 if (tree_view->priv->shift_pressed)
8202 mode |= GTK_TREE_SELECT_MODE_EXTEND;
8204 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8210 /* We bail out if the original (tree, node) don't exist anymore after
8211 * handling the selection-changed callback. We do return TRUE because
8212 * the key press has been handled at this point.
8214 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8216 if (cursor_node != new_node)
8219 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8221 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8222 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8224 if (!tree_view->priv->shift_pressed)
8225 pspp_sheet_view_row_activated (tree_view, cursor_path,
8226 tree_view->priv->focus_column);
8228 gtk_tree_path_free (cursor_path);
8234 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8237 int cursor_node = -1;
8238 GtkTreePath *cursor_path = NULL;
8240 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8244 if (tree_view->priv->cursor)
8245 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8247 if (cursor_path == NULL)
8250 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8251 if (cursor_node < 0)
8253 gtk_tree_path_free (cursor_path);
8257 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8260 GTK_TREE_SELECT_MODE_TOGGLE,
8263 /* We bail out if the original (tree, node) don't exist anymore after
8264 * handling the selection-changed callback. We do return TRUE because
8265 * the key press has been handled at this point.
8267 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8269 if (cursor_node != new_node)
8272 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8274 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8275 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8276 gtk_tree_path_free (cursor_path);
8282 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8284 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8285 tree_view->priv->typeselect_flush_timeout = 0;
8290 /* Cut and paste from gtkwindow.c */
8292 send_focus_change (GtkWidget *widget,
8295 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8297 g_object_ref (widget);
8300 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
8302 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
8304 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8305 fevent->focus_change.window = g_object_ref (widget->window);
8306 fevent->focus_change.in = in;
8308 gtk_widget_event (widget, fevent);
8310 g_object_notify (G_OBJECT (widget), "has-focus");
8312 g_object_unref (widget);
8313 gdk_event_free (fevent);
8317 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8319 GtkWidget *frame, *vbox, *toplevel;
8322 if (tree_view->priv->search_custom_entry_set)
8325 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8326 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8328 if (tree_view->priv->search_window != NULL)
8330 if (GTK_WINDOW (toplevel)->group)
8331 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8332 GTK_WINDOW (tree_view->priv->search_window));
8333 else if (GTK_WINDOW (tree_view->priv->search_window)->group)
8334 gtk_window_group_remove_window (GTK_WINDOW (tree_view->priv->search_window)->group,
8335 GTK_WINDOW (tree_view->priv->search_window));
8336 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8340 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8341 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8343 if (GTK_WINDOW (toplevel)->group)
8344 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8345 GTK_WINDOW (tree_view->priv->search_window));
8347 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8348 GDK_WINDOW_TYPE_HINT_UTILITY);
8349 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8350 g_signal_connect (tree_view->priv->search_window, "delete-event",
8351 G_CALLBACK (pspp_sheet_view_search_delete_event),
8353 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8354 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8356 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8357 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8359 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8360 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8363 frame = gtk_frame_new (NULL);
8364 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8365 gtk_widget_show (frame);
8366 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8368 vbox = gtk_vbox_new (FALSE, 0);
8369 gtk_widget_show (vbox);
8370 gtk_container_add (GTK_CONTAINER (frame), vbox);
8371 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8374 tree_view->priv->search_entry = gtk_entry_new ();
8375 gtk_widget_show (tree_view->priv->search_entry);
8376 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8377 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8379 g_signal_connect (tree_view->priv->search_entry,
8380 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8382 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8384 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8386 gtk_container_add (GTK_CONTAINER (vbox),
8387 tree_view->priv->search_entry);
8389 gtk_widget_realize (tree_view->priv->search_entry);
8392 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8393 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8396 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8397 gboolean keybinding)
8399 /* We only start interactive search if we have focus or the columns
8400 * have focus. If one of our children have focus, we don't want to
8404 gboolean found_focus = FALSE;
8405 GtkWidgetClass *entry_parent_class;
8407 if (!tree_view->priv->enable_search && !keybinding)
8410 if (tree_view->priv->search_custom_entry_set)
8413 if (tree_view->priv->search_window != NULL &&
8414 gtk_widget_get_visible (tree_view->priv->search_window))
8417 for (list = tree_view->priv->columns; list; list = list->next)
8419 PsppSheetViewColumn *column;
8421 column = list->data;
8422 if (! column->visible)
8425 if (column->button && gtk_widget_has_focus (column->button))
8432 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8438 if (tree_view->priv->search_column < 0)
8441 pspp_sheet_view_ensure_interactive_directory (tree_view);
8444 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8447 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8448 gtk_widget_show (tree_view->priv->search_window);
8449 if (tree_view->priv->search_entry_changed_id == 0)
8451 tree_view->priv->search_entry_changed_id =
8452 g_signal_connect (tree_view->priv->search_entry, "changed",
8453 G_CALLBACK (pspp_sheet_view_search_init),
8457 tree_view->priv->typeselect_flush_timeout =
8458 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8459 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8462 /* Grab focus will select all the text. We don't want that to happen, so we
8463 * call the parent instance and bypass the selection change. This is probably
8464 * really non-kosher. */
8465 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8466 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8468 /* send focus-in event */
8469 send_focus_change (tree_view->priv->search_entry, TRUE);
8471 /* search first matching iter */
8472 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8478 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8480 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8483 /* this function returns the new width of the column being resized given
8484 * the column and x position of the cursor; the x cursor position is passed
8485 * in as a pointer and automagicly corrected if it's beyond min/max limits
8488 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8492 PsppSheetViewColumn *column;
8496 /* first translate the x position from widget->window
8497 * to clist->clist_window
8499 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8500 column = g_list_nth (tree_view->priv->columns, i)->data;
8501 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8503 /* Clamp down the value */
8504 if (column->min_width == -1)
8505 width = MAX (column->button_request, width);
8507 width = MAX (column->min_width, width);
8508 if (column->max_width != -1)
8509 width = MIN (width, column->max_width);
8511 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8517 /* FIXME this adjust_allocation is a big cut-and-paste from
8518 * GtkCList, needs to be some "official" way to do this
8528 /* The window to which widget->window is relative */
8529 #define ALLOCATION_WINDOW(widget) \
8530 (!gtk_widget_get_has_window (widget) ? \
8531 (widget)->window : \
8532 gdk_window_get_parent ((widget)->window))
8535 adjust_allocation_recurse (GtkWidget *widget,
8538 ScrollData *scroll_data = data;
8540 /* Need to really size allocate instead of just poking
8541 * into widget->allocation if the widget is not realized.
8542 * FIXME someone figure out why this was.
8544 if (!gtk_widget_get_realized (widget))
8546 if (gtk_widget_get_visible (widget))
8548 GdkRectangle tmp_rectangle = widget->allocation;
8549 tmp_rectangle.x += scroll_data->dx;
8550 tmp_rectangle.y += scroll_data->dy;
8552 gtk_widget_size_allocate (widget, &tmp_rectangle);
8557 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8559 widget->allocation.x += scroll_data->dx;
8560 widget->allocation.y += scroll_data->dy;
8562 if (GTK_IS_CONTAINER (widget))
8563 gtk_container_forall (GTK_CONTAINER (widget),
8564 adjust_allocation_recurse,
8571 adjust_allocation (GtkWidget *widget,
8575 ScrollData scroll_data;
8577 if (gtk_widget_get_realized (widget))
8578 scroll_data.window = ALLOCATION_WINDOW (widget);
8580 scroll_data.window = NULL;
8582 scroll_data.dx = dx;
8583 scroll_data.dy = dy;
8585 adjust_allocation_recurse (widget, &scroll_data);
8589 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8593 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8594 PsppSheetView *tree_view)
8596 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8601 gdk_window_move (tree_view->priv->bin_window,
8602 - tree_view->priv->hadjustment->value,
8603 TREE_VIEW_HEADER_HEIGHT (tree_view));
8604 gdk_window_move (tree_view->priv->header_window,
8605 - tree_view->priv->hadjustment->value,
8607 dy = tree_view->priv->dy - (int) tree_view->priv->vadjustment->value;
8610 update_prelight (tree_view,
8611 tree_view->priv->event_last_x,
8612 tree_view->priv->event_last_y - dy);
8614 if (tree_view->priv->edited_column &&
8615 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8619 PsppSheetViewChild *child = NULL;
8621 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8622 adjust_allocation (widget, 0, dy);
8624 for (list = tree_view->priv->children; list; list = list->next)
8626 child = (PsppSheetViewChild *)list->data;
8627 if (child->widget == widget)
8635 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8637 if (tree_view->priv->dy != (int) tree_view->priv->vadjustment->value)
8639 /* update our dy and top_row */
8640 tree_view->priv->dy = (int) tree_view->priv->vadjustment->value;
8642 if (!tree_view->priv->in_top_row_to_dy)
8643 pspp_sheet_view_dy_to_top_row (tree_view);
8646 for (list = tree_view->priv->columns; list; list = list->next)
8648 PsppSheetViewColumn *column = list->data;
8649 GtkAllocation *allocation = &column->allocation;
8651 if (span_intersects (allocation->x, allocation->width,
8652 tree_view->priv->hadjustment->value,
8653 GTK_WIDGET (tree_view)->allocation.width))
8655 pspp_sheet_view_column_set_need_button (column, TRUE);
8656 if (!column->button)
8657 pspp_sheet_view_column_update_button (column);
8669 * pspp_sheet_view_new:
8671 * Creates a new #PsppSheetView widget.
8673 * Return value: A newly created #PsppSheetView widget.
8676 pspp_sheet_view_new (void)
8678 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8682 * pspp_sheet_view_new_with_model:
8683 * @model: the model.
8685 * Creates a new #PsppSheetView widget with the model initialized to @model.
8687 * Return value: A newly created #PsppSheetView widget.
8690 pspp_sheet_view_new_with_model (GtkTreeModel *model)
8692 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
8699 * pspp_sheet_view_get_model:
8700 * @tree_view: a #PsppSheetView
8702 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
8705 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
8708 pspp_sheet_view_get_model (PsppSheetView *tree_view)
8710 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8712 return tree_view->priv->model;
8716 * pspp_sheet_view_set_model:
8717 * @tree_view: A #GtkTreeNode.
8718 * @model: (allow-none): The model.
8720 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
8721 * set, it will remove it before setting the new model. If @model is %NULL,
8722 * then it will unset the old model.
8725 pspp_sheet_view_set_model (PsppSheetView *tree_view,
8726 GtkTreeModel *model)
8728 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8729 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
8731 if (model == tree_view->priv->model)
8734 if (tree_view->priv->scroll_to_path)
8736 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8737 tree_view->priv->scroll_to_path = NULL;
8740 if (tree_view->priv->model)
8742 GList *tmplist = tree_view->priv->columns;
8744 if (tree_view->priv->selected)
8745 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
8746 pspp_sheet_view_stop_editing (tree_view, TRUE);
8748 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8749 pspp_sheet_view_row_changed,
8751 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8752 pspp_sheet_view_row_inserted,
8754 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8755 pspp_sheet_view_row_deleted,
8757 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8758 pspp_sheet_view_rows_reordered,
8761 for (; tmplist; tmplist = tmplist->next)
8762 _pspp_sheet_view_column_unset_model (tmplist->data,
8763 tree_view->priv->model);
8765 tree_view->priv->prelight_node = -1;
8767 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
8768 tree_view->priv->drag_dest_row = NULL;
8769 gtk_tree_row_reference_free (tree_view->priv->cursor);
8770 tree_view->priv->cursor = NULL;
8771 gtk_tree_row_reference_free (tree_view->priv->anchor);
8772 tree_view->priv->anchor = NULL;
8773 gtk_tree_row_reference_free (tree_view->priv->top_row);
8774 tree_view->priv->top_row = NULL;
8775 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8776 tree_view->priv->scroll_to_path = NULL;
8778 tree_view->priv->scroll_to_column = NULL;
8780 g_object_unref (tree_view->priv->model);
8782 tree_view->priv->search_column = -1;
8783 tree_view->priv->fixed_height = -1;
8784 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
8785 tree_view->priv->last_button_x = -1;
8786 tree_view->priv->last_button_y = -1;
8789 tree_view->priv->model = model;
8791 if (tree_view->priv->model)
8794 GtkTreeModelFlags flags;
8796 if (tree_view->priv->search_column == -1)
8798 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
8800 GType type = gtk_tree_model_get_column_type (model, i);
8802 if (g_value_type_transformable (type, G_TYPE_STRING))
8804 tree_view->priv->search_column = i;
8810 g_object_ref (tree_view->priv->model);
8811 g_signal_connect (tree_view->priv->model,
8813 G_CALLBACK (pspp_sheet_view_row_changed),
8815 g_signal_connect (tree_view->priv->model,
8817 G_CALLBACK (pspp_sheet_view_row_inserted),
8819 g_signal_connect (tree_view->priv->model,
8821 G_CALLBACK (pspp_sheet_view_row_deleted),
8823 g_signal_connect (tree_view->priv->model,
8825 G_CALLBACK (pspp_sheet_view_rows_reordered),
8828 flags = gtk_tree_model_get_flags (tree_view->priv->model);
8830 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
8832 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
8833 install_presize_handler (tree_view);
8836 g_object_notify (G_OBJECT (tree_view), "model");
8838 if (tree_view->priv->selection)
8839 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
8841 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8842 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
8846 * pspp_sheet_view_get_selection:
8847 * @tree_view: A #PsppSheetView.
8849 * Gets the #PsppSheetSelection associated with @tree_view.
8851 * Return value: A #PsppSheetSelection object.
8853 PsppSheetSelection *
8854 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
8856 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8858 return tree_view->priv->selection;
8862 * pspp_sheet_view_get_hadjustment:
8863 * @tree_view: A #PsppSheetView
8865 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
8867 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8871 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
8873 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8875 if (tree_view->priv->hadjustment == NULL)
8876 pspp_sheet_view_set_hadjustment (tree_view, NULL);
8878 return tree_view->priv->hadjustment;
8882 * pspp_sheet_view_set_hadjustment:
8883 * @tree_view: A #PsppSheetView
8884 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8886 * Sets the #GtkAdjustment for the current horizontal aspect.
8889 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
8890 GtkAdjustment *adjustment)
8892 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8894 pspp_sheet_view_set_adjustments (tree_view,
8896 tree_view->priv->vadjustment);
8898 g_object_notify (G_OBJECT (tree_view), "hadjustment");
8902 * pspp_sheet_view_get_vadjustment:
8903 * @tree_view: A #PsppSheetView
8905 * Gets the #GtkAdjustment currently being used for the vertical aspect.
8907 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8911 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
8913 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8915 if (tree_view->priv->vadjustment == NULL)
8916 pspp_sheet_view_set_vadjustment (tree_view, NULL);
8918 return tree_view->priv->vadjustment;
8922 * pspp_sheet_view_set_vadjustment:
8923 * @tree_view: A #PsppSheetView
8924 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8926 * Sets the #GtkAdjustment for the current vertical aspect.
8929 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
8930 GtkAdjustment *adjustment)
8932 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8934 pspp_sheet_view_set_adjustments (tree_view,
8935 tree_view->priv->hadjustment,
8938 g_object_notify (G_OBJECT (tree_view), "vadjustment");
8941 /* Column and header operations */
8944 * pspp_sheet_view_get_headers_visible:
8945 * @tree_view: A #PsppSheetView.
8947 * Returns %TRUE if the headers on the @tree_view are visible.
8949 * Return value: Whether the headers are visible or not.
8952 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
8954 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
8956 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8960 * pspp_sheet_view_set_headers_visible:
8961 * @tree_view: A #PsppSheetView.
8962 * @headers_visible: %TRUE if the headers are visible
8964 * Sets the visibility state of the headers.
8967 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
8968 gboolean headers_visible)
8972 PsppSheetViewColumn *column;
8974 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8976 headers_visible = !! headers_visible;
8978 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
8981 if (headers_visible)
8982 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8984 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8986 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8988 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
8989 if (headers_visible)
8991 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));
8993 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
8994 pspp_sheet_view_map_buttons (tree_view);
8998 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9000 for (list = tree_view->priv->columns; list; list = list->next)
9002 column = list->data;
9004 gtk_widget_unmap (column->button);
9006 gdk_window_hide (tree_view->priv->header_window);
9010 tree_view->priv->vadjustment->page_size = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
9011 tree_view->priv->vadjustment->page_increment = (GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2;
9012 tree_view->priv->vadjustment->lower = 0;
9013 tree_view->priv->vadjustment->upper = tree_view->priv->height;
9014 gtk_adjustment_changed (tree_view->priv->vadjustment);
9016 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9018 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9022 * pspp_sheet_view_columns_autosize:
9023 * @tree_view: A #PsppSheetView.
9025 * Resizes all columns to their optimal width. Only works after the
9026 * treeview has been realized.
9029 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9031 gboolean dirty = FALSE;
9033 PsppSheetViewColumn *column;
9035 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9037 for (list = tree_view->priv->columns; list; list = list->next)
9039 column = list->data;
9040 _pspp_sheet_view_column_cell_set_dirty (column);
9045 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9049 * pspp_sheet_view_set_headers_clickable:
9050 * @tree_view: A #PsppSheetView.
9051 * @setting: %TRUE if the columns are clickable.
9053 * Allow the column title buttons to be clicked.
9056 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9061 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9063 for (list = tree_view->priv->columns; list; list = list->next)
9064 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9066 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9071 * pspp_sheet_view_get_headers_clickable:
9072 * @tree_view: A #PsppSheetView.
9074 * Returns whether all header columns are clickable.
9076 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9081 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9085 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9087 for (list = tree_view->priv->columns; list; list = list->next)
9088 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9095 * pspp_sheet_view_set_rules_hint
9096 * @tree_view: a #PsppSheetView
9097 * @setting: %TRUE if the tree requires reading across rows
9099 * This function tells GTK+ that the user interface for your
9100 * application requires users to read across tree rows and associate
9101 * cells with one another. By default, GTK+ will then render the tree
9102 * with alternating row colors. Do <emphasis>not</emphasis> use it
9103 * just because you prefer the appearance of the ruled tree; that's a
9104 * question for the theme. Some themes will draw tree rows in
9105 * alternating colors even when rules are turned off, and users who
9106 * prefer that appearance all the time can choose those themes. You
9107 * should call this function only as a <emphasis>semantic</emphasis>
9108 * hint to the theme engine that your tree makes alternating colors
9109 * useful from a functional standpoint (since it has lots of columns,
9114 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9117 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9119 setting = setting != FALSE;
9121 if (tree_view->priv->has_rules != setting)
9123 tree_view->priv->has_rules = setting;
9124 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9127 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9131 * pspp_sheet_view_get_rules_hint
9132 * @tree_view: a #PsppSheetView
9134 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9136 * Return value: %TRUE if rules are useful for the user of this tree
9139 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9141 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9143 return tree_view->priv->has_rules;
9146 /* Public Column functions
9150 * pspp_sheet_view_append_column:
9151 * @tree_view: A #PsppSheetView.
9152 * @column: The #PsppSheetViewColumn to add.
9154 * Appends @column to the list of columns.
9156 * Return value: The number of columns in @tree_view after appending.
9159 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9160 PsppSheetViewColumn *column)
9162 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9163 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9164 g_return_val_if_fail (column->tree_view == NULL, -1);
9166 return pspp_sheet_view_insert_column (tree_view, column, -1);
9171 * pspp_sheet_view_remove_column:
9172 * @tree_view: A #PsppSheetView.
9173 * @column: The #PsppSheetViewColumn to remove.
9175 * Removes @column from @tree_view.
9177 * Return value: The number of columns in @tree_view after removing.
9180 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9181 PsppSheetViewColumn *column)
9183 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9184 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9185 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9187 if (tree_view->priv->focus_column == column)
9188 tree_view->priv->focus_column = NULL;
9190 if (tree_view->priv->edited_column == column)
9192 pspp_sheet_view_stop_editing (tree_view, TRUE);
9194 /* no need to, but just to be sure ... */
9195 tree_view->priv->edited_column = NULL;
9198 _pspp_sheet_view_column_unset_tree_view (column);
9200 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9201 tree_view->priv->n_columns--;
9203 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9207 _pspp_sheet_view_column_unrealize_button (column);
9208 for (list = tree_view->priv->columns; list; list = list->next)
9210 PsppSheetViewColumn *tmp_column;
9212 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9213 if (tmp_column->visible)
9214 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9217 if (tree_view->priv->n_columns == 0 &&
9218 pspp_sheet_view_get_headers_visible (tree_view))
9219 gdk_window_hide (tree_view->priv->header_window);
9221 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9224 g_object_unref (column);
9225 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9227 return tree_view->priv->n_columns;
9231 * pspp_sheet_view_insert_column:
9232 * @tree_view: A #PsppSheetView.
9233 * @column: The #PsppSheetViewColumn to be inserted.
9234 * @position: The position to insert @column in.
9236 * This inserts the @column into the @tree_view at @position. If @position is
9237 * -1, then the column is inserted at the end.
9239 * Return value: The number of columns in @tree_view after insertion.
9242 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9243 PsppSheetViewColumn *column,
9246 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9247 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9248 g_return_val_if_fail (column->tree_view == NULL, -1);
9250 g_object_ref_sink (column);
9252 if (tree_view->priv->n_columns == 0 &&
9253 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9254 pspp_sheet_view_get_headers_visible (tree_view))
9256 gdk_window_show (tree_view->priv->header_window);
9259 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9261 tree_view->priv->n_columns++;
9263 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9265 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9269 _pspp_sheet_view_column_realize_button (column);
9271 for (list = tree_view->priv->columns; list; list = list->next)
9273 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9274 if (column->visible)
9275 _pspp_sheet_view_column_cell_set_dirty (column);
9277 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9280 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9282 return tree_view->priv->n_columns;
9286 * pspp_sheet_view_insert_column_with_attributes:
9287 * @tree_view: A #PsppSheetView
9288 * @position: The position to insert the new column in.
9289 * @title: The title to set the header to.
9290 * @cell: The #GtkCellRenderer.
9291 * @Varargs: A %NULL-terminated list of attributes.
9293 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9294 * @position. If @position is -1, then the newly created column is inserted at
9295 * the end. The column is initialized with the attributes given.
9297 * Return value: The number of columns in @tree_view after insertion.
9300 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9303 GtkCellRenderer *cell,
9306 PsppSheetViewColumn *column;
9311 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9313 column = pspp_sheet_view_column_new ();
9314 pspp_sheet_view_column_set_title (column, title);
9315 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9317 va_start (args, cell);
9319 attribute = va_arg (args, gchar *);
9321 while (attribute != NULL)
9323 column_id = va_arg (args, gint);
9324 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9325 attribute = va_arg (args, gchar *);
9330 pspp_sheet_view_insert_column (tree_view, column, position);
9332 return tree_view->priv->n_columns;
9336 * pspp_sheet_view_insert_column_with_data_func:
9337 * @tree_view: a #PsppSheetView
9338 * @position: Position to insert, -1 for append
9339 * @title: column title
9340 * @cell: cell renderer for column
9341 * @func: function to set attributes of cell renderer
9342 * @data: data for @func
9343 * @dnotify: destroy notifier for @data
9345 * Convenience function that inserts a new column into the #PsppSheetView
9346 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9347 * attributes (normally using data from the model). See also
9348 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9350 * Return value: number of columns in the tree view post-insert
9353 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9356 GtkCellRenderer *cell,
9357 PsppSheetCellDataFunc func,
9359 GDestroyNotify dnotify)
9361 PsppSheetViewColumn *column;
9363 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9365 column = pspp_sheet_view_column_new ();
9366 pspp_sheet_view_column_set_title (column, title);
9367 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9368 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9370 pspp_sheet_view_insert_column (tree_view, column, position);
9372 return tree_view->priv->n_columns;
9376 * pspp_sheet_view_get_column:
9377 * @tree_view: A #PsppSheetView.
9378 * @n: The position of the column, counting from 0.
9380 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9382 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9385 PsppSheetViewColumn *
9386 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9389 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9391 if (n < 0 || n >= tree_view->priv->n_columns)
9394 if (tree_view->priv->columns == NULL)
9397 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9401 * pspp_sheet_view_get_columns:
9402 * @tree_view: A #PsppSheetView
9404 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9405 * The returned list must be freed with g_list_free ().
9407 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9410 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9412 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9414 return g_list_copy (tree_view->priv->columns);
9418 * pspp_sheet_view_move_column_after:
9419 * @tree_view: A #PsppSheetView
9420 * @column: The #PsppSheetViewColumn to be moved.
9421 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9423 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9424 * @column is placed in the first position.
9427 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9428 PsppSheetViewColumn *column,
9429 PsppSheetViewColumn *base_column)
9431 GList *column_list_el, *base_el = NULL;
9433 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9435 column_list_el = g_list_find (tree_view->priv->columns, column);
9436 g_return_if_fail (column_list_el != NULL);
9440 base_el = g_list_find (tree_view->priv->columns, base_column);
9441 g_return_if_fail (base_el != NULL);
9444 if (column_list_el->prev == base_el)
9447 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9448 if (base_el == NULL)
9450 column_list_el->prev = NULL;
9451 column_list_el->next = tree_view->priv->columns;
9452 if (column_list_el->next)
9453 column_list_el->next->prev = column_list_el;
9454 tree_view->priv->columns = column_list_el;
9458 column_list_el->prev = base_el;
9459 column_list_el->next = base_el->next;
9460 if (column_list_el->next)
9461 column_list_el->next->prev = column_list_el;
9462 base_el->next = column_list_el;
9465 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9467 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9468 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9471 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9475 * pspp_sheet_view_set_column_drag_function:
9476 * @tree_view: A #PsppSheetView.
9477 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9478 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9479 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9481 * Sets a user function for determining where a column may be dropped when
9482 * dragged. This function is called on every column pair in turn at the
9483 * beginning of a column drag to determine where a drop can take place. The
9484 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9485 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9486 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9487 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9488 * @tree_view reverts to the default behavior of allowing all columns to be
9489 * dropped everywhere.
9492 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9493 PsppSheetViewColumnDropFunc func,
9495 GDestroyNotify destroy)
9497 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9499 if (tree_view->priv->column_drop_func_data_destroy)
9500 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9502 tree_view->priv->column_drop_func = func;
9503 tree_view->priv->column_drop_func_data = user_data;
9504 tree_view->priv->column_drop_func_data_destroy = destroy;
9508 * pspp_sheet_view_scroll_to_point:
9509 * @tree_view: a #PsppSheetView
9510 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9511 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9513 * Scrolls the tree view such that the top-left corner of the visible
9514 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9515 * in tree coordinates. The @tree_view must be realized before
9516 * this function is called. If it isn't, you probably want to be
9517 * using pspp_sheet_view_scroll_to_cell().
9519 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9522 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9526 GtkAdjustment *hadj;
9527 GtkAdjustment *vadj;
9529 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9530 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9532 hadj = tree_view->priv->hadjustment;
9533 vadj = tree_view->priv->vadjustment;
9536 gtk_adjustment_set_value (hadj, CLAMP (tree_x, hadj->lower, hadj->upper - hadj->page_size));
9538 gtk_adjustment_set_value (vadj, CLAMP (tree_y, vadj->lower, vadj->upper - vadj->page_size));
9542 * pspp_sheet_view_scroll_to_cell:
9543 * @tree_view: A #PsppSheetView.
9544 * @path: (allow-none): The path of the row to move to, or %NULL.
9545 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9546 * @use_align: whether to use alignment arguments, or %FALSE.
9547 * @row_align: The vertical alignment of the row specified by @path.
9548 * @col_align: The horizontal alignment of the column specified by @column.
9550 * Moves the alignments of @tree_view to the position specified by @column and
9551 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9552 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9553 * or @path need to be non-%NULL. @row_align determines where the row is
9554 * placed, and @col_align determines where @column is placed. Both are expected
9555 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9556 * right/bottom alignment, 0.5 means center.
9558 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9559 * tree does the minimum amount of work to scroll the cell onto the screen.
9560 * This means that the cell will be scrolled to the edge closest to its current
9561 * position. If the cell is currently visible on the screen, nothing is done.
9563 * This function only works if the model is set, and @path is a valid row on the
9564 * model. If the model changes before the @tree_view is realized, the centered
9565 * path will be modified to reflect this change.
9568 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9570 PsppSheetViewColumn *column,
9575 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9576 g_return_if_fail (tree_view->priv->model != NULL);
9577 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9578 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9579 g_return_if_fail (path != NULL || column != NULL);
9582 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9583 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9585 row_align = CLAMP (row_align, 0.0, 1.0);
9586 col_align = CLAMP (col_align, 0.0, 1.0);
9589 /* Note: Despite the benefits that come from having one code path for the
9590 * scrolling code, we short-circuit validate_visible_area's immplementation as
9591 * it is much slower than just going to the point.
9593 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9594 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9595 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9597 if (tree_view->priv->scroll_to_path)
9598 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9600 tree_view->priv->scroll_to_path = NULL;
9601 tree_view->priv->scroll_to_column = NULL;
9604 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9606 tree_view->priv->scroll_to_column = column;
9607 tree_view->priv->scroll_to_use_align = use_align;
9608 tree_view->priv->scroll_to_row_align = row_align;
9609 tree_view->priv->scroll_to_col_align = col_align;
9611 install_presize_handler (tree_view);
9615 GdkRectangle cell_rect;
9616 GdkRectangle vis_rect;
9617 gint dest_x, dest_y;
9619 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9620 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9622 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9624 dest_x = vis_rect.x;
9625 dest_y = vis_rect.y;
9631 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9635 if (cell_rect.x < vis_rect.x)
9636 dest_x = cell_rect.x;
9637 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9638 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9646 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9647 dest_y = MAX (dest_y, 0);
9651 if (cell_rect.y < vis_rect.y)
9652 dest_y = cell_rect.y;
9653 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9654 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9658 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9663 * pspp_sheet_view_row_activated:
9664 * @tree_view: A #PsppSheetView
9665 * @path: The #GtkTreePath to be activated.
9666 * @column: The #PsppSheetViewColumn to be activated.
9668 * Activates the cell determined by @path and @column.
9671 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9673 PsppSheetViewColumn *column)
9675 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9677 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
9682 * pspp_sheet_view_get_reorderable:
9683 * @tree_view: a #PsppSheetView
9685 * Retrieves whether the user can reorder the tree via drag-and-drop. See
9686 * pspp_sheet_view_set_reorderable().
9688 * Return value: %TRUE if the tree can be reordered.
9691 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
9693 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9695 return tree_view->priv->reorderable;
9699 * pspp_sheet_view_set_reorderable:
9700 * @tree_view: A #PsppSheetView.
9701 * @reorderable: %TRUE, if the tree can be reordered.
9703 * This function is a convenience function to allow you to reorder
9704 * models that support the #GtkDragSourceIface and the
9705 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
9706 * these. If @reorderable is %TRUE, then the user can reorder the
9707 * model by dragging and dropping rows. The developer can listen to
9708 * these changes by connecting to the model's row_inserted and
9709 * row_deleted signals. The reordering is implemented by setting up
9710 * the tree view as a drag source and destination. Therefore, drag and
9711 * drop can not be used in a reorderable view for any other purpose.
9713 * This function does not give you any degree of control over the order -- any
9714 * reordering is allowed. If more control is needed, you should probably
9715 * handle drag and drop manually.
9718 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
9719 gboolean reorderable)
9721 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9723 reorderable = reorderable != FALSE;
9725 if (tree_view->priv->reorderable == reorderable)
9730 const GtkTargetEntry row_targets[] = {
9731 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
9734 pspp_sheet_view_enable_model_drag_source (tree_view,
9737 G_N_ELEMENTS (row_targets),
9739 pspp_sheet_view_enable_model_drag_dest (tree_view,
9741 G_N_ELEMENTS (row_targets),
9746 pspp_sheet_view_unset_rows_drag_source (tree_view);
9747 pspp_sheet_view_unset_rows_drag_dest (tree_view);
9750 tree_view->priv->reorderable = reorderable;
9752 g_object_notify (G_OBJECT (tree_view), "reorderable");
9755 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
9756 is pressed, other rows will be unselected.
9758 If CLAMP_NODE is true, then the sheetview will scroll to make the row
9761 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
9763 gboolean clear_and_select,
9764 gboolean clamp_node)
9768 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9770 GtkTreePath *cursor_path;
9771 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9772 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
9773 gtk_tree_path_free (cursor_path);
9776 gtk_tree_row_reference_free (tree_view->priv->cursor);
9777 tree_view->priv->cursor = NULL;
9779 _pspp_sheet_view_find_node (tree_view, path, &node);
9780 tree_view->priv->cursor =
9781 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
9782 tree_view->priv->model,
9785 if (tree_view->priv->row_count > 0)
9789 if (clear_and_select && !tree_view->priv->ctrl_pressed)
9791 GtkTreeSelectMode mode = 0;
9793 if (tree_view->priv->ctrl_pressed)
9794 mode |= GTK_TREE_SELECT_MODE_TOGGLE;
9795 if (tree_view->priv->shift_pressed)
9796 mode |= GTK_TREE_SELECT_MODE_EXTEND;
9798 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
9803 /* We have to re-find tree and node here again, somebody might have
9804 * cleared the node or the whole tree in the PsppSheetSelection::changed
9805 * callback. If the nodes differ we bail out here.
9807 _pspp_sheet_view_find_node (tree_view, path, &new_node);
9809 if (node != new_node)
9814 pspp_sheet_view_clamp_node_visible (tree_view, node);
9815 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
9819 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
9823 * pspp_sheet_view_get_cursor:
9824 * @tree_view: A #PsppSheetView
9825 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
9826 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
9828 * Fills in @path and @focus_column with the current path and focus column. If
9829 * the cursor isn't currently set, then *@path will be %NULL. If no column
9830 * currently has focus, then *@focus_column will be %NULL.
9832 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
9833 * you are done with it.
9836 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
9838 PsppSheetViewColumn **focus_column)
9840 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9844 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9845 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9852 *focus_column = tree_view->priv->focus_column;
9857 * pspp_sheet_view_set_cursor:
9858 * @tree_view: A #PsppSheetView
9859 * @path: A #GtkTreePath
9860 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9861 * @start_editing: %TRUE if the specified cell should start being edited.
9863 * Sets the current keyboard focus to be at @path, and selects it. This is
9864 * useful when you want to focus the user's attention on a particular row. If
9865 * @focus_column is not %NULL, then focus is given to the column specified by
9866 * it. Additionally, if @focus_column is specified, and @start_editing is
9867 * %TRUE, then editing should be started in the specified cell.
9868 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
9869 * in order to give keyboard focus to the widget. Please note that editing
9870 * can only happen when the widget is realized.
9872 * If @path is invalid for @model, the current cursor (if any) will be unset
9873 * and the function will return without failing.
9876 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
9878 PsppSheetViewColumn *focus_column,
9879 gboolean start_editing)
9881 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
9882 NULL, start_editing);
9886 * pspp_sheet_view_set_cursor_on_cell:
9887 * @tree_view: A #PsppSheetView
9888 * @path: A #GtkTreePath
9889 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9890 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
9891 * @start_editing: %TRUE if the specified cell should start being edited.
9893 * Sets the current keyboard focus to be at @path, and selects it. This is
9894 * useful when you want to focus the user's attention on a particular row. If
9895 * @focus_column is not %NULL, then focus is given to the column specified by
9896 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
9897 * contains 2 or more editable or activatable cells, then focus is given to
9898 * the cell specified by @focus_cell. Additionally, if @focus_column is
9899 * specified, and @start_editing is %TRUE, then editing should be started in
9900 * the specified cell. This function is often followed by
9901 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
9902 * widget. Please note that editing can only happen when the widget is
9905 * If @path is invalid for @model, the current cursor (if any) will be unset
9906 * and the function will return without failing.
9911 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
9913 PsppSheetViewColumn *focus_column,
9914 GtkCellRenderer *focus_cell,
9915 gboolean start_editing)
9917 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9918 g_return_if_fail (path != NULL);
9919 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
9921 if (!tree_view->priv->model)
9926 g_return_if_fail (focus_column);
9927 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
9930 /* cancel the current editing, if it exists */
9931 if (tree_view->priv->edited_column &&
9932 tree_view->priv->edited_column->editable_widget)
9933 pspp_sheet_view_stop_editing (tree_view, TRUE);
9935 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
9937 if (focus_column && focus_column->visible)
9940 gboolean column_in_tree = FALSE;
9942 for (list = tree_view->priv->columns; list; list = list->next)
9943 if (list->data == focus_column)
9945 column_in_tree = TRUE;
9948 g_return_if_fail (column_in_tree);
9949 tree_view->priv->focus_column = focus_column;
9951 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
9953 pspp_sheet_view_start_editing (tree_view, path);
9955 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
9956 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
9962 * pspp_sheet_view_get_bin_window:
9963 * @tree_view: A #PsppSheetView
9965 * Returns the window that @tree_view renders to. This is used primarily to
9966 * compare to <literal>event->window</literal> to confirm that the event on
9967 * @tree_view is on the right window.
9969 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
9972 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
9974 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9976 return tree_view->priv->bin_window;
9980 * pspp_sheet_view_get_path_at_pos:
9981 * @tree_view: A #PsppSheetView.
9982 * @x: The x position to be identified (relative to bin_window).
9983 * @y: The y position to be identified (relative to bin_window).
9984 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
9985 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
9986 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
9987 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
9989 * Finds the path at the point (@x, @y), relative to bin_window coordinates
9990 * (please see pspp_sheet_view_get_bin_window()).
9991 * That is, @x and @y are relative to an events coordinates. @x and @y must
9992 * come from an event on the @tree_view only where <literal>event->window ==
9993 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
9994 * things like popup menus. If @path is non-%NULL, then it will be filled
9995 * with the #GtkTreePath at that point. This path should be freed with
9996 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
9997 * with the column at that point. @cell_x and @cell_y return the coordinates
9998 * relative to the cell background (i.e. the @background_area passed to
9999 * gtk_cell_renderer_render()). This function is only meaningful if
10000 * @tree_view is realized. Therefore this function will always return %FALSE
10001 * if @tree_view is not realized or does not have a model.
10003 * For converting widget coordinates (eg. the ones you get from
10004 * GtkWidget::query-tooltip), please see
10005 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10007 * Return value: %TRUE if a row exists at that coordinate.
10010 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10013 GtkTreePath **path,
10014 PsppSheetViewColumn **column,
10021 g_return_val_if_fail (tree_view != NULL, FALSE);
10028 if (tree_view->priv->bin_window == NULL)
10031 if (tree_view->priv->row_count == 0)
10034 if (x > tree_view->priv->hadjustment->upper)
10037 if (x < 0 || y < 0)
10040 if (column || cell_x)
10042 PsppSheetViewColumn *tmp_column;
10043 PsppSheetViewColumn *last_column = NULL;
10045 gint remaining_x = x;
10046 gboolean found = FALSE;
10049 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10050 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10052 list = (rtl ? list->prev : list->next))
10054 tmp_column = list->data;
10056 if (tmp_column->visible == FALSE)
10059 last_column = tmp_column;
10060 if (remaining_x <= tmp_column->width)
10065 *column = tmp_column;
10068 *cell_x = remaining_x;
10072 remaining_x -= tmp_column->width;
10075 /* If found is FALSE and there is a last_column, then it the remainder
10076 * space is in that area
10083 *column = last_column;
10086 *cell_x = last_column->width + remaining_x;
10095 y_offset = pspp_sheet_view_find_offset (tree_view,
10096 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10103 *cell_y = y_offset;
10106 *path = _pspp_sheet_view_find_path (tree_view, node);
10111 /* Computes 'cell_area' from 'background_area', which must be the background
10112 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10113 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10114 the cell area as passed to _pspp_sheet_view_column_cell_render().
10116 'column' is required to properly adjust 'cell_area->x' and
10117 'cell_area->width'. It may be set to NULL if these values are not of
10118 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10121 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10122 PsppSheetViewColumn *column,
10123 const GdkRectangle *background_area,
10124 gboolean subtract_focus_rect,
10125 GdkRectangle *cell_area)
10127 gint vertical_separator;
10128 gint horizontal_separator;
10130 *cell_area = *background_area;
10132 gtk_widget_style_get (GTK_WIDGET (tree_view),
10133 "vertical-separator", &vertical_separator,
10134 "horizontal-separator", &horizontal_separator,
10136 cell_area->x += horizontal_separator / 2;
10137 cell_area->y += vertical_separator / 2;
10138 cell_area->width -= horizontal_separator;
10139 cell_area->height -= vertical_separator;
10141 if (subtract_focus_rect)
10143 int focus_line_width;
10145 gtk_widget_style_get (GTK_WIDGET (tree_view),
10146 "focus-line-width", &focus_line_width,
10148 cell_area->x += focus_line_width;
10149 cell_area->y += focus_line_width;
10150 cell_area->width -= 2 * focus_line_width;
10151 cell_area->height -= 2 * focus_line_width;
10154 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10156 gint grid_line_width;
10157 gtk_widget_style_get (GTK_WIDGET (tree_view),
10158 "grid-line-width", &grid_line_width,
10161 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10162 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10165 PsppSheetViewColumn *first_column, *last_column;
10168 /* Find the last visible column. */
10169 last_column = NULL;
10170 for (list = g_list_last (tree_view->priv->columns);
10174 PsppSheetViewColumn *c = list->data;
10182 /* Find the first visible column. */
10183 first_column = NULL;
10184 for (list = g_list_first (tree_view->priv->columns);
10188 PsppSheetViewColumn *c = list->data;
10196 if (column == first_column)
10198 cell_area->width -= grid_line_width / 2;
10200 else if (column == last_column)
10202 cell_area->x += grid_line_width / 2;
10203 cell_area->width -= grid_line_width / 2;
10207 cell_area->x += grid_line_width / 2;
10208 cell_area->width -= grid_line_width;
10212 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10213 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10215 cell_area->y += grid_line_width / 2;
10216 cell_area->height -= grid_line_width;
10220 if (column == NULL)
10223 cell_area->width = 0;
10228 * pspp_sheet_view_get_cell_area:
10229 * @tree_view: a #PsppSheetView
10230 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10231 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10232 * @rect: rectangle to fill with cell rect
10234 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10235 * row specified by @path and the column specified by @column. If @path is
10236 * %NULL, or points to a path not currently displayed, the @y and @height fields
10237 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10238 * fields will be filled with 0. The sum of all cell rects does not cover the
10239 * entire tree; there are extra pixels in between rows, for example. The
10240 * returned rectangle is equivalent to the @cell_area passed to
10241 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10245 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10247 PsppSheetViewColumn *column,
10248 GdkRectangle *rect)
10250 GdkRectangle background_area;
10252 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10253 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10254 g_return_if_fail (rect != NULL);
10255 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10256 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10258 pspp_sheet_view_get_background_area (tree_view, path, column,
10260 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10265 * pspp_sheet_view_get_background_area:
10266 * @tree_view: a #PsppSheetView
10267 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10268 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10269 * @rect: rectangle to fill with cell background rect
10271 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10272 * row specified by @path and the column specified by @column. If @path is
10273 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10274 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10275 * fields will be filled with 0. The returned rectangle is equivalent to the
10276 * @background_area passed to gtk_cell_renderer_render(). These background
10277 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10278 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10279 * itself, excluding surrounding borders.
10283 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10285 PsppSheetViewColumn *column,
10286 GdkRectangle *rect)
10290 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10291 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10292 g_return_if_fail (rect != NULL);
10301 /* Get vertical coords */
10303 _pspp_sheet_view_find_node (tree_view, path, &node);
10307 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10309 rect->height = ROW_HEIGHT (tree_view);
10316 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10317 rect->width = x2 - rect->x;
10322 * pspp_sheet_view_get_visible_rect:
10323 * @tree_view: a #PsppSheetView
10324 * @visible_rect: rectangle to fill
10326 * Fills @visible_rect with the currently-visible region of the
10327 * buffer, in tree coordinates. Convert to bin_window coordinates with
10328 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10329 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10330 * scrollable area of the tree.
10333 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10334 GdkRectangle *visible_rect)
10338 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10340 widget = GTK_WIDGET (tree_view);
10344 visible_rect->x = tree_view->priv->hadjustment->value;
10345 visible_rect->y = tree_view->priv->vadjustment->value;
10346 visible_rect->width = widget->allocation.width;
10347 visible_rect->height = widget->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10352 * pspp_sheet_view_widget_to_tree_coords:
10353 * @tree_view: a #PsppSheetView
10354 * @wx: X coordinate relative to bin_window
10355 * @wy: Y coordinate relative to bin_window
10356 * @tx: return location for tree X coordinate
10357 * @ty: return location for tree Y coordinate
10359 * Converts bin_window coordinates to coordinates for the
10360 * tree (the full scrollable area of the tree).
10362 * Deprecated: 2.12: Due to historial reasons the name of this function is
10363 * incorrect. For converting coordinates relative to the widget to
10364 * bin_window coordinates, please see
10365 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10369 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10375 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10378 *tx = wx + tree_view->priv->hadjustment->value;
10380 *ty = wy + tree_view->priv->dy;
10384 * pspp_sheet_view_tree_to_widget_coords:
10385 * @tree_view: a #PsppSheetView
10386 * @tx: tree X coordinate
10387 * @ty: tree Y coordinate
10388 * @wx: return location for X coordinate relative to bin_window
10389 * @wy: return location for Y coordinate relative to bin_window
10391 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10392 * to bin_window coordinates.
10394 * Deprecated: 2.12: Due to historial reasons the name of this function is
10395 * incorrect. For converting bin_window coordinates to coordinates relative
10396 * to bin_window, please see
10397 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10401 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10407 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10410 *wx = tx - tree_view->priv->hadjustment->value;
10412 *wy = ty - tree_view->priv->dy;
10417 * pspp_sheet_view_convert_widget_to_tree_coords:
10418 * @tree_view: a #PsppSheetView
10419 * @wx: X coordinate relative to the widget
10420 * @wy: Y coordinate relative to the widget
10421 * @tx: return location for tree X coordinate
10422 * @ty: return location for tree Y coordinate
10424 * Converts widget coordinates to coordinates for the
10425 * tree (the full scrollable area of the tree).
10430 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10438 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10440 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10443 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10449 * pspp_sheet_view_convert_tree_to_widget_coords:
10450 * @tree_view: a #PsppSheetView
10451 * @tx: X coordinate relative to the tree
10452 * @ty: Y coordinate relative to the tree
10453 * @wx: return location for widget X coordinate
10454 * @wy: return location for widget Y coordinate
10456 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10457 * to widget coordinates.
10462 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10470 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10472 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10475 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10481 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10482 * @tree_view: a #PsppSheetView
10483 * @wx: X coordinate relative to the widget
10484 * @wy: Y coordinate relative to the widget
10485 * @bx: return location for bin_window X coordinate
10486 * @by: return location for bin_window Y coordinate
10488 * Converts widget coordinates to coordinates for the bin_window
10489 * (see pspp_sheet_view_get_bin_window()).
10494 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10500 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10503 *bx = wx + tree_view->priv->hadjustment->value;
10505 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10509 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10510 * @tree_view: a #PsppSheetView
10511 * @bx: bin_window X coordinate
10512 * @by: bin_window Y coordinate
10513 * @wx: return location for widget X coordinate
10514 * @wy: return location for widget Y coordinate
10516 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10517 * to widget relative coordinates.
10522 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10528 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10531 *wx = bx - tree_view->priv->hadjustment->value;
10533 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10537 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10538 * @tree_view: a #PsppSheetView
10539 * @tx: tree X coordinate
10540 * @ty: tree Y coordinate
10541 * @bx: return location for X coordinate relative to bin_window
10542 * @by: return location for Y coordinate relative to bin_window
10544 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10545 * to bin_window coordinates.
10550 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10556 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10561 *by = ty - tree_view->priv->dy;
10565 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10566 * @tree_view: a #PsppSheetView
10567 * @bx: X coordinate relative to bin_window
10568 * @by: Y coordinate relative to bin_window
10569 * @tx: return location for tree X coordinate
10570 * @ty: return location for tree Y coordinate
10572 * Converts bin_window coordinates to coordinates for the
10573 * tree (the full scrollable area of the tree).
10578 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10584 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10589 *ty = by + tree_view->priv->dy;
10595 * pspp_sheet_view_get_visible_range:
10596 * @tree_view: A #PsppSheetView
10597 * @start_path: (allow-none): Return location for start of region, or %NULL.
10598 * @end_path: (allow-none): Return location for end of region, or %NULL.
10600 * Sets @start_path and @end_path to be the first and last visible path.
10601 * Note that there may be invisible paths in between.
10603 * The paths should be freed with gtk_tree_path_free() after use.
10605 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10610 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10611 GtkTreePath **start_path,
10612 GtkTreePath **end_path)
10617 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10619 if (!tree_view->priv->row_count)
10626 pspp_sheet_view_find_offset (tree_view,
10627 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10630 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10639 if (tree_view->priv->height < tree_view->priv->vadjustment->page_size)
10640 y = tree_view->priv->height - 1;
10642 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, tree_view->priv->vadjustment->page_size) - 1;
10644 pspp_sheet_view_find_offset (tree_view, y, &node);
10646 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10655 unset_reorderable (PsppSheetView *tree_view)
10657 if (tree_view->priv->reorderable)
10659 tree_view->priv->reorderable = FALSE;
10660 g_object_notify (G_OBJECT (tree_view), "reorderable");
10665 * pspp_sheet_view_enable_model_drag_source:
10666 * @tree_view: a #PsppSheetView
10667 * @start_button_mask: Mask of allowed buttons to start drag
10668 * @targets: the table of targets that the drag will support
10669 * @n_targets: the number of items in @targets
10670 * @actions: the bitmask of possible actions for a drag from this
10673 * Turns @tree_view into a drag source for automatic DND. Calling this
10674 * method sets #PsppSheetView:reorderable to %FALSE.
10677 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10678 GdkModifierType start_button_mask,
10679 const GtkTargetEntry *targets,
10681 GdkDragAction actions)
10683 TreeViewDragInfo *di;
10685 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10687 gtk_drag_source_set (GTK_WIDGET (tree_view),
10693 di = ensure_info (tree_view);
10695 di->start_button_mask = start_button_mask;
10696 di->source_actions = actions;
10697 di->source_set = TRUE;
10699 unset_reorderable (tree_view);
10703 * pspp_sheet_view_enable_model_drag_dest:
10704 * @tree_view: a #PsppSheetView
10705 * @targets: the table of targets that the drag will support
10706 * @n_targets: the number of items in @targets
10707 * @actions: the bitmask of possible actions for a drag from this
10710 * Turns @tree_view into a drop destination for automatic DND. Calling
10711 * this method sets #PsppSheetView:reorderable to %FALSE.
10714 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
10715 const GtkTargetEntry *targets,
10717 GdkDragAction actions)
10719 TreeViewDragInfo *di;
10721 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10723 gtk_drag_dest_set (GTK_WIDGET (tree_view),
10729 di = ensure_info (tree_view);
10730 di->dest_set = TRUE;
10732 unset_reorderable (tree_view);
10736 * pspp_sheet_view_unset_rows_drag_source:
10737 * @tree_view: a #PsppSheetView
10739 * Undoes the effect of
10740 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
10741 * #PsppSheetView:reorderable to %FALSE.
10744 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
10746 TreeViewDragInfo *di;
10748 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10750 di = get_info (tree_view);
10754 if (di->source_set)
10756 gtk_drag_source_unset (GTK_WIDGET (tree_view));
10757 di->source_set = FALSE;
10760 if (!di->dest_set && !di->source_set)
10761 remove_info (tree_view);
10764 unset_reorderable (tree_view);
10768 * pspp_sheet_view_unset_rows_drag_dest:
10769 * @tree_view: a #PsppSheetView
10771 * Undoes the effect of
10772 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
10773 * #PsppSheetView:reorderable to %FALSE.
10776 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
10778 TreeViewDragInfo *di;
10780 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10782 di = get_info (tree_view);
10788 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
10789 di->dest_set = FALSE;
10792 if (!di->dest_set && !di->source_set)
10793 remove_info (tree_view);
10796 unset_reorderable (tree_view);
10800 * pspp_sheet_view_set_drag_dest_row:
10801 * @tree_view: a #PsppSheetView
10802 * @path: (allow-none): The path of the row to highlight, or %NULL.
10803 * @pos: Specifies whether to drop before, after or into the row
10805 * Sets the row that is highlighted for feedback.
10808 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
10810 PsppSheetViewDropPosition pos)
10812 GtkTreePath *current_dest;
10814 /* Note; this function is exported to allow a custom DND
10815 * implementation, so it can't touch TreeViewDragInfo
10818 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10820 current_dest = NULL;
10822 if (tree_view->priv->drag_dest_row)
10824 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10825 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
10828 /* special case a drop on an empty model */
10829 tree_view->priv->empty_view_drop = 0;
10831 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
10832 && gtk_tree_path_get_depth (path) == 1
10833 && gtk_tree_path_get_indices (path)[0] == 0)
10837 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
10841 tree_view->priv->empty_view_drop = 1;
10844 tree_view->priv->drag_dest_pos = pos;
10848 tree_view->priv->drag_dest_row =
10849 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
10850 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
10853 tree_view->priv->drag_dest_row = NULL;
10857 int node, new_node;
10859 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
10860 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10864 new_node = pspp_sheet_view_node_next (tree_view, node);
10866 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
10868 new_node = pspp_sheet_view_node_prev (tree_view, node);
10870 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
10872 gtk_tree_path_free (current_dest);
10877 * pspp_sheet_view_get_drag_dest_row:
10878 * @tree_view: a #PsppSheetView
10879 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
10880 * @pos: (allow-none): Return location for the drop position, or %NULL
10882 * Gets information about the row that is highlighted for feedback.
10885 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
10886 GtkTreePath **path,
10887 PsppSheetViewDropPosition *pos)
10889 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10893 if (tree_view->priv->drag_dest_row)
10894 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10897 if (tree_view->priv->empty_view_drop)
10898 *path = gtk_tree_path_new_from_indices (0, -1);
10905 *pos = tree_view->priv->drag_dest_pos;
10909 * pspp_sheet_view_get_dest_row_at_pos:
10910 * @tree_view: a #PsppSheetView
10911 * @drag_x: the position to determine the destination row for
10912 * @drag_y: the position to determine the destination row for
10913 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
10914 * @pos: (allow-none): Return location for the drop position, or %NULL
10916 * Determines the destination row for a given position. @drag_x and
10917 * @drag_y are expected to be in widget coordinates. This function is only
10918 * meaningful if @tree_view is realized. Therefore this function will always
10919 * return %FALSE if @tree_view is not realized or does not have a model.
10921 * Return value: whether there is a row at the given position, %TRUE if this
10922 * is indeed the case.
10925 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
10928 GtkTreePath **path,
10929 PsppSheetViewDropPosition *pos)
10933 gdouble offset_into_row;
10936 PsppSheetViewColumn *column = NULL;
10937 GtkTreePath *tmp_path = NULL;
10939 /* Note; this function is exported to allow a custom DND
10940 * implementation, so it can't touch TreeViewDragInfo
10943 g_return_val_if_fail (tree_view != NULL, FALSE);
10944 g_return_val_if_fail (drag_x >= 0, FALSE);
10945 g_return_val_if_fail (drag_y >= 0, FALSE);
10950 if (tree_view->priv->bin_window == NULL)
10953 if (tree_view->priv->row_count == 0)
10956 /* If in the top third of a row, we drop before that row; if
10957 * in the bottom third, drop after that row; if in the middle,
10958 * and the row has children, drop into the row.
10960 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
10963 if (!pspp_sheet_view_get_path_at_pos (tree_view,
10972 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
10975 offset_into_row = cell_y;
10980 gtk_tree_path_free (tmp_path);
10984 third = cell.height / 3.0;
10988 if (offset_into_row < third)
10990 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
10992 else if (offset_into_row < (cell.height / 2.0))
10994 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
10996 else if (offset_into_row < third * 2.0)
10998 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11002 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11011 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11013 * pspp_sheet_view_create_row_drag_icon:
11014 * @tree_view: a #PsppSheetView
11015 * @path: a #GtkTreePath in @tree_view
11017 * Creates a #GdkPixmap representation of the row at @path.
11018 * This image is used for a drag icon.
11020 * Return value: a newly-allocated pixmap of the drag icon.
11023 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11030 GdkRectangle background_area;
11031 GdkRectangle expose_area;
11034 /* start drawing inside the black outline */
11036 GdkDrawable *drawable;
11037 gint bin_window_width;
11040 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11041 g_return_val_if_fail (path != NULL, NULL);
11043 widget = GTK_WIDGET (tree_view);
11045 if (!gtk_widget_get_realized (widget))
11048 depth = gtk_tree_path_get_depth (path);
11050 _pspp_sheet_view_find_node (tree_view,
11057 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11064 background_area.y = y;
11065 background_area.height = ROW_HEIGHT (tree_view);
11067 gdk_drawable_get_size (tree_view->priv->bin_window,
11068 &bin_window_width, NULL);
11070 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11071 bin_window_width + 2,
11072 background_area.height + 2,
11077 expose_area.width = bin_window_width + 2;
11078 expose_area.height = background_area.height + 2;
11080 gdk_draw_rectangle (drawable,
11081 widget->style->base_gc [gtk_widget_get_state (widget)],
11084 bin_window_width + 2,
11085 background_area.height + 2);
11087 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11089 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11091 list = (rtl ? list->prev : list->next))
11093 PsppSheetViewColumn *column = list->data;
11094 GdkRectangle cell_area;
11095 gint vertical_separator;
11097 if (!column->visible)
11100 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11102 background_area.x = cell_offset;
11103 background_area.width = column->width;
11105 gtk_widget_style_get (widget,
11106 "vertical-separator", &vertical_separator,
11109 cell_area = background_area;
11111 cell_area.y += vertical_separator / 2;
11112 cell_area.height -= vertical_separator;
11114 if (pspp_sheet_view_column_cell_is_visible (column))
11115 _pspp_sheet_view_column_cell_render (column,
11121 cell_offset += column->width;
11124 gdk_draw_rectangle (drawable,
11125 widget->style->black_gc,
11128 bin_window_width + 1,
11129 background_area.height + 1);
11136 * pspp_sheet_view_set_destroy_count_func:
11137 * @tree_view: A #PsppSheetView
11138 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11139 * @data: (allow-none): User data to be passed to @func, or %NULL
11140 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11142 * This function should almost never be used. It is meant for private use by
11143 * ATK for determining the number of visible children that are removed when a row is deleted.
11146 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11147 PsppSheetDestroyCountFunc func,
11149 GDestroyNotify destroy)
11151 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11153 if (tree_view->priv->destroy_count_destroy)
11154 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11156 tree_view->priv->destroy_count_func = func;
11157 tree_view->priv->destroy_count_data = data;
11158 tree_view->priv->destroy_count_destroy = destroy;
11163 * Interactive search
11167 * pspp_sheet_view_set_enable_search:
11168 * @tree_view: A #PsppSheetView
11169 * @enable_search: %TRUE, if the user can search interactively
11171 * If @enable_search is set, then the user can type in text to search through
11172 * the tree interactively (this is sometimes called "typeahead find").
11174 * Note that even if this is %FALSE, the user can still initiate a search
11175 * using the "start-interactive-search" key binding.
11178 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11179 gboolean enable_search)
11181 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11183 enable_search = !!enable_search;
11185 if (tree_view->priv->enable_search != enable_search)
11187 tree_view->priv->enable_search = enable_search;
11188 g_object_notify (G_OBJECT (tree_view), "enable-search");
11193 * pspp_sheet_view_get_enable_search:
11194 * @tree_view: A #PsppSheetView
11196 * Returns whether or not the tree allows to start interactive searching
11197 * by typing in text.
11199 * Return value: whether or not to let the user search interactively
11202 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11204 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11206 return tree_view->priv->enable_search;
11211 * pspp_sheet_view_get_search_column:
11212 * @tree_view: A #PsppSheetView
11214 * Gets the column searched on by the interactive search code.
11216 * Return value: the column the interactive search code searches in.
11219 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11221 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11223 return (tree_view->priv->search_column);
11227 * pspp_sheet_view_set_search_column:
11228 * @tree_view: A #PsppSheetView
11229 * @column: the column of the model to search in, or -1 to disable searching
11231 * Sets @column as the column where the interactive search code should
11232 * search in for the current model.
11234 * If the search column is set, users can use the "start-interactive-search"
11235 * key binding to bring up search popup. The enable-search property controls
11236 * whether simply typing text will also start an interactive search.
11238 * Note that @column refers to a column of the current model. The search
11239 * column is reset to -1 when the model is changed.
11242 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11245 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11246 g_return_if_fail (column >= -1);
11248 if (tree_view->priv->search_column == column)
11251 tree_view->priv->search_column = column;
11252 g_object_notify (G_OBJECT (tree_view), "search-column");
11256 * pspp_sheet_view_get_search_equal_func:
11257 * @tree_view: A #PsppSheetView
11259 * Returns the compare function currently in use.
11261 * Return value: the currently used compare function for the search code.
11264 PsppSheetViewSearchEqualFunc
11265 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11267 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11269 return tree_view->priv->search_equal_func;
11273 * pspp_sheet_view_set_search_equal_func:
11274 * @tree_view: A #PsppSheetView
11275 * @search_equal_func: the compare function to use during the search
11276 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11277 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11279 * Sets the compare function for the interactive search capabilities; note
11280 * that somewhat like strcmp() returning 0 for equality
11281 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11284 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11285 PsppSheetViewSearchEqualFunc search_equal_func,
11286 gpointer search_user_data,
11287 GDestroyNotify search_destroy)
11289 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11290 g_return_if_fail (search_equal_func != NULL);
11292 if (tree_view->priv->search_destroy)
11293 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11295 tree_view->priv->search_equal_func = search_equal_func;
11296 tree_view->priv->search_user_data = search_user_data;
11297 tree_view->priv->search_destroy = search_destroy;
11298 if (tree_view->priv->search_equal_func == NULL)
11299 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11303 * pspp_sheet_view_get_search_entry:
11304 * @tree_view: A #PsppSheetView
11306 * Returns the #GtkEntry which is currently in use as interactive search
11307 * entry for @tree_view. In case the built-in entry is being used, %NULL
11308 * will be returned.
11310 * Return value: the entry currently in use as search entry.
11315 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11317 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11319 if (tree_view->priv->search_custom_entry_set)
11320 return GTK_ENTRY (tree_view->priv->search_entry);
11326 * pspp_sheet_view_set_search_entry:
11327 * @tree_view: A #PsppSheetView
11328 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11330 * Sets the entry which the interactive search code will use for this
11331 * @tree_view. This is useful when you want to provide a search entry
11332 * in our interface at all time at a fixed position. Passing %NULL for
11333 * @entry will make the interactive search code use the built-in popup
11339 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11342 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11343 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11345 if (tree_view->priv->search_custom_entry_set)
11347 if (tree_view->priv->search_entry_changed_id)
11349 g_signal_handler_disconnect (tree_view->priv->search_entry,
11350 tree_view->priv->search_entry_changed_id);
11351 tree_view->priv->search_entry_changed_id = 0;
11353 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11354 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11357 g_object_unref (tree_view->priv->search_entry);
11359 else if (tree_view->priv->search_window)
11361 gtk_widget_destroy (tree_view->priv->search_window);
11363 tree_view->priv->search_window = NULL;
11368 tree_view->priv->search_entry = g_object_ref (entry);
11369 tree_view->priv->search_custom_entry_set = TRUE;
11371 if (tree_view->priv->search_entry_changed_id == 0)
11373 tree_view->priv->search_entry_changed_id =
11374 g_signal_connect (tree_view->priv->search_entry, "changed",
11375 G_CALLBACK (pspp_sheet_view_search_init),
11379 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11380 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11383 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11387 tree_view->priv->search_entry = NULL;
11388 tree_view->priv->search_custom_entry_set = FALSE;
11393 * pspp_sheet_view_set_search_position_func:
11394 * @tree_view: A #PsppSheetView
11395 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11396 * to use the default search position function
11397 * @data: (allow-none): user data to pass to @func, or %NULL
11398 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11400 * Sets the function to use when positioning the search dialog.
11405 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11406 PsppSheetViewSearchPositionFunc func,
11407 gpointer user_data,
11408 GDestroyNotify destroy)
11410 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11412 if (tree_view->priv->search_position_destroy)
11413 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11415 tree_view->priv->search_position_func = func;
11416 tree_view->priv->search_position_user_data = user_data;
11417 tree_view->priv->search_position_destroy = destroy;
11418 if (tree_view->priv->search_position_func == NULL)
11419 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11423 * pspp_sheet_view_get_search_position_func:
11424 * @tree_view: A #PsppSheetView
11426 * Returns the positioning function currently in use.
11428 * Return value: the currently used function for positioning the search dialog.
11432 PsppSheetViewSearchPositionFunc
11433 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11435 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11437 return tree_view->priv->search_position_func;
11442 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11443 PsppSheetView *tree_view)
11445 if (tree_view->priv->disable_popdown)
11448 if (tree_view->priv->search_entry_changed_id)
11450 g_signal_handler_disconnect (tree_view->priv->search_entry,
11451 tree_view->priv->search_entry_changed_id);
11452 tree_view->priv->search_entry_changed_id = 0;
11454 if (tree_view->priv->typeselect_flush_timeout)
11456 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11457 tree_view->priv->typeselect_flush_timeout = 0;
11460 if (gtk_widget_get_visible (search_dialog))
11462 /* send focus-in event */
11463 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11464 gtk_widget_hide (search_dialog);
11465 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11466 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11471 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11472 GtkWidget *search_dialog,
11473 gpointer user_data)
11476 gint tree_x, tree_y;
11477 gint tree_width, tree_height;
11478 GdkWindow *tree_window = GTK_WIDGET (tree_view)->window;
11479 GdkScreen *screen = gdk_drawable_get_screen (tree_window);
11480 GtkRequisition requisition;
11482 GdkRectangle monitor;
11484 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11485 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11487 gtk_widget_realize (search_dialog);
11489 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11490 gdk_drawable_get_size (tree_window,
11493 gtk_widget_size_request (search_dialog, &requisition);
11495 if (tree_x + tree_width > gdk_screen_get_width (screen))
11496 x = gdk_screen_get_width (screen) - requisition.width;
11497 else if (tree_x + tree_width - requisition.width < 0)
11500 x = tree_x + tree_width - requisition.width;
11502 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11503 y = gdk_screen_get_height (screen) - requisition.height;
11504 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11507 y = tree_y + tree_height;
11509 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11513 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11517 PsppSheetView *tree_view = (PsppSheetView *)data;
11519 tree_view->priv->disable_popdown = 1;
11520 g_signal_connect (menu, "hide",
11521 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11524 /* Because we're visible but offscreen, we just set a flag in the preedit
11528 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11529 PsppSheetView *tree_view)
11531 tree_view->priv->imcontext_changed = 1;
11532 if (tree_view->priv->typeselect_flush_timeout)
11534 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11535 tree_view->priv->typeselect_flush_timeout =
11536 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11537 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11544 pspp_sheet_view_search_activate (GtkEntry *entry,
11545 PsppSheetView *tree_view)
11550 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11553 /* If we have a row selected and it's the cursor row, we activate
11555 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11557 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11559 _pspp_sheet_view_find_node (tree_view, path, &node);
11561 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11562 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11564 gtk_tree_path_free (path);
11569 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11571 PsppSheetView *tree_view = (PsppSheetView *)data;
11573 tree_view->priv->disable_popdown = 0;
11579 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11582 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11586 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11587 GdkEventAny *event,
11588 PsppSheetView *tree_view)
11590 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11592 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11598 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11599 GdkEventButton *event,
11600 PsppSheetView *tree_view)
11602 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11604 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11606 if (event->window == tree_view->priv->bin_window)
11607 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11613 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11614 GdkEventScroll *event,
11615 PsppSheetView *tree_view)
11617 gboolean retval = FALSE;
11619 if (event->direction == GDK_SCROLL_UP)
11621 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11624 else if (event->direction == GDK_SCROLL_DOWN)
11626 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11630 /* renew the flush timeout */
11631 if (retval && tree_view->priv->typeselect_flush_timeout
11632 && !tree_view->priv->search_custom_entry_set)
11634 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11635 tree_view->priv->typeselect_flush_timeout =
11636 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11637 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11645 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11646 GdkEventKey *event,
11647 PsppSheetView *tree_view)
11649 gboolean retval = FALSE;
11651 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11652 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11654 /* close window and cancel the search */
11655 if (!tree_view->priv->search_custom_entry_set
11656 && (event->keyval == GDK_Escape ||
11657 event->keyval == GDK_Tab ||
11658 event->keyval == GDK_KP_Tab ||
11659 event->keyval == GDK_ISO_Left_Tab))
11661 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11665 /* select previous matching iter */
11666 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11668 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11669 gtk_widget_error_bell (widget);
11674 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11675 && (event->keyval == GDK_g || event->keyval == GDK_G))
11677 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11678 gtk_widget_error_bell (widget);
11683 /* select next matching iter */
11684 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
11686 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11687 gtk_widget_error_bell (widget);
11692 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
11693 && (event->keyval == GDK_g || event->keyval == GDK_G))
11695 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11696 gtk_widget_error_bell (widget);
11701 /* renew the flush timeout */
11702 if (retval && tree_view->priv->typeselect_flush_timeout
11703 && !tree_view->priv->search_custom_entry_set)
11705 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11706 tree_view->priv->typeselect_flush_timeout =
11707 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11708 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11715 /* this function returns FALSE if there is a search string but
11716 * nothing was found, and TRUE otherwise.
11719 pspp_sheet_view_search_move (GtkWidget *window,
11720 PsppSheetView *tree_view,
11728 GtkTreeModel *model;
11729 PsppSheetSelection *selection;
11731 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
11733 g_return_val_if_fail (text != NULL, FALSE);
11735 len = strlen (text);
11737 if (up && tree_view->priv->selected_iter == 1)
11738 return strlen (text) < 1;
11740 len = strlen (text);
11745 model = pspp_sheet_view_get_model (tree_view);
11746 selection = pspp_sheet_view_get_selection (tree_view);
11749 pspp_sheet_selection_unselect_all (selection);
11750 if (!gtk_tree_model_get_iter_first (model, &iter))
11753 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
11754 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
11759 tree_view->priv->selected_iter += up?(-1):(1);
11764 /* return to old iter */
11766 gtk_tree_model_get_iter_first (model, &iter);
11767 pspp_sheet_view_search_iter (model, selection,
11769 &count, tree_view->priv->selected_iter);
11775 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
11779 gpointer search_data)
11781 gboolean retval = TRUE;
11783 gchar *normalized_string;
11784 gchar *normalized_key;
11785 gchar *case_normalized_string = NULL;
11786 gchar *case_normalized_key = NULL;
11787 GValue value = {0,};
11788 GValue transformed = {0,};
11790 gtk_tree_model_get_value (model, iter, column, &value);
11792 g_value_init (&transformed, G_TYPE_STRING);
11794 if (!g_value_transform (&value, &transformed))
11796 g_value_unset (&value);
11800 g_value_unset (&value);
11802 str = g_value_get_string (&transformed);
11805 g_value_unset (&transformed);
11809 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
11810 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
11812 if (normalized_string && normalized_key)
11814 case_normalized_string = g_utf8_casefold (normalized_string, -1);
11815 case_normalized_key = g_utf8_casefold (normalized_key, -1);
11817 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
11821 g_value_unset (&transformed);
11822 g_free (normalized_key);
11823 g_free (normalized_string);
11824 g_free (case_normalized_key);
11825 g_free (case_normalized_string);
11831 pspp_sheet_view_search_iter (GtkTreeModel *model,
11832 PsppSheetSelection *selection,
11841 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
11843 path = gtk_tree_model_get_path (model, iter);
11844 _pspp_sheet_view_find_node (tree_view, path, &node);
11848 gboolean done = FALSE;
11850 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
11855 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
11857 pspp_sheet_selection_select_iter (selection, iter);
11858 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
11861 gtk_tree_path_free (path);
11870 node = pspp_sheet_view_node_next (tree_view, node);
11876 has_next = gtk_tree_model_iter_next (model, iter);
11879 gtk_tree_path_next (path);
11882 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
11887 gtk_tree_path_free (path);
11889 /* we've run out of tree, done with this func */
11901 pspp_sheet_view_search_init (GtkWidget *entry,
11902 PsppSheetView *tree_view)
11908 GtkTreeModel *model;
11909 PsppSheetSelection *selection;
11911 g_return_if_fail (GTK_IS_ENTRY (entry));
11912 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11914 text = gtk_entry_get_text (GTK_ENTRY (entry));
11916 model = pspp_sheet_view_get_model (tree_view);
11917 selection = pspp_sheet_view_get_selection (tree_view);
11920 pspp_sheet_selection_unselect_all (selection);
11921 if (tree_view->priv->typeselect_flush_timeout
11922 && !tree_view->priv->search_custom_entry_set)
11924 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11925 tree_view->priv->typeselect_flush_timeout =
11926 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11927 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11934 if (!gtk_tree_model_get_iter_first (model, &iter))
11937 ret = pspp_sheet_view_search_iter (model, selection,
11942 tree_view->priv->selected_iter = 1;
11946 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
11947 PsppSheetView *tree_view)
11949 if (tree_view->priv->edited_column == NULL)
11952 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
11953 tree_view->priv->edited_column = NULL;
11955 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
11956 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
11958 g_signal_handlers_disconnect_by_func (cell_editable,
11959 pspp_sheet_view_remove_widget,
11961 g_signal_handlers_disconnect_by_func (cell_editable,
11962 pspp_sheet_view_editable_button_press_event,
11964 g_signal_handlers_disconnect_by_func (cell_editable,
11965 pspp_sheet_view_editable_clicked,
11968 gtk_container_remove (GTK_CONTAINER (tree_view),
11969 GTK_WIDGET (cell_editable));
11971 /* FIXME should only redraw a single node */
11972 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
11976 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
11977 GtkTreePath *cursor_path)
11980 GdkRectangle background_area;
11981 GdkRectangle cell_area;
11982 GtkCellEditable *editable_widget = NULL;
11983 gchar *path_string;
11984 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
11985 gint retval = FALSE;
11988 g_assert (tree_view->priv->focus_column);
11990 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
11993 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
11994 if (cursor_node < 0)
11997 path_string = gtk_tree_path_to_string (cursor_path);
11998 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12000 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12001 tree_view->priv->model,
12003 pspp_sheet_view_get_background_area (tree_view,
12005 tree_view->priv->focus_column,
12007 pspp_sheet_view_get_cell_area (tree_view,
12009 tree_view->priv->focus_column,
12012 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12021 if (editable_widget != NULL)
12025 GtkCellRenderer *cell;
12028 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12030 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12033 area.width -= right + left;
12035 pspp_sheet_view_real_start_editing (tree_view,
12036 tree_view->priv->focus_column,
12045 g_free (path_string);
12050 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12051 GdkEventButton *event,
12052 PsppSheetView *sheet_view)
12056 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12057 "pspp-sheet-view-node"));
12058 return pspp_sheet_view_row_head_clicked (sheet_view,
12060 sheet_view->priv->edited_column,
12065 pspp_sheet_view_editable_clicked (GtkButton *button,
12066 PsppSheetView *sheet_view)
12068 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12073 is_all_selected (GtkWidget *widget)
12075 GtkEntryBuffer *buffer;
12076 gint start_pos, end_pos;
12078 if (!GTK_IS_ENTRY (widget))
12081 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12082 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12083 &start_pos, &end_pos)
12085 && end_pos == gtk_entry_buffer_get_length (buffer));
12089 is_at_left (GtkWidget *widget)
12091 return (GTK_IS_ENTRY (widget)
12092 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12096 is_at_right (GtkWidget *widget)
12098 GtkEntryBuffer *buffer;
12101 if (!GTK_IS_ENTRY (widget))
12104 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12105 length = gtk_entry_buffer_get_length (buffer);
12106 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12110 pspp_sheet_view_event (GtkWidget *widget,
12111 GdkEventKey *event,
12112 PsppSheetView *tree_view)
12114 PsppSheetViewColumn *column;
12122 /* Intercept only key press events.
12123 It would make sense to use "key-press-event" instead of "event", but
12124 GtkEntry attaches its own signal handler to "key-press-event" that runs
12125 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12127 if (event->type != GDK_KEY_PRESS)
12130 if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12132 /* Pass through most keys that include modifiers. */
12133 if ((event->keyval == GDK_Tab || event->keyval == GDK_ISO_Left_Tab)
12134 && !(event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK)))
12136 /* Special case for Shift-Tab. */
12142 keyval = event->keyval;
12143 state = event->state & ~(GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK);
12145 switch (event->keyval)
12147 case GDK_Left: case GDK_KP_Left:
12148 if (!is_all_selected (widget) && !is_at_left (widget))
12152 case GDK_Right: case GDK_KP_Right:
12153 if (!is_all_selected (widget) && !is_at_right (widget))
12157 case GDK_Up: case GDK_KP_Up:
12158 case GDK_Down: case GDK_KP_Down:
12161 case GDK_Page_Up: case GDK_KP_Page_Up:
12162 case GDK_Page_Down: case GDK_KP_Page_Down:
12174 case GDK_ISO_Left_Tab:
12175 keyval = event->state & GDK_SHIFT_MASK ? GDK_Left : GDK_Right;
12182 row = tree_view->priv->edited_row;
12183 column = tree_view->priv->edited_column;
12184 path = gtk_tree_path_new_from_indices (row, -1);
12186 pspp_sheet_view_stop_editing (tree_view, cancel);
12187 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12189 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12190 gtk_tree_path_free (path);
12192 handled = gtk_binding_set_activate (edit_bindings, keyval, state,
12193 GTK_OBJECT (tree_view));
12195 g_signal_stop_emission_by_name (widget, "event");
12197 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12198 pspp_sheet_view_start_editing (tree_view, path);
12199 gtk_tree_path_free (path);
12205 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12208 PsppSheetView *sheet_view = data;
12210 g_signal_connect (widget, "event",
12211 G_CALLBACK (pspp_sheet_view_event),
12214 if (GTK_IS_CONTAINER (widget))
12215 gtk_container_foreach (GTK_CONTAINER (widget),
12216 pspp_sheet_view_override_cell_keypresses,
12221 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12222 PsppSheetViewColumn *column,
12224 GtkCellEditable *cell_editable,
12225 GdkRectangle *cell_area,
12229 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12230 gint pre_val = tree_view->priv->vadjustment->value;
12231 GtkRequisition requisition;
12234 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12236 tree_view->priv->edited_column = column;
12237 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12239 row = gtk_tree_path_get_indices (path)[0];
12240 tree_view->priv->edited_row = row;
12241 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
12242 cell_area->y += pre_val - (int)tree_view->priv->vadjustment->value;
12244 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12245 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12246 tree_view->priv->anchor_column = column;
12248 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12250 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12252 if (requisition.height < cell_area->height)
12254 gint diff = cell_area->height - requisition.height;
12255 pspp_sheet_view_put (tree_view,
12256 GTK_WIDGET (cell_editable),
12257 cell_area->x, cell_area->y + diff/2,
12258 cell_area->width, requisition.height);
12262 pspp_sheet_view_put (tree_view,
12263 GTK_WIDGET (cell_editable),
12264 cell_area->x, cell_area->y,
12265 cell_area->width, cell_area->height);
12268 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12269 (GdkEvent *)event);
12271 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12272 g_signal_connect (cell_editable, "remove-widget",
12273 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12274 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12275 GTK_IS_BUTTON (cell_editable))
12277 g_signal_connect (cell_editable, "button-press-event",
12278 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12280 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12281 GINT_TO_POINTER (row));
12282 g_signal_connect (cell_editable, "clicked",
12283 G_CALLBACK (pspp_sheet_view_editable_clicked),
12287 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12292 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12293 gboolean cancel_editing)
12295 PsppSheetViewColumn *column;
12296 GtkCellRenderer *cell;
12298 if (tree_view->priv->edited_column == NULL)
12302 * This is very evil. We need to do this, because
12303 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12304 * later on. If pspp_sheet_view_row_changed notices
12305 * tree_view->priv->edited_column != NULL, it'll call
12306 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12308 * Please read that again if you intend to modify anything here.
12311 column = tree_view->priv->edited_column;
12312 tree_view->priv->edited_column = NULL;
12314 cell = _pspp_sheet_view_column_get_edited_cell (column);
12315 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12317 if (!cancel_editing)
12318 gtk_cell_editable_editing_done (column->editable_widget);
12320 tree_view->priv->edited_column = column;
12322 gtk_cell_editable_remove_widget (column->editable_widget);
12327 * pspp_sheet_view_set_hover_selection:
12328 * @tree_view: a #PsppSheetView
12329 * @hover: %TRUE to enable hover selection mode
12331 * Enables of disables the hover selection mode of @tree_view.
12332 * Hover selection makes the selected row follow the pointer.
12333 * Currently, this works only for the selection modes
12334 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12339 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12342 hover = hover != FALSE;
12344 if (hover != tree_view->priv->hover_selection)
12346 tree_view->priv->hover_selection = hover;
12348 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12353 * pspp_sheet_view_get_hover_selection:
12354 * @tree_view: a #PsppSheetView
12356 * Returns whether hover selection mode is turned on for @tree_view.
12358 * Return value: %TRUE if @tree_view is in hover selection mode
12363 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12365 return tree_view->priv->hover_selection;
12369 * pspp_sheet_view_set_rubber_banding:
12370 * @tree_view: a #PsppSheetView
12371 * @enable: %TRUE to enable rubber banding
12373 * Enables or disables rubber banding in @tree_view. If the selection mode is
12374 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12375 * banding will allow the user to select multiple rows by dragging the mouse.
12380 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12383 enable = enable != FALSE;
12385 if (enable != tree_view->priv->rubber_banding_enable)
12387 tree_view->priv->rubber_banding_enable = enable;
12389 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12394 * pspp_sheet_view_get_rubber_banding:
12395 * @tree_view: a #PsppSheetView
12397 * Returns whether rubber banding is turned on for @tree_view. If the
12398 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12399 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12400 * select multiple rows by dragging the mouse.
12402 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12407 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12409 return tree_view->priv->rubber_banding_enable;
12413 * pspp_sheet_view_is_rubber_banding_active:
12414 * @tree_view: a #PsppSheetView
12416 * Returns whether a rubber banding operation is currently being done
12419 * Return value: %TRUE if a rubber banding operation is currently being
12420 * done in @tree_view.
12425 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12427 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12429 if (tree_view->priv->rubber_banding_enable
12430 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12437 pspp_sheet_view_grab_notify (GtkWidget *widget,
12438 gboolean was_grabbed)
12440 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12442 tree_view->priv->in_grab = !was_grabbed;
12446 tree_view->priv->pressed_button = -1;
12448 if (tree_view->priv->rubber_band_status)
12449 pspp_sheet_view_stop_rubber_band (tree_view);
12454 pspp_sheet_view_state_changed (GtkWidget *widget,
12455 GtkStateType previous_state)
12457 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12459 if (gtk_widget_get_realized (widget))
12461 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
12462 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
12465 gtk_widget_queue_draw (widget);
12469 * pspp_sheet_view_get_grid_lines:
12470 * @tree_view: a #PsppSheetView
12472 * Returns which grid lines are enabled in @tree_view.
12474 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12479 PsppSheetViewGridLines
12480 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12482 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12484 return tree_view->priv->grid_lines;
12488 * pspp_sheet_view_set_grid_lines:
12489 * @tree_view: a #PsppSheetView
12490 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12493 * Sets which grid lines to draw in @tree_view.
12498 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12499 PsppSheetViewGridLines grid_lines)
12501 PsppSheetViewPrivate *priv;
12503 PsppSheetViewGridLines old_grid_lines;
12505 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12507 priv = tree_view->priv;
12508 widget = GTK_WIDGET (tree_view);
12510 old_grid_lines = priv->grid_lines;
12511 priv->grid_lines = grid_lines;
12513 if (gtk_widget_get_realized (widget))
12515 if (grid_lines == PSPP_SHEET_VIEW_GRID_LINES_NONE &&
12516 priv->grid_line_gc)
12518 g_object_unref (priv->grid_line_gc);
12519 priv->grid_line_gc = NULL;
12522 if (grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE &&
12523 !priv->grid_line_gc)
12527 gtk_widget_style_get (widget,
12528 "grid-line-width", &line_width,
12531 priv->grid_line_gc = gdk_gc_new (widget->window);
12532 gdk_gc_copy (priv->grid_line_gc, widget->style->black_gc);
12536 if (old_grid_lines != grid_lines)
12538 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12540 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12545 * pspp_sheet_view_get_special_cells:
12546 * @tree_view: a #PsppSheetView
12548 * Returns which grid lines are enabled in @tree_view.
12550 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12551 * the sheet view contain special cells.
12553 PsppSheetViewSpecialCells
12554 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12556 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12558 return tree_view->priv->special_cells;
12562 * pspp_sheet_view_set_special_cells:
12563 * @tree_view: a #PsppSheetView
12564 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12565 * the sheet view contain special cells.
12567 * Sets whether rows in the sheet view contain special cells, controlling the
12568 * rendering of row selections.
12571 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12572 PsppSheetViewSpecialCells special_cells)
12574 PsppSheetViewPrivate *priv;
12577 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12579 priv = tree_view->priv;
12580 widget = GTK_WIDGET (tree_view);
12582 if (priv->special_cells != special_cells)
12584 priv->special_cells = special_cells;
12585 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12586 g_object_notify (G_OBJECT (tree_view), "special-cells");
12591 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12593 /* XXX (re)calculate fixed_height if necessary */
12594 return tree_view->priv->fixed_height;
12598 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12601 g_return_if_fail (fixed_height > 0);
12603 if (tree_view->priv->fixed_height != fixed_height)
12605 tree_view->priv->fixed_height = fixed_height;
12606 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12608 if (!tree_view->priv->fixed_height_set)
12610 tree_view->priv->fixed_height_set = TRUE;
12611 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12616 * pspp_sheet_view_set_tooltip_row:
12617 * @tree_view: a #PsppSheetView
12618 * @tooltip: a #GtkTooltip
12619 * @path: a #GtkTreePath
12621 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12622 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12623 * See also gtk_tooltip_set_tip_area().
12628 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12629 GtkTooltip *tooltip,
12632 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12633 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12635 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12639 * pspp_sheet_view_set_tooltip_cell:
12640 * @tree_view: a #PsppSheetView
12641 * @tooltip: a #GtkTooltip
12642 * @path: (allow-none): a #GtkTreePath or %NULL
12643 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12644 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12646 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12647 * in common. For example if @path is %NULL and @column is set, the tip
12648 * area will be set to the full area covered by @column. See also
12649 * gtk_tooltip_set_tip_area().
12651 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12656 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12657 GtkTooltip *tooltip,
12659 PsppSheetViewColumn *column,
12660 GtkCellRenderer *cell)
12664 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12665 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12666 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12667 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12669 /* Determine x values. */
12670 if (column && cell)
12675 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12676 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12678 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12681 rect.width = width;
12687 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
12688 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12691 rect.width = tmp.width;
12696 rect.width = GTK_WIDGET (tree_view)->allocation.width;
12699 /* Determine y values. */
12704 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
12705 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12708 rect.height = tmp.height;
12713 rect.height = tree_view->priv->vadjustment->page_size;
12716 gtk_tooltip_set_tip_area (tooltip, &rect);
12720 * pspp_sheet_view_get_tooltip_context:
12721 * @tree_view: a #PsppSheetView
12722 * @x: the x coordinate (relative to widget coordinates)
12723 * @y: the y coordinate (relative to widget coordinates)
12724 * @keyboard_tip: whether this is a keyboard tooltip or not
12725 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
12726 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
12727 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
12729 * This function is supposed to be used in a #GtkWidget::query-tooltip
12730 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
12731 * which are received in the signal handler, should be passed to this
12732 * function without modification.
12734 * The return value indicates whether there is a tree view row at the given
12735 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
12736 * tooltips the row returned will be the cursor row. When %TRUE, then any of
12737 * @model, @path and @iter which have been provided will be set to point to
12738 * that row and the corresponding model. @x and @y will always be converted
12739 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
12741 * Return value: whether or not the given tooltip context points to a row.
12746 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
12749 gboolean keyboard_tip,
12750 GtkTreeModel **model,
12751 GtkTreePath **path,
12754 GtkTreePath *tmppath = NULL;
12756 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12757 g_return_val_if_fail (x != NULL, FALSE);
12758 g_return_val_if_fail (y != NULL, FALSE);
12762 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
12769 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
12772 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
12773 &tmppath, NULL, NULL, NULL))
12778 *model = pspp_sheet_view_get_model (tree_view);
12781 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
12787 gtk_tree_path_free (tmppath);
12793 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
12796 gboolean keyboard_tip,
12797 GtkTooltip *tooltip,
12800 GValue value = { 0, };
12801 GValue transformed = { 0, };
12804 GtkTreeModel *model;
12805 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12807 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
12810 &model, &path, &iter))
12813 gtk_tree_model_get_value (model, &iter,
12814 tree_view->priv->tooltip_column, &value);
12816 g_value_init (&transformed, G_TYPE_STRING);
12818 if (!g_value_transform (&value, &transformed))
12820 g_value_unset (&value);
12821 gtk_tree_path_free (path);
12826 g_value_unset (&value);
12828 if (!g_value_get_string (&transformed))
12830 g_value_unset (&transformed);
12831 gtk_tree_path_free (path);
12836 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
12837 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
12839 gtk_tree_path_free (path);
12840 g_value_unset (&transformed);
12846 * pspp_sheet_view_set_tooltip_column:
12847 * @tree_view: a #PsppSheetView
12848 * @column: an integer, which is a valid column number for @tree_view's model
12850 * If you only plan to have simple (text-only) tooltips on full rows, you
12851 * can use this function to have #PsppSheetView handle these automatically
12852 * for you. @column should be set to the column in @tree_view's model
12853 * containing the tooltip texts, or -1 to disable this feature.
12855 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
12856 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
12858 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
12859 * so &, <, etc have to be escaped in the text.
12864 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
12867 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12869 if (column == tree_view->priv->tooltip_column)
12874 g_signal_handlers_disconnect_by_func (tree_view,
12875 pspp_sheet_view_set_tooltip_query_cb,
12877 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
12881 if (tree_view->priv->tooltip_column == -1)
12883 g_signal_connect (tree_view, "query-tooltip",
12884 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
12885 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
12889 tree_view->priv->tooltip_column = column;
12890 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
12894 * pspp_sheet_view_get_tooltip_column:
12895 * @tree_view: a #PsppSheetView
12897 * Returns the column of @tree_view's model which is being used for
12898 * displaying tooltips on @tree_view's rows.
12900 * Return value: the index of the tooltip column that is currently being
12901 * used, or -1 if this is disabled.
12906 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
12908 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12910 return tree_view->priv->tooltip_column;
12914 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
12915 GValue *return_accu,
12916 const GValue *handler_return,
12919 gboolean continue_emission;
12920 gboolean signal_handled;
12922 signal_handled = g_value_get_boolean (handler_return);
12923 g_value_set_boolean (return_accu, signal_handled);
12924 continue_emission = !signal_handled;
12926 return continue_emission;
12930 pspp_sheet_view_grid_lines_get_type (void)
12932 static GType etype = 0;
12933 if (G_UNLIKELY(etype == 0)) {
12934 static const GEnumValue values[] = {
12935 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
12936 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
12937 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
12938 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
12941 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
12947 pspp_sheet_view_special_cells_get_type (void)
12949 static GType etype = 0;
12950 if (G_UNLIKELY(etype == 0)) {
12951 static const GEnumValue values[] = {
12952 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
12953 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
12954 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
12957 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);