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,
150 static void pspp_sheet_view_finalize (GObject *object);
151 static void pspp_sheet_view_set_property (GObject *object,
155 static void pspp_sheet_view_get_property (GObject *object,
160 /* gtkobject signals */
161 static void pspp_sheet_view_destroy (GtkObject *object);
163 /* gtkwidget signals */
164 static void pspp_sheet_view_realize (GtkWidget *widget);
165 static void pspp_sheet_view_unrealize (GtkWidget *widget);
166 static void pspp_sheet_view_map (GtkWidget *widget);
167 static void pspp_sheet_view_size_request (GtkWidget *widget,
168 GtkRequisition *requisition);
169 static void pspp_sheet_view_size_allocate (GtkWidget *widget,
170 GtkAllocation *allocation);
171 static gboolean pspp_sheet_view_expose (GtkWidget *widget,
172 GdkEventExpose *event);
173 static gboolean pspp_sheet_view_key_press (GtkWidget *widget,
175 static gboolean pspp_sheet_view_key_release (GtkWidget *widget,
177 static gboolean pspp_sheet_view_motion (GtkWidget *widget,
178 GdkEventMotion *event);
179 static gboolean pspp_sheet_view_enter_notify (GtkWidget *widget,
180 GdkEventCrossing *event);
181 static gboolean pspp_sheet_view_leave_notify (GtkWidget *widget,
182 GdkEventCrossing *event);
183 static gboolean pspp_sheet_view_button_press (GtkWidget *widget,
184 GdkEventButton *event);
185 static gboolean pspp_sheet_view_button_release (GtkWidget *widget,
186 GdkEventButton *event);
187 static gboolean pspp_sheet_view_grab_broken (GtkWidget *widget,
188 GdkEventGrabBroken *event);
190 static void pspp_sheet_view_set_focus_child (GtkContainer *container,
192 static gint pspp_sheet_view_focus_out (GtkWidget *widget,
193 GdkEventFocus *event);
194 static gint pspp_sheet_view_focus (GtkWidget *widget,
195 GtkDirectionType direction);
196 static void pspp_sheet_view_grab_focus (GtkWidget *widget);
197 static void pspp_sheet_view_style_set (GtkWidget *widget,
198 GtkStyle *previous_style);
199 static void pspp_sheet_view_grab_notify (GtkWidget *widget,
200 gboolean was_grabbed);
201 static void pspp_sheet_view_state_changed (GtkWidget *widget,
202 GtkStateType previous_state);
204 /* container signals */
205 static void pspp_sheet_view_remove (GtkContainer *container,
207 static void pspp_sheet_view_forall (GtkContainer *container,
208 gboolean include_internals,
209 GtkCallback callback,
210 gpointer callback_data);
212 /* Source side drag signals */
213 static void pspp_sheet_view_drag_begin (GtkWidget *widget,
214 GdkDragContext *context);
215 static void pspp_sheet_view_drag_end (GtkWidget *widget,
216 GdkDragContext *context);
217 static void pspp_sheet_view_drag_data_get (GtkWidget *widget,
218 GdkDragContext *context,
219 GtkSelectionData *selection_data,
222 static void pspp_sheet_view_drag_data_delete (GtkWidget *widget,
223 GdkDragContext *context);
225 /* Target side drag signals */
226 static void pspp_sheet_view_drag_leave (GtkWidget *widget,
227 GdkDragContext *context,
229 static gboolean pspp_sheet_view_drag_motion (GtkWidget *widget,
230 GdkDragContext *context,
234 static gboolean pspp_sheet_view_drag_drop (GtkWidget *widget,
235 GdkDragContext *context,
239 static void pspp_sheet_view_drag_data_received (GtkWidget *widget,
240 GdkDragContext *context,
243 GtkSelectionData *selection_data,
247 /* tree_model signals */
248 static void pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
250 GtkAdjustment *vadj);
251 static gboolean pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
252 GtkMovementStep step,
254 static gboolean pspp_sheet_view_real_select_all (PsppSheetView *tree_view);
255 static gboolean pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view);
256 static gboolean pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
257 gboolean start_editing);
258 static gboolean pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view);
259 static void pspp_sheet_view_row_changed (GtkTreeModel *model,
263 static void pspp_sheet_view_row_inserted (GtkTreeModel *model,
267 static void pspp_sheet_view_row_deleted (GtkTreeModel *model,
270 static void pspp_sheet_view_rows_reordered (GtkTreeModel *model,
276 /* Incremental reflow */
277 static gint validate_row (PsppSheetView *tree_view,
281 static void validate_visible_area (PsppSheetView *tree_view);
282 static gboolean validate_rows_handler (PsppSheetView *tree_view);
283 static gboolean presize_handler_callback (gpointer data);
284 static void install_presize_handler (PsppSheetView *tree_view);
285 static void install_scroll_sync_handler (PsppSheetView *tree_view);
286 static void pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
289 static void pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view);
290 static void pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view);
291 static void invalidate_empty_focus (PsppSheetView *tree_view);
293 /* Internal functions */
294 static void pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
297 gboolean add_shifted_binding,
298 GtkMovementStep step,
300 static void pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
302 const GdkRectangle *clip_rect);
303 static gint pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
306 static void pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
307 PsppSheetView *tree_view);
308 static void pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
310 static void pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
311 PsppSheetViewColumn *column,
312 gboolean focus_to_cell);
313 static gboolean pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
314 GdkEventMotion *event);
315 static void pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view);
316 static void pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
318 static void pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
320 static void pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
322 static void pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
324 static void pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
326 gboolean clear_and_select,
327 gboolean clamp_node);
328 static gboolean pspp_sheet_view_has_special_cell (PsppSheetView *tree_view);
329 static void pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view);
330 static void update_prelight (PsppSheetView *tree_view,
333 static void initialize_fixed_height_mode (PsppSheetView *tree_view);
335 /* interactive search */
336 static void pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view);
337 static void pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
338 PsppSheetView *tree_view);
339 static void pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
340 GtkWidget *search_dialog,
342 static void pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
345 static void pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
346 PsppSheetView *tree_view);
347 static void pspp_sheet_view_search_activate (GtkEntry *entry,
348 PsppSheetView *tree_view);
349 static gboolean pspp_sheet_view_real_search_enable_popdown(gpointer data);
350 static void pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
352 static gboolean pspp_sheet_view_search_delete_event (GtkWidget *widget,
354 PsppSheetView *tree_view);
355 static gboolean pspp_sheet_view_search_button_press_event (GtkWidget *widget,
356 GdkEventButton *event,
357 PsppSheetView *tree_view);
358 static gboolean pspp_sheet_view_search_scroll_event (GtkWidget *entry,
359 GdkEventScroll *event,
360 PsppSheetView *tree_view);
361 static gboolean pspp_sheet_view_search_key_press_event (GtkWidget *entry,
363 PsppSheetView *tree_view);
364 static gboolean pspp_sheet_view_search_move (GtkWidget *window,
365 PsppSheetView *tree_view,
367 static gboolean pspp_sheet_view_search_equal_func (GtkTreeModel *model,
371 gpointer search_data);
372 static gboolean pspp_sheet_view_search_iter (GtkTreeModel *model,
373 PsppSheetSelection *selection,
378 static void pspp_sheet_view_search_init (GtkWidget *entry,
379 PsppSheetView *tree_view);
380 static void pspp_sheet_view_put (PsppSheetView *tree_view,
381 GtkWidget *child_widget,
386 static gboolean pspp_sheet_view_start_editing (PsppSheetView *tree_view,
387 GtkTreePath *cursor_path);
388 static gboolean pspp_sheet_view_editable_button_press_event (GtkWidget *,
391 static void pspp_sheet_view_editable_clicked (GtkButton *, PsppSheetView *);
392 static void pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
393 PsppSheetViewColumn *column,
395 GtkCellEditable *cell_editable,
396 GdkRectangle *cell_area,
399 static void pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
400 gboolean cancel_editing);
401 static gboolean pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
402 gboolean keybinding);
403 static gboolean pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view);
404 static PsppSheetViewColumn *pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
405 PsppSheetViewColumn *column,
408 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
409 PsppSheetViewColumn *column,
410 const GdkRectangle *background_area,
411 gboolean subtract_focus_rect,
412 GdkRectangle *cell_area);
413 static gint pspp_sheet_view_find_offset (PsppSheetView *tree_view,
418 static void pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
422 static void pspp_sheet_view_buildable_init (GtkBuildableIface *iface);
425 static gboolean scroll_row_timeout (gpointer data);
426 static void add_scroll_timeout (PsppSheetView *tree_view);
427 static void remove_scroll_timeout (PsppSheetView *tree_view);
429 static guint tree_view_signals [LAST_SIGNAL] = { 0 };
436 G_DEFINE_TYPE_WITH_CODE (PsppSheetView, pspp_sheet_view, GTK_TYPE_CONTAINER,
437 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
438 pspp_sheet_view_buildable_init))
441 pspp_sheet_view_class_init (PsppSheetViewClass *class)
443 GObjectClass *o_class;
444 GtkObjectClass *object_class;
445 GtkWidgetClass *widget_class;
446 GtkContainerClass *container_class;
447 GtkBindingSet *binding_set;
449 binding_set = gtk_binding_set_by_class (class);
451 o_class = (GObjectClass *) class;
452 object_class = (GtkObjectClass *) class;
453 widget_class = (GtkWidgetClass *) class;
454 container_class = (GtkContainerClass *) class;
456 /* GObject signals */
457 o_class->set_property = pspp_sheet_view_set_property;
458 o_class->get_property = pspp_sheet_view_get_property;
459 o_class->finalize = pspp_sheet_view_finalize;
461 /* GtkObject signals */
462 object_class->destroy = pspp_sheet_view_destroy;
464 /* GtkWidget signals */
465 widget_class->map = pspp_sheet_view_map;
466 widget_class->realize = pspp_sheet_view_realize;
467 widget_class->unrealize = pspp_sheet_view_unrealize;
468 widget_class->size_request = pspp_sheet_view_size_request;
469 widget_class->size_allocate = pspp_sheet_view_size_allocate;
470 widget_class->button_press_event = pspp_sheet_view_button_press;
471 widget_class->button_release_event = pspp_sheet_view_button_release;
472 widget_class->grab_broken_event = pspp_sheet_view_grab_broken;
473 /*widget_class->configure_event = pspp_sheet_view_configure;*/
474 widget_class->motion_notify_event = pspp_sheet_view_motion;
475 widget_class->expose_event = pspp_sheet_view_expose;
476 widget_class->key_press_event = pspp_sheet_view_key_press;
477 widget_class->key_release_event = pspp_sheet_view_key_release;
478 widget_class->enter_notify_event = pspp_sheet_view_enter_notify;
479 widget_class->leave_notify_event = pspp_sheet_view_leave_notify;
480 widget_class->focus_out_event = pspp_sheet_view_focus_out;
481 widget_class->drag_begin = pspp_sheet_view_drag_begin;
482 widget_class->drag_end = pspp_sheet_view_drag_end;
483 widget_class->drag_data_get = pspp_sheet_view_drag_data_get;
484 widget_class->drag_data_delete = pspp_sheet_view_drag_data_delete;
485 widget_class->drag_leave = pspp_sheet_view_drag_leave;
486 widget_class->drag_motion = pspp_sheet_view_drag_motion;
487 widget_class->drag_drop = pspp_sheet_view_drag_drop;
488 widget_class->drag_data_received = pspp_sheet_view_drag_data_received;
489 widget_class->focus = pspp_sheet_view_focus;
490 widget_class->grab_focus = pspp_sheet_view_grab_focus;
491 widget_class->style_set = pspp_sheet_view_style_set;
492 widget_class->grab_notify = pspp_sheet_view_grab_notify;
493 widget_class->state_changed = pspp_sheet_view_state_changed;
495 /* GtkContainer signals */
496 container_class->remove = pspp_sheet_view_remove;
497 container_class->forall = pspp_sheet_view_forall;
498 container_class->set_focus_child = pspp_sheet_view_set_focus_child;
500 class->set_scroll_adjustments = pspp_sheet_view_set_adjustments;
501 class->move_cursor = pspp_sheet_view_real_move_cursor;
502 class->select_all = pspp_sheet_view_real_select_all;
503 class->unselect_all = pspp_sheet_view_real_unselect_all;
504 class->select_cursor_row = pspp_sheet_view_real_select_cursor_row;
505 class->toggle_cursor_row = pspp_sheet_view_real_toggle_cursor_row;
506 class->start_interactive_search = pspp_sheet_view_start_interactive_search;
510 g_object_class_install_property (o_class,
512 g_param_spec_object ("model",
513 P_("TreeView Model"),
514 P_("The model for the tree view"),
516 GTK_PARAM_READWRITE));
518 g_object_class_install_property (o_class,
520 g_param_spec_object ("hadjustment",
521 P_("Horizontal Adjustment"),
522 P_("Horizontal Adjustment for the widget"),
524 GTK_PARAM_READWRITE));
526 g_object_class_install_property (o_class,
528 g_param_spec_object ("vadjustment",
529 P_("Vertical Adjustment"),
530 P_("Vertical Adjustment for the widget"),
532 GTK_PARAM_READWRITE));
534 g_object_class_install_property (o_class,
535 PROP_HEADERS_VISIBLE,
536 g_param_spec_boolean ("headers-visible",
537 P_("Headers Visible"),
538 P_("Show the column header buttons"),
540 GTK_PARAM_READWRITE));
542 g_object_class_install_property (o_class,
543 PROP_HEADERS_CLICKABLE,
544 g_param_spec_boolean ("headers-clickable",
545 P_("Headers Clickable"),
546 P_("Column headers respond to click events"),
548 GTK_PARAM_READWRITE));
550 g_object_class_install_property (o_class,
552 g_param_spec_boolean ("reorderable",
554 P_("View is reorderable"),
556 GTK_PARAM_READWRITE));
558 g_object_class_install_property (o_class,
560 g_param_spec_boolean ("rules-hint",
562 P_("Set a hint to the theme engine to draw rows in alternating colors"),
564 GTK_PARAM_READWRITE));
566 g_object_class_install_property (o_class,
568 g_param_spec_boolean ("enable-search",
570 P_("View allows user to search through columns interactively"),
572 GTK_PARAM_READWRITE));
574 g_object_class_install_property (o_class,
576 g_param_spec_int ("search-column",
578 P_("Model column to search through during interactive search"),
582 GTK_PARAM_READWRITE));
585 * PsppSheetView:hover-selection:
587 * Enables of disables the hover selection mode of @tree_view.
588 * Hover selection makes the selected row follow the pointer.
589 * Currently, this works only for the selection modes
590 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
592 * This mode is primarily intended for treeviews in popups, e.g.
593 * in #GtkComboBox or #GtkEntryCompletion.
597 g_object_class_install_property (o_class,
598 PROP_HOVER_SELECTION,
599 g_param_spec_boolean ("hover-selection",
600 P_("Hover Selection"),
601 P_("Whether the selection should follow the pointer"),
603 GTK_PARAM_READWRITE));
605 g_object_class_install_property (o_class,
607 g_param_spec_boolean ("rubber-banding",
608 P_("Rubber Banding"),
609 P_("Whether to enable selection of multiple items by dragging the mouse pointer"),
611 GTK_PARAM_READWRITE));
613 g_object_class_install_property (o_class,
614 PROP_ENABLE_GRID_LINES,
615 g_param_spec_enum ("enable-grid-lines",
616 P_("Enable Grid Lines"),
617 P_("Whether grid lines should be drawn in the tree view"),
618 PSPP_TYPE_SHEET_VIEW_GRID_LINES,
619 PSPP_SHEET_VIEW_GRID_LINES_NONE,
620 GTK_PARAM_READWRITE));
622 g_object_class_install_property (o_class,
624 g_param_spec_int ("tooltip-column",
625 P_("Tooltip Column"),
626 P_("The column in the model containing the tooltip texts for the rows"),
630 GTK_PARAM_READWRITE));
632 /* Style properties */
633 #define _TREE_VIEW_EXPANDER_SIZE 12
634 #define _TREE_VIEW_VERTICAL_SEPARATOR 2
635 #define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
637 gtk_widget_class_install_style_property (widget_class,
638 g_param_spec_int ("expander-size",
640 P_("Size of the expander arrow"),
643 _TREE_VIEW_EXPANDER_SIZE,
644 GTK_PARAM_READABLE));
646 gtk_widget_class_install_style_property (widget_class,
647 g_param_spec_int ("vertical-separator",
648 P_("Vertical Separator Width"),
649 P_("Vertical space between cells. Must be an even number"),
652 _TREE_VIEW_VERTICAL_SEPARATOR,
653 GTK_PARAM_READABLE));
655 gtk_widget_class_install_style_property (widget_class,
656 g_param_spec_int ("horizontal-separator",
657 P_("Horizontal Separator Width"),
658 P_("Horizontal space between cells. Must be an even number"),
661 _TREE_VIEW_HORIZONTAL_SEPARATOR,
662 GTK_PARAM_READABLE));
664 gtk_widget_class_install_style_property (widget_class,
665 g_param_spec_boolean ("allow-rules",
667 P_("Allow drawing of alternating color rows"),
669 GTK_PARAM_READABLE));
671 gtk_widget_class_install_style_property (widget_class,
672 g_param_spec_boxed ("even-row-color",
673 P_("Even Row Color"),
674 P_("Color to use for even rows"),
676 GTK_PARAM_READABLE));
678 gtk_widget_class_install_style_property (widget_class,
679 g_param_spec_boxed ("odd-row-color",
681 P_("Color to use for odd rows"),
683 GTK_PARAM_READABLE));
685 gtk_widget_class_install_style_property (widget_class,
686 g_param_spec_boolean ("row-ending-details",
687 P_("Row Ending details"),
688 P_("Enable extended row background theming"),
690 GTK_PARAM_READABLE));
692 gtk_widget_class_install_style_property (widget_class,
693 g_param_spec_int ("grid-line-width",
694 P_("Grid line width"),
695 P_("Width, in pixels, of the tree view grid lines"),
697 GTK_PARAM_READABLE));
699 gtk_widget_class_install_style_property (widget_class,
700 g_param_spec_int ("tree-line-width",
701 P_("Tree line width"),
702 P_("Width, in pixels, of the tree view lines"),
704 GTK_PARAM_READABLE));
706 gtk_widget_class_install_style_property (widget_class,
707 g_param_spec_string ("tree-line-pattern",
708 P_("Tree line pattern"),
709 P_("Dash pattern used to draw the tree view lines"),
711 GTK_PARAM_READABLE));
715 * PsppSheetView::set-scroll-adjustments
716 * @horizontal: the horizontal #GtkAdjustment
717 * @vertical: the vertical #GtkAdjustment
719 * Set the scroll adjustments for the tree view. Usually scrolled containers
720 * like #GtkScrolledWindow will emit this signal to connect two instances
721 * of #GtkScrollbar to the scroll directions of the #PsppSheetView.
723 widget_class->set_scroll_adjustments_signal =
724 g_signal_new ("set-scroll-adjustments",
725 G_TYPE_FROM_CLASS (o_class),
726 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
727 G_STRUCT_OFFSET (PsppSheetViewClass, set_scroll_adjustments),
729 psppire_marshal_VOID__OBJECT_OBJECT,
732 GTK_TYPE_ADJUSTMENT);
735 * PsppSheetView::row-activated:
736 * @tree_view: the object on which the signal is emitted
737 * @path: the #GtkTreePath for the activated row
738 * @column: the #PsppSheetViewColumn in which the activation occurred
740 * The "row-activated" signal is emitted when the method
741 * pspp_sheet_view_row_activated() is called or the user double clicks
742 * a treeview row. It is also emitted when a non-editable row is
743 * selected and one of the keys: Space, Shift+Space, Return or
746 * For selection handling refer to the <link linkend="TreeWidget">tree
747 * widget conceptual overview</link> as well as #PsppSheetSelection.
749 tree_view_signals[ROW_ACTIVATED] =
750 g_signal_new ("row-activated",
751 G_TYPE_FROM_CLASS (o_class),
752 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
753 G_STRUCT_OFFSET (PsppSheetViewClass, row_activated),
755 psppire_marshal_VOID__BOXED_OBJECT,
758 PSPP_TYPE_SHEET_VIEW_COLUMN);
761 * PsppSheetView::columns-changed:
762 * @tree_view: the object on which the signal is emitted
764 * The number of columns of the treeview has changed.
766 tree_view_signals[COLUMNS_CHANGED] =
767 g_signal_new ("columns-changed",
768 G_TYPE_FROM_CLASS (o_class),
770 G_STRUCT_OFFSET (PsppSheetViewClass, columns_changed),
772 g_cclosure_marshal_VOID__VOID,
776 * PsppSheetView::cursor-changed:
777 * @tree_view: the object on which the signal is emitted
779 * The position of the cursor (focused cell) has changed.
781 tree_view_signals[CURSOR_CHANGED] =
782 g_signal_new ("cursor-changed",
783 G_TYPE_FROM_CLASS (o_class),
785 G_STRUCT_OFFSET (PsppSheetViewClass, cursor_changed),
787 g_cclosure_marshal_VOID__VOID,
790 tree_view_signals[MOVE_CURSOR] =
791 g_signal_new ("move-cursor",
792 G_TYPE_FROM_CLASS (object_class),
793 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
794 G_STRUCT_OFFSET (PsppSheetViewClass, move_cursor),
796 psppire_marshal_BOOLEAN__ENUM_INT,
798 GTK_TYPE_MOVEMENT_STEP,
801 tree_view_signals[SELECT_ALL] =
802 g_signal_new ("select-all",
803 G_TYPE_FROM_CLASS (object_class),
804 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
805 G_STRUCT_OFFSET (PsppSheetViewClass, select_all),
807 psppire_marshal_BOOLEAN__VOID,
810 tree_view_signals[UNSELECT_ALL] =
811 g_signal_new ("unselect-all",
812 G_TYPE_FROM_CLASS (object_class),
813 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
814 G_STRUCT_OFFSET (PsppSheetViewClass, unselect_all),
816 psppire_marshal_BOOLEAN__VOID,
819 tree_view_signals[SELECT_CURSOR_ROW] =
820 g_signal_new ("select-cursor-row",
821 G_TYPE_FROM_CLASS (object_class),
822 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
823 G_STRUCT_OFFSET (PsppSheetViewClass, select_cursor_row),
825 psppire_marshal_BOOLEAN__BOOLEAN,
829 tree_view_signals[TOGGLE_CURSOR_ROW] =
830 g_signal_new ("toggle-cursor-row",
831 G_TYPE_FROM_CLASS (object_class),
832 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
833 G_STRUCT_OFFSET (PsppSheetViewClass, toggle_cursor_row),
835 psppire_marshal_BOOLEAN__VOID,
838 tree_view_signals[START_INTERACTIVE_SEARCH] =
839 g_signal_new ("start-interactive-search",
840 G_TYPE_FROM_CLASS (object_class),
841 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
842 G_STRUCT_OFFSET (PsppSheetViewClass, start_interactive_search),
844 psppire_marshal_BOOLEAN__VOID,
848 pspp_sheet_view_add_move_binding (binding_set, GDK_Up, 0, TRUE,
849 GTK_MOVEMENT_DISPLAY_LINES, -1);
850 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_Up, 0, TRUE,
851 GTK_MOVEMENT_DISPLAY_LINES, -1);
853 pspp_sheet_view_add_move_binding (binding_set, GDK_Down, 0, TRUE,
854 GTK_MOVEMENT_DISPLAY_LINES, 1);
855 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_Down, 0, TRUE,
856 GTK_MOVEMENT_DISPLAY_LINES, 1);
858 pspp_sheet_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK, FALSE,
859 GTK_MOVEMENT_DISPLAY_LINES, -1);
861 pspp_sheet_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK, FALSE,
862 GTK_MOVEMENT_DISPLAY_LINES, 1);
864 pspp_sheet_view_add_move_binding (binding_set, GDK_Home, 0, TRUE,
865 GTK_MOVEMENT_BUFFER_ENDS, -1);
866 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_Home, 0, TRUE,
867 GTK_MOVEMENT_BUFFER_ENDS, -1);
869 pspp_sheet_view_add_move_binding (binding_set, GDK_End, 0, TRUE,
870 GTK_MOVEMENT_BUFFER_ENDS, 1);
871 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_End, 0, TRUE,
872 GTK_MOVEMENT_BUFFER_ENDS, 1);
874 pspp_sheet_view_add_move_binding (binding_set, GDK_Page_Up, 0, TRUE,
875 GTK_MOVEMENT_PAGES, -1);
876 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0, TRUE,
877 GTK_MOVEMENT_PAGES, -1);
879 pspp_sheet_view_add_move_binding (binding_set, GDK_Page_Down, 0, TRUE,
880 GTK_MOVEMENT_PAGES, 1);
881 pspp_sheet_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0, TRUE,
882 GTK_MOVEMENT_PAGES, 1);
885 gtk_binding_entry_add_signal (binding_set, GDK_Right, 0, "move-cursor", 2,
886 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
889 gtk_binding_entry_add_signal (binding_set, GDK_Left, 0, "move-cursor", 2,
890 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
893 gtk_binding_entry_add_signal (binding_set, GDK_KP_Right, 0, "move-cursor", 2,
894 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
897 gtk_binding_entry_add_signal (binding_set, GDK_KP_Left, 0, "move-cursor", 2,
898 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
901 gtk_binding_entry_add_signal (binding_set, GDK_Right, GDK_CONTROL_MASK,
903 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
906 gtk_binding_entry_add_signal (binding_set, GDK_Left, GDK_CONTROL_MASK,
908 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
911 gtk_binding_entry_add_signal (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
913 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
916 gtk_binding_entry_add_signal (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
918 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
921 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
922 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
924 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK, "select-all", 0);
925 gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK, "select-all", 0);
927 gtk_binding_entry_add_signal (binding_set, GDK_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0);
928 gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK, "unselect-all", 0);
930 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_SHIFT_MASK, "select-cursor-row", 1,
931 G_TYPE_BOOLEAN, TRUE);
932 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", 1,
933 G_TYPE_BOOLEAN, TRUE);
935 gtk_binding_entry_add_signal (binding_set, GDK_space, 0, "select-cursor-row", 1,
936 G_TYPE_BOOLEAN, TRUE);
937 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0, "select-cursor-row", 1,
938 G_TYPE_BOOLEAN, TRUE);
939 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0, "select-cursor-row", 1,
940 G_TYPE_BOOLEAN, TRUE);
941 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0, "select-cursor-row", 1,
942 G_TYPE_BOOLEAN, TRUE);
943 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, "select-cursor-row", 1,
944 G_TYPE_BOOLEAN, TRUE);
946 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0, "select-cursor-parent", 0);
947 gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", 0);
949 gtk_binding_entry_add_signal (binding_set, GDK_f, GDK_CONTROL_MASK, "start-interactive-search", 0);
951 gtk_binding_entry_add_signal (binding_set, GDK_F, GDK_CONTROL_MASK, "start-interactive-search", 0);
953 g_type_class_add_private (o_class, sizeof (PsppSheetViewPrivate));
957 pspp_sheet_view_buildable_init (GtkBuildableIface *iface)
959 iface->add_child = pspp_sheet_view_buildable_add_child;
963 pspp_sheet_view_init (PsppSheetView *tree_view)
965 tree_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (tree_view, PSPP_TYPE_SHEET_VIEW, PsppSheetViewPrivate);
967 gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
968 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (tree_view), FALSE);
970 tree_view->priv->flags = PSPP_SHEET_VIEW_DRAW_KEYFOCUS
971 | PSPP_SHEET_VIEW_HEADERS_VISIBLE;
973 /* We need some padding */
974 tree_view->priv->selected = range_tower_create ();
975 tree_view->priv->dy = 0;
976 tree_view->priv->cursor_offset = 0;
977 tree_view->priv->n_columns = 0;
978 tree_view->priv->header_height = 1;
979 tree_view->priv->x_drag = 0;
980 tree_view->priv->drag_pos = -1;
981 tree_view->priv->header_has_focus = FALSE;
982 tree_view->priv->pressed_button = -1;
983 tree_view->priv->press_start_x = -1;
984 tree_view->priv->press_start_y = -1;
985 tree_view->priv->reorderable = FALSE;
986 tree_view->priv->presize_handler_timer = 0;
987 tree_view->priv->scroll_sync_timer = 0;
988 tree_view->priv->fixed_height = -1;
989 pspp_sheet_view_set_adjustments (tree_view, NULL, NULL);
990 tree_view->priv->selection = _pspp_sheet_selection_new_with_tree_view (tree_view);
991 tree_view->priv->enable_search = TRUE;
992 tree_view->priv->search_column = -1;
993 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
994 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
995 tree_view->priv->search_custom_entry_set = FALSE;
996 tree_view->priv->typeselect_flush_timeout = 0;
997 tree_view->priv->init_hadjust_value = TRUE;
998 tree_view->priv->width = 0;
1000 tree_view->priv->hover_selection = FALSE;
1002 tree_view->priv->rubber_banding_enable = FALSE;
1004 tree_view->priv->grid_lines = PSPP_SHEET_VIEW_GRID_LINES_NONE;
1006 tree_view->priv->tooltip_column = -1;
1008 tree_view->priv->post_validation_flag = FALSE;
1010 tree_view->priv->last_button_x = -1;
1011 tree_view->priv->last_button_y = -1;
1013 tree_view->priv->event_last_x = -10000;
1014 tree_view->priv->event_last_y = -10000;
1016 tree_view->priv->prelight_node = -1;
1017 tree_view->priv->rubber_band_start_node = -1;
1018 tree_view->priv->rubber_band_end_node = -1;
1020 tree_view->priv->anchor_column = NULL;
1029 pspp_sheet_view_set_property (GObject *object,
1031 const GValue *value,
1034 PsppSheetView *tree_view;
1036 tree_view = PSPP_SHEET_VIEW (object);
1041 pspp_sheet_view_set_model (tree_view, g_value_get_object (value));
1043 case PROP_HADJUSTMENT:
1044 pspp_sheet_view_set_hadjustment (tree_view, g_value_get_object (value));
1046 case PROP_VADJUSTMENT:
1047 pspp_sheet_view_set_vadjustment (tree_view, g_value_get_object (value));
1049 case PROP_HEADERS_VISIBLE:
1050 pspp_sheet_view_set_headers_visible (tree_view, g_value_get_boolean (value));
1052 case PROP_HEADERS_CLICKABLE:
1053 pspp_sheet_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
1055 case PROP_REORDERABLE:
1056 pspp_sheet_view_set_reorderable (tree_view, g_value_get_boolean (value));
1058 case PROP_RULES_HINT:
1059 pspp_sheet_view_set_rules_hint (tree_view, g_value_get_boolean (value));
1061 case PROP_ENABLE_SEARCH:
1062 pspp_sheet_view_set_enable_search (tree_view, g_value_get_boolean (value));
1064 case PROP_SEARCH_COLUMN:
1065 pspp_sheet_view_set_search_column (tree_view, g_value_get_int (value));
1067 case PROP_HOVER_SELECTION:
1068 tree_view->priv->hover_selection = g_value_get_boolean (value);
1070 case PROP_RUBBER_BANDING:
1071 tree_view->priv->rubber_banding_enable = g_value_get_boolean (value);
1073 case PROP_ENABLE_GRID_LINES:
1074 pspp_sheet_view_set_grid_lines (tree_view, g_value_get_enum (value));
1076 case PROP_TOOLTIP_COLUMN:
1077 pspp_sheet_view_set_tooltip_column (tree_view, g_value_get_int (value));
1080 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1086 pspp_sheet_view_get_property (GObject *object,
1091 PsppSheetView *tree_view;
1093 tree_view = PSPP_SHEET_VIEW (object);
1098 g_value_set_object (value, tree_view->priv->model);
1100 case PROP_HADJUSTMENT:
1101 g_value_set_object (value, tree_view->priv->hadjustment);
1103 case PROP_VADJUSTMENT:
1104 g_value_set_object (value, tree_view->priv->vadjustment);
1106 case PROP_HEADERS_VISIBLE:
1107 g_value_set_boolean (value, pspp_sheet_view_get_headers_visible (tree_view));
1109 case PROP_HEADERS_CLICKABLE:
1110 g_value_set_boolean (value, pspp_sheet_view_get_headers_clickable (tree_view));
1112 case PROP_REORDERABLE:
1113 g_value_set_boolean (value, tree_view->priv->reorderable);
1115 case PROP_RULES_HINT:
1116 g_value_set_boolean (value, tree_view->priv->has_rules);
1118 case PROP_ENABLE_SEARCH:
1119 g_value_set_boolean (value, tree_view->priv->enable_search);
1121 case PROP_SEARCH_COLUMN:
1122 g_value_set_int (value, tree_view->priv->search_column);
1124 case PROP_HOVER_SELECTION:
1125 g_value_set_boolean (value, tree_view->priv->hover_selection);
1127 case PROP_RUBBER_BANDING:
1128 g_value_set_boolean (value, tree_view->priv->rubber_banding_enable);
1130 case PROP_ENABLE_GRID_LINES:
1131 g_value_set_enum (value, tree_view->priv->grid_lines);
1133 case PROP_TOOLTIP_COLUMN:
1134 g_value_set_int (value, tree_view->priv->tooltip_column);
1137 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1143 pspp_sheet_view_finalize (GObject *object)
1145 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->finalize (object);
1151 pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
1152 GtkBuilder *builder,
1156 pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), PSPP_SHEET_VIEW_COLUMN (child));
1159 /* GtkObject Methods
1163 pspp_sheet_view_destroy (GtkObject *object)
1165 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1168 pspp_sheet_view_stop_editing (tree_view, TRUE);
1170 if (tree_view->priv->selected != NULL)
1172 range_tower_destroy (tree_view->priv->selected);
1173 tree_view->priv->selected = NULL;
1176 if (tree_view->priv->columns != NULL)
1178 list = tree_view->priv->columns;
1181 PsppSheetViewColumn *column;
1182 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1184 pspp_sheet_view_remove_column (tree_view, column);
1186 tree_view->priv->columns = NULL;
1189 tree_view->priv->prelight_node = -1;
1191 if (tree_view->priv->selection != NULL)
1193 _pspp_sheet_selection_set_tree_view (tree_view->priv->selection, NULL);
1194 g_object_unref (tree_view->priv->selection);
1195 tree_view->priv->selection = NULL;
1198 if (tree_view->priv->scroll_to_path != NULL)
1200 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1201 tree_view->priv->scroll_to_path = NULL;
1204 if (tree_view->priv->drag_dest_row != NULL)
1206 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
1207 tree_view->priv->drag_dest_row = NULL;
1210 if (tree_view->priv->top_row != NULL)
1212 gtk_tree_row_reference_free (tree_view->priv->top_row);
1213 tree_view->priv->top_row = NULL;
1216 if (tree_view->priv->column_drop_func_data &&
1217 tree_view->priv->column_drop_func_data_destroy)
1219 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
1220 tree_view->priv->column_drop_func_data = NULL;
1223 if (tree_view->priv->destroy_count_destroy &&
1224 tree_view->priv->destroy_count_data)
1226 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
1227 tree_view->priv->destroy_count_data = NULL;
1230 gtk_tree_row_reference_free (tree_view->priv->cursor);
1231 tree_view->priv->cursor = NULL;
1233 gtk_tree_row_reference_free (tree_view->priv->anchor);
1234 tree_view->priv->anchor = NULL;
1236 /* destroy interactive search dialog */
1237 if (tree_view->priv->search_window)
1239 gtk_widget_destroy (tree_view->priv->search_window);
1240 tree_view->priv->search_window = NULL;
1241 tree_view->priv->search_entry = NULL;
1242 if (tree_view->priv->typeselect_flush_timeout)
1244 g_source_remove (tree_view->priv->typeselect_flush_timeout);
1245 tree_view->priv->typeselect_flush_timeout = 0;
1249 if (tree_view->priv->search_destroy && tree_view->priv->search_user_data)
1251 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
1252 tree_view->priv->search_user_data = NULL;
1255 if (tree_view->priv->search_position_destroy && tree_view->priv->search_position_user_data)
1257 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
1258 tree_view->priv->search_position_user_data = NULL;
1261 pspp_sheet_view_set_model (tree_view, NULL);
1263 if (tree_view->priv->hadjustment)
1265 g_object_unref (tree_view->priv->hadjustment);
1266 tree_view->priv->hadjustment = NULL;
1268 if (tree_view->priv->vadjustment)
1270 g_object_unref (tree_view->priv->vadjustment);
1271 tree_view->priv->vadjustment = NULL;
1274 GTK_OBJECT_CLASS (pspp_sheet_view_parent_class)->destroy (object);
1279 /* GtkWidget Methods
1282 /* GtkWidget::map helper */
1284 pspp_sheet_view_map_buttons (PsppSheetView *tree_view)
1288 g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (tree_view)));
1290 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
1292 PsppSheetViewColumn *column;
1294 for (list = tree_view->priv->columns; list; list = list->next)
1296 column = list->data;
1297 if (gtk_widget_get_visible (column->button) &&
1298 !gtk_widget_get_mapped (column->button))
1299 gtk_widget_map (column->button);
1301 for (list = tree_view->priv->columns; list; list = list->next)
1303 column = list->data;
1304 if (column->visible == FALSE)
1306 if (column->resizable)
1308 gdk_window_raise (column->window);
1309 gdk_window_show (column->window);
1312 gdk_window_hide (column->window);
1314 gdk_window_show (tree_view->priv->header_window);
1319 pspp_sheet_view_map (GtkWidget *widget)
1321 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1324 gtk_widget_set_mapped (widget, TRUE);
1326 tmp_list = tree_view->priv->children;
1329 PsppSheetViewChild *child = tmp_list->data;
1330 tmp_list = tmp_list->next;
1332 if (gtk_widget_get_visible (child->widget))
1334 if (!gtk_widget_get_mapped (child->widget))
1335 gtk_widget_map (child->widget);
1338 gdk_window_show (tree_view->priv->bin_window);
1340 pspp_sheet_view_map_buttons (tree_view);
1342 gdk_window_show (widget->window);
1346 pspp_sheet_view_realize (GtkWidget *widget)
1348 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1350 GdkWindowAttr attributes;
1351 gint attributes_mask;
1353 gtk_widget_set_realized (widget, TRUE);
1355 /* Make the main, clipping window */
1356 attributes.window_type = GDK_WINDOW_CHILD;
1357 attributes.x = widget->allocation.x;
1358 attributes.y = widget->allocation.y;
1359 attributes.width = widget->allocation.width;
1360 attributes.height = widget->allocation.height;
1361 attributes.wclass = GDK_INPUT_OUTPUT;
1362 attributes.visual = gtk_widget_get_visual (widget);
1363 attributes.colormap = gtk_widget_get_colormap (widget);
1364 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1366 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1368 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1369 &attributes, attributes_mask);
1370 gdk_window_set_user_data (widget->window, widget);
1372 /* Make the window for the tree */
1374 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1375 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1376 attributes.height = widget->allocation.height;
1377 attributes.event_mask = (GDK_EXPOSURE_MASK |
1379 GDK_POINTER_MOTION_MASK |
1380 GDK_ENTER_NOTIFY_MASK |
1381 GDK_LEAVE_NOTIFY_MASK |
1382 GDK_BUTTON_PRESS_MASK |
1383 GDK_BUTTON_RELEASE_MASK |
1384 gtk_widget_get_events (widget));
1386 tree_view->priv->bin_window = gdk_window_new (widget->window,
1387 &attributes, attributes_mask);
1388 gdk_window_set_user_data (tree_view->priv->bin_window, widget);
1390 /* Make the column header window */
1393 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1394 attributes.height = tree_view->priv->header_height;
1395 attributes.event_mask = (GDK_EXPOSURE_MASK |
1397 GDK_BUTTON_PRESS_MASK |
1398 GDK_BUTTON_RELEASE_MASK |
1399 GDK_KEY_PRESS_MASK |
1400 GDK_KEY_RELEASE_MASK |
1401 gtk_widget_get_events (widget));
1403 tree_view->priv->header_window = gdk_window_new (widget->window,
1404 &attributes, attributes_mask);
1405 gdk_window_set_user_data (tree_view->priv->header_window, widget);
1407 /* Add them all up. */
1408 widget->style = gtk_style_attach (widget->style, widget->window);
1409 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1410 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
1411 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
1413 tmp_list = tree_view->priv->children;
1416 PsppSheetViewChild *child = tmp_list->data;
1417 tmp_list = tmp_list->next;
1419 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1422 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1423 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1425 /* Need to call those here, since they create GCs */
1426 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1428 install_presize_handler (tree_view);
1432 pspp_sheet_view_unrealize (GtkWidget *widget)
1434 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1435 PsppSheetViewPrivate *priv = tree_view->priv;
1438 if (priv->scroll_timeout != 0)
1440 g_source_remove (priv->scroll_timeout);
1441 priv->scroll_timeout = 0;
1444 if (priv->open_dest_timeout != 0)
1446 g_source_remove (priv->open_dest_timeout);
1447 priv->open_dest_timeout = 0;
1450 if (priv->presize_handler_timer != 0)
1452 g_source_remove (priv->presize_handler_timer);
1453 priv->presize_handler_timer = 0;
1456 if (priv->validate_rows_timer != 0)
1458 g_source_remove (priv->validate_rows_timer);
1459 priv->validate_rows_timer = 0;
1462 if (priv->scroll_sync_timer != 0)
1464 g_source_remove (priv->scroll_sync_timer);
1465 priv->scroll_sync_timer = 0;
1468 if (priv->typeselect_flush_timeout)
1470 g_source_remove (priv->typeselect_flush_timeout);
1471 priv->typeselect_flush_timeout = 0;
1474 for (list = priv->columns; list; list = list->next)
1475 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1477 gdk_window_set_user_data (priv->bin_window, NULL);
1478 gdk_window_destroy (priv->bin_window);
1479 priv->bin_window = NULL;
1481 gdk_window_set_user_data (priv->header_window, NULL);
1482 gdk_window_destroy (priv->header_window);
1483 priv->header_window = NULL;
1485 if (priv->drag_window)
1487 gdk_window_set_user_data (priv->drag_window, NULL);
1488 gdk_window_destroy (priv->drag_window);
1489 priv->drag_window = NULL;
1492 if (priv->drag_highlight_window)
1494 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1495 gdk_window_destroy (priv->drag_highlight_window);
1496 priv->drag_highlight_window = NULL;
1499 if (priv->grid_line_gc)
1501 g_object_unref (priv->grid_line_gc);
1502 priv->grid_line_gc = NULL;
1505 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1508 /* GtkWidget::size_request helper */
1510 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1514 tree_view->priv->header_height = 0;
1516 if (tree_view->priv->model)
1518 for (list = tree_view->priv->columns; list; list = list->next)
1520 GtkRequisition requisition;
1521 PsppSheetViewColumn *column = list->data;
1523 if (column->button == NULL)
1526 column = list->data;
1528 gtk_widget_size_request (column->button, &requisition);
1529 column->button_request = requisition.width;
1530 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1536 /* Called only by ::size_request */
1538 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1541 PsppSheetViewColumn *column;
1544 if (tree_view->priv->model == NULL)
1546 tree_view->priv->width = 0;
1547 tree_view->priv->prev_width = 0;
1548 tree_view->priv->height = 0;
1552 tree_view->priv->prev_width = tree_view->priv->width;
1553 tree_view->priv->width = 0;
1555 /* keep this in sync with size_allocate below */
1556 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1558 gint real_requested_width = 0;
1559 column = list->data;
1560 if (!column->visible)
1563 if (column->use_resized_width)
1565 real_requested_width = column->resized_width;
1569 real_requested_width = column->fixed_width;
1572 if (column->min_width != -1)
1573 real_requested_width = MAX (real_requested_width, column->min_width);
1574 if (column->max_width != -1)
1575 real_requested_width = MIN (real_requested_width, column->max_width);
1577 tree_view->priv->width += real_requested_width;
1580 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1584 pspp_sheet_view_size_request (GtkWidget *widget,
1585 GtkRequisition *requisition)
1587 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1590 /* we validate some rows initially just to make sure we have some size.
1591 * In practice, with a lot of static lists, this should get a good width.
1593 initialize_fixed_height_mode (tree_view);
1594 pspp_sheet_view_size_request_columns (tree_view);
1595 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1597 requisition->width = tree_view->priv->width;
1598 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1600 tmp_list = tree_view->priv->children;
1604 PsppSheetViewChild *child = tmp_list->data;
1605 GtkRequisition child_requisition;
1607 tmp_list = tmp_list->next;
1609 if (gtk_widget_get_visible (child->widget))
1610 gtk_widget_size_request (child->widget, &child_requisition);
1615 invalidate_column (PsppSheetView *tree_view,
1616 PsppSheetViewColumn *column)
1618 gint column_offset = 0;
1620 GtkWidget *widget = GTK_WIDGET (tree_view);
1623 if (!gtk_widget_get_realized (widget))
1626 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1627 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1629 list = (rtl ? list->prev : list->next))
1631 PsppSheetViewColumn *tmpcolumn = list->data;
1632 if (tmpcolumn == column)
1634 GdkRectangle invalid_rect;
1636 invalid_rect.x = column_offset;
1638 invalid_rect.width = column->width;
1639 invalid_rect.height = widget->allocation.height;
1641 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
1645 column_offset += tmpcolumn->width;
1650 invalidate_last_column (PsppSheetView *tree_view)
1655 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1657 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1659 last_column = (rtl ? last_column->next : last_column->prev))
1661 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1663 invalidate_column (tree_view, last_column->data);
1670 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1671 PsppSheetViewColumn *column)
1673 gint real_requested_width;
1675 if (column->use_resized_width)
1677 real_requested_width = column->resized_width;
1681 real_requested_width = column->fixed_width;
1684 if (column->min_width != -1)
1685 real_requested_width = MAX (real_requested_width, column->min_width);
1686 if (column->max_width != -1)
1687 real_requested_width = MIN (real_requested_width, column->max_width);
1689 return real_requested_width;
1692 /* GtkWidget::size_allocate helper */
1694 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1695 gboolean *width_changed)
1697 PsppSheetView *tree_view;
1698 GList *list, *first_column, *last_column;
1699 PsppSheetViewColumn *column;
1700 GtkAllocation allocation;
1702 gint extra, extra_per_column, extra_for_last;
1703 gint full_requested_width = 0;
1704 gint number_of_expand_columns = 0;
1705 gboolean column_changed = FALSE;
1707 gboolean update_expand;
1709 tree_view = PSPP_SHEET_VIEW (widget);
1711 for (last_column = g_list_last (tree_view->priv->columns);
1712 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1713 last_column = last_column->prev)
1715 if (last_column == NULL)
1718 for (first_column = g_list_first (tree_view->priv->columns);
1719 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1720 first_column = first_column->next)
1724 allocation.height = tree_view->priv->header_height;
1726 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1728 /* find out how many extra space and expandable columns we have */
1729 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1731 column = (PsppSheetViewColumn *)list->data;
1733 if (!column->visible)
1736 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1739 number_of_expand_columns++;
1742 /* Only update the expand value if the width of the widget has changed,
1743 * or the number of expand columns has changed, or if there are no expand
1744 * columns, or if we didn't have an size-allocation yet after the
1745 * last validated node.
1747 update_expand = (width_changed && *width_changed == TRUE)
1748 || number_of_expand_columns != tree_view->priv->last_number_of_expand_columns
1749 || number_of_expand_columns == 0
1750 || tree_view->priv->post_validation_flag == TRUE;
1752 tree_view->priv->post_validation_flag = FALSE;
1756 extra = tree_view->priv->last_extra_space;
1757 extra_for_last = MAX (widget->allocation.width - full_requested_width - extra, 0);
1761 extra = MAX (widget->allocation.width - full_requested_width, 0);
1764 tree_view->priv->last_extra_space = extra;
1767 if (number_of_expand_columns > 0)
1768 extra_per_column = extra/number_of_expand_columns;
1770 extra_per_column = 0;
1774 tree_view->priv->last_extra_space_per_column = extra_per_column;
1775 tree_view->priv->last_number_of_expand_columns = number_of_expand_columns;
1778 for (list = (rtl ? last_column : first_column);
1779 list != (rtl ? first_column->prev : last_column->next);
1780 list = (rtl ? list->prev : list->next))
1782 gint real_requested_width = 0;
1785 column = list->data;
1786 old_width = column->width;
1788 if (!column->visible)
1791 /* We need to handle the dragged button specially.
1793 if (column == tree_view->priv->drag_column)
1795 GtkAllocation drag_allocation;
1796 gdk_drawable_get_size (tree_view->priv->drag_window,
1797 &(drag_allocation.width),
1798 &(drag_allocation.height));
1799 drag_allocation.x = 0;
1800 drag_allocation.y = 0;
1801 gtk_widget_size_allocate (tree_view->priv->drag_column->button,
1803 width += drag_allocation.width;
1807 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1809 allocation.x = width;
1810 column->width = real_requested_width;
1814 if (number_of_expand_columns == 1)
1816 /* We add the remander to the last column as
1818 column->width += extra;
1822 column->width += extra_per_column;
1823 extra -= extra_per_column;
1824 number_of_expand_columns --;
1827 else if (number_of_expand_columns == 0 &&
1828 list == last_column)
1830 column->width += extra;
1833 /* In addition to expand, the last column can get even more
1834 * extra space so all available space is filled up.
1836 if (extra_for_last > 0 && list == last_column)
1837 column->width += extra_for_last;
1839 g_object_notify (G_OBJECT (column), "width");
1841 allocation.width = column->width;
1842 width += column->width;
1844 if (column->width > old_width)
1845 column_changed = TRUE;
1847 gtk_widget_size_allocate (column->button, &allocation);
1850 gdk_window_move_resize (column->window,
1851 allocation.x + (rtl ? 0 : allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1853 TREE_VIEW_DRAG_WIDTH, allocation.height);
1856 /* We change the width here. The user might have been resizing columns,
1857 * so the total width of the tree view changes.
1859 tree_view->priv->width = width;
1861 *width_changed = TRUE;
1864 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
1869 pspp_sheet_view_size_allocate (GtkWidget *widget,
1870 GtkAllocation *allocation)
1872 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1874 gboolean width_changed = FALSE;
1875 gint old_width = widget->allocation.width;
1877 if (allocation->width != widget->allocation.width)
1878 width_changed = TRUE;
1880 widget->allocation = *allocation;
1882 tmp_list = tree_view->priv->children;
1886 GtkAllocation allocation;
1888 PsppSheetViewChild *child = tmp_list->data;
1889 tmp_list = tmp_list->next;
1891 /* totally ignore our child's requisition */
1892 allocation.x = child->x;
1893 allocation.y = child->y;
1894 allocation.width = child->width;
1895 allocation.height = child->height;
1896 gtk_widget_size_allocate (child->widget, &allocation);
1899 /* We size-allocate the columns first because the width of the
1900 * tree view (used in updating the adjustments below) might change.
1902 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
1904 tree_view->priv->hadjustment->page_size = allocation->width;
1905 tree_view->priv->hadjustment->page_increment = allocation->width * 0.9;
1906 tree_view->priv->hadjustment->step_increment = allocation->width * 0.1;
1907 tree_view->priv->hadjustment->lower = 0;
1908 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->page_size, tree_view->priv->width);
1910 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
1912 if (allocation->width < tree_view->priv->width)
1914 if (tree_view->priv->init_hadjust_value)
1916 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
1917 tree_view->priv->init_hadjust_value = FALSE;
1919 else if (allocation->width != old_width)
1921 tree_view->priv->hadjustment->value = CLAMP (tree_view->priv->hadjustment->value - allocation->width + old_width, 0, tree_view->priv->width - allocation->width);
1924 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);
1928 tree_view->priv->hadjustment->value = 0;
1929 tree_view->priv->init_hadjust_value = TRUE;
1933 if (tree_view->priv->hadjustment->value + allocation->width > tree_view->priv->width)
1934 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
1936 gtk_adjustment_changed (tree_view->priv->hadjustment);
1938 tree_view->priv->vadjustment->page_size = allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view);
1939 tree_view->priv->vadjustment->step_increment = tree_view->priv->vadjustment->page_size * 0.1;
1940 tree_view->priv->vadjustment->page_increment = tree_view->priv->vadjustment->page_size * 0.9;
1941 tree_view->priv->vadjustment->lower = 0;
1942 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->page_size, tree_view->priv->height);
1944 gtk_adjustment_changed (tree_view->priv->vadjustment);
1946 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
1947 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
1948 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
1949 else if (tree_view->priv->vadjustment->value + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
1950 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
1951 tree_view->priv->height - tree_view->priv->vadjustment->page_size);
1952 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
1953 pspp_sheet_view_top_row_to_dy (tree_view);
1955 pspp_sheet_view_dy_to_top_row (tree_view);
1957 if (gtk_widget_get_realized (widget))
1959 gdk_window_move_resize (widget->window,
1960 allocation->x, allocation->y,
1961 allocation->width, allocation->height);
1962 gdk_window_move_resize (tree_view->priv->header_window,
1963 - (gint) tree_view->priv->hadjustment->value,
1965 MAX (tree_view->priv->width, allocation->width),
1966 tree_view->priv->header_height);
1967 gdk_window_move_resize (tree_view->priv->bin_window,
1968 - (gint) tree_view->priv->hadjustment->value,
1969 TREE_VIEW_HEADER_HEIGHT (tree_view),
1970 MAX (tree_view->priv->width, allocation->width),
1971 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
1974 if (tree_view->priv->row_count == 0)
1975 invalidate_empty_focus (tree_view);
1977 if (gtk_widget_get_realized (widget))
1979 gboolean has_expand_column = FALSE;
1980 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1982 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
1984 has_expand_column = TRUE;
1989 /* This little hack only works if we have an LTR locale, and no column has the */
1992 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
1993 ! has_expand_column)
1994 invalidate_last_column (tree_view);
1996 gtk_widget_queue_draw (widget);
2001 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2003 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2005 GtkWidget *widget = GTK_WIDGET (tree_view);
2007 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2008 gtk_widget_grab_focus (widget);
2009 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2013 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2016 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2020 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2023 range_tower_set1 (tree_view->priv->selected, node, 1);
2027 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2030 range_tower_set0 (tree_view->priv->selected, node, 1);
2034 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2037 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2041 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2044 return node > 0 ? node - 1 : -1;
2048 all_columns_selected (PsppSheetView *tree_view)
2052 for (list = tree_view->priv->columns; list; list = list->next)
2054 PsppSheetViewColumn *column = list->data;
2055 if (column->selectable && !column->selected)
2063 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2065 PsppSheetViewColumn *column,
2066 GdkEventButton *event)
2068 PsppSheetSelection *selection;
2069 PsppSheetSelectionMode mode;
2071 gboolean update_anchor;
2075 g_return_val_if_fail (tree_view != NULL, FALSE);
2076 g_return_val_if_fail (column != NULL, FALSE);
2078 selection = tree_view->priv->selection;
2079 mode = pspp_sheet_selection_get_mode (selection);
2080 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2083 if (!column->row_head)
2088 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2089 if (event->type != GDK_BUTTON_PRESS
2090 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2096 path = gtk_tree_path_new_from_indices (node, -1);
2099 pspp_sheet_selection_unselect_all (selection);
2100 pspp_sheet_selection_select_path (selection, path);
2101 pspp_sheet_selection_select_all_columns (selection);
2102 update_anchor = TRUE;
2105 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2107 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2108 || !all_columns_selected (tree_view))
2110 pspp_sheet_selection_unselect_all (selection);
2111 pspp_sheet_selection_select_path (selection, path);
2112 pspp_sheet_selection_select_all_columns (selection);
2113 update_anchor = TRUE;
2117 update_anchor = handled = FALSE;
2119 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2120 && modifiers == GDK_CONTROL_MASK)
2122 if (!all_columns_selected (tree_view))
2124 pspp_sheet_selection_unselect_all (selection);
2125 pspp_sheet_selection_select_all_columns (selection);
2128 if (pspp_sheet_selection_path_is_selected (selection, path))
2129 pspp_sheet_selection_unselect_path (selection, path);
2131 pspp_sheet_selection_select_path (selection, path);
2132 update_anchor = TRUE;
2135 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2136 && modifiers == GDK_SHIFT_MASK)
2138 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2139 GtkTreePath *anchor_path;
2141 if (all_columns_selected (tree_view)
2142 && gtk_tree_row_reference_valid (anchor))
2144 update_anchor = FALSE;
2145 anchor_path = gtk_tree_row_reference_get_path (anchor);
2149 update_anchor = TRUE;
2150 anchor_path = gtk_tree_path_copy (path);
2153 pspp_sheet_selection_unselect_all (selection);
2154 pspp_sheet_selection_select_range (selection, anchor_path, path);
2155 pspp_sheet_selection_select_all_columns (selection);
2157 gtk_tree_path_free (anchor_path);
2162 update_anchor = handled = FALSE;
2166 if (tree_view->priv->anchor)
2167 gtk_tree_row_reference_free (tree_view->priv->anchor);
2168 tree_view->priv->anchor =
2169 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2170 tree_view->priv->model,
2174 gtk_tree_path_free (path);
2179 find_click (PsppSheetView *tree_view,
2182 PsppSheetViewColumn **column,
2183 GdkRectangle *background_area,
2184 GdkRectangle *cell_area)
2191 /* find the node that was clicked */
2192 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2195 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2200 background_area->y = y_offset + y;
2201 background_area->height = ROW_HEIGHT (tree_view);
2202 background_area->x = 0;
2204 /* Let the column have a chance at selecting it. */
2205 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2206 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2207 list; list = (rtl ? list->prev : list->next))
2209 PsppSheetViewColumn *candidate = list->data;
2211 if (!candidate->visible)
2214 background_area->width = candidate->width;
2215 if ((background_area->x > x) ||
2216 (background_area->x + background_area->width <= x))
2218 background_area->x += background_area->width;
2222 /* we found the focus column */
2224 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2226 *column = candidate;
2234 pspp_sheet_view_button_press (GtkWidget *widget,
2235 GdkEventButton *event)
2237 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2239 PsppSheetViewColumn *column = NULL;
2241 GdkRectangle background_area;
2242 GdkRectangle cell_area;
2245 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2246 pspp_sheet_view_stop_editing (tree_view, FALSE);
2249 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2250 * we're done handling the button press.
2253 if (event->window == tree_view->priv->bin_window)
2258 gint pre_val, aft_val;
2259 PsppSheetViewColumn *column = NULL;
2260 GtkCellRenderer *focus_cell = NULL;
2261 gboolean row_double_click = FALSE;
2262 gboolean node_selected;
2265 if (tree_view->priv->row_count == 0)
2267 grab_focus_and_unset_draw_keyfocus (tree_view);
2271 if (!find_click (tree_view, event->x, event->y, &node, &column,
2272 &background_area, &cell_area))
2274 grab_focus_and_unset_draw_keyfocus (tree_view);
2278 tree_view->priv->focus_column = column;
2280 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2284 node_selected = pspp_sheet_view_node_is_selected (tree_view, node);
2285 pre_val = tree_view->priv->vadjustment->value;
2287 path = _pspp_sheet_view_find_path (tree_view, node);
2289 /* we only handle selection modifications on the first button press
2291 if (event->type == GDK_BUTTON_PRESS)
2293 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2294 tree_view->priv->ctrl_pressed = TRUE;
2295 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2296 tree_view->priv->shift_pressed = TRUE;
2298 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2300 pspp_sheet_view_column_focus_cell (column, focus_cell);
2302 if (event->state & GDK_CONTROL_MASK)
2304 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
2305 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2307 else if (event->state & GDK_SHIFT_MASK)
2309 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
2310 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE);
2314 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
2317 if (tree_view->priv->anchor_column == NULL ||
2318 !(event->state & GDK_SHIFT_MASK))
2319 tree_view->priv->anchor_column = column;
2320 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2321 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2322 tree_view->priv->anchor_column,
2325 tree_view->priv->ctrl_pressed = FALSE;
2326 tree_view->priv->shift_pressed = FALSE;
2329 /* the treeview may have been scrolled because of _set_cursor,
2333 aft_val = tree_view->priv->vadjustment->value;
2334 dval = pre_val - aft_val;
2336 cell_area.y += dval;
2337 background_area.y += dval;
2339 /* Save press to possibly begin a drag
2341 if (!tree_view->priv->in_grab &&
2342 tree_view->priv->pressed_button < 0)
2344 tree_view->priv->pressed_button = event->button;
2345 tree_view->priv->press_start_x = event->x;
2346 tree_view->priv->press_start_y = event->y;
2347 tree_view->priv->press_start_node = node;
2349 if (tree_view->priv->rubber_banding_enable
2351 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2352 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2354 tree_view->priv->press_start_y += tree_view->priv->dy;
2355 tree_view->priv->rubber_band_x = event->x;
2356 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2357 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2359 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2360 tree_view->priv->rubber_band_ctrl = TRUE;
2361 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2362 tree_view->priv->rubber_band_shift = TRUE;
2367 /* Test if a double click happened on the same row. */
2368 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2370 int double_click_time, double_click_distance;
2372 g_object_get (gtk_settings_get_for_screen (
2373 gtk_widget_get_screen (widget)),
2374 "gtk-double-click-time", &double_click_time,
2375 "gtk-double-click-distance", &double_click_distance,
2378 /* Same conditions as _gdk_event_button_generate */
2379 if (tree_view->priv->last_button_x != -1 &&
2380 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2381 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2382 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2384 /* We do no longer compare paths of this row and the
2385 * row clicked previously. We use the double click
2386 * distance to decide whether this is a valid click,
2387 * allowing the mouse to slightly move over another row.
2389 row_double_click = TRUE;
2391 tree_view->priv->last_button_time = 0;
2392 tree_view->priv->last_button_x = -1;
2393 tree_view->priv->last_button_y = -1;
2397 tree_view->priv->last_button_time = event->time;
2398 tree_view->priv->last_button_x = event->x;
2399 tree_view->priv->last_button_y = event->y;
2403 if (row_double_click)
2405 gtk_grab_remove (widget);
2406 pspp_sheet_view_row_activated (tree_view, path, column);
2408 if (tree_view->priv->pressed_button == event->button)
2409 tree_view->priv->pressed_button = -1;
2412 gtk_tree_path_free (path);
2414 /* If we activated the row through a double click we don't want to grab
2415 * focus back, as moving focus to another widget is pretty common.
2417 if (!row_double_click)
2418 grab_focus_and_unset_draw_keyfocus (tree_view);
2423 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2425 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2427 column = list->data;
2428 if (event->window == column->window &&
2429 column->resizable &&
2434 if (gdk_pointer_grab (column->window, FALSE,
2435 GDK_POINTER_MOTION_HINT_MASK |
2436 GDK_BUTTON1_MOTION_MASK |
2437 GDK_BUTTON_RELEASE_MASK,
2438 NULL, NULL, event->time))
2441 gtk_grab_add (widget);
2442 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2443 column->resized_width = column->width - tree_view->priv->last_extra_space_per_column;
2445 /* block attached dnd signal handler */
2446 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2448 g_signal_handlers_block_matched (widget,
2449 G_SIGNAL_MATCH_DATA,
2453 tree_view->priv->drag_pos = i;
2454 tree_view->priv->x_drag = column->button->allocation.x + (rtl ? 0 : column->button->allocation.width);
2456 if (!gtk_widget_has_focus (widget))
2457 gtk_widget_grab_focus (widget);
2465 /* GtkWidget::button_release_event helper */
2467 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2468 GdkEventButton *event)
2470 PsppSheetView *tree_view;
2474 tree_view = PSPP_SHEET_VIEW (widget);
2476 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2477 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2478 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2480 /* Move the button back */
2481 g_object_ref (tree_view->priv->drag_column->button);
2482 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2483 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2484 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2485 g_object_unref (tree_view->priv->drag_column->button);
2486 gtk_widget_queue_resize (widget);
2487 if (tree_view->priv->drag_column->resizable)
2489 gdk_window_raise (tree_view->priv->drag_column->window);
2490 gdk_window_show (tree_view->priv->drag_column->window);
2493 gdk_window_hide (tree_view->priv->drag_column->window);
2495 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2499 if (tree_view->priv->cur_reorder &&
2500 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2501 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2502 tree_view->priv->cur_reorder->right_column);
2506 if (tree_view->priv->cur_reorder &&
2507 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2508 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2509 tree_view->priv->cur_reorder->left_column);
2511 tree_view->priv->drag_column = NULL;
2512 gdk_window_hide (tree_view->priv->drag_window);
2514 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2515 g_slice_free (PsppSheetViewColumnReorder, l->data);
2516 g_list_free (tree_view->priv->column_drag_info);
2517 tree_view->priv->column_drag_info = NULL;
2518 tree_view->priv->cur_reorder = NULL;
2520 if (tree_view->priv->drag_highlight_window)
2521 gdk_window_hide (tree_view->priv->drag_highlight_window);
2523 /* Reset our flags */
2524 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2525 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2530 /* GtkWidget::button_release_event helper */
2532 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2533 GdkEventButton *event)
2535 PsppSheetView *tree_view;
2538 tree_view = PSPP_SHEET_VIEW (widget);
2540 tree_view->priv->drag_pos = -1;
2542 /* unblock attached dnd signal handler */
2543 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2545 g_signal_handlers_unblock_matched (widget,
2546 G_SIGNAL_MATCH_DATA,
2550 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2551 gtk_grab_remove (widget);
2552 gdk_display_pointer_ungrab (gdk_drawable_get_display (event->window),
2558 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2559 GdkEventButton *event)
2561 GtkCellEditable *cell_editable;
2566 PsppSheetViewColumn *column;
2567 GdkRectangle background_area;
2568 GdkRectangle cell_area;
2574 if (event->window != tree_view->priv->bin_window)
2577 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2581 /* decide if we edit */
2582 path = _pspp_sheet_view_find_path (tree_view, node);
2583 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2584 if (event->button != 1 || modifiers)
2587 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2588 pspp_sheet_view_column_cell_set_cell_data (column,
2589 tree_view->priv->model,
2592 if (!pspp_sheet_view_column_get_quick_edit (column)
2593 && _pspp_sheet_view_column_has_editable_cell (column))
2596 flags = 0; /* FIXME: get the right flags */
2597 path_string = gtk_tree_path_to_string (path);
2599 if (!_pspp_sheet_view_column_cell_event (column,
2607 if (cell_editable == NULL)
2610 pspp_sheet_view_real_set_cursor (tree_view, path,
2612 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2615 _pspp_sheet_view_column_get_neighbor_sizes (
2616 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2619 area.width -= right + left;
2621 pspp_sheet_view_real_start_editing (tree_view,
2628 g_free (path_string);
2629 gtk_tree_path_free (path);
2634 pspp_sheet_view_button_release (GtkWidget *widget,
2635 GdkEventButton *event)
2637 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2639 pspp_sheet_view_stop_editing (tree_view, FALSE);
2640 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2641 && pspp_sheet_view_button_release_edit (tree_view, event))
2643 if (tree_view->priv->pressed_button == event->button)
2644 tree_view->priv->pressed_button = -1;
2646 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2650 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2651 return pspp_sheet_view_button_release_drag_column (widget, event);
2653 if (tree_view->priv->rubber_band_status)
2654 pspp_sheet_view_stop_rubber_band (tree_view);
2656 if (tree_view->priv->pressed_button == event->button)
2657 tree_view->priv->pressed_button = -1;
2659 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2660 return pspp_sheet_view_button_release_column_resize (widget, event);
2666 pspp_sheet_view_grab_broken (GtkWidget *widget,
2667 GdkEventGrabBroken *event)
2669 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2671 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2672 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2674 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2675 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2680 /* GtkWidget::motion_event function set.
2684 do_prelight (PsppSheetView *tree_view,
2686 /* these are in bin_window coords */
2690 int prev_node = tree_view->priv->prelight_node;
2692 if (prev_node != node)
2694 tree_view->priv->prelight_node = node;
2697 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2700 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2705 prelight_or_select (PsppSheetView *tree_view,
2707 /* these are in bin_window coords */
2711 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2713 if (tree_view->priv->hover_selection &&
2714 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2715 !(tree_view->priv->edited_column &&
2716 tree_view->priv->edited_column->editable_widget))
2720 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2724 path = _pspp_sheet_view_find_path (tree_view, node);
2725 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2726 if (pspp_sheet_view_node_is_selected (tree_view, node))
2728 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2729 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE);
2731 gtk_tree_path_free (path);
2735 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2736 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2739 do_prelight (tree_view, node, x, y);
2743 ensure_unprelighted (PsppSheetView *tree_view)
2745 do_prelight (tree_view,
2747 -1000, -1000); /* coords not possibly over an arrow */
2749 g_assert (tree_view->priv->prelight_node < 0);
2753 update_prelight (PsppSheetView *tree_view,
2760 if (tree_view->priv->row_count == 0)
2765 ensure_unprelighted (tree_view);
2769 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2773 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2776 prelight_or_select (tree_view, node, x, y);
2782 /* Our motion arrow is either a box (in the case of the original spot)
2783 * or an arrow. It is expander_size wide.
2806 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2808 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2809 GtkWidget *widget = GTK_WIDGET (tree_view);
2810 GdkBitmap *mask = NULL;
2815 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2816 GdkWindowAttr attributes;
2817 guint attributes_mask;
2820 reorder->left_column == tree_view->priv->drag_column ||
2821 reorder->right_column == tree_view->priv->drag_column)
2822 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2823 else if (reorder->left_column || reorder->right_column)
2825 GdkRectangle visible_rect;
2826 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2827 if (reorder->left_column)
2828 x = reorder->left_column->button->allocation.x + reorder->left_column->button->allocation.width;
2830 x = reorder->right_column->button->allocation.x;
2832 if (x < visible_rect.x)
2833 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2834 else if (x > visible_rect.x + visible_rect.width)
2835 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2837 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2840 /* We want to draw the rectangle over the initial location. */
2841 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2846 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2848 if (tree_view->priv->drag_highlight_window)
2850 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2852 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2855 attributes.window_type = GDK_WINDOW_CHILD;
2856 attributes.wclass = GDK_INPUT_OUTPUT;
2857 attributes.x = tree_view->priv->drag_column_x;
2859 width = attributes.width = tree_view->priv->drag_column->button->allocation.width;
2860 height = attributes.height = tree_view->priv->drag_column->button->allocation.height;
2861 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2862 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2863 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2864 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2865 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
2866 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2868 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2869 gc = gdk_gc_new (mask);
2871 gdk_gc_set_foreground (gc, &col);
2872 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2874 gdk_gc_set_foreground(gc, &col);
2875 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
2876 g_object_unref (gc);
2878 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
2880 if (mask) g_object_unref (mask);
2881 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2884 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
2890 width = tree_view->priv->expander_size;
2892 /* Get x, y, width, height of arrow */
2893 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
2894 if (reorder->left_column)
2896 x += reorder->left_column->button->allocation.x + reorder->left_column->button->allocation.width - width/2;
2897 height = reorder->left_column->button->allocation.height;
2901 x += reorder->right_column->button->allocation.x - width/2;
2902 height = reorder->right_column->button->allocation.height;
2904 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
2905 height += tree_view->priv->expander_size;
2907 /* Create the new window */
2908 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
2910 if (tree_view->priv->drag_highlight_window)
2912 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2914 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2917 attributes.window_type = GDK_WINDOW_TEMP;
2918 attributes.wclass = GDK_INPUT_OUTPUT;
2919 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2920 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2921 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2922 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2925 attributes.width = width;
2926 attributes.height = height;
2927 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
2928 &attributes, attributes_mask);
2929 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2931 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2932 gc = gdk_gc_new (mask);
2934 gdk_gc_set_foreground (gc, &col);
2935 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2937 /* Draw the 2 arrows as per above */
2939 gdk_gc_set_foreground (gc, &col);
2940 for (i = 0; i < width; i ++)
2942 if (i == (width/2 - 1))
2944 gdk_draw_line (mask, gc, i, j, i, height - j);
2945 if (i < (width/2 - 1))
2950 g_object_unref (gc);
2951 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
2953 if (mask) g_object_unref (mask);
2956 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
2957 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
2959 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
2960 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
2966 width = tree_view->priv->expander_size;
2968 /* Get x, y, width, height of arrow */
2969 width = width/2; /* remember, the arrow only takes half the available width */
2970 gdk_window_get_origin (widget->window, &x, &y);
2971 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
2972 x += widget->allocation.width - width;
2974 if (reorder->left_column)
2975 height = reorder->left_column->button->allocation.height;
2977 height = reorder->right_column->button->allocation.height;
2979 y -= tree_view->priv->expander_size;
2980 height += 2*tree_view->priv->expander_size;
2982 /* Create the new window */
2983 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
2984 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
2986 if (tree_view->priv->drag_highlight_window)
2988 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2990 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2993 attributes.window_type = GDK_WINDOW_TEMP;
2994 attributes.wclass = GDK_INPUT_OUTPUT;
2995 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2996 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2997 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2998 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3001 attributes.width = width;
3002 attributes.height = height;
3003 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3004 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3006 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3007 gc = gdk_gc_new (mask);
3009 gdk_gc_set_foreground (gc, &col);
3010 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3012 /* Draw the 2 arrows as per above */
3014 gdk_gc_set_foreground (gc, &col);
3015 j = tree_view->priv->expander_size;
3016 for (i = 0; i < width; i ++)
3019 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3023 gdk_draw_line (mask, gc, k, j, k, height - j);
3024 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3025 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3028 g_object_unref (gc);
3029 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3031 if (mask) g_object_unref (mask);
3034 tree_view->priv->drag_column_window_state = arrow_type;
3035 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3039 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3040 gdk_window_hide (tree_view->priv->drag_highlight_window);
3044 gdk_window_show (tree_view->priv->drag_highlight_window);
3045 gdk_window_raise (tree_view->priv->drag_highlight_window);
3049 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3050 GdkEventMotion *event)
3054 PsppSheetViewColumn *column;
3055 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3057 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3059 if (event->is_hint || event->window != widget->window)
3060 gtk_widget_get_pointer (widget, &x, NULL);
3064 if (tree_view->priv->hadjustment)
3065 x += tree_view->priv->hadjustment->value;
3067 new_width = pspp_sheet_view_new_column_width (tree_view,
3068 tree_view->priv->drag_pos, &x);
3069 if (x != tree_view->priv->x_drag &&
3070 (new_width != column->fixed_width))
3072 column->use_resized_width = TRUE;
3073 column->resized_width = new_width;
3075 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3076 gtk_widget_queue_resize (widget);
3084 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3086 PsppSheetViewColumnReorder *reorder = NULL;
3090 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3091 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3093 reorder = (PsppSheetViewColumnReorder *) list->data;
3094 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3099 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3102 tree_view->priv->cur_reorder = reorder;
3103 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3107 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3109 GdkRectangle visible_rect;
3114 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3115 y += tree_view->priv->dy;
3117 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3119 /* see if we are near the edge. */
3120 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3123 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3128 value = CLAMP (tree_view->priv->vadjustment->value + offset, 0.0,
3129 tree_view->priv->vadjustment->upper - tree_view->priv->vadjustment->page_size);
3130 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3134 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3136 GdkRectangle visible_rect;
3141 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3143 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3145 /* See if we are near the edge. */
3146 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3149 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3155 value = CLAMP (tree_view->priv->hadjustment->value + offset,
3156 0.0, tree_view->priv->hadjustment->upper - tree_view->priv->hadjustment->page_size);
3157 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3164 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3165 GdkEventMotion *event)
3167 PsppSheetView *tree_view = (PsppSheetView *) widget;
3168 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3172 if ((column == NULL) ||
3173 (event->window != tree_view->priv->drag_window))
3176 /* Handle moving the header */
3177 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3178 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3179 MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width) - column->button->allocation.width);
3180 gdk_window_move (tree_view->priv->drag_window, x, y);
3182 /* autoscroll, if needed */
3183 pspp_sheet_view_horizontal_autoscroll (tree_view);
3184 /* Update the current reorder position and arrow; */
3185 pspp_sheet_view_update_current_reorder (tree_view);
3191 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3193 remove_scroll_timeout (tree_view);
3194 gtk_grab_remove (GTK_WIDGET (tree_view));
3196 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3198 GtkTreePath *tmp_path;
3200 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3202 /* The anchor path should be set to the start path */
3203 tmp_path = _pspp_sheet_view_find_path (tree_view,
3204 tree_view->priv->rubber_band_start_node);
3206 if (tree_view->priv->anchor)
3207 gtk_tree_row_reference_free (tree_view->priv->anchor);
3209 tree_view->priv->anchor =
3210 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3211 tree_view->priv->model,
3214 gtk_tree_path_free (tmp_path);
3216 /* ... and the cursor to the end path */
3217 tmp_path = _pspp_sheet_view_find_path (tree_view,
3218 tree_view->priv->rubber_band_end_node);
3219 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE);
3220 gtk_tree_path_free (tmp_path);
3222 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3225 /* Clear status variables */
3226 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3227 tree_view->priv->rubber_band_shift = 0;
3228 tree_view->priv->rubber_band_ctrl = 0;
3230 tree_view->priv->rubber_band_start_node = -1;
3231 tree_view->priv->rubber_band_end_node = -1;
3235 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3239 gboolean skip_start,
3242 if (start_node == end_node)
3245 /* We skip the first node and jump inside the loop */
3251 /* Small optimization by assuming insensitive nodes are never
3256 if (tree_view->priv->rubber_band_shift)
3257 pspp_sheet_view_node_select (tree_view, start_node);
3258 else if (tree_view->priv->rubber_band_ctrl)
3260 /* Toggle the selection state */
3261 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3262 pspp_sheet_view_node_unselect (tree_view, start_node);
3264 pspp_sheet_view_node_select (tree_view, start_node);
3267 pspp_sheet_view_node_select (tree_view, start_node);
3271 /* Mirror the above */
3272 if (tree_view->priv->rubber_band_shift)
3273 pspp_sheet_view_node_unselect (tree_view, start_node);
3274 else if (tree_view->priv->rubber_band_ctrl)
3276 /* Toggle the selection state */
3277 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3278 pspp_sheet_view_node_unselect (tree_view, start_node);
3280 pspp_sheet_view_node_select (tree_view, start_node);
3283 pspp_sheet_view_node_unselect (tree_view, start_node);
3286 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3288 if (start_node == end_node)
3293 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3296 /* Ran out of tree */
3299 if (skip_end && start_node == end_node)
3306 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3309 return node * tree_view->priv->fixed_height;
3313 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3317 int fixed_height = tree_view->priv->fixed_height;
3318 if (fixed_height <= 0
3320 || height >= tree_view->priv->row_count * fixed_height)
3327 *new_node = height / fixed_height;
3328 return height % fixed_height;
3333 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3338 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3339 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3341 /* Handle the start area first */
3342 if (tree_view->priv->rubber_band_start_node < 0)
3344 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3351 else if (start_node < tree_view->priv->rubber_band_start_node)
3353 /* New node is above the old one; selection became bigger */
3354 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3356 tree_view->priv->rubber_band_start_node,
3361 else if (start_node > tree_view->priv->rubber_band_start_node)
3363 /* New node is below the old one; selection became smaller */
3364 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3365 tree_view->priv->rubber_band_start_node,
3372 tree_view->priv->rubber_band_start_node = start_node;
3374 /* Next, handle the end area */
3375 if (tree_view->priv->rubber_band_end_node < 0)
3377 /* In the event this happens, start_node was also -1; this case is
3381 else if (end_node < 0)
3383 /* Find the last node in the tree */
3384 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3387 /* Selection reached end of the tree */
3388 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3389 tree_view->priv->rubber_band_end_node,
3395 else if (end_node > tree_view->priv->rubber_band_end_node)
3397 /* New node is below the old one; selection became bigger */
3398 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3399 tree_view->priv->rubber_band_end_node,
3405 else if (end_node < tree_view->priv->rubber_band_end_node)
3407 /* New node is above the old one; selection became smaller */
3408 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3410 tree_view->priv->rubber_band_end_node,
3416 tree_view->priv->rubber_band_end_node = end_node;
3420 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3423 GdkRectangle old_area;
3424 GdkRectangle new_area;
3425 GdkRectangle common;
3426 GdkRegion *invalid_region;
3427 PsppSheetViewColumn *column;
3429 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3430 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3431 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3432 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3434 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3437 y = MAX (y, 0) + tree_view->priv->dy;
3439 new_area.x = MIN (tree_view->priv->press_start_x, x);
3440 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3441 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3442 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3444 invalid_region = gdk_region_rectangle (&old_area);
3445 gdk_region_union_with_rect (invalid_region, &new_area);
3447 gdk_rectangle_intersect (&old_area, &new_area, &common);
3448 if (common.width > 2 && common.height > 2)
3450 GdkRegion *common_region;
3452 /* make sure the border is invalidated */
3458 common_region = gdk_region_rectangle (&common);
3460 gdk_region_subtract (invalid_region, common_region);
3461 gdk_region_destroy (common_region);
3464 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3466 gdk_region_destroy (invalid_region);
3468 tree_view->priv->rubber_band_x = x;
3469 tree_view->priv->rubber_band_y = y;
3470 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3472 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3473 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3474 tree_view->priv->anchor_column,
3477 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3479 pspp_sheet_view_update_rubber_band_selection (tree_view);
3483 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3488 GdkRectangle rubber_rect;
3491 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3492 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3493 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3494 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3496 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3499 cr = gdk_cairo_create (tree_view->priv->bin_window);
3500 cairo_set_line_width (cr, 1.0);
3502 cairo_set_source_rgba (cr,
3503 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3504 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3505 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.,
3508 gdk_cairo_rectangle (cr, &rect);
3512 cairo_set_source_rgb (cr,
3513 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3514 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3515 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.);
3517 cairo_rectangle (cr,
3518 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3519 rubber_rect.width - 1, rubber_rect.height - 1);
3526 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3527 GdkEventMotion *event)
3529 PsppSheetView *tree_view;
3533 tree_view = (PsppSheetView *) widget;
3535 if (tree_view->priv->row_count == 0)
3538 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3540 GdkRectangle background_area, cell_area;
3541 PsppSheetViewColumn *column;
3543 if (find_click (tree_view, event->x, event->y, &node, &column,
3544 &background_area, &cell_area)
3545 && tree_view->priv->focus_column == column
3546 && tree_view->priv->press_start_node == node)
3549 gtk_grab_add (GTK_WIDGET (tree_view));
3550 pspp_sheet_view_update_rubber_band (tree_view);
3552 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3554 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3556 pspp_sheet_view_update_rubber_band (tree_view);
3558 add_scroll_timeout (tree_view);
3561 /* only check for an initiated drag when a button is pressed */
3562 if (tree_view->priv->pressed_button >= 0
3563 && !tree_view->priv->rubber_band_status)
3564 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3566 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3570 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3572 tree_view->priv->event_last_x = event->x;
3573 tree_view->priv->event_last_y = event->y;
3575 prelight_or_select (tree_view, node, event->x, event->y);
3581 pspp_sheet_view_motion (GtkWidget *widget,
3582 GdkEventMotion *event)
3584 PsppSheetView *tree_view;
3586 tree_view = (PsppSheetView *) widget;
3588 /* Resizing a column */
3589 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3590 return pspp_sheet_view_motion_resize_column (widget, event);
3593 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3594 return pspp_sheet_view_motion_drag_column (widget, event);
3596 /* Sanity check it */
3597 if (event->window == tree_view->priv->bin_window)
3598 return pspp_sheet_view_motion_bin_window (widget, event);
3603 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3604 * the tree is empty.
3607 invalidate_empty_focus (PsppSheetView *tree_view)
3611 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3616 gdk_drawable_get_size (tree_view->priv->bin_window, &area.width, &area.height);
3617 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3620 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3624 draw_empty_focus (PsppSheetView *tree_view, GdkRectangle *clip_area)
3626 GtkWidget *widget = GTK_WIDGET (tree_view);
3629 if (!gtk_widget_has_focus (widget))
3632 gdk_drawable_get_size (tree_view->priv->bin_window, &w, &h);
3638 gtk_paint_focus (gtk_widget_get_style (widget),
3639 tree_view->priv->bin_window,
3640 gtk_widget_get_state (widget),
3648 pspp_sheet_view_draw_grid_lines (PsppSheetView *tree_view,
3649 GdkEventExpose *event,
3650 gint n_visible_columns)
3652 GList *list = tree_view->priv->columns;
3657 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3658 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3661 gdk_drawable_get_size (event->window, NULL, &height);
3663 /* Only draw the lines for visible rows and columns */
3664 for (list = tree_view->priv->columns; list; list = list->next, i++)
3666 PsppSheetViewColumn *column = list->data;
3668 /* We don't want a line for the last column */
3669 if (i == n_visible_columns - 1)
3672 if (! column->visible)
3675 current_x += column->width;
3677 if (current_x - 1 >= event->area.x
3678 && current_x - 1 < event->area.x + event->area.width)
3679 gdk_draw_line (event->window,
3680 tree_view->priv->grid_line_gc,
3682 current_x - 1, height);
3686 /* Warning: Very scary function.
3687 * Modify at your own risk
3689 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3690 * FIXME: It's not...
3693 pspp_sheet_view_bin_expose (GtkWidget *widget,
3694 GdkEventExpose *event)
3696 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3701 int drag_highlight = -1;
3704 gint y_offset, cell_offset;
3707 GdkRectangle background_area;
3708 GdkRectangle cell_area;
3710 gint bin_window_width;
3711 gint bin_window_height;
3712 GtkTreePath *cursor_path;
3713 GtkTreePath *drag_dest_path;
3714 GList *first_column, *last_column;
3715 gint vertical_separator;
3716 gint horizontal_separator;
3717 gint focus_line_width;
3718 gboolean allow_rules;
3719 gboolean has_special_cell;
3721 gint n_visible_columns;
3722 gint grid_line_width;
3723 gboolean row_ending_details;
3724 gboolean draw_vgrid_lines, draw_hgrid_lines;
3726 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3728 gtk_widget_style_get (widget,
3729 "horizontal-separator", &horizontal_separator,
3730 "vertical-separator", &vertical_separator,
3731 "allow-rules", &allow_rules,
3732 "focus-line-width", &focus_line_width,
3733 "row-ending-details", &row_ending_details,
3736 if (tree_view->priv->row_count == 0)
3738 draw_empty_focus (tree_view, &event->area);
3742 /* clip event->area to the visible area */
3743 if (event->area.height < 0)
3746 validate_visible_area (tree_view);
3748 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, event->area.y);
3752 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3753 gdk_drawable_get_size (tree_view->priv->bin_window,
3754 &bin_window_width, &bin_window_height);
3756 if (tree_view->priv->height < bin_window_height)
3758 gtk_paint_flat_box (widget->style,
3765 0, tree_view->priv->height,
3767 bin_window_height - tree_view->priv->height);
3773 /* find the path for the node */
3774 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3775 gtk_tree_model_get_iter (tree_view->priv->model,
3778 depth = gtk_tree_path_get_depth (path);
3779 gtk_tree_path_free (path);
3782 drag_dest_path = NULL;
3784 if (tree_view->priv->cursor)
3785 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3788 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3790 if (tree_view->priv->drag_dest_row)
3791 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3794 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3798 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3799 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3801 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3802 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3804 if (draw_vgrid_lines || draw_hgrid_lines)
3805 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3807 n_visible_columns = 0;
3808 for (list = tree_view->priv->columns; list; list = list->next)
3810 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3812 n_visible_columns ++;
3815 /* Find the last column */
3816 for (last_column = g_list_last (tree_view->priv->columns);
3817 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
3818 last_column = last_column->prev)
3822 for (first_column = g_list_first (tree_view->priv->columns);
3823 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
3824 first_column = first_column->next)
3827 /* Actually process the expose event. To do this, we want to
3828 * start at the first node of the event, and walk the tree in
3829 * order, drawing each successive node.
3835 gboolean is_first = FALSE;
3836 gboolean is_last = FALSE;
3837 gboolean done = FALSE;
3840 max_height = ROW_HEIGHT (tree_view);
3844 background_area.y = y_offset + event->area.y;
3845 background_area.height = max_height;
3849 if (node == tree_view->priv->prelight_node)
3850 flags |= GTK_CELL_RENDERER_PRELIT;
3852 selected = pspp_sheet_view_node_is_selected (tree_view, node);
3856 /* we *need* to set cell data on all cells before the call
3857 * to _has_special_cell, else _has_special_cell() does not
3858 * return a correct value.
3860 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3862 list = (rtl ? list->prev : list->next))
3864 PsppSheetViewColumn *column = list->data;
3865 pspp_sheet_view_column_cell_set_cell_data (column,
3866 tree_view->priv->model,
3870 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
3872 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3874 list = (rtl ? list->prev : list->next))
3876 PsppSheetViewColumn *column = list->data;
3877 const gchar *detail = NULL;
3878 gboolean selected_column;
3881 if (!column->visible)
3884 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
3885 selected_column = column->selected && column->selectable;
3887 selected_column = TRUE;
3889 if (cell_offset > event->area.x + event->area.width ||
3890 cell_offset + column->width < event->area.x)
3892 cell_offset += column->width;
3896 if (selected && selected_column)
3897 flags |= GTK_CELL_RENDERER_SELECTED;
3899 flags &= ~GTK_CELL_RENDERER_SELECTED;
3901 if (column->show_sort_indicator)
3902 flags |= GTK_CELL_RENDERER_SORTED;
3904 flags &= ~GTK_CELL_RENDERER_SORTED;
3907 flags |= GTK_CELL_RENDERER_FOCUSED;
3909 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3911 background_area.x = cell_offset;
3912 background_area.width = column->width;
3914 cell_area = background_area;
3915 cell_area.y += vertical_separator / 2;
3916 cell_area.x += horizontal_separator / 2;
3917 cell_area.height -= vertical_separator;
3918 cell_area.width -= horizontal_separator;
3920 if (draw_vgrid_lines)
3922 if (list == first_column)
3924 cell_area.width -= grid_line_width / 2;
3926 else if (list == last_column)
3928 cell_area.x += grid_line_width / 2;
3929 cell_area.width -= grid_line_width / 2;
3933 cell_area.x += grid_line_width / 2;
3934 cell_area.width -= grid_line_width;
3938 if (draw_hgrid_lines)
3940 cell_area.y += grid_line_width / 2;
3941 cell_area.height -= grid_line_width;
3944 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
3946 cell_offset += column->width;
3950 pspp_sheet_view_column_cell_set_cell_data (column,
3951 tree_view->priv->model,
3954 /* Select the detail for drawing the cell. relevant
3955 * factors are parity, sortedness, and whether to
3958 if (allow_rules && tree_view->priv->has_rules)
3960 if ((flags & GTK_CELL_RENDERER_SORTED) &&
3961 n_visible_columns >= 3)
3964 detail = "cell_odd_ruled_sorted";
3966 detail = "cell_even_ruled_sorted";
3971 detail = "cell_odd_ruled";
3973 detail = "cell_even_ruled";
3978 if ((flags & GTK_CELL_RENDERER_SORTED) &&
3979 n_visible_columns >= 3)
3982 detail = "cell_odd_sorted";
3984 detail = "cell_even_sorted";
3989 detail = "cell_odd";
3991 detail = "cell_even";
3997 if (widget->state == GTK_STATE_INSENSITIVE)
3998 state = GTK_STATE_INSENSITIVE;
3999 else if (flags & GTK_CELL_RENDERER_SELECTED)
4000 state = GTK_STATE_SELECTED;
4002 state = GTK_STATE_NORMAL;
4004 /* Draw background */
4005 if (row_ending_details)
4007 char new_detail[128];
4009 is_first = (rtl ? !list->next : !list->prev);
4010 is_last = (rtl ? !list->prev : !list->next);
4012 /* (I don't like the snprintfs either, but couldn't find a
4015 if (is_first && is_last)
4016 g_snprintf (new_detail, 127, "%s", detail);
4018 g_snprintf (new_detail, 127, "%s_start", detail);
4020 g_snprintf (new_detail, 127, "%s_end", detail);
4022 g_snprintf (new_detail, 128, "%s_middle", detail);
4024 gtk_paint_flat_box (widget->style,
4033 background_area.width,
4034 background_area.height);
4038 gtk_paint_flat_box (widget->style,
4047 background_area.width,
4048 background_area.height);
4051 if (draw_hgrid_lines)
4053 if (background_area.y > 0)
4054 gdk_draw_line (event->window,
4055 tree_view->priv->grid_line_gc,
4056 background_area.x, background_area.y,
4057 background_area.x + background_area.width,
4060 if (y_offset + max_height >= event->area.height)
4061 gdk_draw_line (event->window,
4062 tree_view->priv->grid_line_gc,
4063 background_area.x, background_area.y + max_height,
4064 background_area.x + background_area.width,
4065 background_area.y + max_height);
4068 _pspp_sheet_view_column_cell_render (column,
4075 if (node == cursor && has_special_cell &&
4076 ((column == tree_view->priv->focus_column &&
4077 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4078 gtk_widget_has_focus (widget)) ||
4079 (column == tree_view->priv->edited_column)))
4081 _pspp_sheet_view_column_cell_draw_focus (column,
4089 cell_offset += column->width;
4092 if (node == drag_highlight)
4094 /* Draw indicator for the drop
4096 gint highlight_y = -1;
4100 switch (tree_view->priv->drag_dest_pos)
4102 case PSPP_SHEET_VIEW_DROP_BEFORE:
4103 highlight_y = background_area.y - 1;
4104 if (highlight_y < 0)
4108 case PSPP_SHEET_VIEW_DROP_AFTER:
4109 highlight_y = background_area.y + background_area.height - 1;
4112 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4113 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4114 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4118 gdk_drawable_get_size (tree_view->priv->bin_window,
4121 if (row_ending_details)
4122 gtk_paint_focus (widget->style,
4123 tree_view->priv->bin_window,
4124 gtk_widget_get_state (widget),
4128 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4129 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4130 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4131 - focus_line_width / 2,
4132 width, ROW_HEIGHT (tree_view)
4133 - focus_line_width + 1);
4135 gtk_paint_focus (widget->style,
4136 tree_view->priv->bin_window,
4137 gtk_widget_get_state (widget),
4140 "treeview-drop-indicator",
4141 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4142 - focus_line_width / 2,
4143 width, ROW_HEIGHT (tree_view)
4144 - focus_line_width + 1);
4148 if (highlight_y >= 0)
4150 gdk_draw_line (event->window,
4151 widget->style->fg_gc[gtk_widget_get_state (widget)],
4154 rtl ? 0 : bin_window_width,
4159 /* draw the big row-spanning focus rectangle, if needed */
4160 if (!has_special_cell && node == cursor &&
4161 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4162 gtk_widget_has_focus (widget))
4164 gint tmp_y, tmp_height;
4166 GtkStateType focus_rect_state;
4169 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4170 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4171 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4174 gdk_drawable_get_size (tree_view->priv->bin_window,
4177 if (draw_hgrid_lines)
4179 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4180 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4184 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4185 tmp_height = ROW_HEIGHT (tree_view);
4188 if (row_ending_details)
4189 gtk_paint_focus (widget->style,
4190 tree_view->priv->bin_window,
4195 ? (is_last ? "treeview" : "treeview-left" )
4196 : (is_last ? "treeview-right" : "treeview-middle" )),
4200 gtk_paint_focus (widget->style,
4201 tree_view->priv->bin_window,
4210 y_offset += max_height;
4214 node = pspp_sheet_view_node_next (tree_view, node);
4217 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4221 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4228 while (y_offset < event->area.height);
4231 pspp_sheet_view_draw_grid_lines (tree_view, event, n_visible_columns);
4233 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4235 GdkRectangle *rectangles;
4238 gdk_region_get_rectangles (event->region,
4242 while (n_rectangles--)
4243 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4245 g_free (rectangles);
4249 gtk_tree_path_free (cursor_path);
4252 gtk_tree_path_free (drag_dest_path);
4258 pspp_sheet_view_expose (GtkWidget *widget,
4259 GdkEventExpose *event)
4261 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4263 if (event->window == tree_view->priv->bin_window)
4268 retval = pspp_sheet_view_bin_expose (widget, event);
4270 /* We can't just chain up to Container::expose as it will try to send the
4271 * event to the headers, so we handle propagating it to our children
4272 * (eg. widgets being edited) ourselves.
4274 tmp_list = tree_view->priv->children;
4277 PsppSheetViewChild *child = tmp_list->data;
4278 tmp_list = tmp_list->next;
4280 gtk_container_propagate_expose (GTK_CONTAINER (tree_view), child->widget, event);
4286 else if (event->window == tree_view->priv->header_window)
4290 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4292 PsppSheetViewColumn *column = list->data;
4294 if (column == tree_view->priv->drag_column)
4297 if (column->visible)
4298 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4303 else if (event->window == tree_view->priv->drag_window)
4305 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4306 tree_view->priv->drag_column->button,
4320 /* returns 0x1 when no column has been found -- yes it's hackish */
4321 static PsppSheetViewColumn *
4322 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4323 PsppSheetViewColumn *column,
4326 PsppSheetViewColumn *left_column = NULL;
4327 PsppSheetViewColumn *cur_column = NULL;
4330 if (!column->reorderable)
4331 return (PsppSheetViewColumn *)0x1;
4333 switch (drop_position)
4336 /* find first column where we can drop */
4337 tmp_list = tree_view->priv->columns;
4338 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4339 return (PsppSheetViewColumn *)0x1;
4343 g_assert (tmp_list);
4345 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4346 tmp_list = tmp_list->next;
4348 if (left_column && left_column->visible == FALSE)
4351 if (!tree_view->priv->column_drop_func)
4354 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4356 left_column = cur_column;
4363 if (!tree_view->priv->column_drop_func)
4366 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4369 return (PsppSheetViewColumn *)0x1;
4373 /* find first column after column where we can drop */
4374 tmp_list = tree_view->priv->columns;
4376 for (; tmp_list; tmp_list = tmp_list->next)
4377 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4380 if (!tmp_list || !tmp_list->next)
4381 return (PsppSheetViewColumn *)0x1;
4383 tmp_list = tmp_list->next;
4384 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4385 tmp_list = tmp_list->next;
4389 g_assert (tmp_list);
4391 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4392 tmp_list = tmp_list->next;
4394 if (left_column && left_column->visible == FALSE)
4396 left_column = cur_column;
4398 tmp_list = tmp_list->next;
4402 if (!tree_view->priv->column_drop_func)
4405 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4407 left_column = cur_column;
4414 if (!tree_view->priv->column_drop_func)
4417 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4420 return (PsppSheetViewColumn *)0x1;
4424 /* find first column before column where we can drop */
4425 tmp_list = tree_view->priv->columns;
4427 for (; tmp_list; tmp_list = tmp_list->next)
4428 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4431 if (!tmp_list || !tmp_list->prev)
4432 return (PsppSheetViewColumn *)0x1;
4434 tmp_list = tmp_list->prev;
4435 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4436 tmp_list = tmp_list->prev;
4440 g_assert (tmp_list);
4442 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4444 if (left_column && !left_column->visible)
4446 /*if (!tmp_list->prev)
4447 return (PsppSheetViewColumn *)0x1;
4450 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4451 tmp_list = tmp_list->prev->prev;
4454 cur_column = left_column;
4456 tmp_list = tmp_list->prev;
4460 if (!tree_view->priv->column_drop_func)
4463 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4466 cur_column = left_column;
4467 tmp_list = tmp_list->prev;
4470 if (!tree_view->priv->column_drop_func)
4473 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4476 return (PsppSheetViewColumn *)0x1;
4480 /* same as DROP_HOME case, but doing it backwards */
4481 tmp_list = g_list_last (tree_view->priv->columns);
4484 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4485 return (PsppSheetViewColumn *)0x1;
4489 g_assert (tmp_list);
4491 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4493 if (left_column && !left_column->visible)
4495 cur_column = left_column;
4496 tmp_list = tmp_list->prev;
4499 if (!tree_view->priv->column_drop_func)
4502 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4505 cur_column = left_column;
4506 tmp_list = tmp_list->prev;
4509 if (!tree_view->priv->column_drop_func)
4512 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4515 return (PsppSheetViewColumn *)0x1;
4519 return (PsppSheetViewColumn *)0x1;
4523 pspp_sheet_view_key_press (GtkWidget *widget,
4526 PsppSheetView *tree_view = (PsppSheetView *) widget;
4528 if (tree_view->priv->rubber_band_status)
4530 if (event->keyval == GDK_Escape)
4531 pspp_sheet_view_stop_rubber_band (tree_view);
4536 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4538 if (event->keyval == GDK_Escape)
4540 tree_view->priv->cur_reorder = NULL;
4541 pspp_sheet_view_button_release_drag_column (widget, NULL);
4546 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4548 GList *focus_column;
4551 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4553 for (focus_column = tree_view->priv->columns;
4555 focus_column = focus_column->next)
4557 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4559 if (gtk_widget_has_focus (column->button))
4564 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4565 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4566 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4568 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4570 if (!column->resizable)
4572 gtk_widget_error_bell (widget);
4576 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4577 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4579 gint old_width = column->resized_width;
4581 column->resized_width = MAX (column->resized_width,
4583 column->resized_width -= 2;
4584 if (column->resized_width < 0)
4585 column->resized_width = 0;
4587 if (column->min_width == -1)
4588 column->resized_width = MAX (column->button->requisition.width,
4589 column->resized_width);
4591 column->resized_width = MAX (column->min_width,
4592 column->resized_width);
4594 if (column->max_width != -1)
4595 column->resized_width = MIN (column->resized_width,
4598 column->use_resized_width = TRUE;
4600 if (column->resized_width != old_width)
4601 gtk_widget_queue_resize (widget);
4603 gtk_widget_error_bell (widget);
4605 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4606 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4608 gint old_width = column->resized_width;
4610 column->resized_width = MAX (column->resized_width,
4612 column->resized_width += 2;
4614 if (column->max_width != -1)
4615 column->resized_width = MIN (column->resized_width,
4618 column->use_resized_width = TRUE;
4620 if (column->resized_width != old_width)
4621 gtk_widget_queue_resize (widget);
4623 gtk_widget_error_bell (widget);
4630 (event->state & GDK_MOD1_MASK) &&
4631 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4632 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4633 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4634 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4636 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4638 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4639 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4641 PsppSheetViewColumn *col;
4642 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4643 if (col != (PsppSheetViewColumn *)0x1)
4644 pspp_sheet_view_move_column_after (tree_view, column, col);
4646 gtk_widget_error_bell (widget);
4648 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4649 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4651 PsppSheetViewColumn *col;
4652 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4653 if (col != (PsppSheetViewColumn *)0x1)
4654 pspp_sheet_view_move_column_after (tree_view, column, col);
4656 gtk_widget_error_bell (widget);
4658 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4660 PsppSheetViewColumn *col;
4661 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4662 if (col != (PsppSheetViewColumn *)0x1)
4663 pspp_sheet_view_move_column_after (tree_view, column, col);
4665 gtk_widget_error_bell (widget);
4667 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4669 PsppSheetViewColumn *col;
4670 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4671 if (col != (PsppSheetViewColumn *)0x1)
4672 pspp_sheet_view_move_column_after (tree_view, column, col);
4674 gtk_widget_error_bell (widget);
4681 /* Chain up to the parent class. It handles the keybindings. */
4682 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4685 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4687 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4691 /* We pass the event to the search_entry. If its text changes, then we start
4692 * the typeahead find capabilities. */
4693 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4694 && tree_view->priv->enable_search
4695 && !tree_view->priv->search_custom_entry_set)
4697 GdkEvent *new_event;
4699 const char *new_text;
4702 gboolean text_modified;
4703 gulong popup_menu_id;
4705 pspp_sheet_view_ensure_interactive_directory (tree_view);
4707 /* Make a copy of the current text */
4708 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4709 new_event = gdk_event_copy ((GdkEvent *) event);
4710 g_object_unref (((GdkEventKey *) new_event)->window);
4711 ((GdkEventKey *) new_event)->window = g_object_ref (tree_view->priv->search_window->window);
4712 gtk_widget_realize (tree_view->priv->search_window);
4714 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4715 "popup-menu", G_CALLBACK (gtk_true),
4718 /* Move the entry off screen */
4719 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4720 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4721 gdk_screen_get_width (screen) + 1,
4722 gdk_screen_get_height (screen) + 1);
4723 gtk_widget_show (tree_view->priv->search_window);
4725 /* Send the event to the window. If the preedit_changed signal is emitted
4726 * during this event, we will set priv->imcontext_changed */
4727 tree_view->priv->imcontext_changed = FALSE;
4728 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4729 gdk_event_free (new_event);
4730 gtk_widget_hide (tree_view->priv->search_window);
4732 g_signal_handler_disconnect (tree_view->priv->search_entry,
4735 /* We check to make sure that the entry tried to handle the text, and that
4736 * the text has changed.
4738 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4739 text_modified = strcmp (old_text, new_text) != 0;
4741 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4742 (retval && text_modified)) /* ...or the text was modified */
4744 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4746 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4751 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
4761 pspp_sheet_view_key_release (GtkWidget *widget,
4764 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4766 if (tree_view->priv->rubber_band_status)
4769 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
4772 /* FIXME Is this function necessary? Can I get an enter_notify event
4773 * w/o either an expose event or a mouse motion event?
4776 pspp_sheet_view_enter_notify (GtkWidget *widget,
4777 GdkEventCrossing *event)
4779 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4783 /* Sanity check it */
4784 if (event->window != tree_view->priv->bin_window)
4787 if (tree_view->priv->row_count == 0)
4790 if (event->mode == GDK_CROSSING_GRAB ||
4791 event->mode == GDK_CROSSING_GTK_GRAB ||
4792 event->mode == GDK_CROSSING_GTK_UNGRAB ||
4793 event->mode == GDK_CROSSING_STATE_CHANGED)
4796 /* find the node internally */
4797 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
4800 pspp_sheet_view_find_offset (tree_view, new_y, &node);
4802 tree_view->priv->event_last_x = event->x;
4803 tree_view->priv->event_last_y = event->y;
4805 prelight_or_select (tree_view, node, event->x, event->y);
4811 pspp_sheet_view_leave_notify (GtkWidget *widget,
4812 GdkEventCrossing *event)
4814 PsppSheetView *tree_view;
4816 if (event->mode == GDK_CROSSING_GRAB)
4819 tree_view = PSPP_SHEET_VIEW (widget);
4821 if (tree_view->priv->prelight_node >= 0)
4822 _pspp_sheet_view_queue_draw_node (tree_view,
4823 tree_view->priv->prelight_node,
4826 tree_view->priv->event_last_x = -10000;
4827 tree_view->priv->event_last_y = -10000;
4829 prelight_or_select (tree_view,
4831 -1000, -1000); /* coords not possibly over an arrow */
4838 pspp_sheet_view_focus_out (GtkWidget *widget,
4839 GdkEventFocus *event)
4841 PsppSheetView *tree_view;
4843 tree_view = PSPP_SHEET_VIEW (widget);
4845 gtk_widget_queue_draw (widget);
4847 /* destroy interactive search dialog */
4848 if (tree_view->priv->search_window)
4849 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
4855 /* Incremental Reflow
4859 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
4864 y = pspp_sheet_view_node_find_offset (tree_view, node)
4865 - tree_view->priv->vadjustment->value
4866 + TREE_VIEW_HEADER_HEIGHT (tree_view);
4868 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
4870 GTK_WIDGET (tree_view)->allocation.width,
4871 tree_view->priv->fixed_height);
4875 node_is_visible (PsppSheetView *tree_view,
4881 y = pspp_sheet_view_node_find_offset (tree_view, node);
4882 height = ROW_HEIGHT (tree_view);
4884 if (y >= tree_view->priv->vadjustment->value &&
4885 y + height <= (tree_view->priv->vadjustment->value
4886 + tree_view->priv->vadjustment->page_size))
4892 /* Returns the row height. */
4894 validate_row (PsppSheetView *tree_view,
4899 PsppSheetViewColumn *column;
4900 GList *list, *first_column, *last_column;
4902 gint horizontal_separator;
4903 gint vertical_separator;
4904 gint focus_line_width;
4905 gboolean retval = FALSE;
4906 gboolean draw_vgrid_lines, draw_hgrid_lines;
4908 gint grid_line_width;
4909 gboolean wide_separators;
4910 gint separator_height;
4912 gtk_widget_style_get (GTK_WIDGET (tree_view),
4913 "focus-padding", &focus_pad,
4914 "focus-line-width", &focus_line_width,
4915 "horizontal-separator", &horizontal_separator,
4916 "vertical-separator", &vertical_separator,
4917 "grid-line-width", &grid_line_width,
4918 "wide-separators", &wide_separators,
4919 "separator-height", &separator_height,
4923 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
4924 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
4926 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
4927 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
4929 for (last_column = g_list_last (tree_view->priv->columns);
4930 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
4931 last_column = last_column->prev)
4934 for (first_column = g_list_first (tree_view->priv->columns);
4935 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
4936 first_column = first_column->next)
4939 for (list = tree_view->priv->columns; list; list = list->next)
4944 column = list->data;
4946 if (! column->visible)
4949 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
4950 pspp_sheet_view_column_cell_get_size (column,
4952 &tmp_width, &tmp_height);
4954 tmp_height += vertical_separator;
4955 height = MAX (height, tmp_height);
4957 tmp_width = tmp_width + horizontal_separator;
4959 if (draw_vgrid_lines)
4961 if (list->data == first_column || list->data == last_column)
4962 tmp_width += grid_line_width / 2.0;
4964 tmp_width += grid_line_width;
4967 if (tmp_width > column->requested_width)
4970 column->requested_width = tmp_width;
4974 if (draw_hgrid_lines)
4975 height += grid_line_width;
4977 tree_view->priv->post_validation_flag = TRUE;
4983 validate_visible_area (PsppSheetView *tree_view)
4985 GtkTreePath *path = NULL;
4986 GtkTreePath *above_path = NULL;
4989 gboolean size_changed = FALSE;
4991 gint area_above = 0;
4992 gint area_below = 0;
4994 if (tree_view->priv->row_count == 0)
4997 if (tree_view->priv->scroll_to_path == NULL)
5000 total_height = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5002 if (total_height == 0)
5005 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5008 /* we are going to scroll, and will update dy */
5009 _pspp_sheet_view_find_node (tree_view, path, &node);
5010 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5012 if (tree_view->priv->scroll_to_use_align)
5014 gint height = ROW_HEIGHT (tree_view);
5015 area_above = (total_height - height) *
5016 tree_view->priv->scroll_to_row_align;
5017 area_below = total_height - area_above - height;
5018 area_above = MAX (area_above, 0);
5019 area_below = MAX (area_below, 0);
5024 * 1) row not visible
5028 gint height = ROW_HEIGHT (tree_view);
5030 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5032 if (dy >= tree_view->priv->vadjustment->value &&
5033 dy + height <= (tree_view->priv->vadjustment->value
5034 + tree_view->priv->vadjustment->page_size))
5036 /* row visible: keep the row at the same position */
5037 area_above = dy - tree_view->priv->vadjustment->value;
5038 area_below = (tree_view->priv->vadjustment->value +
5039 tree_view->priv->vadjustment->page_size)
5044 /* row not visible */
5046 && dy + height <= tree_view->priv->vadjustment->page_size)
5048 /* row at the beginning -- fixed */
5050 area_below = tree_view->priv->vadjustment->page_size
5051 - area_above - height;
5053 else if (dy >= (tree_view->priv->vadjustment->upper -
5054 tree_view->priv->vadjustment->page_size))
5056 /* row at the end -- fixed */
5057 area_above = dy - (tree_view->priv->vadjustment->upper -
5058 tree_view->priv->vadjustment->page_size);
5059 area_below = tree_view->priv->vadjustment->page_size -
5060 area_above - height;
5064 area_above = tree_view->priv->vadjustment->page_size - height;
5070 /* row somewhere in the middle, bring it to the top
5074 area_below = total_height - height;
5080 /* the scroll to isn't valid; ignore it.
5083 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5084 tree_view->priv->scroll_to_path = NULL;
5088 above_path = gtk_tree_path_copy (path);
5090 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5091 * backwards is much slower then forward, as there is no iter_prev function.
5092 * We go forwards first in case we run out of tree. Then we go backwards to
5095 while (node >= 0 && area_below > 0)
5097 gboolean done = FALSE;
5100 node = pspp_sheet_view_node_next (tree_view, node);
5103 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5105 gtk_tree_path_next (path);
5108 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5118 area_below -= ROW_HEIGHT (tree_view);
5120 gtk_tree_path_free (path);
5122 /* If we ran out of tree, and have extra area_below left, we need to add it
5125 area_above += area_below;
5127 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5129 /* We walk backwards */
5130 while (area_above > 0)
5132 node = pspp_sheet_view_node_prev (tree_view, node);
5134 /* Always find the new path in the tree. We cannot just assume
5135 * a gtk_tree_path_prev() is enough here, as there might be children
5136 * in between this node and the previous sibling node. If this
5137 * appears to be a performance hotspot in profiles, we can look into
5138 * intrigate logic for keeping path, node and iter in sync like
5139 * we do for forward walks. (Which will be hard because of the lacking
5146 gtk_tree_path_free (above_path);
5147 above_path = _pspp_sheet_view_find_path (tree_view, node);
5149 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5151 area_above -= ROW_HEIGHT (tree_view);
5154 /* set the dy here to scroll to the path,
5155 * and sync the top row accordingly
5157 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5158 pspp_sheet_view_top_row_to_dy (tree_view);
5160 /* update width/height and queue a resize */
5163 GtkRequisition requisition;
5165 /* We temporarily guess a size, under the assumption that it will be the
5166 * same when we get our next size_allocate. If we don't do this, we'll be
5167 * in an inconsistent state if we call top_row_to_dy. */
5169 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5170 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5171 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5172 gtk_adjustment_changed (tree_view->priv->hadjustment);
5173 gtk_adjustment_changed (tree_view->priv->vadjustment);
5174 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5177 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5178 tree_view->priv->scroll_to_path = NULL;
5181 gtk_tree_path_free (above_path);
5183 if (tree_view->priv->scroll_to_column)
5185 tree_view->priv->scroll_to_column = NULL;
5187 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5191 initialize_fixed_height_mode (PsppSheetView *tree_view)
5193 if (!tree_view->priv->row_count)
5196 if (tree_view->priv->fixed_height < 0)
5203 path = _pspp_sheet_view_find_path (tree_view, node);
5204 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5206 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5208 gtk_tree_path_free (path);
5212 /* Our strategy for finding nodes to validate is a little convoluted. We find
5213 * the left-most uninvalidated node. We then try walking right, validating
5214 * nodes. Once we find a valid node, we repeat the previous process of finding
5215 * the first invalid node.
5219 validate_rows_handler (PsppSheetView *tree_view)
5221 initialize_fixed_height_mode (tree_view);
5222 if (tree_view->priv->validate_rows_timer)
5224 g_source_remove (tree_view->priv->validate_rows_timer);
5225 tree_view->priv->validate_rows_timer = 0;
5232 do_presize_handler (PsppSheetView *tree_view)
5234 GtkRequisition requisition;
5236 validate_visible_area (tree_view);
5237 tree_view->priv->presize_handler_timer = 0;
5239 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5241 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5242 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5243 gtk_adjustment_changed (tree_view->priv->hadjustment);
5244 gtk_adjustment_changed (tree_view->priv->vadjustment);
5245 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5251 presize_handler_callback (gpointer data)
5253 do_presize_handler (PSPP_SHEET_VIEW (data));
5259 install_presize_handler (PsppSheetView *tree_view)
5261 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5264 if (! tree_view->priv->presize_handler_timer)
5266 tree_view->priv->presize_handler_timer =
5267 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5269 if (! tree_view->priv->validate_rows_timer)
5271 tree_view->priv->validate_rows_timer =
5272 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5277 scroll_sync_handler (PsppSheetView *tree_view)
5279 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
5280 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5281 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5282 pspp_sheet_view_top_row_to_dy (tree_view);
5284 pspp_sheet_view_dy_to_top_row (tree_view);
5286 tree_view->priv->scroll_sync_timer = 0;
5292 install_scroll_sync_handler (PsppSheetView *tree_view)
5294 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5297 if (!tree_view->priv->scroll_sync_timer)
5299 tree_view->priv->scroll_sync_timer =
5300 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5305 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5309 gtk_tree_row_reference_free (tree_view->priv->top_row);
5313 tree_view->priv->top_row = NULL;
5314 tree_view->priv->top_row_dy = 0;
5318 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5319 tree_view->priv->top_row_dy = offset;
5323 /* Always call this iff dy is in the visible range. If the tree is empty, then
5324 * it's set to be NULL, and top_row_dy is 0;
5327 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5333 if (tree_view->priv->row_count == 0)
5335 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5339 offset = pspp_sheet_view_find_offset (tree_view,
5340 tree_view->priv->dy,
5345 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5349 path = _pspp_sheet_view_find_path (tree_view, node);
5350 pspp_sheet_view_set_top_row (tree_view, path, offset);
5351 gtk_tree_path_free (path);
5357 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5363 /* Avoid recursive calls */
5364 if (tree_view->priv->in_top_row_to_dy)
5367 if (tree_view->priv->top_row)
5368 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5375 _pspp_sheet_view_find_node (tree_view, path, &node);
5378 gtk_tree_path_free (path);
5382 /* keep dy and set new toprow */
5383 gtk_tree_row_reference_free (tree_view->priv->top_row);
5384 tree_view->priv->top_row = NULL;
5385 tree_view->priv->top_row_dy = 0;
5386 /* DO NOT install the idle handler */
5387 pspp_sheet_view_dy_to_top_row (tree_view);
5391 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5393 /* new top row -- do NOT install the idle handler */
5394 pspp_sheet_view_dy_to_top_row (tree_view);
5398 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5399 new_dy += tree_view->priv->top_row_dy;
5401 if (new_dy + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
5402 new_dy = tree_view->priv->height - tree_view->priv->vadjustment->page_size;
5404 new_dy = MAX (0, new_dy);
5406 tree_view->priv->in_top_row_to_dy = TRUE;
5407 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5408 tree_view->priv->in_top_row_to_dy = FALSE;
5413 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5415 install_presize_handler (tree_view);
5421 set_source_row (GdkDragContext *context,
5422 GtkTreeModel *model,
5423 GtkTreePath *source_row)
5425 g_object_set_data_full (G_OBJECT (context),
5426 "gtk-tree-view-source-row",
5427 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5428 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5432 get_source_row (GdkDragContext *context)
5434 GtkTreeRowReference *ref =
5435 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5438 return gtk_tree_row_reference_get_path (ref);
5445 GtkTreeRowReference *dest_row;
5446 guint path_down_mode : 1;
5447 guint empty_view_drop : 1;
5448 guint drop_append_mode : 1;
5453 dest_row_free (gpointer data)
5455 DestRow *dr = (DestRow *)data;
5457 gtk_tree_row_reference_free (dr->dest_row);
5458 g_slice_free (DestRow, dr);
5462 set_dest_row (GdkDragContext *context,
5463 GtkTreeModel *model,
5464 GtkTreePath *dest_row,
5465 gboolean path_down_mode,
5466 gboolean empty_view_drop,
5467 gboolean drop_append_mode)
5473 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5478 dr = g_slice_new (DestRow);
5480 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5481 dr->path_down_mode = path_down_mode != FALSE;
5482 dr->empty_view_drop = empty_view_drop != FALSE;
5483 dr->drop_append_mode = drop_append_mode != FALSE;
5485 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5486 dr, (GDestroyNotify) dest_row_free);
5490 get_dest_row (GdkDragContext *context,
5491 gboolean *path_down_mode)
5494 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5498 GtkTreePath *path = NULL;
5501 *path_down_mode = dr->path_down_mode;
5504 path = gtk_tree_row_reference_get_path (dr->dest_row);
5505 else if (dr->empty_view_drop)
5506 path = gtk_tree_path_new_from_indices (0, -1);
5510 if (path && dr->drop_append_mode)
5511 gtk_tree_path_next (path);
5519 /* Get/set whether drag_motion requested the drag data and
5520 * drag_data_received should thus not actually insert the data,
5521 * since the data doesn't result from a drop.
5524 set_status_pending (GdkDragContext *context,
5525 GdkDragAction suggested_action)
5527 g_object_set_data (G_OBJECT (context),
5528 "gtk-tree-view-status-pending",
5529 GINT_TO_POINTER (suggested_action));
5532 static GdkDragAction
5533 get_status_pending (GdkDragContext *context)
5535 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5536 "gtk-tree-view-status-pending"));
5539 static TreeViewDragInfo*
5540 get_info (PsppSheetView *tree_view)
5542 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5546 destroy_info (TreeViewDragInfo *di)
5548 g_slice_free (TreeViewDragInfo, di);
5551 static TreeViewDragInfo*
5552 ensure_info (PsppSheetView *tree_view)
5554 TreeViewDragInfo *di;
5556 di = get_info (tree_view);
5560 di = g_slice_new0 (TreeViewDragInfo);
5562 g_object_set_data_full (G_OBJECT (tree_view),
5563 "gtk-tree-view-drag-info",
5565 (GDestroyNotify) destroy_info);
5572 remove_info (PsppSheetView *tree_view)
5574 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5579 drag_scan_timeout (gpointer data)
5581 PsppSheetView *tree_view;
5583 GdkModifierType state;
5584 GtkTreePath *path = NULL;
5585 PsppSheetViewColumn *column = NULL;
5586 GdkRectangle visible_rect;
5588 GDK_THREADS_ENTER ();
5590 tree_view = PSPP_SHEET_VIEW (data);
5592 gdk_window_get_pointer (tree_view->priv->bin_window,
5595 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5597 /* See if we are near the edge. */
5598 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5599 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5600 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5601 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5603 pspp_sheet_view_get_path_at_pos (tree_view,
5604 tree_view->priv->bin_window,
5613 pspp_sheet_view_scroll_to_cell (tree_view,
5619 gtk_tree_path_free (path);
5623 GDK_THREADS_LEAVE ();
5630 add_scroll_timeout (PsppSheetView *tree_view)
5632 if (tree_view->priv->scroll_timeout == 0)
5634 tree_view->priv->scroll_timeout =
5635 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5640 remove_scroll_timeout (PsppSheetView *tree_view)
5642 if (tree_view->priv->scroll_timeout != 0)
5644 g_source_remove (tree_view->priv->scroll_timeout);
5645 tree_view->priv->scroll_timeout = 0;
5650 check_model_dnd (GtkTreeModel *model,
5651 GType required_iface,
5652 const gchar *signal)
5654 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5656 g_warning ("You must override the default '%s' handler "
5657 "on PsppSheetView when using models that don't support "
5658 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5659 "is to connect to '%s' and call "
5660 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5661 "the default handler from running. Look at the source code "
5662 "for the default handler in gtktreeview.c to get an idea what "
5663 "your handler should do. (gtktreeview.c is in the GTK source "
5664 "code.) If you're using GTK from a language other than C, "
5665 "there may be a more natural way to override default handlers, e.g. via derivation.",
5666 signal, g_type_name (required_iface), signal);
5674 scroll_row_timeout (gpointer data)
5676 PsppSheetView *tree_view = data;
5678 pspp_sheet_view_horizontal_autoscroll (tree_view);
5679 pspp_sheet_view_vertical_autoscroll (tree_view);
5681 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5682 pspp_sheet_view_update_rubber_band (tree_view);
5687 /* Returns TRUE if event should not be propagated to parent widgets */
5689 set_destination_row (PsppSheetView *tree_view,
5690 GdkDragContext *context,
5691 /* coordinates relative to the widget */
5694 GdkDragAction *suggested_action,
5697 GtkTreePath *path = NULL;
5698 PsppSheetViewDropPosition pos;
5699 PsppSheetViewDropPosition old_pos;
5700 TreeViewDragInfo *di;
5702 GtkTreePath *old_dest_path = NULL;
5703 gboolean can_drop = FALSE;
5705 *suggested_action = 0;
5708 widget = GTK_WIDGET (tree_view);
5710 di = get_info (tree_view);
5712 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5714 /* someone unset us as a drag dest, note that if
5715 * we return FALSE drag_leave isn't called
5718 pspp_sheet_view_set_drag_dest_row (tree_view,
5720 PSPP_SHEET_VIEW_DROP_BEFORE);
5722 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5724 return FALSE; /* no longer a drop site */
5727 *target = gtk_drag_dest_find_target (widget, context,
5728 gtk_drag_dest_get_target_list (widget));
5729 if (*target == GDK_NONE)
5734 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5740 GtkTreeModel *model;
5742 /* the row got dropped on empty space, let's setup a special case
5746 gtk_tree_path_free (path);
5748 model = pspp_sheet_view_get_model (tree_view);
5750 n_children = gtk_tree_model_iter_n_children (model, NULL);
5753 pos = PSPP_SHEET_VIEW_DROP_AFTER;
5754 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5758 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
5759 path = gtk_tree_path_new_from_indices (0, -1);
5769 /* If we left the current row's "open" zone, unset the timeout for
5772 pspp_sheet_view_get_drag_dest_row (tree_view,
5777 gtk_tree_path_free (old_dest_path);
5779 if (TRUE /* FIXME if the location droppable predicate */)
5787 GtkWidget *source_widget;
5789 *suggested_action = context->suggested_action;
5790 source_widget = gtk_drag_get_source_widget (context);
5792 if (source_widget == widget)
5794 /* Default to MOVE, unless the user has
5795 * pressed ctrl or shift to affect available actions
5797 if ((context->actions & GDK_ACTION_MOVE) != 0)
5798 *suggested_action = GDK_ACTION_MOVE;
5801 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5806 /* can't drop here */
5807 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5809 PSPP_SHEET_VIEW_DROP_BEFORE);
5813 gtk_tree_path_free (path);
5819 get_logical_dest_row (PsppSheetView *tree_view,
5820 gboolean *path_down_mode,
5821 gboolean *drop_append_mode)
5823 /* adjust path to point to the row the drop goes in front of */
5824 GtkTreePath *path = NULL;
5825 PsppSheetViewDropPosition pos;
5827 g_return_val_if_fail (path_down_mode != NULL, NULL);
5828 g_return_val_if_fail (drop_append_mode != NULL, NULL);
5830 *path_down_mode = FALSE;
5831 *drop_append_mode = 0;
5833 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
5838 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
5840 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
5841 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
5842 *path_down_mode = TRUE;
5846 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
5848 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
5850 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5851 !gtk_tree_model_iter_next (model, &iter))
5852 *drop_append_mode = 1;
5855 *drop_append_mode = 0;
5856 gtk_tree_path_next (path);
5864 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
5865 GdkEventMotion *event)
5867 GtkWidget *widget = GTK_WIDGET (tree_view);
5868 GdkDragContext *context;
5869 TreeViewDragInfo *di;
5870 GtkTreePath *path = NULL;
5872 gint cell_x, cell_y;
5873 GtkTreeModel *model;
5874 gboolean retval = FALSE;
5876 di = get_info (tree_view);
5878 if (di == NULL || !di->source_set)
5881 if (tree_view->priv->pressed_button < 0)
5884 if (!gtk_drag_check_threshold (widget,
5885 tree_view->priv->press_start_x,
5886 tree_view->priv->press_start_y,
5887 event->x, event->y))
5890 model = pspp_sheet_view_get_model (tree_view);
5895 button = tree_view->priv->pressed_button;
5896 tree_view->priv->pressed_button = -1;
5898 pspp_sheet_view_get_path_at_pos (tree_view,
5899 tree_view->priv->press_start_x,
5900 tree_view->priv->press_start_y,
5909 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
5910 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
5914 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
5917 /* Now we can begin the drag */
5921 context = gtk_drag_begin (widget,
5922 gtk_drag_source_get_target_list (widget),
5927 set_source_row (context, model, path);
5931 gtk_tree_path_free (path);
5938 pspp_sheet_view_drag_begin (GtkWidget *widget,
5939 GdkDragContext *context)
5941 PsppSheetView *tree_view;
5942 GtkTreePath *path = NULL;
5943 gint cell_x, cell_y;
5945 TreeViewDragInfo *di;
5947 tree_view = PSPP_SHEET_VIEW (widget);
5949 /* if the user uses a custom DND source impl, we don't set the icon here */
5950 di = get_info (tree_view);
5952 if (di == NULL || !di->source_set)
5955 pspp_sheet_view_get_path_at_pos (tree_view,
5956 tree_view->priv->press_start_x,
5957 tree_view->priv->press_start_y,
5963 g_return_if_fail (path != NULL);
5965 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
5968 gtk_drag_set_icon_pixmap (context,
5969 gdk_drawable_get_colormap (row_pix),
5972 /* the + 1 is for the black border in the icon */
5973 tree_view->priv->press_start_x + 1,
5976 g_object_unref (row_pix);
5977 gtk_tree_path_free (path);
5981 pspp_sheet_view_drag_end (GtkWidget *widget,
5982 GdkDragContext *context)
5987 /* Default signal implementations for the drag signals */
5989 pspp_sheet_view_drag_data_get (GtkWidget *widget,
5990 GdkDragContext *context,
5991 GtkSelectionData *selection_data,
5995 PsppSheetView *tree_view;
5996 GtkTreeModel *model;
5997 TreeViewDragInfo *di;
5998 GtkTreePath *source_row;
6000 tree_view = PSPP_SHEET_VIEW (widget);
6002 model = pspp_sheet_view_get_model (tree_view);
6007 di = get_info (PSPP_SHEET_VIEW (widget));
6012 source_row = get_source_row (context);
6014 if (source_row == NULL)
6017 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6018 * any model; for DragSource models there are some other targets
6022 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6023 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6028 /* If drag_data_get does nothing, try providing row data. */
6029 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6031 gtk_tree_set_row_drag_data (selection_data,
6037 gtk_tree_path_free (source_row);
6042 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6043 GdkDragContext *context)
6045 TreeViewDragInfo *di;
6046 GtkTreeModel *model;
6047 PsppSheetView *tree_view;
6048 GtkTreePath *source_row;
6050 tree_view = PSPP_SHEET_VIEW (widget);
6051 model = pspp_sheet_view_get_model (tree_view);
6053 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6056 di = get_info (tree_view);
6061 source_row = get_source_row (context);
6063 if (source_row == NULL)
6066 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6069 gtk_tree_path_free (source_row);
6071 set_source_row (context, NULL, NULL);
6075 pspp_sheet_view_drag_leave (GtkWidget *widget,
6076 GdkDragContext *context,
6079 /* unset any highlight row */
6080 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6082 PSPP_SHEET_VIEW_DROP_BEFORE);
6084 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6089 pspp_sheet_view_drag_motion (GtkWidget *widget,
6090 GdkDragContext *context,
6091 /* coordinates relative to the widget */
6097 GtkTreePath *path = NULL;
6098 PsppSheetViewDropPosition pos;
6099 PsppSheetView *tree_view;
6100 GdkDragAction suggested_action = 0;
6103 tree_view = PSPP_SHEET_VIEW (widget);
6105 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6108 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6110 /* we only know this *after* set_desination_row */
6111 empty = tree_view->priv->empty_view_drop;
6113 if (path == NULL && !empty)
6115 /* Can't drop here. */
6116 gdk_drag_status (context, 0, time);
6120 if (tree_view->priv->open_dest_timeout == 0 &&
6121 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6122 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6128 add_scroll_timeout (tree_view);
6131 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6133 /* Request data so we can use the source row when
6134 * determining whether to accept the drop
6136 set_status_pending (context, suggested_action);
6137 gtk_drag_get_data (widget, context, target, time);
6141 set_status_pending (context, 0);
6142 gdk_drag_status (context, suggested_action, time);
6147 gtk_tree_path_free (path);
6154 pspp_sheet_view_drag_drop (GtkWidget *widget,
6155 GdkDragContext *context,
6156 /* coordinates relative to the widget */
6161 PsppSheetView *tree_view;
6163 GdkDragAction suggested_action = 0;
6164 GdkAtom target = GDK_NONE;
6165 TreeViewDragInfo *di;
6166 GtkTreeModel *model;
6167 gboolean path_down_mode;
6168 gboolean drop_append_mode;
6170 tree_view = PSPP_SHEET_VIEW (widget);
6172 model = pspp_sheet_view_get_model (tree_view);
6174 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6176 di = get_info (tree_view);
6181 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6184 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6187 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6189 if (target != GDK_NONE && path != NULL)
6191 /* in case a motion had requested drag data, change things so we
6192 * treat drag data receives as a drop.
6194 set_status_pending (context, 0);
6195 set_dest_row (context, model, path,
6196 path_down_mode, tree_view->priv->empty_view_drop,
6201 gtk_tree_path_free (path);
6203 /* Unset this thing */
6204 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6206 PSPP_SHEET_VIEW_DROP_BEFORE);
6208 if (target != GDK_NONE)
6210 gtk_drag_get_data (widget, context, target, time);
6218 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6219 GdkDragContext *context,
6220 /* coordinates relative to the widget */
6223 GtkSelectionData *selection_data,
6228 TreeViewDragInfo *di;
6229 gboolean accepted = FALSE;
6230 GtkTreeModel *model;
6231 PsppSheetView *tree_view;
6232 GtkTreePath *dest_row;
6233 GdkDragAction suggested_action;
6234 gboolean path_down_mode;
6235 gboolean drop_append_mode;
6237 tree_view = PSPP_SHEET_VIEW (widget);
6239 model = pspp_sheet_view_get_model (tree_view);
6241 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6244 di = get_info (tree_view);
6249 suggested_action = get_status_pending (context);
6251 if (suggested_action)
6253 /* We are getting this data due to a request in drag_motion,
6254 * rather than due to a request in drag_drop, so we are just
6255 * supposed to call drag_status, not actually paste in the
6258 path = get_logical_dest_row (tree_view, &path_down_mode,
6262 suggested_action = 0;
6263 else if (path_down_mode)
6264 gtk_tree_path_down (path);
6266 if (suggested_action)
6268 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6274 path_down_mode = FALSE;
6275 gtk_tree_path_up (path);
6277 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6280 suggested_action = 0;
6283 suggested_action = 0;
6287 gdk_drag_status (context, suggested_action, time);
6290 gtk_tree_path_free (path);
6292 /* If you can't drop, remove user drop indicator until the next motion */
6293 if (suggested_action == 0)
6294 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6296 PSPP_SHEET_VIEW_DROP_BEFORE);
6301 dest_row = get_dest_row (context, &path_down_mode);
6303 if (dest_row == NULL)
6306 if (selection_data->length >= 0)
6310 gtk_tree_path_down (dest_row);
6311 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6312 dest_row, selection_data))
6313 gtk_tree_path_up (dest_row);
6317 if (selection_data->length >= 0)
6319 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6325 gtk_drag_finish (context,
6327 (context->action == GDK_ACTION_MOVE),
6330 if (gtk_tree_path_get_depth (dest_row) == 1
6331 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6333 /* special special case drag to "0", scroll to first item */
6334 if (!tree_view->priv->scroll_to_path)
6335 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6338 gtk_tree_path_free (dest_row);
6341 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6346 /* GtkContainer Methods
6351 pspp_sheet_view_remove (GtkContainer *container,
6354 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6355 PsppSheetViewChild *child = NULL;
6358 tmp_list = tree_view->priv->children;
6361 child = tmp_list->data;
6362 if (child->widget == widget)
6364 gtk_widget_unparent (widget);
6366 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6367 g_list_free_1 (tmp_list);
6368 g_slice_free (PsppSheetViewChild, child);
6372 tmp_list = tmp_list->next;
6375 tmp_list = tree_view->priv->columns;
6379 PsppSheetViewColumn *column;
6380 column = tmp_list->data;
6381 if (column->button == widget)
6383 gtk_widget_unparent (widget);
6386 tmp_list = tmp_list->next;
6391 pspp_sheet_view_forall (GtkContainer *container,
6392 gboolean include_internals,
6393 GtkCallback callback,
6394 gpointer callback_data)
6396 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6397 PsppSheetViewChild *child = NULL;
6398 PsppSheetViewColumn *column;
6401 tmp_list = tree_view->priv->children;
6404 child = tmp_list->data;
6405 tmp_list = tmp_list->next;
6407 (* callback) (child->widget, callback_data);
6409 if (include_internals == FALSE)
6412 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6414 column = tmp_list->data;
6417 (* callback) (column->button, callback_data);
6421 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6422 * cells. If so we draw one big row-spanning focus rectangle.
6425 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6429 for (list = tree_view->priv->columns; list; list = list->next)
6431 if (!((PsppSheetViewColumn *)list->data)->visible)
6433 if (_pspp_sheet_view_column_count_special_cells (list->data))
6440 /* Returns TRUE if the focus is within the headers, after the focus operation is
6444 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6445 GtkDirectionType dir,
6446 gboolean clamp_column_visible)
6448 GtkWidget *focus_child;
6450 GList *last_column, *first_column;
6454 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6457 focus_child = GTK_CONTAINER (tree_view)->focus_child;
6459 first_column = tree_view->priv->columns;
6460 while (first_column)
6462 if (gtk_widget_get_can_focus (PSPP_SHEET_VIEW_COLUMN (first_column->data)->button) &&
6463 PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible &&
6464 (PSPP_SHEET_VIEW_COLUMN (first_column->data)->clickable ||
6465 PSPP_SHEET_VIEW_COLUMN (first_column->data)->reorderable))
6467 first_column = first_column->next;
6470 /* No headers are visible, or are focusable. We can't focus in or out.
6472 if (first_column == NULL)
6475 last_column = g_list_last (tree_view->priv->columns);
6478 if (gtk_widget_get_can_focus (PSPP_SHEET_VIEW_COLUMN (last_column->data)->button) &&
6479 PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible &&
6480 (PSPP_SHEET_VIEW_COLUMN (last_column->data)->clickable ||
6481 PSPP_SHEET_VIEW_COLUMN (last_column->data)->reorderable))
6483 last_column = last_column->prev;
6487 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6491 case GTK_DIR_TAB_BACKWARD:
6492 case GTK_DIR_TAB_FORWARD:
6495 if (focus_child == NULL)
6497 if (tree_view->priv->focus_column != NULL &&
6498 gtk_widget_get_can_focus (tree_view->priv->focus_column->button))
6499 focus_child = tree_view->priv->focus_column->button;
6501 focus_child = PSPP_SHEET_VIEW_COLUMN (first_column->data)->button;
6502 gtk_widget_grab_focus (focus_child);
6509 if (focus_child == NULL)
6511 if (tree_view->priv->focus_column != NULL)
6512 focus_child = tree_view->priv->focus_column->button;
6513 else if (dir == GTK_DIR_LEFT)
6514 focus_child = PSPP_SHEET_VIEW_COLUMN (last_column->data)->button;
6516 focus_child = PSPP_SHEET_VIEW_COLUMN (first_column->data)->button;
6517 gtk_widget_grab_focus (focus_child);
6521 if (gtk_widget_child_focus (focus_child, dir))
6523 /* The focus moves inside the button. */
6524 /* This is probably a great example of bad UI */
6528 /* We need to move the focus among the row of buttons. */
6529 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6530 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6533 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6534 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6536 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6542 PsppSheetViewColumn *column;
6544 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6545 tmp_list = tmp_list->next;
6547 tmp_list = tmp_list->prev;
6549 if (tmp_list == NULL)
6551 g_warning ("Internal button not found");
6554 column = tmp_list->data;
6555 if (column->button &&
6557 gtk_widget_get_can_focus (column->button))
6559 focus_child = column->button;
6560 gtk_widget_grab_focus (column->button);
6566 g_assert_not_reached ();
6570 /* if focus child is non-null, we assume it's been set to the current focus child
6574 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6575 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6577 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
6581 if (clamp_column_visible)
6583 pspp_sheet_view_clamp_column_visible (tree_view,
6584 tree_view->priv->focus_column,
6589 return (focus_child != NULL);
6592 /* This function returns in 'path' the first focusable path, if the given path
6593 * is already focusable, it's the returned one.
6597 search_first_focusable_path (PsppSheetView *tree_view,
6599 gboolean search_forward,
6602 /* XXX this function is trivial given that the sheetview doesn't support
6606 if (!path || !*path)
6609 _pspp_sheet_view_find_node (tree_view, *path, &node);
6617 return (*path != NULL);
6621 pspp_sheet_view_focus (GtkWidget *widget,
6622 GtkDirectionType direction)
6624 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6625 GtkContainer *container = GTK_CONTAINER (widget);
6626 GtkWidget *focus_child;
6628 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6631 focus_child = container->focus_child;
6633 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6634 /* Case 1. Headers currently have focus. */
6641 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6643 case GTK_DIR_TAB_BACKWARD:
6646 case GTK_DIR_TAB_FORWARD:
6648 gtk_widget_grab_focus (widget);
6651 g_assert_not_reached ();
6656 /* Case 2. We don't have focus at all. */
6657 if (!gtk_widget_has_focus (widget))
6659 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6660 gtk_widget_grab_focus (widget);
6664 /* Case 3. We have focus already. */
6665 if (direction == GTK_DIR_TAB_BACKWARD)
6666 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6667 else if (direction == GTK_DIR_TAB_FORWARD)
6670 /* Other directions caught by the keybindings */
6671 gtk_widget_grab_focus (widget);
6676 pspp_sheet_view_grab_focus (GtkWidget *widget)
6678 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6680 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6684 pspp_sheet_view_style_set (GtkWidget *widget,
6685 GtkStyle *previous_style)
6687 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6689 PsppSheetViewColumn *column;
6691 if (gtk_widget_get_realized (widget))
6693 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
6694 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
6695 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
6697 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6700 gtk_widget_style_get (widget,
6701 "expander-size", &tree_view->priv->expander_size,
6703 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6705 for (list = tree_view->priv->columns; list; list = list->next)
6707 column = list->data;
6708 _pspp_sheet_view_column_cell_set_dirty (column);
6711 tree_view->priv->fixed_height = -1;
6713 gtk_widget_queue_resize (widget);
6718 pspp_sheet_view_set_focus_child (GtkContainer *container,
6721 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6724 for (list = tree_view->priv->columns; list; list = list->next)
6726 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6728 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6733 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6737 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6738 GtkAdjustment *hadj,
6739 GtkAdjustment *vadj)
6741 gboolean need_adjust = FALSE;
6743 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6746 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6748 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6750 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
6752 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6754 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
6756 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
6757 pspp_sheet_view_adjustment_changed,
6759 g_object_unref (tree_view->priv->hadjustment);
6762 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
6764 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
6765 pspp_sheet_view_adjustment_changed,
6767 g_object_unref (tree_view->priv->vadjustment);
6770 if (tree_view->priv->hadjustment != hadj)
6772 tree_view->priv->hadjustment = hadj;
6773 g_object_ref_sink (tree_view->priv->hadjustment);
6775 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
6776 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6781 if (tree_view->priv->vadjustment != vadj)
6783 tree_view->priv->vadjustment = vadj;
6784 g_object_ref_sink (tree_view->priv->vadjustment);
6786 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
6787 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6793 pspp_sheet_view_adjustment_changed (NULL, tree_view);
6798 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
6799 GtkMovementStep step,
6802 GdkModifierType state;
6804 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
6805 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
6806 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
6807 step == GTK_MOVEMENT_DISPLAY_LINES ||
6808 step == GTK_MOVEMENT_PAGES ||
6809 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
6811 if (tree_view->priv->row_count == 0)
6813 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
6816 pspp_sheet_view_stop_editing (tree_view, FALSE);
6817 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
6818 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
6820 if (gtk_get_current_event_state (&state))
6822 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
6823 tree_view->priv->ctrl_pressed = TRUE;
6824 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
6825 tree_view->priv->shift_pressed = TRUE;
6827 /* else we assume not pressed */
6831 /* currently we make no distinction. When we go bi-di, we need to */
6832 case GTK_MOVEMENT_LOGICAL_POSITIONS:
6833 case GTK_MOVEMENT_VISUAL_POSITIONS:
6834 pspp_sheet_view_move_cursor_left_right (tree_view, count);
6836 case GTK_MOVEMENT_DISPLAY_LINES:
6837 pspp_sheet_view_move_cursor_up_down (tree_view, count);
6839 case GTK_MOVEMENT_PAGES:
6840 pspp_sheet_view_move_cursor_page_up_down (tree_view, count);
6842 case GTK_MOVEMENT_BUFFER_ENDS:
6843 pspp_sheet_view_move_cursor_start_end (tree_view, count);
6846 g_assert_not_reached ();
6849 tree_view->priv->ctrl_pressed = FALSE;
6850 tree_view->priv->shift_pressed = FALSE;
6856 pspp_sheet_view_put (PsppSheetView *tree_view,
6857 GtkWidget *child_widget,
6858 /* in bin_window coordinates */
6864 PsppSheetViewChild *child;
6866 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6867 g_return_if_fail (GTK_IS_WIDGET (child_widget));
6869 child = g_slice_new (PsppSheetViewChild);
6871 child->widget = child_widget;
6874 child->width = width;
6875 child->height = height;
6877 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
6879 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
6880 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
6882 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
6886 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
6888 /* in tree coordinates */
6894 PsppSheetViewChild *child = NULL;
6896 GdkRectangle allocation;
6898 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6899 g_return_if_fail (GTK_IS_WIDGET (widget));
6901 for (list = tree_view->priv->children; list; list = list->next)
6903 if (((PsppSheetViewChild *)list->data)->widget == widget)
6912 allocation.x = child->x = x;
6913 allocation.y = child->y = y;
6914 allocation.width = child->width = width;
6915 allocation.height = child->height = height;
6917 if (gtk_widget_get_realized (widget))
6918 gtk_widget_size_allocate (widget, &allocation);
6922 /* TreeModel Callbacks
6926 pspp_sheet_view_row_changed (GtkTreeModel *model,
6931 PsppSheetView *tree_view = (PsppSheetView *)data;
6933 gboolean free_path = FALSE;
6934 GtkTreePath *cursor_path;
6936 g_return_if_fail (path != NULL || iter != NULL);
6938 if (tree_view->priv->cursor != NULL)
6939 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
6943 if (tree_view->priv->edited_column &&
6944 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
6945 pspp_sheet_view_stop_editing (tree_view, TRUE);
6947 if (cursor_path != NULL)
6948 gtk_tree_path_free (cursor_path);
6952 path = gtk_tree_model_get_path (model, iter);
6955 else if (iter == NULL)
6956 gtk_tree_model_get_iter (model, iter, path);
6958 _pspp_sheet_view_find_node (tree_view,
6964 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
6965 pspp_sheet_view_node_queue_redraw (tree_view, node);
6969 gtk_tree_path_free (path);
6973 pspp_sheet_view_row_inserted (GtkTreeModel *model,
6978 PsppSheetView *tree_view = (PsppSheetView *) data;
6981 gint height = tree_view->priv->fixed_height;
6982 gboolean free_path = FALSE;
6983 gboolean node_visible = TRUE;
6985 g_return_if_fail (path != NULL || iter != NULL);
6989 path = gtk_tree_model_get_path (model, iter);
6992 else if (iter == NULL)
6993 gtk_tree_model_get_iter (model, iter, path);
6995 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
6997 /* Update all row-references */
6998 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
6999 indices = gtk_tree_path_get_indices (path);
7000 tmpnode = indices[0];
7002 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7006 if (node_visible && node_is_visible (tree_view, tmpnode))
7007 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7009 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7012 install_presize_handler (tree_view);
7014 gtk_tree_path_free (path);
7018 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7022 PsppSheetView *tree_view = (PsppSheetView *)data;
7025 g_return_if_fail (path != NULL);
7027 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7029 _pspp_sheet_view_find_node (tree_view, path, &node);
7034 range_tower_delete (tree_view->priv->selected, node, 1);
7036 /* Ensure we don't have a dangling pointer to a dead node */
7037 ensure_unprelighted (tree_view);
7039 /* Cancel editting if we've started */
7040 pspp_sheet_view_stop_editing (tree_view, TRUE);
7042 if (tree_view->priv->destroy_count_func)
7044 gint child_count = 0;
7045 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7048 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7050 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7052 gtk_tree_row_reference_free (tree_view->priv->top_row);
7053 tree_view->priv->top_row = NULL;
7056 install_scroll_sync_handler (tree_view);
7058 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7061 if (helper_data.changed)
7062 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7067 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7068 GtkTreePath *parent,
7073 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7076 /* XXX need to adjust selection */
7077 len = gtk_tree_model_iter_n_children (model, iter);
7082 gtk_tree_row_reference_reordered (G_OBJECT (data),
7087 if (gtk_tree_path_get_depth (parent) != 0)
7090 if (tree_view->priv->edited_column)
7091 pspp_sheet_view_stop_editing (tree_view, TRUE);
7093 /* we need to be unprelighted */
7094 ensure_unprelighted (tree_view);
7096 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7098 pspp_sheet_view_dy_to_top_row (tree_view);
7102 /* Internal tree functions
7107 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7108 PsppSheetViewColumn *column,
7112 PsppSheetViewColumn *tmp_column = NULL;
7123 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7126 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7128 list = (rtl ? list->prev : list->next))
7130 tmp_column = list->data;
7132 if (tmp_column == column)
7135 if (tmp_column->visible)
7136 total_width += tmp_column->width;
7139 if (tmp_column != column)
7141 g_warning (G_STRLOC": passed-in column isn't in the tree");
7150 if (column->visible)
7151 *x2 = total_width + column->width;
7153 *x2 = total_width; /* width of 0 */
7157 /* Make sure the node is visible vertically */
7159 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7162 gint node_dy, height;
7163 GtkTreePath *path = NULL;
7165 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7168 /* just return if the node is visible, avoiding a costly expose */
7169 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7170 height = ROW_HEIGHT (tree_view);
7171 if (node_dy >= tree_view->priv->vadjustment->value
7172 && node_dy + height <= (tree_view->priv->vadjustment->value
7173 + tree_view->priv->vadjustment->page_size))
7176 path = _pspp_sheet_view_find_path (tree_view, node);
7179 /* We process updates because we want to clear old selected items when we scroll.
7180 * if this is removed, we get a "selection streak" at the bottom. */
7181 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7182 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7183 gtk_tree_path_free (path);
7188 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7189 PsppSheetViewColumn *column,
7190 gboolean focus_to_cell)
7197 x = column->button->allocation.x;
7198 width = column->button->allocation.width;
7200 if (width > tree_view->priv->hadjustment->page_size)
7202 /* The column is larger than the horizontal page size. If the
7203 * column has cells which can be focussed individually, then we make
7204 * sure the cell which gets focus is fully visible (if even the
7205 * focus cell is bigger than the page size, we make sure the
7206 * left-hand side of the cell is visible).
7208 * If the column does not have those so-called special cells, we
7209 * make sure the left-hand side of the column is visible.
7212 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7214 GtkTreePath *cursor_path;
7215 GdkRectangle background_area, cell_area, focus_area;
7217 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7219 pspp_sheet_view_get_cell_area (tree_view,
7220 cursor_path, column, &cell_area);
7221 pspp_sheet_view_get_background_area (tree_view,
7222 cursor_path, column,
7225 gtk_tree_path_free (cursor_path);
7227 _pspp_sheet_view_column_get_focus_area (column,
7233 width = focus_area.width;
7235 if (width < tree_view->priv->hadjustment->page_size)
7237 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7238 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7239 x + width - tree_view->priv->hadjustment->page_size);
7240 else if (tree_view->priv->hadjustment->value > x)
7241 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7245 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7247 tree_view->priv->hadjustment->lower,
7248 tree_view->priv->hadjustment->upper
7249 - tree_view->priv->hadjustment->page_size));
7253 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7254 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7255 x + width - tree_view->priv->hadjustment->page_size);
7256 else if (tree_view->priv->hadjustment->value > x)
7257 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7262 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7267 path = gtk_tree_path_new ();
7269 gtk_tree_path_append_index (path, node);
7274 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7278 gint *indices = gtk_tree_path_get_indices (path);
7279 gint depth = gtk_tree_path_get_depth (path);
7282 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7288 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7291 gboolean add_shifted_binding,
7292 GtkMovementStep step,
7296 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7301 if (add_shifted_binding)
7302 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7307 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7310 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7315 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7322 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7323 PsppSheetViewColumn *column)
7325 PsppSheetViewColumn *left_column;
7326 PsppSheetViewColumn *cur_column = NULL;
7327 PsppSheetViewColumnReorder *reorder;
7332 /* We want to precalculate the motion list such that we know what column slots
7336 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7338 /* First, identify all possible drop spots */
7340 tmp_list = g_list_last (tree_view->priv->columns);
7342 tmp_list = g_list_first (tree_view->priv->columns);
7346 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7347 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7349 if (cur_column->visible == FALSE)
7352 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7353 if (left_column != column && cur_column != column &&
7354 tree_view->priv->column_drop_func &&
7355 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7357 left_column = cur_column;
7360 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7361 reorder->left_column = left_column;
7362 left_column = reorder->right_column = cur_column;
7364 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7367 /* Add the last one */
7368 if (tree_view->priv->column_drop_func == NULL ||
7369 ((left_column != column) &&
7370 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7372 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7373 reorder->left_column = left_column;
7374 reorder->right_column = NULL;
7375 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7378 /* We quickly check to see if it even makes sense to reorder columns. */
7379 /* If there is nothing that can be moved, then we return */
7381 if (tree_view->priv->column_drag_info == NULL)
7384 /* We know there are always 2 slots possbile, as you can always return column. */
7385 /* If that's all there is, return */
7386 if (tree_view->priv->column_drag_info->next == NULL ||
7387 (tree_view->priv->column_drag_info->next->next == NULL &&
7388 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7389 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7391 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7392 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7393 g_list_free (tree_view->priv->column_drag_info);
7394 tree_view->priv->column_drag_info = NULL;
7397 /* We fill in the ranges for the columns, now that we've isolated them */
7398 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7400 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7402 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7404 reorder->left_align = left;
7405 if (tmp_list->next != NULL)
7407 g_assert (tmp_list->next->data);
7408 left = reorder->right_align = (reorder->right_column->button->allocation.x +
7409 reorder->right_column->button->allocation.width +
7410 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->button->allocation.x)/2;
7416 gdk_drawable_get_size (tree_view->priv->header_window, &width, NULL);
7417 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7423 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7424 PsppSheetViewColumn *column)
7426 GdkEvent *send_event;
7427 GtkAllocation allocation;
7428 gint x, y, width, height;
7429 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7430 GdkDisplay *display = gdk_screen_get_display (screen);
7432 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7433 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7435 pspp_sheet_view_set_column_drag_info (tree_view, column);
7437 if (tree_view->priv->column_drag_info == NULL)
7440 if (tree_view->priv->drag_window == NULL)
7442 GdkWindowAttr attributes;
7443 guint attributes_mask;
7445 attributes.window_type = GDK_WINDOW_CHILD;
7446 attributes.wclass = GDK_INPUT_OUTPUT;
7447 attributes.x = column->button->allocation.x;
7449 attributes.width = column->button->allocation.width;
7450 attributes.height = column->button->allocation.height;
7451 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7452 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
7453 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7454 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
7456 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7459 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7462 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7463 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7465 gtk_grab_remove (column->button);
7467 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7468 send_event->crossing.send_event = TRUE;
7469 send_event->crossing.window = g_object_ref (GTK_BUTTON (column->button)->event_window);
7470 send_event->crossing.subwindow = NULL;
7471 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7472 send_event->crossing.time = GDK_CURRENT_TIME;
7474 gtk_propagate_event (column->button, send_event);
7475 gdk_event_free (send_event);
7477 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7478 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7479 send_event->button.send_event = TRUE;
7480 send_event->button.time = GDK_CURRENT_TIME;
7481 send_event->button.x = -1;
7482 send_event->button.y = -1;
7483 send_event->button.axes = NULL;
7484 send_event->button.state = 0;
7485 send_event->button.button = 1;
7486 send_event->button.device = gdk_display_get_core_pointer (display);
7487 send_event->button.x_root = 0;
7488 send_event->button.y_root = 0;
7490 gtk_propagate_event (column->button, send_event);
7491 gdk_event_free (send_event);
7493 /* Kids, don't try this at home */
7494 g_object_ref (column->button);
7495 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7496 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7497 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7498 g_object_unref (column->button);
7500 tree_view->priv->drag_column_x = column->button->allocation.x;
7501 allocation = column->button->allocation;
7503 gtk_widget_size_allocate (column->button, &allocation);
7504 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7506 tree_view->priv->drag_column = column;
7507 gdk_window_show (tree_view->priv->drag_window);
7509 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7510 gdk_drawable_get_size (tree_view->priv->header_window, &width, &height);
7512 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7513 while (gtk_events_pending ())
7514 gtk_main_iteration ();
7516 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7517 gdk_pointer_grab (tree_view->priv->drag_window,
7519 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7520 NULL, NULL, GDK_CURRENT_TIME);
7521 gdk_keyboard_grab (tree_view->priv->drag_window,
7527 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7529 const GdkRectangle *clip_rect)
7533 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7537 rect.width = MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width);
7539 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7540 rect.height = ROW_HEIGHT (tree_view);
7544 GdkRectangle new_rect;
7546 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7548 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7552 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7557 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7559 const GdkRectangle *clip_rect)
7563 _pspp_sheet_view_find_node (tree_view, path, &node);
7566 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7570 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7573 GtkTreePath *cursor_path;
7575 if ((tree_view->priv->row_count == 0) ||
7576 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7580 if (tree_view->priv->cursor)
7581 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7583 if (cursor_path == NULL)
7585 /* There's no cursor. Move the cursor to the first selected row, if any
7586 * are selected, otherwise to the first row in the sheetview.
7588 GList *selected_rows;
7589 GtkTreeModel *model;
7590 PsppSheetSelection *selection;
7592 selection = pspp_sheet_view_get_selection (tree_view);
7593 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7597 /* XXX we could avoid doing O(n) work to get this result */
7598 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7599 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7600 g_list_free (selected_rows);
7604 cursor_path = gtk_tree_path_new_first ();
7605 search_first_focusable_path (tree_view, &cursor_path,
7609 gtk_tree_row_reference_free (tree_view->priv->cursor);
7610 tree_view->priv->cursor = NULL;
7614 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7615 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7616 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE);
7618 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
7624 /* Now find a column for the cursor. */
7625 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7627 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7628 gtk_tree_path_free (cursor_path);
7630 if (tree_view->priv->focus_column == NULL)
7633 for (list = tree_view->priv->columns; list; list = list->next)
7635 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7637 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7638 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7639 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7649 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7652 gint selection_count;
7653 int cursor_node = -1;
7654 int new_cursor_node = -1;
7655 GtkTreePath *cursor_path = NULL;
7656 gboolean grab_focus = TRUE;
7658 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7662 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7663 /* FIXME: we lost the cursor; should we get the first? */
7666 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7667 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7669 if (cursor_node < 0)
7670 /* FIXME: we lost the cursor; should we get the first? */
7673 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7675 if (selection_count == 0
7676 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7677 && !tree_view->priv->ctrl_pressed)
7679 /* Don't move the cursor, but just select the current node */
7680 new_cursor_node = cursor_node;
7685 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7687 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7690 gtk_tree_path_free (cursor_path);
7692 if (new_cursor_node)
7694 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7696 search_first_focusable_path (tree_view, &cursor_path,
7701 gtk_tree_path_free (cursor_path);
7705 * If the list has only one item and multi-selection is set then select
7706 * the row (if not yet selected).
7708 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7709 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7710 new_cursor_node < 0)
7713 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7715 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7717 if (new_cursor_node < 0
7718 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7720 new_cursor_node = cursor_node;
7724 new_cursor_node = -1;
7728 if (new_cursor_node >= 0)
7730 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7731 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE);
7732 gtk_tree_path_free (cursor_path);
7736 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7738 if (!tree_view->priv->shift_pressed)
7740 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7742 GTK_DIR_UP : GTK_DIR_DOWN))
7744 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
7747 gtk_widget_child_focus (toplevel,
7749 GTK_DIR_TAB_BACKWARD :
7750 GTK_DIR_TAB_FORWARD);
7757 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7762 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7766 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
7769 int cursor_node = -1;
7770 GtkTreePath *old_cursor_path = NULL;
7771 GtkTreePath *cursor_path = NULL;
7772 int start_cursor_node = -1;
7775 gint vertical_separator;
7777 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7780 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
7781 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7783 /* This is sorta weird. Focus in should give us a cursor */
7786 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
7787 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
7789 if (cursor_node < 0)
7791 /* FIXME: we lost the cursor. Should we try to get one? */
7792 gtk_tree_path_free (old_cursor_path);
7796 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7797 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
7798 y += tree_view->priv->cursor_offset;
7799 y += count * (int)tree_view->priv->vadjustment->page_increment;
7800 y = CLAMP (y, (gint)tree_view->priv->vadjustment->lower, (gint)tree_view->priv->vadjustment->upper - vertical_separator);
7802 if (y >= tree_view->priv->height)
7803 y = tree_view->priv->height - 1;
7805 tree_view->priv->cursor_offset =
7806 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
7808 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
7810 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7811 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
7814 y -= tree_view->priv->cursor_offset;
7815 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7817 start_cursor_node = cursor_node;
7819 if (! search_first_focusable_path (tree_view, &cursor_path,
7823 /* It looks like we reached the end of the view without finding
7824 * a focusable row. We will step backwards to find the last
7827 cursor_node = start_cursor_node;
7828 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7830 search_first_focusable_path (tree_view, &cursor_path,
7839 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7841 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
7844 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
7845 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7846 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
7848 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
7849 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7851 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7854 gtk_tree_path_free (old_cursor_path);
7855 gtk_tree_path_free (cursor_path);
7859 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
7862 int cursor_node = -1;
7863 GtkTreePath *cursor_path = NULL;
7864 PsppSheetViewColumn *column;
7867 gboolean found_column = FALSE;
7870 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7872 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7875 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
7876 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7880 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7881 if (cursor_node < 0)
7883 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
7885 gtk_tree_path_free (cursor_path);
7888 gtk_tree_path_free (cursor_path);
7890 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
7891 if (tree_view->priv->focus_column)
7893 for (; list; list = (rtl ? list->prev : list->next))
7895 if (list->data == tree_view->priv->focus_column)
7902 gboolean left, right;
7904 column = list->data;
7905 if (column->visible == FALSE)
7908 pspp_sheet_view_column_cell_set_cell_data (column,
7909 tree_view->priv->model,
7914 right = list->prev ? TRUE : FALSE;
7915 left = list->next ? TRUE : FALSE;
7919 left = list->prev ? TRUE : FALSE;
7920 right = list->next ? TRUE : FALSE;
7923 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
7925 tree_view->priv->focus_column = column;
7926 found_column = TRUE;
7931 list = rtl ? list->prev : list->next;
7933 list = rtl ? list->next : list->prev;
7938 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
7939 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
7940 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7944 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7947 pspp_sheet_view_clamp_column_visible (tree_view,
7948 tree_view->priv->focus_column, TRUE);
7952 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
7957 GtkTreePath *old_path;
7959 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7962 g_return_if_fail (tree_view->priv->row_count > 0);
7964 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
7968 /* Now go forward to find the first focusable row. */
7969 path = _pspp_sheet_view_find_path (tree_view, 0);
7970 search_first_focusable_path (tree_view, &path,
7971 TRUE, &cursor_node);
7975 /* Now go backwards to find last focusable row. */
7976 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
7977 search_first_focusable_path (tree_view, &path,
7978 FALSE, &cursor_node);
7984 if (gtk_tree_path_compare (old_path, path))
7986 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
7987 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7991 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7995 gtk_tree_path_free (old_path);
7996 gtk_tree_path_free (path);
8000 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8002 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8005 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8006 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8009 pspp_sheet_selection_select_all (tree_view->priv->selection);
8015 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8017 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8020 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8021 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8024 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8030 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8031 gboolean start_editing)
8034 int cursor_node = -1;
8035 GtkTreePath *cursor_path = NULL;
8036 GtkTreeSelectMode mode = 0;
8038 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8041 if (tree_view->priv->cursor)
8042 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8044 if (cursor_path == NULL)
8047 _pspp_sheet_view_find_node (tree_view, cursor_path,
8050 if (cursor_node < 0)
8052 gtk_tree_path_free (cursor_path);
8056 if (!tree_view->priv->shift_pressed && start_editing &&
8057 tree_view->priv->focus_column)
8059 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8061 gtk_tree_path_free (cursor_path);
8066 if (tree_view->priv->ctrl_pressed)
8067 mode |= GTK_TREE_SELECT_MODE_TOGGLE;
8068 if (tree_view->priv->shift_pressed)
8069 mode |= GTK_TREE_SELECT_MODE_EXTEND;
8071 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8077 /* We bail out if the original (tree, node) don't exist anymore after
8078 * handling the selection-changed callback. We do return TRUE because
8079 * the key press has been handled at this point.
8081 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8083 if (cursor_node != new_node)
8086 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8088 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8089 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8091 if (!tree_view->priv->shift_pressed)
8092 pspp_sheet_view_row_activated (tree_view, cursor_path,
8093 tree_view->priv->focus_column);
8095 gtk_tree_path_free (cursor_path);
8101 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8104 int cursor_node = -1;
8105 GtkTreePath *cursor_path = NULL;
8107 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8111 if (tree_view->priv->cursor)
8112 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8114 if (cursor_path == NULL)
8117 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8118 if (cursor_node < 0)
8120 gtk_tree_path_free (cursor_path);
8124 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8127 GTK_TREE_SELECT_MODE_TOGGLE,
8130 /* We bail out if the original (tree, node) don't exist anymore after
8131 * handling the selection-changed callback. We do return TRUE because
8132 * the key press has been handled at this point.
8134 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8136 if (cursor_node != new_node)
8139 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8141 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8142 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8143 gtk_tree_path_free (cursor_path);
8149 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8151 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8152 tree_view->priv->typeselect_flush_timeout = 0;
8157 /* Cut and paste from gtkwindow.c */
8159 send_focus_change (GtkWidget *widget,
8162 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8164 g_object_ref (widget);
8167 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
8169 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
8171 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8172 fevent->focus_change.window = g_object_ref (widget->window);
8173 fevent->focus_change.in = in;
8175 gtk_widget_event (widget, fevent);
8177 g_object_notify (G_OBJECT (widget), "has-focus");
8179 g_object_unref (widget);
8180 gdk_event_free (fevent);
8184 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8186 GtkWidget *frame, *vbox, *toplevel;
8189 if (tree_view->priv->search_custom_entry_set)
8192 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8193 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8195 if (tree_view->priv->search_window != NULL)
8197 if (GTK_WINDOW (toplevel)->group)
8198 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8199 GTK_WINDOW (tree_view->priv->search_window));
8200 else if (GTK_WINDOW (tree_view->priv->search_window)->group)
8201 gtk_window_group_remove_window (GTK_WINDOW (tree_view->priv->search_window)->group,
8202 GTK_WINDOW (tree_view->priv->search_window));
8203 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8207 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8208 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8210 if (GTK_WINDOW (toplevel)->group)
8211 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8212 GTK_WINDOW (tree_view->priv->search_window));
8214 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8215 GDK_WINDOW_TYPE_HINT_UTILITY);
8216 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8217 g_signal_connect (tree_view->priv->search_window, "delete-event",
8218 G_CALLBACK (pspp_sheet_view_search_delete_event),
8220 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8221 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8223 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8224 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8226 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8227 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8230 frame = gtk_frame_new (NULL);
8231 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8232 gtk_widget_show (frame);
8233 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8235 vbox = gtk_vbox_new (FALSE, 0);
8236 gtk_widget_show (vbox);
8237 gtk_container_add (GTK_CONTAINER (frame), vbox);
8238 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8241 tree_view->priv->search_entry = gtk_entry_new ();
8242 gtk_widget_show (tree_view->priv->search_entry);
8243 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8244 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8246 g_signal_connect (tree_view->priv->search_entry,
8247 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8249 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8251 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8253 gtk_container_add (GTK_CONTAINER (vbox),
8254 tree_view->priv->search_entry);
8256 gtk_widget_realize (tree_view->priv->search_entry);
8259 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8260 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8263 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8264 gboolean keybinding)
8266 /* We only start interactive search if we have focus or the columns
8267 * have focus. If one of our children have focus, we don't want to
8271 gboolean found_focus = FALSE;
8272 GtkWidgetClass *entry_parent_class;
8274 if (!tree_view->priv->enable_search && !keybinding)
8277 if (tree_view->priv->search_custom_entry_set)
8280 if (tree_view->priv->search_window != NULL &&
8281 gtk_widget_get_visible (tree_view->priv->search_window))
8284 for (list = tree_view->priv->columns; list; list = list->next)
8286 PsppSheetViewColumn *column;
8288 column = list->data;
8289 if (! column->visible)
8292 if (gtk_widget_has_focus (column->button))
8299 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8305 if (tree_view->priv->search_column < 0)
8308 pspp_sheet_view_ensure_interactive_directory (tree_view);
8311 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8314 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8315 gtk_widget_show (tree_view->priv->search_window);
8316 if (tree_view->priv->search_entry_changed_id == 0)
8318 tree_view->priv->search_entry_changed_id =
8319 g_signal_connect (tree_view->priv->search_entry, "changed",
8320 G_CALLBACK (pspp_sheet_view_search_init),
8324 tree_view->priv->typeselect_flush_timeout =
8325 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8326 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8329 /* Grab focus will select all the text. We don't want that to happen, so we
8330 * call the parent instance and bypass the selection change. This is probably
8331 * really non-kosher. */
8332 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8333 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8335 /* send focus-in event */
8336 send_focus_change (tree_view->priv->search_entry, TRUE);
8338 /* search first matching iter */
8339 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8345 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8347 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8350 /* this function returns the new width of the column being resized given
8351 * the column and x position of the cursor; the x cursor position is passed
8352 * in as a pointer and automagicly corrected if it's beyond min/max limits
8355 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8359 PsppSheetViewColumn *column;
8363 /* first translate the x position from widget->window
8364 * to clist->clist_window
8366 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8367 column = g_list_nth (tree_view->priv->columns, i)->data;
8368 width = rtl ? (column->button->allocation.x + column->button->allocation.width - *x) : (*x - column->button->allocation.x);
8370 /* Clamp down the value */
8371 if (column->min_width == -1)
8372 width = MAX (column->button->requisition.width,
8375 width = MAX (column->min_width,
8377 if (column->max_width != -1)
8378 width = MIN (width, column->max_width);
8380 *x = rtl ? (column->button->allocation.x + column->button->allocation.width - width) : (column->button->allocation.x + width);
8386 /* FIXME this adjust_allocation is a big cut-and-paste from
8387 * GtkCList, needs to be some "official" way to do this
8397 /* The window to which widget->window is relative */
8398 #define ALLOCATION_WINDOW(widget) \
8399 (!gtk_widget_get_has_window (widget) ? \
8400 (widget)->window : \
8401 gdk_window_get_parent ((widget)->window))
8404 adjust_allocation_recurse (GtkWidget *widget,
8407 ScrollData *scroll_data = data;
8409 /* Need to really size allocate instead of just poking
8410 * into widget->allocation if the widget is not realized.
8411 * FIXME someone figure out why this was.
8413 if (!gtk_widget_get_realized (widget))
8415 if (gtk_widget_get_visible (widget))
8417 GdkRectangle tmp_rectangle = widget->allocation;
8418 tmp_rectangle.x += scroll_data->dx;
8419 tmp_rectangle.y += scroll_data->dy;
8421 gtk_widget_size_allocate (widget, &tmp_rectangle);
8426 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8428 widget->allocation.x += scroll_data->dx;
8429 widget->allocation.y += scroll_data->dy;
8431 if (GTK_IS_CONTAINER (widget))
8432 gtk_container_forall (GTK_CONTAINER (widget),
8433 adjust_allocation_recurse,
8440 adjust_allocation (GtkWidget *widget,
8444 ScrollData scroll_data;
8446 if (gtk_widget_get_realized (widget))
8447 scroll_data.window = ALLOCATION_WINDOW (widget);
8449 scroll_data.window = NULL;
8451 scroll_data.dx = dx;
8452 scroll_data.dy = dy;
8454 adjust_allocation_recurse (widget, &scroll_data);
8459 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8460 PsppSheetView *tree_view)
8462 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8466 gdk_window_move (tree_view->priv->bin_window,
8467 - tree_view->priv->hadjustment->value,
8468 TREE_VIEW_HEADER_HEIGHT (tree_view));
8469 gdk_window_move (tree_view->priv->header_window,
8470 - tree_view->priv->hadjustment->value,
8472 dy = tree_view->priv->dy - (int) tree_view->priv->vadjustment->value;
8475 update_prelight (tree_view,
8476 tree_view->priv->event_last_x,
8477 tree_view->priv->event_last_y - dy);
8479 if (tree_view->priv->edited_column &&
8480 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8484 PsppSheetViewChild *child = NULL;
8486 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8487 adjust_allocation (widget, 0, dy);
8489 for (list = tree_view->priv->children; list; list = list->next)
8491 child = (PsppSheetViewChild *)list->data;
8492 if (child->widget == widget)
8500 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8502 if (tree_view->priv->dy != (int) tree_view->priv->vadjustment->value)
8504 /* update our dy and top_row */
8505 tree_view->priv->dy = (int) tree_view->priv->vadjustment->value;
8507 if (!tree_view->priv->in_top_row_to_dy)
8508 pspp_sheet_view_dy_to_top_row (tree_view);
8511 gdk_window_process_updates (tree_view->priv->header_window, TRUE);
8512 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
8522 * pspp_sheet_view_new:
8524 * Creates a new #PsppSheetView widget.
8526 * Return value: A newly created #PsppSheetView widget.
8529 pspp_sheet_view_new (void)
8531 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8535 * pspp_sheet_view_new_with_model:
8536 * @model: the model.
8538 * Creates a new #PsppSheetView widget with the model initialized to @model.
8540 * Return value: A newly created #PsppSheetView widget.
8543 pspp_sheet_view_new_with_model (GtkTreeModel *model)
8545 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
8552 * pspp_sheet_view_get_model:
8553 * @tree_view: a #PsppSheetView
8555 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
8558 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
8561 pspp_sheet_view_get_model (PsppSheetView *tree_view)
8563 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8565 return tree_view->priv->model;
8569 * pspp_sheet_view_set_model:
8570 * @tree_view: A #GtkTreeNode.
8571 * @model: (allow-none): The model.
8573 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
8574 * set, it will remove it before setting the new model. If @model is %NULL,
8575 * then it will unset the old model.
8578 pspp_sheet_view_set_model (PsppSheetView *tree_view,
8579 GtkTreeModel *model)
8581 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8582 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
8584 if (model == tree_view->priv->model)
8587 if (tree_view->priv->scroll_to_path)
8589 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8590 tree_view->priv->scroll_to_path = NULL;
8593 if (tree_view->priv->model)
8595 GList *tmplist = tree_view->priv->columns;
8597 if (tree_view->priv->selected)
8598 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
8599 pspp_sheet_view_stop_editing (tree_view, TRUE);
8601 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8602 pspp_sheet_view_row_changed,
8604 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8605 pspp_sheet_view_row_inserted,
8607 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8608 pspp_sheet_view_row_deleted,
8610 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8611 pspp_sheet_view_rows_reordered,
8614 for (; tmplist; tmplist = tmplist->next)
8615 _pspp_sheet_view_column_unset_model (tmplist->data,
8616 tree_view->priv->model);
8618 tree_view->priv->prelight_node = -1;
8620 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
8621 tree_view->priv->drag_dest_row = NULL;
8622 gtk_tree_row_reference_free (tree_view->priv->cursor);
8623 tree_view->priv->cursor = NULL;
8624 gtk_tree_row_reference_free (tree_view->priv->anchor);
8625 tree_view->priv->anchor = NULL;
8626 gtk_tree_row_reference_free (tree_view->priv->top_row);
8627 tree_view->priv->top_row = NULL;
8628 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8629 tree_view->priv->scroll_to_path = NULL;
8631 tree_view->priv->scroll_to_column = NULL;
8633 g_object_unref (tree_view->priv->model);
8635 tree_view->priv->search_column = -1;
8636 tree_view->priv->fixed_height = -1;
8637 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
8638 tree_view->priv->last_button_x = -1;
8639 tree_view->priv->last_button_y = -1;
8642 tree_view->priv->model = model;
8644 if (tree_view->priv->model)
8647 GtkTreeModelFlags flags;
8649 if (tree_view->priv->search_column == -1)
8651 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
8653 GType type = gtk_tree_model_get_column_type (model, i);
8655 if (g_value_type_transformable (type, G_TYPE_STRING))
8657 tree_view->priv->search_column = i;
8663 g_object_ref (tree_view->priv->model);
8664 g_signal_connect (tree_view->priv->model,
8666 G_CALLBACK (pspp_sheet_view_row_changed),
8668 g_signal_connect (tree_view->priv->model,
8670 G_CALLBACK (pspp_sheet_view_row_inserted),
8672 g_signal_connect (tree_view->priv->model,
8674 G_CALLBACK (pspp_sheet_view_row_deleted),
8676 g_signal_connect (tree_view->priv->model,
8678 G_CALLBACK (pspp_sheet_view_rows_reordered),
8681 flags = gtk_tree_model_get_flags (tree_view->priv->model);
8683 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
8685 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
8686 install_presize_handler (tree_view);
8689 g_object_notify (G_OBJECT (tree_view), "model");
8691 if (tree_view->priv->selection)
8692 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
8694 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8695 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
8699 * pspp_sheet_view_get_selection:
8700 * @tree_view: A #PsppSheetView.
8702 * Gets the #PsppSheetSelection associated with @tree_view.
8704 * Return value: A #PsppSheetSelection object.
8706 PsppSheetSelection *
8707 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
8709 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8711 return tree_view->priv->selection;
8715 * pspp_sheet_view_get_hadjustment:
8716 * @tree_view: A #PsppSheetView
8718 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
8720 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8724 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
8726 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8728 if (tree_view->priv->hadjustment == NULL)
8729 pspp_sheet_view_set_hadjustment (tree_view, NULL);
8731 return tree_view->priv->hadjustment;
8735 * pspp_sheet_view_set_hadjustment:
8736 * @tree_view: A #PsppSheetView
8737 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8739 * Sets the #GtkAdjustment for the current horizontal aspect.
8742 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
8743 GtkAdjustment *adjustment)
8745 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8747 pspp_sheet_view_set_adjustments (tree_view,
8749 tree_view->priv->vadjustment);
8751 g_object_notify (G_OBJECT (tree_view), "hadjustment");
8755 * pspp_sheet_view_get_vadjustment:
8756 * @tree_view: A #PsppSheetView
8758 * Gets the #GtkAdjustment currently being used for the vertical aspect.
8760 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8764 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
8766 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8768 if (tree_view->priv->vadjustment == NULL)
8769 pspp_sheet_view_set_vadjustment (tree_view, NULL);
8771 return tree_view->priv->vadjustment;
8775 * pspp_sheet_view_set_vadjustment:
8776 * @tree_view: A #PsppSheetView
8777 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8779 * Sets the #GtkAdjustment for the current vertical aspect.
8782 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
8783 GtkAdjustment *adjustment)
8785 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8787 pspp_sheet_view_set_adjustments (tree_view,
8788 tree_view->priv->hadjustment,
8791 g_object_notify (G_OBJECT (tree_view), "vadjustment");
8794 /* Column and header operations */
8797 * pspp_sheet_view_get_headers_visible:
8798 * @tree_view: A #PsppSheetView.
8800 * Returns %TRUE if the headers on the @tree_view are visible.
8802 * Return value: Whether the headers are visible or not.
8805 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
8807 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
8809 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8813 * pspp_sheet_view_set_headers_visible:
8814 * @tree_view: A #PsppSheetView.
8815 * @headers_visible: %TRUE if the headers are visible
8817 * Sets the visibility state of the headers.
8820 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
8821 gboolean headers_visible)
8825 PsppSheetViewColumn *column;
8827 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8829 headers_visible = !! headers_visible;
8831 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
8834 if (headers_visible)
8835 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8837 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8839 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8841 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
8842 if (headers_visible)
8844 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));
8846 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
8847 pspp_sheet_view_map_buttons (tree_view);
8851 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
8853 for (list = tree_view->priv->columns; list; list = list->next)
8855 column = list->data;
8856 gtk_widget_unmap (column->button);
8858 gdk_window_hide (tree_view->priv->header_window);
8862 tree_view->priv->vadjustment->page_size = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
8863 tree_view->priv->vadjustment->page_increment = (GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2;
8864 tree_view->priv->vadjustment->lower = 0;
8865 tree_view->priv->vadjustment->upper = tree_view->priv->height;
8866 gtk_adjustment_changed (tree_view->priv->vadjustment);
8868 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
8870 g_object_notify (G_OBJECT (tree_view), "headers-visible");
8874 * pspp_sheet_view_columns_autosize:
8875 * @tree_view: A #PsppSheetView.
8877 * Resizes all columns to their optimal width. Only works after the
8878 * treeview has been realized.
8881 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
8883 gboolean dirty = FALSE;
8885 PsppSheetViewColumn *column;
8887 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8889 for (list = tree_view->priv->columns; list; list = list->next)
8891 column = list->data;
8892 _pspp_sheet_view_column_cell_set_dirty (column);
8897 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
8901 * pspp_sheet_view_set_headers_clickable:
8902 * @tree_view: A #PsppSheetView.
8903 * @setting: %TRUE if the columns are clickable.
8905 * Allow the column title buttons to be clicked.
8908 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
8913 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8915 for (list = tree_view->priv->columns; list; list = list->next)
8916 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
8918 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
8923 * pspp_sheet_view_get_headers_clickable:
8924 * @tree_view: A #PsppSheetView.
8926 * Returns whether all header columns are clickable.
8928 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
8933 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
8937 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
8939 for (list = tree_view->priv->columns; list; list = list->next)
8940 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
8947 * pspp_sheet_view_set_rules_hint
8948 * @tree_view: a #PsppSheetView
8949 * @setting: %TRUE if the tree requires reading across rows
8951 * This function tells GTK+ that the user interface for your
8952 * application requires users to read across tree rows and associate
8953 * cells with one another. By default, GTK+ will then render the tree
8954 * with alternating row colors. Do <emphasis>not</emphasis> use it
8955 * just because you prefer the appearance of the ruled tree; that's a
8956 * question for the theme. Some themes will draw tree rows in
8957 * alternating colors even when rules are turned off, and users who
8958 * prefer that appearance all the time can choose those themes. You
8959 * should call this function only as a <emphasis>semantic</emphasis>
8960 * hint to the theme engine that your tree makes alternating colors
8961 * useful from a functional standpoint (since it has lots of columns,
8966 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
8969 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8971 setting = setting != FALSE;
8973 if (tree_view->priv->has_rules != setting)
8975 tree_view->priv->has_rules = setting;
8976 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
8979 g_object_notify (G_OBJECT (tree_view), "rules-hint");
8983 * pspp_sheet_view_get_rules_hint
8984 * @tree_view: a #PsppSheetView
8986 * Gets the setting set by pspp_sheet_view_set_rules_hint().
8988 * Return value: %TRUE if rules are useful for the user of this tree
8991 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
8993 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
8995 return tree_view->priv->has_rules;
8998 /* Public Column functions
9002 * pspp_sheet_view_append_column:
9003 * @tree_view: A #PsppSheetView.
9004 * @column: The #PsppSheetViewColumn to add.
9006 * Appends @column to the list of columns.
9008 * Return value: The number of columns in @tree_view after appending.
9011 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9012 PsppSheetViewColumn *column)
9014 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9015 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9016 g_return_val_if_fail (column->tree_view == NULL, -1);
9018 return pspp_sheet_view_insert_column (tree_view, column, -1);
9023 * pspp_sheet_view_remove_column:
9024 * @tree_view: A #PsppSheetView.
9025 * @column: The #PsppSheetViewColumn to remove.
9027 * Removes @column from @tree_view.
9029 * Return value: The number of columns in @tree_view after removing.
9032 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9033 PsppSheetViewColumn *column)
9035 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9036 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9037 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9039 if (tree_view->priv->focus_column == column)
9040 tree_view->priv->focus_column = NULL;
9042 if (tree_view->priv->edited_column == column)
9044 pspp_sheet_view_stop_editing (tree_view, TRUE);
9046 /* no need to, but just to be sure ... */
9047 tree_view->priv->edited_column = NULL;
9050 _pspp_sheet_view_column_unset_tree_view (column);
9052 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9053 tree_view->priv->n_columns--;
9055 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9059 _pspp_sheet_view_column_unrealize_button (column);
9060 for (list = tree_view->priv->columns; list; list = list->next)
9062 PsppSheetViewColumn *tmp_column;
9064 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9065 if (tmp_column->visible)
9066 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9069 if (tree_view->priv->n_columns == 0 &&
9070 pspp_sheet_view_get_headers_visible (tree_view))
9071 gdk_window_hide (tree_view->priv->header_window);
9073 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9076 g_object_unref (column);
9077 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9079 return tree_view->priv->n_columns;
9083 * pspp_sheet_view_insert_column:
9084 * @tree_view: A #PsppSheetView.
9085 * @column: The #PsppSheetViewColumn to be inserted.
9086 * @position: The position to insert @column in.
9088 * This inserts the @column into the @tree_view at @position. If @position is
9089 * -1, then the column is inserted at the end.
9091 * Return value: The number of columns in @tree_view after insertion.
9094 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9095 PsppSheetViewColumn *column,
9098 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9099 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9100 g_return_val_if_fail (column->tree_view == NULL, -1);
9102 g_object_ref_sink (column);
9104 if (tree_view->priv->n_columns == 0 &&
9105 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9106 pspp_sheet_view_get_headers_visible (tree_view))
9108 gdk_window_show (tree_view->priv->header_window);
9111 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9113 tree_view->priv->n_columns++;
9115 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9117 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9121 _pspp_sheet_view_column_realize_button (column);
9123 for (list = tree_view->priv->columns; list; list = list->next)
9125 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9126 if (column->visible)
9127 _pspp_sheet_view_column_cell_set_dirty (column);
9129 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9132 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9134 return tree_view->priv->n_columns;
9138 * pspp_sheet_view_insert_column_with_attributes:
9139 * @tree_view: A #PsppSheetView
9140 * @position: The position to insert the new column in.
9141 * @title: The title to set the header to.
9142 * @cell: The #GtkCellRenderer.
9143 * @Varargs: A %NULL-terminated list of attributes.
9145 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9146 * @position. If @position is -1, then the newly created column is inserted at
9147 * the end. The column is initialized with the attributes given.
9149 * Return value: The number of columns in @tree_view after insertion.
9152 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9155 GtkCellRenderer *cell,
9158 PsppSheetViewColumn *column;
9163 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9165 column = pspp_sheet_view_column_new ();
9166 pspp_sheet_view_column_set_title (column, title);
9167 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9169 va_start (args, cell);
9171 attribute = va_arg (args, gchar *);
9173 while (attribute != NULL)
9175 column_id = va_arg (args, gint);
9176 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9177 attribute = va_arg (args, gchar *);
9182 pspp_sheet_view_insert_column (tree_view, column, position);
9184 return tree_view->priv->n_columns;
9188 * pspp_sheet_view_insert_column_with_data_func:
9189 * @tree_view: a #PsppSheetView
9190 * @position: Position to insert, -1 for append
9191 * @title: column title
9192 * @cell: cell renderer for column
9193 * @func: function to set attributes of cell renderer
9194 * @data: data for @func
9195 * @dnotify: destroy notifier for @data
9197 * Convenience function that inserts a new column into the #PsppSheetView
9198 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9199 * attributes (normally using data from the model). See also
9200 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9202 * Return value: number of columns in the tree view post-insert
9205 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9208 GtkCellRenderer *cell,
9209 PsppSheetCellDataFunc func,
9211 GDestroyNotify dnotify)
9213 PsppSheetViewColumn *column;
9215 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9217 column = pspp_sheet_view_column_new ();
9218 pspp_sheet_view_column_set_title (column, title);
9219 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9220 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9222 pspp_sheet_view_insert_column (tree_view, column, position);
9224 return tree_view->priv->n_columns;
9228 * pspp_sheet_view_get_column:
9229 * @tree_view: A #PsppSheetView.
9230 * @n: The position of the column, counting from 0.
9232 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9234 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9237 PsppSheetViewColumn *
9238 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9241 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9243 if (n < 0 || n >= tree_view->priv->n_columns)
9246 if (tree_view->priv->columns == NULL)
9249 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9253 * pspp_sheet_view_get_columns:
9254 * @tree_view: A #PsppSheetView
9256 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9257 * The returned list must be freed with g_list_free ().
9259 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9262 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9264 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9266 return g_list_copy (tree_view->priv->columns);
9270 * pspp_sheet_view_move_column_after:
9271 * @tree_view: A #PsppSheetView
9272 * @column: The #PsppSheetViewColumn to be moved.
9273 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9275 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9276 * @column is placed in the first position.
9279 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9280 PsppSheetViewColumn *column,
9281 PsppSheetViewColumn *base_column)
9283 GList *column_list_el, *base_el = NULL;
9285 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9287 column_list_el = g_list_find (tree_view->priv->columns, column);
9288 g_return_if_fail (column_list_el != NULL);
9292 base_el = g_list_find (tree_view->priv->columns, base_column);
9293 g_return_if_fail (base_el != NULL);
9296 if (column_list_el->prev == base_el)
9299 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9300 if (base_el == NULL)
9302 column_list_el->prev = NULL;
9303 column_list_el->next = tree_view->priv->columns;
9304 if (column_list_el->next)
9305 column_list_el->next->prev = column_list_el;
9306 tree_view->priv->columns = column_list_el;
9310 column_list_el->prev = base_el;
9311 column_list_el->next = base_el->next;
9312 if (column_list_el->next)
9313 column_list_el->next->prev = column_list_el;
9314 base_el->next = column_list_el;
9317 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9319 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9320 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9323 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9327 * pspp_sheet_view_set_column_drag_function:
9328 * @tree_view: A #PsppSheetView.
9329 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9330 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9331 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9333 * Sets a user function for determining where a column may be dropped when
9334 * dragged. This function is called on every column pair in turn at the
9335 * beginning of a column drag to determine where a drop can take place. The
9336 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9337 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9338 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9339 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9340 * @tree_view reverts to the default behavior of allowing all columns to be
9341 * dropped everywhere.
9344 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9345 PsppSheetViewColumnDropFunc func,
9347 GDestroyNotify destroy)
9349 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9351 if (tree_view->priv->column_drop_func_data_destroy)
9352 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9354 tree_view->priv->column_drop_func = func;
9355 tree_view->priv->column_drop_func_data = user_data;
9356 tree_view->priv->column_drop_func_data_destroy = destroy;
9360 * pspp_sheet_view_scroll_to_point:
9361 * @tree_view: a #PsppSheetView
9362 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9363 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9365 * Scrolls the tree view such that the top-left corner of the visible
9366 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9367 * in tree coordinates. The @tree_view must be realized before
9368 * this function is called. If it isn't, you probably want to be
9369 * using pspp_sheet_view_scroll_to_cell().
9371 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9374 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9378 GtkAdjustment *hadj;
9379 GtkAdjustment *vadj;
9381 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9382 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9384 hadj = tree_view->priv->hadjustment;
9385 vadj = tree_view->priv->vadjustment;
9388 gtk_adjustment_set_value (hadj, CLAMP (tree_x, hadj->lower, hadj->upper - hadj->page_size));
9390 gtk_adjustment_set_value (vadj, CLAMP (tree_y, vadj->lower, vadj->upper - vadj->page_size));
9394 * pspp_sheet_view_scroll_to_cell:
9395 * @tree_view: A #PsppSheetView.
9396 * @path: (allow-none): The path of the row to move to, or %NULL.
9397 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9398 * @use_align: whether to use alignment arguments, or %FALSE.
9399 * @row_align: The vertical alignment of the row specified by @path.
9400 * @col_align: The horizontal alignment of the column specified by @column.
9402 * Moves the alignments of @tree_view to the position specified by @column and
9403 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9404 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9405 * or @path need to be non-%NULL. @row_align determines where the row is
9406 * placed, and @col_align determines where @column is placed. Both are expected
9407 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9408 * right/bottom alignment, 0.5 means center.
9410 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9411 * tree does the minimum amount of work to scroll the cell onto the screen.
9412 * This means that the cell will be scrolled to the edge closest to its current
9413 * position. If the cell is currently visible on the screen, nothing is done.
9415 * This function only works if the model is set, and @path is a valid row on the
9416 * model. If the model changes before the @tree_view is realized, the centered
9417 * path will be modified to reflect this change.
9420 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9422 PsppSheetViewColumn *column,
9427 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9428 g_return_if_fail (tree_view->priv->model != NULL);
9429 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9430 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9431 g_return_if_fail (path != NULL || column != NULL);
9434 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9435 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9437 row_align = CLAMP (row_align, 0.0, 1.0);
9438 col_align = CLAMP (col_align, 0.0, 1.0);
9441 /* Note: Despite the benefits that come from having one code path for the
9442 * scrolling code, we short-circuit validate_visible_area's immplementation as
9443 * it is much slower than just going to the point.
9445 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9446 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9447 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9449 if (tree_view->priv->scroll_to_path)
9450 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9452 tree_view->priv->scroll_to_path = NULL;
9453 tree_view->priv->scroll_to_column = NULL;
9456 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9458 tree_view->priv->scroll_to_column = column;
9459 tree_view->priv->scroll_to_use_align = use_align;
9460 tree_view->priv->scroll_to_row_align = row_align;
9461 tree_view->priv->scroll_to_col_align = col_align;
9463 install_presize_handler (tree_view);
9467 GdkRectangle cell_rect;
9468 GdkRectangle vis_rect;
9469 gint dest_x, dest_y;
9471 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9472 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9474 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9476 dest_x = vis_rect.x;
9477 dest_y = vis_rect.y;
9483 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9487 if (cell_rect.x < vis_rect.x)
9488 dest_x = cell_rect.x;
9489 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9490 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9498 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9499 dest_y = MAX (dest_y, 0);
9503 if (cell_rect.y < vis_rect.y)
9504 dest_y = cell_rect.y;
9505 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9506 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9510 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9515 * pspp_sheet_view_row_activated:
9516 * @tree_view: A #PsppSheetView
9517 * @path: The #GtkTreePath to be activated.
9518 * @column: The #PsppSheetViewColumn to be activated.
9520 * Activates the cell determined by @path and @column.
9523 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9525 PsppSheetViewColumn *column)
9527 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9529 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
9534 * pspp_sheet_view_get_reorderable:
9535 * @tree_view: a #PsppSheetView
9537 * Retrieves whether the user can reorder the tree via drag-and-drop. See
9538 * pspp_sheet_view_set_reorderable().
9540 * Return value: %TRUE if the tree can be reordered.
9543 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
9545 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9547 return tree_view->priv->reorderable;
9551 * pspp_sheet_view_set_reorderable:
9552 * @tree_view: A #PsppSheetView.
9553 * @reorderable: %TRUE, if the tree can be reordered.
9555 * This function is a convenience function to allow you to reorder
9556 * models that support the #GtkDragSourceIface and the
9557 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
9558 * these. If @reorderable is %TRUE, then the user can reorder the
9559 * model by dragging and dropping rows. The developer can listen to
9560 * these changes by connecting to the model's row_inserted and
9561 * row_deleted signals. The reordering is implemented by setting up
9562 * the tree view as a drag source and destination. Therefore, drag and
9563 * drop can not be used in a reorderable view for any other purpose.
9565 * This function does not give you any degree of control over the order -- any
9566 * reordering is allowed. If more control is needed, you should probably
9567 * handle drag and drop manually.
9570 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
9571 gboolean reorderable)
9573 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9575 reorderable = reorderable != FALSE;
9577 if (tree_view->priv->reorderable == reorderable)
9582 const GtkTargetEntry row_targets[] = {
9583 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
9586 pspp_sheet_view_enable_model_drag_source (tree_view,
9589 G_N_ELEMENTS (row_targets),
9591 pspp_sheet_view_enable_model_drag_dest (tree_view,
9593 G_N_ELEMENTS (row_targets),
9598 pspp_sheet_view_unset_rows_drag_source (tree_view);
9599 pspp_sheet_view_unset_rows_drag_dest (tree_view);
9602 tree_view->priv->reorderable = reorderable;
9604 g_object_notify (G_OBJECT (tree_view), "reorderable");
9607 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
9608 is pressed, other rows will be unselected.
9610 If CLAMP_NODE is true, then the sheetview will scroll to make the row
9613 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
9615 gboolean clear_and_select,
9616 gboolean clamp_node)
9620 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9622 GtkTreePath *cursor_path;
9623 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9624 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
9625 gtk_tree_path_free (cursor_path);
9628 gtk_tree_row_reference_free (tree_view->priv->cursor);
9629 tree_view->priv->cursor = NULL;
9631 _pspp_sheet_view_find_node (tree_view, path, &node);
9632 tree_view->priv->cursor =
9633 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
9634 tree_view->priv->model,
9637 if (tree_view->priv->row_count > 0)
9641 if (clear_and_select && !tree_view->priv->ctrl_pressed)
9643 GtkTreeSelectMode mode = 0;
9645 if (tree_view->priv->ctrl_pressed)
9646 mode |= GTK_TREE_SELECT_MODE_TOGGLE;
9647 if (tree_view->priv->shift_pressed)
9648 mode |= GTK_TREE_SELECT_MODE_EXTEND;
9650 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
9655 /* We have to re-find tree and node here again, somebody might have
9656 * cleared the node or the whole tree in the PsppSheetSelection::changed
9657 * callback. If the nodes differ we bail out here.
9659 _pspp_sheet_view_find_node (tree_view, path, &new_node);
9661 if (node != new_node)
9666 pspp_sheet_view_clamp_node_visible (tree_view, node);
9667 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
9671 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
9675 * pspp_sheet_view_get_cursor:
9676 * @tree_view: A #PsppSheetView
9677 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
9678 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
9680 * Fills in @path and @focus_column with the current path and focus column. If
9681 * the cursor isn't currently set, then *@path will be %NULL. If no column
9682 * currently has focus, then *@focus_column will be %NULL.
9684 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
9685 * you are done with it.
9688 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
9690 PsppSheetViewColumn **focus_column)
9692 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9696 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9697 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9704 *focus_column = tree_view->priv->focus_column;
9709 * pspp_sheet_view_set_cursor:
9710 * @tree_view: A #PsppSheetView
9711 * @path: A #GtkTreePath
9712 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9713 * @start_editing: %TRUE if the specified cell should start being edited.
9715 * Sets the current keyboard focus to be at @path, and selects it. This is
9716 * useful when you want to focus the user's attention on a particular row. If
9717 * @focus_column is not %NULL, then focus is given to the column specified by
9718 * it. Additionally, if @focus_column is specified, and @start_editing is
9719 * %TRUE, then editing should be started in the specified cell.
9720 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
9721 * in order to give keyboard focus to the widget. Please note that editing
9722 * can only happen when the widget is realized.
9724 * If @path is invalid for @model, the current cursor (if any) will be unset
9725 * and the function will return without failing.
9728 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
9730 PsppSheetViewColumn *focus_column,
9731 gboolean start_editing)
9733 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
9734 NULL, start_editing);
9738 * pspp_sheet_view_set_cursor_on_cell:
9739 * @tree_view: A #PsppSheetView
9740 * @path: A #GtkTreePath
9741 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9742 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
9743 * @start_editing: %TRUE if the specified cell should start being edited.
9745 * Sets the current keyboard focus to be at @path, and selects it. This is
9746 * useful when you want to focus the user's attention on a particular row. If
9747 * @focus_column is not %NULL, then focus is given to the column specified by
9748 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
9749 * contains 2 or more editable or activatable cells, then focus is given to
9750 * the cell specified by @focus_cell. Additionally, if @focus_column is
9751 * specified, and @start_editing is %TRUE, then editing should be started in
9752 * the specified cell. This function is often followed by
9753 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
9754 * widget. Please note that editing can only happen when the widget is
9757 * If @path is invalid for @model, the current cursor (if any) will be unset
9758 * and the function will return without failing.
9763 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
9765 PsppSheetViewColumn *focus_column,
9766 GtkCellRenderer *focus_cell,
9767 gboolean start_editing)
9769 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9770 g_return_if_fail (path != NULL);
9771 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
9773 if (!tree_view->priv->model)
9778 g_return_if_fail (focus_column);
9779 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
9782 /* cancel the current editing, if it exists */
9783 if (tree_view->priv->edited_column &&
9784 tree_view->priv->edited_column->editable_widget)
9785 pspp_sheet_view_stop_editing (tree_view, TRUE);
9787 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
9789 if (focus_column && focus_column->visible)
9792 gboolean column_in_tree = FALSE;
9794 for (list = tree_view->priv->columns; list; list = list->next)
9795 if (list->data == focus_column)
9797 column_in_tree = TRUE;
9800 g_return_if_fail (column_in_tree);
9801 tree_view->priv->focus_column = focus_column;
9803 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
9805 pspp_sheet_view_start_editing (tree_view, path);
9807 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
9808 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
9814 * pspp_sheet_view_get_bin_window:
9815 * @tree_view: A #PsppSheetView
9817 * Returns the window that @tree_view renders to. This is used primarily to
9818 * compare to <literal>event->window</literal> to confirm that the event on
9819 * @tree_view is on the right window.
9821 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
9824 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
9826 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9828 return tree_view->priv->bin_window;
9832 * pspp_sheet_view_get_path_at_pos:
9833 * @tree_view: A #PsppSheetView.
9834 * @x: The x position to be identified (relative to bin_window).
9835 * @y: The y position to be identified (relative to bin_window).
9836 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
9837 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
9838 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
9839 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
9841 * Finds the path at the point (@x, @y), relative to bin_window coordinates
9842 * (please see pspp_sheet_view_get_bin_window()).
9843 * That is, @x and @y are relative to an events coordinates. @x and @y must
9844 * come from an event on the @tree_view only where <literal>event->window ==
9845 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
9846 * things like popup menus. If @path is non-%NULL, then it will be filled
9847 * with the #GtkTreePath at that point. This path should be freed with
9848 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
9849 * with the column at that point. @cell_x and @cell_y return the coordinates
9850 * relative to the cell background (i.e. the @background_area passed to
9851 * gtk_cell_renderer_render()). This function is only meaningful if
9852 * @tree_view is realized. Therefore this function will always return %FALSE
9853 * if @tree_view is not realized or does not have a model.
9855 * For converting widget coordinates (eg. the ones you get from
9856 * GtkWidget::query-tooltip), please see
9857 * pspp_sheet_view_convert_widget_to_bin_window_coords().
9859 * Return value: %TRUE if a row exists at that coordinate.
9862 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
9866 PsppSheetViewColumn **column,
9873 g_return_val_if_fail (tree_view != NULL, FALSE);
9880 if (tree_view->priv->bin_window == NULL)
9883 if (tree_view->priv->row_count == 0)
9886 if (x > tree_view->priv->hadjustment->upper)
9892 if (column || cell_x)
9894 PsppSheetViewColumn *tmp_column;
9895 PsppSheetViewColumn *last_column = NULL;
9897 gint remaining_x = x;
9898 gboolean found = FALSE;
9901 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
9902 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
9904 list = (rtl ? list->prev : list->next))
9906 tmp_column = list->data;
9908 if (tmp_column->visible == FALSE)
9911 last_column = tmp_column;
9912 if (remaining_x <= tmp_column->width)
9917 *column = tmp_column;
9920 *cell_x = remaining_x;
9924 remaining_x -= tmp_column->width;
9927 /* If found is FALSE and there is a last_column, then it the remainder
9928 * space is in that area
9935 *column = last_column;
9938 *cell_x = last_column->width + remaining_x;
9947 y_offset = pspp_sheet_view_find_offset (tree_view,
9948 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
9958 *path = _pspp_sheet_view_find_path (tree_view, node);
9963 /* Computes 'cell_area' from 'background_area', which must be the background
9964 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
9965 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
9966 the cell area as passed to _pspp_sheet_view_column_cell_render().
9968 'column' is required to properly adjust 'cell_area->x' and
9969 'cell_area->width'. It may be set to NULL if these values are not of
9970 interest. In this case 'cell_area->x' and 'cell_area->width' will be
9973 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
9974 PsppSheetViewColumn *column,
9975 const GdkRectangle *background_area,
9976 gboolean subtract_focus_rect,
9977 GdkRectangle *cell_area)
9979 gint vertical_separator;
9980 gint horizontal_separator;
9982 *cell_area = *background_area;
9984 gtk_widget_style_get (GTK_WIDGET (tree_view),
9985 "vertical-separator", &vertical_separator,
9986 "horizontal-separator", &horizontal_separator,
9988 cell_area->x += horizontal_separator / 2;
9989 cell_area->y += vertical_separator / 2;
9990 cell_area->width -= horizontal_separator;
9991 cell_area->height -= vertical_separator;
9993 if (subtract_focus_rect)
9995 int focus_line_width;
9997 gtk_widget_style_get (GTK_WIDGET (tree_view),
9998 "focus-line-width", &focus_line_width,
10000 cell_area->x += focus_line_width;
10001 cell_area->y += focus_line_width;
10002 cell_area->width -= 2 * focus_line_width;
10003 cell_area->height -= 2 * focus_line_width;
10006 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10008 gint grid_line_width;
10009 gtk_widget_style_get (GTK_WIDGET (tree_view),
10010 "grid-line-width", &grid_line_width,
10013 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10014 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10017 PsppSheetViewColumn *first_column, *last_column;
10020 /* Find the last visible column. */
10021 last_column = NULL;
10022 for (list = g_list_last (tree_view->priv->columns);
10026 PsppSheetViewColumn *c = list->data;
10034 /* Find the first visible column. */
10035 first_column = NULL;
10036 for (list = g_list_first (tree_view->priv->columns);
10040 PsppSheetViewColumn *c = list->data;
10048 if (column == first_column)
10050 cell_area->width -= grid_line_width / 2;
10052 else if (column == last_column)
10054 cell_area->x += grid_line_width / 2;
10055 cell_area->width -= grid_line_width / 2;
10059 cell_area->x += grid_line_width / 2;
10060 cell_area->width -= grid_line_width;
10064 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10065 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10067 cell_area->y += grid_line_width / 2;
10068 cell_area->height -= grid_line_width;
10072 if (column == NULL)
10075 cell_area->width = 0;
10080 * pspp_sheet_view_get_cell_area:
10081 * @tree_view: a #PsppSheetView
10082 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10083 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10084 * @rect: rectangle to fill with cell rect
10086 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10087 * row specified by @path and the column specified by @column. If @path is
10088 * %NULL, or points to a path not currently displayed, the @y and @height fields
10089 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10090 * fields will be filled with 0. The sum of all cell rects does not cover the
10091 * entire tree; there are extra pixels in between rows, for example. The
10092 * returned rectangle is equivalent to the @cell_area passed to
10093 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10097 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10099 PsppSheetViewColumn *column,
10100 GdkRectangle *rect)
10102 GdkRectangle background_area;
10104 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10105 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10106 g_return_if_fail (rect != NULL);
10107 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10108 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10110 pspp_sheet_view_get_background_area (tree_view, path, column,
10112 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10117 * pspp_sheet_view_get_background_area:
10118 * @tree_view: a #PsppSheetView
10119 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10120 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10121 * @rect: rectangle to fill with cell background rect
10123 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10124 * row specified by @path and the column specified by @column. If @path is
10125 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10126 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10127 * fields will be filled with 0. The returned rectangle is equivalent to the
10128 * @background_area passed to gtk_cell_renderer_render(). These background
10129 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10130 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10131 * itself, excluding surrounding borders.
10135 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10137 PsppSheetViewColumn *column,
10138 GdkRectangle *rect)
10142 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10143 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10144 g_return_if_fail (rect != NULL);
10153 /* Get vertical coords */
10155 _pspp_sheet_view_find_node (tree_view, path, &node);
10159 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10161 rect->height = ROW_HEIGHT (tree_view);
10168 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10169 rect->width = x2 - rect->x;
10174 * pspp_sheet_view_get_visible_rect:
10175 * @tree_view: a #PsppSheetView
10176 * @visible_rect: rectangle to fill
10178 * Fills @visible_rect with the currently-visible region of the
10179 * buffer, in tree coordinates. Convert to bin_window coordinates with
10180 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10181 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10182 * scrollable area of the tree.
10185 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10186 GdkRectangle *visible_rect)
10190 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10192 widget = GTK_WIDGET (tree_view);
10196 visible_rect->x = tree_view->priv->hadjustment->value;
10197 visible_rect->y = tree_view->priv->vadjustment->value;
10198 visible_rect->width = widget->allocation.width;
10199 visible_rect->height = widget->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10204 * pspp_sheet_view_widget_to_tree_coords:
10205 * @tree_view: a #PsppSheetView
10206 * @wx: X coordinate relative to bin_window
10207 * @wy: Y coordinate relative to bin_window
10208 * @tx: return location for tree X coordinate
10209 * @ty: return location for tree Y coordinate
10211 * Converts bin_window coordinates to coordinates for the
10212 * tree (the full scrollable area of the tree).
10214 * Deprecated: 2.12: Due to historial reasons the name of this function is
10215 * incorrect. For converting coordinates relative to the widget to
10216 * bin_window coordinates, please see
10217 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10221 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10227 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10230 *tx = wx + tree_view->priv->hadjustment->value;
10232 *ty = wy + tree_view->priv->dy;
10236 * pspp_sheet_view_tree_to_widget_coords:
10237 * @tree_view: a #PsppSheetView
10238 * @tx: tree X coordinate
10239 * @ty: tree Y coordinate
10240 * @wx: return location for X coordinate relative to bin_window
10241 * @wy: return location for Y coordinate relative to bin_window
10243 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10244 * to bin_window coordinates.
10246 * Deprecated: 2.12: Due to historial reasons the name of this function is
10247 * incorrect. For converting bin_window coordinates to coordinates relative
10248 * to bin_window, please see
10249 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10253 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10259 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10262 *wx = tx - tree_view->priv->hadjustment->value;
10264 *wy = ty - tree_view->priv->dy;
10269 * pspp_sheet_view_convert_widget_to_tree_coords:
10270 * @tree_view: a #PsppSheetView
10271 * @wx: X coordinate relative to the widget
10272 * @wy: Y coordinate relative to the widget
10273 * @tx: return location for tree X coordinate
10274 * @ty: return location for tree Y coordinate
10276 * Converts widget coordinates to coordinates for the
10277 * tree (the full scrollable area of the tree).
10282 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10290 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10292 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10295 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10301 * pspp_sheet_view_convert_tree_to_widget_coords:
10302 * @tree_view: a #PsppSheetView
10303 * @tx: X coordinate relative to the tree
10304 * @ty: Y coordinate relative to the tree
10305 * @wx: return location for widget X coordinate
10306 * @wy: return location for widget Y coordinate
10308 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10309 * to widget coordinates.
10314 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10322 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10324 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10327 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10333 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10334 * @tree_view: a #PsppSheetView
10335 * @wx: X coordinate relative to the widget
10336 * @wy: Y coordinate relative to the widget
10337 * @bx: return location for bin_window X coordinate
10338 * @by: return location for bin_window Y coordinate
10340 * Converts widget coordinates to coordinates for the bin_window
10341 * (see pspp_sheet_view_get_bin_window()).
10346 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10352 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10355 *bx = wx + tree_view->priv->hadjustment->value;
10357 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10361 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10362 * @tree_view: a #PsppSheetView
10363 * @bx: bin_window X coordinate
10364 * @by: bin_window Y coordinate
10365 * @wx: return location for widget X coordinate
10366 * @wy: return location for widget Y coordinate
10368 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10369 * to widget relative coordinates.
10374 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10380 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10383 *wx = bx - tree_view->priv->hadjustment->value;
10385 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10389 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10390 * @tree_view: a #PsppSheetView
10391 * @tx: tree X coordinate
10392 * @ty: tree Y coordinate
10393 * @bx: return location for X coordinate relative to bin_window
10394 * @by: return location for Y coordinate relative to bin_window
10396 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10397 * to bin_window coordinates.
10402 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10408 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10413 *by = ty - tree_view->priv->dy;
10417 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10418 * @tree_view: a #PsppSheetView
10419 * @bx: X coordinate relative to bin_window
10420 * @by: Y coordinate relative to bin_window
10421 * @tx: return location for tree X coordinate
10422 * @ty: return location for tree Y coordinate
10424 * Converts bin_window coordinates to coordinates for the
10425 * tree (the full scrollable area of the tree).
10430 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10436 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10441 *ty = by + tree_view->priv->dy;
10447 * pspp_sheet_view_get_visible_range:
10448 * @tree_view: A #PsppSheetView
10449 * @start_path: (allow-none): Return location for start of region, or %NULL.
10450 * @end_path: (allow-none): Return location for end of region, or %NULL.
10452 * Sets @start_path and @end_path to be the first and last visible path.
10453 * Note that there may be invisible paths in between.
10455 * The paths should be freed with gtk_tree_path_free() after use.
10457 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10462 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10463 GtkTreePath **start_path,
10464 GtkTreePath **end_path)
10469 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10471 if (!tree_view->priv->row_count)
10478 pspp_sheet_view_find_offset (tree_view,
10479 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10482 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10491 if (tree_view->priv->height < tree_view->priv->vadjustment->page_size)
10492 y = tree_view->priv->height - 1;
10494 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, tree_view->priv->vadjustment->page_size) - 1;
10496 pspp_sheet_view_find_offset (tree_view, y, &node);
10498 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10507 unset_reorderable (PsppSheetView *tree_view)
10509 if (tree_view->priv->reorderable)
10511 tree_view->priv->reorderable = FALSE;
10512 g_object_notify (G_OBJECT (tree_view), "reorderable");
10517 * pspp_sheet_view_enable_model_drag_source:
10518 * @tree_view: a #PsppSheetView
10519 * @start_button_mask: Mask of allowed buttons to start drag
10520 * @targets: the table of targets that the drag will support
10521 * @n_targets: the number of items in @targets
10522 * @actions: the bitmask of possible actions for a drag from this
10525 * Turns @tree_view into a drag source for automatic DND. Calling this
10526 * method sets #PsppSheetView:reorderable to %FALSE.
10529 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10530 GdkModifierType start_button_mask,
10531 const GtkTargetEntry *targets,
10533 GdkDragAction actions)
10535 TreeViewDragInfo *di;
10537 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10539 gtk_drag_source_set (GTK_WIDGET (tree_view),
10545 di = ensure_info (tree_view);
10547 di->start_button_mask = start_button_mask;
10548 di->source_actions = actions;
10549 di->source_set = TRUE;
10551 unset_reorderable (tree_view);
10555 * pspp_sheet_view_enable_model_drag_dest:
10556 * @tree_view: a #PsppSheetView
10557 * @targets: the table of targets that the drag will support
10558 * @n_targets: the number of items in @targets
10559 * @actions: the bitmask of possible actions for a drag from this
10562 * Turns @tree_view into a drop destination for automatic DND. Calling
10563 * this method sets #PsppSheetView:reorderable to %FALSE.
10566 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
10567 const GtkTargetEntry *targets,
10569 GdkDragAction actions)
10571 TreeViewDragInfo *di;
10573 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10575 gtk_drag_dest_set (GTK_WIDGET (tree_view),
10581 di = ensure_info (tree_view);
10582 di->dest_set = TRUE;
10584 unset_reorderable (tree_view);
10588 * pspp_sheet_view_unset_rows_drag_source:
10589 * @tree_view: a #PsppSheetView
10591 * Undoes the effect of
10592 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
10593 * #PsppSheetView:reorderable to %FALSE.
10596 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
10598 TreeViewDragInfo *di;
10600 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10602 di = get_info (tree_view);
10606 if (di->source_set)
10608 gtk_drag_source_unset (GTK_WIDGET (tree_view));
10609 di->source_set = FALSE;
10612 if (!di->dest_set && !di->source_set)
10613 remove_info (tree_view);
10616 unset_reorderable (tree_view);
10620 * pspp_sheet_view_unset_rows_drag_dest:
10621 * @tree_view: a #PsppSheetView
10623 * Undoes the effect of
10624 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
10625 * #PsppSheetView:reorderable to %FALSE.
10628 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
10630 TreeViewDragInfo *di;
10632 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10634 di = get_info (tree_view);
10640 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
10641 di->dest_set = FALSE;
10644 if (!di->dest_set && !di->source_set)
10645 remove_info (tree_view);
10648 unset_reorderable (tree_view);
10652 * pspp_sheet_view_set_drag_dest_row:
10653 * @tree_view: a #PsppSheetView
10654 * @path: (allow-none): The path of the row to highlight, or %NULL.
10655 * @pos: Specifies whether to drop before, after or into the row
10657 * Sets the row that is highlighted for feedback.
10660 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
10662 PsppSheetViewDropPosition pos)
10664 GtkTreePath *current_dest;
10666 /* Note; this function is exported to allow a custom DND
10667 * implementation, so it can't touch TreeViewDragInfo
10670 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10672 current_dest = NULL;
10674 if (tree_view->priv->drag_dest_row)
10676 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10677 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
10680 /* special case a drop on an empty model */
10681 tree_view->priv->empty_view_drop = 0;
10683 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
10684 && gtk_tree_path_get_depth (path) == 1
10685 && gtk_tree_path_get_indices (path)[0] == 0)
10689 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
10693 tree_view->priv->empty_view_drop = 1;
10696 tree_view->priv->drag_dest_pos = pos;
10700 tree_view->priv->drag_dest_row =
10701 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
10702 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
10705 tree_view->priv->drag_dest_row = NULL;
10709 int node, new_node;
10711 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
10712 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10716 new_node = pspp_sheet_view_node_next (tree_view, node);
10718 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
10720 new_node = pspp_sheet_view_node_prev (tree_view, node);
10722 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
10724 gtk_tree_path_free (current_dest);
10729 * pspp_sheet_view_get_drag_dest_row:
10730 * @tree_view: a #PsppSheetView
10731 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
10732 * @pos: (allow-none): Return location for the drop position, or %NULL
10734 * Gets information about the row that is highlighted for feedback.
10737 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
10738 GtkTreePath **path,
10739 PsppSheetViewDropPosition *pos)
10741 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10745 if (tree_view->priv->drag_dest_row)
10746 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10749 if (tree_view->priv->empty_view_drop)
10750 *path = gtk_tree_path_new_from_indices (0, -1);
10757 *pos = tree_view->priv->drag_dest_pos;
10761 * pspp_sheet_view_get_dest_row_at_pos:
10762 * @tree_view: a #PsppSheetView
10763 * @drag_x: the position to determine the destination row for
10764 * @drag_y: the position to determine the destination row for
10765 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
10766 * @pos: (allow-none): Return location for the drop position, or %NULL
10768 * Determines the destination row for a given position. @drag_x and
10769 * @drag_y are expected to be in widget coordinates. This function is only
10770 * meaningful if @tree_view is realized. Therefore this function will always
10771 * return %FALSE if @tree_view is not realized or does not have a model.
10773 * Return value: whether there is a row at the given position, %TRUE if this
10774 * is indeed the case.
10777 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
10780 GtkTreePath **path,
10781 PsppSheetViewDropPosition *pos)
10785 gdouble offset_into_row;
10788 PsppSheetViewColumn *column = NULL;
10789 GtkTreePath *tmp_path = NULL;
10791 /* Note; this function is exported to allow a custom DND
10792 * implementation, so it can't touch TreeViewDragInfo
10795 g_return_val_if_fail (tree_view != NULL, FALSE);
10796 g_return_val_if_fail (drag_x >= 0, FALSE);
10797 g_return_val_if_fail (drag_y >= 0, FALSE);
10802 if (tree_view->priv->bin_window == NULL)
10805 if (tree_view->priv->row_count == 0)
10808 /* If in the top third of a row, we drop before that row; if
10809 * in the bottom third, drop after that row; if in the middle,
10810 * and the row has children, drop into the row.
10812 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
10815 if (!pspp_sheet_view_get_path_at_pos (tree_view,
10824 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
10827 offset_into_row = cell_y;
10832 gtk_tree_path_free (tmp_path);
10836 third = cell.height / 3.0;
10840 if (offset_into_row < third)
10842 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
10844 else if (offset_into_row < (cell.height / 2.0))
10846 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
10848 else if (offset_into_row < third * 2.0)
10850 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
10854 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
10863 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
10865 * pspp_sheet_view_create_row_drag_icon:
10866 * @tree_view: a #PsppSheetView
10867 * @path: a #GtkTreePath in @tree_view
10869 * Creates a #GdkPixmap representation of the row at @path.
10870 * This image is used for a drag icon.
10872 * Return value: a newly-allocated pixmap of the drag icon.
10875 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
10882 GdkRectangle background_area;
10883 GdkRectangle expose_area;
10886 /* start drawing inside the black outline */
10888 GdkDrawable *drawable;
10889 gint bin_window_width;
10892 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
10893 g_return_val_if_fail (path != NULL, NULL);
10895 widget = GTK_WIDGET (tree_view);
10897 if (!gtk_widget_get_realized (widget))
10900 depth = gtk_tree_path_get_depth (path);
10902 _pspp_sheet_view_find_node (tree_view,
10909 if (!gtk_tree_model_get_iter (tree_view->priv->model,
10916 background_area.y = y;
10917 background_area.height = ROW_HEIGHT (tree_view);
10919 gdk_drawable_get_size (tree_view->priv->bin_window,
10920 &bin_window_width, NULL);
10922 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
10923 bin_window_width + 2,
10924 background_area.height + 2,
10929 expose_area.width = bin_window_width + 2;
10930 expose_area.height = background_area.height + 2;
10932 gdk_draw_rectangle (drawable,
10933 widget->style->base_gc [gtk_widget_get_state (widget)],
10936 bin_window_width + 2,
10937 background_area.height + 2);
10939 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
10941 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10943 list = (rtl ? list->prev : list->next))
10945 PsppSheetViewColumn *column = list->data;
10946 GdkRectangle cell_area;
10947 gint vertical_separator;
10949 if (!column->visible)
10952 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
10954 background_area.x = cell_offset;
10955 background_area.width = column->width;
10957 gtk_widget_style_get (widget,
10958 "vertical-separator", &vertical_separator,
10961 cell_area = background_area;
10963 cell_area.y += vertical_separator / 2;
10964 cell_area.height -= vertical_separator;
10966 if (pspp_sheet_view_column_cell_is_visible (column))
10967 _pspp_sheet_view_column_cell_render (column,
10973 cell_offset += column->width;
10976 gdk_draw_rectangle (drawable,
10977 widget->style->black_gc,
10980 bin_window_width + 1,
10981 background_area.height + 1);
10988 * pspp_sheet_view_set_destroy_count_func:
10989 * @tree_view: A #PsppSheetView
10990 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
10991 * @data: (allow-none): User data to be passed to @func, or %NULL
10992 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
10994 * This function should almost never be used. It is meant for private use by
10995 * ATK for determining the number of visible children that are removed when a row is deleted.
10998 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
10999 PsppSheetDestroyCountFunc func,
11001 GDestroyNotify destroy)
11003 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11005 if (tree_view->priv->destroy_count_destroy)
11006 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11008 tree_view->priv->destroy_count_func = func;
11009 tree_view->priv->destroy_count_data = data;
11010 tree_view->priv->destroy_count_destroy = destroy;
11015 * Interactive search
11019 * pspp_sheet_view_set_enable_search:
11020 * @tree_view: A #PsppSheetView
11021 * @enable_search: %TRUE, if the user can search interactively
11023 * If @enable_search is set, then the user can type in text to search through
11024 * the tree interactively (this is sometimes called "typeahead find").
11026 * Note that even if this is %FALSE, the user can still initiate a search
11027 * using the "start-interactive-search" key binding.
11030 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11031 gboolean enable_search)
11033 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11035 enable_search = !!enable_search;
11037 if (tree_view->priv->enable_search != enable_search)
11039 tree_view->priv->enable_search = enable_search;
11040 g_object_notify (G_OBJECT (tree_view), "enable-search");
11045 * pspp_sheet_view_get_enable_search:
11046 * @tree_view: A #PsppSheetView
11048 * Returns whether or not the tree allows to start interactive searching
11049 * by typing in text.
11051 * Return value: whether or not to let the user search interactively
11054 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11056 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11058 return tree_view->priv->enable_search;
11063 * pspp_sheet_view_get_search_column:
11064 * @tree_view: A #PsppSheetView
11066 * Gets the column searched on by the interactive search code.
11068 * Return value: the column the interactive search code searches in.
11071 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11073 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11075 return (tree_view->priv->search_column);
11079 * pspp_sheet_view_set_search_column:
11080 * @tree_view: A #PsppSheetView
11081 * @column: the column of the model to search in, or -1 to disable searching
11083 * Sets @column as the column where the interactive search code should
11084 * search in for the current model.
11086 * If the search column is set, users can use the "start-interactive-search"
11087 * key binding to bring up search popup. The enable-search property controls
11088 * whether simply typing text will also start an interactive search.
11090 * Note that @column refers to a column of the current model. The search
11091 * column is reset to -1 when the model is changed.
11094 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11097 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11098 g_return_if_fail (column >= -1);
11100 if (tree_view->priv->search_column == column)
11103 tree_view->priv->search_column = column;
11104 g_object_notify (G_OBJECT (tree_view), "search-column");
11108 * pspp_sheet_view_get_search_equal_func:
11109 * @tree_view: A #PsppSheetView
11111 * Returns the compare function currently in use.
11113 * Return value: the currently used compare function for the search code.
11116 PsppSheetViewSearchEqualFunc
11117 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11119 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11121 return tree_view->priv->search_equal_func;
11125 * pspp_sheet_view_set_search_equal_func:
11126 * @tree_view: A #PsppSheetView
11127 * @search_equal_func: the compare function to use during the search
11128 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11129 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11131 * Sets the compare function for the interactive search capabilities; note
11132 * that somewhat like strcmp() returning 0 for equality
11133 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11136 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11137 PsppSheetViewSearchEqualFunc search_equal_func,
11138 gpointer search_user_data,
11139 GDestroyNotify search_destroy)
11141 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11142 g_return_if_fail (search_equal_func != NULL);
11144 if (tree_view->priv->search_destroy)
11145 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11147 tree_view->priv->search_equal_func = search_equal_func;
11148 tree_view->priv->search_user_data = search_user_data;
11149 tree_view->priv->search_destroy = search_destroy;
11150 if (tree_view->priv->search_equal_func == NULL)
11151 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11155 * pspp_sheet_view_get_search_entry:
11156 * @tree_view: A #PsppSheetView
11158 * Returns the #GtkEntry which is currently in use as interactive search
11159 * entry for @tree_view. In case the built-in entry is being used, %NULL
11160 * will be returned.
11162 * Return value: the entry currently in use as search entry.
11167 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11169 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11171 if (tree_view->priv->search_custom_entry_set)
11172 return GTK_ENTRY (tree_view->priv->search_entry);
11178 * pspp_sheet_view_set_search_entry:
11179 * @tree_view: A #PsppSheetView
11180 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11182 * Sets the entry which the interactive search code will use for this
11183 * @tree_view. This is useful when you want to provide a search entry
11184 * in our interface at all time at a fixed position. Passing %NULL for
11185 * @entry will make the interactive search code use the built-in popup
11191 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11194 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11195 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11197 if (tree_view->priv->search_custom_entry_set)
11199 if (tree_view->priv->search_entry_changed_id)
11201 g_signal_handler_disconnect (tree_view->priv->search_entry,
11202 tree_view->priv->search_entry_changed_id);
11203 tree_view->priv->search_entry_changed_id = 0;
11205 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11206 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11209 g_object_unref (tree_view->priv->search_entry);
11211 else if (tree_view->priv->search_window)
11213 gtk_widget_destroy (tree_view->priv->search_window);
11215 tree_view->priv->search_window = NULL;
11220 tree_view->priv->search_entry = g_object_ref (entry);
11221 tree_view->priv->search_custom_entry_set = TRUE;
11223 if (tree_view->priv->search_entry_changed_id == 0)
11225 tree_view->priv->search_entry_changed_id =
11226 g_signal_connect (tree_view->priv->search_entry, "changed",
11227 G_CALLBACK (pspp_sheet_view_search_init),
11231 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11232 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11235 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11239 tree_view->priv->search_entry = NULL;
11240 tree_view->priv->search_custom_entry_set = FALSE;
11245 * pspp_sheet_view_set_search_position_func:
11246 * @tree_view: A #PsppSheetView
11247 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11248 * to use the default search position function
11249 * @data: (allow-none): user data to pass to @func, or %NULL
11250 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11252 * Sets the function to use when positioning the search dialog.
11257 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11258 PsppSheetViewSearchPositionFunc func,
11259 gpointer user_data,
11260 GDestroyNotify destroy)
11262 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11264 if (tree_view->priv->search_position_destroy)
11265 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11267 tree_view->priv->search_position_func = func;
11268 tree_view->priv->search_position_user_data = user_data;
11269 tree_view->priv->search_position_destroy = destroy;
11270 if (tree_view->priv->search_position_func == NULL)
11271 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11275 * pspp_sheet_view_get_search_position_func:
11276 * @tree_view: A #PsppSheetView
11278 * Returns the positioning function currently in use.
11280 * Return value: the currently used function for positioning the search dialog.
11284 PsppSheetViewSearchPositionFunc
11285 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11287 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11289 return tree_view->priv->search_position_func;
11294 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11295 PsppSheetView *tree_view)
11297 if (tree_view->priv->disable_popdown)
11300 if (tree_view->priv->search_entry_changed_id)
11302 g_signal_handler_disconnect (tree_view->priv->search_entry,
11303 tree_view->priv->search_entry_changed_id);
11304 tree_view->priv->search_entry_changed_id = 0;
11306 if (tree_view->priv->typeselect_flush_timeout)
11308 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11309 tree_view->priv->typeselect_flush_timeout = 0;
11312 if (gtk_widget_get_visible (search_dialog))
11314 /* send focus-in event */
11315 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11316 gtk_widget_hide (search_dialog);
11317 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11318 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11323 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11324 GtkWidget *search_dialog,
11325 gpointer user_data)
11328 gint tree_x, tree_y;
11329 gint tree_width, tree_height;
11330 GdkWindow *tree_window = GTK_WIDGET (tree_view)->window;
11331 GdkScreen *screen = gdk_drawable_get_screen (tree_window);
11332 GtkRequisition requisition;
11334 GdkRectangle monitor;
11336 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11337 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11339 gtk_widget_realize (search_dialog);
11341 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11342 gdk_drawable_get_size (tree_window,
11345 gtk_widget_size_request (search_dialog, &requisition);
11347 if (tree_x + tree_width > gdk_screen_get_width (screen))
11348 x = gdk_screen_get_width (screen) - requisition.width;
11349 else if (tree_x + tree_width - requisition.width < 0)
11352 x = tree_x + tree_width - requisition.width;
11354 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11355 y = gdk_screen_get_height (screen) - requisition.height;
11356 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11359 y = tree_y + tree_height;
11361 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11365 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11369 PsppSheetView *tree_view = (PsppSheetView *)data;
11371 tree_view->priv->disable_popdown = 1;
11372 g_signal_connect (menu, "hide",
11373 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11376 /* Because we're visible but offscreen, we just set a flag in the preedit
11380 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11381 PsppSheetView *tree_view)
11383 tree_view->priv->imcontext_changed = 1;
11384 if (tree_view->priv->typeselect_flush_timeout)
11386 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11387 tree_view->priv->typeselect_flush_timeout =
11388 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11389 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11396 pspp_sheet_view_search_activate (GtkEntry *entry,
11397 PsppSheetView *tree_view)
11402 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11405 /* If we have a row selected and it's the cursor row, we activate
11407 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11409 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11411 _pspp_sheet_view_find_node (tree_view, path, &node);
11413 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11414 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11416 gtk_tree_path_free (path);
11421 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11423 PsppSheetView *tree_view = (PsppSheetView *)data;
11425 tree_view->priv->disable_popdown = 0;
11431 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11434 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11438 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11439 GdkEventAny *event,
11440 PsppSheetView *tree_view)
11442 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11444 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11450 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11451 GdkEventButton *event,
11452 PsppSheetView *tree_view)
11454 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11456 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11458 if (event->window == tree_view->priv->bin_window)
11459 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11465 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11466 GdkEventScroll *event,
11467 PsppSheetView *tree_view)
11469 gboolean retval = FALSE;
11471 if (event->direction == GDK_SCROLL_UP)
11473 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11476 else if (event->direction == GDK_SCROLL_DOWN)
11478 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11482 /* renew the flush timeout */
11483 if (retval && tree_view->priv->typeselect_flush_timeout
11484 && !tree_view->priv->search_custom_entry_set)
11486 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11487 tree_view->priv->typeselect_flush_timeout =
11488 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11489 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11497 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11498 GdkEventKey *event,
11499 PsppSheetView *tree_view)
11501 gboolean retval = FALSE;
11503 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11504 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11506 /* close window and cancel the search */
11507 if (!tree_view->priv->search_custom_entry_set
11508 && (event->keyval == GDK_Escape ||
11509 event->keyval == GDK_Tab ||
11510 event->keyval == GDK_KP_Tab ||
11511 event->keyval == GDK_ISO_Left_Tab))
11513 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11517 /* select previous matching iter */
11518 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11520 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11521 gtk_widget_error_bell (widget);
11526 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11527 && (event->keyval == GDK_g || event->keyval == GDK_G))
11529 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11530 gtk_widget_error_bell (widget);
11535 /* select next matching iter */
11536 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
11538 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11539 gtk_widget_error_bell (widget);
11544 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
11545 && (event->keyval == GDK_g || event->keyval == GDK_G))
11547 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11548 gtk_widget_error_bell (widget);
11553 /* renew the flush timeout */
11554 if (retval && tree_view->priv->typeselect_flush_timeout
11555 && !tree_view->priv->search_custom_entry_set)
11557 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11558 tree_view->priv->typeselect_flush_timeout =
11559 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11560 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11567 /* this function returns FALSE if there is a search string but
11568 * nothing was found, and TRUE otherwise.
11571 pspp_sheet_view_search_move (GtkWidget *window,
11572 PsppSheetView *tree_view,
11580 GtkTreeModel *model;
11581 PsppSheetSelection *selection;
11583 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
11585 g_return_val_if_fail (text != NULL, FALSE);
11587 len = strlen (text);
11589 if (up && tree_view->priv->selected_iter == 1)
11590 return strlen (text) < 1;
11592 len = strlen (text);
11597 model = pspp_sheet_view_get_model (tree_view);
11598 selection = pspp_sheet_view_get_selection (tree_view);
11601 pspp_sheet_selection_unselect_all (selection);
11602 if (!gtk_tree_model_get_iter_first (model, &iter))
11605 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
11606 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
11611 tree_view->priv->selected_iter += up?(-1):(1);
11616 /* return to old iter */
11618 gtk_tree_model_get_iter_first (model, &iter);
11619 pspp_sheet_view_search_iter (model, selection,
11621 &count, tree_view->priv->selected_iter);
11627 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
11631 gpointer search_data)
11633 gboolean retval = TRUE;
11635 gchar *normalized_string;
11636 gchar *normalized_key;
11637 gchar *case_normalized_string = NULL;
11638 gchar *case_normalized_key = NULL;
11639 GValue value = {0,};
11640 GValue transformed = {0,};
11642 gtk_tree_model_get_value (model, iter, column, &value);
11644 g_value_init (&transformed, G_TYPE_STRING);
11646 if (!g_value_transform (&value, &transformed))
11648 g_value_unset (&value);
11652 g_value_unset (&value);
11654 str = g_value_get_string (&transformed);
11657 g_value_unset (&transformed);
11661 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
11662 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
11664 if (normalized_string && normalized_key)
11666 case_normalized_string = g_utf8_casefold (normalized_string, -1);
11667 case_normalized_key = g_utf8_casefold (normalized_key, -1);
11669 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
11673 g_value_unset (&transformed);
11674 g_free (normalized_key);
11675 g_free (normalized_string);
11676 g_free (case_normalized_key);
11677 g_free (case_normalized_string);
11683 pspp_sheet_view_search_iter (GtkTreeModel *model,
11684 PsppSheetSelection *selection,
11693 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
11695 path = gtk_tree_model_get_path (model, iter);
11696 _pspp_sheet_view_find_node (tree_view, path, &node);
11700 gboolean done = FALSE;
11702 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
11707 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
11709 pspp_sheet_selection_select_iter (selection, iter);
11710 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
11713 gtk_tree_path_free (path);
11722 node = pspp_sheet_view_node_next (tree_view, node);
11728 has_next = gtk_tree_model_iter_next (model, iter);
11731 gtk_tree_path_next (path);
11734 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
11739 gtk_tree_path_free (path);
11741 /* we've run out of tree, done with this func */
11753 pspp_sheet_view_search_init (GtkWidget *entry,
11754 PsppSheetView *tree_view)
11760 GtkTreeModel *model;
11761 PsppSheetSelection *selection;
11763 g_return_if_fail (GTK_IS_ENTRY (entry));
11764 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11766 text = gtk_entry_get_text (GTK_ENTRY (entry));
11768 model = pspp_sheet_view_get_model (tree_view);
11769 selection = pspp_sheet_view_get_selection (tree_view);
11772 pspp_sheet_selection_unselect_all (selection);
11773 if (tree_view->priv->typeselect_flush_timeout
11774 && !tree_view->priv->search_custom_entry_set)
11776 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11777 tree_view->priv->typeselect_flush_timeout =
11778 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11779 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11786 if (!gtk_tree_model_get_iter_first (model, &iter))
11789 ret = pspp_sheet_view_search_iter (model, selection,
11794 tree_view->priv->selected_iter = 1;
11798 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
11799 PsppSheetView *tree_view)
11801 if (tree_view->priv->edited_column == NULL)
11804 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
11805 tree_view->priv->edited_column = NULL;
11807 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
11808 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
11810 g_signal_handlers_disconnect_by_func (cell_editable,
11811 pspp_sheet_view_remove_widget,
11813 g_signal_handlers_disconnect_by_func (cell_editable,
11814 pspp_sheet_view_editable_button_press_event,
11816 g_signal_handlers_disconnect_by_func (cell_editable,
11817 pspp_sheet_view_editable_clicked,
11820 gtk_container_remove (GTK_CONTAINER (tree_view),
11821 GTK_WIDGET (cell_editable));
11823 /* FIXME should only redraw a single node */
11824 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
11828 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
11829 GtkTreePath *cursor_path)
11832 GdkRectangle background_area;
11833 GdkRectangle cell_area;
11834 GtkCellEditable *editable_widget = NULL;
11835 gchar *path_string;
11836 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
11837 gint retval = FALSE;
11840 g_assert (tree_view->priv->focus_column);
11842 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
11845 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
11846 if (cursor_node < 0)
11849 path_string = gtk_tree_path_to_string (cursor_path);
11850 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
11852 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
11853 tree_view->priv->model,
11855 pspp_sheet_view_get_background_area (tree_view,
11857 tree_view->priv->focus_column,
11859 pspp_sheet_view_get_cell_area (tree_view,
11861 tree_view->priv->focus_column,
11864 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
11873 if (editable_widget != NULL)
11877 GtkCellRenderer *cell;
11880 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
11882 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
11885 area.width -= right + left;
11887 pspp_sheet_view_real_start_editing (tree_view,
11888 tree_view->priv->focus_column,
11897 g_free (path_string);
11902 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
11903 GdkEventButton *event,
11904 PsppSheetView *sheet_view)
11908 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
11909 "pspp-sheet-view-node"));
11910 return pspp_sheet_view_row_head_clicked (sheet_view,
11912 sheet_view->priv->edited_column,
11917 pspp_sheet_view_editable_clicked (GtkButton *button,
11918 PsppSheetView *sheet_view)
11920 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
11925 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
11926 PsppSheetViewColumn *column,
11928 GtkCellEditable *cell_editable,
11929 GdkRectangle *cell_area,
11933 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
11934 gint pre_val = tree_view->priv->vadjustment->value;
11935 GtkRequisition requisition;
11937 tree_view->priv->edited_column = column;
11938 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
11940 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
11941 cell_area->y += pre_val - (int)tree_view->priv->vadjustment->value;
11943 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
11944 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
11945 tree_view->priv->anchor_column = column;
11947 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
11949 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
11951 if (requisition.height < cell_area->height)
11953 gint diff = cell_area->height - requisition.height;
11954 pspp_sheet_view_put (tree_view,
11955 GTK_WIDGET (cell_editable),
11956 cell_area->x, cell_area->y + diff/2,
11957 cell_area->width, requisition.height);
11961 pspp_sheet_view_put (tree_view,
11962 GTK_WIDGET (cell_editable),
11963 cell_area->x, cell_area->y,
11964 cell_area->width, cell_area->height);
11967 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
11968 (GdkEvent *)event);
11970 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
11971 g_signal_connect (cell_editable, "remove-widget",
11972 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
11973 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
11974 GTK_IS_BUTTON (cell_editable))
11976 g_signal_connect (cell_editable, "button-press-event",
11977 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
11979 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
11980 GINT_TO_POINTER (gtk_tree_path_get_indices (path)[0]));
11981 g_signal_connect (cell_editable, "clicked",
11982 G_CALLBACK (pspp_sheet_view_editable_clicked),
11988 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
11989 gboolean cancel_editing)
11991 PsppSheetViewColumn *column;
11992 GtkCellRenderer *cell;
11994 if (tree_view->priv->edited_column == NULL)
11998 * This is very evil. We need to do this, because
11999 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12000 * later on. If pspp_sheet_view_row_changed notices
12001 * tree_view->priv->edited_column != NULL, it'll call
12002 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12004 * Please read that again if you intend to modify anything here.
12007 column = tree_view->priv->edited_column;
12008 tree_view->priv->edited_column = NULL;
12010 cell = _pspp_sheet_view_column_get_edited_cell (column);
12011 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12013 if (!cancel_editing)
12014 gtk_cell_editable_editing_done (column->editable_widget);
12016 tree_view->priv->edited_column = column;
12018 gtk_cell_editable_remove_widget (column->editable_widget);
12023 * pspp_sheet_view_set_hover_selection:
12024 * @tree_view: a #PsppSheetView
12025 * @hover: %TRUE to enable hover selection mode
12027 * Enables of disables the hover selection mode of @tree_view.
12028 * Hover selection makes the selected row follow the pointer.
12029 * Currently, this works only for the selection modes
12030 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12035 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12038 hover = hover != FALSE;
12040 if (hover != tree_view->priv->hover_selection)
12042 tree_view->priv->hover_selection = hover;
12044 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12049 * pspp_sheet_view_get_hover_selection:
12050 * @tree_view: a #PsppSheetView
12052 * Returns whether hover selection mode is turned on for @tree_view.
12054 * Return value: %TRUE if @tree_view is in hover selection mode
12059 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12061 return tree_view->priv->hover_selection;
12065 * pspp_sheet_view_set_rubber_banding:
12066 * @tree_view: a #PsppSheetView
12067 * @enable: %TRUE to enable rubber banding
12069 * Enables or disables rubber banding in @tree_view. If the selection mode is
12070 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12071 * banding will allow the user to select multiple rows by dragging the mouse.
12076 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12079 enable = enable != FALSE;
12081 if (enable != tree_view->priv->rubber_banding_enable)
12083 tree_view->priv->rubber_banding_enable = enable;
12085 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12090 * pspp_sheet_view_get_rubber_banding:
12091 * @tree_view: a #PsppSheetView
12093 * Returns whether rubber banding is turned on for @tree_view. If the
12094 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12095 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12096 * select multiple rows by dragging the mouse.
12098 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12103 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12105 return tree_view->priv->rubber_banding_enable;
12109 * pspp_sheet_view_is_rubber_banding_active:
12110 * @tree_view: a #PsppSheetView
12112 * Returns whether a rubber banding operation is currently being done
12115 * Return value: %TRUE if a rubber banding operation is currently being
12116 * done in @tree_view.
12121 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12123 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12125 if (tree_view->priv->rubber_banding_enable
12126 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12133 pspp_sheet_view_grab_notify (GtkWidget *widget,
12134 gboolean was_grabbed)
12136 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12138 tree_view->priv->in_grab = !was_grabbed;
12142 tree_view->priv->pressed_button = -1;
12144 if (tree_view->priv->rubber_band_status)
12145 pspp_sheet_view_stop_rubber_band (tree_view);
12150 pspp_sheet_view_state_changed (GtkWidget *widget,
12151 GtkStateType previous_state)
12153 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12155 if (gtk_widget_get_realized (widget))
12157 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
12158 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
12161 gtk_widget_queue_draw (widget);
12165 * pspp_sheet_view_get_grid_lines:
12166 * @tree_view: a #PsppSheetView
12168 * Returns which grid lines are enabled in @tree_view.
12170 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12175 PsppSheetViewGridLines
12176 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12178 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12180 return tree_view->priv->grid_lines;
12184 * pspp_sheet_view_set_grid_lines:
12185 * @tree_view: a #PsppSheetView
12186 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12189 * Sets which grid lines to draw in @tree_view.
12194 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12195 PsppSheetViewGridLines grid_lines)
12197 PsppSheetViewPrivate *priv;
12199 PsppSheetViewGridLines old_grid_lines;
12201 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12203 priv = tree_view->priv;
12204 widget = GTK_WIDGET (tree_view);
12206 old_grid_lines = priv->grid_lines;
12207 priv->grid_lines = grid_lines;
12209 if (gtk_widget_get_realized (widget))
12211 if (grid_lines == PSPP_SHEET_VIEW_GRID_LINES_NONE &&
12212 priv->grid_line_gc)
12214 g_object_unref (priv->grid_line_gc);
12215 priv->grid_line_gc = NULL;
12218 if (grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE &&
12219 !priv->grid_line_gc)
12223 gtk_widget_style_get (widget,
12224 "grid-line-width", &line_width,
12227 priv->grid_line_gc = gdk_gc_new (widget->window);
12228 gdk_gc_copy (priv->grid_line_gc, widget->style->black_gc);
12232 if (old_grid_lines != grid_lines)
12234 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12236 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12241 * pspp_sheet_view_set_tooltip_row:
12242 * @tree_view: a #PsppSheetView
12243 * @tooltip: a #GtkTooltip
12244 * @path: a #GtkTreePath
12246 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12247 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12248 * See also gtk_tooltip_set_tip_area().
12253 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12254 GtkTooltip *tooltip,
12257 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12258 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12260 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12264 * pspp_sheet_view_set_tooltip_cell:
12265 * @tree_view: a #PsppSheetView
12266 * @tooltip: a #GtkTooltip
12267 * @path: (allow-none): a #GtkTreePath or %NULL
12268 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12269 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12271 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12272 * in common. For example if @path is %NULL and @column is set, the tip
12273 * area will be set to the full area covered by @column. See also
12274 * gtk_tooltip_set_tip_area().
12276 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12281 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12282 GtkTooltip *tooltip,
12284 PsppSheetViewColumn *column,
12285 GtkCellRenderer *cell)
12289 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12290 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12291 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12292 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12294 /* Determine x values. */
12295 if (column && cell)
12300 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12301 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12303 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12306 rect.width = width;
12312 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
12313 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12316 rect.width = tmp.width;
12321 rect.width = GTK_WIDGET (tree_view)->allocation.width;
12324 /* Determine y values. */
12329 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
12330 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12333 rect.height = tmp.height;
12338 rect.height = tree_view->priv->vadjustment->page_size;
12341 gtk_tooltip_set_tip_area (tooltip, &rect);
12345 * pspp_sheet_view_get_tooltip_context:
12346 * @tree_view: a #PsppSheetView
12347 * @x: the x coordinate (relative to widget coordinates)
12348 * @y: the y coordinate (relative to widget coordinates)
12349 * @keyboard_tip: whether this is a keyboard tooltip or not
12350 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
12351 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
12352 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
12354 * This function is supposed to be used in a #GtkWidget::query-tooltip
12355 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
12356 * which are received in the signal handler, should be passed to this
12357 * function without modification.
12359 * The return value indicates whether there is a tree view row at the given
12360 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
12361 * tooltips the row returned will be the cursor row. When %TRUE, then any of
12362 * @model, @path and @iter which have been provided will be set to point to
12363 * that row and the corresponding model. @x and @y will always be converted
12364 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
12366 * Return value: whether or not the given tooltip context points to a row.
12371 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
12374 gboolean keyboard_tip,
12375 GtkTreeModel **model,
12376 GtkTreePath **path,
12379 GtkTreePath *tmppath = NULL;
12381 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12382 g_return_val_if_fail (x != NULL, FALSE);
12383 g_return_val_if_fail (y != NULL, FALSE);
12387 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
12394 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
12397 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
12398 &tmppath, NULL, NULL, NULL))
12403 *model = pspp_sheet_view_get_model (tree_view);
12406 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
12412 gtk_tree_path_free (tmppath);
12418 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
12421 gboolean keyboard_tip,
12422 GtkTooltip *tooltip,
12425 GValue value = { 0, };
12426 GValue transformed = { 0, };
12429 GtkTreeModel *model;
12430 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12432 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
12435 &model, &path, &iter))
12438 gtk_tree_model_get_value (model, &iter,
12439 tree_view->priv->tooltip_column, &value);
12441 g_value_init (&transformed, G_TYPE_STRING);
12443 if (!g_value_transform (&value, &transformed))
12445 g_value_unset (&value);
12446 gtk_tree_path_free (path);
12451 g_value_unset (&value);
12453 if (!g_value_get_string (&transformed))
12455 g_value_unset (&transformed);
12456 gtk_tree_path_free (path);
12461 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
12462 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
12464 gtk_tree_path_free (path);
12465 g_value_unset (&transformed);
12471 * pspp_sheet_view_set_tooltip_column:
12472 * @tree_view: a #PsppSheetView
12473 * @column: an integer, which is a valid column number for @tree_view's model
12475 * If you only plan to have simple (text-only) tooltips on full rows, you
12476 * can use this function to have #PsppSheetView handle these automatically
12477 * for you. @column should be set to the column in @tree_view's model
12478 * containing the tooltip texts, or -1 to disable this feature.
12480 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
12481 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
12483 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
12484 * so &, <, etc have to be escaped in the text.
12489 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
12492 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12494 if (column == tree_view->priv->tooltip_column)
12499 g_signal_handlers_disconnect_by_func (tree_view,
12500 pspp_sheet_view_set_tooltip_query_cb,
12502 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
12506 if (tree_view->priv->tooltip_column == -1)
12508 g_signal_connect (tree_view, "query-tooltip",
12509 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
12510 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
12514 tree_view->priv->tooltip_column = column;
12515 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
12519 * pspp_sheet_view_get_tooltip_column:
12520 * @tree_view: a #PsppSheetView
12522 * Returns the column of @tree_view's model which is being used for
12523 * displaying tooltips on @tree_view's rows.
12525 * Return value: the index of the tooltip column that is currently being
12526 * used, or -1 if this is disabled.
12531 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
12533 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12535 return tree_view->priv->tooltip_column;
12539 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
12540 GValue *return_accu,
12541 const GValue *handler_return,
12544 gboolean continue_emission;
12545 gboolean signal_handled;
12547 signal_handled = g_value_get_boolean (handler_return);
12548 g_value_set_boolean (return_accu, signal_handled);
12549 continue_emission = !signal_handled;
12551 return continue_emission;
12555 pspp_sheet_view_grid_lines_get_type (void)
12557 static GType etype = 0;
12558 if (G_UNLIKELY(etype == 0)) {
12559 static const GEnumValue values[] = {
12560 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
12561 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
12562 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
12563 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
12566 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);