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/>. */
17 /* gtktreeviewcolumn.c
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"
45 #include "ui/gui/psppire-marshal.h"
46 #include "ui/gui/pspp-sheet-selection.h"
47 #include "ui/gui/pspp-widget-facade.h"
49 #define P_(STRING) STRING
50 #define GTK_PARAM_READABLE G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
51 #define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
88 typedef struct _PsppSheetViewColumnCellInfo PsppSheetViewColumnCellInfo;
89 struct _PsppSheetViewColumnCellInfo
91 GtkCellRenderer *cell;
93 PsppSheetCellDataFunc func;
95 GDestroyNotify destroy;
101 guint in_editing_mode : 1;
105 static void pspp_sheet_view_column_cell_layout_init (GtkCellLayoutIface *iface);
107 /* GObject methods */
108 static void pspp_sheet_view_column_set_property (GObject *object,
112 static void pspp_sheet_view_column_get_property (GObject *object,
116 static void pspp_sheet_view_column_finalize (GObject *object);
118 /* GtkCellLayout implementation */
119 static void pspp_sheet_view_column_cell_layout_pack_start (GtkCellLayout *cell_layout,
120 GtkCellRenderer *cell,
122 static void pspp_sheet_view_column_cell_layout_pack_end (GtkCellLayout *cell_layout,
123 GtkCellRenderer *cell,
125 static void pspp_sheet_view_column_cell_layout_clear (GtkCellLayout *cell_layout);
126 static void pspp_sheet_view_column_cell_layout_add_attribute (GtkCellLayout *cell_layout,
127 GtkCellRenderer *cell,
128 const gchar *attribute,
130 static void pspp_sheet_view_column_cell_layout_set_cell_data_func (GtkCellLayout *cell_layout,
131 GtkCellRenderer *cell,
132 GtkCellLayoutDataFunc func,
134 GDestroyNotify destroy);
135 static void pspp_sheet_view_column_cell_layout_clear_attributes (GtkCellLayout *cell_layout,
136 GtkCellRenderer *cell);
137 static void pspp_sheet_view_column_cell_layout_reorder (GtkCellLayout *cell_layout,
138 GtkCellRenderer *cell,
140 static GList *pspp_sheet_view_column_cell_layout_get_cells (GtkCellLayout *cell_layout);
142 /* Button handling code */
143 static void pspp_sheet_view_column_create_button (PsppSheetViewColumn *tree_column);
144 void pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
146 /* Button signal handlers */
147 static gint pspp_sheet_view_column_button_event (GtkWidget *widget,
150 static void pspp_sheet_view_column_button_clicked (GtkWidget *widget,
152 static void pspp_sheet_view_column_button_popup_menu (GtkWidget *widget,
154 static gboolean pspp_sheet_view_column_mnemonic_activate (GtkWidget *widget,
155 gboolean group_cycling,
157 static gboolean on_pspp_sheet_view_column_button_clicked (PsppSheetViewColumn *);
158 static gboolean on_pspp_sheet_view_column_button_press_event (PsppSheetViewColumn *,
161 /* Property handlers */
162 static void pspp_sheet_view_model_sort_column_changed (GtkTreeSortable *sortable,
163 PsppSheetViewColumn *tree_column);
165 /* Internal functions */
166 static void pspp_sheet_view_column_sort (PsppSheetViewColumn *tree_column,
168 static void pspp_sheet_view_column_setup_sort_column_id_callback (PsppSheetViewColumn *tree_column);
169 static void pspp_sheet_view_column_set_attributesv (PsppSheetViewColumn *tree_column,
170 GtkCellRenderer *cell_renderer,
172 static PsppSheetViewColumnCellInfo *pspp_sheet_view_column_get_cell_info (PsppSheetViewColumn *tree_column,
173 GtkCellRenderer *cell_renderer);
175 /* cell list manipulation */
176 static GList *pspp_sheet_view_column_cell_first (PsppSheetViewColumn *tree_column);
177 static GList *pspp_sheet_view_column_cell_last (PsppSheetViewColumn *tree_column);
178 static GList *pspp_sheet_view_column_cell_next (PsppSheetViewColumn *tree_column,
180 static GList *pspp_sheet_view_column_cell_prev (PsppSheetViewColumn *tree_column,
182 static void pspp_sheet_view_column_clear_attributes_by_info (PsppSheetViewColumn *tree_column,
183 PsppSheetViewColumnCellInfo *info);
184 /* GtkBuildable implementation */
185 static void pspp_sheet_view_column_buildable_init (GtkBuildableIface *iface);
187 static guint tree_column_signals[LAST_SIGNAL] = { 0 };
189 G_DEFINE_TYPE_WITH_CODE (PsppSheetViewColumn, pspp_sheet_view_column, GTK_TYPE_OBJECT,
190 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
191 pspp_sheet_view_column_cell_layout_init)
192 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
193 pspp_sheet_view_column_buildable_init))
197 pspp_sheet_view_column_class_init (PsppSheetViewColumnClass *class)
199 GObjectClass *object_class;
201 object_class = (GObjectClass*) class;
203 class->clicked = on_pspp_sheet_view_column_button_clicked;
204 class->button_press_event = on_pspp_sheet_view_column_button_press_event;
206 object_class->finalize = pspp_sheet_view_column_finalize;
207 object_class->set_property = pspp_sheet_view_column_set_property;
208 object_class->get_property = pspp_sheet_view_column_get_property;
210 tree_column_signals[CLICKED] =
211 g_signal_new ("clicked",
212 G_OBJECT_CLASS_TYPE (object_class),
214 G_STRUCT_OFFSET (PsppSheetViewColumnClass, clicked),
215 g_signal_accumulator_true_handled, NULL,
216 psppire_marshal_BOOLEAN__VOID,
219 tree_column_signals[POPUP_MENU] =
220 g_signal_new ("popup-menu",
221 G_OBJECT_CLASS_TYPE (object_class),
225 g_cclosure_marshal_VOID__VOID,
228 tree_column_signals[QUERY_TOOLTIP] =
229 g_signal_new ("query-tooltip",
230 G_OBJECT_CLASS_TYPE (object_class),
233 g_signal_accumulator_true_handled, NULL,
234 psppire_marshal_BOOLEAN__OBJECT,
238 tree_column_signals[BUTTON_PRESS_EVENT] =
239 g_signal_new ("button-press-event",
240 G_OBJECT_CLASS_TYPE (object_class),
241 G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
242 G_STRUCT_OFFSET (PsppSheetViewColumnClass, button_press_event),
243 g_signal_accumulator_true_handled, NULL,
244 psppire_marshal_BOOLEAN__BOXED,
246 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
248 g_object_class_install_property (object_class,
250 g_param_spec_boolean ("visible",
252 P_("Whether to display the column"),
254 GTK_PARAM_READWRITE));
256 g_object_class_install_property (object_class,
258 g_param_spec_boolean ("resizable",
260 P_("Column is user-resizable"),
262 GTK_PARAM_READWRITE));
264 g_object_class_install_property (object_class,
266 g_param_spec_int ("width",
268 P_("Current width of the column"),
272 GTK_PARAM_READABLE));
273 g_object_class_install_property (object_class,
275 g_param_spec_int ("spacing",
277 P_("Space which is inserted between cells"),
281 GTK_PARAM_READWRITE));
283 g_object_class_install_property (object_class,
285 g_param_spec_int ("fixed-width",
287 P_("Current fixed width of the column"),
291 GTK_PARAM_READWRITE));
293 g_object_class_install_property (object_class,
295 g_param_spec_int ("min-width",
297 P_("Minimum allowed width of the column"),
301 GTK_PARAM_READWRITE));
303 g_object_class_install_property (object_class,
305 g_param_spec_int ("max-width",
307 P_("Maximum allowed width of the column"),
311 GTK_PARAM_READWRITE));
313 g_object_class_install_property (object_class,
315 g_param_spec_string ("title",
317 P_("Title to appear in column header"),
319 GTK_PARAM_READWRITE));
321 g_object_class_install_property (object_class,
323 g_param_spec_boolean ("expand",
325 P_("Column gets share of extra width allocated to the widget"),
327 GTK_PARAM_READWRITE));
329 g_object_class_install_property (object_class,
331 g_param_spec_boolean ("clickable",
333 P_("Whether the header can be clicked"),
335 GTK_PARAM_READWRITE));
338 g_object_class_install_property (object_class,
340 g_param_spec_object ("widget",
342 P_("Widget to put in column header button instead of column title"),
344 GTK_PARAM_READWRITE));
346 g_object_class_install_property (object_class,
348 g_param_spec_float ("alignment",
350 P_("X Alignment of the column header text or widget"),
354 GTK_PARAM_READWRITE));
356 g_object_class_install_property (object_class,
358 g_param_spec_boolean ("reorderable",
360 P_("Whether the column can be reordered around the headers"),
362 GTK_PARAM_READWRITE));
364 g_object_class_install_property (object_class,
366 g_param_spec_boolean ("sort-indicator",
367 P_("Sort indicator"),
368 P_("Whether to show a sort indicator"),
370 GTK_PARAM_READWRITE));
372 g_object_class_install_property (object_class,
374 g_param_spec_enum ("sort-order",
376 P_("Sort direction the sort indicator should indicate"),
379 GTK_PARAM_READWRITE));
382 * PsppSheetViewColumn:sort-column-id:
384 * Logical sort column ID this column sorts on when selected for sorting. Setting the sort column ID makes the column header
385 * clickable. Set to %-1 to make the column unsortable.
389 g_object_class_install_property (object_class,
391 g_param_spec_int ("sort-column-id",
392 P_("Sort column ID"),
393 P_("Logical sort column ID this column sorts on when selected for sorting"),
397 GTK_PARAM_READWRITE));
399 g_object_class_install_property (object_class,
401 g_param_spec_boolean ("quick-edit",
403 P_("If true, editing starts upon the first click in the column. If false, the first click selects the column and a second click is needed to begin editing. This has no effect on cells that are not editable."),
405 GTK_PARAM_READWRITE));
407 g_object_class_install_property (object_class,
409 g_param_spec_boolean ("selected",
411 P_("If true, this column is selected as part of a rectangular selection."),
413 GTK_PARAM_READWRITE));
415 g_object_class_install_property (object_class,
417 g_param_spec_boolean ("selectable",
419 P_("If true, this column may be selected as part of a rectangular selection."),
421 GTK_PARAM_READWRITE));
423 g_object_class_install_property (object_class,
425 g_param_spec_boolean ("row-head",
427 P_("If true, this column is a \"row head\", equivalent to a column head. If rectangular selection is enabled, then shift+click and control+click in the column select row ranges and toggle row selection, respectively. The column should ordinarily include a button cell; clicking on the button will select the row (and deselect all other rows)."),
429 GTK_PARAM_READWRITE));
431 g_object_class_install_property (object_class,
433 g_param_spec_boolean ("tabbable",
435 P_("If true, Tab and Shift+Tab visit this column. If false, Tab and Shift+Tab skip this column."),
437 GTK_PARAM_READWRITE));
441 pspp_sheet_view_column_buildable_init (GtkBuildableIface *iface)
443 iface->add_child = _gtk_cell_layout_buildable_add_child;
444 iface->custom_tag_start = _gtk_cell_layout_buildable_custom_tag_start;
445 iface->custom_tag_end = _gtk_cell_layout_buildable_custom_tag_end;
449 pspp_sheet_view_column_cell_layout_init (GtkCellLayoutIface *iface)
451 iface->pack_start = pspp_sheet_view_column_cell_layout_pack_start;
452 iface->pack_end = pspp_sheet_view_column_cell_layout_pack_end;
453 iface->clear = pspp_sheet_view_column_cell_layout_clear;
454 iface->add_attribute = pspp_sheet_view_column_cell_layout_add_attribute;
455 iface->set_cell_data_func = pspp_sheet_view_column_cell_layout_set_cell_data_func;
456 iface->clear_attributes = pspp_sheet_view_column_cell_layout_clear_attributes;
457 iface->reorder = pspp_sheet_view_column_cell_layout_reorder;
458 iface->get_cells = pspp_sheet_view_column_cell_layout_get_cells;
462 pspp_sheet_view_column_init (PsppSheetViewColumn *tree_column)
464 tree_column->button = NULL;
465 tree_column->xalign = 0.0;
466 tree_column->width = 0;
467 tree_column->spacing = 0;
468 tree_column->requested_width = -1;
469 tree_column->min_width = -1;
470 tree_column->max_width = -1;
471 tree_column->resized_width = 0;
472 tree_column->visible = TRUE;
473 tree_column->resizable = FALSE;
474 tree_column->expand = FALSE;
475 tree_column->clickable = FALSE;
476 tree_column->dirty = TRUE;
477 tree_column->selected = FALSE;
478 tree_column->selectable = TRUE;
479 tree_column->row_head = FALSE;
480 tree_column->tabbable = TRUE;
481 tree_column->sort_order = GTK_SORT_ASCENDING;
482 tree_column->show_sort_indicator = FALSE;
483 tree_column->property_changed_signal = 0;
484 tree_column->sort_clicked_signal = 0;
485 tree_column->sort_column_changed_signal = 0;
486 tree_column->sort_column_id = -1;
487 tree_column->reorderable = FALSE;
488 tree_column->maybe_reordered = FALSE;
489 tree_column->fixed_width = 1;
490 tree_column->use_resized_width = FALSE;
491 tree_column->title = g_strdup ("");
492 tree_column->quick_edit = TRUE;
493 tree_column->need_button = FALSE;
497 pspp_sheet_view_column_finalize (GObject *object)
499 PsppSheetViewColumn *tree_column = (PsppSheetViewColumn *) object;
502 for (list = tree_column->cell_list; list; list = list->next)
504 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
508 GDestroyNotify d = info->destroy;
510 info->destroy = NULL;
513 pspp_sheet_view_column_clear_attributes_by_info (tree_column, info);
514 g_object_unref (info->cell);
518 g_free (tree_column->title);
519 g_list_free (tree_column->cell_list);
521 if (tree_column->child)
522 g_object_unref (tree_column->child);
524 G_OBJECT_CLASS (pspp_sheet_view_column_parent_class)->finalize (object);
528 pspp_sheet_view_column_set_property (GObject *object,
533 PsppSheetViewColumn *tree_column;
535 tree_column = PSPP_SHEET_VIEW_COLUMN (object);
540 pspp_sheet_view_column_set_visible (tree_column,
541 g_value_get_boolean (value));
545 pspp_sheet_view_column_set_resizable (tree_column,
546 g_value_get_boolean (value));
549 case PROP_FIXED_WIDTH:
550 pspp_sheet_view_column_set_fixed_width (tree_column,
551 g_value_get_int (value));
555 pspp_sheet_view_column_set_min_width (tree_column,
556 g_value_get_int (value));
560 pspp_sheet_view_column_set_max_width (tree_column,
561 g_value_get_int (value));
565 pspp_sheet_view_column_set_spacing (tree_column,
566 g_value_get_int (value));
570 pspp_sheet_view_column_set_title (tree_column,
571 g_value_get_string (value));
575 pspp_sheet_view_column_set_expand (tree_column,
576 g_value_get_boolean (value));
580 pspp_sheet_view_column_set_clickable (tree_column,
581 g_value_get_boolean (value));
585 pspp_sheet_view_column_set_widget (tree_column,
586 (GtkWidget*) g_value_get_object (value));
590 pspp_sheet_view_column_set_alignment (tree_column,
591 g_value_get_float (value));
594 case PROP_REORDERABLE:
595 pspp_sheet_view_column_set_reorderable (tree_column,
596 g_value_get_boolean (value));
599 case PROP_SORT_INDICATOR:
600 pspp_sheet_view_column_set_sort_indicator (tree_column,
601 g_value_get_boolean (value));
604 case PROP_SORT_ORDER:
605 pspp_sheet_view_column_set_sort_order (tree_column,
606 g_value_get_enum (value));
609 case PROP_SORT_COLUMN_ID:
610 pspp_sheet_view_column_set_sort_column_id (tree_column,
611 g_value_get_int (value));
614 case PROP_QUICK_EDIT:
615 pspp_sheet_view_column_set_quick_edit (tree_column,
616 g_value_get_boolean (value));
620 pspp_sheet_view_column_set_selected (tree_column,
621 g_value_get_boolean (value));
624 case PROP_SELECTABLE:
625 pspp_sheet_view_column_set_selectable (tree_column,
626 g_value_get_boolean (value));
630 pspp_sheet_view_column_set_row_head (tree_column,
631 g_value_get_boolean (value));
635 pspp_sheet_view_column_set_tabbable (tree_column,
636 g_value_get_boolean (value));
640 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
646 pspp_sheet_view_column_get_property (GObject *object,
651 PsppSheetViewColumn *tree_column;
653 tree_column = PSPP_SHEET_VIEW_COLUMN (object);
658 g_value_set_boolean (value,
659 pspp_sheet_view_column_get_visible (tree_column));
663 g_value_set_boolean (value,
664 pspp_sheet_view_column_get_resizable (tree_column));
668 g_value_set_int (value,
669 pspp_sheet_view_column_get_width (tree_column));
673 g_value_set_int (value,
674 pspp_sheet_view_column_get_spacing (tree_column));
677 case PROP_FIXED_WIDTH:
678 g_value_set_int (value,
679 pspp_sheet_view_column_get_fixed_width (tree_column));
683 g_value_set_int (value,
684 pspp_sheet_view_column_get_min_width (tree_column));
688 g_value_set_int (value,
689 pspp_sheet_view_column_get_max_width (tree_column));
693 g_value_set_string (value,
694 pspp_sheet_view_column_get_title (tree_column));
698 g_value_set_boolean (value,
699 pspp_sheet_view_column_get_expand (tree_column));
703 g_value_set_boolean (value,
704 pspp_sheet_view_column_get_clickable (tree_column));
708 g_value_set_object (value,
709 (GObject*) pspp_sheet_view_column_get_widget (tree_column));
713 g_value_set_float (value,
714 pspp_sheet_view_column_get_alignment (tree_column));
717 case PROP_REORDERABLE:
718 g_value_set_boolean (value,
719 pspp_sheet_view_column_get_reorderable (tree_column));
722 case PROP_SORT_INDICATOR:
723 g_value_set_boolean (value,
724 pspp_sheet_view_column_get_sort_indicator (tree_column));
727 case PROP_SORT_ORDER:
728 g_value_set_enum (value,
729 pspp_sheet_view_column_get_sort_order (tree_column));
732 case PROP_SORT_COLUMN_ID:
733 g_value_set_int (value,
734 pspp_sheet_view_column_get_sort_column_id (tree_column));
737 case PROP_QUICK_EDIT:
738 g_value_set_boolean (value,
739 pspp_sheet_view_column_get_quick_edit (tree_column));
743 g_value_set_boolean (value,
744 pspp_sheet_view_column_get_selected (tree_column));
747 case PROP_SELECTABLE:
748 g_value_set_boolean (value,
749 pspp_sheet_view_column_get_selectable (tree_column));
753 g_value_set_boolean (value,
754 pspp_sheet_view_column_get_row_head (tree_column));
758 g_value_set_boolean (value,
759 pspp_sheet_view_column_get_tabbable (tree_column));
763 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
768 /* Implementation of GtkCellLayout interface
772 pspp_sheet_view_column_cell_layout_pack_start (GtkCellLayout *cell_layout,
773 GtkCellRenderer *cell,
776 PsppSheetViewColumn *column;
777 PsppSheetViewColumnCellInfo *cell_info;
779 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
780 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
781 g_return_if_fail (! pspp_sheet_view_column_get_cell_info (column, cell));
783 g_object_ref_sink (cell);
785 cell_info = g_new0 (PsppSheetViewColumnCellInfo, 1);
786 cell_info->cell = cell;
787 cell_info->expand = expand ? TRUE : FALSE;
788 cell_info->pack = GTK_PACK_START;
789 cell_info->has_focus = 0;
790 cell_info->attributes = NULL;
792 column->cell_list = g_list_append (column->cell_list, cell_info);
796 pspp_sheet_view_column_cell_layout_pack_end (GtkCellLayout *cell_layout,
797 GtkCellRenderer *cell,
800 PsppSheetViewColumn *column;
801 PsppSheetViewColumnCellInfo *cell_info;
803 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
804 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
805 g_return_if_fail (! pspp_sheet_view_column_get_cell_info (column, cell));
807 g_object_ref_sink (cell);
809 cell_info = g_new0 (PsppSheetViewColumnCellInfo, 1);
810 cell_info->cell = cell;
811 cell_info->expand = expand ? TRUE : FALSE;
812 cell_info->pack = GTK_PACK_END;
813 cell_info->has_focus = 0;
814 cell_info->attributes = NULL;
816 column->cell_list = g_list_append (column->cell_list, cell_info);
820 pspp_sheet_view_column_cell_layout_clear (GtkCellLayout *cell_layout)
822 PsppSheetViewColumn *column;
824 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
825 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
827 while (column->cell_list)
829 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *)column->cell_list->data;
831 pspp_sheet_view_column_cell_layout_clear_attributes (cell_layout, info->cell);
832 g_object_unref (info->cell);
834 column->cell_list = g_list_delete_link (column->cell_list,
840 pspp_sheet_view_column_cell_layout_add_attribute (GtkCellLayout *cell_layout,
841 GtkCellRenderer *cell,
842 const gchar *attribute,
845 PsppSheetViewColumn *tree_column;
846 PsppSheetViewColumnCellInfo *info;
848 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
849 tree_column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
851 info = pspp_sheet_view_column_get_cell_info (tree_column, cell);
852 g_return_if_fail (info != NULL);
854 info->attributes = g_slist_prepend (info->attributes, GINT_TO_POINTER (column));
855 info->attributes = g_slist_prepend (info->attributes, g_strdup (attribute));
857 if (tree_column->tree_view)
858 _pspp_sheet_view_column_cell_set_dirty (tree_column);
862 pspp_sheet_view_column_cell_layout_set_cell_data_func (GtkCellLayout *cell_layout,
863 GtkCellRenderer *cell,
864 GtkCellLayoutDataFunc func,
866 GDestroyNotify destroy)
868 PsppSheetViewColumn *column;
869 PsppSheetViewColumnCellInfo *info;
871 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
872 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
874 info = pspp_sheet_view_column_get_cell_info (column, cell);
875 g_return_if_fail (info != NULL);
879 GDestroyNotify d = info->destroy;
881 info->destroy = NULL;
885 info->func = (PsppSheetCellDataFunc)func;
886 info->func_data = func_data;
887 info->destroy = destroy;
889 if (column->tree_view)
890 _pspp_sheet_view_column_cell_set_dirty (column);
894 pspp_sheet_view_column_cell_layout_clear_attributes (GtkCellLayout *cell_layout,
895 GtkCellRenderer *cell_renderer)
897 PsppSheetViewColumn *column;
898 PsppSheetViewColumnCellInfo *info;
900 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
901 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
903 info = pspp_sheet_view_column_get_cell_info (column, cell_renderer);
905 pspp_sheet_view_column_clear_attributes_by_info (column, info);
909 pspp_sheet_view_column_cell_layout_reorder (GtkCellLayout *cell_layout,
910 GtkCellRenderer *cell,
914 PsppSheetViewColumn *column;
915 PsppSheetViewColumnCellInfo *info;
917 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
918 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
920 info = pspp_sheet_view_column_get_cell_info (column, cell);
922 g_return_if_fail (info != NULL);
923 g_return_if_fail (position >= 0);
925 link = g_list_find (column->cell_list, info);
927 g_return_if_fail (link != NULL);
929 column->cell_list = g_list_delete_link (column->cell_list, link);
930 column->cell_list = g_list_insert (column->cell_list, info, position);
932 if (column->tree_view)
933 gtk_widget_queue_draw (column->tree_view);
937 pspp_sheet_view_column_clear_attributes_by_info (PsppSheetViewColumn *tree_column,
938 PsppSheetViewColumnCellInfo *info)
942 list = info->attributes;
944 while (list && list->next)
947 list = list->next->next;
949 g_slist_free (info->attributes);
950 info->attributes = NULL;
952 if (tree_column->tree_view)
953 _pspp_sheet_view_column_cell_set_dirty (tree_column);
957 on_query_tooltip (GtkWidget *widget,
960 gboolean keyboard_mode,
964 PsppSheetViewColumn *tree_column = user_data;
967 g_signal_emit (tree_column, tree_column_signals[QUERY_TOOLTIP], 0,
973 on_button_pressed (GtkWidget *widget, GdkEventButton *event,
976 PsppSheetViewColumn *tree_column = user_data;
979 /* XXX See "Implement GtkWidget::popup_menu" in GTK+ reference manual. */
980 g_signal_emit (tree_column, tree_column_signals[BUTTON_PRESS_EVENT],
988 /* Button handling code
991 pspp_sheet_view_column_create_button (PsppSheetViewColumn *tree_column)
993 PsppSheetView *tree_view;
997 tree_view = (PsppSheetView *) tree_column->tree_view;
999 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
1000 g_return_if_fail (tree_column->button == NULL);
1002 gtk_widget_push_composite_child ();
1003 tree_column->button = gtk_button_new ();
1004 gtk_widget_add_events (tree_column->button, GDK_POINTER_MOTION_MASK);
1005 gtk_widget_pop_composite_child ();
1007 /* make sure we own a reference to it as well. */
1008 if (tree_view->priv->header_window)
1009 gtk_widget_set_parent_window (tree_column->button, tree_view->priv->header_window);
1010 gtk_widget_set_parent (tree_column->button, GTK_WIDGET (tree_view));
1012 g_signal_connect (tree_column->button, "event",
1013 G_CALLBACK (pspp_sheet_view_column_button_event),
1015 g_signal_connect (tree_column->button, "clicked",
1016 G_CALLBACK (pspp_sheet_view_column_button_clicked),
1018 g_signal_connect (tree_column->button, "popup-menu",
1019 G_CALLBACK (pspp_sheet_view_column_button_popup_menu),
1021 g_signal_connect (tree_column->button, "button-press-event",
1022 G_CALLBACK (on_button_pressed), tree_column);
1024 g_signal_connect (tree_column->button, "query-tooltip",
1025 G_CALLBACK (on_query_tooltip), tree_column);
1026 g_object_set (tree_column->button, "has-tooltip", TRUE, NULL);
1028 tree_column->alignment = gtk_alignment_new (tree_column->xalign, 0.5, 0.0, 0.0);
1030 hbox = gtk_hbox_new (FALSE, 2);
1031 tree_column->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN);
1033 if (tree_column->child)
1034 child = tree_column->child;
1037 child = gtk_label_new (tree_column->title);
1038 gtk_widget_show (child);
1041 g_signal_connect (child, "mnemonic-activate",
1042 G_CALLBACK (pspp_sheet_view_column_mnemonic_activate),
1045 if (tree_column->xalign <= 0.5)
1046 gtk_box_pack_end (GTK_BOX (hbox), tree_column->arrow, FALSE, FALSE, 0);
1048 gtk_box_pack_start (GTK_BOX (hbox), tree_column->arrow, FALSE, FALSE, 0);
1050 gtk_box_pack_start (GTK_BOX (hbox), tree_column->alignment, TRUE, TRUE, 0);
1052 gtk_container_add (GTK_CONTAINER (tree_column->alignment), child);
1053 gtk_container_add (GTK_CONTAINER (tree_column->button), hbox);
1055 gtk_widget_show (hbox);
1056 gtk_widget_show (tree_column->alignment);
1057 pspp_sheet_view_column_update_button (tree_column);
1061 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column)
1063 gint sort_column_id = -1;
1065 GtkWidget *alignment;
1067 GtkWidget *current_child;
1068 GtkArrowType arrow_type = GTK_ARROW_NONE;
1069 GtkTreeModel *model;
1072 if (tree_column->tree_view)
1073 model = pspp_sheet_view_get_model (PSPP_SHEET_VIEW (tree_column->tree_view));
1077 /* Create a button if necessary */
1078 if (tree_column->need_button &&
1079 tree_column->visible &&
1080 tree_column->button == NULL &&
1081 tree_column->tree_view &&
1082 gtk_widget_get_realized (tree_column->tree_view))
1083 pspp_sheet_view_column_create_button (tree_column);
1085 if (! tree_column->button)
1088 hbox = GTK_BIN (tree_column->button)->child;
1089 alignment = tree_column->alignment;
1090 arrow = tree_column->arrow;
1091 current_child = GTK_BIN (alignment)->child;
1093 /* Set up the actual button */
1094 gtk_alignment_set (GTK_ALIGNMENT (alignment), tree_column->xalign,
1097 if (tree_column->child)
1099 if (current_child != tree_column->child)
1101 gtk_container_remove (GTK_CONTAINER (alignment),
1103 gtk_container_add (GTK_CONTAINER (alignment),
1104 tree_column->child);
1109 if (current_child == NULL)
1111 current_child = gtk_label_new (NULL);
1112 gtk_widget_show (current_child);
1113 gtk_container_add (GTK_CONTAINER (alignment),
1117 g_return_if_fail (GTK_IS_LABEL (current_child));
1119 if (tree_column->title)
1120 gtk_label_set_text_with_mnemonic (GTK_LABEL (current_child),
1121 tree_column->title);
1123 gtk_label_set_text_with_mnemonic (GTK_LABEL (current_child),
1127 if (GTK_IS_TREE_SORTABLE (model))
1128 gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model),
1132 if (tree_column->show_sort_indicator)
1134 gboolean alternative;
1136 g_object_get (gtk_widget_get_settings (tree_column->tree_view),
1137 "gtk-alternative-sort-arrows", &alternative,
1140 switch (tree_column->sort_order)
1142 case GTK_SORT_ASCENDING:
1143 arrow_type = alternative ? GTK_ARROW_UP : GTK_ARROW_DOWN;
1146 case GTK_SORT_DESCENDING:
1147 arrow_type = alternative ? GTK_ARROW_DOWN : GTK_ARROW_UP;
1151 g_warning (G_STRLOC": bad sort order");
1156 gtk_arrow_set (GTK_ARROW (arrow),
1160 /* Put arrow on the right if the text is left-or-center justified, and on the
1161 * left otherwise; do this by packing boxes, so flipping text direction will
1164 g_object_ref (arrow);
1165 gtk_container_remove (GTK_CONTAINER (hbox), arrow);
1167 if (tree_column->xalign <= 0.5)
1169 gtk_box_pack_end (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
1173 gtk_box_pack_start (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
1174 /* move it to the front */
1175 gtk_box_reorder_child (GTK_BOX (hbox), arrow, 0);
1177 g_object_unref (arrow);
1179 if (tree_column->show_sort_indicator
1180 || (GTK_IS_TREE_SORTABLE (model) && tree_column->sort_column_id >= 0))
1181 gtk_widget_show (arrow);
1183 gtk_widget_hide (arrow);
1185 /* It's always safe to hide the button. It isn't always safe to show it, as
1186 * if you show it before it's realized, it'll get the wrong window. */
1187 if (tree_column->button &&
1188 tree_column->tree_view != NULL &&
1189 gtk_widget_get_realized (tree_column->tree_view))
1191 if (tree_column->visible)
1193 gtk_widget_show_now (tree_column->button);
1194 if (tree_column->window)
1196 if (tree_column->resizable)
1198 gdk_window_show (tree_column->window);
1199 gdk_window_raise (tree_column->window);
1203 gdk_window_hide (tree_column->window);
1209 gtk_widget_hide (tree_column->button);
1210 if (tree_column->window)
1211 gdk_window_hide (tree_column->window);
1215 can_focus = pspp_sheet_view_column_can_focus (tree_column);
1216 gtk_widget_set_can_focus (tree_column->button, can_focus);
1217 if (!can_focus && gtk_widget_has_focus (tree_column->button))
1219 GtkWidget *toplevel = gtk_widget_get_toplevel (tree_column->tree_view);
1220 if (gtk_widget_is_toplevel (toplevel))
1222 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
1226 /* Queue a resize on the assumption that we always want to catch all changes
1227 * and columns don't change all that often.
1229 if (gtk_widget_get_realized (tree_column->tree_view))
1230 gtk_widget_queue_resize (tree_column->tree_view);
1234 /* Button signal handlers
1238 pspp_sheet_view_column_button_event (GtkWidget *widget,
1242 PsppSheetViewColumn *column = (PsppSheetViewColumn *) data;
1244 g_return_val_if_fail (event != NULL, FALSE);
1246 if (event->type == GDK_BUTTON_PRESS &&
1247 column->reorderable &&
1248 ((GdkEventButton *)event)->button == 1)
1250 column->maybe_reordered = TRUE;
1251 gdk_window_get_pointer (GTK_BUTTON (widget)->event_window,
1255 gtk_widget_grab_focus (widget);
1258 if (event->type == GDK_BUTTON_RELEASE ||
1259 event->type == GDK_LEAVE_NOTIFY)
1260 column->maybe_reordered = FALSE;
1262 if (event->type == GDK_MOTION_NOTIFY &&
1263 column->maybe_reordered &&
1264 (gtk_drag_check_threshold (widget,
1267 (gint) ((GdkEventMotion *)event)->x,
1268 (gint) ((GdkEventMotion *)event)->y)))
1270 column->maybe_reordered = FALSE;
1271 _pspp_sheet_view_column_start_drag (PSPP_SHEET_VIEW (column->tree_view), column);
1274 if (column->clickable == FALSE)
1276 switch (event->type)
1278 case GDK_MOTION_NOTIFY:
1279 case GDK_BUTTON_RELEASE:
1280 case GDK_ENTER_NOTIFY:
1281 case GDK_LEAVE_NOTIFY:
1291 all_rows_selected (PsppSheetView *sheet_view)
1293 PsppSheetSelection *selection = sheet_view->priv->selection;
1294 gint n_rows, n_selected_rows;
1296 n_rows = sheet_view->priv->row_count;
1297 n_selected_rows = pspp_sheet_selection_count_selected_rows (selection);
1299 return n_rows > 0 && n_selected_rows >= n_rows;
1303 on_pspp_sheet_view_column_button_press_event (PsppSheetViewColumn *column,
1304 GdkEventButton *event)
1306 PsppSheetView *sheet_view = PSPP_SHEET_VIEW (column->tree_view);
1307 PsppSheetSelection *selection;
1308 GSignalInvocationHint *hint;
1311 /* We only want to run first, not last, but combining that with return type
1312 `gboolean' makes GObject warn, so just ignore the run_last call. */
1313 hint = g_signal_get_invocation_hint (column);
1314 g_return_val_if_fail (hint != NULL, FALSE);
1315 if (hint->run_type != G_SIGNAL_RUN_FIRST)
1318 g_return_val_if_fail (sheet_view != NULL, FALSE);
1320 selection = sheet_view->priv->selection;
1321 g_return_val_if_fail (selection != NULL, FALSE);
1323 if (pspp_sheet_selection_get_mode (selection) != PSPP_SHEET_SELECTION_RECTANGLE)
1326 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
1327 if (event->type == GDK_BUTTON_PRESS && event->button == 3)
1329 if (pspp_sheet_selection_count_selected_columns (selection) <= 1
1330 || !all_rows_selected (sheet_view))
1332 pspp_sheet_selection_select_all (selection);
1333 pspp_sheet_selection_unselect_all_columns (selection);
1334 pspp_sheet_selection_select_column (selection, column);
1335 sheet_view->priv->anchor_column = column;
1339 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
1340 && modifiers == GDK_CONTROL_MASK)
1342 gboolean is_selected;
1344 if (!all_rows_selected (sheet_view))
1346 pspp_sheet_selection_select_all (selection);
1347 pspp_sheet_selection_unselect_all_columns (selection);
1349 sheet_view->priv->anchor_column = column;
1351 is_selected = pspp_sheet_view_column_get_selected (column);
1352 pspp_sheet_view_column_set_selected (column, !is_selected);
1356 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
1357 && modifiers == GDK_SHIFT_MASK)
1359 if (!all_rows_selected (sheet_view))
1361 pspp_sheet_selection_select_all (selection);
1362 pspp_sheet_selection_unselect_all_columns (selection);
1363 sheet_view->priv->anchor_column = column;
1365 else if (sheet_view->priv->anchor_column == NULL)
1366 sheet_view->priv->anchor_column = column;
1368 pspp_sheet_selection_unselect_all_columns (selection);
1369 pspp_sheet_selection_select_column_range (selection,
1370 sheet_view->priv->anchor_column,
1379 on_pspp_sheet_view_column_button_clicked (PsppSheetViewColumn *column)
1381 PsppSheetSelection *selection;
1382 PsppSheetView *sheet_view;
1384 sheet_view = PSPP_SHEET_VIEW (pspp_sheet_view_column_get_tree_view (column));
1385 selection = pspp_sheet_view_get_selection (sheet_view);
1386 if (pspp_sheet_selection_get_mode (selection) == PSPP_SHEET_SELECTION_RECTANGLE)
1388 pspp_sheet_selection_select_all (selection);
1389 if (pspp_sheet_view_column_get_row_head (column))
1390 pspp_sheet_selection_select_all_columns (selection);
1393 pspp_sheet_selection_unselect_all_columns (selection);
1394 pspp_sheet_selection_select_column (selection, column);
1396 sheet_view->priv->anchor_column = column;
1403 pspp_sheet_view_column_button_clicked (GtkWidget *widget, gpointer data)
1405 PsppSheetViewColumn *column = data;
1408 g_signal_emit (column, tree_column_signals[CLICKED], 0, &handled);
1412 pspp_sheet_view_column_button_popup_menu (GtkWidget *widget, gpointer data)
1414 g_signal_emit_by_name (data, "popup-menu");
1418 pspp_sheet_view_column_mnemonic_activate (GtkWidget *widget,
1419 gboolean group_cycling,
1422 PsppSheetViewColumn *column = (PsppSheetViewColumn *)data;
1424 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), FALSE);
1426 PSPP_SHEET_VIEW (column->tree_view)->priv->focus_column = column;
1427 if (column->clickable)
1428 gtk_button_clicked (GTK_BUTTON (column->button));
1429 else if (gtk_widget_get_can_focus (column->button))
1430 gtk_widget_grab_focus (column->button);
1432 gtk_widget_grab_focus (column->tree_view);
1438 pspp_sheet_view_model_sort_column_changed (GtkTreeSortable *sortable,
1439 PsppSheetViewColumn *column)
1441 gint sort_column_id;
1444 if (gtk_tree_sortable_get_sort_column_id (sortable,
1448 if (sort_column_id == column->sort_column_id)
1450 pspp_sheet_view_column_set_sort_indicator (column, TRUE);
1451 pspp_sheet_view_column_set_sort_order (column, order);
1455 pspp_sheet_view_column_set_sort_indicator (column, FALSE);
1460 pspp_sheet_view_column_set_sort_indicator (column, FALSE);
1465 pspp_sheet_view_column_sort (PsppSheetViewColumn *tree_column,
1468 gint sort_column_id;
1470 gboolean has_sort_column;
1471 gboolean has_default_sort_func;
1473 g_return_if_fail (tree_column->tree_view != NULL);
1476 gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model),
1479 has_default_sort_func =
1480 gtk_tree_sortable_has_default_sort_func (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model));
1482 if (has_sort_column &&
1483 sort_column_id == tree_column->sort_column_id)
1485 if (order == GTK_SORT_ASCENDING)
1486 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model),
1487 tree_column->sort_column_id,
1488 GTK_SORT_DESCENDING);
1489 else if (order == GTK_SORT_DESCENDING && has_default_sort_func)
1490 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model),
1491 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
1492 GTK_SORT_ASCENDING);
1494 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model),
1495 tree_column->sort_column_id,
1496 GTK_SORT_ASCENDING);
1500 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model),
1501 tree_column->sort_column_id,
1502 GTK_SORT_ASCENDING);
1508 pspp_sheet_view_column_setup_sort_column_id_callback (PsppSheetViewColumn *tree_column)
1510 GtkTreeModel *model;
1512 if (tree_column->tree_view == NULL)
1515 model = pspp_sheet_view_get_model (PSPP_SHEET_VIEW (tree_column->tree_view));
1520 if (GTK_IS_TREE_SORTABLE (model) &&
1521 tree_column->sort_column_id != -1)
1523 gint real_sort_column_id;
1524 GtkSortType real_order;
1526 if (tree_column->sort_column_changed_signal == 0)
1527 tree_column->sort_column_changed_signal =
1528 g_signal_connect (model, "sort-column-changed",
1529 G_CALLBACK (pspp_sheet_view_model_sort_column_changed),
1532 if (gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model),
1533 &real_sort_column_id,
1535 (real_sort_column_id == tree_column->sort_column_id))
1537 pspp_sheet_view_column_set_sort_indicator (tree_column, TRUE);
1538 pspp_sheet_view_column_set_sort_order (tree_column, real_order);
1542 pspp_sheet_view_column_set_sort_indicator (tree_column, FALSE);
1548 /* Exported Private Functions.
1549 * These should only be called by gtktreeview.c or gtktreeviewcolumn.c
1553 _pspp_sheet_view_column_realize_button (PsppSheetViewColumn *column)
1555 PsppSheetView *tree_view;
1557 guint attributes_mask;
1560 tree_view = (PsppSheetView *)column->tree_view;
1561 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1563 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
1564 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
1565 g_return_if_fail (tree_view->priv->header_window != NULL);
1566 if (!column->need_button || !column->button)
1569 g_return_if_fail (column->button != NULL);
1571 gtk_widget_set_parent_window (column->button, tree_view->priv->header_window);
1573 if (column->visible)
1574 gtk_widget_show (column->button);
1576 attr.window_type = GDK_WINDOW_CHILD;
1577 attr.wclass = GDK_INPUT_ONLY;
1578 attr.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
1579 attr.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
1580 attr.event_mask = gtk_widget_get_events (GTK_WIDGET (tree_view)) |
1581 (GDK_BUTTON_PRESS_MASK |
1582 GDK_BUTTON_RELEASE_MASK |
1583 GDK_POINTER_MOTION_MASK |
1584 GDK_POINTER_MOTION_HINT_MASK |
1585 GDK_KEY_PRESS_MASK);
1586 attributes_mask = GDK_WA_CURSOR | GDK_WA_X | GDK_WA_Y;
1587 attr.cursor = gdk_cursor_new_for_display (gdk_drawable_get_display (tree_view->priv->header_window),
1588 GDK_SB_H_DOUBLE_ARROW);
1590 attr.width = TREE_VIEW_DRAG_WIDTH;
1591 attr.height = tree_view->priv->header_height;
1593 attr.x = (column->button->allocation.x + (rtl ? 0 : column->button->allocation.width)) - TREE_VIEW_DRAG_WIDTH / 2;
1594 column->window = gdk_window_new (tree_view->priv->header_window,
1595 &attr, attributes_mask);
1596 gdk_window_set_user_data (column->window, tree_view);
1598 pspp_sheet_view_column_update_button (column);
1600 gdk_cursor_unref (attr.cursor);
1604 _pspp_sheet_view_column_unrealize_button (PsppSheetViewColumn *column)
1606 g_return_if_fail (column != NULL);
1607 if (column->window != NULL)
1609 gdk_window_set_user_data (column->window, NULL);
1610 gdk_window_destroy (column->window);
1611 column->window = NULL;
1616 _pspp_sheet_view_column_unset_model (PsppSheetViewColumn *column,
1617 GtkTreeModel *old_model)
1619 if (column->sort_column_changed_signal)
1621 g_signal_handler_disconnect (old_model,
1622 column->sort_column_changed_signal);
1623 column->sort_column_changed_signal = 0;
1625 pspp_sheet_view_column_set_sort_indicator (column, FALSE);
1629 _pspp_sheet_view_column_set_tree_view (PsppSheetViewColumn *column,
1630 PsppSheetView *tree_view)
1632 g_assert (column->tree_view == NULL);
1634 column->tree_view = GTK_WIDGET (tree_view);
1635 if (column->need_button)
1636 pspp_sheet_view_column_create_button (column);
1638 column->property_changed_signal =
1639 g_signal_connect_swapped (tree_view,
1641 G_CALLBACK (pspp_sheet_view_column_setup_sort_column_id_callback),
1644 pspp_sheet_view_column_setup_sort_column_id_callback (column);
1648 _pspp_sheet_view_column_unset_tree_view (PsppSheetViewColumn *column)
1650 if (column->tree_view && column->button)
1652 gtk_container_remove (GTK_CONTAINER (column->tree_view), column->button);
1654 if (column->property_changed_signal)
1656 g_signal_handler_disconnect (column->tree_view, column->property_changed_signal);
1657 column->property_changed_signal = 0;
1660 if (column->sort_column_changed_signal)
1662 g_signal_handler_disconnect (pspp_sheet_view_get_model (PSPP_SHEET_VIEW (column->tree_view)),
1663 column->sort_column_changed_signal);
1664 column->sort_column_changed_signal = 0;
1667 column->tree_view = NULL;
1668 column->button = NULL;
1672 _pspp_sheet_view_column_has_editable_cell (PsppSheetViewColumn *column)
1676 for (list = column->cell_list; list; list = list->next)
1677 if (((PsppSheetViewColumnCellInfo *)list->data)->cell->mode ==
1678 GTK_CELL_RENDERER_MODE_EDITABLE)
1684 /* gets cell being edited */
1686 _pspp_sheet_view_column_get_edited_cell (PsppSheetViewColumn *column)
1690 for (list = column->cell_list; list; list = list->next)
1691 if (((PsppSheetViewColumnCellInfo *)list->data)->in_editing_mode)
1692 return ((PsppSheetViewColumnCellInfo *)list->data)->cell;
1698 _pspp_sheet_view_column_count_special_cells (PsppSheetViewColumn *column)
1703 for (list = column->cell_list; list; list = list->next)
1705 PsppSheetViewColumnCellInfo *cellinfo = list->data;
1707 if ((cellinfo->cell->mode == GTK_CELL_RENDERER_MODE_EDITABLE ||
1708 cellinfo->cell->mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE) &&
1709 cellinfo->cell->visible)
1717 _pspp_sheet_view_column_get_cell_at_pos (PsppSheetViewColumn *column,
1723 list = pspp_sheet_view_column_cell_first (column);
1724 for (; list; list = pspp_sheet_view_column_cell_next (column, list))
1726 PsppSheetViewColumnCellInfo *cellinfo = list->data;
1727 if (current_x <= x && x <= current_x + cellinfo->real_width)
1728 return cellinfo->cell;
1729 current_x += cellinfo->real_width;
1735 /* Public Functions */
1739 * pspp_sheet_view_column_new:
1741 * Creates a new #PsppSheetViewColumn.
1743 * Return value: A newly created #PsppSheetViewColumn.
1745 PsppSheetViewColumn *
1746 pspp_sheet_view_column_new (void)
1748 PsppSheetViewColumn *tree_column;
1750 tree_column = g_object_new (PSPP_TYPE_SHEET_VIEW_COLUMN, NULL);
1756 * pspp_sheet_view_column_new_with_attributes:
1757 * @title: The title to set the header to.
1758 * @cell: The #GtkCellRenderer.
1759 * @Varargs: A %NULL-terminated list of attributes.
1761 * Creates a new #PsppSheetViewColumn with a number of default values. This is
1762 * equivalent to calling pspp_sheet_view_column_set_title(),
1763 * pspp_sheet_view_column_pack_start(), and
1764 * pspp_sheet_view_column_set_attributes() on the newly created #PsppSheetViewColumn.
1766 * Here's a simple example:
1768 * enum { TEXT_COLUMN, COLOR_COLUMN, N_COLUMNS };
1771 * PsppSheetViewColumn *column;
1772 * GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
1774 * column = pspp_sheet_view_column_new_with_attributes ("Title",
1776 * "text", TEXT_COLUMN,
1777 * "foreground", COLOR_COLUMN,
1782 * Return value: A newly created #PsppSheetViewColumn.
1784 PsppSheetViewColumn *
1785 pspp_sheet_view_column_new_with_attributes (const gchar *title,
1786 GtkCellRenderer *cell,
1789 PsppSheetViewColumn *retval;
1792 retval = pspp_sheet_view_column_new ();
1794 pspp_sheet_view_column_set_title (retval, title);
1795 pspp_sheet_view_column_pack_start (retval, cell, TRUE);
1797 va_start (args, cell);
1798 pspp_sheet_view_column_set_attributesv (retval, cell, args);
1804 static PsppSheetViewColumnCellInfo *
1805 pspp_sheet_view_column_get_cell_info (PsppSheetViewColumn *tree_column,
1806 GtkCellRenderer *cell_renderer)
1809 for (list = tree_column->cell_list; list; list = list->next)
1810 if (((PsppSheetViewColumnCellInfo *)list->data)->cell == cell_renderer)
1811 return (PsppSheetViewColumnCellInfo *) list->data;
1817 * pspp_sheet_view_column_pack_start:
1818 * @tree_column: A #PsppSheetViewColumn.
1819 * @cell: The #GtkCellRenderer.
1820 * @expand: %TRUE if @cell is to be given extra space allocated to @tree_column.
1822 * Packs the @cell into the beginning of the column. If @expand is %FALSE, then
1823 * the @cell is allocated no more space than it needs. Any unused space is divided
1824 * evenly between cells for which @expand is %TRUE.
1827 pspp_sheet_view_column_pack_start (PsppSheetViewColumn *tree_column,
1828 GtkCellRenderer *cell,
1831 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (tree_column), cell, expand);
1835 * pspp_sheet_view_column_pack_end:
1836 * @tree_column: A #PsppSheetViewColumn.
1837 * @cell: The #GtkCellRenderer.
1838 * @expand: %TRUE if @cell is to be given extra space allocated to @tree_column.
1840 * Adds the @cell to end of the column. If @expand is %FALSE, then the @cell
1841 * is allocated no more space than it needs. Any unused space is divided
1842 * evenly between cells for which @expand is %TRUE.
1845 pspp_sheet_view_column_pack_end (PsppSheetViewColumn *tree_column,
1846 GtkCellRenderer *cell,
1849 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (tree_column), cell, expand);
1853 * pspp_sheet_view_column_clear:
1854 * @tree_column: A #PsppSheetViewColumn
1856 * Unsets all the mappings on all renderers on the @tree_column.
1859 pspp_sheet_view_column_clear (PsppSheetViewColumn *tree_column)
1861 gtk_cell_layout_clear (GTK_CELL_LAYOUT (tree_column));
1865 pspp_sheet_view_column_cell_layout_get_cells (GtkCellLayout *layout)
1867 PsppSheetViewColumn *tree_column = PSPP_SHEET_VIEW_COLUMN (layout);
1868 GList *retval = NULL, *list;
1870 g_return_val_if_fail (tree_column != NULL, NULL);
1872 for (list = tree_column->cell_list; list; list = list->next)
1874 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *)list->data;
1876 retval = g_list_append (retval, info->cell);
1883 * pspp_sheet_view_column_get_cell_renderers:
1884 * @tree_column: A #PsppSheetViewColumn
1886 * Returns a newly-allocated #GList of all the cell renderers in the column,
1887 * in no particular order. The list must be freed with g_list_free().
1889 * Return value: A list of #GtkCellRenderers
1891 * Deprecated: 2.18: use gtk_cell_layout_get_cells() instead.
1894 pspp_sheet_view_column_get_cell_renderers (PsppSheetViewColumn *tree_column)
1896 return pspp_sheet_view_column_cell_layout_get_cells (GTK_CELL_LAYOUT (tree_column));
1900 * pspp_sheet_view_column_add_attribute:
1901 * @tree_column: A #PsppSheetViewColumn.
1902 * @cell_renderer: the #GtkCellRenderer to set attributes on
1903 * @attribute: An attribute on the renderer
1904 * @column: The column position on the model to get the attribute from.
1906 * Adds an attribute mapping to the list in @tree_column. The @column is the
1907 * column of the model to get a value from, and the @attribute is the
1908 * parameter on @cell_renderer to be set from the value. So for example
1909 * if column 2 of the model contains strings, you could have the
1910 * "text" attribute of a #GtkCellRendererText get its values from
1914 pspp_sheet_view_column_add_attribute (PsppSheetViewColumn *tree_column,
1915 GtkCellRenderer *cell_renderer,
1916 const gchar *attribute,
1919 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (tree_column),
1920 cell_renderer, attribute, column);
1924 pspp_sheet_view_column_set_attributesv (PsppSheetViewColumn *tree_column,
1925 GtkCellRenderer *cell_renderer,
1931 attribute = va_arg (args, gchar *);
1933 pspp_sheet_view_column_clear_attributes (tree_column, cell_renderer);
1935 while (attribute != NULL)
1937 column = va_arg (args, gint);
1938 pspp_sheet_view_column_add_attribute (tree_column, cell_renderer, attribute, column);
1939 attribute = va_arg (args, gchar *);
1944 * pspp_sheet_view_column_set_attributes:
1945 * @tree_column: A #PsppSheetViewColumn.
1946 * @cell_renderer: the #GtkCellRenderer we're setting the attributes of
1947 * @Varargs: A %NULL-terminated list of attributes.
1949 * Sets the attributes in the list as the attributes of @tree_column.
1950 * The attributes should be in attribute/column order, as in
1951 * pspp_sheet_view_column_add_attribute(). All existing attributes
1952 * are removed, and replaced with the new attributes.
1955 pspp_sheet_view_column_set_attributes (PsppSheetViewColumn *tree_column,
1956 GtkCellRenderer *cell_renderer,
1961 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
1962 g_return_if_fail (GTK_IS_CELL_RENDERER (cell_renderer));
1963 g_return_if_fail (pspp_sheet_view_column_get_cell_info (tree_column, cell_renderer));
1965 va_start (args, cell_renderer);
1966 pspp_sheet_view_column_set_attributesv (tree_column, cell_renderer, args);
1972 * pspp_sheet_view_column_set_cell_data_func:
1973 * @tree_column: A #PsppSheetViewColumn
1974 * @cell_renderer: A #GtkCellRenderer
1975 * @func: The #PsppSheetViewColumnFunc to use.
1976 * @func_data: The user data for @func.
1977 * @destroy: The destroy notification for @func_data
1979 * Sets the #PsppSheetViewColumnFunc to use for the column. This
1980 * function is used instead of the standard attributes mapping for
1981 * setting the column value, and should set the value of @tree_column's
1982 * cell renderer as appropriate. @func may be %NULL to remove an
1986 pspp_sheet_view_column_set_cell_data_func (PsppSheetViewColumn *tree_column,
1987 GtkCellRenderer *cell_renderer,
1988 PsppSheetCellDataFunc func,
1990 GDestroyNotify destroy)
1992 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (tree_column),
1994 (GtkCellLayoutDataFunc)func,
1995 func_data, destroy);
2000 * pspp_sheet_view_column_clear_attributes:
2001 * @tree_column: a #PsppSheetViewColumn
2002 * @cell_renderer: a #GtkCellRenderer to clear the attribute mapping on.
2004 * Clears all existing attributes previously set with
2005 * pspp_sheet_view_column_set_attributes().
2008 pspp_sheet_view_column_clear_attributes (PsppSheetViewColumn *tree_column,
2009 GtkCellRenderer *cell_renderer)
2011 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (tree_column),
2016 * pspp_sheet_view_column_set_spacing:
2017 * @tree_column: A #PsppSheetViewColumn.
2018 * @spacing: distance between cell renderers in pixels.
2020 * Sets the spacing field of @tree_column, which is the number of pixels to
2021 * place between cell renderers packed into it.
2024 pspp_sheet_view_column_set_spacing (PsppSheetViewColumn *tree_column,
2027 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2028 g_return_if_fail (spacing >= 0);
2030 if (tree_column->spacing == spacing)
2033 tree_column->spacing = spacing;
2034 if (tree_column->tree_view)
2035 _pspp_sheet_view_column_cell_set_dirty (tree_column);
2039 * pspp_sheet_view_column_get_spacing:
2040 * @tree_column: A #PsppSheetViewColumn.
2042 * Returns the spacing of @tree_column.
2044 * Return value: the spacing of @tree_column.
2047 pspp_sheet_view_column_get_spacing (PsppSheetViewColumn *tree_column)
2049 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0);
2051 return tree_column->spacing;
2054 /* Options for manipulating the columns */
2057 * pspp_sheet_view_column_set_visible:
2058 * @tree_column: A #PsppSheetViewColumn.
2059 * @visible: %TRUE if the @tree_column is visible.
2061 * Sets the visibility of @tree_column.
2064 pspp_sheet_view_column_set_visible (PsppSheetViewColumn *tree_column,
2067 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2069 visible = !! visible;
2071 if (tree_column->visible == visible)
2074 tree_column->visible = visible;
2076 if (tree_column->visible)
2077 _pspp_sheet_view_column_cell_set_dirty (tree_column);
2079 pspp_sheet_view_column_update_button (tree_column);
2080 g_object_notify (G_OBJECT (tree_column), "visible");
2084 * pspp_sheet_view_column_get_visible:
2085 * @tree_column: A #PsppSheetViewColumn.
2087 * Returns %TRUE if @tree_column is visible.
2089 * Return value: whether the column is visible or not. If it is visible, then
2090 * the tree will show the column.
2093 pspp_sheet_view_column_get_visible (PsppSheetViewColumn *tree_column)
2095 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2097 return tree_column->visible;
2101 * pspp_sheet_view_column_set_resizable:
2102 * @tree_column: A #PsppSheetViewColumn
2103 * @resizable: %TRUE, if the column can be resized
2105 * If @resizable is %TRUE, then the user can explicitly resize the column by
2106 * grabbing the outer edge of the column button.
2109 pspp_sheet_view_column_set_resizable (PsppSheetViewColumn *tree_column,
2112 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2114 resizable = !! resizable;
2116 if (tree_column->resizable == resizable)
2119 tree_column->resizable = resizable;
2121 pspp_sheet_view_column_update_button (tree_column);
2123 g_object_notify (G_OBJECT (tree_column), "resizable");
2127 * pspp_sheet_view_column_get_resizable:
2128 * @tree_column: A #PsppSheetViewColumn
2130 * Returns %TRUE if the @tree_column can be resized by the end user.
2132 * Return value: %TRUE, if the @tree_column can be resized.
2135 pspp_sheet_view_column_get_resizable (PsppSheetViewColumn *tree_column)
2137 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2139 return tree_column->resizable;
2144 * pspp_sheet_view_column_get_width:
2145 * @tree_column: A #PsppSheetViewColumn.
2147 * Returns the current size of @tree_column in pixels.
2149 * Return value: The current width of @tree_column.
2152 pspp_sheet_view_column_get_width (PsppSheetViewColumn *tree_column)
2154 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0);
2156 return tree_column->width;
2160 * pspp_sheet_view_column_set_fixed_width:
2161 * @tree_column: A #PsppSheetViewColumn.
2162 * @fixed_width: The size to set @tree_column to. Must be greater than 0.
2164 * Sets the size of the column in pixels. The size of the column is clamped to
2165 * the min/max width for the column. Please note that the min/max width of the
2166 * column doesn't actually affect the "fixed_width" property of the widget, just
2167 * the actual size when displayed.
2170 pspp_sheet_view_column_set_fixed_width (PsppSheetViewColumn *tree_column,
2173 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2174 g_return_if_fail (fixed_width > 0);
2176 tree_column->fixed_width = fixed_width;
2177 tree_column->use_resized_width = FALSE;
2179 if (tree_column->tree_view &&
2180 gtk_widget_get_realized (tree_column->tree_view))
2182 gtk_widget_queue_resize (tree_column->tree_view);
2185 g_object_notify (G_OBJECT (tree_column), "fixed-width");
2189 * pspp_sheet_view_column_get_fixed_width:
2190 * @tree_column: a #PsppSheetViewColumn
2192 * Gets the fixed width of the column. This value is only meaning may not be
2193 * the actual width of the column on the screen, just what is requested.
2195 * Return value: the fixed width of the column
2198 pspp_sheet_view_column_get_fixed_width (PsppSheetViewColumn *tree_column)
2200 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0);
2202 return tree_column->fixed_width;
2206 * pspp_sheet_view_column_set_min_width:
2207 * @tree_column: A #PsppSheetViewColumn.
2208 * @min_width: The minimum width of the column in pixels, or -1.
2210 * Sets the minimum width of the @tree_column. If @min_width is -1, then the
2211 * minimum width is unset.
2214 pspp_sheet_view_column_set_min_width (PsppSheetViewColumn *tree_column,
2217 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2218 g_return_if_fail (min_width >= -1);
2220 if (min_width == tree_column->min_width)
2223 if (tree_column->visible &&
2224 tree_column->tree_view != NULL &&
2225 gtk_widget_get_realized (tree_column->tree_view))
2227 if (min_width > tree_column->width)
2228 gtk_widget_queue_resize (tree_column->tree_view);
2231 tree_column->min_width = min_width;
2232 g_object_freeze_notify (G_OBJECT (tree_column));
2233 if (tree_column->max_width != -1 && tree_column->max_width < min_width)
2235 tree_column->max_width = min_width;
2236 g_object_notify (G_OBJECT (tree_column), "max-width");
2238 g_object_notify (G_OBJECT (tree_column), "min-width");
2239 g_object_thaw_notify (G_OBJECT (tree_column));
2243 * pspp_sheet_view_column_get_min_width:
2244 * @tree_column: A #PsppSheetViewColumn.
2246 * Returns the minimum width in pixels of the @tree_column, or -1 if no minimum
2249 * Return value: The minimum width of the @tree_column.
2252 pspp_sheet_view_column_get_min_width (PsppSheetViewColumn *tree_column)
2254 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), -1);
2256 return tree_column->min_width;
2260 * pspp_sheet_view_column_set_max_width:
2261 * @tree_column: A #PsppSheetViewColumn.
2262 * @max_width: The maximum width of the column in pixels, or -1.
2264 * Sets the maximum width of the @tree_column. If @max_width is -1, then the
2265 * maximum width is unset. Note, the column can actually be wider than max
2266 * width if it's the last column in a view. In this case, the column expands to
2267 * fill any extra space.
2270 pspp_sheet_view_column_set_max_width (PsppSheetViewColumn *tree_column,
2273 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2274 g_return_if_fail (max_width >= -1);
2276 if (max_width == tree_column->max_width)
2279 if (tree_column->visible &&
2280 tree_column->tree_view != NULL &&
2281 gtk_widget_get_realized (tree_column->tree_view))
2283 if (max_width != -1 && max_width < tree_column->width)
2284 gtk_widget_queue_resize (tree_column->tree_view);
2287 tree_column->max_width = max_width;
2288 g_object_freeze_notify (G_OBJECT (tree_column));
2289 if (max_width != -1 && max_width < tree_column->min_width)
2291 tree_column->min_width = max_width;
2292 g_object_notify (G_OBJECT (tree_column), "min-width");
2294 g_object_notify (G_OBJECT (tree_column), "max-width");
2295 g_object_thaw_notify (G_OBJECT (tree_column));
2299 * pspp_sheet_view_column_get_max_width:
2300 * @tree_column: A #PsppSheetViewColumn.
2302 * Returns the maximum width in pixels of the @tree_column, or -1 if no maximum
2305 * Return value: The maximum width of the @tree_column.
2308 pspp_sheet_view_column_get_max_width (PsppSheetViewColumn *tree_column)
2310 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), -1);
2312 return tree_column->max_width;
2316 * pspp_sheet_view_column_clicked:
2317 * @tree_column: a #PsppSheetViewColumn
2319 * Emits the "clicked" signal on the column. This function will only work if
2320 * @tree_column is clickable.
2323 pspp_sheet_view_column_clicked (PsppSheetViewColumn *tree_column)
2325 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2327 if (tree_column->visible &&
2328 tree_column->button &&
2329 tree_column->clickable)
2330 gtk_button_clicked (GTK_BUTTON (tree_column->button));
2334 * pspp_sheet_view_column_set_title:
2335 * @tree_column: A #PsppSheetViewColumn.
2336 * @title: The title of the @tree_column.
2338 * Sets the title of the @tree_column. If a custom widget has been set, then
2339 * this value is ignored.
2342 pspp_sheet_view_column_set_title (PsppSheetViewColumn *tree_column,
2347 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2349 new_title = g_strdup (title);
2350 g_free (tree_column->title);
2351 tree_column->title = new_title;
2353 pspp_sheet_view_column_update_button (tree_column);
2354 g_object_notify (G_OBJECT (tree_column), "title");
2358 * pspp_sheet_view_column_get_title:
2359 * @tree_column: A #PsppSheetViewColumn.
2361 * Returns the title of the widget.
2363 * Return value: the title of the column. This string should not be
2364 * modified or freed.
2367 pspp_sheet_view_column_get_title (PsppSheetViewColumn *tree_column)
2369 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), NULL);
2371 return tree_column->title;
2375 * pspp_sheet_view_column_set_expand:
2376 * @tree_column: A #PsppSheetViewColumn
2377 * @expand: %TRUE if the column should take available extra space, %FALSE if not
2379 * Sets the column to take available extra space. This space is shared equally
2380 * amongst all columns that have the expand set to %TRUE. If no column has this
2381 * option set, then the last column gets all extra space. By default, every
2382 * column is created with this %FALSE.
2387 pspp_sheet_view_column_set_expand (PsppSheetViewColumn *tree_column,
2390 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2393 if (tree_column->expand == expand)
2395 tree_column->expand = expand;
2397 if (tree_column->visible &&
2398 tree_column->tree_view != NULL &&
2399 gtk_widget_get_realized (tree_column->tree_view))
2401 /* We want to continue using the original width of the
2402 * column that includes additional space added by the user
2403 * resizing the columns and possibly extra (expanded) space, which
2404 * are not included in the resized width.
2406 tree_column->use_resized_width = FALSE;
2408 gtk_widget_queue_resize (tree_column->tree_view);
2411 g_object_notify (G_OBJECT (tree_column), "expand");
2415 * pspp_sheet_view_column_get_expand:
2416 * @tree_column: a #PsppSheetViewColumn
2418 * Return %TRUE if the column expands to take any available space.
2420 * Return value: %TRUE, if the column expands
2425 pspp_sheet_view_column_get_expand (PsppSheetViewColumn *tree_column)
2427 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2429 return tree_column->expand;
2433 * pspp_sheet_view_column_set_clickable:
2434 * @tree_column: A #PsppSheetViewColumn.
2435 * @clickable: %TRUE if the header is active.
2437 * Sets the header to be active if @active is %TRUE. When the header is active,
2438 * then it can take keyboard focus, and can be clicked.
2441 pspp_sheet_view_column_set_clickable (PsppSheetViewColumn *tree_column,
2444 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2446 clickable = !! clickable;
2447 if (tree_column->clickable == clickable)
2450 tree_column->clickable = clickable;
2451 pspp_sheet_view_column_update_button (tree_column);
2452 g_object_notify (G_OBJECT (tree_column), "clickable");
2456 * pspp_sheet_view_column_get_clickable:
2457 * @tree_column: a #PsppSheetViewColumn
2459 * Returns %TRUE if the user can click on the header for the column.
2461 * Return value: %TRUE if user can click the column header.
2464 pspp_sheet_view_column_get_clickable (PsppSheetViewColumn *tree_column)
2466 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2468 return tree_column->clickable;
2472 * pspp_sheet_view_column_set_widget:
2473 * @tree_column: A #PsppSheetViewColumn.
2474 * @widget: (allow-none): A child #GtkWidget, or %NULL.
2476 * Sets the widget in the header to be @widget. If widget is %NULL, then the
2477 * header button is set with a #GtkLabel set to the title of @tree_column.
2480 pspp_sheet_view_column_set_widget (PsppSheetViewColumn *tree_column,
2483 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2484 g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
2487 g_object_ref_sink (widget);
2489 if (tree_column->child)
2490 g_object_unref (tree_column->child);
2492 tree_column->child = widget;
2493 pspp_sheet_view_column_update_button (tree_column);
2494 g_object_notify (G_OBJECT (tree_column), "widget");
2498 * pspp_sheet_view_column_get_widget:
2499 * @tree_column: A #PsppSheetViewColumn.
2501 * Returns the #GtkWidget in the button on the column header. If a custom
2502 * widget has not been set then %NULL is returned.
2504 * Return value: The #GtkWidget in the column header, or %NULL
2507 pspp_sheet_view_column_get_widget (PsppSheetViewColumn *tree_column)
2509 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), NULL);
2511 return tree_column->child;
2515 * pspp_sheet_view_column_set_alignment:
2516 * @tree_column: A #PsppSheetViewColumn.
2517 * @xalign: The alignment, which is between [0.0 and 1.0] inclusive.
2519 * Sets the alignment of the title or custom widget inside the column header.
2520 * The alignment determines its location inside the button -- 0.0 for left, 0.5
2521 * for center, 1.0 for right.
2524 pspp_sheet_view_column_set_alignment (PsppSheetViewColumn *tree_column,
2527 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2529 xalign = CLAMP (xalign, 0.0, 1.0);
2531 if (tree_column->xalign == xalign)
2534 tree_column->xalign = xalign;
2535 pspp_sheet_view_column_update_button (tree_column);
2536 g_object_notify (G_OBJECT (tree_column), "alignment");
2540 * pspp_sheet_view_column_get_alignment:
2541 * @tree_column: A #PsppSheetViewColumn.
2543 * Returns the current x alignment of @tree_column. This value can range
2544 * between 0.0 and 1.0.
2546 * Return value: The current alignent of @tree_column.
2549 pspp_sheet_view_column_get_alignment (PsppSheetViewColumn *tree_column)
2551 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0.5);
2553 return tree_column->xalign;
2557 * pspp_sheet_view_column_set_reorderable:
2558 * @tree_column: A #PsppSheetViewColumn
2559 * @reorderable: %TRUE, if the column can be reordered.
2561 * If @reorderable is %TRUE, then the column can be reordered by the end user
2562 * dragging the header.
2565 pspp_sheet_view_column_set_reorderable (PsppSheetViewColumn *tree_column,
2566 gboolean reorderable)
2568 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2571 pspp_sheet_view_column_set_clickable (tree_column, TRUE);*/
2573 reorderable = !!reorderable;
2574 if (tree_column->reorderable == reorderable)
2577 tree_column->reorderable = reorderable;
2578 pspp_sheet_view_column_update_button (tree_column);
2579 g_object_notify (G_OBJECT (tree_column), "reorderable");
2583 * pspp_sheet_view_column_get_reorderable:
2584 * @tree_column: A #PsppSheetViewColumn
2586 * Returns %TRUE if the @tree_column can be reordered by the user.
2588 * Return value: %TRUE if the @tree_column can be reordered by the user.
2591 pspp_sheet_view_column_get_reorderable (PsppSheetViewColumn *tree_column)
2593 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2595 return tree_column->reorderable;
2599 * pspp_sheet_view_column_set_quick_edit:
2600 * @tree_column: A #PsppSheetViewColumn
2601 * @quick_edit: If true, editing starts upon the first click in the column. If
2602 * false, the first click selects the column and a second click is needed to
2603 * begin editing. This has no effect on cells that are not editable.
2606 pspp_sheet_view_column_set_quick_edit (PsppSheetViewColumn *tree_column,
2607 gboolean quick_edit)
2609 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2611 quick_edit = !!quick_edit;
2612 if (tree_column->quick_edit != quick_edit)
2614 tree_column->quick_edit = quick_edit;
2615 g_object_notify (G_OBJECT (tree_column), "quick-edit");
2620 * pspp_sheet_view_column_get_quick_edit:
2621 * @tree_column: A #PsppSheetViewColumn
2623 * Returns %TRUE if editing starts upon the first click in the column. Returns
2624 * %FALSE, the first click selects the column and a second click is needed to
2625 * begin editing. This is not meaningful for cells that are not editable.
2627 * Return value: %TRUE if editing starts upon the first click.
2630 pspp_sheet_view_column_get_quick_edit (PsppSheetViewColumn *tree_column)
2632 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2634 return tree_column->quick_edit;
2639 * pspp_sheet_view_column_set_selected:
2640 * @tree_column: A #PsppSheetViewColumn
2641 * @selected: If true, the column is selected as part of a rectangular
2645 pspp_sheet_view_column_set_selected (PsppSheetViewColumn *tree_column,
2648 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2650 selected = !!selected;
2651 if (tree_column->selected != selected)
2653 PsppSheetSelection *selection;
2654 PsppSheetView *sheet_view;
2656 if (tree_column->tree_view != NULL)
2657 gtk_widget_queue_draw (GTK_WIDGET (tree_column->tree_view));
2658 tree_column->selected = selected;
2659 g_object_notify (G_OBJECT (tree_column), "selected");
2661 sheet_view = PSPP_SHEET_VIEW (pspp_sheet_view_column_get_tree_view (
2663 selection = pspp_sheet_view_get_selection (sheet_view);
2664 _pspp_sheet_selection_emit_changed (selection);
2669 * pspp_sheet_view_column_get_selected:
2670 * @tree_column: A #PsppSheetViewColumn
2672 * Returns %TRUE if the column is selected as part of a rectangular
2675 * Return value: %TRUE if the column is selected as part of a rectangular
2679 pspp_sheet_view_column_get_selected (PsppSheetViewColumn *tree_column)
2681 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2683 return tree_column->selected;
2687 * pspp_sheet_view_column_set_selectable:
2688 * @tree_column: A #PsppSheetViewColumn
2689 * @selectable: If true, the column may be selected as part of a rectangular
2693 pspp_sheet_view_column_set_selectable (PsppSheetViewColumn *tree_column,
2694 gboolean selectable)
2696 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2698 selectable = !!selectable;
2699 if (tree_column->selectable != selectable)
2701 if (tree_column->tree_view != NULL)
2702 gtk_widget_queue_draw (GTK_WIDGET (tree_column->tree_view));
2703 tree_column->selectable = selectable;
2704 g_object_notify (G_OBJECT (tree_column), "selectable");
2709 * pspp_sheet_view_column_get_selectable:
2710 * @tree_column: A #PsppSheetViewColumn
2712 * Returns %TRUE if the column may be selected as part of a rectangular
2715 * Return value: %TRUE if the column may be selected as part of a rectangular
2719 pspp_sheet_view_column_get_selectable (PsppSheetViewColumn *tree_column)
2721 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2723 return tree_column->selectable;
2728 * pspp_sheet_view_column_set_row_head:
2729 * @tree_column: A #PsppSheetViewColumn
2730 * @row_head: If true, the column is a "row head", analogous to a column head.
2731 * See the description of the row-head property for more information.
2734 pspp_sheet_view_column_set_row_head (PsppSheetViewColumn *tree_column,
2737 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2739 row_head = !!row_head;
2740 if (tree_column->row_head != row_head)
2742 tree_column->row_head = row_head;
2743 g_object_notify (G_OBJECT (tree_column), "row_head");
2748 * pspp_sheet_view_column_get_row_head:
2749 * @tree_column: A #PsppSheetViewColumn
2751 * Returns %TRUE if the column is a row head.
2753 * Return value: %TRUE if the column is a row head.
2756 pspp_sheet_view_column_get_row_head (PsppSheetViewColumn *tree_column)
2758 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2760 return tree_column->row_head;
2765 * pspp_sheet_view_column_set_tabbable:
2766 * @tree_column: A #PsppSheetViewColumn
2767 * @tabbable: If true, the column is "tabbable", meaning that Tab and Shift+Tab
2768 * in the sheet visit this column. If false, Tab and Shift+Tab skip this
2772 pspp_sheet_view_column_set_tabbable (PsppSheetViewColumn *tree_column,
2775 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2777 tabbable = !!tabbable;
2778 if (tree_column->tabbable != tabbable)
2780 tree_column->tabbable = tabbable;
2781 g_object_notify (G_OBJECT (tree_column), "tabbable");
2786 * pspp_sheet_view_column_get_tabbable:
2787 * @tree_column: A #PsppSheetViewColumn
2789 * Returns %TRUE if the column is tabbable.
2791 * Return value: %TRUE if the column is tabbable.
2794 pspp_sheet_view_column_get_tabbable (PsppSheetViewColumn *tree_column)
2796 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2798 return tree_column->tabbable;
2803 * pspp_sheet_view_column_set_sort_column_id:
2804 * @tree_column: a #PsppSheetViewColumn
2805 * @sort_column_id: The @sort_column_id of the model to sort on.
2807 * Sets the logical @sort_column_id that this column sorts on when this column
2808 * is selected for sorting. Doing so makes the column header clickable.
2811 pspp_sheet_view_column_set_sort_column_id (PsppSheetViewColumn *tree_column,
2812 gint sort_column_id)
2814 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2815 g_return_if_fail (sort_column_id >= -1);
2817 if (tree_column->sort_column_id == sort_column_id)
2820 tree_column->sort_column_id = sort_column_id;
2822 /* Handle unsetting the id */
2823 if (sort_column_id == -1)
2825 GtkTreeModel *model = pspp_sheet_view_get_model (PSPP_SHEET_VIEW (tree_column->tree_view));
2827 if (tree_column->sort_clicked_signal)
2829 g_signal_handler_disconnect (tree_column, tree_column->sort_clicked_signal);
2830 tree_column->sort_clicked_signal = 0;
2833 if (tree_column->sort_column_changed_signal)
2835 g_signal_handler_disconnect (model, tree_column->sort_column_changed_signal);
2836 tree_column->sort_column_changed_signal = 0;
2839 pspp_sheet_view_column_set_sort_order (tree_column, GTK_SORT_ASCENDING);
2840 pspp_sheet_view_column_set_sort_indicator (tree_column, FALSE);
2841 pspp_sheet_view_column_set_clickable (tree_column, FALSE);
2842 g_object_notify (G_OBJECT (tree_column), "sort-column-id");
2846 pspp_sheet_view_column_set_clickable (tree_column, TRUE);
2848 if (! tree_column->sort_clicked_signal)
2849 tree_column->sort_clicked_signal = g_signal_connect (tree_column,
2851 G_CALLBACK (pspp_sheet_view_column_sort),
2854 pspp_sheet_view_column_setup_sort_column_id_callback (tree_column);
2855 g_object_notify (G_OBJECT (tree_column), "sort-column-id");
2859 * pspp_sheet_view_column_get_sort_column_id:
2860 * @tree_column: a #PsppSheetViewColumn
2862 * Gets the logical @sort_column_id that the model sorts on when this
2863 * column is selected for sorting.
2864 * See pspp_sheet_view_column_set_sort_column_id().
2866 * Return value: the current @sort_column_id for this column, or -1 if
2867 * this column can't be used for sorting.
2870 pspp_sheet_view_column_get_sort_column_id (PsppSheetViewColumn *tree_column)
2872 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0);
2874 return tree_column->sort_column_id;
2878 * pspp_sheet_view_column_set_sort_indicator:
2879 * @tree_column: a #PsppSheetViewColumn
2880 * @setting: %TRUE to display an indicator that the column is sorted
2882 * Call this function with a @setting of %TRUE to display an arrow in
2883 * the header button indicating the column is sorted. Call
2884 * pspp_sheet_view_column_set_sort_order() to change the direction of
2889 pspp_sheet_view_column_set_sort_indicator (PsppSheetViewColumn *tree_column,
2892 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2894 setting = setting != FALSE;
2896 if (setting == tree_column->show_sort_indicator)
2899 tree_column->show_sort_indicator = setting;
2900 pspp_sheet_view_column_update_button (tree_column);
2901 g_object_notify (G_OBJECT (tree_column), "sort-indicator");
2905 * pspp_sheet_view_column_get_sort_indicator:
2906 * @tree_column: a #PsppSheetViewColumn
2908 * Gets the value set by pspp_sheet_view_column_set_sort_indicator().
2910 * Return value: whether the sort indicator arrow is displayed
2913 pspp_sheet_view_column_get_sort_indicator (PsppSheetViewColumn *tree_column)
2915 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2917 return tree_column->show_sort_indicator;
2921 * pspp_sheet_view_column_set_sort_order:
2922 * @tree_column: a #PsppSheetViewColumn
2923 * @order: sort order that the sort indicator should indicate
2925 * Changes the appearance of the sort indicator.
2927 * This <emphasis>does not</emphasis> actually sort the model. Use
2928 * pspp_sheet_view_column_set_sort_column_id() if you want automatic sorting
2929 * support. This function is primarily for custom sorting behavior, and should
2930 * be used in conjunction with gtk_tree_sortable_set_sort_column() to do
2931 * that. For custom models, the mechanism will vary.
2933 * The sort indicator changes direction to indicate normal sort or reverse sort.
2934 * Note that you must have the sort indicator enabled to see anything when
2935 * calling this function; see pspp_sheet_view_column_set_sort_indicator().
2938 pspp_sheet_view_column_set_sort_order (PsppSheetViewColumn *tree_column,
2941 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2943 if (order == tree_column->sort_order)
2946 tree_column->sort_order = order;
2947 pspp_sheet_view_column_update_button (tree_column);
2948 g_object_notify (G_OBJECT (tree_column), "sort-order");
2952 * pspp_sheet_view_column_get_sort_order:
2953 * @tree_column: a #PsppSheetViewColumn
2955 * Gets the value set by pspp_sheet_view_column_set_sort_order().
2957 * Return value: the sort order the sort indicator is indicating
2960 pspp_sheet_view_column_get_sort_order (PsppSheetViewColumn *tree_column)
2962 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0);
2964 return tree_column->sort_order;
2968 * pspp_sheet_view_column_cell_set_cell_data:
2969 * @tree_column: A #PsppSheetViewColumn.
2970 * @tree_model: The #GtkTreeModel to to get the cell renderers attributes from.
2971 * @iter: The #GtkTreeIter to to get the cell renderer's attributes from.
2973 * Sets the cell renderer based on the @tree_model and @iter. That is, for
2974 * every attribute mapping in @tree_column, it will get a value from the set
2975 * column on the @iter, and use that value to set the attribute on the cell
2976 * renderer. This is used primarily by the #PsppSheetView.
2979 pspp_sheet_view_column_cell_set_cell_data (PsppSheetViewColumn *tree_column,
2980 GtkTreeModel *tree_model,
2984 GValue value = { 0, };
2987 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2989 if (tree_model == NULL)
2992 for (cell_list = tree_column->cell_list; cell_list; cell_list = cell_list->next)
2994 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) cell_list->data;
2995 GObject *cell = (GObject *) info->cell;
2997 list = info->attributes;
2999 g_object_freeze_notify (cell);
3001 while (list && list->next)
3003 gtk_tree_model_get_value (tree_model, iter,
3004 GPOINTER_TO_INT (list->next->data),
3006 g_object_set_property (cell, (gchar *) list->data, &value);
3007 g_value_unset (&value);
3008 list = list->next->next;
3012 (* info->func) (tree_column, info->cell, tree_model, iter, info->func_data);
3013 g_object_thaw_notify (G_OBJECT (info->cell));
3019 * pspp_sheet_view_column_cell_get_size:
3020 * @tree_column: A #PsppSheetViewColumn.
3021 * @cell_area: (allow-none): The area a cell in the column will be allocated, or %NULL
3022 * @x_offset: (allow-none): location to return x offset of a cell relative to @cell_area, or %NULL
3023 * @y_offset: (allow-none): location to return y offset of a cell relative to @cell_area, or %NULL
3024 * @width: (allow-none): location to return width needed to render a cell, or %NULL
3025 * @height: (allow-none): location to return height needed to render a cell, or %NULL
3027 * Obtains the width and height needed to render the column. This is used
3028 * primarily by the #PsppSheetView.
3031 pspp_sheet_view_column_cell_get_size (PsppSheetViewColumn *tree_column,
3032 const GdkRectangle *cell_area,
3039 gboolean first_cell = TRUE;
3040 gint focus_line_width;
3042 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
3049 gtk_widget_style_get (tree_column->tree_view, "focus-line-width", &focus_line_width, NULL);
3051 for (list = tree_column->cell_list; list; list = list->next)
3053 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
3055 gint new_height = 0;
3057 g_object_get (info->cell, "visible", &visible, NULL);
3059 if (visible == FALSE)
3062 if (first_cell == FALSE && width)
3063 *width += tree_column->spacing;
3065 gtk_cell_renderer_get_size (info->cell,
3066 tree_column->tree_view,
3074 * height = MAX (*height, new_height + focus_line_width * 2);
3075 info->requested_width = MAX (info->requested_width, new_width + focus_line_width * 2);
3077 * width += info->requested_width;
3082 /* rendering, event handling and rendering focus are somewhat complicated, and
3083 * quite a bit of code. Rather than duplicate them, we put them together to
3084 * keep the code in one place.
3086 * To better understand what's going on, check out
3087 * docs/tree-column-sizing.png
3096 pspp_sheet_view_column_cell_process_action (PsppSheetViewColumn *tree_column,
3098 const GdkRectangle *background_area,
3099 const GdkRectangle *cell_area,
3102 const GdkRectangle *expose_area, /* RENDER */
3103 GdkRectangle *focus_rectangle, /* FOCUS */
3104 GtkCellEditable **editable_widget, /* EVENT */
3105 GdkEvent *event, /* EVENT */
3106 gchar *path_string) /* EVENT */
3109 GdkRectangle real_cell_area;
3110 GdkRectangle real_background_area;
3111 GdkRectangle real_expose_area = *cell_area;
3113 gint expand_cell_count = 0;
3114 gint full_requested_width = 0;
3116 gint min_x, min_y, max_x, max_y;
3117 gint focus_line_width;
3119 gint horizontal_separator;
3120 gboolean cursor_row = FALSE;
3121 gboolean first_cell = TRUE;
3123 /* If we have rtl text, we need to transform our areas */
3124 GdkRectangle rtl_cell_area;
3125 GdkRectangle rtl_background_area;
3132 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_column->tree_view)) == GTK_TEXT_DIR_RTL);
3133 special_cells = _pspp_sheet_view_column_count_special_cells (tree_column);
3135 if (special_cells > 1 && action == CELL_ACTION_FOCUS)
3137 PsppSheetViewColumnCellInfo *info = NULL;
3138 gboolean found_has_focus = FALSE;
3140 /* one should have focus */
3141 for (list = tree_column->cell_list; list; list = list->next)
3144 if (info && info->has_focus)
3146 found_has_focus = TRUE;
3151 if (!found_has_focus)
3153 /* give the first one focus */
3154 info = pspp_sheet_view_column_cell_first (tree_column)->data;
3155 info->has_focus = TRUE;
3159 cursor_row = flags & GTK_CELL_RENDERER_FOCUSED;
3161 gtk_widget_style_get (GTK_WIDGET (tree_column->tree_view),
3162 "focus-line-width", &focus_line_width,
3163 "horizontal-separator", &horizontal_separator,
3166 real_cell_area = *cell_area;
3167 real_background_area = *background_area;
3170 real_cell_area.x += focus_line_width;
3171 real_cell_area.y += focus_line_width;
3172 real_cell_area.height -= 2 * focus_line_width;
3175 depth = real_background_area.width - real_cell_area.width;
3177 depth = real_cell_area.x - real_background_area.x;
3179 /* Find out how much extra space we have to allocate */
3180 for (list = tree_column->cell_list; list; list = list->next)
3182 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *)list->data;
3184 if (! info->cell->visible)
3187 if (info->expand == TRUE)
3188 expand_cell_count ++;
3189 full_requested_width += info->requested_width;
3192 full_requested_width += tree_column->spacing;
3197 extra_space = cell_area->width - full_requested_width;
3198 if (extra_space < 0)
3200 else if (extra_space > 0 && expand_cell_count > 0)
3201 extra_space /= expand_cell_count;
3203 /* iterate list for GTK_PACK_START cells */
3204 for (list = tree_column->cell_list; list; list = list->next)
3206 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
3208 if (info->pack == GTK_PACK_END)
3211 if (! info->cell->visible)
3214 if ((info->has_focus || special_cells == 1) && cursor_row)
3215 flags |= GTK_CELL_RENDERER_FOCUSED;
3217 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3219 info->real_width = info->requested_width + (info->expand?extra_space:0);
3221 /* We constrain ourselves to only the width available */
3222 if (real_cell_area.x - focus_line_width + info->real_width > cell_area->x + cell_area->width)
3224 info->real_width = cell_area->x + cell_area->width - real_cell_area.x;
3227 if (real_cell_area.x > cell_area->x + cell_area->width)
3230 real_cell_area.width = info->real_width;
3231 real_cell_area.width -= 2 * focus_line_width;
3235 real_background_area.width = info->real_width + depth;
3239 /* fill the rest of background for the last cell */
3240 real_background_area.width = background_area->x + background_area->width - real_background_area.x;
3243 rtl_cell_area = real_cell_area;
3244 rtl_background_area = real_background_area;
3248 rtl_cell_area.x = cell_area->x + cell_area->width - (real_cell_area.x - cell_area->x) - real_cell_area.width;
3249 rtl_background_area.x = background_area->x + background_area->width - (real_background_area.x - background_area->x) - real_background_area.width;
3253 if (action == CELL_ACTION_RENDER)
3255 gtk_cell_renderer_render (info->cell,
3257 tree_column->tree_view,
3258 &rtl_background_area,
3264 else if (action == CELL_ACTION_FOCUS)
3266 gint x_offset, y_offset, width, height;
3268 gtk_cell_renderer_get_size (info->cell,
3269 tree_column->tree_view,
3271 &x_offset, &y_offset,
3274 if (special_cells > 1)
3276 if (info->has_focus)
3278 min_x = rtl_cell_area.x + x_offset;
3279 max_x = min_x + width;
3280 min_y = rtl_cell_area.y + y_offset;
3281 max_y = min_y + height;
3286 if (min_x > (rtl_cell_area.x + x_offset))
3287 min_x = rtl_cell_area.x + x_offset;
3288 if (max_x < rtl_cell_area.x + x_offset + width)
3289 max_x = rtl_cell_area.x + x_offset + width;
3290 if (min_y > (rtl_cell_area.y + y_offset))
3291 min_y = rtl_cell_area.y + y_offset;
3292 if (max_y < rtl_cell_area.y + y_offset + height)
3293 max_y = rtl_cell_area.y + y_offset + height;
3297 else if (action == CELL_ACTION_EVENT)
3299 gboolean try_event = FALSE;
3303 if (special_cells == 1)
3305 /* only 1 activatable cell -> whole column can activate */
3306 if (cell_area->x <= ((GdkEventButton *)event)->x &&
3307 cell_area->x + cell_area->width > ((GdkEventButton *)event)->x)
3310 else if (rtl_cell_area.x <= ((GdkEventButton *)event)->x &&
3311 rtl_cell_area.x + rtl_cell_area.width > ((GdkEventButton *)event)->x)
3312 /* only activate cell if the user clicked on an individual
3317 else if (special_cells > 1 && info->has_focus)
3319 else if (special_cells == 1)
3324 gboolean visible, mode;
3326 g_object_get (info->cell,
3327 "visible", &visible,
3330 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
3332 if (gtk_cell_renderer_activate (info->cell,
3334 tree_column->tree_view,
3336 &rtl_background_area,
3340 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3344 else if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
3347 gtk_cell_renderer_start_editing (info->cell,
3349 tree_column->tree_view,
3351 &rtl_background_area,
3355 if (*editable_widget != NULL)
3357 g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
3358 info->in_editing_mode = TRUE;
3359 pspp_sheet_view_column_focus_cell (tree_column, info->cell);
3361 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3369 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3371 real_cell_area.x += (real_cell_area.width + 2 * focus_line_width + tree_column->spacing);
3372 real_background_area.x += real_background_area.width + tree_column->spacing;
3374 /* Only needed for first cell */
3378 /* iterate list for PACK_END cells */
3379 for (list = g_list_last (tree_column->cell_list); list; list = list->prev)
3381 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
3383 if (info->pack == GTK_PACK_START)
3386 if (! info->cell->visible)
3389 if ((info->has_focus || special_cells == 1) && cursor_row)
3390 flags |= GTK_CELL_RENDERER_FOCUSED;
3392 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3394 info->real_width = info->requested_width + (info->expand?extra_space:0);
3396 /* We constrain ourselves to only the width available */
3397 if (real_cell_area.x - focus_line_width + info->real_width > cell_area->x + cell_area->width)
3399 info->real_width = cell_area->x + cell_area->width - real_cell_area.x;
3402 if (real_cell_area.x > cell_area->x + cell_area->width)
3405 real_cell_area.width = info->real_width;
3406 real_cell_area.width -= 2 * focus_line_width;
3407 real_background_area.width = info->real_width + depth;
3409 rtl_cell_area = real_cell_area;
3410 rtl_background_area = real_background_area;
3413 rtl_cell_area.x = cell_area->x + cell_area->width - (real_cell_area.x - cell_area->x) - real_cell_area.width;
3414 rtl_background_area.x = background_area->x + background_area->width - (real_background_area.x - background_area->x) - real_background_area.width;
3418 if (action == CELL_ACTION_RENDER)
3420 gtk_cell_renderer_render (info->cell,
3422 tree_column->tree_view,
3423 &rtl_background_area,
3429 else if (action == CELL_ACTION_FOCUS)
3431 gint x_offset, y_offset, width, height;
3433 gtk_cell_renderer_get_size (info->cell,
3434 tree_column->tree_view,
3436 &x_offset, &y_offset,
3439 if (special_cells > 1)
3441 if (info->has_focus)
3443 min_x = rtl_cell_area.x + x_offset;
3444 max_x = min_x + width;
3445 min_y = rtl_cell_area.y + y_offset;
3446 max_y = min_y + height;
3451 if (min_x > (rtl_cell_area.x + x_offset))
3452 min_x = rtl_cell_area.x + x_offset;
3453 if (max_x < rtl_cell_area.x + x_offset + width)
3454 max_x = rtl_cell_area.x + x_offset + width;
3455 if (min_y > (rtl_cell_area.y + y_offset))
3456 min_y = rtl_cell_area.y + y_offset;
3457 if (max_y < rtl_cell_area.y + y_offset + height)
3458 max_y = rtl_cell_area.y + y_offset + height;
3462 else if (action == CELL_ACTION_EVENT)
3464 gboolean try_event = FALSE;
3468 if (special_cells == 1)
3470 /* only 1 activatable cell -> whole column can activate */
3471 if (cell_area->x <= ((GdkEventButton *)event)->x &&
3472 cell_area->x + cell_area->width > ((GdkEventButton *)event)->x)
3475 else if (rtl_cell_area.x <= ((GdkEventButton *)event)->x &&
3476 rtl_cell_area.x + rtl_cell_area.width > ((GdkEventButton *)event)->x)
3477 /* only activate cell if the user clicked on an individual
3482 else if (special_cells > 1 && info->has_focus)
3484 else if (special_cells == 1)
3489 gboolean visible, mode;
3491 g_object_get (info->cell,
3492 "visible", &visible,
3495 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
3497 if (gtk_cell_renderer_activate (info->cell,
3499 tree_column->tree_view,
3501 &rtl_background_area,
3505 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3509 else if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
3512 gtk_cell_renderer_start_editing (info->cell,
3514 tree_column->tree_view,
3516 &rtl_background_area,
3520 if (*editable_widget != NULL)
3522 g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
3523 info->in_editing_mode = TRUE;
3524 pspp_sheet_view_column_focus_cell (tree_column, info->cell);
3526 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3533 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3535 real_cell_area.x += (real_cell_area.width + 2 * focus_line_width + tree_column->spacing);
3536 real_background_area.x += (real_background_area.width + tree_column->spacing);
3538 /* Only needed for first cell */
3542 /* fill focus_rectangle when required */
3543 if (action == CELL_ACTION_FOCUS)
3545 if (min_x >= max_x || min_y >= max_y)
3547 *focus_rectangle = *cell_area;
3548 /* don't change the focus_rectangle, just draw it nicely inside
3553 focus_rectangle->x = min_x - focus_line_width;
3554 focus_rectangle->y = min_y - focus_line_width;
3555 focus_rectangle->width = (max_x - min_x) + 2 * focus_line_width;
3556 focus_rectangle->height = (max_y - min_y) + 2 * focus_line_width;
3564 * pspp_sheet_view_column_cell_render:
3565 * @tree_column: A #PsppSheetViewColumn.
3566 * @window: a #GdkDrawable to draw to
3567 * @background_area: entire cell area (including tree expanders and maybe padding on the sides)
3568 * @cell_area: area normally rendered by a cell renderer
3569 * @expose_area: area that actually needs updating
3570 * @flags: flags that affect rendering
3572 * Renders the cell contained by #tree_column. This is used primarily by the
3576 _pspp_sheet_view_column_cell_render (PsppSheetViewColumn *tree_column,
3578 const GdkRectangle *background_area,
3579 const GdkRectangle *cell_area,
3580 const GdkRectangle *expose_area,
3583 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
3584 g_return_if_fail (background_area != NULL);
3585 g_return_if_fail (cell_area != NULL);
3586 g_return_if_fail (expose_area != NULL);
3588 pspp_sheet_view_column_cell_process_action (tree_column,
3595 NULL, NULL, NULL, NULL);
3599 _pspp_sheet_view_column_cell_event (PsppSheetViewColumn *tree_column,
3600 GtkCellEditable **editable_widget,
3603 const GdkRectangle *background_area,
3604 const GdkRectangle *cell_area,
3607 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
3609 return pspp_sheet_view_column_cell_process_action (tree_column,
3622 _pspp_sheet_view_column_get_focus_area (PsppSheetViewColumn *tree_column,
3623 const GdkRectangle *background_area,
3624 const GdkRectangle *cell_area,
3625 GdkRectangle *focus_area)
3627 pspp_sheet_view_column_cell_process_action (tree_column,
3639 /* cell list manipulation */
3641 pspp_sheet_view_column_cell_first (PsppSheetViewColumn *tree_column)
3643 GList *list = tree_column->cell_list;
3645 /* first GTK_PACK_START cell we find */
3646 for ( ; list; list = list->next)
3648 PsppSheetViewColumnCellInfo *info = list->data;
3649 if (info->pack == GTK_PACK_START)
3653 /* hmm, else the *last* GTK_PACK_END cell */
3654 list = g_list_last (tree_column->cell_list);
3656 for ( ; list; list = list->prev)
3658 PsppSheetViewColumnCellInfo *info = list->data;
3659 if (info->pack == GTK_PACK_END)
3667 pspp_sheet_view_column_cell_last (PsppSheetViewColumn *tree_column)
3669 GList *list = tree_column->cell_list;
3671 /* *first* GTK_PACK_END cell we find */
3672 for ( ; list ; list = list->next)
3674 PsppSheetViewColumnCellInfo *info = list->data;
3675 if (info->pack == GTK_PACK_END)
3679 /* hmm, else the last GTK_PACK_START cell */
3680 list = g_list_last (tree_column->cell_list);
3682 for ( ; list; list = list->prev)
3684 PsppSheetViewColumnCellInfo *info = list->data;
3685 if (info->pack == GTK_PACK_START)
3693 pspp_sheet_view_column_cell_next (PsppSheetViewColumn *tree_column,
3697 PsppSheetViewColumnCellInfo *info = current->data;
3699 if (info->pack == GTK_PACK_START)
3701 for (list = current->next; list; list = list->next)
3703 PsppSheetViewColumnCellInfo *inf = list->data;
3704 if (inf->pack == GTK_PACK_START)
3708 /* out of GTK_PACK_START cells, get *last* GTK_PACK_END one */
3709 list = g_list_last (tree_column->cell_list);
3710 for (; list; list = list->prev)
3712 PsppSheetViewColumnCellInfo *inf = list->data;
3713 if (inf->pack == GTK_PACK_END)
3718 for (list = current->prev; list; list = list->prev)
3720 PsppSheetViewColumnCellInfo *inf = list->data;
3721 if (inf->pack == GTK_PACK_END)
3729 pspp_sheet_view_column_cell_prev (PsppSheetViewColumn *tree_column,
3733 PsppSheetViewColumnCellInfo *info = current->data;
3735 if (info->pack == GTK_PACK_END)
3737 for (list = current->next; list; list = list->next)
3739 PsppSheetViewColumnCellInfo *inf = list->data;
3740 if (inf->pack == GTK_PACK_END)
3744 /* out of GTK_PACK_END, get last GTK_PACK_START one */
3745 list = g_list_last (tree_column->cell_list);
3746 for ( ; list; list = list->prev)
3748 PsppSheetViewColumnCellInfo *inf = list->data;
3749 if (inf->pack == GTK_PACK_START)
3754 for (list = current->prev; list; list = list->prev)
3756 PsppSheetViewColumnCellInfo *inf = list->data;
3757 if (inf->pack == GTK_PACK_START)
3765 _pspp_sheet_view_column_cell_focus (PsppSheetViewColumn *tree_column,
3773 count = _pspp_sheet_view_column_count_special_cells (tree_column);
3774 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_column->tree_view)) == GTK_TEXT_DIR_RTL;
3776 /* if we are the current focus column and have multiple editable cells,
3777 * try to select the next one, else move the focus to the next column
3779 if (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->focus_column == tree_column)
3784 GList *list = tree_column->cell_list;
3785 PsppSheetViewColumnCellInfo *info = NULL;
3787 /* find current focussed cell */
3788 for ( ; list; list = list->next)
3791 if (info->has_focus)
3795 /* not a focussed cell in the focus column? */
3796 if (!list || !info || !info->has_focus)
3801 prev = pspp_sheet_view_column_cell_next (tree_column, list);
3802 next = pspp_sheet_view_column_cell_prev (tree_column, list);
3806 next = pspp_sheet_view_column_cell_next (tree_column, list);
3807 prev = pspp_sheet_view_column_cell_prev (tree_column, list);
3810 info->has_focus = FALSE;
3811 if (direction > 0 && next)
3814 info->has_focus = TRUE;
3817 else if (direction > 0 && !next && !right)
3819 /* keep focus on last cell */
3821 info = pspp_sheet_view_column_cell_first (tree_column)->data;
3823 info = pspp_sheet_view_column_cell_last (tree_column)->data;
3825 info->has_focus = TRUE;
3828 else if (direction < 0 && prev)
3831 info->has_focus = TRUE;
3834 else if (direction < 0 && !prev && !left)
3836 /* keep focus on first cell */
3838 info = pspp_sheet_view_column_cell_last (tree_column)->data;
3840 info = pspp_sheet_view_column_cell_first (tree_column)->data;
3842 info->has_focus = TRUE;
3849 /* we get focus, if we have multiple editable cells, give the correct one
3854 GList *list = tree_column->cell_list;
3856 /* clear focus first */
3857 for ( ; list ; list = list->next)
3859 PsppSheetViewColumnCellInfo *info = list->data;
3860 if (info->has_focus)
3861 info->has_focus = FALSE;
3868 list = pspp_sheet_view_column_cell_last (tree_column);
3869 else if (direction < 0)
3870 list = pspp_sheet_view_column_cell_first (tree_column);
3875 list = pspp_sheet_view_column_cell_first (tree_column);
3876 else if (direction < 0)
3877 list = pspp_sheet_view_column_cell_last (tree_column);
3881 ((PsppSheetViewColumnCellInfo *) list->data)->has_focus = TRUE;
3888 _pspp_sheet_view_column_cell_draw_focus (PsppSheetViewColumn *tree_column,
3890 const GdkRectangle *background_area,
3891 const GdkRectangle *cell_area,
3892 const GdkRectangle *expose_area,
3895 gint focus_line_width;
3896 GtkStateType cell_state;
3898 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
3899 gtk_widget_style_get (GTK_WIDGET (tree_column->tree_view),
3900 "focus-line-width", &focus_line_width, NULL);
3901 if (tree_column->editable_widget)
3903 /* This function is only called on the editable row when editing.
3906 gtk_paint_focus (tree_column->tree_view->style,
3908 gtk_widget_get_state (tree_column->tree_view),
3910 tree_column->tree_view,
3912 cell_area->x - focus_line_width,
3913 cell_area->y - focus_line_width,
3914 cell_area->width + 2 * focus_line_width,
3915 cell_area->height + 2 * focus_line_width);
3920 GdkRectangle focus_rectangle;
3921 pspp_sheet_view_column_cell_process_action (tree_column,
3931 cell_state = flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
3932 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
3933 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL));
3934 gtk_paint_focus (tree_column->tree_view->style,
3938 tree_column->tree_view,
3942 focus_rectangle.width,
3943 focus_rectangle.height);
3948 * pspp_sheet_view_column_cell_is_visible:
3949 * @tree_column: A #PsppSheetViewColumn
3951 * Returns %TRUE if any of the cells packed into the @tree_column are visible.
3952 * For this to be meaningful, you must first initialize the cells with
3953 * pspp_sheet_view_column_cell_set_cell_data()
3955 * Return value: %TRUE, if any of the cells packed into the @tree_column are currently visible
3958 pspp_sheet_view_column_cell_is_visible (PsppSheetViewColumn *tree_column)
3962 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
3964 for (list = tree_column->cell_list; list; list = list->next)
3966 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
3968 if (info->cell->visible)
3976 * pspp_sheet_view_column_focus_cell:
3977 * @tree_column: A #PsppSheetViewColumn
3978 * @cell: A #GtkCellRenderer
3980 * Sets the current keyboard focus to be at @cell, if the column contains
3981 * 2 or more editable and activatable cells.
3986 pspp_sheet_view_column_focus_cell (PsppSheetViewColumn *tree_column,
3987 GtkCellRenderer *cell)
3990 gboolean found_cell = FALSE;
3992 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
3993 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
3995 if (_pspp_sheet_view_column_count_special_cells (tree_column) < 2)
3998 for (list = tree_column->cell_list; list; list = list->next)
4000 PsppSheetViewColumnCellInfo *info = list->data;
4002 if (info->cell == cell)
4004 info->has_focus = TRUE;
4012 for (list = tree_column->cell_list; list; list = list->next)
4014 PsppSheetViewColumnCellInfo *info = list->data;
4016 if (info->cell != cell)
4017 info->has_focus = FALSE;
4020 /* FIXME: redraw? */
4025 _pspp_sheet_view_column_cell_set_dirty (PsppSheetViewColumn *tree_column)
4029 for (list = tree_column->cell_list; list; list = list->next)
4031 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
4033 info->requested_width = 0;
4035 tree_column->dirty = TRUE;
4036 tree_column->requested_width = -1;
4037 tree_column->width = 0;
4039 if (tree_column->tree_view &&
4040 gtk_widget_get_realized (tree_column->tree_view))
4042 _pspp_sheet_view_install_mark_rows_col_dirty (PSPP_SHEET_VIEW (tree_column->tree_view));
4043 gtk_widget_queue_resize (tree_column->tree_view);
4048 _pspp_sheet_view_column_start_editing (PsppSheetViewColumn *tree_column,
4049 GtkCellEditable *cell_editable)
4051 g_return_if_fail (tree_column->editable_widget == NULL);
4053 tree_column->editable_widget = cell_editable;
4057 _pspp_sheet_view_column_stop_editing (PsppSheetViewColumn *tree_column)
4061 g_return_if_fail (tree_column->editable_widget != NULL);
4063 tree_column->editable_widget = NULL;
4064 for (list = tree_column->cell_list; list; list = list->next)
4065 ((PsppSheetViewColumnCellInfo *)list->data)->in_editing_mode = FALSE;
4069 _pspp_sheet_view_column_get_neighbor_sizes (PsppSheetViewColumn *column,
4070 GtkCellRenderer *cell,
4075 PsppSheetViewColumnCellInfo *info;
4081 list = pspp_sheet_view_column_cell_first (column);
4085 info = (PsppSheetViewColumnCellInfo *)list->data;
4087 list = pspp_sheet_view_column_cell_next (column, list);
4089 if (info->cell == cell)
4092 if (info->cell->visible)
4093 l += info->real_width + column->spacing;
4098 info = (PsppSheetViewColumnCellInfo *)list->data;
4100 list = pspp_sheet_view_column_cell_next (column, list);
4102 if (info->cell->visible)
4103 r += info->real_width + column->spacing;
4106 rtl = (gtk_widget_get_direction (GTK_WIDGET (column->tree_view)) == GTK_TEXT_DIR_RTL);
4108 *left = rtl ? r : l;
4111 *right = rtl ? l : r;
4115 * pspp_sheet_view_column_cell_get_position:
4116 * @tree_column: a #PsppSheetViewColumn
4117 * @cell_renderer: a #GtkCellRenderer
4118 * @start_pos: return location for the horizontal position of @cell within
4119 * @tree_column, may be %NULL
4120 * @width: return location for the width of @cell, may be %NULL
4122 * Obtains the horizontal position and size of a cell in a column. If the
4123 * cell is not found in the column, @start_pos and @width are not changed and
4124 * %FALSE is returned.
4126 * Return value: %TRUE if @cell belongs to @tree_column.
4129 pspp_sheet_view_column_cell_get_position (PsppSheetViewColumn *tree_column,
4130 GtkCellRenderer *cell_renderer,
4136 gboolean found_cell = FALSE;
4137 PsppSheetViewColumnCellInfo *cellinfo = NULL;
4139 list = pspp_sheet_view_column_cell_first (tree_column);
4140 for (; list; list = pspp_sheet_view_column_cell_next (tree_column, list))
4142 cellinfo = list->data;
4143 if (cellinfo->cell == cell_renderer)
4149 if (cellinfo->cell->visible)
4150 current_x += cellinfo->real_width;
4156 *start_pos = current_x;
4158 *width = cellinfo->real_width;
4165 * pspp_sheet_view_column_queue_resize:
4166 * @tree_column: A #PsppSheetViewColumn
4168 * Flags the column, and the cell renderers added to this column, to have
4169 * their sizes renegotiated.
4174 pspp_sheet_view_column_queue_resize (PsppSheetViewColumn *tree_column)
4176 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
4178 if (tree_column->tree_view)
4179 _pspp_sheet_view_column_cell_set_dirty (tree_column);
4183 * pspp_sheet_view_column_get_tree_view:
4184 * @tree_column: A #PsppSheetViewColumn
4186 * Returns the #PsppSheetView wherein @tree_column has been inserted. If
4187 * @column is currently not inserted in any tree view, %NULL is
4190 * Return value: The tree view wherein @column has been inserted if any,
4196 pspp_sheet_view_column_get_tree_view (PsppSheetViewColumn *tree_column)
4198 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), NULL);
4200 return tree_column->tree_view;
4204 GtkCellLayout *cell_layout;
4205 GtkCellRenderer *renderer;
4207 } AttributesSubParserData;
4210 attributes_start_element (GMarkupParseContext *context,
4211 const gchar *element_name,
4212 const gchar **names,
4213 const gchar **values,
4217 AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
4220 if (strcmp (element_name, "attribute") == 0)
4222 for (i = 0; names[i]; i++)
4223 if (strcmp (names[i], "name") == 0)
4224 parser_data->attr_name = g_strdup (values[i]);
4226 else if (strcmp (element_name, "attributes") == 0)
4229 g_warning ("Unsupported tag for GtkCellLayout: %s\n", element_name);
4233 attributes_text_element (GMarkupParseContext *context,
4239 AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
4244 if (!parser_data->attr_name)
4248 string = g_strndup (text, text_len);
4249 l = strtol (string, &endptr, 0);
4250 if (errno || endptr == string)
4254 GTK_BUILDER_ERROR_INVALID_VALUE,
4255 "Could not parse integer `%s'",
4262 gtk_cell_layout_add_attribute (parser_data->cell_layout,
4263 parser_data->renderer,
4264 parser_data->attr_name, l);
4265 g_free (parser_data->attr_name);
4266 parser_data->attr_name = NULL;
4269 static const GMarkupParser attributes_parser =
4271 attributes_start_element,
4273 attributes_text_element,
4277 _gtk_cell_layout_buildable_custom_tag_start (GtkBuildable *buildable,
4278 GtkBuilder *builder,
4280 const gchar *tagname,
4281 GMarkupParser *parser,
4284 AttributesSubParserData *parser_data;
4289 if (strcmp (tagname, "attributes") == 0)
4291 parser_data = g_slice_new0 (AttributesSubParserData);
4292 parser_data->cell_layout = GTK_CELL_LAYOUT (buildable);
4293 parser_data->renderer = GTK_CELL_RENDERER (child);
4294 parser_data->attr_name = NULL;
4296 *parser = attributes_parser;
4297 *data = parser_data;
4305 _gtk_cell_layout_buildable_custom_tag_end (GtkBuildable *buildable,
4306 GtkBuilder *builder,
4308 const gchar *tagname,
4311 AttributesSubParserData *parser_data;
4313 parser_data = (AttributesSubParserData*)data;
4314 g_assert (!parser_data->attr_name);
4315 g_slice_free (AttributesSubParserData, parser_data);
4319 _gtk_cell_layout_buildable_add_child (GtkBuildable *buildable,
4320 GtkBuilder *builder,
4324 GtkCellLayoutIface *iface;
4326 g_return_if_fail (GTK_IS_CELL_LAYOUT (buildable));
4327 g_return_if_fail (GTK_IS_CELL_RENDERER (child));
4329 iface = GTK_CELL_LAYOUT_GET_IFACE (buildable);
4330 g_return_if_fail (iface->pack_start != NULL);
4331 iface->pack_start (GTK_CELL_LAYOUT (buildable), GTK_CELL_RENDERER (child), FALSE);
4335 pspp_sheet_view_column_size_request (PsppSheetViewColumn *tree_column,
4336 GtkRequisition *request)
4338 GtkWidget *base = GTK_WIDGET (tree_column->tree_view);
4339 GtkRequisition label_req;
4340 GtkRequisition align_req;
4341 GtkRequisition arrow_req;
4342 GtkRequisition hbox_req;
4343 GtkStyle **button_style;
4345 if (tree_column->button)
4347 gtk_widget_size_request (tree_column->button, request);
4351 facade_label_get_size_request (0, 0, base, tree_column->title, &label_req);
4352 facade_alignment_get_size_request (0, 0, 0, 0, 0, &label_req, &align_req);
4353 facade_arrow_get_size_request (0, 0, &arrow_req);
4355 facade_hbox_get_base_size_request (0, 2, 2, &hbox_req);
4356 facade_hbox_add_child_size_request (0, &arrow_req, 0, &hbox_req);
4357 facade_hbox_add_child_size_request (0, &align_req, 0, &hbox_req);
4359 button_style = &PSPP_SHEET_VIEW (tree_column->tree_view)->priv->button_style;
4360 if (*button_style == NULL)
4362 *button_style = facade_get_style (base, GTK_TYPE_BUTTON, 0);
4363 g_object_ref (*button_style);
4365 facade_button_get_size_request (0, base, *button_style, &hbox_req, request);
4369 pspp_sheet_view_column_size_allocate (PsppSheetViewColumn *tree_column,
4370 GtkAllocation *allocation)
4372 tree_column->allocation = *allocation;
4373 if (tree_column->button)
4374 gtk_widget_size_allocate (tree_column->button, allocation);
4378 pspp_sheet_view_column_can_focus (PsppSheetViewColumn *tree_column)
4380 return tree_column->reorderable || tree_column->clickable;
4384 pspp_sheet_view_column_set_need_button (PsppSheetViewColumn *tree_column,
4385 gboolean need_button)
4387 if (tree_column->need_button != need_button)
4389 tree_column->need_button = need_button;
4390 pspp_sheet_view_column_update_button (tree_column);
4391 _pspp_sheet_view_column_realize_button (tree_column);