1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011, 2012 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Library General Public
22 * License as published by the Free Software Foundation; either
23 * version 2 of the License, or (at your option) any later version.
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Library General Public License for more details.
30 * You should have received a copy of the GNU Library General Public
31 * License along with this library; if not, write to the
32 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
33 * Boston, MA 02111-1307, USA.
38 #include "ui/gui/pspp-sheet-private.h"
42 #include <gdk/gdkkeysyms.h>
45 #include "ui/gui/psppire-marshal.h"
46 #include "ui/gui/pspp-sheet-selection.h"
48 #define P_(STRING) STRING
49 #define GTK_PARAM_READABLE G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
50 #define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
52 /* Many keyboard shortcuts for Mac are the same as for X
53 * except they use Command key instead of Control (e.g. Cut,
54 * Copy, Paste). This symbol is for those simple cases. */
55 #ifndef GDK_WINDOWING_QUARTZ
56 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_CONTROL_MASK
58 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_META_MASK
61 #define PSPP_SHEET_VIEW_PRIORITY_VALIDATE (GDK_PRIORITY_REDRAW + 5)
62 #define PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC (PSPP_SHEET_VIEW_PRIORITY_VALIDATE + 2)
63 #define PSPP_SHEET_VIEW_TIME_MS_PER_IDLE 30
64 #define SCROLL_EDGE_SIZE 15
65 #define EXPANDER_EXTRA_PADDING 4
66 #define PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT 5000
68 /* The "background" areas of all rows/cells add up to cover the entire tree.
69 * The background includes all inter-row and inter-cell spacing.
70 * The "cell" areas are the cell_area passed in to gtk_cell_renderer_render(),
71 * i.e. just the cells, no spacing.
74 #define BACKGROUND_HEIGHT(tree_view) (tree_view->priv->fixed_height)
75 #define CELL_HEIGHT(tree_view, separator) ((BACKGROUND_HEIGHT (tree_view)) - (separator))
77 /* Translate from bin_window coordinates to rbtree (tree coordinates) and
80 #define TREE_WINDOW_Y_TO_RBTREE_Y(tree_view,y) ((y) + tree_view->priv->dy)
81 #define RBTREE_Y_TO_TREE_WINDOW_Y(tree_view,y) ((y) - tree_view->priv->dy)
83 /* This is in bin_window coordinates */
84 #define BACKGROUND_FIRST_PIXEL(tree_view,node) (RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, pspp_sheet_view_node_find_offset (tree_view, (node))))
85 #define CELL_FIRST_PIXEL(tree_view,node,separator) (BACKGROUND_FIRST_PIXEL (tree_view,node) + separator/2)
87 #define ROW_HEIGHT(tree_view) \
88 ((tree_view->priv->fixed_height > 0) ? (tree_view->priv->fixed_height) : (tree_view)->priv->expander_size)
91 typedef struct _PsppSheetViewChild PsppSheetViewChild;
92 struct _PsppSheetViewChild
102 typedef struct _TreeViewDragInfo TreeViewDragInfo;
103 struct _TreeViewDragInfo
105 GdkModifierType start_button_mask;
106 GtkTargetList *_unused_source_target_list;
107 GdkDragAction source_actions;
109 GtkTargetList *_unused_dest_target_list;
111 guint source_set : 1;
127 START_INTERACTIVE_SEARCH,
137 PROP_HEADERS_VISIBLE,
138 PROP_HEADERS_CLICKABLE,
143 PROP_HOVER_SELECTION,
145 PROP_ENABLE_GRID_LINES,
149 PROP_FIXED_HEIGHT_SET
153 static void pspp_sheet_view_finalize (GObject *object);
154 static void pspp_sheet_view_set_property (GObject *object,
158 static void pspp_sheet_view_get_property (GObject *object,
163 /* gtkobject signals */
164 static void pspp_sheet_view_destroy (GtkObject *object);
166 /* gtkwidget signals */
167 static void pspp_sheet_view_realize (GtkWidget *widget);
168 static void pspp_sheet_view_unrealize (GtkWidget *widget);
169 static void pspp_sheet_view_map (GtkWidget *widget);
170 static void pspp_sheet_view_size_request (GtkWidget *widget,
171 GtkRequisition *requisition);
172 static void pspp_sheet_view_size_allocate (GtkWidget *widget,
173 GtkAllocation *allocation);
174 static gboolean pspp_sheet_view_expose (GtkWidget *widget,
175 GdkEventExpose *event);
176 static gboolean pspp_sheet_view_key_press (GtkWidget *widget,
178 static gboolean pspp_sheet_view_key_release (GtkWidget *widget,
180 static gboolean pspp_sheet_view_motion (GtkWidget *widget,
181 GdkEventMotion *event);
182 static gboolean pspp_sheet_view_enter_notify (GtkWidget *widget,
183 GdkEventCrossing *event);
184 static gboolean pspp_sheet_view_leave_notify (GtkWidget *widget,
185 GdkEventCrossing *event);
186 static gboolean pspp_sheet_view_button_press (GtkWidget *widget,
187 GdkEventButton *event);
188 static gboolean pspp_sheet_view_button_release (GtkWidget *widget,
189 GdkEventButton *event);
190 static gboolean pspp_sheet_view_grab_broken (GtkWidget *widget,
191 GdkEventGrabBroken *event);
193 static void pspp_sheet_view_set_focus_child (GtkContainer *container,
195 static gint pspp_sheet_view_focus_out (GtkWidget *widget,
196 GdkEventFocus *event);
197 static gint pspp_sheet_view_focus (GtkWidget *widget,
198 GtkDirectionType direction);
199 static void pspp_sheet_view_grab_focus (GtkWidget *widget);
200 static void pspp_sheet_view_style_set (GtkWidget *widget,
201 GtkStyle *previous_style);
202 static void pspp_sheet_view_grab_notify (GtkWidget *widget,
203 gboolean was_grabbed);
204 static void pspp_sheet_view_state_changed (GtkWidget *widget,
205 GtkStateType previous_state);
207 /* container signals */
208 static void pspp_sheet_view_remove (GtkContainer *container,
210 static void pspp_sheet_view_forall (GtkContainer *container,
211 gboolean include_internals,
212 GtkCallback callback,
213 gpointer callback_data);
215 /* Source side drag signals */
216 static void pspp_sheet_view_drag_begin (GtkWidget *widget,
217 GdkDragContext *context);
218 static void pspp_sheet_view_drag_end (GtkWidget *widget,
219 GdkDragContext *context);
220 static void pspp_sheet_view_drag_data_get (GtkWidget *widget,
221 GdkDragContext *context,
222 GtkSelectionData *selection_data,
225 static void pspp_sheet_view_drag_data_delete (GtkWidget *widget,
226 GdkDragContext *context);
228 /* Target side drag signals */
229 static void pspp_sheet_view_drag_leave (GtkWidget *widget,
230 GdkDragContext *context,
232 static gboolean pspp_sheet_view_drag_motion (GtkWidget *widget,
233 GdkDragContext *context,
237 static gboolean pspp_sheet_view_drag_drop (GtkWidget *widget,
238 GdkDragContext *context,
242 static void pspp_sheet_view_drag_data_received (GtkWidget *widget,
243 GdkDragContext *context,
246 GtkSelectionData *selection_data,
250 /* tree_model signals */
251 static void pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
253 GtkAdjustment *vadj);
254 static gboolean pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
255 GtkMovementStep step,
257 static gboolean pspp_sheet_view_real_select_all (PsppSheetView *tree_view);
258 static gboolean pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view);
259 static gboolean pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
260 gboolean start_editing);
261 static gboolean pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view);
262 static void pspp_sheet_view_row_changed (GtkTreeModel *model,
266 static void pspp_sheet_view_row_inserted (GtkTreeModel *model,
270 static void pspp_sheet_view_row_deleted (GtkTreeModel *model,
273 static void pspp_sheet_view_rows_reordered (GtkTreeModel *model,
279 /* Incremental reflow */
280 static gint validate_row (PsppSheetView *tree_view,
284 static void validate_visible_area (PsppSheetView *tree_view);
285 static gboolean validate_rows_handler (PsppSheetView *tree_view);
286 static gboolean presize_handler_callback (gpointer data);
287 static void install_presize_handler (PsppSheetView *tree_view);
288 static void install_scroll_sync_handler (PsppSheetView *tree_view);
289 static void pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
292 static void pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view);
293 static void pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view);
294 static void invalidate_empty_focus (PsppSheetView *tree_view);
296 /* Internal functions */
297 static void pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
300 gboolean add_shifted_binding,
301 GtkMovementStep step,
303 static void pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
305 const GdkRectangle *clip_rect);
306 static gint pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
309 static void pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
310 PsppSheetView *tree_view);
311 static void pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
313 static void pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
314 PsppSheetViewColumn *column,
315 gboolean focus_to_cell);
316 static gboolean pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
317 GdkEventMotion *event);
318 static void pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view);
319 static void pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
321 static void pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
323 static void pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
325 static void pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
327 static void pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
329 gboolean clear_and_select,
330 gboolean clamp_node);
331 static gboolean pspp_sheet_view_has_special_cell (PsppSheetView *tree_view);
332 static void pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view);
333 static void update_prelight (PsppSheetView *tree_view,
336 static void initialize_fixed_height_mode (PsppSheetView *tree_view);
338 /* interactive search */
339 static void pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view);
340 static void pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
341 PsppSheetView *tree_view);
342 static void pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
343 GtkWidget *search_dialog,
345 static void pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
348 static void pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
349 PsppSheetView *tree_view);
350 static void pspp_sheet_view_search_activate (GtkEntry *entry,
351 PsppSheetView *tree_view);
352 static gboolean pspp_sheet_view_real_search_enable_popdown(gpointer data);
353 static void pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
355 static gboolean pspp_sheet_view_search_delete_event (GtkWidget *widget,
357 PsppSheetView *tree_view);
358 static gboolean pspp_sheet_view_search_button_press_event (GtkWidget *widget,
359 GdkEventButton *event,
360 PsppSheetView *tree_view);
361 static gboolean pspp_sheet_view_search_scroll_event (GtkWidget *entry,
362 GdkEventScroll *event,
363 PsppSheetView *tree_view);
364 static gboolean pspp_sheet_view_search_key_press_event (GtkWidget *entry,
366 PsppSheetView *tree_view);
367 static gboolean pspp_sheet_view_search_move (GtkWidget *window,
368 PsppSheetView *tree_view,
370 static gboolean pspp_sheet_view_search_equal_func (GtkTreeModel *model,
374 gpointer search_data);
375 static gboolean pspp_sheet_view_search_iter (GtkTreeModel *model,
376 PsppSheetSelection *selection,
381 static void pspp_sheet_view_search_init (GtkWidget *entry,
382 PsppSheetView *tree_view);
383 static void pspp_sheet_view_put (PsppSheetView *tree_view,
384 GtkWidget *child_widget,
389 static gboolean pspp_sheet_view_start_editing (PsppSheetView *tree_view,
390 GtkTreePath *cursor_path);
391 static gboolean pspp_sheet_view_editable_button_press_event (GtkWidget *,
394 static void pspp_sheet_view_editable_clicked (GtkButton *, PsppSheetView *);
395 static void pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
396 PsppSheetViewColumn *column,
398 GtkCellEditable *cell_editable,
399 GdkRectangle *cell_area,
402 static gboolean pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
403 gboolean keybinding);
404 static gboolean pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view);
405 static PsppSheetViewColumn *pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
406 PsppSheetViewColumn *column,
409 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
410 PsppSheetViewColumn *column,
411 const GdkRectangle *background_area,
412 gboolean subtract_focus_rect,
413 GdkRectangle *cell_area);
414 static gint pspp_sheet_view_find_offset (PsppSheetView *tree_view,
419 static void pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
423 static void pspp_sheet_view_buildable_init (GtkBuildableIface *iface);
426 static gboolean scroll_row_timeout (gpointer data);
427 static void add_scroll_timeout (PsppSheetView *tree_view);
428 static void remove_scroll_timeout (PsppSheetView *tree_view);
430 static guint tree_view_signals [LAST_SIGNAL] = { 0 };
437 G_DEFINE_TYPE_WITH_CODE (PsppSheetView, pspp_sheet_view, GTK_TYPE_CONTAINER,
438 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
439 pspp_sheet_view_buildable_init))
442 pspp_sheet_view_class_init (PsppSheetViewClass *class)
444 GObjectClass *o_class;
445 GtkObjectClass *object_class;
446 GtkWidgetClass *widget_class;
447 GtkContainerClass *container_class;
448 GtkBindingSet *binding_set;
450 binding_set = gtk_binding_set_by_class (class);
452 o_class = (GObjectClass *) class;
453 object_class = (GtkObjectClass *) class;
454 widget_class = (GtkWidgetClass *) class;
455 container_class = (GtkContainerClass *) class;
457 /* GObject signals */
458 o_class->set_property = pspp_sheet_view_set_property;
459 o_class->get_property = pspp_sheet_view_get_property;
460 o_class->finalize = pspp_sheet_view_finalize;
462 /* GtkObject signals */
463 object_class->destroy = pspp_sheet_view_destroy;
465 /* GtkWidget signals */
466 widget_class->map = pspp_sheet_view_map;
467 widget_class->realize = pspp_sheet_view_realize;
468 widget_class->unrealize = pspp_sheet_view_unrealize;
469 widget_class->size_request = pspp_sheet_view_size_request;
470 widget_class->size_allocate = pspp_sheet_view_size_allocate;
471 widget_class->button_press_event = pspp_sheet_view_button_press;
472 widget_class->button_release_event = pspp_sheet_view_button_release;
473 widget_class->grab_broken_event = pspp_sheet_view_grab_broken;
474 /*widget_class->configure_event = pspp_sheet_view_configure;*/
475 widget_class->motion_notify_event = pspp_sheet_view_motion;
476 widget_class->expose_event = pspp_sheet_view_expose;
477 widget_class->key_press_event = pspp_sheet_view_key_press;
478 widget_class->key_release_event = pspp_sheet_view_key_release;
479 widget_class->enter_notify_event = pspp_sheet_view_enter_notify;
480 widget_class->leave_notify_event = pspp_sheet_view_leave_notify;
481 widget_class->focus_out_event = pspp_sheet_view_focus_out;
482 widget_class->drag_begin = pspp_sheet_view_drag_begin;
483 widget_class->drag_end = pspp_sheet_view_drag_end;
484 widget_class->drag_data_get = pspp_sheet_view_drag_data_get;
485 widget_class->drag_data_delete = pspp_sheet_view_drag_data_delete;
486 widget_class->drag_leave = pspp_sheet_view_drag_leave;
487 widget_class->drag_motion = pspp_sheet_view_drag_motion;
488 widget_class->drag_drop = pspp_sheet_view_drag_drop;
489 widget_class->drag_data_received = pspp_sheet_view_drag_data_received;
490 widget_class->focus = pspp_sheet_view_focus;
491 widget_class->grab_focus = pspp_sheet_view_grab_focus;
492 widget_class->style_set = pspp_sheet_view_style_set;
493 widget_class->grab_notify = pspp_sheet_view_grab_notify;
494 widget_class->state_changed = pspp_sheet_view_state_changed;
496 /* GtkContainer signals */
497 container_class->remove = pspp_sheet_view_remove;
498 container_class->forall = pspp_sheet_view_forall;
499 container_class->set_focus_child = pspp_sheet_view_set_focus_child;
501 class->set_scroll_adjustments = pspp_sheet_view_set_adjustments;
502 class->move_cursor = pspp_sheet_view_real_move_cursor;
503 class->select_all = pspp_sheet_view_real_select_all;
504 class->unselect_all = pspp_sheet_view_real_unselect_all;
505 class->select_cursor_row = pspp_sheet_view_real_select_cursor_row;
506 class->toggle_cursor_row = pspp_sheet_view_real_toggle_cursor_row;
507 class->start_interactive_search = pspp_sheet_view_start_interactive_search;
511 g_object_class_install_property (o_class,
513 g_param_spec_object ("model",
514 P_("TreeView Model"),
515 P_("The model for the tree view"),
517 GTK_PARAM_READWRITE));
519 g_object_class_install_property (o_class,
521 g_param_spec_object ("hadjustment",
522 P_("Horizontal Adjustment"),
523 P_("Horizontal Adjustment for the widget"),
525 GTK_PARAM_READWRITE));
527 g_object_class_install_property (o_class,
529 g_param_spec_object ("vadjustment",
530 P_("Vertical Adjustment"),
531 P_("Vertical Adjustment for the widget"),
533 GTK_PARAM_READWRITE));
535 g_object_class_install_property (o_class,
536 PROP_HEADERS_VISIBLE,
537 g_param_spec_boolean ("headers-visible",
538 P_("Headers Visible"),
539 P_("Show the column header buttons"),
541 GTK_PARAM_READWRITE));
543 g_object_class_install_property (o_class,
544 PROP_HEADERS_CLICKABLE,
545 g_param_spec_boolean ("headers-clickable",
546 P_("Headers Clickable"),
547 P_("Column headers respond to click events"),
549 GTK_PARAM_READWRITE));
551 g_object_class_install_property (o_class,
553 g_param_spec_boolean ("reorderable",
555 P_("View is reorderable"),
557 GTK_PARAM_READWRITE));
559 g_object_class_install_property (o_class,
561 g_param_spec_boolean ("rules-hint",
563 P_("Set a hint to the theme engine to draw rows in alternating colors"),
565 GTK_PARAM_READWRITE));
567 g_object_class_install_property (o_class,
569 g_param_spec_boolean ("enable-search",
571 P_("View allows user to search through columns interactively"),
573 GTK_PARAM_READWRITE));
575 g_object_class_install_property (o_class,
577 g_param_spec_int ("search-column",
579 P_("Model column to search through during interactive search"),
583 GTK_PARAM_READWRITE));
586 * PsppSheetView:hover-selection:
588 * Enables of disables the hover selection mode of @tree_view.
589 * Hover selection makes the selected row follow the pointer.
590 * Currently, this works only for the selection modes
591 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
593 * This mode is primarily intended for treeviews in popups, e.g.
594 * in #GtkComboBox or #GtkEntryCompletion.
598 g_object_class_install_property (o_class,
599 PROP_HOVER_SELECTION,
600 g_param_spec_boolean ("hover-selection",
601 P_("Hover Selection"),
602 P_("Whether the selection should follow the pointer"),
604 GTK_PARAM_READWRITE));
606 g_object_class_install_property (o_class,
608 g_param_spec_boolean ("rubber-banding",
609 P_("Rubber Banding"),
610 P_("Whether to enable selection of multiple items by dragging the mouse pointer"),
612 GTK_PARAM_READWRITE));
614 g_object_class_install_property (o_class,
615 PROP_ENABLE_GRID_LINES,
616 g_param_spec_enum ("enable-grid-lines",
617 P_("Enable Grid Lines"),
618 P_("Whether grid lines should be drawn in the tree view"),
619 PSPP_TYPE_SHEET_VIEW_GRID_LINES,
620 PSPP_SHEET_VIEW_GRID_LINES_NONE,
621 GTK_PARAM_READWRITE));
623 g_object_class_install_property (o_class,
625 g_param_spec_int ("tooltip-column",
626 P_("Tooltip Column"),
627 P_("The column in the model containing the tooltip texts for the rows"),
631 GTK_PARAM_READWRITE));
633 g_object_class_install_property (o_class,
635 g_param_spec_enum ("special-cells",
637 P_("Whether rows have special cells."),
638 PSPP_TYPE_SHEET_VIEW_SPECIAL_CELLS,
639 PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT,
640 GTK_PARAM_READWRITE));
642 g_object_class_install_property (o_class,
644 g_param_spec_int ("fixed-height",
646 P_("Height of a single row. Normally the height of a row is determined automatically. Writing this property sets fixed-height-set to true, preventing this property's value from changing."),
650 GTK_PARAM_READWRITE));
652 g_object_class_install_property (o_class,
653 PROP_FIXED_HEIGHT_SET,
654 g_param_spec_boolean ("fixed-height-set",
655 P_("Fixed Height Set"),
656 P_("Whether fixed-height was set externally."),
658 GTK_PARAM_READWRITE));
660 /* Style properties */
661 #define _TREE_VIEW_EXPANDER_SIZE 12
662 #define _TREE_VIEW_VERTICAL_SEPARATOR 2
663 #define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
665 gtk_widget_class_install_style_property (widget_class,
666 g_param_spec_int ("expander-size",
668 P_("Size of the expander arrow"),
671 _TREE_VIEW_EXPANDER_SIZE,
672 GTK_PARAM_READABLE));
674 gtk_widget_class_install_style_property (widget_class,
675 g_param_spec_int ("vertical-separator",
676 P_("Vertical Separator Width"),
677 P_("Vertical space between cells. Must be an even number"),
680 _TREE_VIEW_VERTICAL_SEPARATOR,
681 GTK_PARAM_READABLE));
683 gtk_widget_class_install_style_property (widget_class,
684 g_param_spec_int ("horizontal-separator",
685 P_("Horizontal Separator Width"),
686 P_("Horizontal space between cells. Must be an even number"),
689 _TREE_VIEW_HORIZONTAL_SEPARATOR,
690 GTK_PARAM_READABLE));
692 gtk_widget_class_install_style_property (widget_class,
693 g_param_spec_boolean ("allow-rules",
695 P_("Allow drawing of alternating color rows"),
697 GTK_PARAM_READABLE));
699 gtk_widget_class_install_style_property (widget_class,
700 g_param_spec_boxed ("even-row-color",
701 P_("Even Row Color"),
702 P_("Color to use for even rows"),
704 GTK_PARAM_READABLE));
706 gtk_widget_class_install_style_property (widget_class,
707 g_param_spec_boxed ("odd-row-color",
709 P_("Color to use for odd rows"),
711 GTK_PARAM_READABLE));
713 gtk_widget_class_install_style_property (widget_class,
714 g_param_spec_boolean ("row-ending-details",
715 P_("Row Ending details"),
716 P_("Enable extended row background theming"),
718 GTK_PARAM_READABLE));
720 gtk_widget_class_install_style_property (widget_class,
721 g_param_spec_int ("grid-line-width",
722 P_("Grid line width"),
723 P_("Width, in pixels, of the tree view grid lines"),
725 GTK_PARAM_READABLE));
727 gtk_widget_class_install_style_property (widget_class,
728 g_param_spec_int ("tree-line-width",
729 P_("Tree line width"),
730 P_("Width, in pixels, of the tree view lines"),
732 GTK_PARAM_READABLE));
734 gtk_widget_class_install_style_property (widget_class,
735 g_param_spec_string ("tree-line-pattern",
736 P_("Tree line pattern"),
737 P_("Dash pattern used to draw the tree view lines"),
739 GTK_PARAM_READABLE));
743 * PsppSheetView::set-scroll-adjustments
744 * @horizontal: the horizontal #GtkAdjustment
745 * @vertical: the vertical #GtkAdjustment
747 * Set the scroll adjustments for the tree view. Usually scrolled containers
748 * like #GtkScrolledWindow will emit this signal to connect two instances
749 * of #GtkScrollbar to the scroll directions of the #PsppSheetView.
751 widget_class->set_scroll_adjustments_signal =
752 g_signal_new ("set-scroll-adjustments",
753 G_TYPE_FROM_CLASS (o_class),
754 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
755 G_STRUCT_OFFSET (PsppSheetViewClass, set_scroll_adjustments),
757 psppire_marshal_VOID__OBJECT_OBJECT,
760 GTK_TYPE_ADJUSTMENT);
763 * PsppSheetView::row-activated:
764 * @tree_view: the object on which the signal is emitted
765 * @path: the #GtkTreePath for the activated row
766 * @column: the #PsppSheetViewColumn in which the activation occurred
768 * The "row-activated" signal is emitted when the method
769 * pspp_sheet_view_row_activated() is called or the user double clicks
770 * a treeview row. It is also emitted when a non-editable row is
771 * selected and one of the keys: Space, Shift+Space, Return or
774 * For selection handling refer to the <link linkend="TreeWidget">tree
775 * widget conceptual overview</link> as well as #PsppSheetSelection.
777 tree_view_signals[ROW_ACTIVATED] =
778 g_signal_new ("row-activated",
779 G_TYPE_FROM_CLASS (o_class),
780 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
781 G_STRUCT_OFFSET (PsppSheetViewClass, row_activated),
783 psppire_marshal_VOID__BOXED_OBJECT,
786 PSPP_TYPE_SHEET_VIEW_COLUMN);
789 * PsppSheetView::columns-changed:
790 * @tree_view: the object on which the signal is emitted
792 * The number of columns of the treeview has changed.
794 tree_view_signals[COLUMNS_CHANGED] =
795 g_signal_new ("columns-changed",
796 G_TYPE_FROM_CLASS (o_class),
798 G_STRUCT_OFFSET (PsppSheetViewClass, columns_changed),
800 g_cclosure_marshal_VOID__VOID,
804 * PsppSheetView::cursor-changed:
805 * @tree_view: the object on which the signal is emitted
807 * The position of the cursor (focused cell) has changed.
809 tree_view_signals[CURSOR_CHANGED] =
810 g_signal_new ("cursor-changed",
811 G_TYPE_FROM_CLASS (o_class),
813 G_STRUCT_OFFSET (PsppSheetViewClass, cursor_changed),
815 g_cclosure_marshal_VOID__VOID,
818 tree_view_signals[MOVE_CURSOR] =
819 g_signal_new ("move-cursor",
820 G_TYPE_FROM_CLASS (object_class),
821 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
822 G_STRUCT_OFFSET (PsppSheetViewClass, move_cursor),
824 psppire_marshal_BOOLEAN__ENUM_INT,
826 GTK_TYPE_MOVEMENT_STEP,
829 tree_view_signals[SELECT_ALL] =
830 g_signal_new ("select-all",
831 G_TYPE_FROM_CLASS (object_class),
832 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
833 G_STRUCT_OFFSET (PsppSheetViewClass, select_all),
835 psppire_marshal_BOOLEAN__VOID,
838 tree_view_signals[UNSELECT_ALL] =
839 g_signal_new ("unselect-all",
840 G_TYPE_FROM_CLASS (object_class),
841 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
842 G_STRUCT_OFFSET (PsppSheetViewClass, unselect_all),
844 psppire_marshal_BOOLEAN__VOID,
847 tree_view_signals[SELECT_CURSOR_ROW] =
848 g_signal_new ("select-cursor-row",
849 G_TYPE_FROM_CLASS (object_class),
850 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
851 G_STRUCT_OFFSET (PsppSheetViewClass, select_cursor_row),
853 psppire_marshal_BOOLEAN__BOOLEAN,
857 tree_view_signals[TOGGLE_CURSOR_ROW] =
858 g_signal_new ("toggle-cursor-row",
859 G_TYPE_FROM_CLASS (object_class),
860 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
861 G_STRUCT_OFFSET (PsppSheetViewClass, toggle_cursor_row),
863 psppire_marshal_BOOLEAN__VOID,
866 tree_view_signals[START_INTERACTIVE_SEARCH] =
867 g_signal_new ("start-interactive-search",
868 G_TYPE_FROM_CLASS (object_class),
869 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
870 G_STRUCT_OFFSET (PsppSheetViewClass, start_interactive_search),
872 psppire_marshal_BOOLEAN__VOID,
876 pspp_sheet_view_add_move_binding (binding_set, GDK_Up, 0, TRUE,
877 GTK_MOVEMENT_DISPLAY_LINES, -1);
878 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_Up, 0, TRUE,
879 GTK_MOVEMENT_DISPLAY_LINES, -1);
881 pspp_sheet_view_add_move_binding (binding_set, GDK_Down, 0, TRUE,
882 GTK_MOVEMENT_DISPLAY_LINES, 1);
883 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_Down, 0, TRUE,
884 GTK_MOVEMENT_DISPLAY_LINES, 1);
886 pspp_sheet_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK, FALSE,
887 GTK_MOVEMENT_DISPLAY_LINES, -1);
889 pspp_sheet_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK, FALSE,
890 GTK_MOVEMENT_DISPLAY_LINES, 1);
892 pspp_sheet_view_add_move_binding (binding_set, GDK_Home, 0, TRUE,
893 GTK_MOVEMENT_BUFFER_ENDS, -1);
894 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_Home, 0, TRUE,
895 GTK_MOVEMENT_BUFFER_ENDS, -1);
897 pspp_sheet_view_add_move_binding (binding_set, GDK_End, 0, TRUE,
898 GTK_MOVEMENT_BUFFER_ENDS, 1);
899 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_End, 0, TRUE,
900 GTK_MOVEMENT_BUFFER_ENDS, 1);
902 pspp_sheet_view_add_move_binding (binding_set, GDK_Page_Up, 0, TRUE,
903 GTK_MOVEMENT_PAGES, -1);
904 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0, TRUE,
905 GTK_MOVEMENT_PAGES, -1);
907 pspp_sheet_view_add_move_binding (binding_set, GDK_Page_Down, 0, TRUE,
908 GTK_MOVEMENT_PAGES, 1);
909 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0, TRUE,
910 GTK_MOVEMENT_PAGES, 1);
913 gtk_binding_entry_add_signal (binding_set, GDK_Right, 0, "move-cursor", 2,
914 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
917 gtk_binding_entry_add_signal (binding_set, GDK_Left, 0, "move-cursor", 2,
918 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
921 gtk_binding_entry_add_signal (binding_set, GDK_KP_Right, 0, "move-cursor", 2,
922 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
925 gtk_binding_entry_add_signal (binding_set, GDK_KP_Left, 0, "move-cursor", 2,
926 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
929 gtk_binding_entry_add_signal (binding_set, GDK_Right, GDK_CONTROL_MASK,
931 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
934 gtk_binding_entry_add_signal (binding_set, GDK_Left, GDK_CONTROL_MASK,
936 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
939 gtk_binding_entry_add_signal (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
941 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
944 gtk_binding_entry_add_signal (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
946 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
949 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
950 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
952 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK, "select-all", 0);
953 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK, "select-all", 0);
955 gtk_binding_entry_add_signal (binding_set, GDK_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0);
956 gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK, "unselect-all", 0);
958 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_SHIFT_MASK, "select-cursor-row", 1,
959 G_TYPE_BOOLEAN, TRUE);
960 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", 1,
961 G_TYPE_BOOLEAN, TRUE);
963 gtk_binding_entry_add_signal (binding_set, GDK_space, 0, "select-cursor-row", 1,
964 G_TYPE_BOOLEAN, TRUE);
965 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0, "select-cursor-row", 1,
966 G_TYPE_BOOLEAN, TRUE);
967 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0, "select-cursor-row", 1,
968 G_TYPE_BOOLEAN, TRUE);
969 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0, "select-cursor-row", 1,
970 G_TYPE_BOOLEAN, TRUE);
971 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, "select-cursor-row", 1,
972 G_TYPE_BOOLEAN, TRUE);
974 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0, "select-cursor-parent", 0);
975 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", 0);
977 gtk_binding_entry_add_signal (binding_set, GDK_f, GDK_CONTROL_MASK, "start-interactive-search", 0);
979 gtk_binding_entry_add_signal (binding_set, GDK_F, GDK_CONTROL_MASK, "start-interactive-search", 0);
981 g_type_class_add_private (o_class, sizeof (PsppSheetViewPrivate));
985 pspp_sheet_view_buildable_init (GtkBuildableIface *iface)
987 iface->add_child = pspp_sheet_view_buildable_add_child;
991 pspp_sheet_view_init (PsppSheetView *tree_view)
993 tree_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (tree_view, PSPP_TYPE_SHEET_VIEW, PsppSheetViewPrivate);
995 gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
996 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (tree_view), FALSE);
998 tree_view->priv->flags = PSPP_SHEET_VIEW_DRAW_KEYFOCUS
999 | PSPP_SHEET_VIEW_HEADERS_VISIBLE;
1001 /* We need some padding */
1002 tree_view->priv->selected = range_tower_create ();
1003 tree_view->priv->dy = 0;
1004 tree_view->priv->cursor_offset = 0;
1005 tree_view->priv->n_columns = 0;
1006 tree_view->priv->header_height = 1;
1007 tree_view->priv->x_drag = 0;
1008 tree_view->priv->drag_pos = -1;
1009 tree_view->priv->header_has_focus = FALSE;
1010 tree_view->priv->pressed_button = -1;
1011 tree_view->priv->press_start_x = -1;
1012 tree_view->priv->press_start_y = -1;
1013 tree_view->priv->reorderable = FALSE;
1014 tree_view->priv->presize_handler_timer = 0;
1015 tree_view->priv->scroll_sync_timer = 0;
1016 tree_view->priv->fixed_height = -1;
1017 tree_view->priv->fixed_height_set = FALSE;
1018 pspp_sheet_view_set_adjustments (tree_view, NULL, NULL);
1019 tree_view->priv->selection = _pspp_sheet_selection_new_with_tree_view (tree_view);
1020 tree_view->priv->enable_search = TRUE;
1021 tree_view->priv->search_column = -1;
1022 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
1023 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
1024 tree_view->priv->search_custom_entry_set = FALSE;
1025 tree_view->priv->typeselect_flush_timeout = 0;
1026 tree_view->priv->init_hadjust_value = TRUE;
1027 tree_view->priv->width = 0;
1029 tree_view->priv->hover_selection = FALSE;
1031 tree_view->priv->rubber_banding_enable = FALSE;
1033 tree_view->priv->grid_lines = PSPP_SHEET_VIEW_GRID_LINES_NONE;
1035 tree_view->priv->tooltip_column = -1;
1037 tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT;
1039 tree_view->priv->post_validation_flag = FALSE;
1041 tree_view->priv->last_button_x = -1;
1042 tree_view->priv->last_button_y = -1;
1044 tree_view->priv->event_last_x = -10000;
1045 tree_view->priv->event_last_y = -10000;
1047 tree_view->priv->prelight_node = -1;
1048 tree_view->priv->rubber_band_start_node = -1;
1049 tree_view->priv->rubber_band_end_node = -1;
1051 tree_view->priv->anchor_column = NULL;
1053 tree_view->priv->button_style = NULL;
1062 pspp_sheet_view_set_property (GObject *object,
1064 const GValue *value,
1067 PsppSheetView *tree_view;
1069 tree_view = PSPP_SHEET_VIEW (object);
1074 pspp_sheet_view_set_model (tree_view, g_value_get_object (value));
1076 case PROP_HADJUSTMENT:
1077 pspp_sheet_view_set_hadjustment (tree_view, g_value_get_object (value));
1079 case PROP_VADJUSTMENT:
1080 pspp_sheet_view_set_vadjustment (tree_view, g_value_get_object (value));
1082 case PROP_HEADERS_VISIBLE:
1083 pspp_sheet_view_set_headers_visible (tree_view, g_value_get_boolean (value));
1085 case PROP_HEADERS_CLICKABLE:
1086 pspp_sheet_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
1088 case PROP_REORDERABLE:
1089 pspp_sheet_view_set_reorderable (tree_view, g_value_get_boolean (value));
1091 case PROP_RULES_HINT:
1092 pspp_sheet_view_set_rules_hint (tree_view, g_value_get_boolean (value));
1094 case PROP_ENABLE_SEARCH:
1095 pspp_sheet_view_set_enable_search (tree_view, g_value_get_boolean (value));
1097 case PROP_SEARCH_COLUMN:
1098 pspp_sheet_view_set_search_column (tree_view, g_value_get_int (value));
1100 case PROP_HOVER_SELECTION:
1101 tree_view->priv->hover_selection = g_value_get_boolean (value);
1103 case PROP_RUBBER_BANDING:
1104 tree_view->priv->rubber_banding_enable = g_value_get_boolean (value);
1106 case PROP_ENABLE_GRID_LINES:
1107 pspp_sheet_view_set_grid_lines (tree_view, g_value_get_enum (value));
1109 case PROP_TOOLTIP_COLUMN:
1110 pspp_sheet_view_set_tooltip_column (tree_view, g_value_get_int (value));
1112 case PROP_SPECIAL_CELLS:
1113 pspp_sheet_view_set_special_cells (tree_view, g_value_get_enum (value));
1115 case PROP_FIXED_HEIGHT:
1116 pspp_sheet_view_set_fixed_height (tree_view, g_value_get_int (value));
1118 case PROP_FIXED_HEIGHT_SET:
1119 if (g_value_get_boolean (value))
1121 if (!tree_view->priv->fixed_height_set
1122 && tree_view->priv->fixed_height >= 0)
1124 tree_view->priv->fixed_height_set = true;
1125 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1130 if (tree_view->priv->fixed_height_set)
1132 tree_view->priv->fixed_height_set = false;
1133 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1134 install_presize_handler (tree_view);
1139 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1145 pspp_sheet_view_get_property (GObject *object,
1150 PsppSheetView *tree_view;
1152 tree_view = PSPP_SHEET_VIEW (object);
1157 g_value_set_object (value, tree_view->priv->model);
1159 case PROP_HADJUSTMENT:
1160 g_value_set_object (value, tree_view->priv->hadjustment);
1162 case PROP_VADJUSTMENT:
1163 g_value_set_object (value, tree_view->priv->vadjustment);
1165 case PROP_HEADERS_VISIBLE:
1166 g_value_set_boolean (value, pspp_sheet_view_get_headers_visible (tree_view));
1168 case PROP_HEADERS_CLICKABLE:
1169 g_value_set_boolean (value, pspp_sheet_view_get_headers_clickable (tree_view));
1171 case PROP_REORDERABLE:
1172 g_value_set_boolean (value, tree_view->priv->reorderable);
1174 case PROP_RULES_HINT:
1175 g_value_set_boolean (value, tree_view->priv->has_rules);
1177 case PROP_ENABLE_SEARCH:
1178 g_value_set_boolean (value, tree_view->priv->enable_search);
1180 case PROP_SEARCH_COLUMN:
1181 g_value_set_int (value, tree_view->priv->search_column);
1183 case PROP_HOVER_SELECTION:
1184 g_value_set_boolean (value, tree_view->priv->hover_selection);
1186 case PROP_RUBBER_BANDING:
1187 g_value_set_boolean (value, tree_view->priv->rubber_banding_enable);
1189 case PROP_ENABLE_GRID_LINES:
1190 g_value_set_enum (value, tree_view->priv->grid_lines);
1192 case PROP_TOOLTIP_COLUMN:
1193 g_value_set_int (value, tree_view->priv->tooltip_column);
1195 case PROP_SPECIAL_CELLS:
1196 g_value_set_enum (value, tree_view->priv->special_cells);
1198 case PROP_FIXED_HEIGHT:
1199 g_value_set_int (value, pspp_sheet_view_get_fixed_height (tree_view));
1201 case PROP_FIXED_HEIGHT_SET:
1202 g_value_set_boolean (value, tree_view->priv->fixed_height_set);
1205 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1211 pspp_sheet_view_finalize (GObject *object)
1213 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->finalize (object);
1219 pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
1220 GtkBuilder *builder,
1224 pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), PSPP_SHEET_VIEW_COLUMN (child));
1227 /* GtkObject Methods
1231 pspp_sheet_view_destroy (GtkObject *object)
1233 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1236 pspp_sheet_view_stop_editing (tree_view, TRUE);
1238 if (tree_view->priv->selected != NULL)
1240 range_tower_destroy (tree_view->priv->selected);
1241 tree_view->priv->selected = NULL;
1244 if (tree_view->priv->columns != NULL)
1246 list = tree_view->priv->columns;
1249 PsppSheetViewColumn *column;
1250 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1252 pspp_sheet_view_remove_column (tree_view, column);
1254 tree_view->priv->columns = NULL;
1257 tree_view->priv->prelight_node = -1;
1259 if (tree_view->priv->selection != NULL)
1261 _pspp_sheet_selection_set_tree_view (tree_view->priv->selection, NULL);
1262 g_object_unref (tree_view->priv->selection);
1263 tree_view->priv->selection = NULL;
1266 if (tree_view->priv->scroll_to_path != NULL)
1268 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1269 tree_view->priv->scroll_to_path = NULL;
1272 if (tree_view->priv->drag_dest_row != NULL)
1274 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
1275 tree_view->priv->drag_dest_row = NULL;
1278 if (tree_view->priv->top_row != NULL)
1280 gtk_tree_row_reference_free (tree_view->priv->top_row);
1281 tree_view->priv->top_row = NULL;
1284 if (tree_view->priv->column_drop_func_data &&
1285 tree_view->priv->column_drop_func_data_destroy)
1287 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
1288 tree_view->priv->column_drop_func_data = NULL;
1291 if (tree_view->priv->destroy_count_destroy &&
1292 tree_view->priv->destroy_count_data)
1294 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
1295 tree_view->priv->destroy_count_data = NULL;
1298 gtk_tree_row_reference_free (tree_view->priv->cursor);
1299 tree_view->priv->cursor = NULL;
1301 gtk_tree_row_reference_free (tree_view->priv->anchor);
1302 tree_view->priv->anchor = NULL;
1304 /* destroy interactive search dialog */
1305 if (tree_view->priv->search_window)
1307 gtk_widget_destroy (tree_view->priv->search_window);
1308 tree_view->priv->search_window = NULL;
1309 tree_view->priv->search_entry = NULL;
1310 if (tree_view->priv->typeselect_flush_timeout)
1312 g_source_remove (tree_view->priv->typeselect_flush_timeout);
1313 tree_view->priv->typeselect_flush_timeout = 0;
1317 if (tree_view->priv->search_destroy && tree_view->priv->search_user_data)
1319 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
1320 tree_view->priv->search_user_data = NULL;
1323 if (tree_view->priv->search_position_destroy && tree_view->priv->search_position_user_data)
1325 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
1326 tree_view->priv->search_position_user_data = NULL;
1329 pspp_sheet_view_set_model (tree_view, NULL);
1331 if (tree_view->priv->hadjustment)
1333 g_object_unref (tree_view->priv->hadjustment);
1334 tree_view->priv->hadjustment = NULL;
1336 if (tree_view->priv->vadjustment)
1338 g_object_unref (tree_view->priv->vadjustment);
1339 tree_view->priv->vadjustment = NULL;
1342 if (tree_view->priv->button_style)
1344 g_object_unref (tree_view->priv->button_style);
1345 tree_view->priv->button_style = NULL;
1348 GTK_OBJECT_CLASS (pspp_sheet_view_parent_class)->destroy (object);
1353 /* GtkWidget Methods
1356 /* GtkWidget::map helper */
1358 pspp_sheet_view_map_buttons (PsppSheetView *tree_view)
1362 g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (tree_view)));
1364 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
1366 PsppSheetViewColumn *column;
1368 for (list = tree_view->priv->columns; list; list = list->next)
1370 column = list->data;
1371 if (column->button != NULL &&
1372 gtk_widget_get_visible (column->button) &&
1373 !gtk_widget_get_mapped (column->button))
1374 gtk_widget_map (column->button);
1376 for (list = tree_view->priv->columns; list; list = list->next)
1378 column = list->data;
1379 if (column->visible == FALSE || column->window == NULL)
1381 if (column->resizable)
1383 gdk_window_raise (column->window);
1384 gdk_window_show (column->window);
1387 gdk_window_hide (column->window);
1389 gdk_window_show (tree_view->priv->header_window);
1394 pspp_sheet_view_map (GtkWidget *widget)
1396 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1399 gtk_widget_set_mapped (widget, TRUE);
1401 tmp_list = tree_view->priv->children;
1404 PsppSheetViewChild *child = tmp_list->data;
1405 tmp_list = tmp_list->next;
1407 if (gtk_widget_get_visible (child->widget))
1409 if (!gtk_widget_get_mapped (child->widget))
1410 gtk_widget_map (child->widget);
1413 gdk_window_show (tree_view->priv->bin_window);
1415 pspp_sheet_view_map_buttons (tree_view);
1417 gdk_window_show (widget->window);
1421 pspp_sheet_view_realize (GtkWidget *widget)
1423 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1425 GdkWindowAttr attributes;
1426 gint attributes_mask;
1428 gtk_widget_set_realized (widget, TRUE);
1430 /* Make the main, clipping window */
1431 attributes.window_type = GDK_WINDOW_CHILD;
1432 attributes.x = widget->allocation.x;
1433 attributes.y = widget->allocation.y;
1434 attributes.width = widget->allocation.width;
1435 attributes.height = widget->allocation.height;
1436 attributes.wclass = GDK_INPUT_OUTPUT;
1437 attributes.visual = gtk_widget_get_visual (widget);
1438 attributes.colormap = gtk_widget_get_colormap (widget);
1439 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1441 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1443 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1444 &attributes, attributes_mask);
1445 gdk_window_set_user_data (widget->window, widget);
1447 /* Make the window for the tree */
1449 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1450 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1451 attributes.height = widget->allocation.height;
1452 attributes.event_mask = (GDK_EXPOSURE_MASK |
1454 GDK_POINTER_MOTION_MASK |
1455 GDK_ENTER_NOTIFY_MASK |
1456 GDK_LEAVE_NOTIFY_MASK |
1457 GDK_BUTTON_PRESS_MASK |
1458 GDK_BUTTON_RELEASE_MASK |
1459 gtk_widget_get_events (widget));
1461 tree_view->priv->bin_window = gdk_window_new (widget->window,
1462 &attributes, attributes_mask);
1463 gdk_window_set_user_data (tree_view->priv->bin_window, widget);
1465 /* Make the column header window */
1468 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1469 attributes.height = tree_view->priv->header_height;
1470 attributes.event_mask = (GDK_EXPOSURE_MASK |
1472 GDK_BUTTON_PRESS_MASK |
1473 GDK_BUTTON_RELEASE_MASK |
1474 GDK_KEY_PRESS_MASK |
1475 GDK_KEY_RELEASE_MASK |
1476 gtk_widget_get_events (widget));
1478 tree_view->priv->header_window = gdk_window_new (widget->window,
1479 &attributes, attributes_mask);
1480 gdk_window_set_user_data (tree_view->priv->header_window, widget);
1482 /* Add them all up. */
1483 widget->style = gtk_style_attach (widget->style, widget->window);
1484 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1485 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
1486 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
1488 tmp_list = tree_view->priv->children;
1491 PsppSheetViewChild *child = tmp_list->data;
1492 tmp_list = tmp_list->next;
1494 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1497 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1498 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1500 /* Need to call those here, since they create GCs */
1501 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1503 install_presize_handler (tree_view);
1507 pspp_sheet_view_unrealize (GtkWidget *widget)
1509 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1510 PsppSheetViewPrivate *priv = tree_view->priv;
1513 if (priv->scroll_timeout != 0)
1515 g_source_remove (priv->scroll_timeout);
1516 priv->scroll_timeout = 0;
1519 if (priv->open_dest_timeout != 0)
1521 g_source_remove (priv->open_dest_timeout);
1522 priv->open_dest_timeout = 0;
1525 if (priv->presize_handler_timer != 0)
1527 g_source_remove (priv->presize_handler_timer);
1528 priv->presize_handler_timer = 0;
1531 if (priv->validate_rows_timer != 0)
1533 g_source_remove (priv->validate_rows_timer);
1534 priv->validate_rows_timer = 0;
1537 if (priv->scroll_sync_timer != 0)
1539 g_source_remove (priv->scroll_sync_timer);
1540 priv->scroll_sync_timer = 0;
1543 if (priv->typeselect_flush_timeout)
1545 g_source_remove (priv->typeselect_flush_timeout);
1546 priv->typeselect_flush_timeout = 0;
1549 for (list = priv->columns; list; list = list->next)
1550 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1552 gdk_window_set_user_data (priv->bin_window, NULL);
1553 gdk_window_destroy (priv->bin_window);
1554 priv->bin_window = NULL;
1556 gdk_window_set_user_data (priv->header_window, NULL);
1557 gdk_window_destroy (priv->header_window);
1558 priv->header_window = NULL;
1560 if (priv->drag_window)
1562 gdk_window_set_user_data (priv->drag_window, NULL);
1563 gdk_window_destroy (priv->drag_window);
1564 priv->drag_window = NULL;
1567 if (priv->drag_highlight_window)
1569 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1570 gdk_window_destroy (priv->drag_highlight_window);
1571 priv->drag_highlight_window = NULL;
1574 if (priv->grid_line_gc)
1576 g_object_unref (priv->grid_line_gc);
1577 priv->grid_line_gc = NULL;
1580 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1583 /* GtkWidget::size_request helper */
1585 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1589 tree_view->priv->header_height = 0;
1591 if (tree_view->priv->model)
1593 for (list = tree_view->priv->columns; list; list = list->next)
1595 GtkRequisition requisition;
1596 PsppSheetViewColumn *column = list->data;
1598 pspp_sheet_view_column_size_request (column, &requisition);
1599 column->button_request = requisition.width;
1600 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1606 /* Called only by ::size_request */
1608 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1611 PsppSheetViewColumn *column;
1614 if (tree_view->priv->model == NULL)
1616 tree_view->priv->width = 0;
1617 tree_view->priv->prev_width = 0;
1618 tree_view->priv->height = 0;
1622 tree_view->priv->prev_width = tree_view->priv->width;
1623 tree_view->priv->width = 0;
1625 /* keep this in sync with size_allocate below */
1626 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1628 gint real_requested_width = 0;
1629 column = list->data;
1630 if (!column->visible)
1633 if (column->use_resized_width)
1635 real_requested_width = column->resized_width;
1639 real_requested_width = column->fixed_width;
1642 if (column->min_width != -1)
1643 real_requested_width = MAX (real_requested_width, column->min_width);
1644 if (column->max_width != -1)
1645 real_requested_width = MIN (real_requested_width, column->max_width);
1647 tree_view->priv->width += real_requested_width;
1650 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1654 pspp_sheet_view_size_request (GtkWidget *widget,
1655 GtkRequisition *requisition)
1657 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1660 /* we validate some rows initially just to make sure we have some size.
1661 * In practice, with a lot of static lists, this should get a good width.
1663 initialize_fixed_height_mode (tree_view);
1664 pspp_sheet_view_size_request_columns (tree_view);
1665 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1667 requisition->width = tree_view->priv->width;
1668 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1670 tmp_list = tree_view->priv->children;
1674 PsppSheetViewChild *child = tmp_list->data;
1675 GtkRequisition child_requisition;
1677 tmp_list = tmp_list->next;
1679 if (gtk_widget_get_visible (child->widget))
1680 gtk_widget_size_request (child->widget, &child_requisition);
1685 invalidate_column (PsppSheetView *tree_view,
1686 PsppSheetViewColumn *column)
1688 gint column_offset = 0;
1690 GtkWidget *widget = GTK_WIDGET (tree_view);
1693 if (!gtk_widget_get_realized (widget))
1696 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1697 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1699 list = (rtl ? list->prev : list->next))
1701 PsppSheetViewColumn *tmpcolumn = list->data;
1702 if (tmpcolumn == column)
1704 GdkRectangle invalid_rect;
1706 invalid_rect.x = column_offset;
1708 invalid_rect.width = column->width;
1709 invalid_rect.height = widget->allocation.height;
1711 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
1715 column_offset += tmpcolumn->width;
1720 invalidate_last_column (PsppSheetView *tree_view)
1725 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1727 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1729 last_column = (rtl ? last_column->next : last_column->prev))
1731 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1733 invalidate_column (tree_view, last_column->data);
1740 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1741 PsppSheetViewColumn *column)
1743 gint real_requested_width;
1745 if (column->use_resized_width)
1747 real_requested_width = column->resized_width;
1751 real_requested_width = column->fixed_width;
1754 if (column->min_width != -1)
1755 real_requested_width = MAX (real_requested_width, column->min_width);
1756 if (column->max_width != -1)
1757 real_requested_width = MIN (real_requested_width, column->max_width);
1759 return real_requested_width;
1763 span_intersects (int a0, int a_width,
1764 int b0, int b_width)
1766 int a1 = a0 + a_width;
1767 int b1 = b0 + b_width;
1768 return (a0 >= b0 && a0 < b1) || (b0 >= a0 && b0 < a1);
1771 /* GtkWidget::size_allocate helper */
1773 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1774 gboolean *width_changed)
1776 PsppSheetView *tree_view;
1777 GList *list, *first_column, *last_column;
1778 PsppSheetViewColumn *column;
1779 GtkAllocation allocation;
1781 gint extra, extra_per_column;
1782 gint full_requested_width = 0;
1783 gint number_of_expand_columns = 0;
1784 gboolean column_changed = FALSE;
1787 tree_view = PSPP_SHEET_VIEW (widget);
1789 for (last_column = g_list_last (tree_view->priv->columns);
1790 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1791 last_column = last_column->prev)
1793 if (last_column == NULL)
1796 for (first_column = g_list_first (tree_view->priv->columns);
1797 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1798 first_column = first_column->next)
1802 allocation.height = tree_view->priv->header_height;
1804 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1806 /* find out how many extra space and expandable columns we have */
1807 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1809 column = (PsppSheetViewColumn *)list->data;
1811 if (!column->visible)
1814 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1817 number_of_expand_columns++;
1820 extra = MAX (widget->allocation.width - full_requested_width, 0);
1821 if (number_of_expand_columns > 0)
1822 extra_per_column = extra/number_of_expand_columns;
1824 extra_per_column = 0;
1826 for (list = (rtl ? last_column : first_column);
1827 list != (rtl ? first_column->prev : last_column->next);
1828 list = (rtl ? list->prev : list->next))
1830 gint real_requested_width = 0;
1833 column = list->data;
1834 old_width = column->width;
1836 if (!column->visible)
1839 /* We need to handle the dragged button specially.
1841 if (column == tree_view->priv->drag_column)
1843 GtkAllocation drag_allocation;
1844 gdk_drawable_get_size (tree_view->priv->drag_window,
1845 &(drag_allocation.width),
1846 &(drag_allocation.height));
1847 drag_allocation.x = 0;
1848 drag_allocation.y = 0;
1849 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1851 width += drag_allocation.width;
1855 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1857 allocation.x = width;
1858 column->width = real_requested_width;
1862 if (number_of_expand_columns == 1)
1864 /* We add the remander to the last column as
1866 column->width += extra;
1870 column->width += extra_per_column;
1871 extra -= extra_per_column;
1872 number_of_expand_columns --;
1876 if (column->width != old_width)
1877 g_object_notify (G_OBJECT (column), "width");
1879 allocation.width = column->width;
1880 width += column->width;
1882 if (column->width > old_width)
1883 column_changed = TRUE;
1885 pspp_sheet_view_column_size_allocate (column, &allocation);
1887 if (span_intersects (allocation.x, allocation.width,
1888 tree_view->priv->hadjustment->value,
1889 widget->allocation.width)
1890 && gtk_widget_get_realized (widget))
1891 pspp_sheet_view_column_set_need_button (column, TRUE);
1894 gdk_window_move_resize (column->window,
1895 allocation.x + (rtl ? 0 : allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1897 TREE_VIEW_DRAG_WIDTH, allocation.height);
1900 /* We change the width here. The user might have been resizing columns,
1901 * so the total width of the tree view changes.
1903 tree_view->priv->width = width;
1905 *width_changed = TRUE;
1908 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
1913 pspp_sheet_view_size_allocate (GtkWidget *widget,
1914 GtkAllocation *allocation)
1916 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1918 gboolean width_changed = FALSE;
1919 gint old_width = widget->allocation.width;
1921 if (allocation->width != widget->allocation.width)
1922 width_changed = TRUE;
1924 widget->allocation = *allocation;
1926 tmp_list = tree_view->priv->children;
1930 GtkAllocation allocation;
1932 PsppSheetViewChild *child = tmp_list->data;
1933 tmp_list = tmp_list->next;
1935 /* totally ignore our child's requisition */
1936 allocation.x = child->x;
1937 allocation.y = child->y;
1938 allocation.width = child->width;
1939 allocation.height = child->height;
1940 gtk_widget_size_allocate (child->widget, &allocation);
1943 /* We size-allocate the columns first because the width of the
1944 * tree view (used in updating the adjustments below) might change.
1946 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
1948 tree_view->priv->hadjustment->page_size = allocation->width;
1949 tree_view->priv->hadjustment->page_increment = allocation->width * 0.9;
1950 tree_view->priv->hadjustment->step_increment = allocation->width * 0.1;
1951 tree_view->priv->hadjustment->lower = 0;
1952 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->page_size, tree_view->priv->width);
1954 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
1956 if (allocation->width < tree_view->priv->width)
1958 if (tree_view->priv->init_hadjust_value)
1960 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
1961 tree_view->priv->init_hadjust_value = FALSE;
1963 else if (allocation->width != old_width)
1965 tree_view->priv->hadjustment->value = CLAMP (tree_view->priv->hadjustment->value - allocation->width + old_width, 0, tree_view->priv->width - allocation->width);
1968 tree_view->priv->hadjustment->value = CLAMP (tree_view->priv->width - (tree_view->priv->prev_width - tree_view->priv->hadjustment->value), 0, tree_view->priv->width - allocation->width);
1972 tree_view->priv->hadjustment->value = 0;
1973 tree_view->priv->init_hadjust_value = TRUE;
1977 if (tree_view->priv->hadjustment->value + allocation->width > tree_view->priv->width)
1978 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
1980 gtk_adjustment_changed (tree_view->priv->hadjustment);
1982 tree_view->priv->vadjustment->page_size = allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view);
1983 tree_view->priv->vadjustment->step_increment = tree_view->priv->vadjustment->page_size * 0.1;
1984 tree_view->priv->vadjustment->page_increment = tree_view->priv->vadjustment->page_size * 0.9;
1985 tree_view->priv->vadjustment->lower = 0;
1986 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->page_size, tree_view->priv->height);
1988 gtk_adjustment_changed (tree_view->priv->vadjustment);
1990 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
1991 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
1992 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
1993 else if (tree_view->priv->vadjustment->value + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
1994 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
1995 tree_view->priv->height - tree_view->priv->vadjustment->page_size);
1996 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
1997 pspp_sheet_view_top_row_to_dy (tree_view);
1999 pspp_sheet_view_dy_to_top_row (tree_view);
2001 if (gtk_widget_get_realized (widget))
2003 gdk_window_move_resize (widget->window,
2004 allocation->x, allocation->y,
2005 allocation->width, allocation->height);
2006 gdk_window_move_resize (tree_view->priv->header_window,
2007 - (gint) tree_view->priv->hadjustment->value,
2009 MAX (tree_view->priv->width, allocation->width),
2010 tree_view->priv->header_height);
2011 gdk_window_move_resize (tree_view->priv->bin_window,
2012 - (gint) tree_view->priv->hadjustment->value,
2013 TREE_VIEW_HEADER_HEIGHT (tree_view),
2014 MAX (tree_view->priv->width, allocation->width),
2015 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2018 if (tree_view->priv->row_count == 0)
2019 invalidate_empty_focus (tree_view);
2021 if (gtk_widget_get_realized (widget))
2023 gboolean has_expand_column = FALSE;
2024 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2026 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2028 has_expand_column = TRUE;
2033 /* This little hack only works if we have an LTR locale, and no column has the */
2036 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2037 ! has_expand_column)
2038 invalidate_last_column (tree_view);
2040 gtk_widget_queue_draw (widget);
2045 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2047 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2049 GtkWidget *widget = GTK_WIDGET (tree_view);
2051 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2052 gtk_widget_grab_focus (widget);
2053 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2057 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2060 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2064 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2067 range_tower_set1 (tree_view->priv->selected, node, 1);
2071 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2074 range_tower_set0 (tree_view->priv->selected, node, 1);
2078 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2081 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2085 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2088 return node > 0 ? node - 1 : -1;
2092 all_columns_selected (PsppSheetView *tree_view)
2096 for (list = tree_view->priv->columns; list; list = list->next)
2098 PsppSheetViewColumn *column = list->data;
2099 if (column->selectable && !column->selected)
2107 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2109 PsppSheetViewColumn *column,
2110 GdkEventButton *event)
2112 PsppSheetSelection *selection;
2113 PsppSheetSelectionMode mode;
2115 gboolean update_anchor;
2119 g_return_val_if_fail (tree_view != NULL, FALSE);
2120 g_return_val_if_fail (column != NULL, FALSE);
2122 selection = tree_view->priv->selection;
2123 mode = pspp_sheet_selection_get_mode (selection);
2124 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2127 if (!column->row_head)
2132 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2133 if (event->type != GDK_BUTTON_PRESS
2134 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2140 path = gtk_tree_path_new_from_indices (node, -1);
2143 pspp_sheet_selection_unselect_all (selection);
2144 pspp_sheet_selection_select_path (selection, path);
2145 pspp_sheet_selection_select_all_columns (selection);
2146 update_anchor = TRUE;
2149 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2151 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2152 || !all_columns_selected (tree_view))
2154 pspp_sheet_selection_unselect_all (selection);
2155 pspp_sheet_selection_select_path (selection, path);
2156 pspp_sheet_selection_select_all_columns (selection);
2157 update_anchor = TRUE;
2161 update_anchor = handled = FALSE;
2163 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2164 && modifiers == GDK_CONTROL_MASK)
2166 if (!all_columns_selected (tree_view))
2168 pspp_sheet_selection_unselect_all (selection);
2169 pspp_sheet_selection_select_all_columns (selection);
2172 if (pspp_sheet_selection_path_is_selected (selection, path))
2173 pspp_sheet_selection_unselect_path (selection, path);
2175 pspp_sheet_selection_select_path (selection, path);
2176 update_anchor = TRUE;
2179 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2180 && modifiers == GDK_SHIFT_MASK)
2182 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2183 GtkTreePath *anchor_path;
2185 if (all_columns_selected (tree_view)
2186 && gtk_tree_row_reference_valid (anchor))
2188 update_anchor = FALSE;
2189 anchor_path = gtk_tree_row_reference_get_path (anchor);
2193 update_anchor = TRUE;
2194 anchor_path = gtk_tree_path_copy (path);
2197 pspp_sheet_selection_unselect_all (selection);
2198 pspp_sheet_selection_select_range (selection, anchor_path, path);
2199 pspp_sheet_selection_select_all_columns (selection);
2201 gtk_tree_path_free (anchor_path);
2206 update_anchor = handled = FALSE;
2210 if (tree_view->priv->anchor)
2211 gtk_tree_row_reference_free (tree_view->priv->anchor);
2212 tree_view->priv->anchor =
2213 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2214 tree_view->priv->model,
2218 gtk_tree_path_free (path);
2223 find_click (PsppSheetView *tree_view,
2226 PsppSheetViewColumn **column,
2227 GdkRectangle *background_area,
2228 GdkRectangle *cell_area)
2235 /* find the node that was clicked */
2236 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2239 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2244 background_area->y = y_offset + y;
2245 background_area->height = ROW_HEIGHT (tree_view);
2246 background_area->x = 0;
2248 /* Let the column have a chance at selecting it. */
2249 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2250 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2251 list; list = (rtl ? list->prev : list->next))
2253 PsppSheetViewColumn *candidate = list->data;
2255 if (!candidate->visible)
2258 background_area->width = candidate->width;
2259 if ((background_area->x > x) ||
2260 (background_area->x + background_area->width <= x))
2262 background_area->x += background_area->width;
2266 /* we found the focus column */
2268 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2270 *column = candidate;
2278 pspp_sheet_view_button_press (GtkWidget *widget,
2279 GdkEventButton *event)
2281 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2283 PsppSheetViewColumn *column = NULL;
2285 GdkRectangle background_area;
2286 GdkRectangle cell_area;
2289 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2290 pspp_sheet_view_stop_editing (tree_view, FALSE);
2293 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2294 * we're done handling the button press.
2297 if (event->window == tree_view->priv->bin_window)
2302 gint pre_val, aft_val;
2303 PsppSheetViewColumn *column = NULL;
2304 GtkCellRenderer *focus_cell = NULL;
2305 gboolean row_double_click = FALSE;
2308 if (tree_view->priv->row_count == 0)
2310 grab_focus_and_unset_draw_keyfocus (tree_view);
2314 if (!find_click (tree_view, event->x, event->y, &node, &column,
2315 &background_area, &cell_area))
2317 grab_focus_and_unset_draw_keyfocus (tree_view);
2321 tree_view->priv->focus_column = column;
2323 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2327 pre_val = tree_view->priv->vadjustment->value;
2329 path = _pspp_sheet_view_find_path (tree_view, node);
2331 /* we only handle selection modifications on the first button press
2333 if (event->type == GDK_BUTTON_PRESS)
2335 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2336 tree_view->priv->ctrl_pressed = TRUE;
2337 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2338 tree_view->priv->shift_pressed = TRUE;
2340 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2342 pspp_sheet_view_column_focus_cell (column, focus_cell);
2344 if (event->state & GDK_CONTROL_MASK)
2346 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
2347 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2349 else if (event->state & GDK_SHIFT_MASK)
2351 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
2352 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE);
2356 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
2359 if (tree_view->priv->anchor_column == NULL ||
2360 !(event->state & GDK_SHIFT_MASK))
2361 tree_view->priv->anchor_column = column;
2362 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2363 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2364 tree_view->priv->anchor_column,
2367 tree_view->priv->ctrl_pressed = FALSE;
2368 tree_view->priv->shift_pressed = FALSE;
2371 /* the treeview may have been scrolled because of _set_cursor,
2375 aft_val = tree_view->priv->vadjustment->value;
2376 dval = pre_val - aft_val;
2378 cell_area.y += dval;
2379 background_area.y += dval;
2381 /* Save press to possibly begin a drag
2383 if (!tree_view->priv->in_grab &&
2384 tree_view->priv->pressed_button < 0)
2386 tree_view->priv->pressed_button = event->button;
2387 tree_view->priv->press_start_x = event->x;
2388 tree_view->priv->press_start_y = event->y;
2389 tree_view->priv->press_start_node = node;
2391 if (tree_view->priv->rubber_banding_enable
2392 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2393 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2395 tree_view->priv->press_start_y += tree_view->priv->dy;
2396 tree_view->priv->rubber_band_x = event->x;
2397 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2398 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2400 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2401 tree_view->priv->rubber_band_ctrl = TRUE;
2402 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2403 tree_view->priv->rubber_band_shift = TRUE;
2408 /* Test if a double click happened on the same row. */
2409 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2411 int double_click_time, double_click_distance;
2413 g_object_get (gtk_settings_get_for_screen (
2414 gtk_widget_get_screen (widget)),
2415 "gtk-double-click-time", &double_click_time,
2416 "gtk-double-click-distance", &double_click_distance,
2419 /* Same conditions as _gdk_event_button_generate */
2420 if (tree_view->priv->last_button_x != -1 &&
2421 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2422 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2423 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2425 /* We do no longer compare paths of this row and the
2426 * row clicked previously. We use the double click
2427 * distance to decide whether this is a valid click,
2428 * allowing the mouse to slightly move over another row.
2430 row_double_click = TRUE;
2432 tree_view->priv->last_button_time = 0;
2433 tree_view->priv->last_button_x = -1;
2434 tree_view->priv->last_button_y = -1;
2438 tree_view->priv->last_button_time = event->time;
2439 tree_view->priv->last_button_x = event->x;
2440 tree_view->priv->last_button_y = event->y;
2444 if (row_double_click)
2446 gtk_grab_remove (widget);
2447 pspp_sheet_view_row_activated (tree_view, path, column);
2449 if (tree_view->priv->pressed_button == event->button)
2450 tree_view->priv->pressed_button = -1;
2453 gtk_tree_path_free (path);
2455 /* If we activated the row through a double click we don't want to grab
2456 * focus back, as moving focus to another widget is pretty common.
2458 if (!row_double_click)
2459 grab_focus_and_unset_draw_keyfocus (tree_view);
2464 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2466 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2468 column = list->data;
2469 if (event->window == column->window &&
2470 column->resizable &&
2475 if (gdk_pointer_grab (column->window, FALSE,
2476 GDK_POINTER_MOTION_HINT_MASK |
2477 GDK_BUTTON1_MOTION_MASK |
2478 GDK_BUTTON_RELEASE_MASK,
2479 NULL, NULL, event->time))
2482 gtk_grab_add (widget);
2483 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2484 column->resized_width = column->width;
2486 /* block attached dnd signal handler */
2487 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2489 g_signal_handlers_block_matched (widget,
2490 G_SIGNAL_MATCH_DATA,
2494 tree_view->priv->drag_pos = i;
2495 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2497 if (!gtk_widget_has_focus (widget))
2498 gtk_widget_grab_focus (widget);
2506 /* GtkWidget::button_release_event helper */
2508 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2509 GdkEventButton *event)
2511 PsppSheetView *tree_view;
2515 tree_view = PSPP_SHEET_VIEW (widget);
2517 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2518 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2519 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2521 /* Move the button back */
2522 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2524 g_object_ref (tree_view->priv->drag_column->button);
2525 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2526 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2527 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2528 g_object_unref (tree_view->priv->drag_column->button);
2529 gtk_widget_queue_resize (widget);
2530 if (tree_view->priv->drag_column->resizable)
2532 gdk_window_raise (tree_view->priv->drag_column->window);
2533 gdk_window_show (tree_view->priv->drag_column->window);
2536 gdk_window_hide (tree_view->priv->drag_column->window);
2538 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2542 if (tree_view->priv->cur_reorder &&
2543 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2544 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2545 tree_view->priv->cur_reorder->right_column);
2549 if (tree_view->priv->cur_reorder &&
2550 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2551 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2552 tree_view->priv->cur_reorder->left_column);
2554 tree_view->priv->drag_column = NULL;
2555 gdk_window_hide (tree_view->priv->drag_window);
2557 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2558 g_slice_free (PsppSheetViewColumnReorder, l->data);
2559 g_list_free (tree_view->priv->column_drag_info);
2560 tree_view->priv->column_drag_info = NULL;
2561 tree_view->priv->cur_reorder = NULL;
2563 if (tree_view->priv->drag_highlight_window)
2564 gdk_window_hide (tree_view->priv->drag_highlight_window);
2566 /* Reset our flags */
2567 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2568 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2573 /* GtkWidget::button_release_event helper */
2575 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2576 GdkEventButton *event)
2578 PsppSheetView *tree_view;
2581 tree_view = PSPP_SHEET_VIEW (widget);
2583 tree_view->priv->drag_pos = -1;
2585 /* unblock attached dnd signal handler */
2586 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2588 g_signal_handlers_unblock_matched (widget,
2589 G_SIGNAL_MATCH_DATA,
2593 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2594 gtk_grab_remove (widget);
2595 gdk_display_pointer_ungrab (gdk_drawable_get_display (event->window),
2601 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2602 GdkEventButton *event)
2604 GtkCellEditable *cell_editable;
2609 PsppSheetViewColumn *column;
2610 GdkRectangle background_area;
2611 GdkRectangle cell_area;
2617 if (event->window != tree_view->priv->bin_window)
2620 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2624 /* decide if we edit */
2625 path = _pspp_sheet_view_find_path (tree_view, node);
2626 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2627 if (event->button != 1 || modifiers)
2630 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2631 pspp_sheet_view_column_cell_set_cell_data (column,
2632 tree_view->priv->model,
2635 if (!pspp_sheet_view_column_get_quick_edit (column)
2636 && _pspp_sheet_view_column_has_editable_cell (column))
2639 flags = 0; /* FIXME: get the right flags */
2640 path_string = gtk_tree_path_to_string (path);
2642 if (!_pspp_sheet_view_column_cell_event (column,
2650 if (cell_editable == NULL)
2653 pspp_sheet_view_real_set_cursor (tree_view, path,
2655 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2658 _pspp_sheet_view_column_get_neighbor_sizes (
2659 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2662 area.width -= right + left;
2664 pspp_sheet_view_real_start_editing (tree_view,
2671 g_free (path_string);
2672 gtk_tree_path_free (path);
2677 pspp_sheet_view_button_release (GtkWidget *widget,
2678 GdkEventButton *event)
2680 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2682 pspp_sheet_view_stop_editing (tree_view, FALSE);
2683 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2684 && pspp_sheet_view_button_release_edit (tree_view, event))
2686 if (tree_view->priv->pressed_button == event->button)
2687 tree_view->priv->pressed_button = -1;
2689 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2693 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2694 return pspp_sheet_view_button_release_drag_column (widget, event);
2696 if (tree_view->priv->rubber_band_status)
2697 pspp_sheet_view_stop_rubber_band (tree_view);
2699 if (tree_view->priv->pressed_button == event->button)
2700 tree_view->priv->pressed_button = -1;
2702 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2703 return pspp_sheet_view_button_release_column_resize (widget, event);
2709 pspp_sheet_view_grab_broken (GtkWidget *widget,
2710 GdkEventGrabBroken *event)
2712 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2714 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2715 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2717 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2718 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2723 /* GtkWidget::motion_event function set.
2727 do_prelight (PsppSheetView *tree_view,
2729 /* these are in bin_window coords */
2733 int prev_node = tree_view->priv->prelight_node;
2735 if (prev_node != node)
2737 tree_view->priv->prelight_node = node;
2740 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2743 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2748 prelight_or_select (PsppSheetView *tree_view,
2750 /* these are in bin_window coords */
2754 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2756 if (tree_view->priv->hover_selection &&
2757 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2758 !(tree_view->priv->edited_column &&
2759 tree_view->priv->edited_column->editable_widget))
2763 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2767 path = _pspp_sheet_view_find_path (tree_view, node);
2768 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2769 if (pspp_sheet_view_node_is_selected (tree_view, node))
2771 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2772 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE);
2774 gtk_tree_path_free (path);
2778 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2779 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2782 do_prelight (tree_view, node, x, y);
2786 ensure_unprelighted (PsppSheetView *tree_view)
2788 do_prelight (tree_view,
2790 -1000, -1000); /* coords not possibly over an arrow */
2792 g_assert (tree_view->priv->prelight_node < 0);
2796 update_prelight (PsppSheetView *tree_view,
2803 if (tree_view->priv->row_count == 0)
2808 ensure_unprelighted (tree_view);
2812 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2816 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2819 prelight_or_select (tree_view, node, x, y);
2825 /* Our motion arrow is either a box (in the case of the original spot)
2826 * or an arrow. It is expander_size wide.
2849 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2851 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2852 GtkWidget *widget = GTK_WIDGET (tree_view);
2853 GdkBitmap *mask = NULL;
2858 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2859 GdkWindowAttr attributes;
2860 guint attributes_mask;
2863 reorder->left_column == tree_view->priv->drag_column ||
2864 reorder->right_column == tree_view->priv->drag_column)
2865 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2866 else if (reorder->left_column || reorder->right_column)
2868 GdkRectangle visible_rect;
2869 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2870 if (reorder->left_column)
2871 x = reorder->left_column->allocation.x + reorder->left_column->allocation.width;
2873 x = reorder->right_column->allocation.x;
2875 if (x < visible_rect.x)
2876 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2877 else if (x > visible_rect.x + visible_rect.width)
2878 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2880 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2883 /* We want to draw the rectangle over the initial location. */
2884 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2889 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2891 if (tree_view->priv->drag_highlight_window)
2893 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2895 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2898 attributes.window_type = GDK_WINDOW_CHILD;
2899 attributes.wclass = GDK_INPUT_OUTPUT;
2900 attributes.x = tree_view->priv->drag_column_x;
2902 width = attributes.width = tree_view->priv->drag_column->allocation.width;
2903 height = attributes.height = tree_view->priv->drag_column->allocation.height;
2904 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2905 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2906 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2907 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2908 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
2909 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2911 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2912 gc = gdk_gc_new (mask);
2914 gdk_gc_set_foreground (gc, &col);
2915 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2917 gdk_gc_set_foreground(gc, &col);
2918 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
2919 g_object_unref (gc);
2921 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
2923 if (mask) g_object_unref (mask);
2924 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2927 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
2933 width = tree_view->priv->expander_size;
2935 /* Get x, y, width, height of arrow */
2936 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
2937 if (reorder->left_column)
2939 x += reorder->left_column->allocation.x + reorder->left_column->allocation.width - width/2;
2940 height = reorder->left_column->allocation.height;
2944 x += reorder->right_column->allocation.x - width/2;
2945 height = reorder->right_column->allocation.height;
2947 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
2948 height += tree_view->priv->expander_size;
2950 /* Create the new window */
2951 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
2953 if (tree_view->priv->drag_highlight_window)
2955 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2957 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2960 attributes.window_type = GDK_WINDOW_TEMP;
2961 attributes.wclass = GDK_INPUT_OUTPUT;
2962 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2963 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2964 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2965 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2968 attributes.width = width;
2969 attributes.height = height;
2970 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
2971 &attributes, attributes_mask);
2972 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2974 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2975 gc = gdk_gc_new (mask);
2977 gdk_gc_set_foreground (gc, &col);
2978 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2980 /* Draw the 2 arrows as per above */
2982 gdk_gc_set_foreground (gc, &col);
2983 for (i = 0; i < width; i ++)
2985 if (i == (width/2 - 1))
2987 gdk_draw_line (mask, gc, i, j, i, height - j);
2988 if (i < (width/2 - 1))
2993 g_object_unref (gc);
2994 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
2996 if (mask) g_object_unref (mask);
2999 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
3000 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3002 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
3003 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3009 width = tree_view->priv->expander_size;
3011 /* Get x, y, width, height of arrow */
3012 width = width/2; /* remember, the arrow only takes half the available width */
3013 gdk_window_get_origin (widget->window, &x, &y);
3014 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3015 x += widget->allocation.width - width;
3017 if (reorder->left_column)
3018 height = reorder->left_column->allocation.height;
3020 height = reorder->right_column->allocation.height;
3022 y -= tree_view->priv->expander_size;
3023 height += 2*tree_view->priv->expander_size;
3025 /* Create the new window */
3026 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
3027 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3029 if (tree_view->priv->drag_highlight_window)
3031 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3033 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3036 attributes.window_type = GDK_WINDOW_TEMP;
3037 attributes.wclass = GDK_INPUT_OUTPUT;
3038 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3039 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3040 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3041 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3044 attributes.width = width;
3045 attributes.height = height;
3046 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3047 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3049 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3050 gc = gdk_gc_new (mask);
3052 gdk_gc_set_foreground (gc, &col);
3053 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3055 /* Draw the 2 arrows as per above */
3057 gdk_gc_set_foreground (gc, &col);
3058 j = tree_view->priv->expander_size;
3059 for (i = 0; i < width; i ++)
3062 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3066 gdk_draw_line (mask, gc, k, j, k, height - j);
3067 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3068 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3071 g_object_unref (gc);
3072 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3074 if (mask) g_object_unref (mask);
3077 tree_view->priv->drag_column_window_state = arrow_type;
3078 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3082 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3083 gdk_window_hide (tree_view->priv->drag_highlight_window);
3087 gdk_window_show (tree_view->priv->drag_highlight_window);
3088 gdk_window_raise (tree_view->priv->drag_highlight_window);
3092 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3093 GdkEventMotion *event)
3097 PsppSheetViewColumn *column;
3098 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3100 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3102 if (event->is_hint || event->window != widget->window)
3103 gtk_widget_get_pointer (widget, &x, NULL);
3107 if (tree_view->priv->hadjustment)
3108 x += tree_view->priv->hadjustment->value;
3110 new_width = pspp_sheet_view_new_column_width (tree_view,
3111 tree_view->priv->drag_pos, &x);
3112 if (x != tree_view->priv->x_drag &&
3113 (new_width != column->fixed_width))
3115 column->use_resized_width = TRUE;
3116 column->resized_width = new_width;
3119 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3121 gtk_widget_queue_resize (widget);
3129 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3131 PsppSheetViewColumnReorder *reorder = NULL;
3135 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3136 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3138 reorder = (PsppSheetViewColumnReorder *) list->data;
3139 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3144 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3147 tree_view->priv->cur_reorder = reorder;
3148 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3152 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3154 GdkRectangle visible_rect;
3159 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3160 y += tree_view->priv->dy;
3162 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3164 /* see if we are near the edge. */
3165 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3168 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3173 value = CLAMP (tree_view->priv->vadjustment->value + offset, 0.0,
3174 tree_view->priv->vadjustment->upper - tree_view->priv->vadjustment->page_size);
3175 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3179 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3181 GdkRectangle visible_rect;
3186 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3188 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3190 /* See if we are near the edge. */
3191 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3194 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3200 value = CLAMP (tree_view->priv->hadjustment->value + offset,
3201 0.0, tree_view->priv->hadjustment->upper - tree_view->priv->hadjustment->page_size);
3202 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3209 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3210 GdkEventMotion *event)
3212 PsppSheetView *tree_view = (PsppSheetView *) widget;
3213 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3217 if ((column == NULL) ||
3218 (event->window != tree_view->priv->drag_window))
3221 /* Handle moving the header */
3222 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3223 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3224 MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width) - column->allocation.width);
3225 gdk_window_move (tree_view->priv->drag_window, x, y);
3227 /* autoscroll, if needed */
3228 pspp_sheet_view_horizontal_autoscroll (tree_view);
3229 /* Update the current reorder position and arrow; */
3230 pspp_sheet_view_update_current_reorder (tree_view);
3236 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3238 remove_scroll_timeout (tree_view);
3239 gtk_grab_remove (GTK_WIDGET (tree_view));
3241 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3243 GtkTreePath *tmp_path;
3245 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3247 /* The anchor path should be set to the start path */
3248 tmp_path = _pspp_sheet_view_find_path (tree_view,
3249 tree_view->priv->rubber_band_start_node);
3251 if (tree_view->priv->anchor)
3252 gtk_tree_row_reference_free (tree_view->priv->anchor);
3254 tree_view->priv->anchor =
3255 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3256 tree_view->priv->model,
3259 gtk_tree_path_free (tmp_path);
3261 /* ... and the cursor to the end path */
3262 tmp_path = _pspp_sheet_view_find_path (tree_view,
3263 tree_view->priv->rubber_band_end_node);
3264 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE);
3265 gtk_tree_path_free (tmp_path);
3267 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3270 /* Clear status variables */
3271 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3272 tree_view->priv->rubber_band_shift = 0;
3273 tree_view->priv->rubber_band_ctrl = 0;
3275 tree_view->priv->rubber_band_start_node = -1;
3276 tree_view->priv->rubber_band_end_node = -1;
3280 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3284 gboolean skip_start,
3287 if (start_node == end_node)
3290 /* We skip the first node and jump inside the loop */
3296 /* Small optimization by assuming insensitive nodes are never
3301 if (tree_view->priv->rubber_band_shift)
3302 pspp_sheet_view_node_select (tree_view, start_node);
3303 else if (tree_view->priv->rubber_band_ctrl)
3305 /* Toggle the selection state */
3306 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3307 pspp_sheet_view_node_unselect (tree_view, start_node);
3309 pspp_sheet_view_node_select (tree_view, start_node);
3312 pspp_sheet_view_node_select (tree_view, start_node);
3316 /* Mirror the above */
3317 if (tree_view->priv->rubber_band_shift)
3318 pspp_sheet_view_node_unselect (tree_view, start_node);
3319 else if (tree_view->priv->rubber_band_ctrl)
3321 /* Toggle the selection state */
3322 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3323 pspp_sheet_view_node_unselect (tree_view, start_node);
3325 pspp_sheet_view_node_select (tree_view, start_node);
3328 pspp_sheet_view_node_unselect (tree_view, start_node);
3331 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3333 if (start_node == end_node)
3338 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3341 /* Ran out of tree */
3344 if (skip_end && start_node == end_node)
3351 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3354 return node * tree_view->priv->fixed_height;
3358 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3362 int fixed_height = tree_view->priv->fixed_height;
3363 if (fixed_height <= 0
3365 || height >= tree_view->priv->row_count * fixed_height)
3372 *new_node = height / fixed_height;
3373 return height % fixed_height;
3378 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3383 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3384 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3386 /* Handle the start area first */
3387 if (tree_view->priv->rubber_band_start_node < 0)
3389 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3396 else if (start_node < tree_view->priv->rubber_band_start_node)
3398 /* New node is above the old one; selection became bigger */
3399 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3401 tree_view->priv->rubber_band_start_node,
3406 else if (start_node > tree_view->priv->rubber_band_start_node)
3408 /* New node is below the old one; selection became smaller */
3409 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3410 tree_view->priv->rubber_band_start_node,
3417 tree_view->priv->rubber_band_start_node = start_node;
3419 /* Next, handle the end area */
3420 if (tree_view->priv->rubber_band_end_node < 0)
3422 /* In the event this happens, start_node was also -1; this case is
3426 else if (end_node < 0)
3428 /* Find the last node in the tree */
3429 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3432 /* Selection reached end of the tree */
3433 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3434 tree_view->priv->rubber_band_end_node,
3440 else if (end_node > tree_view->priv->rubber_band_end_node)
3442 /* New node is below the old one; selection became bigger */
3443 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3444 tree_view->priv->rubber_band_end_node,
3450 else if (end_node < tree_view->priv->rubber_band_end_node)
3452 /* New node is above the old one; selection became smaller */
3453 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3455 tree_view->priv->rubber_band_end_node,
3461 tree_view->priv->rubber_band_end_node = end_node;
3465 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3468 GdkRectangle old_area;
3469 GdkRectangle new_area;
3470 GdkRectangle common;
3471 GdkRegion *invalid_region;
3472 PsppSheetViewColumn *column;
3474 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3475 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3476 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3477 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3479 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3482 y = MAX (y, 0) + tree_view->priv->dy;
3484 new_area.x = MIN (tree_view->priv->press_start_x, x);
3485 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3486 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3487 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3489 invalid_region = gdk_region_rectangle (&old_area);
3490 gdk_region_union_with_rect (invalid_region, &new_area);
3492 gdk_rectangle_intersect (&old_area, &new_area, &common);
3493 if (common.width > 2 && common.height > 2)
3495 GdkRegion *common_region;
3497 /* make sure the border is invalidated */
3503 common_region = gdk_region_rectangle (&common);
3505 gdk_region_subtract (invalid_region, common_region);
3506 gdk_region_destroy (common_region);
3509 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3511 gdk_region_destroy (invalid_region);
3513 tree_view->priv->rubber_band_x = x;
3514 tree_view->priv->rubber_band_y = y;
3515 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3517 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3518 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3519 tree_view->priv->anchor_column,
3522 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3524 pspp_sheet_view_update_rubber_band_selection (tree_view);
3528 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3533 GdkRectangle rubber_rect;
3536 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3537 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3538 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3539 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3541 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3544 cr = gdk_cairo_create (tree_view->priv->bin_window);
3545 cairo_set_line_width (cr, 1.0);
3547 cairo_set_source_rgba (cr,
3548 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3549 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3550 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.,
3553 gdk_cairo_rectangle (cr, &rect);
3557 cairo_set_source_rgb (cr,
3558 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3559 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3560 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.);
3562 cairo_rectangle (cr,
3563 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3564 rubber_rect.width - 1, rubber_rect.height - 1);
3571 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3572 GdkEventMotion *event)
3574 PsppSheetView *tree_view;
3578 tree_view = (PsppSheetView *) widget;
3580 if (tree_view->priv->row_count == 0)
3583 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3585 GdkRectangle background_area, cell_area;
3586 PsppSheetViewColumn *column;
3588 if (find_click (tree_view, event->x, event->y, &node, &column,
3589 &background_area, &cell_area)
3590 && tree_view->priv->focus_column == column
3591 && tree_view->priv->press_start_node == node)
3594 gtk_grab_add (GTK_WIDGET (tree_view));
3595 pspp_sheet_view_update_rubber_band (tree_view);
3597 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3599 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3601 pspp_sheet_view_update_rubber_band (tree_view);
3603 add_scroll_timeout (tree_view);
3606 /* only check for an initiated drag when a button is pressed */
3607 if (tree_view->priv->pressed_button >= 0
3608 && !tree_view->priv->rubber_band_status)
3609 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3611 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3615 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3617 tree_view->priv->event_last_x = event->x;
3618 tree_view->priv->event_last_y = event->y;
3620 prelight_or_select (tree_view, node, event->x, event->y);
3626 pspp_sheet_view_motion (GtkWidget *widget,
3627 GdkEventMotion *event)
3629 PsppSheetView *tree_view;
3631 tree_view = (PsppSheetView *) widget;
3633 /* Resizing a column */
3634 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3635 return pspp_sheet_view_motion_resize_column (widget, event);
3638 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3639 return pspp_sheet_view_motion_drag_column (widget, event);
3641 /* Sanity check it */
3642 if (event->window == tree_view->priv->bin_window)
3643 return pspp_sheet_view_motion_bin_window (widget, event);
3648 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3649 * the tree is empty.
3652 invalidate_empty_focus (PsppSheetView *tree_view)
3656 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3661 gdk_drawable_get_size (tree_view->priv->bin_window, &area.width, &area.height);
3662 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3665 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3669 draw_empty_focus (PsppSheetView *tree_view, GdkRectangle *clip_area)
3671 GtkWidget *widget = GTK_WIDGET (tree_view);
3674 if (!gtk_widget_has_focus (widget))
3677 gdk_drawable_get_size (tree_view->priv->bin_window, &w, &h);
3683 gtk_paint_focus (gtk_widget_get_style (widget),
3684 tree_view->priv->bin_window,
3685 gtk_widget_get_state (widget),
3693 pspp_sheet_view_draw_grid_lines (PsppSheetView *tree_view,
3694 GdkEventExpose *event,
3695 gint n_visible_columns,
3699 GList *list = tree_view->priv->columns;
3704 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3705 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3708 gdk_drawable_get_size (event->window, NULL, &height);
3710 /* Only draw the lines for visible rows and columns */
3711 for (list = tree_view->priv->columns; list; list = list->next, i++)
3713 PsppSheetViewColumn *column = list->data;
3715 /* We don't want a line for the last column */
3716 if (i == n_visible_columns - 1)
3719 if (! column->visible)
3722 current_x += column->width;
3724 if (current_x - 1 >= event->area.x
3725 && current_x - 1 < event->area.x + event->area.width)
3726 gdk_draw_line (event->window,
3727 tree_view->priv->grid_line_gc,
3728 current_x - 1, min_y,
3729 current_x - 1, max_y - min_y);
3733 /* Warning: Very scary function.
3734 * Modify at your own risk
3736 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3737 * FIXME: It's not...
3740 pspp_sheet_view_bin_expose (GtkWidget *widget,
3741 GdkEventExpose *event)
3743 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3748 int drag_highlight = -1;
3751 gint y_offset, cell_offset;
3753 GdkRectangle background_area;
3754 GdkRectangle cell_area;
3756 gint bin_window_width;
3757 gint bin_window_height;
3758 GtkTreePath *cursor_path;
3759 GtkTreePath *drag_dest_path;
3760 GList *first_column, *last_column;
3761 gint vertical_separator;
3762 gint horizontal_separator;
3763 gint focus_line_width;
3764 gboolean allow_rules;
3765 gboolean has_special_cell;
3767 gint n_visible_columns;
3768 gint grid_line_width;
3769 gboolean row_ending_details;
3770 gboolean draw_vgrid_lines, draw_hgrid_lines;
3773 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3775 gtk_widget_style_get (widget,
3776 "horizontal-separator", &horizontal_separator,
3777 "vertical-separator", &vertical_separator,
3778 "allow-rules", &allow_rules,
3779 "focus-line-width", &focus_line_width,
3780 "row-ending-details", &row_ending_details,
3783 if (tree_view->priv->row_count == 0)
3785 draw_empty_focus (tree_view, &event->area);
3789 /* clip event->area to the visible area */
3790 if (event->area.height < 0)
3793 validate_visible_area (tree_view);
3795 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, event->area.y);
3799 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3800 gdk_drawable_get_size (tree_view->priv->bin_window,
3801 &bin_window_width, &bin_window_height);
3803 if (tree_view->priv->height < bin_window_height)
3805 gtk_paint_flat_box (widget->style,
3812 0, tree_view->priv->height,
3814 bin_window_height - tree_view->priv->height);
3820 /* find the path for the node */
3821 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3822 gtk_tree_model_get_iter (tree_view->priv->model,
3825 gtk_tree_path_free (path);
3828 drag_dest_path = NULL;
3830 if (tree_view->priv->cursor)
3831 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3834 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3836 if (tree_view->priv->drag_dest_row)
3837 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3840 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3844 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3845 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3847 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3848 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3850 if (draw_vgrid_lines || draw_hgrid_lines)
3851 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3853 n_visible_columns = 0;
3854 for (list = tree_view->priv->columns; list; list = list->next)
3856 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3858 n_visible_columns ++;
3861 /* Find the last column */
3862 for (last_column = g_list_last (tree_view->priv->columns);
3863 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
3864 last_column = last_column->prev)
3868 for (first_column = g_list_first (tree_view->priv->columns);
3869 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
3870 first_column = first_column->next)
3873 /* Actually process the expose event. To do this, we want to
3874 * start at the first node of the event, and walk the tree in
3875 * order, drawing each successive node.
3882 gboolean is_first = FALSE;
3883 gboolean is_last = FALSE;
3884 gboolean done = FALSE;
3887 max_height = ROW_HEIGHT (tree_view);
3891 background_area.y = y_offset + event->area.y;
3892 background_area.height = max_height;
3893 max_y = background_area.y + max_height;
3897 if (node == tree_view->priv->prelight_node)
3898 flags |= GTK_CELL_RENDERER_PRELIT;
3900 selected = pspp_sheet_view_node_is_selected (tree_view, node);
3904 if (tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
3906 /* we *need* to set cell data on all cells before the call
3907 * to _has_special_cell, else _has_special_cell() does not
3908 * return a correct value.
3910 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3912 list = (rtl ? list->prev : list->next))
3914 PsppSheetViewColumn *column = list->data;
3915 pspp_sheet_view_column_cell_set_cell_data (column,
3916 tree_view->priv->model,
3920 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
3923 has_special_cell = tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
3925 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3927 list = (rtl ? list->prev : list->next))
3929 PsppSheetViewColumn *column = list->data;
3930 const gchar *detail = NULL;
3931 gboolean selected_column;
3934 if (!column->visible)
3937 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
3938 selected_column = column->selected && column->selectable;
3940 selected_column = TRUE;
3942 if (cell_offset > event->area.x + event->area.width ||
3943 cell_offset + column->width < event->area.x)
3945 cell_offset += column->width;
3949 if (selected && selected_column)
3950 flags |= GTK_CELL_RENDERER_SELECTED;
3952 flags &= ~GTK_CELL_RENDERER_SELECTED;
3954 if (column->show_sort_indicator)
3955 flags |= GTK_CELL_RENDERER_SORTED;
3957 flags &= ~GTK_CELL_RENDERER_SORTED;
3960 flags |= GTK_CELL_RENDERER_FOCUSED;
3962 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3964 background_area.x = cell_offset;
3965 background_area.width = column->width;
3967 cell_area = background_area;
3968 cell_area.y += vertical_separator / 2;
3969 cell_area.x += horizontal_separator / 2;
3970 cell_area.height -= vertical_separator;
3971 cell_area.width -= horizontal_separator;
3973 if (draw_vgrid_lines)
3975 if (list == first_column)
3977 cell_area.width -= grid_line_width / 2;
3979 else if (list == last_column)
3981 cell_area.x += grid_line_width / 2;
3982 cell_area.width -= grid_line_width / 2;
3986 cell_area.x += grid_line_width / 2;
3987 cell_area.width -= grid_line_width;
3991 if (draw_hgrid_lines)
3993 cell_area.y += grid_line_width / 2;
3994 cell_area.height -= grid_line_width;
3997 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
3999 cell_offset += column->width;
4003 pspp_sheet_view_column_cell_set_cell_data (column,
4004 tree_view->priv->model,
4007 /* Select the detail for drawing the cell. relevant
4008 * factors are parity, sortedness, and whether to
4011 if (allow_rules && tree_view->priv->has_rules)
4013 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4014 n_visible_columns >= 3)
4017 detail = "cell_odd_ruled_sorted";
4019 detail = "cell_even_ruled_sorted";
4024 detail = "cell_odd_ruled";
4026 detail = "cell_even_ruled";
4031 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4032 n_visible_columns >= 3)
4035 detail = "cell_odd_sorted";
4037 detail = "cell_even_sorted";
4042 detail = "cell_odd";
4044 detail = "cell_even";
4050 if (widget->state == GTK_STATE_INSENSITIVE)
4051 state = GTK_STATE_INSENSITIVE;
4052 else if (flags & GTK_CELL_RENDERER_SELECTED)
4053 state = GTK_STATE_SELECTED;
4055 state = GTK_STATE_NORMAL;
4057 /* Draw background */
4058 if (row_ending_details)
4060 char new_detail[128];
4062 is_first = (rtl ? !list->next : !list->prev);
4063 is_last = (rtl ? !list->prev : !list->next);
4065 /* (I don't like the snprintfs either, but couldn't find a
4068 if (is_first && is_last)
4069 g_snprintf (new_detail, 127, "%s", detail);
4071 g_snprintf (new_detail, 127, "%s_start", detail);
4073 g_snprintf (new_detail, 127, "%s_end", detail);
4075 g_snprintf (new_detail, 128, "%s_middle", detail);
4077 gtk_paint_flat_box (widget->style,
4086 background_area.width,
4087 background_area.height);
4091 gtk_paint_flat_box (widget->style,
4100 background_area.width,
4101 background_area.height);
4104 if (draw_hgrid_lines)
4106 if (background_area.y > 0)
4107 gdk_draw_line (event->window,
4108 tree_view->priv->grid_line_gc,
4109 background_area.x, background_area.y,
4110 background_area.x + background_area.width,
4113 if (y_offset + max_height >= event->area.height)
4114 gdk_draw_line (event->window,
4115 tree_view->priv->grid_line_gc,
4116 background_area.x, background_area.y + max_height,
4117 background_area.x + background_area.width,
4118 background_area.y + max_height);
4121 _pspp_sheet_view_column_cell_render (column,
4128 if (node == cursor && has_special_cell &&
4129 ((column == tree_view->priv->focus_column &&
4130 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4131 gtk_widget_has_focus (widget)) ||
4132 (column == tree_view->priv->edited_column)))
4134 _pspp_sheet_view_column_cell_draw_focus (column,
4142 cell_offset += column->width;
4145 if (cell_offset < event->area.x)
4147 gtk_paint_flat_box (widget->style,
4156 event->area.x - cell_offset,
4157 background_area.height);
4160 if (node == drag_highlight)
4162 /* Draw indicator for the drop
4164 gint highlight_y = -1;
4168 switch (tree_view->priv->drag_dest_pos)
4170 case PSPP_SHEET_VIEW_DROP_BEFORE:
4171 highlight_y = background_area.y - 1;
4172 if (highlight_y < 0)
4176 case PSPP_SHEET_VIEW_DROP_AFTER:
4177 highlight_y = background_area.y + background_area.height - 1;
4180 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4181 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4182 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4186 gdk_drawable_get_size (tree_view->priv->bin_window,
4189 if (row_ending_details)
4190 gtk_paint_focus (widget->style,
4191 tree_view->priv->bin_window,
4192 gtk_widget_get_state (widget),
4196 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4197 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4198 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4199 - focus_line_width / 2,
4200 width, ROW_HEIGHT (tree_view)
4201 - focus_line_width + 1);
4203 gtk_paint_focus (widget->style,
4204 tree_view->priv->bin_window,
4205 gtk_widget_get_state (widget),
4208 "treeview-drop-indicator",
4209 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4210 - focus_line_width / 2,
4211 width, ROW_HEIGHT (tree_view)
4212 - focus_line_width + 1);
4216 if (highlight_y >= 0)
4218 gdk_draw_line (event->window,
4219 widget->style->fg_gc[gtk_widget_get_state (widget)],
4222 rtl ? 0 : bin_window_width,
4227 /* draw the big row-spanning focus rectangle, if needed */
4228 if (!has_special_cell && node == cursor &&
4229 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4230 gtk_widget_has_focus (widget))
4232 gint tmp_y, tmp_height;
4234 GtkStateType focus_rect_state;
4237 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4238 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4239 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4242 gdk_drawable_get_size (tree_view->priv->bin_window,
4245 if (draw_hgrid_lines)
4247 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4248 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4252 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4253 tmp_height = ROW_HEIGHT (tree_view);
4256 if (row_ending_details)
4257 gtk_paint_focus (widget->style,
4258 tree_view->priv->bin_window,
4263 ? (is_last ? "treeview" : "treeview-left" )
4264 : (is_last ? "treeview-right" : "treeview-middle" )),
4268 gtk_paint_focus (widget->style,
4269 tree_view->priv->bin_window,
4278 y_offset += max_height;
4282 node = pspp_sheet_view_node_next (tree_view, node);
4285 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4289 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4296 while (y_offset < event->area.height);
4299 pspp_sheet_view_draw_grid_lines (tree_view, event, n_visible_columns,
4302 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4304 GdkRectangle *rectangles;
4307 gdk_region_get_rectangles (event->region,
4311 while (n_rectangles--)
4312 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4314 g_free (rectangles);
4318 gtk_tree_path_free (cursor_path);
4321 gtk_tree_path_free (drag_dest_path);
4327 pspp_sheet_view_expose (GtkWidget *widget,
4328 GdkEventExpose *event)
4330 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4332 if (event->window == tree_view->priv->bin_window)
4337 retval = pspp_sheet_view_bin_expose (widget, event);
4339 /* We can't just chain up to Container::expose as it will try to send the
4340 * event to the headers, so we handle propagating it to our children
4341 * (eg. widgets being edited) ourselves.
4343 tmp_list = tree_view->priv->children;
4346 PsppSheetViewChild *child = tmp_list->data;
4347 tmp_list = tmp_list->next;
4349 gtk_container_propagate_expose (GTK_CONTAINER (tree_view), child->widget, event);
4355 else if (event->window == tree_view->priv->header_window)
4357 gint n_visible_columns;
4360 gtk_paint_flat_box (widget->style,
4370 event->area.height);
4372 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4374 PsppSheetViewColumn *column = list->data;
4376 if (column == tree_view->priv->drag_column || !column->visible)
4379 if (span_intersects (column->allocation.x, column->allocation.width,
4380 event->area.x, event->area.width)
4381 && column->button != NULL)
4382 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4383 column->button, event);
4386 n_visible_columns = 0;
4387 for (list = tree_view->priv->columns; list; list = list->next)
4389 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4391 n_visible_columns ++;
4393 pspp_sheet_view_draw_grid_lines (tree_view,
4397 event->area.height);
4399 else if (event->window == tree_view->priv->drag_window)
4401 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4402 tree_view->priv->drag_column->button,
4416 /* returns 0x1 when no column has been found -- yes it's hackish */
4417 static PsppSheetViewColumn *
4418 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4419 PsppSheetViewColumn *column,
4422 PsppSheetViewColumn *left_column = NULL;
4423 PsppSheetViewColumn *cur_column = NULL;
4426 if (!column->reorderable)
4427 return (PsppSheetViewColumn *)0x1;
4429 switch (drop_position)
4432 /* find first column where we can drop */
4433 tmp_list = tree_view->priv->columns;
4434 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4435 return (PsppSheetViewColumn *)0x1;
4439 g_assert (tmp_list);
4441 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4442 tmp_list = tmp_list->next;
4444 if (left_column && left_column->visible == FALSE)
4447 if (!tree_view->priv->column_drop_func)
4450 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4452 left_column = cur_column;
4459 if (!tree_view->priv->column_drop_func)
4462 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4465 return (PsppSheetViewColumn *)0x1;
4469 /* find first column after column where we can drop */
4470 tmp_list = tree_view->priv->columns;
4472 for (; tmp_list; tmp_list = tmp_list->next)
4473 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4476 if (!tmp_list || !tmp_list->next)
4477 return (PsppSheetViewColumn *)0x1;
4479 tmp_list = tmp_list->next;
4480 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4481 tmp_list = tmp_list->next;
4485 g_assert (tmp_list);
4487 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4488 tmp_list = tmp_list->next;
4490 if (left_column && left_column->visible == FALSE)
4492 left_column = cur_column;
4494 tmp_list = tmp_list->next;
4498 if (!tree_view->priv->column_drop_func)
4501 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4503 left_column = cur_column;
4510 if (!tree_view->priv->column_drop_func)
4513 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4516 return (PsppSheetViewColumn *)0x1;
4520 /* find first column before column where we can drop */
4521 tmp_list = tree_view->priv->columns;
4523 for (; tmp_list; tmp_list = tmp_list->next)
4524 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4527 if (!tmp_list || !tmp_list->prev)
4528 return (PsppSheetViewColumn *)0x1;
4530 tmp_list = tmp_list->prev;
4531 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4532 tmp_list = tmp_list->prev;
4536 g_assert (tmp_list);
4538 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4540 if (left_column && !left_column->visible)
4542 /*if (!tmp_list->prev)
4543 return (PsppSheetViewColumn *)0x1;
4546 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4547 tmp_list = tmp_list->prev->prev;
4550 cur_column = left_column;
4552 tmp_list = tmp_list->prev;
4556 if (!tree_view->priv->column_drop_func)
4559 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4562 cur_column = left_column;
4563 tmp_list = tmp_list->prev;
4566 if (!tree_view->priv->column_drop_func)
4569 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4572 return (PsppSheetViewColumn *)0x1;
4576 /* same as DROP_HOME case, but doing it backwards */
4577 tmp_list = g_list_last (tree_view->priv->columns);
4580 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4581 return (PsppSheetViewColumn *)0x1;
4585 g_assert (tmp_list);
4587 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4589 if (left_column && !left_column->visible)
4591 cur_column = left_column;
4592 tmp_list = tmp_list->prev;
4595 if (!tree_view->priv->column_drop_func)
4598 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4601 cur_column = left_column;
4602 tmp_list = tmp_list->prev;
4605 if (!tree_view->priv->column_drop_func)
4608 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4611 return (PsppSheetViewColumn *)0x1;
4615 return (PsppSheetViewColumn *)0x1;
4619 pspp_sheet_view_key_press (GtkWidget *widget,
4622 PsppSheetView *tree_view = (PsppSheetView *) widget;
4624 if (tree_view->priv->rubber_band_status)
4626 if (event->keyval == GDK_Escape)
4627 pspp_sheet_view_stop_rubber_band (tree_view);
4632 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4634 if (event->keyval == GDK_Escape)
4636 tree_view->priv->cur_reorder = NULL;
4637 pspp_sheet_view_button_release_drag_column (widget, NULL);
4642 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4644 GList *focus_column;
4647 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4649 for (focus_column = tree_view->priv->columns;
4651 focus_column = focus_column->next)
4653 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4655 if (column->button && gtk_widget_has_focus (column->button))
4660 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4661 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4662 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4664 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4666 if (!column->resizable)
4668 gtk_widget_error_bell (widget);
4672 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4673 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4675 gint old_width = column->resized_width;
4677 column->resized_width = MAX (column->resized_width,
4679 column->resized_width -= 2;
4680 if (column->resized_width < 0)
4681 column->resized_width = 0;
4683 if (column->min_width == -1)
4684 column->resized_width = MAX (column->button_request,
4685 column->resized_width);
4687 column->resized_width = MAX (column->min_width,
4688 column->resized_width);
4690 if (column->max_width != -1)
4691 column->resized_width = MIN (column->resized_width,
4694 column->use_resized_width = TRUE;
4696 if (column->resized_width != old_width)
4697 gtk_widget_queue_resize (widget);
4699 gtk_widget_error_bell (widget);
4701 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4702 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4704 gint old_width = column->resized_width;
4706 column->resized_width = MAX (column->resized_width,
4708 column->resized_width += 2;
4710 if (column->max_width != -1)
4711 column->resized_width = MIN (column->resized_width,
4714 column->use_resized_width = TRUE;
4716 if (column->resized_width != old_width)
4717 gtk_widget_queue_resize (widget);
4719 gtk_widget_error_bell (widget);
4726 (event->state & GDK_MOD1_MASK) &&
4727 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4728 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4729 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4730 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4732 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4734 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4735 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4737 PsppSheetViewColumn *col;
4738 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4739 if (col != (PsppSheetViewColumn *)0x1)
4740 pspp_sheet_view_move_column_after (tree_view, column, col);
4742 gtk_widget_error_bell (widget);
4744 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4745 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4747 PsppSheetViewColumn *col;
4748 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4749 if (col != (PsppSheetViewColumn *)0x1)
4750 pspp_sheet_view_move_column_after (tree_view, column, col);
4752 gtk_widget_error_bell (widget);
4754 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4756 PsppSheetViewColumn *col;
4757 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4758 if (col != (PsppSheetViewColumn *)0x1)
4759 pspp_sheet_view_move_column_after (tree_view, column, col);
4761 gtk_widget_error_bell (widget);
4763 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4765 PsppSheetViewColumn *col;
4766 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4767 if (col != (PsppSheetViewColumn *)0x1)
4768 pspp_sheet_view_move_column_after (tree_view, column, col);
4770 gtk_widget_error_bell (widget);
4777 /* Chain up to the parent class. It handles the keybindings. */
4778 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4781 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4783 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4787 /* We pass the event to the search_entry. If its text changes, then we start
4788 * the typeahead find capabilities. */
4789 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4790 && tree_view->priv->enable_search
4791 && !tree_view->priv->search_custom_entry_set)
4793 GdkEvent *new_event;
4795 const char *new_text;
4798 gboolean text_modified;
4799 gulong popup_menu_id;
4801 pspp_sheet_view_ensure_interactive_directory (tree_view);
4803 /* Make a copy of the current text */
4804 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4805 new_event = gdk_event_copy ((GdkEvent *) event);
4806 g_object_unref (((GdkEventKey *) new_event)->window);
4807 ((GdkEventKey *) new_event)->window = g_object_ref (tree_view->priv->search_window->window);
4808 gtk_widget_realize (tree_view->priv->search_window);
4810 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4811 "popup-menu", G_CALLBACK (gtk_true),
4814 /* Move the entry off screen */
4815 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4816 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4817 gdk_screen_get_width (screen) + 1,
4818 gdk_screen_get_height (screen) + 1);
4819 gtk_widget_show (tree_view->priv->search_window);
4821 /* Send the event to the window. If the preedit_changed signal is emitted
4822 * during this event, we will set priv->imcontext_changed */
4823 tree_view->priv->imcontext_changed = FALSE;
4824 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4825 gdk_event_free (new_event);
4826 gtk_widget_hide (tree_view->priv->search_window);
4828 g_signal_handler_disconnect (tree_view->priv->search_entry,
4831 /* We check to make sure that the entry tried to handle the text, and that
4832 * the text has changed.
4834 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4835 text_modified = strcmp (old_text, new_text) != 0;
4837 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4838 (retval && text_modified)) /* ...or the text was modified */
4840 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4842 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4847 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
4857 pspp_sheet_view_key_release (GtkWidget *widget,
4860 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4862 if (tree_view->priv->rubber_band_status)
4865 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
4868 /* FIXME Is this function necessary? Can I get an enter_notify event
4869 * w/o either an expose event or a mouse motion event?
4872 pspp_sheet_view_enter_notify (GtkWidget *widget,
4873 GdkEventCrossing *event)
4875 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4879 /* Sanity check it */
4880 if (event->window != tree_view->priv->bin_window)
4883 if (tree_view->priv->row_count == 0)
4886 if (event->mode == GDK_CROSSING_GRAB ||
4887 event->mode == GDK_CROSSING_GTK_GRAB ||
4888 event->mode == GDK_CROSSING_GTK_UNGRAB ||
4889 event->mode == GDK_CROSSING_STATE_CHANGED)
4892 /* find the node internally */
4893 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
4896 pspp_sheet_view_find_offset (tree_view, new_y, &node);
4898 tree_view->priv->event_last_x = event->x;
4899 tree_view->priv->event_last_y = event->y;
4901 prelight_or_select (tree_view, node, event->x, event->y);
4907 pspp_sheet_view_leave_notify (GtkWidget *widget,
4908 GdkEventCrossing *event)
4910 PsppSheetView *tree_view;
4912 if (event->mode == GDK_CROSSING_GRAB)
4915 tree_view = PSPP_SHEET_VIEW (widget);
4917 if (tree_view->priv->prelight_node >= 0)
4918 _pspp_sheet_view_queue_draw_node (tree_view,
4919 tree_view->priv->prelight_node,
4922 tree_view->priv->event_last_x = -10000;
4923 tree_view->priv->event_last_y = -10000;
4925 prelight_or_select (tree_view,
4927 -1000, -1000); /* coords not possibly over an arrow */
4934 pspp_sheet_view_focus_out (GtkWidget *widget,
4935 GdkEventFocus *event)
4937 PsppSheetView *tree_view;
4939 tree_view = PSPP_SHEET_VIEW (widget);
4941 gtk_widget_queue_draw (widget);
4943 /* destroy interactive search dialog */
4944 if (tree_view->priv->search_window)
4945 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
4951 /* Incremental Reflow
4955 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
4960 y = pspp_sheet_view_node_find_offset (tree_view, node)
4961 - tree_view->priv->vadjustment->value
4962 + TREE_VIEW_HEADER_HEIGHT (tree_view);
4964 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
4966 GTK_WIDGET (tree_view)->allocation.width,
4967 tree_view->priv->fixed_height);
4971 node_is_visible (PsppSheetView *tree_view,
4977 y = pspp_sheet_view_node_find_offset (tree_view, node);
4978 height = ROW_HEIGHT (tree_view);
4980 if (y >= tree_view->priv->vadjustment->value &&
4981 y + height <= (tree_view->priv->vadjustment->value
4982 + tree_view->priv->vadjustment->page_size))
4988 /* Returns the row height. */
4990 validate_row (PsppSheetView *tree_view,
4995 PsppSheetViewColumn *column;
4996 GList *list, *first_column, *last_column;
4998 gint horizontal_separator;
4999 gint vertical_separator;
5000 gint focus_line_width;
5001 gboolean draw_vgrid_lines, draw_hgrid_lines;
5003 gint grid_line_width;
5004 gboolean wide_separators;
5005 gint separator_height;
5007 gtk_widget_style_get (GTK_WIDGET (tree_view),
5008 "focus-padding", &focus_pad,
5009 "focus-line-width", &focus_line_width,
5010 "horizontal-separator", &horizontal_separator,
5011 "vertical-separator", &vertical_separator,
5012 "grid-line-width", &grid_line_width,
5013 "wide-separators", &wide_separators,
5014 "separator-height", &separator_height,
5018 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5019 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5021 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5022 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5024 for (last_column = g_list_last (tree_view->priv->columns);
5025 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5026 last_column = last_column->prev)
5029 for (first_column = g_list_first (tree_view->priv->columns);
5030 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5031 first_column = first_column->next)
5034 for (list = tree_view->priv->columns; list; list = list->next)
5039 column = list->data;
5041 if (! column->visible)
5044 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5045 pspp_sheet_view_column_cell_get_size (column,
5047 &tmp_width, &tmp_height);
5049 tmp_height += vertical_separator;
5050 height = MAX (height, tmp_height);
5052 tmp_width = tmp_width + horizontal_separator;
5054 if (draw_vgrid_lines)
5056 if (list->data == first_column || list->data == last_column)
5057 tmp_width += grid_line_width / 2.0;
5059 tmp_width += grid_line_width;
5062 if (tmp_width > column->requested_width)
5063 column->requested_width = tmp_width;
5066 if (draw_hgrid_lines)
5067 height += grid_line_width;
5069 tree_view->priv->post_validation_flag = TRUE;
5075 validate_visible_area (PsppSheetView *tree_view)
5077 GtkTreePath *path = NULL;
5078 GtkTreePath *above_path = NULL;
5081 gboolean size_changed = FALSE;
5083 gint area_above = 0;
5084 gint area_below = 0;
5086 if (tree_view->priv->row_count == 0)
5089 if (tree_view->priv->scroll_to_path == NULL)
5092 total_height = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5094 if (total_height == 0)
5097 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5100 /* we are going to scroll, and will update dy */
5101 _pspp_sheet_view_find_node (tree_view, path, &node);
5102 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5104 if (tree_view->priv->scroll_to_use_align)
5106 gint height = ROW_HEIGHT (tree_view);
5107 area_above = (total_height - height) *
5108 tree_view->priv->scroll_to_row_align;
5109 area_below = total_height - area_above - height;
5110 area_above = MAX (area_above, 0);
5111 area_below = MAX (area_below, 0);
5116 * 1) row not visible
5120 gint height = ROW_HEIGHT (tree_view);
5122 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5124 if (dy >= tree_view->priv->vadjustment->value &&
5125 dy + height <= (tree_view->priv->vadjustment->value
5126 + tree_view->priv->vadjustment->page_size))
5128 /* row visible: keep the row at the same position */
5129 area_above = dy - tree_view->priv->vadjustment->value;
5130 area_below = (tree_view->priv->vadjustment->value +
5131 tree_view->priv->vadjustment->page_size)
5136 /* row not visible */
5138 && dy + height <= tree_view->priv->vadjustment->page_size)
5140 /* row at the beginning -- fixed */
5142 area_below = tree_view->priv->vadjustment->page_size
5143 - area_above - height;
5145 else if (dy >= (tree_view->priv->vadjustment->upper -
5146 tree_view->priv->vadjustment->page_size))
5148 /* row at the end -- fixed */
5149 area_above = dy - (tree_view->priv->vadjustment->upper -
5150 tree_view->priv->vadjustment->page_size);
5151 area_below = tree_view->priv->vadjustment->page_size -
5152 area_above - height;
5156 area_above = tree_view->priv->vadjustment->page_size - height;
5162 /* row somewhere in the middle, bring it to the top
5166 area_below = total_height - height;
5172 /* the scroll to isn't valid; ignore it.
5175 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5176 tree_view->priv->scroll_to_path = NULL;
5180 above_path = gtk_tree_path_copy (path);
5182 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5183 * backwards is much slower then forward, as there is no iter_prev function.
5184 * We go forwards first in case we run out of tree. Then we go backwards to
5187 while (node >= 0 && area_below > 0)
5189 gboolean done = FALSE;
5192 node = pspp_sheet_view_node_next (tree_view, node);
5195 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5197 gtk_tree_path_next (path);
5200 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5210 area_below -= ROW_HEIGHT (tree_view);
5212 gtk_tree_path_free (path);
5214 /* If we ran out of tree, and have extra area_below left, we need to add it
5217 area_above += area_below;
5219 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5221 /* We walk backwards */
5222 while (area_above > 0)
5224 node = pspp_sheet_view_node_prev (tree_view, node);
5226 /* Always find the new path in the tree. We cannot just assume
5227 * a gtk_tree_path_prev() is enough here, as there might be children
5228 * in between this node and the previous sibling node. If this
5229 * appears to be a performance hotspot in profiles, we can look into
5230 * intrigate logic for keeping path, node and iter in sync like
5231 * we do for forward walks. (Which will be hard because of the lacking
5238 gtk_tree_path_free (above_path);
5239 above_path = _pspp_sheet_view_find_path (tree_view, node);
5241 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5243 area_above -= ROW_HEIGHT (tree_view);
5246 /* set the dy here to scroll to the path,
5247 * and sync the top row accordingly
5249 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5250 pspp_sheet_view_top_row_to_dy (tree_view);
5252 /* update width/height and queue a resize */
5255 GtkRequisition requisition;
5257 /* We temporarily guess a size, under the assumption that it will be the
5258 * same when we get our next size_allocate. If we don't do this, we'll be
5259 * in an inconsistent state if we call top_row_to_dy. */
5261 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5262 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5263 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5264 gtk_adjustment_changed (tree_view->priv->hadjustment);
5265 gtk_adjustment_changed (tree_view->priv->vadjustment);
5266 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5269 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5270 tree_view->priv->scroll_to_path = NULL;
5273 gtk_tree_path_free (above_path);
5275 if (tree_view->priv->scroll_to_column)
5277 tree_view->priv->scroll_to_column = NULL;
5279 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5283 initialize_fixed_height_mode (PsppSheetView *tree_view)
5285 if (!tree_view->priv->row_count)
5288 if (tree_view->priv->fixed_height_set)
5291 if (tree_view->priv->fixed_height < 0)
5298 path = _pspp_sheet_view_find_path (tree_view, node);
5299 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5301 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5303 gtk_tree_path_free (path);
5305 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5309 /* Our strategy for finding nodes to validate is a little convoluted. We find
5310 * the left-most uninvalidated node. We then try walking right, validating
5311 * nodes. Once we find a valid node, we repeat the previous process of finding
5312 * the first invalid node.
5316 validate_rows_handler (PsppSheetView *tree_view)
5318 initialize_fixed_height_mode (tree_view);
5319 if (tree_view->priv->validate_rows_timer)
5321 g_source_remove (tree_view->priv->validate_rows_timer);
5322 tree_view->priv->validate_rows_timer = 0;
5329 do_presize_handler (PsppSheetView *tree_view)
5331 GtkRequisition requisition;
5333 validate_visible_area (tree_view);
5334 tree_view->priv->presize_handler_timer = 0;
5336 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5338 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5339 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5340 gtk_adjustment_changed (tree_view->priv->hadjustment);
5341 gtk_adjustment_changed (tree_view->priv->vadjustment);
5342 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5348 presize_handler_callback (gpointer data)
5350 do_presize_handler (PSPP_SHEET_VIEW (data));
5356 install_presize_handler (PsppSheetView *tree_view)
5358 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5361 if (! tree_view->priv->presize_handler_timer)
5363 tree_view->priv->presize_handler_timer =
5364 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5366 if (! tree_view->priv->validate_rows_timer)
5368 tree_view->priv->validate_rows_timer =
5369 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5374 scroll_sync_handler (PsppSheetView *tree_view)
5376 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
5377 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5378 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5379 pspp_sheet_view_top_row_to_dy (tree_view);
5381 pspp_sheet_view_dy_to_top_row (tree_view);
5383 tree_view->priv->scroll_sync_timer = 0;
5389 install_scroll_sync_handler (PsppSheetView *tree_view)
5391 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5394 if (!tree_view->priv->scroll_sync_timer)
5396 tree_view->priv->scroll_sync_timer =
5397 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5402 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5406 gtk_tree_row_reference_free (tree_view->priv->top_row);
5410 tree_view->priv->top_row = NULL;
5411 tree_view->priv->top_row_dy = 0;
5415 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5416 tree_view->priv->top_row_dy = offset;
5420 /* Always call this iff dy is in the visible range. If the tree is empty, then
5421 * it's set to be NULL, and top_row_dy is 0;
5424 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5430 if (tree_view->priv->row_count == 0)
5432 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5436 offset = pspp_sheet_view_find_offset (tree_view,
5437 tree_view->priv->dy,
5442 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5446 path = _pspp_sheet_view_find_path (tree_view, node);
5447 pspp_sheet_view_set_top_row (tree_view, path, offset);
5448 gtk_tree_path_free (path);
5454 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5460 /* Avoid recursive calls */
5461 if (tree_view->priv->in_top_row_to_dy)
5464 if (tree_view->priv->top_row)
5465 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5472 _pspp_sheet_view_find_node (tree_view, path, &node);
5475 gtk_tree_path_free (path);
5479 /* keep dy and set new toprow */
5480 gtk_tree_row_reference_free (tree_view->priv->top_row);
5481 tree_view->priv->top_row = NULL;
5482 tree_view->priv->top_row_dy = 0;
5483 /* DO NOT install the idle handler */
5484 pspp_sheet_view_dy_to_top_row (tree_view);
5488 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5490 /* new top row -- do NOT install the idle handler */
5491 pspp_sheet_view_dy_to_top_row (tree_view);
5495 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5496 new_dy += tree_view->priv->top_row_dy;
5498 if (new_dy + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
5499 new_dy = tree_view->priv->height - tree_view->priv->vadjustment->page_size;
5501 new_dy = MAX (0, new_dy);
5503 tree_view->priv->in_top_row_to_dy = TRUE;
5504 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5505 tree_view->priv->in_top_row_to_dy = FALSE;
5510 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5512 install_presize_handler (tree_view);
5518 set_source_row (GdkDragContext *context,
5519 GtkTreeModel *model,
5520 GtkTreePath *source_row)
5522 g_object_set_data_full (G_OBJECT (context),
5523 "gtk-tree-view-source-row",
5524 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5525 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5529 get_source_row (GdkDragContext *context)
5531 GtkTreeRowReference *ref =
5532 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5535 return gtk_tree_row_reference_get_path (ref);
5542 GtkTreeRowReference *dest_row;
5543 guint path_down_mode : 1;
5544 guint empty_view_drop : 1;
5545 guint drop_append_mode : 1;
5550 dest_row_free (gpointer data)
5552 DestRow *dr = (DestRow *)data;
5554 gtk_tree_row_reference_free (dr->dest_row);
5555 g_slice_free (DestRow, dr);
5559 set_dest_row (GdkDragContext *context,
5560 GtkTreeModel *model,
5561 GtkTreePath *dest_row,
5562 gboolean path_down_mode,
5563 gboolean empty_view_drop,
5564 gboolean drop_append_mode)
5570 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5575 dr = g_slice_new (DestRow);
5577 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5578 dr->path_down_mode = path_down_mode != FALSE;
5579 dr->empty_view_drop = empty_view_drop != FALSE;
5580 dr->drop_append_mode = drop_append_mode != FALSE;
5582 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5583 dr, (GDestroyNotify) dest_row_free);
5587 get_dest_row (GdkDragContext *context,
5588 gboolean *path_down_mode)
5591 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5595 GtkTreePath *path = NULL;
5598 *path_down_mode = dr->path_down_mode;
5601 path = gtk_tree_row_reference_get_path (dr->dest_row);
5602 else if (dr->empty_view_drop)
5603 path = gtk_tree_path_new_from_indices (0, -1);
5607 if (path && dr->drop_append_mode)
5608 gtk_tree_path_next (path);
5616 /* Get/set whether drag_motion requested the drag data and
5617 * drag_data_received should thus not actually insert the data,
5618 * since the data doesn't result from a drop.
5621 set_status_pending (GdkDragContext *context,
5622 GdkDragAction suggested_action)
5624 g_object_set_data (G_OBJECT (context),
5625 "gtk-tree-view-status-pending",
5626 GINT_TO_POINTER (suggested_action));
5629 static GdkDragAction
5630 get_status_pending (GdkDragContext *context)
5632 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5633 "gtk-tree-view-status-pending"));
5636 static TreeViewDragInfo*
5637 get_info (PsppSheetView *tree_view)
5639 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5643 destroy_info (TreeViewDragInfo *di)
5645 g_slice_free (TreeViewDragInfo, di);
5648 static TreeViewDragInfo*
5649 ensure_info (PsppSheetView *tree_view)
5651 TreeViewDragInfo *di;
5653 di = get_info (tree_view);
5657 di = g_slice_new0 (TreeViewDragInfo);
5659 g_object_set_data_full (G_OBJECT (tree_view),
5660 "gtk-tree-view-drag-info",
5662 (GDestroyNotify) destroy_info);
5669 remove_info (PsppSheetView *tree_view)
5671 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5676 drag_scan_timeout (gpointer data)
5678 PsppSheetView *tree_view;
5680 GdkModifierType state;
5681 GtkTreePath *path = NULL;
5682 PsppSheetViewColumn *column = NULL;
5683 GdkRectangle visible_rect;
5685 GDK_THREADS_ENTER ();
5687 tree_view = PSPP_SHEET_VIEW (data);
5689 gdk_window_get_pointer (tree_view->priv->bin_window,
5692 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5694 /* See if we are near the edge. */
5695 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5696 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5697 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5698 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5700 pspp_sheet_view_get_path_at_pos (tree_view,
5701 tree_view->priv->bin_window,
5710 pspp_sheet_view_scroll_to_cell (tree_view,
5716 gtk_tree_path_free (path);
5720 GDK_THREADS_LEAVE ();
5727 add_scroll_timeout (PsppSheetView *tree_view)
5729 if (tree_view->priv->scroll_timeout == 0)
5731 tree_view->priv->scroll_timeout =
5732 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5737 remove_scroll_timeout (PsppSheetView *tree_view)
5739 if (tree_view->priv->scroll_timeout != 0)
5741 g_source_remove (tree_view->priv->scroll_timeout);
5742 tree_view->priv->scroll_timeout = 0;
5747 check_model_dnd (GtkTreeModel *model,
5748 GType required_iface,
5749 const gchar *signal)
5751 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5753 g_warning ("You must override the default '%s' handler "
5754 "on PsppSheetView when using models that don't support "
5755 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5756 "is to connect to '%s' and call "
5757 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5758 "the default handler from running. Look at the source code "
5759 "for the default handler in gtktreeview.c to get an idea what "
5760 "your handler should do. (gtktreeview.c is in the GTK source "
5761 "code.) If you're using GTK from a language other than C, "
5762 "there may be a more natural way to override default handlers, e.g. via derivation.",
5763 signal, g_type_name (required_iface), signal);
5771 scroll_row_timeout (gpointer data)
5773 PsppSheetView *tree_view = data;
5775 pspp_sheet_view_horizontal_autoscroll (tree_view);
5776 pspp_sheet_view_vertical_autoscroll (tree_view);
5778 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5779 pspp_sheet_view_update_rubber_band (tree_view);
5784 /* Returns TRUE if event should not be propagated to parent widgets */
5786 set_destination_row (PsppSheetView *tree_view,
5787 GdkDragContext *context,
5788 /* coordinates relative to the widget */
5791 GdkDragAction *suggested_action,
5794 GtkTreePath *path = NULL;
5795 PsppSheetViewDropPosition pos;
5796 PsppSheetViewDropPosition old_pos;
5797 TreeViewDragInfo *di;
5799 GtkTreePath *old_dest_path = NULL;
5800 gboolean can_drop = FALSE;
5802 *suggested_action = 0;
5805 widget = GTK_WIDGET (tree_view);
5807 di = get_info (tree_view);
5809 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5811 /* someone unset us as a drag dest, note that if
5812 * we return FALSE drag_leave isn't called
5815 pspp_sheet_view_set_drag_dest_row (tree_view,
5817 PSPP_SHEET_VIEW_DROP_BEFORE);
5819 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5821 return FALSE; /* no longer a drop site */
5824 *target = gtk_drag_dest_find_target (widget, context,
5825 gtk_drag_dest_get_target_list (widget));
5826 if (*target == GDK_NONE)
5831 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5837 GtkTreeModel *model;
5839 /* the row got dropped on empty space, let's setup a special case
5843 gtk_tree_path_free (path);
5845 model = pspp_sheet_view_get_model (tree_view);
5847 n_children = gtk_tree_model_iter_n_children (model, NULL);
5850 pos = PSPP_SHEET_VIEW_DROP_AFTER;
5851 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5855 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
5856 path = gtk_tree_path_new_from_indices (0, -1);
5866 /* If we left the current row's "open" zone, unset the timeout for
5869 pspp_sheet_view_get_drag_dest_row (tree_view,
5874 gtk_tree_path_free (old_dest_path);
5876 if (TRUE /* FIXME if the location droppable predicate */)
5884 GtkWidget *source_widget;
5886 *suggested_action = context->suggested_action;
5887 source_widget = gtk_drag_get_source_widget (context);
5889 if (source_widget == widget)
5891 /* Default to MOVE, unless the user has
5892 * pressed ctrl or shift to affect available actions
5894 if ((context->actions & GDK_ACTION_MOVE) != 0)
5895 *suggested_action = GDK_ACTION_MOVE;
5898 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5903 /* can't drop here */
5904 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5906 PSPP_SHEET_VIEW_DROP_BEFORE);
5910 gtk_tree_path_free (path);
5916 get_logical_dest_row (PsppSheetView *tree_view,
5917 gboolean *path_down_mode,
5918 gboolean *drop_append_mode)
5920 /* adjust path to point to the row the drop goes in front of */
5921 GtkTreePath *path = NULL;
5922 PsppSheetViewDropPosition pos;
5924 g_return_val_if_fail (path_down_mode != NULL, NULL);
5925 g_return_val_if_fail (drop_append_mode != NULL, NULL);
5927 *path_down_mode = FALSE;
5928 *drop_append_mode = 0;
5930 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
5935 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
5937 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
5938 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
5939 *path_down_mode = TRUE;
5943 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
5945 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
5947 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5948 !gtk_tree_model_iter_next (model, &iter))
5949 *drop_append_mode = 1;
5952 *drop_append_mode = 0;
5953 gtk_tree_path_next (path);
5961 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
5962 GdkEventMotion *event)
5964 GtkWidget *widget = GTK_WIDGET (tree_view);
5965 GdkDragContext *context;
5966 TreeViewDragInfo *di;
5967 GtkTreePath *path = NULL;
5969 gint cell_x, cell_y;
5970 GtkTreeModel *model;
5971 gboolean retval = FALSE;
5973 di = get_info (tree_view);
5975 if (di == NULL || !di->source_set)
5978 if (tree_view->priv->pressed_button < 0)
5981 if (!gtk_drag_check_threshold (widget,
5982 tree_view->priv->press_start_x,
5983 tree_view->priv->press_start_y,
5984 event->x, event->y))
5987 model = pspp_sheet_view_get_model (tree_view);
5992 button = tree_view->priv->pressed_button;
5993 tree_view->priv->pressed_button = -1;
5995 pspp_sheet_view_get_path_at_pos (tree_view,
5996 tree_view->priv->press_start_x,
5997 tree_view->priv->press_start_y,
6006 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6007 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6011 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6014 /* Now we can begin the drag */
6018 context = gtk_drag_begin (widget,
6019 gtk_drag_source_get_target_list (widget),
6024 set_source_row (context, model, path);
6028 gtk_tree_path_free (path);
6035 pspp_sheet_view_drag_begin (GtkWidget *widget,
6036 GdkDragContext *context)
6038 PsppSheetView *tree_view;
6039 GtkTreePath *path = NULL;
6040 gint cell_x, cell_y;
6042 TreeViewDragInfo *di;
6044 tree_view = PSPP_SHEET_VIEW (widget);
6046 /* if the user uses a custom DND source impl, we don't set the icon here */
6047 di = get_info (tree_view);
6049 if (di == NULL || !di->source_set)
6052 pspp_sheet_view_get_path_at_pos (tree_view,
6053 tree_view->priv->press_start_x,
6054 tree_view->priv->press_start_y,
6060 g_return_if_fail (path != NULL);
6062 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6065 gtk_drag_set_icon_pixmap (context,
6066 gdk_drawable_get_colormap (row_pix),
6069 /* the + 1 is for the black border in the icon */
6070 tree_view->priv->press_start_x + 1,
6073 g_object_unref (row_pix);
6074 gtk_tree_path_free (path);
6078 pspp_sheet_view_drag_end (GtkWidget *widget,
6079 GdkDragContext *context)
6084 /* Default signal implementations for the drag signals */
6086 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6087 GdkDragContext *context,
6088 GtkSelectionData *selection_data,
6092 PsppSheetView *tree_view;
6093 GtkTreeModel *model;
6094 TreeViewDragInfo *di;
6095 GtkTreePath *source_row;
6097 tree_view = PSPP_SHEET_VIEW (widget);
6099 model = pspp_sheet_view_get_model (tree_view);
6104 di = get_info (PSPP_SHEET_VIEW (widget));
6109 source_row = get_source_row (context);
6111 if (source_row == NULL)
6114 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6115 * any model; for DragSource models there are some other targets
6119 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6120 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6125 /* If drag_data_get does nothing, try providing row data. */
6126 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6128 gtk_tree_set_row_drag_data (selection_data,
6134 gtk_tree_path_free (source_row);
6139 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6140 GdkDragContext *context)
6142 TreeViewDragInfo *di;
6143 GtkTreeModel *model;
6144 PsppSheetView *tree_view;
6145 GtkTreePath *source_row;
6147 tree_view = PSPP_SHEET_VIEW (widget);
6148 model = pspp_sheet_view_get_model (tree_view);
6150 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6153 di = get_info (tree_view);
6158 source_row = get_source_row (context);
6160 if (source_row == NULL)
6163 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6166 gtk_tree_path_free (source_row);
6168 set_source_row (context, NULL, NULL);
6172 pspp_sheet_view_drag_leave (GtkWidget *widget,
6173 GdkDragContext *context,
6176 /* unset any highlight row */
6177 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6179 PSPP_SHEET_VIEW_DROP_BEFORE);
6181 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6186 pspp_sheet_view_drag_motion (GtkWidget *widget,
6187 GdkDragContext *context,
6188 /* coordinates relative to the widget */
6194 GtkTreePath *path = NULL;
6195 PsppSheetViewDropPosition pos;
6196 PsppSheetView *tree_view;
6197 GdkDragAction suggested_action = 0;
6200 tree_view = PSPP_SHEET_VIEW (widget);
6202 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6205 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6207 /* we only know this *after* set_desination_row */
6208 empty = tree_view->priv->empty_view_drop;
6210 if (path == NULL && !empty)
6212 /* Can't drop here. */
6213 gdk_drag_status (context, 0, time);
6217 if (tree_view->priv->open_dest_timeout == 0 &&
6218 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6219 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6225 add_scroll_timeout (tree_view);
6228 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6230 /* Request data so we can use the source row when
6231 * determining whether to accept the drop
6233 set_status_pending (context, suggested_action);
6234 gtk_drag_get_data (widget, context, target, time);
6238 set_status_pending (context, 0);
6239 gdk_drag_status (context, suggested_action, time);
6244 gtk_tree_path_free (path);
6251 pspp_sheet_view_drag_drop (GtkWidget *widget,
6252 GdkDragContext *context,
6253 /* coordinates relative to the widget */
6258 PsppSheetView *tree_view;
6260 GdkDragAction suggested_action = 0;
6261 GdkAtom target = GDK_NONE;
6262 TreeViewDragInfo *di;
6263 GtkTreeModel *model;
6264 gboolean path_down_mode;
6265 gboolean drop_append_mode;
6267 tree_view = PSPP_SHEET_VIEW (widget);
6269 model = pspp_sheet_view_get_model (tree_view);
6271 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6273 di = get_info (tree_view);
6278 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6281 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6284 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6286 if (target != GDK_NONE && path != NULL)
6288 /* in case a motion had requested drag data, change things so we
6289 * treat drag data receives as a drop.
6291 set_status_pending (context, 0);
6292 set_dest_row (context, model, path,
6293 path_down_mode, tree_view->priv->empty_view_drop,
6298 gtk_tree_path_free (path);
6300 /* Unset this thing */
6301 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6303 PSPP_SHEET_VIEW_DROP_BEFORE);
6305 if (target != GDK_NONE)
6307 gtk_drag_get_data (widget, context, target, time);
6315 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6316 GdkDragContext *context,
6317 /* coordinates relative to the widget */
6320 GtkSelectionData *selection_data,
6325 TreeViewDragInfo *di;
6326 gboolean accepted = FALSE;
6327 GtkTreeModel *model;
6328 PsppSheetView *tree_view;
6329 GtkTreePath *dest_row;
6330 GdkDragAction suggested_action;
6331 gboolean path_down_mode;
6332 gboolean drop_append_mode;
6334 tree_view = PSPP_SHEET_VIEW (widget);
6336 model = pspp_sheet_view_get_model (tree_view);
6338 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6341 di = get_info (tree_view);
6346 suggested_action = get_status_pending (context);
6348 if (suggested_action)
6350 /* We are getting this data due to a request in drag_motion,
6351 * rather than due to a request in drag_drop, so we are just
6352 * supposed to call drag_status, not actually paste in the
6355 path = get_logical_dest_row (tree_view, &path_down_mode,
6359 suggested_action = 0;
6360 else if (path_down_mode)
6361 gtk_tree_path_down (path);
6363 if (suggested_action)
6365 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6371 path_down_mode = FALSE;
6372 gtk_tree_path_up (path);
6374 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6377 suggested_action = 0;
6380 suggested_action = 0;
6384 gdk_drag_status (context, suggested_action, time);
6387 gtk_tree_path_free (path);
6389 /* If you can't drop, remove user drop indicator until the next motion */
6390 if (suggested_action == 0)
6391 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6393 PSPP_SHEET_VIEW_DROP_BEFORE);
6398 dest_row = get_dest_row (context, &path_down_mode);
6400 if (dest_row == NULL)
6403 if (selection_data->length >= 0)
6407 gtk_tree_path_down (dest_row);
6408 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6409 dest_row, selection_data))
6410 gtk_tree_path_up (dest_row);
6414 if (selection_data->length >= 0)
6416 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6422 gtk_drag_finish (context,
6424 (context->action == GDK_ACTION_MOVE),
6427 if (gtk_tree_path_get_depth (dest_row) == 1
6428 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6430 /* special special case drag to "0", scroll to first item */
6431 if (!tree_view->priv->scroll_to_path)
6432 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6435 gtk_tree_path_free (dest_row);
6438 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6443 /* GtkContainer Methods
6448 pspp_sheet_view_remove (GtkContainer *container,
6451 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6452 PsppSheetViewChild *child = NULL;
6455 tmp_list = tree_view->priv->children;
6458 child = tmp_list->data;
6459 if (child->widget == widget)
6461 gtk_widget_unparent (widget);
6463 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6464 g_list_free_1 (tmp_list);
6465 g_slice_free (PsppSheetViewChild, child);
6469 tmp_list = tmp_list->next;
6472 tmp_list = tree_view->priv->columns;
6476 PsppSheetViewColumn *column;
6477 column = tmp_list->data;
6478 if (column->button == widget)
6480 gtk_widget_unparent (widget);
6483 tmp_list = tmp_list->next;
6488 pspp_sheet_view_forall (GtkContainer *container,
6489 gboolean include_internals,
6490 GtkCallback callback,
6491 gpointer callback_data)
6493 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6494 PsppSheetViewChild *child = NULL;
6495 PsppSheetViewColumn *column;
6498 tmp_list = tree_view->priv->children;
6501 child = tmp_list->data;
6502 tmp_list = tmp_list->next;
6504 (* callback) (child->widget, callback_data);
6506 if (include_internals == FALSE)
6509 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6511 column = tmp_list->data;
6514 (* callback) (column->button, callback_data);
6518 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6519 * cells. If so we draw one big row-spanning focus rectangle.
6522 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6526 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6527 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6529 for (list = tree_view->priv->columns; list; list = list->next)
6531 if (!((PsppSheetViewColumn *)list->data)->visible)
6533 if (_pspp_sheet_view_column_count_special_cells (list->data))
6541 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6542 PsppSheetViewColumn *focus_column,
6543 gboolean clamp_column_visible)
6545 g_return_if_fail (focus_column != NULL);
6547 tree_view->priv->focus_column = focus_column;
6548 if (!focus_column->button)
6550 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6551 g_return_if_fail (focus_column->button != NULL);
6554 if (GTK_CONTAINER (tree_view)->focus_child != focus_column->button)
6555 gtk_widget_grab_focus (focus_column->button);
6557 if (clamp_column_visible)
6558 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6561 /* Returns TRUE if the focus is within the headers, after the focus operation is
6565 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6566 GtkDirectionType dir,
6567 gboolean clamp_column_visible)
6569 GtkWidget *focus_child;
6570 PsppSheetViewColumn *focus_column;
6571 GList *last_column, *first_column;
6575 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6578 focus_child = GTK_CONTAINER (tree_view)->focus_child;
6580 first_column = tree_view->priv->columns;
6581 while (first_column)
6583 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6585 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6587 first_column = first_column->next;
6590 /* No headers are visible, or are focusable. We can't focus in or out.
6592 if (first_column == NULL)
6595 last_column = g_list_last (tree_view->priv->columns);
6598 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6600 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6602 last_column = last_column->prev;
6606 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6610 case GTK_DIR_TAB_BACKWARD:
6611 case GTK_DIR_TAB_FORWARD:
6614 if (focus_child == NULL)
6616 if (tree_view->priv->focus_column != NULL &&
6617 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6618 focus_column = tree_view->priv->focus_column;
6620 focus_column = first_column->data;
6621 pspp_sheet_view_focus_column (tree_view, focus_column,
6622 clamp_column_visible);
6629 if (focus_child == NULL)
6631 if (tree_view->priv->focus_column != NULL)
6632 focus_column = tree_view->priv->focus_column;
6633 else if (dir == GTK_DIR_LEFT)
6634 focus_column = last_column->data;
6636 focus_column = first_column->data;
6637 pspp_sheet_view_focus_column (tree_view, focus_column,
6638 clamp_column_visible);
6642 if (gtk_widget_child_focus (focus_child, dir))
6644 /* The focus moves inside the button. */
6645 /* This is probably a great example of bad UI */
6646 if (clamp_column_visible)
6647 pspp_sheet_view_clamp_column_visible (tree_view,
6648 tree_view->priv->focus_column,
6653 /* We need to move the focus among the row of buttons. */
6654 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6655 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6658 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6659 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6661 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6667 PsppSheetViewColumn *column;
6669 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6670 tmp_list = tmp_list->next;
6672 tmp_list = tmp_list->prev;
6674 if (tmp_list == NULL)
6676 g_warning ("Internal button not found");
6679 column = tmp_list->data;
6680 if (column->button &&
6682 pspp_sheet_view_column_can_focus (column))
6684 pspp_sheet_view_focus_column (tree_view, column,
6685 clamp_column_visible);
6692 g_assert_not_reached ();
6699 /* This function returns in 'path' the first focusable path, if the given path
6700 * is already focusable, it's the returned one.
6704 search_first_focusable_path (PsppSheetView *tree_view,
6706 gboolean search_forward,
6709 /* XXX this function is trivial given that the sheetview doesn't support
6713 if (!path || !*path)
6716 _pspp_sheet_view_find_node (tree_view, *path, &node);
6724 return (*path != NULL);
6728 pspp_sheet_view_focus (GtkWidget *widget,
6729 GtkDirectionType direction)
6731 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6732 GtkContainer *container = GTK_CONTAINER (widget);
6733 GtkWidget *focus_child;
6735 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6738 focus_child = container->focus_child;
6740 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6741 /* Case 1. Headers currently have focus. */
6748 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6750 case GTK_DIR_TAB_BACKWARD:
6753 case GTK_DIR_TAB_FORWARD:
6755 gtk_widget_grab_focus (widget);
6758 g_assert_not_reached ();
6763 /* Case 2. We don't have focus at all. */
6764 if (!gtk_widget_has_focus (widget))
6766 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6767 gtk_widget_grab_focus (widget);
6771 /* Case 3. We have focus already. */
6772 if (direction == GTK_DIR_TAB_BACKWARD)
6773 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6774 else if (direction == GTK_DIR_TAB_FORWARD)
6777 /* Other directions caught by the keybindings */
6778 gtk_widget_grab_focus (widget);
6783 pspp_sheet_view_grab_focus (GtkWidget *widget)
6785 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6787 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6791 pspp_sheet_view_style_set (GtkWidget *widget,
6792 GtkStyle *previous_style)
6794 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6796 PsppSheetViewColumn *column;
6798 if (gtk_widget_get_realized (widget))
6800 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
6801 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
6802 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
6804 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6807 gtk_widget_style_get (widget,
6808 "expander-size", &tree_view->priv->expander_size,
6810 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6812 for (list = tree_view->priv->columns; list; list = list->next)
6814 column = list->data;
6815 _pspp_sheet_view_column_cell_set_dirty (column);
6818 tree_view->priv->fixed_height = -1;
6820 /* Invalidate cached button style. */
6821 if (tree_view->priv->button_style)
6823 g_object_unref (tree_view->priv->button_style);
6824 tree_view->priv->button_style = NULL;
6827 gtk_widget_queue_resize (widget);
6832 pspp_sheet_view_set_focus_child (GtkContainer *container,
6835 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6838 for (list = tree_view->priv->columns; list; list = list->next)
6840 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6842 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6847 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6851 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6852 GtkAdjustment *hadj,
6853 GtkAdjustment *vadj)
6855 gboolean need_adjust = FALSE;
6857 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6860 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6862 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6864 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
6866 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6868 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
6870 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
6871 pspp_sheet_view_adjustment_changed,
6873 g_object_unref (tree_view->priv->hadjustment);
6876 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
6878 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
6879 pspp_sheet_view_adjustment_changed,
6881 g_object_unref (tree_view->priv->vadjustment);
6884 if (tree_view->priv->hadjustment != hadj)
6886 tree_view->priv->hadjustment = hadj;
6887 g_object_ref_sink (tree_view->priv->hadjustment);
6889 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
6890 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6895 if (tree_view->priv->vadjustment != vadj)
6897 tree_view->priv->vadjustment = vadj;
6898 g_object_ref_sink (tree_view->priv->vadjustment);
6900 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
6901 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6907 pspp_sheet_view_adjustment_changed (NULL, tree_view);
6912 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
6913 GtkMovementStep step,
6916 GdkModifierType state;
6918 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
6919 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
6920 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
6921 step == GTK_MOVEMENT_DISPLAY_LINES ||
6922 step == GTK_MOVEMENT_PAGES ||
6923 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
6925 if (tree_view->priv->row_count == 0)
6927 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
6930 pspp_sheet_view_stop_editing (tree_view, FALSE);
6931 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
6932 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
6934 if (gtk_get_current_event_state (&state))
6936 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
6937 tree_view->priv->ctrl_pressed = TRUE;
6938 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
6939 tree_view->priv->shift_pressed = TRUE;
6941 /* else we assume not pressed */
6945 /* currently we make no distinction. When we go bi-di, we need to */
6946 case GTK_MOVEMENT_LOGICAL_POSITIONS:
6947 case GTK_MOVEMENT_VISUAL_POSITIONS:
6948 pspp_sheet_view_move_cursor_left_right (tree_view, count);
6950 case GTK_MOVEMENT_DISPLAY_LINES:
6951 pspp_sheet_view_move_cursor_up_down (tree_view, count);
6953 case GTK_MOVEMENT_PAGES:
6954 pspp_sheet_view_move_cursor_page_up_down (tree_view, count);
6956 case GTK_MOVEMENT_BUFFER_ENDS:
6957 pspp_sheet_view_move_cursor_start_end (tree_view, count);
6960 g_assert_not_reached ();
6963 tree_view->priv->ctrl_pressed = FALSE;
6964 tree_view->priv->shift_pressed = FALSE;
6970 pspp_sheet_view_put (PsppSheetView *tree_view,
6971 GtkWidget *child_widget,
6972 /* in bin_window coordinates */
6978 PsppSheetViewChild *child;
6980 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6981 g_return_if_fail (GTK_IS_WIDGET (child_widget));
6983 child = g_slice_new (PsppSheetViewChild);
6985 child->widget = child_widget;
6988 child->width = width;
6989 child->height = height;
6991 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
6993 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
6994 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
6996 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7000 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7002 /* in tree coordinates */
7008 PsppSheetViewChild *child = NULL;
7010 GdkRectangle allocation;
7012 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7013 g_return_if_fail (GTK_IS_WIDGET (widget));
7015 for (list = tree_view->priv->children; list; list = list->next)
7017 if (((PsppSheetViewChild *)list->data)->widget == widget)
7026 allocation.x = child->x = x;
7027 allocation.y = child->y = y;
7028 allocation.width = child->width = width;
7029 allocation.height = child->height = height;
7031 if (gtk_widget_get_realized (widget))
7032 gtk_widget_size_allocate (widget, &allocation);
7036 /* TreeModel Callbacks
7040 pspp_sheet_view_row_changed (GtkTreeModel *model,
7045 PsppSheetView *tree_view = (PsppSheetView *)data;
7047 gboolean free_path = FALSE;
7048 GtkTreePath *cursor_path;
7050 g_return_if_fail (path != NULL || iter != NULL);
7052 if (tree_view->priv->cursor != NULL)
7053 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7057 if (tree_view->priv->edited_column &&
7058 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7059 pspp_sheet_view_stop_editing (tree_view, TRUE);
7061 if (cursor_path != NULL)
7062 gtk_tree_path_free (cursor_path);
7066 path = gtk_tree_model_get_path (model, iter);
7069 else if (iter == NULL)
7070 gtk_tree_model_get_iter (model, iter, path);
7072 _pspp_sheet_view_find_node (tree_view,
7078 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7079 pspp_sheet_view_node_queue_redraw (tree_view, node);
7083 gtk_tree_path_free (path);
7087 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7092 PsppSheetView *tree_view = (PsppSheetView *) data;
7095 gint height = tree_view->priv->fixed_height;
7096 gboolean free_path = FALSE;
7097 gboolean node_visible = TRUE;
7099 g_return_if_fail (path != NULL || iter != NULL);
7103 path = gtk_tree_model_get_path (model, iter);
7106 else if (iter == NULL)
7107 gtk_tree_model_get_iter (model, iter, path);
7109 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7111 /* Update all row-references */
7112 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7113 indices = gtk_tree_path_get_indices (path);
7114 tmpnode = indices[0];
7116 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7120 if (node_visible && node_is_visible (tree_view, tmpnode))
7121 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7123 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7126 install_presize_handler (tree_view);
7128 gtk_tree_path_free (path);
7132 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7136 PsppSheetView *tree_view = (PsppSheetView *)data;
7139 g_return_if_fail (path != NULL);
7141 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7143 _pspp_sheet_view_find_node (tree_view, path, &node);
7148 range_tower_delete (tree_view->priv->selected, node, 1);
7150 /* Ensure we don't have a dangling pointer to a dead node */
7151 ensure_unprelighted (tree_view);
7153 /* Cancel editting if we've started */
7154 pspp_sheet_view_stop_editing (tree_view, TRUE);
7156 if (tree_view->priv->destroy_count_func)
7158 gint child_count = 0;
7159 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7162 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7164 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7166 gtk_tree_row_reference_free (tree_view->priv->top_row);
7167 tree_view->priv->top_row = NULL;
7170 install_scroll_sync_handler (tree_view);
7172 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7175 if (helper_data.changed)
7176 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7181 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7182 GtkTreePath *parent,
7187 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7190 /* XXX need to adjust selection */
7191 len = gtk_tree_model_iter_n_children (model, iter);
7196 gtk_tree_row_reference_reordered (G_OBJECT (data),
7201 if (gtk_tree_path_get_depth (parent) != 0)
7204 if (tree_view->priv->edited_column)
7205 pspp_sheet_view_stop_editing (tree_view, TRUE);
7207 /* we need to be unprelighted */
7208 ensure_unprelighted (tree_view);
7210 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7212 pspp_sheet_view_dy_to_top_row (tree_view);
7216 /* Internal tree functions
7221 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7222 PsppSheetViewColumn *column,
7226 PsppSheetViewColumn *tmp_column = NULL;
7237 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7240 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7242 list = (rtl ? list->prev : list->next))
7244 tmp_column = list->data;
7246 if (tmp_column == column)
7249 if (tmp_column->visible)
7250 total_width += tmp_column->width;
7253 if (tmp_column != column)
7255 g_warning (G_STRLOC": passed-in column isn't in the tree");
7264 if (column->visible)
7265 *x2 = total_width + column->width;
7267 *x2 = total_width; /* width of 0 */
7271 /* Make sure the node is visible vertically */
7273 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7276 gint node_dy, height;
7277 GtkTreePath *path = NULL;
7279 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7282 /* just return if the node is visible, avoiding a costly expose */
7283 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7284 height = ROW_HEIGHT (tree_view);
7285 if (node_dy >= tree_view->priv->vadjustment->value
7286 && node_dy + height <= (tree_view->priv->vadjustment->value
7287 + tree_view->priv->vadjustment->page_size))
7290 path = _pspp_sheet_view_find_path (tree_view, node);
7293 /* We process updates because we want to clear old selected items when we scroll.
7294 * if this is removed, we get a "selection streak" at the bottom. */
7295 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7296 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7297 gtk_tree_path_free (path);
7302 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7303 PsppSheetViewColumn *column,
7304 gboolean focus_to_cell)
7311 x = column->allocation.x;
7312 width = column->allocation.width;
7314 if (width > tree_view->priv->hadjustment->page_size)
7316 /* The column is larger than the horizontal page size. If the
7317 * column has cells which can be focussed individually, then we make
7318 * sure the cell which gets focus is fully visible (if even the
7319 * focus cell is bigger than the page size, we make sure the
7320 * left-hand side of the cell is visible).
7322 * If the column does not have those so-called special cells, we
7323 * make sure the left-hand side of the column is visible.
7326 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7328 GtkTreePath *cursor_path;
7329 GdkRectangle background_area, cell_area, focus_area;
7331 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7333 pspp_sheet_view_get_cell_area (tree_view,
7334 cursor_path, column, &cell_area);
7335 pspp_sheet_view_get_background_area (tree_view,
7336 cursor_path, column,
7339 gtk_tree_path_free (cursor_path);
7341 _pspp_sheet_view_column_get_focus_area (column,
7347 width = focus_area.width;
7349 if (width < tree_view->priv->hadjustment->page_size)
7351 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7352 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7353 x + width - tree_view->priv->hadjustment->page_size);
7354 else if (tree_view->priv->hadjustment->value > x)
7355 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7359 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7361 tree_view->priv->hadjustment->lower,
7362 tree_view->priv->hadjustment->upper
7363 - tree_view->priv->hadjustment->page_size));
7367 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7368 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7369 x + width - tree_view->priv->hadjustment->page_size);
7370 else if (tree_view->priv->hadjustment->value > x)
7371 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7376 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7381 path = gtk_tree_path_new ();
7383 gtk_tree_path_append_index (path, node);
7388 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7392 gint *indices = gtk_tree_path_get_indices (path);
7393 gint depth = gtk_tree_path_get_depth (path);
7396 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7402 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7405 gboolean add_shifted_binding,
7406 GtkMovementStep step,
7410 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7415 if (add_shifted_binding)
7416 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7421 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7424 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7429 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7436 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7437 PsppSheetViewColumn *column)
7439 PsppSheetViewColumn *left_column;
7440 PsppSheetViewColumn *cur_column = NULL;
7441 PsppSheetViewColumnReorder *reorder;
7446 /* We want to precalculate the motion list such that we know what column slots
7450 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7452 /* First, identify all possible drop spots */
7454 tmp_list = g_list_last (tree_view->priv->columns);
7456 tmp_list = g_list_first (tree_view->priv->columns);
7460 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7461 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7463 if (cur_column->visible == FALSE)
7466 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7467 if (left_column != column && cur_column != column &&
7468 tree_view->priv->column_drop_func &&
7469 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7471 left_column = cur_column;
7474 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7475 reorder->left_column = left_column;
7476 left_column = reorder->right_column = cur_column;
7478 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7481 /* Add the last one */
7482 if (tree_view->priv->column_drop_func == NULL ||
7483 ((left_column != column) &&
7484 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7486 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7487 reorder->left_column = left_column;
7488 reorder->right_column = NULL;
7489 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7492 /* We quickly check to see if it even makes sense to reorder columns. */
7493 /* If there is nothing that can be moved, then we return */
7495 if (tree_view->priv->column_drag_info == NULL)
7498 /* We know there are always 2 slots possbile, as you can always return column. */
7499 /* If that's all there is, return */
7500 if (tree_view->priv->column_drag_info->next == NULL ||
7501 (tree_view->priv->column_drag_info->next->next == NULL &&
7502 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7503 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7505 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7506 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7507 g_list_free (tree_view->priv->column_drag_info);
7508 tree_view->priv->column_drag_info = NULL;
7511 /* We fill in the ranges for the columns, now that we've isolated them */
7512 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7514 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7516 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7518 reorder->left_align = left;
7519 if (tmp_list->next != NULL)
7521 g_assert (tmp_list->next->data);
7522 left = reorder->right_align = (reorder->right_column->allocation.x +
7523 reorder->right_column->allocation.width +
7524 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7530 gdk_drawable_get_size (tree_view->priv->header_window, &width, NULL);
7531 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7537 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7538 PsppSheetViewColumn *column)
7540 GdkEvent *send_event;
7541 GtkAllocation allocation;
7542 gint x, y, width, height;
7543 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7544 GdkDisplay *display = gdk_screen_get_display (screen);
7546 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7547 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7548 g_return_if_fail (column->button);
7550 pspp_sheet_view_set_column_drag_info (tree_view, column);
7552 if (tree_view->priv->column_drag_info == NULL)
7555 if (tree_view->priv->drag_window == NULL)
7557 GdkWindowAttr attributes;
7558 guint attributes_mask;
7560 attributes.window_type = GDK_WINDOW_CHILD;
7561 attributes.wclass = GDK_INPUT_OUTPUT;
7562 attributes.x = column->allocation.x;
7564 attributes.width = column->allocation.width;
7565 attributes.height = column->allocation.height;
7566 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7567 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
7568 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7569 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
7571 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7574 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7577 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7578 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7580 gtk_grab_remove (column->button);
7582 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7583 send_event->crossing.send_event = TRUE;
7584 send_event->crossing.window = g_object_ref (GTK_BUTTON (column->button)->event_window);
7585 send_event->crossing.subwindow = NULL;
7586 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7587 send_event->crossing.time = GDK_CURRENT_TIME;
7589 gtk_propagate_event (column->button, send_event);
7590 gdk_event_free (send_event);
7592 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7593 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7594 send_event->button.send_event = TRUE;
7595 send_event->button.time = GDK_CURRENT_TIME;
7596 send_event->button.x = -1;
7597 send_event->button.y = -1;
7598 send_event->button.axes = NULL;
7599 send_event->button.state = 0;
7600 send_event->button.button = 1;
7601 send_event->button.device = gdk_display_get_core_pointer (display);
7602 send_event->button.x_root = 0;
7603 send_event->button.y_root = 0;
7605 gtk_propagate_event (column->button, send_event);
7606 gdk_event_free (send_event);
7608 /* Kids, don't try this at home */
7609 g_object_ref (column->button);
7610 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7611 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7612 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7613 g_object_unref (column->button);
7615 tree_view->priv->drag_column_x = column->allocation.x;
7616 allocation = column->allocation;
7618 gtk_widget_size_allocate (column->button, &allocation);
7619 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7621 tree_view->priv->drag_column = column;
7622 gdk_window_show (tree_view->priv->drag_window);
7624 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7625 gdk_drawable_get_size (tree_view->priv->header_window, &width, &height);
7627 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7628 while (gtk_events_pending ())
7629 gtk_main_iteration ();
7631 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7632 gdk_pointer_grab (tree_view->priv->drag_window,
7634 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7635 NULL, NULL, GDK_CURRENT_TIME);
7636 gdk_keyboard_grab (tree_view->priv->drag_window,
7642 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7644 const GdkRectangle *clip_rect)
7648 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7652 rect.width = MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width);
7654 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7655 rect.height = ROW_HEIGHT (tree_view);
7659 GdkRectangle new_rect;
7661 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7663 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7667 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7672 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7674 const GdkRectangle *clip_rect)
7678 _pspp_sheet_view_find_node (tree_view, path, &node);
7681 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7685 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7688 GtkTreePath *cursor_path;
7690 if ((tree_view->priv->row_count == 0) ||
7691 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7695 if (tree_view->priv->cursor)
7696 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7698 if (cursor_path == NULL)
7700 /* There's no cursor. Move the cursor to the first selected row, if any
7701 * are selected, otherwise to the first row in the sheetview.
7703 GList *selected_rows;
7704 GtkTreeModel *model;
7705 PsppSheetSelection *selection;
7707 selection = pspp_sheet_view_get_selection (tree_view);
7708 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7712 /* XXX we could avoid doing O(n) work to get this result */
7713 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7714 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7715 g_list_free (selected_rows);
7719 cursor_path = gtk_tree_path_new_first ();
7720 search_first_focusable_path (tree_view, &cursor_path,
7724 gtk_tree_row_reference_free (tree_view->priv->cursor);
7725 tree_view->priv->cursor = NULL;
7729 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7730 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7731 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE);
7733 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
7739 /* Now find a column for the cursor. */
7740 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7742 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7743 gtk_tree_path_free (cursor_path);
7745 if (tree_view->priv->focus_column == NULL)
7748 for (list = tree_view->priv->columns; list; list = list->next)
7750 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7752 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7753 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7754 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7764 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7767 gint selection_count;
7768 int cursor_node = -1;
7769 int new_cursor_node = -1;
7770 GtkTreePath *cursor_path = NULL;
7771 gboolean grab_focus = TRUE;
7773 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7777 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7778 /* FIXME: we lost the cursor; should we get the first? */
7781 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7782 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7784 if (cursor_node < 0)
7785 /* FIXME: we lost the cursor; should we get the first? */
7788 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7790 if (selection_count == 0
7791 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7792 && !tree_view->priv->ctrl_pressed)
7794 /* Don't move the cursor, but just select the current node */
7795 new_cursor_node = cursor_node;
7800 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7802 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7805 gtk_tree_path_free (cursor_path);
7807 if (new_cursor_node)
7809 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7811 search_first_focusable_path (tree_view, &cursor_path,
7816 gtk_tree_path_free (cursor_path);
7820 * If the list has only one item and multi-selection is set then select
7821 * the row (if not yet selected).
7823 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7824 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7825 new_cursor_node < 0)
7828 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7830 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7832 if (new_cursor_node < 0
7833 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7835 new_cursor_node = cursor_node;
7839 new_cursor_node = -1;
7843 if (new_cursor_node >= 0)
7845 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7846 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE);
7847 gtk_tree_path_free (cursor_path);
7851 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7853 if (!tree_view->priv->shift_pressed)
7855 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7857 GTK_DIR_UP : GTK_DIR_DOWN))
7859 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
7862 gtk_widget_child_focus (toplevel,
7864 GTK_DIR_TAB_BACKWARD :
7865 GTK_DIR_TAB_FORWARD);
7872 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7877 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7881 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
7884 int cursor_node = -1;
7885 GtkTreePath *old_cursor_path = NULL;
7886 GtkTreePath *cursor_path = NULL;
7887 int start_cursor_node = -1;
7890 gint vertical_separator;
7892 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7895 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
7896 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7898 /* This is sorta weird. Focus in should give us a cursor */
7901 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
7902 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
7904 if (cursor_node < 0)
7906 /* FIXME: we lost the cursor. Should we try to get one? */
7907 gtk_tree_path_free (old_cursor_path);
7911 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7912 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
7913 y += tree_view->priv->cursor_offset;
7914 y += count * (int)tree_view->priv->vadjustment->page_increment;
7915 y = CLAMP (y, (gint)tree_view->priv->vadjustment->lower, (gint)tree_view->priv->vadjustment->upper - vertical_separator);
7917 if (y >= tree_view->priv->height)
7918 y = tree_view->priv->height - 1;
7920 tree_view->priv->cursor_offset =
7921 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
7923 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
7925 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7926 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
7929 y -= tree_view->priv->cursor_offset;
7930 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7932 start_cursor_node = cursor_node;
7934 if (! search_first_focusable_path (tree_view, &cursor_path,
7938 /* It looks like we reached the end of the view without finding
7939 * a focusable row. We will step backwards to find the last
7942 cursor_node = start_cursor_node;
7943 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7945 search_first_focusable_path (tree_view, &cursor_path,
7954 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7956 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
7959 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
7960 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7961 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
7963 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
7964 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7966 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7969 gtk_tree_path_free (old_cursor_path);
7970 gtk_tree_path_free (cursor_path);
7974 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
7977 int cursor_node = -1;
7978 GtkTreePath *cursor_path = NULL;
7979 PsppSheetViewColumn *column;
7982 gboolean found_column = FALSE;
7985 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7987 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7990 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
7991 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7995 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7996 if (cursor_node < 0)
7998 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8000 gtk_tree_path_free (cursor_path);
8003 gtk_tree_path_free (cursor_path);
8005 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8006 if (tree_view->priv->focus_column)
8008 for (; list; list = (rtl ? list->prev : list->next))
8010 if (list->data == tree_view->priv->focus_column)
8017 gboolean left, right;
8019 column = list->data;
8020 if (column->visible == FALSE)
8023 pspp_sheet_view_column_cell_set_cell_data (column,
8024 tree_view->priv->model,
8029 right = list->prev ? TRUE : FALSE;
8030 left = list->next ? TRUE : FALSE;
8034 left = list->prev ? TRUE : FALSE;
8035 right = list->next ? TRUE : FALSE;
8038 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8040 tree_view->priv->focus_column = column;
8041 found_column = TRUE;
8046 list = rtl ? list->prev : list->next;
8048 list = rtl ? list->next : list->prev;
8053 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8054 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8055 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8059 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8062 pspp_sheet_view_clamp_column_visible (tree_view,
8063 tree_view->priv->focus_column, TRUE);
8067 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8072 GtkTreePath *old_path;
8074 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8077 g_return_if_fail (tree_view->priv->row_count > 0);
8079 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8083 /* Now go forward to find the first focusable row. */
8084 path = _pspp_sheet_view_find_path (tree_view, 0);
8085 search_first_focusable_path (tree_view, &path,
8086 TRUE, &cursor_node);
8090 /* Now go backwards to find last focusable row. */
8091 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8092 search_first_focusable_path (tree_view, &path,
8093 FALSE, &cursor_node);
8099 if (gtk_tree_path_compare (old_path, path))
8101 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
8102 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8106 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8110 gtk_tree_path_free (old_path);
8111 gtk_tree_path_free (path);
8115 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8117 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8120 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8121 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8124 pspp_sheet_selection_select_all (tree_view->priv->selection);
8130 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8132 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8135 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8136 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8139 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8145 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8146 gboolean start_editing)
8149 int cursor_node = -1;
8150 GtkTreePath *cursor_path = NULL;
8151 GtkTreeSelectMode mode = 0;
8153 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8156 if (tree_view->priv->cursor)
8157 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8159 if (cursor_path == NULL)
8162 _pspp_sheet_view_find_node (tree_view, cursor_path,
8165 if (cursor_node < 0)
8167 gtk_tree_path_free (cursor_path);
8171 if (!tree_view->priv->shift_pressed && start_editing &&
8172 tree_view->priv->focus_column)
8174 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8176 gtk_tree_path_free (cursor_path);
8181 if (tree_view->priv->ctrl_pressed)
8182 mode |= GTK_TREE_SELECT_MODE_TOGGLE;
8183 if (tree_view->priv->shift_pressed)
8184 mode |= GTK_TREE_SELECT_MODE_EXTEND;
8186 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8192 /* We bail out if the original (tree, node) don't exist anymore after
8193 * handling the selection-changed callback. We do return TRUE because
8194 * the key press has been handled at this point.
8196 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8198 if (cursor_node != new_node)
8201 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8203 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8204 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8206 if (!tree_view->priv->shift_pressed)
8207 pspp_sheet_view_row_activated (tree_view, cursor_path,
8208 tree_view->priv->focus_column);
8210 gtk_tree_path_free (cursor_path);
8216 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8219 int cursor_node = -1;
8220 GtkTreePath *cursor_path = NULL;
8222 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8226 if (tree_view->priv->cursor)
8227 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8229 if (cursor_path == NULL)
8232 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8233 if (cursor_node < 0)
8235 gtk_tree_path_free (cursor_path);
8239 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8242 GTK_TREE_SELECT_MODE_TOGGLE,
8245 /* We bail out if the original (tree, node) don't exist anymore after
8246 * handling the selection-changed callback. We do return TRUE because
8247 * the key press has been handled at this point.
8249 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8251 if (cursor_node != new_node)
8254 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8256 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8257 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8258 gtk_tree_path_free (cursor_path);
8264 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8266 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8267 tree_view->priv->typeselect_flush_timeout = 0;
8272 /* Cut and paste from gtkwindow.c */
8274 send_focus_change (GtkWidget *widget,
8277 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8279 g_object_ref (widget);
8282 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
8284 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
8286 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8287 fevent->focus_change.window = g_object_ref (widget->window);
8288 fevent->focus_change.in = in;
8290 gtk_widget_event (widget, fevent);
8292 g_object_notify (G_OBJECT (widget), "has-focus");
8294 g_object_unref (widget);
8295 gdk_event_free (fevent);
8299 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8301 GtkWidget *frame, *vbox, *toplevel;
8304 if (tree_view->priv->search_custom_entry_set)
8307 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8308 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8310 if (tree_view->priv->search_window != NULL)
8312 if (GTK_WINDOW (toplevel)->group)
8313 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8314 GTK_WINDOW (tree_view->priv->search_window));
8315 else if (GTK_WINDOW (tree_view->priv->search_window)->group)
8316 gtk_window_group_remove_window (GTK_WINDOW (tree_view->priv->search_window)->group,
8317 GTK_WINDOW (tree_view->priv->search_window));
8318 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8322 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8323 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8325 if (GTK_WINDOW (toplevel)->group)
8326 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8327 GTK_WINDOW (tree_view->priv->search_window));
8329 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8330 GDK_WINDOW_TYPE_HINT_UTILITY);
8331 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8332 g_signal_connect (tree_view->priv->search_window, "delete-event",
8333 G_CALLBACK (pspp_sheet_view_search_delete_event),
8335 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8336 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8338 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8339 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8341 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8342 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8345 frame = gtk_frame_new (NULL);
8346 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8347 gtk_widget_show (frame);
8348 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8350 vbox = gtk_vbox_new (FALSE, 0);
8351 gtk_widget_show (vbox);
8352 gtk_container_add (GTK_CONTAINER (frame), vbox);
8353 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8356 tree_view->priv->search_entry = gtk_entry_new ();
8357 gtk_widget_show (tree_view->priv->search_entry);
8358 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8359 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8361 g_signal_connect (tree_view->priv->search_entry,
8362 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8364 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8366 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8368 gtk_container_add (GTK_CONTAINER (vbox),
8369 tree_view->priv->search_entry);
8371 gtk_widget_realize (tree_view->priv->search_entry);
8374 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8375 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8378 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8379 gboolean keybinding)
8381 /* We only start interactive search if we have focus or the columns
8382 * have focus. If one of our children have focus, we don't want to
8386 gboolean found_focus = FALSE;
8387 GtkWidgetClass *entry_parent_class;
8389 if (!tree_view->priv->enable_search && !keybinding)
8392 if (tree_view->priv->search_custom_entry_set)
8395 if (tree_view->priv->search_window != NULL &&
8396 gtk_widget_get_visible (tree_view->priv->search_window))
8399 for (list = tree_view->priv->columns; list; list = list->next)
8401 PsppSheetViewColumn *column;
8403 column = list->data;
8404 if (! column->visible)
8407 if (column->button && gtk_widget_has_focus (column->button))
8414 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8420 if (tree_view->priv->search_column < 0)
8423 pspp_sheet_view_ensure_interactive_directory (tree_view);
8426 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8429 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8430 gtk_widget_show (tree_view->priv->search_window);
8431 if (tree_view->priv->search_entry_changed_id == 0)
8433 tree_view->priv->search_entry_changed_id =
8434 g_signal_connect (tree_view->priv->search_entry, "changed",
8435 G_CALLBACK (pspp_sheet_view_search_init),
8439 tree_view->priv->typeselect_flush_timeout =
8440 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8441 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8444 /* Grab focus will select all the text. We don't want that to happen, so we
8445 * call the parent instance and bypass the selection change. This is probably
8446 * really non-kosher. */
8447 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8448 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8450 /* send focus-in event */
8451 send_focus_change (tree_view->priv->search_entry, TRUE);
8453 /* search first matching iter */
8454 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8460 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8462 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8465 /* this function returns the new width of the column being resized given
8466 * the column and x position of the cursor; the x cursor position is passed
8467 * in as a pointer and automagicly corrected if it's beyond min/max limits
8470 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8474 PsppSheetViewColumn *column;
8478 /* first translate the x position from widget->window
8479 * to clist->clist_window
8481 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8482 column = g_list_nth (tree_view->priv->columns, i)->data;
8483 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8485 /* Clamp down the value */
8486 if (column->min_width == -1)
8487 width = MAX (column->button_request, width);
8489 width = MAX (column->min_width, width);
8490 if (column->max_width != -1)
8491 width = MIN (width, column->max_width);
8493 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8499 /* FIXME this adjust_allocation is a big cut-and-paste from
8500 * GtkCList, needs to be some "official" way to do this
8510 /* The window to which widget->window is relative */
8511 #define ALLOCATION_WINDOW(widget) \
8512 (!gtk_widget_get_has_window (widget) ? \
8513 (widget)->window : \
8514 gdk_window_get_parent ((widget)->window))
8517 adjust_allocation_recurse (GtkWidget *widget,
8520 ScrollData *scroll_data = data;
8522 /* Need to really size allocate instead of just poking
8523 * into widget->allocation if the widget is not realized.
8524 * FIXME someone figure out why this was.
8526 if (!gtk_widget_get_realized (widget))
8528 if (gtk_widget_get_visible (widget))
8530 GdkRectangle tmp_rectangle = widget->allocation;
8531 tmp_rectangle.x += scroll_data->dx;
8532 tmp_rectangle.y += scroll_data->dy;
8534 gtk_widget_size_allocate (widget, &tmp_rectangle);
8539 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8541 widget->allocation.x += scroll_data->dx;
8542 widget->allocation.y += scroll_data->dy;
8544 if (GTK_IS_CONTAINER (widget))
8545 gtk_container_forall (GTK_CONTAINER (widget),
8546 adjust_allocation_recurse,
8553 adjust_allocation (GtkWidget *widget,
8557 ScrollData scroll_data;
8559 if (gtk_widget_get_realized (widget))
8560 scroll_data.window = ALLOCATION_WINDOW (widget);
8562 scroll_data.window = NULL;
8564 scroll_data.dx = dx;
8565 scroll_data.dy = dy;
8567 adjust_allocation_recurse (widget, &scroll_data);
8571 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8575 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8576 PsppSheetView *tree_view)
8578 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8583 gdk_window_move (tree_view->priv->bin_window,
8584 - tree_view->priv->hadjustment->value,
8585 TREE_VIEW_HEADER_HEIGHT (tree_view));
8586 gdk_window_move (tree_view->priv->header_window,
8587 - tree_view->priv->hadjustment->value,
8589 dy = tree_view->priv->dy - (int) tree_view->priv->vadjustment->value;
8592 update_prelight (tree_view,
8593 tree_view->priv->event_last_x,
8594 tree_view->priv->event_last_y - dy);
8596 if (tree_view->priv->edited_column &&
8597 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8601 PsppSheetViewChild *child = NULL;
8603 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8604 adjust_allocation (widget, 0, dy);
8606 for (list = tree_view->priv->children; list; list = list->next)
8608 child = (PsppSheetViewChild *)list->data;
8609 if (child->widget == widget)
8617 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8619 if (tree_view->priv->dy != (int) tree_view->priv->vadjustment->value)
8621 /* update our dy and top_row */
8622 tree_view->priv->dy = (int) tree_view->priv->vadjustment->value;
8624 if (!tree_view->priv->in_top_row_to_dy)
8625 pspp_sheet_view_dy_to_top_row (tree_view);
8628 for (list = tree_view->priv->columns; list; list = list->next)
8630 PsppSheetViewColumn *column = list->data;
8631 GtkAllocation *allocation = &column->allocation;
8633 if (span_intersects (allocation->x, allocation->width,
8634 tree_view->priv->hadjustment->value,
8635 GTK_WIDGET (tree_view)->allocation.width))
8637 pspp_sheet_view_column_set_need_button (column, TRUE);
8638 if (!column->button)
8639 pspp_sheet_view_column_update_button (column);
8651 * pspp_sheet_view_new:
8653 * Creates a new #PsppSheetView widget.
8655 * Return value: A newly created #PsppSheetView widget.
8658 pspp_sheet_view_new (void)
8660 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8664 * pspp_sheet_view_new_with_model:
8665 * @model: the model.
8667 * Creates a new #PsppSheetView widget with the model initialized to @model.
8669 * Return value: A newly created #PsppSheetView widget.
8672 pspp_sheet_view_new_with_model (GtkTreeModel *model)
8674 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
8681 * pspp_sheet_view_get_model:
8682 * @tree_view: a #PsppSheetView
8684 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
8687 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
8690 pspp_sheet_view_get_model (PsppSheetView *tree_view)
8692 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8694 return tree_view->priv->model;
8698 * pspp_sheet_view_set_model:
8699 * @tree_view: A #GtkTreeNode.
8700 * @model: (allow-none): The model.
8702 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
8703 * set, it will remove it before setting the new model. If @model is %NULL,
8704 * then it will unset the old model.
8707 pspp_sheet_view_set_model (PsppSheetView *tree_view,
8708 GtkTreeModel *model)
8710 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8711 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
8713 if (model == tree_view->priv->model)
8716 if (tree_view->priv->scroll_to_path)
8718 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8719 tree_view->priv->scroll_to_path = NULL;
8722 if (tree_view->priv->model)
8724 GList *tmplist = tree_view->priv->columns;
8726 if (tree_view->priv->selected)
8727 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
8728 pspp_sheet_view_stop_editing (tree_view, TRUE);
8730 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8731 pspp_sheet_view_row_changed,
8733 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8734 pspp_sheet_view_row_inserted,
8736 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8737 pspp_sheet_view_row_deleted,
8739 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8740 pspp_sheet_view_rows_reordered,
8743 for (; tmplist; tmplist = tmplist->next)
8744 _pspp_sheet_view_column_unset_model (tmplist->data,
8745 tree_view->priv->model);
8747 tree_view->priv->prelight_node = -1;
8749 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
8750 tree_view->priv->drag_dest_row = NULL;
8751 gtk_tree_row_reference_free (tree_view->priv->cursor);
8752 tree_view->priv->cursor = NULL;
8753 gtk_tree_row_reference_free (tree_view->priv->anchor);
8754 tree_view->priv->anchor = NULL;
8755 gtk_tree_row_reference_free (tree_view->priv->top_row);
8756 tree_view->priv->top_row = NULL;
8757 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8758 tree_view->priv->scroll_to_path = NULL;
8760 tree_view->priv->scroll_to_column = NULL;
8762 g_object_unref (tree_view->priv->model);
8764 tree_view->priv->search_column = -1;
8765 tree_view->priv->fixed_height = -1;
8766 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
8767 tree_view->priv->last_button_x = -1;
8768 tree_view->priv->last_button_y = -1;
8771 tree_view->priv->model = model;
8773 if (tree_view->priv->model)
8777 if (tree_view->priv->search_column == -1)
8779 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
8781 GType type = gtk_tree_model_get_column_type (model, i);
8783 if (g_value_type_transformable (type, G_TYPE_STRING))
8785 tree_view->priv->search_column = i;
8791 g_object_ref (tree_view->priv->model);
8792 g_signal_connect (tree_view->priv->model,
8794 G_CALLBACK (pspp_sheet_view_row_changed),
8796 g_signal_connect (tree_view->priv->model,
8798 G_CALLBACK (pspp_sheet_view_row_inserted),
8800 g_signal_connect (tree_view->priv->model,
8802 G_CALLBACK (pspp_sheet_view_row_deleted),
8804 g_signal_connect (tree_view->priv->model,
8806 G_CALLBACK (pspp_sheet_view_rows_reordered),
8809 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
8811 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
8812 install_presize_handler (tree_view);
8815 g_object_notify (G_OBJECT (tree_view), "model");
8817 if (tree_view->priv->selection)
8818 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
8820 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8821 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
8825 * pspp_sheet_view_get_selection:
8826 * @tree_view: A #PsppSheetView.
8828 * Gets the #PsppSheetSelection associated with @tree_view.
8830 * Return value: A #PsppSheetSelection object.
8832 PsppSheetSelection *
8833 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
8835 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8837 return tree_view->priv->selection;
8841 * pspp_sheet_view_get_hadjustment:
8842 * @tree_view: A #PsppSheetView
8844 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
8846 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8850 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
8852 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8854 if (tree_view->priv->hadjustment == NULL)
8855 pspp_sheet_view_set_hadjustment (tree_view, NULL);
8857 return tree_view->priv->hadjustment;
8861 * pspp_sheet_view_set_hadjustment:
8862 * @tree_view: A #PsppSheetView
8863 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8865 * Sets the #GtkAdjustment for the current horizontal aspect.
8868 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
8869 GtkAdjustment *adjustment)
8871 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8873 pspp_sheet_view_set_adjustments (tree_view,
8875 tree_view->priv->vadjustment);
8877 g_object_notify (G_OBJECT (tree_view), "hadjustment");
8881 * pspp_sheet_view_get_vadjustment:
8882 * @tree_view: A #PsppSheetView
8884 * Gets the #GtkAdjustment currently being used for the vertical aspect.
8886 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8890 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
8892 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8894 if (tree_view->priv->vadjustment == NULL)
8895 pspp_sheet_view_set_vadjustment (tree_view, NULL);
8897 return tree_view->priv->vadjustment;
8901 * pspp_sheet_view_set_vadjustment:
8902 * @tree_view: A #PsppSheetView
8903 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8905 * Sets the #GtkAdjustment for the current vertical aspect.
8908 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
8909 GtkAdjustment *adjustment)
8911 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8913 pspp_sheet_view_set_adjustments (tree_view,
8914 tree_view->priv->hadjustment,
8917 g_object_notify (G_OBJECT (tree_view), "vadjustment");
8920 /* Column and header operations */
8923 * pspp_sheet_view_get_headers_visible:
8924 * @tree_view: A #PsppSheetView.
8926 * Returns %TRUE if the headers on the @tree_view are visible.
8928 * Return value: Whether the headers are visible or not.
8931 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
8933 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
8935 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8939 * pspp_sheet_view_set_headers_visible:
8940 * @tree_view: A #PsppSheetView.
8941 * @headers_visible: %TRUE if the headers are visible
8943 * Sets the visibility state of the headers.
8946 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
8947 gboolean headers_visible)
8951 PsppSheetViewColumn *column;
8953 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8955 headers_visible = !! headers_visible;
8957 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
8960 if (headers_visible)
8961 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8963 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8965 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8967 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
8968 if (headers_visible)
8970 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));
8972 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
8973 pspp_sheet_view_map_buttons (tree_view);
8977 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
8979 for (list = tree_view->priv->columns; list; list = list->next)
8981 column = list->data;
8983 gtk_widget_unmap (column->button);
8985 gdk_window_hide (tree_view->priv->header_window);
8989 tree_view->priv->vadjustment->page_size = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
8990 tree_view->priv->vadjustment->page_increment = (GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2;
8991 tree_view->priv->vadjustment->lower = 0;
8992 tree_view->priv->vadjustment->upper = tree_view->priv->height;
8993 gtk_adjustment_changed (tree_view->priv->vadjustment);
8995 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
8997 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9001 * pspp_sheet_view_columns_autosize:
9002 * @tree_view: A #PsppSheetView.
9004 * Resizes all columns to their optimal width. Only works after the
9005 * treeview has been realized.
9008 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9010 gboolean dirty = FALSE;
9012 PsppSheetViewColumn *column;
9014 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9016 for (list = tree_view->priv->columns; list; list = list->next)
9018 column = list->data;
9019 _pspp_sheet_view_column_cell_set_dirty (column);
9024 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9028 * pspp_sheet_view_set_headers_clickable:
9029 * @tree_view: A #PsppSheetView.
9030 * @setting: %TRUE if the columns are clickable.
9032 * Allow the column title buttons to be clicked.
9035 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9040 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9042 for (list = tree_view->priv->columns; list; list = list->next)
9043 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9045 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9050 * pspp_sheet_view_get_headers_clickable:
9051 * @tree_view: A #PsppSheetView.
9053 * Returns whether all header columns are clickable.
9055 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9060 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9064 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9066 for (list = tree_view->priv->columns; list; list = list->next)
9067 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9074 * pspp_sheet_view_set_rules_hint
9075 * @tree_view: a #PsppSheetView
9076 * @setting: %TRUE if the tree requires reading across rows
9078 * This function tells GTK+ that the user interface for your
9079 * application requires users to read across tree rows and associate
9080 * cells with one another. By default, GTK+ will then render the tree
9081 * with alternating row colors. Do <emphasis>not</emphasis> use it
9082 * just because you prefer the appearance of the ruled tree; that's a
9083 * question for the theme. Some themes will draw tree rows in
9084 * alternating colors even when rules are turned off, and users who
9085 * prefer that appearance all the time can choose those themes. You
9086 * should call this function only as a <emphasis>semantic</emphasis>
9087 * hint to the theme engine that your tree makes alternating colors
9088 * useful from a functional standpoint (since it has lots of columns,
9093 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9096 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9098 setting = setting != FALSE;
9100 if (tree_view->priv->has_rules != setting)
9102 tree_view->priv->has_rules = setting;
9103 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9106 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9110 * pspp_sheet_view_get_rules_hint
9111 * @tree_view: a #PsppSheetView
9113 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9115 * Return value: %TRUE if rules are useful for the user of this tree
9118 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9120 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9122 return tree_view->priv->has_rules;
9125 /* Public Column functions
9129 * pspp_sheet_view_append_column:
9130 * @tree_view: A #PsppSheetView.
9131 * @column: The #PsppSheetViewColumn to add.
9133 * Appends @column to the list of columns.
9135 * Return value: The number of columns in @tree_view after appending.
9138 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9139 PsppSheetViewColumn *column)
9141 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9142 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9143 g_return_val_if_fail (column->tree_view == NULL, -1);
9145 return pspp_sheet_view_insert_column (tree_view, column, -1);
9150 * pspp_sheet_view_remove_column:
9151 * @tree_view: A #PsppSheetView.
9152 * @column: The #PsppSheetViewColumn to remove.
9154 * Removes @column from @tree_view.
9156 * Return value: The number of columns in @tree_view after removing.
9159 pspp_sheet_view_remove_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 == GTK_WIDGET (tree_view), -1);
9166 if (tree_view->priv->focus_column == column)
9167 tree_view->priv->focus_column = NULL;
9169 if (tree_view->priv->edited_column == column)
9171 pspp_sheet_view_stop_editing (tree_view, TRUE);
9173 /* no need to, but just to be sure ... */
9174 tree_view->priv->edited_column = NULL;
9177 _pspp_sheet_view_column_unset_tree_view (column);
9179 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9180 tree_view->priv->n_columns--;
9182 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9186 _pspp_sheet_view_column_unrealize_button (column);
9187 for (list = tree_view->priv->columns; list; list = list->next)
9189 PsppSheetViewColumn *tmp_column;
9191 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9192 if (tmp_column->visible)
9193 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9196 if (tree_view->priv->n_columns == 0 &&
9197 pspp_sheet_view_get_headers_visible (tree_view))
9198 gdk_window_hide (tree_view->priv->header_window);
9200 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9203 g_object_unref (column);
9204 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9206 return tree_view->priv->n_columns;
9210 * pspp_sheet_view_insert_column:
9211 * @tree_view: A #PsppSheetView.
9212 * @column: The #PsppSheetViewColumn to be inserted.
9213 * @position: The position to insert @column in.
9215 * This inserts the @column into the @tree_view at @position. If @position is
9216 * -1, then the column is inserted at the end.
9218 * Return value: The number of columns in @tree_view after insertion.
9221 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9222 PsppSheetViewColumn *column,
9225 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9226 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9227 g_return_val_if_fail (column->tree_view == NULL, -1);
9229 g_object_ref_sink (column);
9231 if (tree_view->priv->n_columns == 0 &&
9232 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9233 pspp_sheet_view_get_headers_visible (tree_view))
9235 gdk_window_show (tree_view->priv->header_window);
9238 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9240 tree_view->priv->n_columns++;
9242 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9244 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9248 _pspp_sheet_view_column_realize_button (column);
9250 for (list = tree_view->priv->columns; list; list = list->next)
9252 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9253 if (column->visible)
9254 _pspp_sheet_view_column_cell_set_dirty (column);
9256 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9259 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9261 return tree_view->priv->n_columns;
9265 * pspp_sheet_view_insert_column_with_attributes:
9266 * @tree_view: A #PsppSheetView
9267 * @position: The position to insert the new column in.
9268 * @title: The title to set the header to.
9269 * @cell: The #GtkCellRenderer.
9270 * @Varargs: A %NULL-terminated list of attributes.
9272 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9273 * @position. If @position is -1, then the newly created column is inserted at
9274 * the end. The column is initialized with the attributes given.
9276 * Return value: The number of columns in @tree_view after insertion.
9279 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9282 GtkCellRenderer *cell,
9285 PsppSheetViewColumn *column;
9290 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9292 column = pspp_sheet_view_column_new ();
9293 pspp_sheet_view_column_set_title (column, title);
9294 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9296 va_start (args, cell);
9298 attribute = va_arg (args, gchar *);
9300 while (attribute != NULL)
9302 column_id = va_arg (args, gint);
9303 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9304 attribute = va_arg (args, gchar *);
9309 pspp_sheet_view_insert_column (tree_view, column, position);
9311 return tree_view->priv->n_columns;
9315 * pspp_sheet_view_insert_column_with_data_func:
9316 * @tree_view: a #PsppSheetView
9317 * @position: Position to insert, -1 for append
9318 * @title: column title
9319 * @cell: cell renderer for column
9320 * @func: function to set attributes of cell renderer
9321 * @data: data for @func
9322 * @dnotify: destroy notifier for @data
9324 * Convenience function that inserts a new column into the #PsppSheetView
9325 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9326 * attributes (normally using data from the model). See also
9327 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9329 * Return value: number of columns in the tree view post-insert
9332 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9335 GtkCellRenderer *cell,
9336 PsppSheetCellDataFunc func,
9338 GDestroyNotify dnotify)
9340 PsppSheetViewColumn *column;
9342 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9344 column = pspp_sheet_view_column_new ();
9345 pspp_sheet_view_column_set_title (column, title);
9346 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9347 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9349 pspp_sheet_view_insert_column (tree_view, column, position);
9351 return tree_view->priv->n_columns;
9355 * pspp_sheet_view_get_column:
9356 * @tree_view: A #PsppSheetView.
9357 * @n: The position of the column, counting from 0.
9359 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9361 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9364 PsppSheetViewColumn *
9365 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9368 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9370 if (n < 0 || n >= tree_view->priv->n_columns)
9373 if (tree_view->priv->columns == NULL)
9376 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9380 * pspp_sheet_view_get_columns:
9381 * @tree_view: A #PsppSheetView
9383 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9384 * The returned list must be freed with g_list_free ().
9386 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9389 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9391 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9393 return g_list_copy (tree_view->priv->columns);
9397 * pspp_sheet_view_move_column_after:
9398 * @tree_view: A #PsppSheetView
9399 * @column: The #PsppSheetViewColumn to be moved.
9400 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9402 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9403 * @column is placed in the first position.
9406 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9407 PsppSheetViewColumn *column,
9408 PsppSheetViewColumn *base_column)
9410 GList *column_list_el, *base_el = NULL;
9412 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9414 column_list_el = g_list_find (tree_view->priv->columns, column);
9415 g_return_if_fail (column_list_el != NULL);
9419 base_el = g_list_find (tree_view->priv->columns, base_column);
9420 g_return_if_fail (base_el != NULL);
9423 if (column_list_el->prev == base_el)
9426 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9427 if (base_el == NULL)
9429 column_list_el->prev = NULL;
9430 column_list_el->next = tree_view->priv->columns;
9431 if (column_list_el->next)
9432 column_list_el->next->prev = column_list_el;
9433 tree_view->priv->columns = column_list_el;
9437 column_list_el->prev = base_el;
9438 column_list_el->next = base_el->next;
9439 if (column_list_el->next)
9440 column_list_el->next->prev = column_list_el;
9441 base_el->next = column_list_el;
9444 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9446 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9447 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9450 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9454 * pspp_sheet_view_set_column_drag_function:
9455 * @tree_view: A #PsppSheetView.
9456 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9457 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9458 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9460 * Sets a user function for determining where a column may be dropped when
9461 * dragged. This function is called on every column pair in turn at the
9462 * beginning of a column drag to determine where a drop can take place. The
9463 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9464 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9465 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9466 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9467 * @tree_view reverts to the default behavior of allowing all columns to be
9468 * dropped everywhere.
9471 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9472 PsppSheetViewColumnDropFunc func,
9474 GDestroyNotify destroy)
9476 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9478 if (tree_view->priv->column_drop_func_data_destroy)
9479 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9481 tree_view->priv->column_drop_func = func;
9482 tree_view->priv->column_drop_func_data = user_data;
9483 tree_view->priv->column_drop_func_data_destroy = destroy;
9487 * pspp_sheet_view_scroll_to_point:
9488 * @tree_view: a #PsppSheetView
9489 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9490 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9492 * Scrolls the tree view such that the top-left corner of the visible
9493 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9494 * in tree coordinates. The @tree_view must be realized before
9495 * this function is called. If it isn't, you probably want to be
9496 * using pspp_sheet_view_scroll_to_cell().
9498 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9501 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9505 GtkAdjustment *hadj;
9506 GtkAdjustment *vadj;
9508 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9509 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9511 hadj = tree_view->priv->hadjustment;
9512 vadj = tree_view->priv->vadjustment;
9515 gtk_adjustment_set_value (hadj, CLAMP (tree_x, hadj->lower, hadj->upper - hadj->page_size));
9517 gtk_adjustment_set_value (vadj, CLAMP (tree_y, vadj->lower, vadj->upper - vadj->page_size));
9521 * pspp_sheet_view_scroll_to_cell:
9522 * @tree_view: A #PsppSheetView.
9523 * @path: (allow-none): The path of the row to move to, or %NULL.
9524 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9525 * @use_align: whether to use alignment arguments, or %FALSE.
9526 * @row_align: The vertical alignment of the row specified by @path.
9527 * @col_align: The horizontal alignment of the column specified by @column.
9529 * Moves the alignments of @tree_view to the position specified by @column and
9530 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9531 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9532 * or @path need to be non-%NULL. @row_align determines where the row is
9533 * placed, and @col_align determines where @column is placed. Both are expected
9534 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9535 * right/bottom alignment, 0.5 means center.
9537 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9538 * tree does the minimum amount of work to scroll the cell onto the screen.
9539 * This means that the cell will be scrolled to the edge closest to its current
9540 * position. If the cell is currently visible on the screen, nothing is done.
9542 * This function only works if the model is set, and @path is a valid row on the
9543 * model. If the model changes before the @tree_view is realized, the centered
9544 * path will be modified to reflect this change.
9547 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9549 PsppSheetViewColumn *column,
9554 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9555 g_return_if_fail (tree_view->priv->model != NULL);
9556 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9557 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9558 g_return_if_fail (path != NULL || column != NULL);
9561 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9562 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9564 row_align = CLAMP (row_align, 0.0, 1.0);
9565 col_align = CLAMP (col_align, 0.0, 1.0);
9568 /* Note: Despite the benefits that come from having one code path for the
9569 * scrolling code, we short-circuit validate_visible_area's immplementation as
9570 * it is much slower than just going to the point.
9572 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9573 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9574 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9576 if (tree_view->priv->scroll_to_path)
9577 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9579 tree_view->priv->scroll_to_path = NULL;
9580 tree_view->priv->scroll_to_column = NULL;
9583 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9585 tree_view->priv->scroll_to_column = column;
9586 tree_view->priv->scroll_to_use_align = use_align;
9587 tree_view->priv->scroll_to_row_align = row_align;
9588 tree_view->priv->scroll_to_col_align = col_align;
9590 install_presize_handler (tree_view);
9594 GdkRectangle cell_rect;
9595 GdkRectangle vis_rect;
9596 gint dest_x, dest_y;
9598 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9599 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9601 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9603 dest_x = vis_rect.x;
9604 dest_y = vis_rect.y;
9610 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9614 if (cell_rect.x < vis_rect.x)
9615 dest_x = cell_rect.x;
9616 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9617 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9625 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9626 dest_y = MAX (dest_y, 0);
9630 if (cell_rect.y < vis_rect.y)
9631 dest_y = cell_rect.y;
9632 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9633 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9637 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9642 * pspp_sheet_view_row_activated:
9643 * @tree_view: A #PsppSheetView
9644 * @path: The #GtkTreePath to be activated.
9645 * @column: The #PsppSheetViewColumn to be activated.
9647 * Activates the cell determined by @path and @column.
9650 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9652 PsppSheetViewColumn *column)
9654 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9656 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
9661 * pspp_sheet_view_get_reorderable:
9662 * @tree_view: a #PsppSheetView
9664 * Retrieves whether the user can reorder the tree via drag-and-drop. See
9665 * pspp_sheet_view_set_reorderable().
9667 * Return value: %TRUE if the tree can be reordered.
9670 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
9672 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9674 return tree_view->priv->reorderable;
9678 * pspp_sheet_view_set_reorderable:
9679 * @tree_view: A #PsppSheetView.
9680 * @reorderable: %TRUE, if the tree can be reordered.
9682 * This function is a convenience function to allow you to reorder
9683 * models that support the #GtkDragSourceIface and the
9684 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
9685 * these. If @reorderable is %TRUE, then the user can reorder the
9686 * model by dragging and dropping rows. The developer can listen to
9687 * these changes by connecting to the model's row_inserted and
9688 * row_deleted signals. The reordering is implemented by setting up
9689 * the tree view as a drag source and destination. Therefore, drag and
9690 * drop can not be used in a reorderable view for any other purpose.
9692 * This function does not give you any degree of control over the order -- any
9693 * reordering is allowed. If more control is needed, you should probably
9694 * handle drag and drop manually.
9697 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
9698 gboolean reorderable)
9700 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9702 reorderable = reorderable != FALSE;
9704 if (tree_view->priv->reorderable == reorderable)
9709 const GtkTargetEntry row_targets[] = {
9710 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
9713 pspp_sheet_view_enable_model_drag_source (tree_view,
9716 G_N_ELEMENTS (row_targets),
9718 pspp_sheet_view_enable_model_drag_dest (tree_view,
9720 G_N_ELEMENTS (row_targets),
9725 pspp_sheet_view_unset_rows_drag_source (tree_view);
9726 pspp_sheet_view_unset_rows_drag_dest (tree_view);
9729 tree_view->priv->reorderable = reorderable;
9731 g_object_notify (G_OBJECT (tree_view), "reorderable");
9734 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
9735 is pressed, other rows will be unselected.
9737 If CLAMP_NODE is true, then the sheetview will scroll to make the row
9740 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
9742 gboolean clear_and_select,
9743 gboolean clamp_node)
9747 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9749 GtkTreePath *cursor_path;
9750 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9751 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
9752 gtk_tree_path_free (cursor_path);
9755 gtk_tree_row_reference_free (tree_view->priv->cursor);
9756 tree_view->priv->cursor = NULL;
9758 _pspp_sheet_view_find_node (tree_view, path, &node);
9759 tree_view->priv->cursor =
9760 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
9761 tree_view->priv->model,
9764 if (tree_view->priv->row_count > 0)
9768 if (clear_and_select && !tree_view->priv->ctrl_pressed)
9770 GtkTreeSelectMode mode = 0;
9772 if (tree_view->priv->ctrl_pressed)
9773 mode |= GTK_TREE_SELECT_MODE_TOGGLE;
9774 if (tree_view->priv->shift_pressed)
9775 mode |= GTK_TREE_SELECT_MODE_EXTEND;
9777 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
9782 /* We have to re-find tree and node here again, somebody might have
9783 * cleared the node or the whole tree in the PsppSheetSelection::changed
9784 * callback. If the nodes differ we bail out here.
9786 _pspp_sheet_view_find_node (tree_view, path, &new_node);
9788 if (node != new_node)
9793 pspp_sheet_view_clamp_node_visible (tree_view, node);
9794 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
9798 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
9802 * pspp_sheet_view_get_cursor:
9803 * @tree_view: A #PsppSheetView
9804 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
9805 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
9807 * Fills in @path and @focus_column with the current path and focus column. If
9808 * the cursor isn't currently set, then *@path will be %NULL. If no column
9809 * currently has focus, then *@focus_column will be %NULL.
9811 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
9812 * you are done with it.
9815 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
9817 PsppSheetViewColumn **focus_column)
9819 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9823 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9824 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9831 *focus_column = tree_view->priv->focus_column;
9836 * pspp_sheet_view_set_cursor:
9837 * @tree_view: A #PsppSheetView
9838 * @path: A #GtkTreePath
9839 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9840 * @start_editing: %TRUE if the specified cell should start being edited.
9842 * Sets the current keyboard focus to be at @path, and selects it. This is
9843 * useful when you want to focus the user's attention on a particular row. If
9844 * @focus_column is not %NULL, then focus is given to the column specified by
9845 * it. Additionally, if @focus_column is specified, and @start_editing is
9846 * %TRUE, then editing should be started in the specified cell.
9847 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
9848 * in order to give keyboard focus to the widget. Please note that editing
9849 * can only happen when the widget is realized.
9851 * If @path is invalid for @model, the current cursor (if any) will be unset
9852 * and the function will return without failing.
9855 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
9857 PsppSheetViewColumn *focus_column,
9858 gboolean start_editing)
9860 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
9861 NULL, start_editing);
9865 * pspp_sheet_view_set_cursor_on_cell:
9866 * @tree_view: A #PsppSheetView
9867 * @path: A #GtkTreePath
9868 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9869 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
9870 * @start_editing: %TRUE if the specified cell should start being edited.
9872 * Sets the current keyboard focus to be at @path, and selects it. This is
9873 * useful when you want to focus the user's attention on a particular row. If
9874 * @focus_column is not %NULL, then focus is given to the column specified by
9875 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
9876 * contains 2 or more editable or activatable cells, then focus is given to
9877 * the cell specified by @focus_cell. Additionally, if @focus_column is
9878 * specified, and @start_editing is %TRUE, then editing should be started in
9879 * the specified cell. This function is often followed by
9880 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
9881 * widget. Please note that editing can only happen when the widget is
9884 * If @path is invalid for @model, the current cursor (if any) will be unset
9885 * and the function will return without failing.
9890 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
9892 PsppSheetViewColumn *focus_column,
9893 GtkCellRenderer *focus_cell,
9894 gboolean start_editing)
9896 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9897 g_return_if_fail (path != NULL);
9898 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
9900 if (!tree_view->priv->model)
9905 g_return_if_fail (focus_column);
9906 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
9909 /* cancel the current editing, if it exists */
9910 if (tree_view->priv->edited_column &&
9911 tree_view->priv->edited_column->editable_widget)
9912 pspp_sheet_view_stop_editing (tree_view, TRUE);
9914 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
9916 if (focus_column && focus_column->visible)
9919 gboolean column_in_tree = FALSE;
9921 for (list = tree_view->priv->columns; list; list = list->next)
9922 if (list->data == focus_column)
9924 column_in_tree = TRUE;
9927 g_return_if_fail (column_in_tree);
9928 tree_view->priv->focus_column = focus_column;
9930 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
9932 pspp_sheet_view_start_editing (tree_view, path);
9934 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
9935 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
9941 * pspp_sheet_view_get_bin_window:
9942 * @tree_view: A #PsppSheetView
9944 * Returns the window that @tree_view renders to. This is used primarily to
9945 * compare to <literal>event->window</literal> to confirm that the event on
9946 * @tree_view is on the right window.
9948 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
9951 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
9953 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9955 return tree_view->priv->bin_window;
9959 * pspp_sheet_view_get_path_at_pos:
9960 * @tree_view: A #PsppSheetView.
9961 * @x: The x position to be identified (relative to bin_window).
9962 * @y: The y position to be identified (relative to bin_window).
9963 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
9964 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
9965 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
9966 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
9968 * Finds the path at the point (@x, @y), relative to bin_window coordinates
9969 * (please see pspp_sheet_view_get_bin_window()).
9970 * That is, @x and @y are relative to an events coordinates. @x and @y must
9971 * come from an event on the @tree_view only where <literal>event->window ==
9972 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
9973 * things like popup menus. If @path is non-%NULL, then it will be filled
9974 * with the #GtkTreePath at that point. This path should be freed with
9975 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
9976 * with the column at that point. @cell_x and @cell_y return the coordinates
9977 * relative to the cell background (i.e. the @background_area passed to
9978 * gtk_cell_renderer_render()). This function is only meaningful if
9979 * @tree_view is realized. Therefore this function will always return %FALSE
9980 * if @tree_view is not realized or does not have a model.
9982 * For converting widget coordinates (eg. the ones you get from
9983 * GtkWidget::query-tooltip), please see
9984 * pspp_sheet_view_convert_widget_to_bin_window_coords().
9986 * Return value: %TRUE if a row exists at that coordinate.
9989 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
9993 PsppSheetViewColumn **column,
10000 g_return_val_if_fail (tree_view != NULL, FALSE);
10007 if (tree_view->priv->bin_window == NULL)
10010 if (tree_view->priv->row_count == 0)
10013 if (x > tree_view->priv->hadjustment->upper)
10016 if (x < 0 || y < 0)
10019 if (column || cell_x)
10021 PsppSheetViewColumn *tmp_column;
10022 PsppSheetViewColumn *last_column = NULL;
10024 gint remaining_x = x;
10025 gboolean found = FALSE;
10028 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10029 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10031 list = (rtl ? list->prev : list->next))
10033 tmp_column = list->data;
10035 if (tmp_column->visible == FALSE)
10038 last_column = tmp_column;
10039 if (remaining_x <= tmp_column->width)
10044 *column = tmp_column;
10047 *cell_x = remaining_x;
10051 remaining_x -= tmp_column->width;
10054 /* If found is FALSE and there is a last_column, then it the remainder
10055 * space is in that area
10062 *column = last_column;
10065 *cell_x = last_column->width + remaining_x;
10074 y_offset = pspp_sheet_view_find_offset (tree_view,
10075 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10082 *cell_y = y_offset;
10085 *path = _pspp_sheet_view_find_path (tree_view, node);
10090 /* Computes 'cell_area' from 'background_area', which must be the background
10091 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10092 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10093 the cell area as passed to _pspp_sheet_view_column_cell_render().
10095 'column' is required to properly adjust 'cell_area->x' and
10096 'cell_area->width'. It may be set to NULL if these values are not of
10097 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10100 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10101 PsppSheetViewColumn *column,
10102 const GdkRectangle *background_area,
10103 gboolean subtract_focus_rect,
10104 GdkRectangle *cell_area)
10106 gint vertical_separator;
10107 gint horizontal_separator;
10109 *cell_area = *background_area;
10111 gtk_widget_style_get (GTK_WIDGET (tree_view),
10112 "vertical-separator", &vertical_separator,
10113 "horizontal-separator", &horizontal_separator,
10115 cell_area->x += horizontal_separator / 2;
10116 cell_area->y += vertical_separator / 2;
10117 cell_area->width -= horizontal_separator;
10118 cell_area->height -= vertical_separator;
10120 if (subtract_focus_rect)
10122 int focus_line_width;
10124 gtk_widget_style_get (GTK_WIDGET (tree_view),
10125 "focus-line-width", &focus_line_width,
10127 cell_area->x += focus_line_width;
10128 cell_area->y += focus_line_width;
10129 cell_area->width -= 2 * focus_line_width;
10130 cell_area->height -= 2 * focus_line_width;
10133 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10135 gint grid_line_width;
10136 gtk_widget_style_get (GTK_WIDGET (tree_view),
10137 "grid-line-width", &grid_line_width,
10140 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10141 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10144 PsppSheetViewColumn *first_column, *last_column;
10147 /* Find the last visible column. */
10148 last_column = NULL;
10149 for (list = g_list_last (tree_view->priv->columns);
10153 PsppSheetViewColumn *c = list->data;
10161 /* Find the first visible column. */
10162 first_column = NULL;
10163 for (list = g_list_first (tree_view->priv->columns);
10167 PsppSheetViewColumn *c = list->data;
10175 if (column == first_column)
10177 cell_area->width -= grid_line_width / 2;
10179 else if (column == last_column)
10181 cell_area->x += grid_line_width / 2;
10182 cell_area->width -= grid_line_width / 2;
10186 cell_area->x += grid_line_width / 2;
10187 cell_area->width -= grid_line_width;
10191 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10192 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10194 cell_area->y += grid_line_width / 2;
10195 cell_area->height -= grid_line_width;
10199 if (column == NULL)
10202 cell_area->width = 0;
10207 * pspp_sheet_view_get_cell_area:
10208 * @tree_view: a #PsppSheetView
10209 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10210 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10211 * @rect: rectangle to fill with cell rect
10213 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10214 * row specified by @path and the column specified by @column. If @path is
10215 * %NULL, or points to a path not currently displayed, the @y and @height fields
10216 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10217 * fields will be filled with 0. The sum of all cell rects does not cover the
10218 * entire tree; there are extra pixels in between rows, for example. The
10219 * returned rectangle is equivalent to the @cell_area passed to
10220 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10224 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10226 PsppSheetViewColumn *column,
10227 GdkRectangle *rect)
10229 GdkRectangle background_area;
10231 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10232 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10233 g_return_if_fail (rect != NULL);
10234 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10235 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10237 pspp_sheet_view_get_background_area (tree_view, path, column,
10239 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10244 * pspp_sheet_view_get_background_area:
10245 * @tree_view: a #PsppSheetView
10246 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10247 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10248 * @rect: rectangle to fill with cell background rect
10250 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10251 * row specified by @path and the column specified by @column. If @path is
10252 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10253 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10254 * fields will be filled with 0. The returned rectangle is equivalent to the
10255 * @background_area passed to gtk_cell_renderer_render(). These background
10256 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10257 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10258 * itself, excluding surrounding borders.
10262 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10264 PsppSheetViewColumn *column,
10265 GdkRectangle *rect)
10269 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10270 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10271 g_return_if_fail (rect != NULL);
10280 /* Get vertical coords */
10282 _pspp_sheet_view_find_node (tree_view, path, &node);
10286 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10288 rect->height = ROW_HEIGHT (tree_view);
10295 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10296 rect->width = x2 - rect->x;
10301 * pspp_sheet_view_get_visible_rect:
10302 * @tree_view: a #PsppSheetView
10303 * @visible_rect: rectangle to fill
10305 * Fills @visible_rect with the currently-visible region of the
10306 * buffer, in tree coordinates. Convert to bin_window coordinates with
10307 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10308 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10309 * scrollable area of the tree.
10312 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10313 GdkRectangle *visible_rect)
10317 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10319 widget = GTK_WIDGET (tree_view);
10323 visible_rect->x = tree_view->priv->hadjustment->value;
10324 visible_rect->y = tree_view->priv->vadjustment->value;
10325 visible_rect->width = widget->allocation.width;
10326 visible_rect->height = widget->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10331 * pspp_sheet_view_widget_to_tree_coords:
10332 * @tree_view: a #PsppSheetView
10333 * @wx: X coordinate relative to bin_window
10334 * @wy: Y coordinate relative to bin_window
10335 * @tx: return location for tree X coordinate
10336 * @ty: return location for tree Y coordinate
10338 * Converts bin_window coordinates to coordinates for the
10339 * tree (the full scrollable area of the tree).
10341 * Deprecated: 2.12: Due to historial reasons the name of this function is
10342 * incorrect. For converting coordinates relative to the widget to
10343 * bin_window coordinates, please see
10344 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10348 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10354 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10357 *tx = wx + tree_view->priv->hadjustment->value;
10359 *ty = wy + tree_view->priv->dy;
10363 * pspp_sheet_view_tree_to_widget_coords:
10364 * @tree_view: a #PsppSheetView
10365 * @tx: tree X coordinate
10366 * @ty: tree Y coordinate
10367 * @wx: return location for X coordinate relative to bin_window
10368 * @wy: return location for Y coordinate relative to bin_window
10370 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10371 * to bin_window coordinates.
10373 * Deprecated: 2.12: Due to historial reasons the name of this function is
10374 * incorrect. For converting bin_window coordinates to coordinates relative
10375 * to bin_window, please see
10376 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10380 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10386 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10389 *wx = tx - tree_view->priv->hadjustment->value;
10391 *wy = ty - tree_view->priv->dy;
10396 * pspp_sheet_view_convert_widget_to_tree_coords:
10397 * @tree_view: a #PsppSheetView
10398 * @wx: X coordinate relative to the widget
10399 * @wy: Y coordinate relative to the widget
10400 * @tx: return location for tree X coordinate
10401 * @ty: return location for tree Y coordinate
10403 * Converts widget coordinates to coordinates for the
10404 * tree (the full scrollable area of the tree).
10409 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10417 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10419 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10422 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10428 * pspp_sheet_view_convert_tree_to_widget_coords:
10429 * @tree_view: a #PsppSheetView
10430 * @tx: X coordinate relative to the tree
10431 * @ty: Y coordinate relative to the tree
10432 * @wx: return location for widget X coordinate
10433 * @wy: return location for widget Y coordinate
10435 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10436 * to widget coordinates.
10441 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10449 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10451 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10454 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10460 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10461 * @tree_view: a #PsppSheetView
10462 * @wx: X coordinate relative to the widget
10463 * @wy: Y coordinate relative to the widget
10464 * @bx: return location for bin_window X coordinate
10465 * @by: return location for bin_window Y coordinate
10467 * Converts widget coordinates to coordinates for the bin_window
10468 * (see pspp_sheet_view_get_bin_window()).
10473 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10479 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10482 *bx = wx + tree_view->priv->hadjustment->value;
10484 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10488 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10489 * @tree_view: a #PsppSheetView
10490 * @bx: bin_window X coordinate
10491 * @by: bin_window Y coordinate
10492 * @wx: return location for widget X coordinate
10493 * @wy: return location for widget Y coordinate
10495 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10496 * to widget relative coordinates.
10501 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10507 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10510 *wx = bx - tree_view->priv->hadjustment->value;
10512 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10516 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10517 * @tree_view: a #PsppSheetView
10518 * @tx: tree X coordinate
10519 * @ty: tree Y coordinate
10520 * @bx: return location for X coordinate relative to bin_window
10521 * @by: return location for Y coordinate relative to bin_window
10523 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10524 * to bin_window coordinates.
10529 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10535 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10540 *by = ty - tree_view->priv->dy;
10544 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10545 * @tree_view: a #PsppSheetView
10546 * @bx: X coordinate relative to bin_window
10547 * @by: Y coordinate relative to bin_window
10548 * @tx: return location for tree X coordinate
10549 * @ty: return location for tree Y coordinate
10551 * Converts bin_window coordinates to coordinates for the
10552 * tree (the full scrollable area of the tree).
10557 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10563 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10568 *ty = by + tree_view->priv->dy;
10574 * pspp_sheet_view_get_visible_range:
10575 * @tree_view: A #PsppSheetView
10576 * @start_path: (allow-none): Return location for start of region, or %NULL.
10577 * @end_path: (allow-none): Return location for end of region, or %NULL.
10579 * Sets @start_path and @end_path to be the first and last visible path.
10580 * Note that there may be invisible paths in between.
10582 * The paths should be freed with gtk_tree_path_free() after use.
10584 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10589 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10590 GtkTreePath **start_path,
10591 GtkTreePath **end_path)
10596 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10598 if (!tree_view->priv->row_count)
10605 pspp_sheet_view_find_offset (tree_view,
10606 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10609 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10618 if (tree_view->priv->height < tree_view->priv->vadjustment->page_size)
10619 y = tree_view->priv->height - 1;
10621 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, tree_view->priv->vadjustment->page_size) - 1;
10623 pspp_sheet_view_find_offset (tree_view, y, &node);
10625 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10634 unset_reorderable (PsppSheetView *tree_view)
10636 if (tree_view->priv->reorderable)
10638 tree_view->priv->reorderable = FALSE;
10639 g_object_notify (G_OBJECT (tree_view), "reorderable");
10644 * pspp_sheet_view_enable_model_drag_source:
10645 * @tree_view: a #PsppSheetView
10646 * @start_button_mask: Mask of allowed buttons to start drag
10647 * @targets: the table of targets that the drag will support
10648 * @n_targets: the number of items in @targets
10649 * @actions: the bitmask of possible actions for a drag from this
10652 * Turns @tree_view into a drag source for automatic DND. Calling this
10653 * method sets #PsppSheetView:reorderable to %FALSE.
10656 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10657 GdkModifierType start_button_mask,
10658 const GtkTargetEntry *targets,
10660 GdkDragAction actions)
10662 TreeViewDragInfo *di;
10664 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10666 gtk_drag_source_set (GTK_WIDGET (tree_view),
10672 di = ensure_info (tree_view);
10674 di->start_button_mask = start_button_mask;
10675 di->source_actions = actions;
10676 di->source_set = TRUE;
10678 unset_reorderable (tree_view);
10682 * pspp_sheet_view_enable_model_drag_dest:
10683 * @tree_view: a #PsppSheetView
10684 * @targets: the table of targets that the drag will support
10685 * @n_targets: the number of items in @targets
10686 * @actions: the bitmask of possible actions for a drag from this
10689 * Turns @tree_view into a drop destination for automatic DND. Calling
10690 * this method sets #PsppSheetView:reorderable to %FALSE.
10693 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
10694 const GtkTargetEntry *targets,
10696 GdkDragAction actions)
10698 TreeViewDragInfo *di;
10700 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10702 gtk_drag_dest_set (GTK_WIDGET (tree_view),
10708 di = ensure_info (tree_view);
10709 di->dest_set = TRUE;
10711 unset_reorderable (tree_view);
10715 * pspp_sheet_view_unset_rows_drag_source:
10716 * @tree_view: a #PsppSheetView
10718 * Undoes the effect of
10719 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
10720 * #PsppSheetView:reorderable to %FALSE.
10723 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
10725 TreeViewDragInfo *di;
10727 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10729 di = get_info (tree_view);
10733 if (di->source_set)
10735 gtk_drag_source_unset (GTK_WIDGET (tree_view));
10736 di->source_set = FALSE;
10739 if (!di->dest_set && !di->source_set)
10740 remove_info (tree_view);
10743 unset_reorderable (tree_view);
10747 * pspp_sheet_view_unset_rows_drag_dest:
10748 * @tree_view: a #PsppSheetView
10750 * Undoes the effect of
10751 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
10752 * #PsppSheetView:reorderable to %FALSE.
10755 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
10757 TreeViewDragInfo *di;
10759 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10761 di = get_info (tree_view);
10767 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
10768 di->dest_set = FALSE;
10771 if (!di->dest_set && !di->source_set)
10772 remove_info (tree_view);
10775 unset_reorderable (tree_view);
10779 * pspp_sheet_view_set_drag_dest_row:
10780 * @tree_view: a #PsppSheetView
10781 * @path: (allow-none): The path of the row to highlight, or %NULL.
10782 * @pos: Specifies whether to drop before, after or into the row
10784 * Sets the row that is highlighted for feedback.
10787 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
10789 PsppSheetViewDropPosition pos)
10791 GtkTreePath *current_dest;
10793 /* Note; this function is exported to allow a custom DND
10794 * implementation, so it can't touch TreeViewDragInfo
10797 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10799 current_dest = NULL;
10801 if (tree_view->priv->drag_dest_row)
10803 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10804 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
10807 /* special case a drop on an empty model */
10808 tree_view->priv->empty_view_drop = 0;
10810 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
10811 && gtk_tree_path_get_depth (path) == 1
10812 && gtk_tree_path_get_indices (path)[0] == 0)
10816 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
10820 tree_view->priv->empty_view_drop = 1;
10823 tree_view->priv->drag_dest_pos = pos;
10827 tree_view->priv->drag_dest_row =
10828 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
10829 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
10832 tree_view->priv->drag_dest_row = NULL;
10836 int node, new_node;
10838 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
10839 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10843 new_node = pspp_sheet_view_node_next (tree_view, node);
10845 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
10847 new_node = pspp_sheet_view_node_prev (tree_view, node);
10849 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
10851 gtk_tree_path_free (current_dest);
10856 * pspp_sheet_view_get_drag_dest_row:
10857 * @tree_view: a #PsppSheetView
10858 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
10859 * @pos: (allow-none): Return location for the drop position, or %NULL
10861 * Gets information about the row that is highlighted for feedback.
10864 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
10865 GtkTreePath **path,
10866 PsppSheetViewDropPosition *pos)
10868 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10872 if (tree_view->priv->drag_dest_row)
10873 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10876 if (tree_view->priv->empty_view_drop)
10877 *path = gtk_tree_path_new_from_indices (0, -1);
10884 *pos = tree_view->priv->drag_dest_pos;
10888 * pspp_sheet_view_get_dest_row_at_pos:
10889 * @tree_view: a #PsppSheetView
10890 * @drag_x: the position to determine the destination row for
10891 * @drag_y: the position to determine the destination row for
10892 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
10893 * @pos: (allow-none): Return location for the drop position, or %NULL
10895 * Determines the destination row for a given position. @drag_x and
10896 * @drag_y are expected to be in widget coordinates. This function is only
10897 * meaningful if @tree_view is realized. Therefore this function will always
10898 * return %FALSE if @tree_view is not realized or does not have a model.
10900 * Return value: whether there is a row at the given position, %TRUE if this
10901 * is indeed the case.
10904 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
10907 GtkTreePath **path,
10908 PsppSheetViewDropPosition *pos)
10912 gdouble offset_into_row;
10915 PsppSheetViewColumn *column = NULL;
10916 GtkTreePath *tmp_path = NULL;
10918 /* Note; this function is exported to allow a custom DND
10919 * implementation, so it can't touch TreeViewDragInfo
10922 g_return_val_if_fail (tree_view != NULL, FALSE);
10923 g_return_val_if_fail (drag_x >= 0, FALSE);
10924 g_return_val_if_fail (drag_y >= 0, FALSE);
10929 if (tree_view->priv->bin_window == NULL)
10932 if (tree_view->priv->row_count == 0)
10935 /* If in the top third of a row, we drop before that row; if
10936 * in the bottom third, drop after that row; if in the middle,
10937 * and the row has children, drop into the row.
10939 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
10942 if (!pspp_sheet_view_get_path_at_pos (tree_view,
10951 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
10954 offset_into_row = cell_y;
10959 gtk_tree_path_free (tmp_path);
10963 third = cell.height / 3.0;
10967 if (offset_into_row < third)
10969 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
10971 else if (offset_into_row < (cell.height / 2.0))
10973 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
10975 else if (offset_into_row < third * 2.0)
10977 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
10981 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
10990 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
10992 * pspp_sheet_view_create_row_drag_icon:
10993 * @tree_view: a #PsppSheetView
10994 * @path: a #GtkTreePath in @tree_view
10996 * Creates a #GdkPixmap representation of the row at @path.
10997 * This image is used for a drag icon.
10999 * Return value: a newly-allocated pixmap of the drag icon.
11002 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11009 GdkRectangle background_area;
11010 GdkRectangle expose_area;
11012 /* start drawing inside the black outline */
11014 GdkDrawable *drawable;
11015 gint bin_window_width;
11018 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11019 g_return_val_if_fail (path != NULL, NULL);
11021 widget = GTK_WIDGET (tree_view);
11023 if (!gtk_widget_get_realized (widget))
11026 _pspp_sheet_view_find_node (tree_view,
11033 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11040 background_area.y = y;
11041 background_area.height = ROW_HEIGHT (tree_view);
11043 gdk_drawable_get_size (tree_view->priv->bin_window,
11044 &bin_window_width, NULL);
11046 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11047 bin_window_width + 2,
11048 background_area.height + 2,
11053 expose_area.width = bin_window_width + 2;
11054 expose_area.height = background_area.height + 2;
11056 gdk_draw_rectangle (drawable,
11057 widget->style->base_gc [gtk_widget_get_state (widget)],
11060 bin_window_width + 2,
11061 background_area.height + 2);
11063 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11065 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11067 list = (rtl ? list->prev : list->next))
11069 PsppSheetViewColumn *column = list->data;
11070 GdkRectangle cell_area;
11071 gint vertical_separator;
11073 if (!column->visible)
11076 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11078 background_area.x = cell_offset;
11079 background_area.width = column->width;
11081 gtk_widget_style_get (widget,
11082 "vertical-separator", &vertical_separator,
11085 cell_area = background_area;
11087 cell_area.y += vertical_separator / 2;
11088 cell_area.height -= vertical_separator;
11090 if (pspp_sheet_view_column_cell_is_visible (column))
11091 _pspp_sheet_view_column_cell_render (column,
11097 cell_offset += column->width;
11100 gdk_draw_rectangle (drawable,
11101 widget->style->black_gc,
11104 bin_window_width + 1,
11105 background_area.height + 1);
11112 * pspp_sheet_view_set_destroy_count_func:
11113 * @tree_view: A #PsppSheetView
11114 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11115 * @data: (allow-none): User data to be passed to @func, or %NULL
11116 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11118 * This function should almost never be used. It is meant for private use by
11119 * ATK for determining the number of visible children that are removed when a row is deleted.
11122 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11123 PsppSheetDestroyCountFunc func,
11125 GDestroyNotify destroy)
11127 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11129 if (tree_view->priv->destroy_count_destroy)
11130 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11132 tree_view->priv->destroy_count_func = func;
11133 tree_view->priv->destroy_count_data = data;
11134 tree_view->priv->destroy_count_destroy = destroy;
11139 * Interactive search
11143 * pspp_sheet_view_set_enable_search:
11144 * @tree_view: A #PsppSheetView
11145 * @enable_search: %TRUE, if the user can search interactively
11147 * If @enable_search is set, then the user can type in text to search through
11148 * the tree interactively (this is sometimes called "typeahead find").
11150 * Note that even if this is %FALSE, the user can still initiate a search
11151 * using the "start-interactive-search" key binding.
11154 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11155 gboolean enable_search)
11157 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11159 enable_search = !!enable_search;
11161 if (tree_view->priv->enable_search != enable_search)
11163 tree_view->priv->enable_search = enable_search;
11164 g_object_notify (G_OBJECT (tree_view), "enable-search");
11169 * pspp_sheet_view_get_enable_search:
11170 * @tree_view: A #PsppSheetView
11172 * Returns whether or not the tree allows to start interactive searching
11173 * by typing in text.
11175 * Return value: whether or not to let the user search interactively
11178 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11180 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11182 return tree_view->priv->enable_search;
11187 * pspp_sheet_view_get_search_column:
11188 * @tree_view: A #PsppSheetView
11190 * Gets the column searched on by the interactive search code.
11192 * Return value: the column the interactive search code searches in.
11195 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11197 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11199 return (tree_view->priv->search_column);
11203 * pspp_sheet_view_set_search_column:
11204 * @tree_view: A #PsppSheetView
11205 * @column: the column of the model to search in, or -1 to disable searching
11207 * Sets @column as the column where the interactive search code should
11208 * search in for the current model.
11210 * If the search column is set, users can use the "start-interactive-search"
11211 * key binding to bring up search popup. The enable-search property controls
11212 * whether simply typing text will also start an interactive search.
11214 * Note that @column refers to a column of the current model. The search
11215 * column is reset to -1 when the model is changed.
11218 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11221 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11222 g_return_if_fail (column >= -1);
11224 if (tree_view->priv->search_column == column)
11227 tree_view->priv->search_column = column;
11228 g_object_notify (G_OBJECT (tree_view), "search-column");
11232 * pspp_sheet_view_get_search_equal_func:
11233 * @tree_view: A #PsppSheetView
11235 * Returns the compare function currently in use.
11237 * Return value: the currently used compare function for the search code.
11240 PsppSheetViewSearchEqualFunc
11241 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11243 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11245 return tree_view->priv->search_equal_func;
11249 * pspp_sheet_view_set_search_equal_func:
11250 * @tree_view: A #PsppSheetView
11251 * @search_equal_func: the compare function to use during the search
11252 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11253 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11255 * Sets the compare function for the interactive search capabilities; note
11256 * that somewhat like strcmp() returning 0 for equality
11257 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11260 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11261 PsppSheetViewSearchEqualFunc search_equal_func,
11262 gpointer search_user_data,
11263 GDestroyNotify search_destroy)
11265 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11266 g_return_if_fail (search_equal_func != NULL);
11268 if (tree_view->priv->search_destroy)
11269 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11271 tree_view->priv->search_equal_func = search_equal_func;
11272 tree_view->priv->search_user_data = search_user_data;
11273 tree_view->priv->search_destroy = search_destroy;
11274 if (tree_view->priv->search_equal_func == NULL)
11275 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11279 * pspp_sheet_view_get_search_entry:
11280 * @tree_view: A #PsppSheetView
11282 * Returns the #GtkEntry which is currently in use as interactive search
11283 * entry for @tree_view. In case the built-in entry is being used, %NULL
11284 * will be returned.
11286 * Return value: the entry currently in use as search entry.
11291 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11293 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11295 if (tree_view->priv->search_custom_entry_set)
11296 return GTK_ENTRY (tree_view->priv->search_entry);
11302 * pspp_sheet_view_set_search_entry:
11303 * @tree_view: A #PsppSheetView
11304 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11306 * Sets the entry which the interactive search code will use for this
11307 * @tree_view. This is useful when you want to provide a search entry
11308 * in our interface at all time at a fixed position. Passing %NULL for
11309 * @entry will make the interactive search code use the built-in popup
11315 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11318 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11319 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11321 if (tree_view->priv->search_custom_entry_set)
11323 if (tree_view->priv->search_entry_changed_id)
11325 g_signal_handler_disconnect (tree_view->priv->search_entry,
11326 tree_view->priv->search_entry_changed_id);
11327 tree_view->priv->search_entry_changed_id = 0;
11329 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11330 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11333 g_object_unref (tree_view->priv->search_entry);
11335 else if (tree_view->priv->search_window)
11337 gtk_widget_destroy (tree_view->priv->search_window);
11339 tree_view->priv->search_window = NULL;
11344 tree_view->priv->search_entry = g_object_ref (entry);
11345 tree_view->priv->search_custom_entry_set = TRUE;
11347 if (tree_view->priv->search_entry_changed_id == 0)
11349 tree_view->priv->search_entry_changed_id =
11350 g_signal_connect (tree_view->priv->search_entry, "changed",
11351 G_CALLBACK (pspp_sheet_view_search_init),
11355 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11356 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11359 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11363 tree_view->priv->search_entry = NULL;
11364 tree_view->priv->search_custom_entry_set = FALSE;
11369 * pspp_sheet_view_set_search_position_func:
11370 * @tree_view: A #PsppSheetView
11371 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11372 * to use the default search position function
11373 * @data: (allow-none): user data to pass to @func, or %NULL
11374 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11376 * Sets the function to use when positioning the search dialog.
11381 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11382 PsppSheetViewSearchPositionFunc func,
11383 gpointer user_data,
11384 GDestroyNotify destroy)
11386 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11388 if (tree_view->priv->search_position_destroy)
11389 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11391 tree_view->priv->search_position_func = func;
11392 tree_view->priv->search_position_user_data = user_data;
11393 tree_view->priv->search_position_destroy = destroy;
11394 if (tree_view->priv->search_position_func == NULL)
11395 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11399 * pspp_sheet_view_get_search_position_func:
11400 * @tree_view: A #PsppSheetView
11402 * Returns the positioning function currently in use.
11404 * Return value: the currently used function for positioning the search dialog.
11408 PsppSheetViewSearchPositionFunc
11409 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11411 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11413 return tree_view->priv->search_position_func;
11418 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11419 PsppSheetView *tree_view)
11421 if (tree_view->priv->disable_popdown)
11424 if (tree_view->priv->search_entry_changed_id)
11426 g_signal_handler_disconnect (tree_view->priv->search_entry,
11427 tree_view->priv->search_entry_changed_id);
11428 tree_view->priv->search_entry_changed_id = 0;
11430 if (tree_view->priv->typeselect_flush_timeout)
11432 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11433 tree_view->priv->typeselect_flush_timeout = 0;
11436 if (gtk_widget_get_visible (search_dialog))
11438 /* send focus-in event */
11439 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11440 gtk_widget_hide (search_dialog);
11441 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11442 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11447 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11448 GtkWidget *search_dialog,
11449 gpointer user_data)
11452 gint tree_x, tree_y;
11453 gint tree_width, tree_height;
11454 GdkWindow *tree_window = GTK_WIDGET (tree_view)->window;
11455 GdkScreen *screen = gdk_drawable_get_screen (tree_window);
11456 GtkRequisition requisition;
11458 GdkRectangle monitor;
11460 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11461 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11463 gtk_widget_realize (search_dialog);
11465 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11466 gdk_drawable_get_size (tree_window,
11469 gtk_widget_size_request (search_dialog, &requisition);
11471 if (tree_x + tree_width > gdk_screen_get_width (screen))
11472 x = gdk_screen_get_width (screen) - requisition.width;
11473 else if (tree_x + tree_width - requisition.width < 0)
11476 x = tree_x + tree_width - requisition.width;
11478 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11479 y = gdk_screen_get_height (screen) - requisition.height;
11480 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11483 y = tree_y + tree_height;
11485 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11489 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11493 PsppSheetView *tree_view = (PsppSheetView *)data;
11495 tree_view->priv->disable_popdown = 1;
11496 g_signal_connect (menu, "hide",
11497 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11500 /* Because we're visible but offscreen, we just set a flag in the preedit
11504 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11505 PsppSheetView *tree_view)
11507 tree_view->priv->imcontext_changed = 1;
11508 if (tree_view->priv->typeselect_flush_timeout)
11510 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11511 tree_view->priv->typeselect_flush_timeout =
11512 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11513 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11520 pspp_sheet_view_search_activate (GtkEntry *entry,
11521 PsppSheetView *tree_view)
11526 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11529 /* If we have a row selected and it's the cursor row, we activate
11531 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11533 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11535 _pspp_sheet_view_find_node (tree_view, path, &node);
11537 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11538 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11540 gtk_tree_path_free (path);
11545 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11547 PsppSheetView *tree_view = (PsppSheetView *)data;
11549 tree_view->priv->disable_popdown = 0;
11555 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11558 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11562 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11563 GdkEventAny *event,
11564 PsppSheetView *tree_view)
11566 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11568 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11574 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11575 GdkEventButton *event,
11576 PsppSheetView *tree_view)
11578 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11580 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11582 if (event->window == tree_view->priv->bin_window)
11583 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11589 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11590 GdkEventScroll *event,
11591 PsppSheetView *tree_view)
11593 gboolean retval = FALSE;
11595 if (event->direction == GDK_SCROLL_UP)
11597 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11600 else if (event->direction == GDK_SCROLL_DOWN)
11602 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11606 /* renew the flush timeout */
11607 if (retval && tree_view->priv->typeselect_flush_timeout
11608 && !tree_view->priv->search_custom_entry_set)
11610 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11611 tree_view->priv->typeselect_flush_timeout =
11612 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11613 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11621 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11622 GdkEventKey *event,
11623 PsppSheetView *tree_view)
11625 gboolean retval = FALSE;
11627 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11628 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11630 /* close window and cancel the search */
11631 if (!tree_view->priv->search_custom_entry_set
11632 && (event->keyval == GDK_Escape ||
11633 event->keyval == GDK_Tab ||
11634 event->keyval == GDK_KP_Tab ||
11635 event->keyval == GDK_ISO_Left_Tab))
11637 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11641 /* select previous matching iter */
11642 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11644 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11645 gtk_widget_error_bell (widget);
11650 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11651 && (event->keyval == GDK_g || event->keyval == GDK_G))
11653 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11654 gtk_widget_error_bell (widget);
11659 /* select next matching iter */
11660 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
11662 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11663 gtk_widget_error_bell (widget);
11668 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
11669 && (event->keyval == GDK_g || event->keyval == GDK_G))
11671 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11672 gtk_widget_error_bell (widget);
11677 /* renew the flush timeout */
11678 if (retval && tree_view->priv->typeselect_flush_timeout
11679 && !tree_view->priv->search_custom_entry_set)
11681 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11682 tree_view->priv->typeselect_flush_timeout =
11683 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11684 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11691 /* this function returns FALSE if there is a search string but
11692 * nothing was found, and TRUE otherwise.
11695 pspp_sheet_view_search_move (GtkWidget *window,
11696 PsppSheetView *tree_view,
11704 GtkTreeModel *model;
11705 PsppSheetSelection *selection;
11707 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
11709 g_return_val_if_fail (text != NULL, FALSE);
11711 len = strlen (text);
11713 if (up && tree_view->priv->selected_iter == 1)
11714 return strlen (text) < 1;
11716 len = strlen (text);
11721 model = pspp_sheet_view_get_model (tree_view);
11722 selection = pspp_sheet_view_get_selection (tree_view);
11725 pspp_sheet_selection_unselect_all (selection);
11726 if (!gtk_tree_model_get_iter_first (model, &iter))
11729 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
11730 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
11735 tree_view->priv->selected_iter += up?(-1):(1);
11740 /* return to old iter */
11742 gtk_tree_model_get_iter_first (model, &iter);
11743 pspp_sheet_view_search_iter (model, selection,
11745 &count, tree_view->priv->selected_iter);
11751 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
11755 gpointer search_data)
11757 gboolean retval = TRUE;
11759 gchar *normalized_string;
11760 gchar *normalized_key;
11761 gchar *case_normalized_string = NULL;
11762 gchar *case_normalized_key = NULL;
11763 GValue value = {0,};
11764 GValue transformed = {0,};
11766 gtk_tree_model_get_value (model, iter, column, &value);
11768 g_value_init (&transformed, G_TYPE_STRING);
11770 if (!g_value_transform (&value, &transformed))
11772 g_value_unset (&value);
11776 g_value_unset (&value);
11778 str = g_value_get_string (&transformed);
11781 g_value_unset (&transformed);
11785 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
11786 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
11788 if (normalized_string && normalized_key)
11790 case_normalized_string = g_utf8_casefold (normalized_string, -1);
11791 case_normalized_key = g_utf8_casefold (normalized_key, -1);
11793 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
11797 g_value_unset (&transformed);
11798 g_free (normalized_key);
11799 g_free (normalized_string);
11800 g_free (case_normalized_key);
11801 g_free (case_normalized_string);
11807 pspp_sheet_view_search_iter (GtkTreeModel *model,
11808 PsppSheetSelection *selection,
11817 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
11819 path = gtk_tree_model_get_path (model, iter);
11820 _pspp_sheet_view_find_node (tree_view, path, &node);
11824 gboolean done = FALSE;
11826 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
11831 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
11833 pspp_sheet_selection_select_iter (selection, iter);
11834 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
11837 gtk_tree_path_free (path);
11846 node = pspp_sheet_view_node_next (tree_view, node);
11852 has_next = gtk_tree_model_iter_next (model, iter);
11855 gtk_tree_path_next (path);
11858 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
11863 gtk_tree_path_free (path);
11865 /* we've run out of tree, done with this func */
11877 pspp_sheet_view_search_init (GtkWidget *entry,
11878 PsppSheetView *tree_view)
11884 GtkTreeModel *model;
11885 PsppSheetSelection *selection;
11887 g_return_if_fail (GTK_IS_ENTRY (entry));
11888 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11890 text = gtk_entry_get_text (GTK_ENTRY (entry));
11892 model = pspp_sheet_view_get_model (tree_view);
11893 selection = pspp_sheet_view_get_selection (tree_view);
11896 pspp_sheet_selection_unselect_all (selection);
11897 if (tree_view->priv->typeselect_flush_timeout
11898 && !tree_view->priv->search_custom_entry_set)
11900 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11901 tree_view->priv->typeselect_flush_timeout =
11902 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11903 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11910 if (!gtk_tree_model_get_iter_first (model, &iter))
11913 ret = pspp_sheet_view_search_iter (model, selection,
11918 tree_view->priv->selected_iter = 1;
11922 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
11923 PsppSheetView *tree_view)
11925 if (tree_view->priv->edited_column == NULL)
11928 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
11929 tree_view->priv->edited_column = NULL;
11931 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
11932 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
11934 g_signal_handlers_disconnect_by_func (cell_editable,
11935 pspp_sheet_view_remove_widget,
11937 g_signal_handlers_disconnect_by_func (cell_editable,
11938 pspp_sheet_view_editable_button_press_event,
11940 g_signal_handlers_disconnect_by_func (cell_editable,
11941 pspp_sheet_view_editable_clicked,
11944 gtk_container_remove (GTK_CONTAINER (tree_view),
11945 GTK_WIDGET (cell_editable));
11947 /* FIXME should only redraw a single node */
11948 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
11952 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
11953 GtkTreePath *cursor_path)
11956 GdkRectangle background_area;
11957 GdkRectangle cell_area;
11958 GtkCellEditable *editable_widget = NULL;
11959 gchar *path_string;
11960 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
11961 gint retval = FALSE;
11964 g_assert (tree_view->priv->focus_column);
11966 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
11969 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
11970 if (cursor_node < 0)
11973 path_string = gtk_tree_path_to_string (cursor_path);
11974 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
11976 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
11977 tree_view->priv->model,
11979 pspp_sheet_view_get_background_area (tree_view,
11981 tree_view->priv->focus_column,
11983 pspp_sheet_view_get_cell_area (tree_view,
11985 tree_view->priv->focus_column,
11988 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
11997 if (editable_widget != NULL)
12001 GtkCellRenderer *cell;
12004 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12006 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12009 area.width -= right + left;
12011 pspp_sheet_view_real_start_editing (tree_view,
12012 tree_view->priv->focus_column,
12021 g_free (path_string);
12026 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12027 GdkEventButton *event,
12028 PsppSheetView *sheet_view)
12032 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12033 "pspp-sheet-view-node"));
12034 return pspp_sheet_view_row_head_clicked (sheet_view,
12036 sheet_view->priv->edited_column,
12041 pspp_sheet_view_editable_clicked (GtkButton *button,
12042 PsppSheetView *sheet_view)
12044 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12049 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12050 PsppSheetViewColumn *column,
12052 GtkCellEditable *cell_editable,
12053 GdkRectangle *cell_area,
12057 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12058 gint pre_val = tree_view->priv->vadjustment->value;
12059 GtkRequisition requisition;
12061 tree_view->priv->edited_column = column;
12062 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12064 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
12065 cell_area->y += pre_val - (int)tree_view->priv->vadjustment->value;
12067 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12068 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12069 tree_view->priv->anchor_column = column;
12071 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12073 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12075 if (requisition.height < cell_area->height)
12077 gint diff = cell_area->height - requisition.height;
12078 pspp_sheet_view_put (tree_view,
12079 GTK_WIDGET (cell_editable),
12080 cell_area->x, cell_area->y + diff/2,
12081 cell_area->width, requisition.height);
12085 pspp_sheet_view_put (tree_view,
12086 GTK_WIDGET (cell_editable),
12087 cell_area->x, cell_area->y,
12088 cell_area->width, cell_area->height);
12091 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12092 (GdkEvent *)event);
12094 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12095 g_signal_connect (cell_editable, "remove-widget",
12096 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12097 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12098 GTK_IS_BUTTON (cell_editable))
12100 g_signal_connect (cell_editable, "button-press-event",
12101 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12103 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12104 GINT_TO_POINTER (gtk_tree_path_get_indices (path)[0]));
12105 g_signal_connect (cell_editable, "clicked",
12106 G_CALLBACK (pspp_sheet_view_editable_clicked),
12112 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12113 gboolean cancel_editing)
12115 PsppSheetViewColumn *column;
12116 GtkCellRenderer *cell;
12118 if (tree_view->priv->edited_column == NULL)
12122 * This is very evil. We need to do this, because
12123 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12124 * later on. If pspp_sheet_view_row_changed notices
12125 * tree_view->priv->edited_column != NULL, it'll call
12126 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12128 * Please read that again if you intend to modify anything here.
12131 column = tree_view->priv->edited_column;
12132 tree_view->priv->edited_column = NULL;
12134 cell = _pspp_sheet_view_column_get_edited_cell (column);
12135 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12137 if (!cancel_editing)
12138 gtk_cell_editable_editing_done (column->editable_widget);
12140 tree_view->priv->edited_column = column;
12142 gtk_cell_editable_remove_widget (column->editable_widget);
12147 * pspp_sheet_view_set_hover_selection:
12148 * @tree_view: a #PsppSheetView
12149 * @hover: %TRUE to enable hover selection mode
12151 * Enables of disables the hover selection mode of @tree_view.
12152 * Hover selection makes the selected row follow the pointer.
12153 * Currently, this works only for the selection modes
12154 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12159 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12162 hover = hover != FALSE;
12164 if (hover != tree_view->priv->hover_selection)
12166 tree_view->priv->hover_selection = hover;
12168 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12173 * pspp_sheet_view_get_hover_selection:
12174 * @tree_view: a #PsppSheetView
12176 * Returns whether hover selection mode is turned on for @tree_view.
12178 * Return value: %TRUE if @tree_view is in hover selection mode
12183 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12185 return tree_view->priv->hover_selection;
12189 * pspp_sheet_view_set_rubber_banding:
12190 * @tree_view: a #PsppSheetView
12191 * @enable: %TRUE to enable rubber banding
12193 * Enables or disables rubber banding in @tree_view. If the selection mode is
12194 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12195 * banding will allow the user to select multiple rows by dragging the mouse.
12200 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12203 enable = enable != FALSE;
12205 if (enable != tree_view->priv->rubber_banding_enable)
12207 tree_view->priv->rubber_banding_enable = enable;
12209 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12214 * pspp_sheet_view_get_rubber_banding:
12215 * @tree_view: a #PsppSheetView
12217 * Returns whether rubber banding is turned on for @tree_view. If the
12218 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12219 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12220 * select multiple rows by dragging the mouse.
12222 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12227 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12229 return tree_view->priv->rubber_banding_enable;
12233 * pspp_sheet_view_is_rubber_banding_active:
12234 * @tree_view: a #PsppSheetView
12236 * Returns whether a rubber banding operation is currently being done
12239 * Return value: %TRUE if a rubber banding operation is currently being
12240 * done in @tree_view.
12245 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12247 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12249 if (tree_view->priv->rubber_banding_enable
12250 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12257 pspp_sheet_view_grab_notify (GtkWidget *widget,
12258 gboolean was_grabbed)
12260 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12262 tree_view->priv->in_grab = !was_grabbed;
12266 tree_view->priv->pressed_button = -1;
12268 if (tree_view->priv->rubber_band_status)
12269 pspp_sheet_view_stop_rubber_band (tree_view);
12274 pspp_sheet_view_state_changed (GtkWidget *widget,
12275 GtkStateType previous_state)
12277 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12279 if (gtk_widget_get_realized (widget))
12281 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
12282 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
12285 gtk_widget_queue_draw (widget);
12289 * pspp_sheet_view_get_grid_lines:
12290 * @tree_view: a #PsppSheetView
12292 * Returns which grid lines are enabled in @tree_view.
12294 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12299 PsppSheetViewGridLines
12300 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12302 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12304 return tree_view->priv->grid_lines;
12308 * pspp_sheet_view_set_grid_lines:
12309 * @tree_view: a #PsppSheetView
12310 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12313 * Sets which grid lines to draw in @tree_view.
12318 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12319 PsppSheetViewGridLines grid_lines)
12321 PsppSheetViewPrivate *priv;
12323 PsppSheetViewGridLines old_grid_lines;
12325 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12327 priv = tree_view->priv;
12328 widget = GTK_WIDGET (tree_view);
12330 old_grid_lines = priv->grid_lines;
12331 priv->grid_lines = grid_lines;
12333 if (gtk_widget_get_realized (widget))
12335 if (grid_lines == PSPP_SHEET_VIEW_GRID_LINES_NONE &&
12336 priv->grid_line_gc)
12338 g_object_unref (priv->grid_line_gc);
12339 priv->grid_line_gc = NULL;
12342 if (grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE &&
12343 !priv->grid_line_gc)
12347 gtk_widget_style_get (widget,
12348 "grid-line-width", &line_width,
12351 priv->grid_line_gc = gdk_gc_new (widget->window);
12352 gdk_gc_copy (priv->grid_line_gc, widget->style->black_gc);
12356 if (old_grid_lines != grid_lines)
12358 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12360 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12365 * pspp_sheet_view_get_special_cells:
12366 * @tree_view: a #PsppSheetView
12368 * Returns which grid lines are enabled in @tree_view.
12370 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12371 * the sheet view contain special cells.
12373 PsppSheetViewSpecialCells
12374 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12376 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12378 return tree_view->priv->special_cells;
12382 * pspp_sheet_view_set_special_cells:
12383 * @tree_view: a #PsppSheetView
12384 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12385 * the sheet view contain special cells.
12387 * Sets whether rows in the sheet view contain special cells, controlling the
12388 * rendering of row selections.
12391 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12392 PsppSheetViewSpecialCells special_cells)
12394 PsppSheetViewPrivate *priv;
12396 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12398 priv = tree_view->priv;
12400 if (priv->special_cells != special_cells)
12402 priv->special_cells = special_cells;
12403 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12404 g_object_notify (G_OBJECT (tree_view), "special-cells");
12409 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12411 /* XXX (re)calculate fixed_height if necessary */
12412 return tree_view->priv->fixed_height;
12416 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12419 g_return_if_fail (fixed_height > 0);
12421 if (tree_view->priv->fixed_height != fixed_height)
12423 tree_view->priv->fixed_height = fixed_height;
12424 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12426 if (!tree_view->priv->fixed_height_set)
12428 tree_view->priv->fixed_height_set = TRUE;
12429 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12434 * pspp_sheet_view_set_tooltip_row:
12435 * @tree_view: a #PsppSheetView
12436 * @tooltip: a #GtkTooltip
12437 * @path: a #GtkTreePath
12439 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12440 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12441 * See also gtk_tooltip_set_tip_area().
12446 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12447 GtkTooltip *tooltip,
12450 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12451 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12453 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12457 * pspp_sheet_view_set_tooltip_cell:
12458 * @tree_view: a #PsppSheetView
12459 * @tooltip: a #GtkTooltip
12460 * @path: (allow-none): a #GtkTreePath or %NULL
12461 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12462 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12464 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12465 * in common. For example if @path is %NULL and @column is set, the tip
12466 * area will be set to the full area covered by @column. See also
12467 * gtk_tooltip_set_tip_area().
12469 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12474 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12475 GtkTooltip *tooltip,
12477 PsppSheetViewColumn *column,
12478 GtkCellRenderer *cell)
12482 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12483 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12484 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12485 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12487 /* Determine x values. */
12488 if (column && cell)
12493 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12494 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12496 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12499 rect.width = width;
12505 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
12506 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12509 rect.width = tmp.width;
12514 rect.width = GTK_WIDGET (tree_view)->allocation.width;
12517 /* Determine y values. */
12522 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
12523 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12526 rect.height = tmp.height;
12531 rect.height = tree_view->priv->vadjustment->page_size;
12534 gtk_tooltip_set_tip_area (tooltip, &rect);
12538 * pspp_sheet_view_get_tooltip_context:
12539 * @tree_view: a #PsppSheetView
12540 * @x: the x coordinate (relative to widget coordinates)
12541 * @y: the y coordinate (relative to widget coordinates)
12542 * @keyboard_tip: whether this is a keyboard tooltip or not
12543 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
12544 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
12545 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
12547 * This function is supposed to be used in a #GtkWidget::query-tooltip
12548 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
12549 * which are received in the signal handler, should be passed to this
12550 * function without modification.
12552 * The return value indicates whether there is a tree view row at the given
12553 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
12554 * tooltips the row returned will be the cursor row. When %TRUE, then any of
12555 * @model, @path and @iter which have been provided will be set to point to
12556 * that row and the corresponding model. @x and @y will always be converted
12557 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
12559 * Return value: whether or not the given tooltip context points to a row.
12564 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
12567 gboolean keyboard_tip,
12568 GtkTreeModel **model,
12569 GtkTreePath **path,
12572 GtkTreePath *tmppath = NULL;
12574 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12575 g_return_val_if_fail (x != NULL, FALSE);
12576 g_return_val_if_fail (y != NULL, FALSE);
12580 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
12587 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
12590 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
12591 &tmppath, NULL, NULL, NULL))
12596 *model = pspp_sheet_view_get_model (tree_view);
12599 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
12605 gtk_tree_path_free (tmppath);
12611 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
12614 gboolean keyboard_tip,
12615 GtkTooltip *tooltip,
12618 GValue value = { 0, };
12619 GValue transformed = { 0, };
12622 GtkTreeModel *model;
12623 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12625 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
12628 &model, &path, &iter))
12631 gtk_tree_model_get_value (model, &iter,
12632 tree_view->priv->tooltip_column, &value);
12634 g_value_init (&transformed, G_TYPE_STRING);
12636 if (!g_value_transform (&value, &transformed))
12638 g_value_unset (&value);
12639 gtk_tree_path_free (path);
12644 g_value_unset (&value);
12646 if (!g_value_get_string (&transformed))
12648 g_value_unset (&transformed);
12649 gtk_tree_path_free (path);
12654 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
12655 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
12657 gtk_tree_path_free (path);
12658 g_value_unset (&transformed);
12664 * pspp_sheet_view_set_tooltip_column:
12665 * @tree_view: a #PsppSheetView
12666 * @column: an integer, which is a valid column number for @tree_view's model
12668 * If you only plan to have simple (text-only) tooltips on full rows, you
12669 * can use this function to have #PsppSheetView handle these automatically
12670 * for you. @column should be set to the column in @tree_view's model
12671 * containing the tooltip texts, or -1 to disable this feature.
12673 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
12674 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
12676 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
12677 * so &, <, etc have to be escaped in the text.
12682 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
12685 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12687 if (column == tree_view->priv->tooltip_column)
12692 g_signal_handlers_disconnect_by_func (tree_view,
12693 pspp_sheet_view_set_tooltip_query_cb,
12695 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
12699 if (tree_view->priv->tooltip_column == -1)
12701 g_signal_connect (tree_view, "query-tooltip",
12702 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
12703 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
12707 tree_view->priv->tooltip_column = column;
12708 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
12712 * pspp_sheet_view_get_tooltip_column:
12713 * @tree_view: a #PsppSheetView
12715 * Returns the column of @tree_view's model which is being used for
12716 * displaying tooltips on @tree_view's rows.
12718 * Return value: the index of the tooltip column that is currently being
12719 * used, or -1 if this is disabled.
12724 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
12726 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12728 return tree_view->priv->tooltip_column;
12732 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
12733 GValue *return_accu,
12734 const GValue *handler_return,
12737 gboolean continue_emission;
12738 gboolean signal_handled;
12740 signal_handled = g_value_get_boolean (handler_return);
12741 g_value_set_boolean (return_accu, signal_handled);
12742 continue_emission = !signal_handled;
12744 return continue_emission;
12748 pspp_sheet_view_grid_lines_get_type (void)
12750 static GType etype = 0;
12751 if (G_UNLIKELY(etype == 0)) {
12752 static const GEnumValue values[] = {
12753 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
12754 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
12755 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
12756 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
12759 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
12765 pspp_sheet_view_special_cells_get_type (void)
12767 static GType etype = 0;
12768 if (G_UNLIKELY(etype == 0)) {
12769 static const GEnumValue values[] = {
12770 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
12771 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
12772 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
12775 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);