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
87 typedef struct _PsppSheetViewColumnCellInfo PsppSheetViewColumnCellInfo;
88 struct _PsppSheetViewColumnCellInfo
90 GtkCellRenderer *cell;
92 PsppSheetCellDataFunc func;
94 GDestroyNotify destroy;
100 guint in_editing_mode : 1;
104 static void pspp_sheet_view_column_cell_layout_init (GtkCellLayoutIface *iface);
106 /* GObject methods */
107 static void pspp_sheet_view_column_set_property (GObject *object,
111 static void pspp_sheet_view_column_get_property (GObject *object,
115 static void pspp_sheet_view_column_finalize (GObject *object);
117 /* GtkCellLayout implementation */
118 static void pspp_sheet_view_column_cell_layout_pack_start (GtkCellLayout *cell_layout,
119 GtkCellRenderer *cell,
121 static void pspp_sheet_view_column_cell_layout_pack_end (GtkCellLayout *cell_layout,
122 GtkCellRenderer *cell,
124 static void pspp_sheet_view_column_cell_layout_clear (GtkCellLayout *cell_layout);
125 static void pspp_sheet_view_column_cell_layout_add_attribute (GtkCellLayout *cell_layout,
126 GtkCellRenderer *cell,
127 const gchar *attribute,
129 static void pspp_sheet_view_column_cell_layout_set_cell_data_func (GtkCellLayout *cell_layout,
130 GtkCellRenderer *cell,
131 GtkCellLayoutDataFunc func,
133 GDestroyNotify destroy);
134 static void pspp_sheet_view_column_cell_layout_clear_attributes (GtkCellLayout *cell_layout,
135 GtkCellRenderer *cell);
136 static void pspp_sheet_view_column_cell_layout_reorder (GtkCellLayout *cell_layout,
137 GtkCellRenderer *cell,
139 static GList *pspp_sheet_view_column_cell_layout_get_cells (GtkCellLayout *cell_layout);
141 /* Button handling code */
142 static void pspp_sheet_view_column_create_button (PsppSheetViewColumn *tree_column);
143 void pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
145 /* Button signal handlers */
146 static gint pspp_sheet_view_column_button_event (GtkWidget *widget,
149 static void pspp_sheet_view_column_button_clicked (GtkWidget *widget,
151 static void pspp_sheet_view_column_button_popup_menu (GtkWidget *widget,
153 static gboolean pspp_sheet_view_column_mnemonic_activate (GtkWidget *widget,
154 gboolean group_cycling,
156 static gboolean on_pspp_sheet_view_column_button_clicked (PsppSheetViewColumn *);
157 static gboolean on_pspp_sheet_view_column_button_press_event (PsppSheetViewColumn *,
160 /* Property handlers */
161 static void pspp_sheet_view_model_sort_column_changed (GtkTreeSortable *sortable,
162 PsppSheetViewColumn *tree_column);
164 /* Internal functions */
165 static void pspp_sheet_view_column_sort (PsppSheetViewColumn *tree_column,
167 static void pspp_sheet_view_column_setup_sort_column_id_callback (PsppSheetViewColumn *tree_column);
168 static void pspp_sheet_view_column_set_attributesv (PsppSheetViewColumn *tree_column,
169 GtkCellRenderer *cell_renderer,
171 static PsppSheetViewColumnCellInfo *pspp_sheet_view_column_get_cell_info (PsppSheetViewColumn *tree_column,
172 GtkCellRenderer *cell_renderer);
174 /* cell list manipulation */
175 static GList *pspp_sheet_view_column_cell_first (PsppSheetViewColumn *tree_column);
176 static GList *pspp_sheet_view_column_cell_last (PsppSheetViewColumn *tree_column);
177 static GList *pspp_sheet_view_column_cell_next (PsppSheetViewColumn *tree_column,
179 static GList *pspp_sheet_view_column_cell_prev (PsppSheetViewColumn *tree_column,
181 static void pspp_sheet_view_column_clear_attributes_by_info (PsppSheetViewColumn *tree_column,
182 PsppSheetViewColumnCellInfo *info);
183 /* GtkBuildable implementation */
184 static void pspp_sheet_view_column_buildable_init (GtkBuildableIface *iface);
186 static guint tree_column_signals[LAST_SIGNAL] = { 0 };
188 G_DEFINE_TYPE_WITH_CODE (PsppSheetViewColumn, pspp_sheet_view_column, GTK_TYPE_OBJECT,
189 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
190 pspp_sheet_view_column_cell_layout_init)
191 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
192 pspp_sheet_view_column_buildable_init))
196 pspp_sheet_view_column_class_init (PsppSheetViewColumnClass *class)
198 GObjectClass *object_class;
200 object_class = (GObjectClass*) class;
202 class->clicked = on_pspp_sheet_view_column_button_clicked;
203 class->button_press_event = on_pspp_sheet_view_column_button_press_event;
205 object_class->finalize = pspp_sheet_view_column_finalize;
206 object_class->set_property = pspp_sheet_view_column_set_property;
207 object_class->get_property = pspp_sheet_view_column_get_property;
209 tree_column_signals[CLICKED] =
210 g_signal_new ("clicked",
211 G_OBJECT_CLASS_TYPE (object_class),
213 G_STRUCT_OFFSET (PsppSheetViewColumnClass, clicked),
214 g_signal_accumulator_true_handled, NULL,
215 psppire_marshal_BOOLEAN__VOID,
218 tree_column_signals[POPUP_MENU] =
219 g_signal_new ("popup-menu",
220 G_OBJECT_CLASS_TYPE (object_class),
224 g_cclosure_marshal_VOID__VOID,
227 tree_column_signals[QUERY_TOOLTIP] =
228 g_signal_new ("query-tooltip",
229 G_OBJECT_CLASS_TYPE (object_class),
232 g_signal_accumulator_true_handled, NULL,
233 psppire_marshal_BOOLEAN__OBJECT,
237 tree_column_signals[BUTTON_PRESS_EVENT] =
238 g_signal_new ("button-press-event",
239 G_OBJECT_CLASS_TYPE (object_class),
240 G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
241 G_STRUCT_OFFSET (PsppSheetViewColumnClass, button_press_event),
242 g_signal_accumulator_true_handled, NULL,
243 psppire_marshal_BOOLEAN__BOXED,
245 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
247 g_object_class_install_property (object_class,
249 g_param_spec_boolean ("visible",
251 P_("Whether to display the column"),
253 GTK_PARAM_READWRITE));
255 g_object_class_install_property (object_class,
257 g_param_spec_boolean ("resizable",
259 P_("Column is user-resizable"),
261 GTK_PARAM_READWRITE));
263 g_object_class_install_property (object_class,
265 g_param_spec_int ("width",
267 P_("Current width of the column"),
271 GTK_PARAM_READABLE));
272 g_object_class_install_property (object_class,
274 g_param_spec_int ("spacing",
276 P_("Space which is inserted between cells"),
280 GTK_PARAM_READWRITE));
282 g_object_class_install_property (object_class,
284 g_param_spec_int ("fixed-width",
286 P_("Current fixed width of the column"),
290 GTK_PARAM_READWRITE));
292 g_object_class_install_property (object_class,
294 g_param_spec_int ("min-width",
296 P_("Minimum allowed width of the column"),
300 GTK_PARAM_READWRITE));
302 g_object_class_install_property (object_class,
304 g_param_spec_int ("max-width",
306 P_("Maximum allowed width of the column"),
310 GTK_PARAM_READWRITE));
312 g_object_class_install_property (object_class,
314 g_param_spec_string ("title",
316 P_("Title to appear in column header"),
318 GTK_PARAM_READWRITE));
320 g_object_class_install_property (object_class,
322 g_param_spec_boolean ("expand",
324 P_("Column gets share of extra width allocated to the widget"),
326 GTK_PARAM_READWRITE));
328 g_object_class_install_property (object_class,
330 g_param_spec_boolean ("clickable",
332 P_("Whether the header can be clicked"),
334 GTK_PARAM_READWRITE));
337 g_object_class_install_property (object_class,
339 g_param_spec_object ("widget",
341 P_("Widget to put in column header button instead of column title"),
343 GTK_PARAM_READWRITE));
345 g_object_class_install_property (object_class,
347 g_param_spec_float ("alignment",
349 P_("X Alignment of the column header text or widget"),
353 GTK_PARAM_READWRITE));
355 g_object_class_install_property (object_class,
357 g_param_spec_boolean ("reorderable",
359 P_("Whether the column can be reordered around the headers"),
361 GTK_PARAM_READWRITE));
363 g_object_class_install_property (object_class,
365 g_param_spec_boolean ("sort-indicator",
366 P_("Sort indicator"),
367 P_("Whether to show a sort indicator"),
369 GTK_PARAM_READWRITE));
371 g_object_class_install_property (object_class,
373 g_param_spec_enum ("sort-order",
375 P_("Sort direction the sort indicator should indicate"),
378 GTK_PARAM_READWRITE));
381 * PsppSheetViewColumn:sort-column-id:
383 * Logical sort column ID this column sorts on when selected for sorting. Setting the sort column ID makes the column header
384 * clickable. Set to %-1 to make the column unsortable.
388 g_object_class_install_property (object_class,
390 g_param_spec_int ("sort-column-id",
391 P_("Sort column ID"),
392 P_("Logical sort column ID this column sorts on when selected for sorting"),
396 GTK_PARAM_READWRITE));
398 g_object_class_install_property (object_class,
400 g_param_spec_boolean ("quick-edit",
402 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."),
404 GTK_PARAM_READWRITE));
406 g_object_class_install_property (object_class,
408 g_param_spec_boolean ("selected",
410 P_("If true, this column is selected as part of a rectangular selection."),
412 GTK_PARAM_READWRITE));
414 g_object_class_install_property (object_class,
416 g_param_spec_boolean ("selectable",
418 P_("If true, this column may be selected as part of a rectangular selection."),
420 GTK_PARAM_READWRITE));
422 g_object_class_install_property (object_class,
424 g_param_spec_boolean ("row-head",
426 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)."),
428 GTK_PARAM_READWRITE));
432 pspp_sheet_view_column_buildable_init (GtkBuildableIface *iface)
434 iface->add_child = _gtk_cell_layout_buildable_add_child;
435 iface->custom_tag_start = _gtk_cell_layout_buildable_custom_tag_start;
436 iface->custom_tag_end = _gtk_cell_layout_buildable_custom_tag_end;
440 pspp_sheet_view_column_cell_layout_init (GtkCellLayoutIface *iface)
442 iface->pack_start = pspp_sheet_view_column_cell_layout_pack_start;
443 iface->pack_end = pspp_sheet_view_column_cell_layout_pack_end;
444 iface->clear = pspp_sheet_view_column_cell_layout_clear;
445 iface->add_attribute = pspp_sheet_view_column_cell_layout_add_attribute;
446 iface->set_cell_data_func = pspp_sheet_view_column_cell_layout_set_cell_data_func;
447 iface->clear_attributes = pspp_sheet_view_column_cell_layout_clear_attributes;
448 iface->reorder = pspp_sheet_view_column_cell_layout_reorder;
449 iface->get_cells = pspp_sheet_view_column_cell_layout_get_cells;
453 pspp_sheet_view_column_init (PsppSheetViewColumn *tree_column)
455 tree_column->button = NULL;
456 tree_column->xalign = 0.0;
457 tree_column->width = 0;
458 tree_column->spacing = 0;
459 tree_column->requested_width = -1;
460 tree_column->min_width = -1;
461 tree_column->max_width = -1;
462 tree_column->resized_width = 0;
463 tree_column->visible = TRUE;
464 tree_column->resizable = FALSE;
465 tree_column->expand = FALSE;
466 tree_column->clickable = FALSE;
467 tree_column->dirty = TRUE;
468 tree_column->selected = FALSE;
469 tree_column->selectable = TRUE;
470 tree_column->row_head = FALSE;
471 tree_column->sort_order = GTK_SORT_ASCENDING;
472 tree_column->show_sort_indicator = FALSE;
473 tree_column->property_changed_signal = 0;
474 tree_column->sort_clicked_signal = 0;
475 tree_column->sort_column_changed_signal = 0;
476 tree_column->sort_column_id = -1;
477 tree_column->reorderable = FALSE;
478 tree_column->maybe_reordered = FALSE;
479 tree_column->fixed_width = 1;
480 tree_column->use_resized_width = FALSE;
481 tree_column->title = g_strdup ("");
482 tree_column->quick_edit = TRUE;
483 tree_column->need_button = FALSE;
487 pspp_sheet_view_column_finalize (GObject *object)
489 PsppSheetViewColumn *tree_column = (PsppSheetViewColumn *) object;
492 for (list = tree_column->cell_list; list; list = list->next)
494 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
498 GDestroyNotify d = info->destroy;
500 info->destroy = NULL;
503 pspp_sheet_view_column_clear_attributes_by_info (tree_column, info);
504 g_object_unref (info->cell);
508 g_free (tree_column->title);
509 g_list_free (tree_column->cell_list);
511 if (tree_column->child)
512 g_object_unref (tree_column->child);
514 G_OBJECT_CLASS (pspp_sheet_view_column_parent_class)->finalize (object);
518 pspp_sheet_view_column_set_property (GObject *object,
523 PsppSheetViewColumn *tree_column;
525 tree_column = PSPP_SHEET_VIEW_COLUMN (object);
530 pspp_sheet_view_column_set_visible (tree_column,
531 g_value_get_boolean (value));
535 pspp_sheet_view_column_set_resizable (tree_column,
536 g_value_get_boolean (value));
539 case PROP_FIXED_WIDTH:
540 pspp_sheet_view_column_set_fixed_width (tree_column,
541 g_value_get_int (value));
545 pspp_sheet_view_column_set_min_width (tree_column,
546 g_value_get_int (value));
550 pspp_sheet_view_column_set_max_width (tree_column,
551 g_value_get_int (value));
555 pspp_sheet_view_column_set_spacing (tree_column,
556 g_value_get_int (value));
560 pspp_sheet_view_column_set_title (tree_column,
561 g_value_get_string (value));
565 pspp_sheet_view_column_set_expand (tree_column,
566 g_value_get_boolean (value));
570 pspp_sheet_view_column_set_clickable (tree_column,
571 g_value_get_boolean (value));
575 pspp_sheet_view_column_set_widget (tree_column,
576 (GtkWidget*) g_value_get_object (value));
580 pspp_sheet_view_column_set_alignment (tree_column,
581 g_value_get_float (value));
584 case PROP_REORDERABLE:
585 pspp_sheet_view_column_set_reorderable (tree_column,
586 g_value_get_boolean (value));
589 case PROP_SORT_INDICATOR:
590 pspp_sheet_view_column_set_sort_indicator (tree_column,
591 g_value_get_boolean (value));
594 case PROP_SORT_ORDER:
595 pspp_sheet_view_column_set_sort_order (tree_column,
596 g_value_get_enum (value));
599 case PROP_SORT_COLUMN_ID:
600 pspp_sheet_view_column_set_sort_column_id (tree_column,
601 g_value_get_int (value));
604 case PROP_QUICK_EDIT:
605 pspp_sheet_view_column_set_quick_edit (tree_column,
606 g_value_get_boolean (value));
610 pspp_sheet_view_column_set_selected (tree_column,
611 g_value_get_boolean (value));
614 case PROP_SELECTABLE:
615 pspp_sheet_view_column_set_selectable (tree_column,
616 g_value_get_boolean (value));
620 pspp_sheet_view_column_set_row_head (tree_column,
621 g_value_get_boolean (value));
625 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
631 pspp_sheet_view_column_get_property (GObject *object,
636 PsppSheetViewColumn *tree_column;
638 tree_column = PSPP_SHEET_VIEW_COLUMN (object);
643 g_value_set_boolean (value,
644 pspp_sheet_view_column_get_visible (tree_column));
648 g_value_set_boolean (value,
649 pspp_sheet_view_column_get_resizable (tree_column));
653 g_value_set_int (value,
654 pspp_sheet_view_column_get_width (tree_column));
658 g_value_set_int (value,
659 pspp_sheet_view_column_get_spacing (tree_column));
662 case PROP_FIXED_WIDTH:
663 g_value_set_int (value,
664 pspp_sheet_view_column_get_fixed_width (tree_column));
668 g_value_set_int (value,
669 pspp_sheet_view_column_get_min_width (tree_column));
673 g_value_set_int (value,
674 pspp_sheet_view_column_get_max_width (tree_column));
678 g_value_set_string (value,
679 pspp_sheet_view_column_get_title (tree_column));
683 g_value_set_boolean (value,
684 pspp_sheet_view_column_get_expand (tree_column));
688 g_value_set_boolean (value,
689 pspp_sheet_view_column_get_clickable (tree_column));
693 g_value_set_object (value,
694 (GObject*) pspp_sheet_view_column_get_widget (tree_column));
698 g_value_set_float (value,
699 pspp_sheet_view_column_get_alignment (tree_column));
702 case PROP_REORDERABLE:
703 g_value_set_boolean (value,
704 pspp_sheet_view_column_get_reorderable (tree_column));
707 case PROP_SORT_INDICATOR:
708 g_value_set_boolean (value,
709 pspp_sheet_view_column_get_sort_indicator (tree_column));
712 case PROP_SORT_ORDER:
713 g_value_set_enum (value,
714 pspp_sheet_view_column_get_sort_order (tree_column));
717 case PROP_SORT_COLUMN_ID:
718 g_value_set_int (value,
719 pspp_sheet_view_column_get_sort_column_id (tree_column));
722 case PROP_QUICK_EDIT:
723 g_value_set_boolean (value,
724 pspp_sheet_view_column_get_quick_edit (tree_column));
728 g_value_set_boolean (value,
729 pspp_sheet_view_column_get_selected (tree_column));
732 case PROP_SELECTABLE:
733 g_value_set_boolean (value,
734 pspp_sheet_view_column_get_selectable (tree_column));
738 g_value_set_boolean (value,
739 pspp_sheet_view_column_get_row_head (tree_column));
743 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
748 /* Implementation of GtkCellLayout interface
752 pspp_sheet_view_column_cell_layout_pack_start (GtkCellLayout *cell_layout,
753 GtkCellRenderer *cell,
756 PsppSheetViewColumn *column;
757 PsppSheetViewColumnCellInfo *cell_info;
759 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
760 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
761 g_return_if_fail (! pspp_sheet_view_column_get_cell_info (column, cell));
763 g_object_ref_sink (cell);
765 cell_info = g_new0 (PsppSheetViewColumnCellInfo, 1);
766 cell_info->cell = cell;
767 cell_info->expand = expand ? TRUE : FALSE;
768 cell_info->pack = GTK_PACK_START;
769 cell_info->has_focus = 0;
770 cell_info->attributes = NULL;
772 column->cell_list = g_list_append (column->cell_list, cell_info);
776 pspp_sheet_view_column_cell_layout_pack_end (GtkCellLayout *cell_layout,
777 GtkCellRenderer *cell,
780 PsppSheetViewColumn *column;
781 PsppSheetViewColumnCellInfo *cell_info;
783 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
784 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
785 g_return_if_fail (! pspp_sheet_view_column_get_cell_info (column, cell));
787 g_object_ref_sink (cell);
789 cell_info = g_new0 (PsppSheetViewColumnCellInfo, 1);
790 cell_info->cell = cell;
791 cell_info->expand = expand ? TRUE : FALSE;
792 cell_info->pack = GTK_PACK_END;
793 cell_info->has_focus = 0;
794 cell_info->attributes = NULL;
796 column->cell_list = g_list_append (column->cell_list, cell_info);
800 pspp_sheet_view_column_cell_layout_clear (GtkCellLayout *cell_layout)
802 PsppSheetViewColumn *column;
804 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
805 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
807 while (column->cell_list)
809 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *)column->cell_list->data;
811 pspp_sheet_view_column_cell_layout_clear_attributes (cell_layout, info->cell);
812 g_object_unref (info->cell);
814 column->cell_list = g_list_delete_link (column->cell_list,
820 pspp_sheet_view_column_cell_layout_add_attribute (GtkCellLayout *cell_layout,
821 GtkCellRenderer *cell,
822 const gchar *attribute,
825 PsppSheetViewColumn *tree_column;
826 PsppSheetViewColumnCellInfo *info;
828 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
829 tree_column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
831 info = pspp_sheet_view_column_get_cell_info (tree_column, cell);
832 g_return_if_fail (info != NULL);
834 info->attributes = g_slist_prepend (info->attributes, GINT_TO_POINTER (column));
835 info->attributes = g_slist_prepend (info->attributes, g_strdup (attribute));
837 if (tree_column->tree_view)
838 _pspp_sheet_view_column_cell_set_dirty (tree_column);
842 pspp_sheet_view_column_cell_layout_set_cell_data_func (GtkCellLayout *cell_layout,
843 GtkCellRenderer *cell,
844 GtkCellLayoutDataFunc func,
846 GDestroyNotify destroy)
848 PsppSheetViewColumn *column;
849 PsppSheetViewColumnCellInfo *info;
851 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
852 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
854 info = pspp_sheet_view_column_get_cell_info (column, cell);
855 g_return_if_fail (info != NULL);
859 GDestroyNotify d = info->destroy;
861 info->destroy = NULL;
865 info->func = (PsppSheetCellDataFunc)func;
866 info->func_data = func_data;
867 info->destroy = destroy;
869 if (column->tree_view)
870 _pspp_sheet_view_column_cell_set_dirty (column);
874 pspp_sheet_view_column_cell_layout_clear_attributes (GtkCellLayout *cell_layout,
875 GtkCellRenderer *cell_renderer)
877 PsppSheetViewColumn *column;
878 PsppSheetViewColumnCellInfo *info;
880 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
881 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
883 info = pspp_sheet_view_column_get_cell_info (column, cell_renderer);
885 pspp_sheet_view_column_clear_attributes_by_info (column, info);
889 pspp_sheet_view_column_cell_layout_reorder (GtkCellLayout *cell_layout,
890 GtkCellRenderer *cell,
894 PsppSheetViewColumn *column;
895 PsppSheetViewColumnCellInfo *info;
897 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
898 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
900 info = pspp_sheet_view_column_get_cell_info (column, cell);
902 g_return_if_fail (info != NULL);
903 g_return_if_fail (position >= 0);
905 link = g_list_find (column->cell_list, info);
907 g_return_if_fail (link != NULL);
909 column->cell_list = g_list_delete_link (column->cell_list, link);
910 column->cell_list = g_list_insert (column->cell_list, info, position);
912 if (column->tree_view)
913 gtk_widget_queue_draw (column->tree_view);
917 pspp_sheet_view_column_clear_attributes_by_info (PsppSheetViewColumn *tree_column,
918 PsppSheetViewColumnCellInfo *info)
922 list = info->attributes;
924 while (list && list->next)
927 list = list->next->next;
929 g_slist_free (info->attributes);
930 info->attributes = NULL;
932 if (tree_column->tree_view)
933 _pspp_sheet_view_column_cell_set_dirty (tree_column);
937 on_query_tooltip (GtkWidget *widget,
940 gboolean keyboard_mode,
944 PsppSheetViewColumn *tree_column = user_data;
947 g_signal_emit (tree_column, tree_column_signals[QUERY_TOOLTIP], 0,
953 on_button_pressed (GtkWidget *widget, GdkEventButton *event,
956 PsppSheetViewColumn *tree_column = user_data;
959 /* XXX See "Implement GtkWidget::popup_menu" in GTK+ reference manual. */
960 g_signal_emit (tree_column, tree_column_signals[BUTTON_PRESS_EVENT],
968 /* Button handling code
971 pspp_sheet_view_column_create_button (PsppSheetViewColumn *tree_column)
973 PsppSheetView *tree_view;
977 tree_view = (PsppSheetView *) tree_column->tree_view;
979 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
980 g_return_if_fail (tree_column->button == NULL);
982 gtk_widget_push_composite_child ();
983 tree_column->button = gtk_button_new ();
984 gtk_widget_add_events (tree_column->button, GDK_POINTER_MOTION_MASK);
985 gtk_widget_pop_composite_child ();
987 /* make sure we own a reference to it as well. */
988 if (tree_view->priv->header_window)
989 gtk_widget_set_parent_window (tree_column->button, tree_view->priv->header_window);
990 gtk_widget_set_parent (tree_column->button, GTK_WIDGET (tree_view));
992 g_signal_connect (tree_column->button, "event",
993 G_CALLBACK (pspp_sheet_view_column_button_event),
995 g_signal_connect (tree_column->button, "clicked",
996 G_CALLBACK (pspp_sheet_view_column_button_clicked),
998 g_signal_connect (tree_column->button, "popup-menu",
999 G_CALLBACK (pspp_sheet_view_column_button_popup_menu),
1001 g_signal_connect (tree_column->button, "button-press-event",
1002 G_CALLBACK (on_button_pressed), tree_column);
1004 g_signal_connect (tree_column->button, "query-tooltip",
1005 G_CALLBACK (on_query_tooltip), tree_column);
1006 g_object_set (tree_column->button, "has-tooltip", TRUE, NULL);
1008 tree_column->alignment = gtk_alignment_new (tree_column->xalign, 0.5, 0.0, 0.0);
1010 hbox = gtk_hbox_new (FALSE, 2);
1011 tree_column->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN);
1013 if (tree_column->child)
1014 child = tree_column->child;
1017 child = gtk_label_new (tree_column->title);
1018 gtk_widget_show (child);
1021 g_signal_connect (child, "mnemonic-activate",
1022 G_CALLBACK (pspp_sheet_view_column_mnemonic_activate),
1025 if (tree_column->xalign <= 0.5)
1026 gtk_box_pack_end (GTK_BOX (hbox), tree_column->arrow, FALSE, FALSE, 0);
1028 gtk_box_pack_start (GTK_BOX (hbox), tree_column->arrow, FALSE, FALSE, 0);
1030 gtk_box_pack_start (GTK_BOX (hbox), tree_column->alignment, TRUE, TRUE, 0);
1032 gtk_container_add (GTK_CONTAINER (tree_column->alignment), child);
1033 gtk_container_add (GTK_CONTAINER (tree_column->button), hbox);
1035 gtk_widget_show (hbox);
1036 gtk_widget_show (tree_column->alignment);
1037 pspp_sheet_view_column_update_button (tree_column);
1041 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column)
1043 gint sort_column_id = -1;
1045 GtkWidget *alignment;
1047 GtkWidget *current_child;
1048 GtkArrowType arrow_type = GTK_ARROW_NONE;
1049 GtkTreeModel *model;
1052 if (tree_column->tree_view)
1053 model = pspp_sheet_view_get_model (PSPP_SHEET_VIEW (tree_column->tree_view));
1057 /* Create a button if necessary */
1058 if (tree_column->need_button &&
1059 tree_column->visible &&
1060 tree_column->button == NULL &&
1061 tree_column->tree_view &&
1062 gtk_widget_get_realized (tree_column->tree_view))
1063 pspp_sheet_view_column_create_button (tree_column);
1065 if (! tree_column->button)
1068 hbox = GTK_BIN (tree_column->button)->child;
1069 alignment = tree_column->alignment;
1070 arrow = tree_column->arrow;
1071 current_child = GTK_BIN (alignment)->child;
1073 /* Set up the actual button */
1074 gtk_alignment_set (GTK_ALIGNMENT (alignment), tree_column->xalign,
1077 if (tree_column->child)
1079 if (current_child != tree_column->child)
1081 gtk_container_remove (GTK_CONTAINER (alignment),
1083 gtk_container_add (GTK_CONTAINER (alignment),
1084 tree_column->child);
1089 if (current_child == NULL)
1091 current_child = gtk_label_new (NULL);
1092 gtk_widget_show (current_child);
1093 gtk_container_add (GTK_CONTAINER (alignment),
1097 g_return_if_fail (GTK_IS_LABEL (current_child));
1099 if (tree_column->title)
1100 gtk_label_set_text_with_mnemonic (GTK_LABEL (current_child),
1101 tree_column->title);
1103 gtk_label_set_text_with_mnemonic (GTK_LABEL (current_child),
1107 if (GTK_IS_TREE_SORTABLE (model))
1108 gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model),
1112 if (tree_column->show_sort_indicator)
1114 gboolean alternative;
1116 g_object_get (gtk_widget_get_settings (tree_column->tree_view),
1117 "gtk-alternative-sort-arrows", &alternative,
1120 switch (tree_column->sort_order)
1122 case GTK_SORT_ASCENDING:
1123 arrow_type = alternative ? GTK_ARROW_UP : GTK_ARROW_DOWN;
1126 case GTK_SORT_DESCENDING:
1127 arrow_type = alternative ? GTK_ARROW_DOWN : GTK_ARROW_UP;
1131 g_warning (G_STRLOC": bad sort order");
1136 gtk_arrow_set (GTK_ARROW (arrow),
1140 /* Put arrow on the right if the text is left-or-center justified, and on the
1141 * left otherwise; do this by packing boxes, so flipping text direction will
1144 g_object_ref (arrow);
1145 gtk_container_remove (GTK_CONTAINER (hbox), arrow);
1147 if (tree_column->xalign <= 0.5)
1149 gtk_box_pack_end (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
1153 gtk_box_pack_start (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
1154 /* move it to the front */
1155 gtk_box_reorder_child (GTK_BOX (hbox), arrow, 0);
1157 g_object_unref (arrow);
1159 if (tree_column->show_sort_indicator
1160 || (GTK_IS_TREE_SORTABLE (model) && tree_column->sort_column_id >= 0))
1161 gtk_widget_show (arrow);
1163 gtk_widget_hide (arrow);
1165 /* It's always safe to hide the button. It isn't always safe to show it, as
1166 * if you show it before it's realized, it'll get the wrong window. */
1167 if (tree_column->button &&
1168 tree_column->tree_view != NULL &&
1169 gtk_widget_get_realized (tree_column->tree_view))
1171 if (tree_column->visible)
1173 gtk_widget_show_now (tree_column->button);
1174 if (tree_column->window)
1176 if (tree_column->resizable)
1178 gdk_window_show (tree_column->window);
1179 gdk_window_raise (tree_column->window);
1183 gdk_window_hide (tree_column->window);
1189 gtk_widget_hide (tree_column->button);
1190 if (tree_column->window)
1191 gdk_window_hide (tree_column->window);
1195 can_focus = pspp_sheet_view_column_can_focus (tree_column);
1196 gtk_widget_set_can_focus (tree_column->button, can_focus);
1197 if (!can_focus && gtk_widget_has_focus (tree_column->button))
1199 GtkWidget *toplevel = gtk_widget_get_toplevel (tree_column->tree_view);
1200 if (gtk_widget_is_toplevel (toplevel))
1202 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
1206 /* Queue a resize on the assumption that we always want to catch all changes
1207 * and columns don't change all that often.
1209 if (gtk_widget_get_realized (tree_column->tree_view))
1210 gtk_widget_queue_resize (tree_column->tree_view);
1214 /* Button signal handlers
1218 pspp_sheet_view_column_button_event (GtkWidget *widget,
1222 PsppSheetViewColumn *column = (PsppSheetViewColumn *) data;
1224 g_return_val_if_fail (event != NULL, FALSE);
1226 if (event->type == GDK_BUTTON_PRESS &&
1227 column->reorderable &&
1228 ((GdkEventButton *)event)->button == 1)
1230 column->maybe_reordered = TRUE;
1231 gdk_window_get_pointer (GTK_BUTTON (widget)->event_window,
1235 gtk_widget_grab_focus (widget);
1238 if (event->type == GDK_BUTTON_RELEASE ||
1239 event->type == GDK_LEAVE_NOTIFY)
1240 column->maybe_reordered = FALSE;
1242 if (event->type == GDK_MOTION_NOTIFY &&
1243 column->maybe_reordered &&
1244 (gtk_drag_check_threshold (widget,
1247 (gint) ((GdkEventMotion *)event)->x,
1248 (gint) ((GdkEventMotion *)event)->y)))
1250 column->maybe_reordered = FALSE;
1251 _pspp_sheet_view_column_start_drag (PSPP_SHEET_VIEW (column->tree_view), column);
1254 if (column->clickable == FALSE)
1256 switch (event->type)
1258 case GDK_MOTION_NOTIFY:
1259 case GDK_BUTTON_RELEASE:
1260 case GDK_ENTER_NOTIFY:
1261 case GDK_LEAVE_NOTIFY:
1271 all_rows_selected (PsppSheetView *sheet_view)
1273 PsppSheetSelection *selection = sheet_view->priv->selection;
1274 gint n_rows, n_selected_rows;
1276 n_rows = sheet_view->priv->row_count;
1277 n_selected_rows = pspp_sheet_selection_count_selected_rows (selection);
1279 return n_rows > 0 && n_selected_rows >= n_rows;
1283 on_pspp_sheet_view_column_button_press_event (PsppSheetViewColumn *column,
1284 GdkEventButton *event)
1286 PsppSheetView *sheet_view = PSPP_SHEET_VIEW (column->tree_view);
1287 PsppSheetSelection *selection;
1288 GSignalInvocationHint *hint;
1291 /* We only want to run first, not last, but combining that with return type
1292 `gboolean' makes GObject warn, so just ignore the run_last call. */
1293 hint = g_signal_get_invocation_hint (column);
1294 g_return_val_if_fail (hint != NULL, FALSE);
1295 if (hint->run_type != G_SIGNAL_RUN_FIRST)
1298 g_return_val_if_fail (sheet_view != NULL, FALSE);
1300 selection = sheet_view->priv->selection;
1301 g_return_val_if_fail (selection != NULL, FALSE);
1303 if (pspp_sheet_selection_get_mode (selection) != PSPP_SHEET_SELECTION_RECTANGLE)
1306 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
1307 if (event->type == GDK_BUTTON_PRESS && event->button == 3)
1309 if (pspp_sheet_selection_count_selected_columns (selection) <= 1
1310 || !all_rows_selected (sheet_view))
1312 pspp_sheet_selection_select_all (selection);
1313 pspp_sheet_selection_unselect_all_columns (selection);
1314 pspp_sheet_selection_select_column (selection, column);
1315 sheet_view->priv->anchor_column = column;
1319 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
1320 && modifiers == GDK_CONTROL_MASK)
1322 gboolean is_selected;
1324 if (!all_rows_selected (sheet_view))
1326 pspp_sheet_selection_select_all (selection);
1327 pspp_sheet_selection_unselect_all_columns (selection);
1329 sheet_view->priv->anchor_column = column;
1331 is_selected = pspp_sheet_view_column_get_selected (column);
1332 pspp_sheet_view_column_set_selected (column, !is_selected);
1336 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
1337 && modifiers == GDK_SHIFT_MASK)
1339 if (!all_rows_selected (sheet_view))
1341 pspp_sheet_selection_select_all (selection);
1342 pspp_sheet_selection_unselect_all_columns (selection);
1343 sheet_view->priv->anchor_column = column;
1345 else if (sheet_view->priv->anchor_column == NULL)
1346 sheet_view->priv->anchor_column = column;
1348 pspp_sheet_selection_unselect_all_columns (selection);
1349 pspp_sheet_selection_select_column_range (selection,
1350 sheet_view->priv->anchor_column,
1359 on_pspp_sheet_view_column_button_clicked (PsppSheetViewColumn *column)
1361 PsppSheetSelection *selection;
1362 PsppSheetView *sheet_view;
1364 sheet_view = PSPP_SHEET_VIEW (pspp_sheet_view_column_get_tree_view (column));
1365 selection = pspp_sheet_view_get_selection (sheet_view);
1366 if (pspp_sheet_selection_get_mode (selection) == PSPP_SHEET_SELECTION_RECTANGLE)
1368 pspp_sheet_selection_select_all (selection);
1369 pspp_sheet_selection_unselect_all_columns (selection);
1370 pspp_sheet_selection_select_column (selection, column);
1371 sheet_view->priv->anchor_column = column;
1378 pspp_sheet_view_column_button_clicked (GtkWidget *widget, gpointer data)
1380 PsppSheetViewColumn *column = data;
1383 g_signal_emit (column, tree_column_signals[CLICKED], 0, &handled);
1387 pspp_sheet_view_column_button_popup_menu (GtkWidget *widget, gpointer data)
1389 g_signal_emit_by_name (data, "popup-menu");
1393 pspp_sheet_view_column_mnemonic_activate (GtkWidget *widget,
1394 gboolean group_cycling,
1397 PsppSheetViewColumn *column = (PsppSheetViewColumn *)data;
1399 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), FALSE);
1401 PSPP_SHEET_VIEW (column->tree_view)->priv->focus_column = column;
1402 if (column->clickable)
1403 gtk_button_clicked (GTK_BUTTON (column->button));
1404 else if (gtk_widget_get_can_focus (column->button))
1405 gtk_widget_grab_focus (column->button);
1407 gtk_widget_grab_focus (column->tree_view);
1413 pspp_sheet_view_model_sort_column_changed (GtkTreeSortable *sortable,
1414 PsppSheetViewColumn *column)
1416 gint sort_column_id;
1419 if (gtk_tree_sortable_get_sort_column_id (sortable,
1423 if (sort_column_id == column->sort_column_id)
1425 pspp_sheet_view_column_set_sort_indicator (column, TRUE);
1426 pspp_sheet_view_column_set_sort_order (column, order);
1430 pspp_sheet_view_column_set_sort_indicator (column, FALSE);
1435 pspp_sheet_view_column_set_sort_indicator (column, FALSE);
1440 pspp_sheet_view_column_sort (PsppSheetViewColumn *tree_column,
1443 gint sort_column_id;
1445 gboolean has_sort_column;
1446 gboolean has_default_sort_func;
1448 g_return_if_fail (tree_column->tree_view != NULL);
1451 gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model),
1454 has_default_sort_func =
1455 gtk_tree_sortable_has_default_sort_func (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model));
1457 if (has_sort_column &&
1458 sort_column_id == tree_column->sort_column_id)
1460 if (order == GTK_SORT_ASCENDING)
1461 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model),
1462 tree_column->sort_column_id,
1463 GTK_SORT_DESCENDING);
1464 else if (order == GTK_SORT_DESCENDING && has_default_sort_func)
1465 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model),
1466 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
1467 GTK_SORT_ASCENDING);
1469 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model),
1470 tree_column->sort_column_id,
1471 GTK_SORT_ASCENDING);
1475 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model),
1476 tree_column->sort_column_id,
1477 GTK_SORT_ASCENDING);
1483 pspp_sheet_view_column_setup_sort_column_id_callback (PsppSheetViewColumn *tree_column)
1485 GtkTreeModel *model;
1487 if (tree_column->tree_view == NULL)
1490 model = pspp_sheet_view_get_model (PSPP_SHEET_VIEW (tree_column->tree_view));
1495 if (GTK_IS_TREE_SORTABLE (model) &&
1496 tree_column->sort_column_id != -1)
1498 gint real_sort_column_id;
1499 GtkSortType real_order;
1501 if (tree_column->sort_column_changed_signal == 0)
1502 tree_column->sort_column_changed_signal =
1503 g_signal_connect (model, "sort-column-changed",
1504 G_CALLBACK (pspp_sheet_view_model_sort_column_changed),
1507 if (gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model),
1508 &real_sort_column_id,
1510 (real_sort_column_id == tree_column->sort_column_id))
1512 pspp_sheet_view_column_set_sort_indicator (tree_column, TRUE);
1513 pspp_sheet_view_column_set_sort_order (tree_column, real_order);
1517 pspp_sheet_view_column_set_sort_indicator (tree_column, FALSE);
1523 /* Exported Private Functions.
1524 * These should only be called by gtktreeview.c or gtktreeviewcolumn.c
1528 _pspp_sheet_view_column_realize_button (PsppSheetViewColumn *column)
1530 PsppSheetView *tree_view;
1532 guint attributes_mask;
1535 tree_view = (PsppSheetView *)column->tree_view;
1536 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1538 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
1539 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
1540 g_return_if_fail (tree_view->priv->header_window != NULL);
1541 if (!column->need_button || !column->button)
1544 g_return_if_fail (column->button != NULL);
1546 gtk_widget_set_parent_window (column->button, tree_view->priv->header_window);
1548 if (column->visible)
1549 gtk_widget_show (column->button);
1551 attr.window_type = GDK_WINDOW_CHILD;
1552 attr.wclass = GDK_INPUT_ONLY;
1553 attr.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
1554 attr.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
1555 attr.event_mask = gtk_widget_get_events (GTK_WIDGET (tree_view)) |
1556 (GDK_BUTTON_PRESS_MASK |
1557 GDK_BUTTON_RELEASE_MASK |
1558 GDK_POINTER_MOTION_MASK |
1559 GDK_POINTER_MOTION_HINT_MASK |
1560 GDK_KEY_PRESS_MASK);
1561 attributes_mask = GDK_WA_CURSOR | GDK_WA_X | GDK_WA_Y;
1562 attr.cursor = gdk_cursor_new_for_display (gdk_drawable_get_display (tree_view->priv->header_window),
1563 GDK_SB_H_DOUBLE_ARROW);
1565 attr.width = TREE_VIEW_DRAG_WIDTH;
1566 attr.height = tree_view->priv->header_height;
1568 attr.x = (column->button->allocation.x + (rtl ? 0 : column->button->allocation.width)) - TREE_VIEW_DRAG_WIDTH / 2;
1569 column->window = gdk_window_new (tree_view->priv->header_window,
1570 &attr, attributes_mask);
1571 gdk_window_set_user_data (column->window, tree_view);
1573 pspp_sheet_view_column_update_button (column);
1575 gdk_cursor_unref (attr.cursor);
1579 _pspp_sheet_view_column_unrealize_button (PsppSheetViewColumn *column)
1581 g_return_if_fail (column != NULL);
1582 if (column->window != NULL)
1584 gdk_window_set_user_data (column->window, NULL);
1585 gdk_window_destroy (column->window);
1586 column->window = NULL;
1591 _pspp_sheet_view_column_unset_model (PsppSheetViewColumn *column,
1592 GtkTreeModel *old_model)
1594 if (column->sort_column_changed_signal)
1596 g_signal_handler_disconnect (old_model,
1597 column->sort_column_changed_signal);
1598 column->sort_column_changed_signal = 0;
1600 pspp_sheet_view_column_set_sort_indicator (column, FALSE);
1604 _pspp_sheet_view_column_set_tree_view (PsppSheetViewColumn *column,
1605 PsppSheetView *tree_view)
1607 g_assert (column->tree_view == NULL);
1609 column->tree_view = GTK_WIDGET (tree_view);
1610 if (column->need_button)
1611 pspp_sheet_view_column_create_button (column);
1613 column->property_changed_signal =
1614 g_signal_connect_swapped (tree_view,
1616 G_CALLBACK (pspp_sheet_view_column_setup_sort_column_id_callback),
1619 pspp_sheet_view_column_setup_sort_column_id_callback (column);
1623 _pspp_sheet_view_column_unset_tree_view (PsppSheetViewColumn *column)
1625 if (column->tree_view && column->button)
1627 gtk_container_remove (GTK_CONTAINER (column->tree_view), column->button);
1629 if (column->property_changed_signal)
1631 g_signal_handler_disconnect (column->tree_view, column->property_changed_signal);
1632 column->property_changed_signal = 0;
1635 if (column->sort_column_changed_signal)
1637 g_signal_handler_disconnect (pspp_sheet_view_get_model (PSPP_SHEET_VIEW (column->tree_view)),
1638 column->sort_column_changed_signal);
1639 column->sort_column_changed_signal = 0;
1642 column->tree_view = NULL;
1643 column->button = NULL;
1647 _pspp_sheet_view_column_has_editable_cell (PsppSheetViewColumn *column)
1651 for (list = column->cell_list; list; list = list->next)
1652 if (((PsppSheetViewColumnCellInfo *)list->data)->cell->mode ==
1653 GTK_CELL_RENDERER_MODE_EDITABLE)
1659 /* gets cell being edited */
1661 _pspp_sheet_view_column_get_edited_cell (PsppSheetViewColumn *column)
1665 for (list = column->cell_list; list; list = list->next)
1666 if (((PsppSheetViewColumnCellInfo *)list->data)->in_editing_mode)
1667 return ((PsppSheetViewColumnCellInfo *)list->data)->cell;
1673 _pspp_sheet_view_column_count_special_cells (PsppSheetViewColumn *column)
1678 for (list = column->cell_list; list; list = list->next)
1680 PsppSheetViewColumnCellInfo *cellinfo = list->data;
1682 if ((cellinfo->cell->mode == GTK_CELL_RENDERER_MODE_EDITABLE ||
1683 cellinfo->cell->mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE) &&
1684 cellinfo->cell->visible)
1692 _pspp_sheet_view_column_get_cell_at_pos (PsppSheetViewColumn *column,
1698 list = pspp_sheet_view_column_cell_first (column);
1699 for (; list; list = pspp_sheet_view_column_cell_next (column, list))
1701 PsppSheetViewColumnCellInfo *cellinfo = list->data;
1702 if (current_x <= x && x <= current_x + cellinfo->real_width)
1703 return cellinfo->cell;
1704 current_x += cellinfo->real_width;
1710 /* Public Functions */
1714 * pspp_sheet_view_column_new:
1716 * Creates a new #PsppSheetViewColumn.
1718 * Return value: A newly created #PsppSheetViewColumn.
1720 PsppSheetViewColumn *
1721 pspp_sheet_view_column_new (void)
1723 PsppSheetViewColumn *tree_column;
1725 tree_column = g_object_new (PSPP_TYPE_SHEET_VIEW_COLUMN, NULL);
1731 * pspp_sheet_view_column_new_with_attributes:
1732 * @title: The title to set the header to.
1733 * @cell: The #GtkCellRenderer.
1734 * @Varargs: A %NULL-terminated list of attributes.
1736 * Creates a new #PsppSheetViewColumn with a number of default values. This is
1737 * equivalent to calling pspp_sheet_view_column_set_title(),
1738 * pspp_sheet_view_column_pack_start(), and
1739 * pspp_sheet_view_column_set_attributes() on the newly created #PsppSheetViewColumn.
1741 * Here's a simple example:
1743 * enum { TEXT_COLUMN, COLOR_COLUMN, N_COLUMNS };
1746 * PsppSheetViewColumn *column;
1747 * GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
1749 * column = pspp_sheet_view_column_new_with_attributes ("Title",
1751 * "text", TEXT_COLUMN,
1752 * "foreground", COLOR_COLUMN,
1757 * Return value: A newly created #PsppSheetViewColumn.
1759 PsppSheetViewColumn *
1760 pspp_sheet_view_column_new_with_attributes (const gchar *title,
1761 GtkCellRenderer *cell,
1764 PsppSheetViewColumn *retval;
1767 retval = pspp_sheet_view_column_new ();
1769 pspp_sheet_view_column_set_title (retval, title);
1770 pspp_sheet_view_column_pack_start (retval, cell, TRUE);
1772 va_start (args, cell);
1773 pspp_sheet_view_column_set_attributesv (retval, cell, args);
1779 static PsppSheetViewColumnCellInfo *
1780 pspp_sheet_view_column_get_cell_info (PsppSheetViewColumn *tree_column,
1781 GtkCellRenderer *cell_renderer)
1784 for (list = tree_column->cell_list; list; list = list->next)
1785 if (((PsppSheetViewColumnCellInfo *)list->data)->cell == cell_renderer)
1786 return (PsppSheetViewColumnCellInfo *) list->data;
1792 * pspp_sheet_view_column_pack_start:
1793 * @tree_column: A #PsppSheetViewColumn.
1794 * @cell: The #GtkCellRenderer.
1795 * @expand: %TRUE if @cell is to be given extra space allocated to @tree_column.
1797 * Packs the @cell into the beginning of the column. If @expand is %FALSE, then
1798 * the @cell is allocated no more space than it needs. Any unused space is divided
1799 * evenly between cells for which @expand is %TRUE.
1802 pspp_sheet_view_column_pack_start (PsppSheetViewColumn *tree_column,
1803 GtkCellRenderer *cell,
1806 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (tree_column), cell, expand);
1810 * pspp_sheet_view_column_pack_end:
1811 * @tree_column: A #PsppSheetViewColumn.
1812 * @cell: The #GtkCellRenderer.
1813 * @expand: %TRUE if @cell is to be given extra space allocated to @tree_column.
1815 * Adds the @cell to end of the column. If @expand is %FALSE, then the @cell
1816 * is allocated no more space than it needs. Any unused space is divided
1817 * evenly between cells for which @expand is %TRUE.
1820 pspp_sheet_view_column_pack_end (PsppSheetViewColumn *tree_column,
1821 GtkCellRenderer *cell,
1824 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (tree_column), cell, expand);
1828 * pspp_sheet_view_column_clear:
1829 * @tree_column: A #PsppSheetViewColumn
1831 * Unsets all the mappings on all renderers on the @tree_column.
1834 pspp_sheet_view_column_clear (PsppSheetViewColumn *tree_column)
1836 gtk_cell_layout_clear (GTK_CELL_LAYOUT (tree_column));
1840 pspp_sheet_view_column_cell_layout_get_cells (GtkCellLayout *layout)
1842 PsppSheetViewColumn *tree_column = PSPP_SHEET_VIEW_COLUMN (layout);
1843 GList *retval = NULL, *list;
1845 g_return_val_if_fail (tree_column != NULL, NULL);
1847 for (list = tree_column->cell_list; list; list = list->next)
1849 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *)list->data;
1851 retval = g_list_append (retval, info->cell);
1858 * pspp_sheet_view_column_get_cell_renderers:
1859 * @tree_column: A #PsppSheetViewColumn
1861 * Returns a newly-allocated #GList of all the cell renderers in the column,
1862 * in no particular order. The list must be freed with g_list_free().
1864 * Return value: A list of #GtkCellRenderers
1866 * Deprecated: 2.18: use gtk_cell_layout_get_cells() instead.
1869 pspp_sheet_view_column_get_cell_renderers (PsppSheetViewColumn *tree_column)
1871 return pspp_sheet_view_column_cell_layout_get_cells (GTK_CELL_LAYOUT (tree_column));
1875 * pspp_sheet_view_column_add_attribute:
1876 * @tree_column: A #PsppSheetViewColumn.
1877 * @cell_renderer: the #GtkCellRenderer to set attributes on
1878 * @attribute: An attribute on the renderer
1879 * @column: The column position on the model to get the attribute from.
1881 * Adds an attribute mapping to the list in @tree_column. The @column is the
1882 * column of the model to get a value from, and the @attribute is the
1883 * parameter on @cell_renderer to be set from the value. So for example
1884 * if column 2 of the model contains strings, you could have the
1885 * "text" attribute of a #GtkCellRendererText get its values from
1889 pspp_sheet_view_column_add_attribute (PsppSheetViewColumn *tree_column,
1890 GtkCellRenderer *cell_renderer,
1891 const gchar *attribute,
1894 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (tree_column),
1895 cell_renderer, attribute, column);
1899 pspp_sheet_view_column_set_attributesv (PsppSheetViewColumn *tree_column,
1900 GtkCellRenderer *cell_renderer,
1906 attribute = va_arg (args, gchar *);
1908 pspp_sheet_view_column_clear_attributes (tree_column, cell_renderer);
1910 while (attribute != NULL)
1912 column = va_arg (args, gint);
1913 pspp_sheet_view_column_add_attribute (tree_column, cell_renderer, attribute, column);
1914 attribute = va_arg (args, gchar *);
1919 * pspp_sheet_view_column_set_attributes:
1920 * @tree_column: A #PsppSheetViewColumn.
1921 * @cell_renderer: the #GtkCellRenderer we're setting the attributes of
1922 * @Varargs: A %NULL-terminated list of attributes.
1924 * Sets the attributes in the list as the attributes of @tree_column.
1925 * The attributes should be in attribute/column order, as in
1926 * pspp_sheet_view_column_add_attribute(). All existing attributes
1927 * are removed, and replaced with the new attributes.
1930 pspp_sheet_view_column_set_attributes (PsppSheetViewColumn *tree_column,
1931 GtkCellRenderer *cell_renderer,
1936 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
1937 g_return_if_fail (GTK_IS_CELL_RENDERER (cell_renderer));
1938 g_return_if_fail (pspp_sheet_view_column_get_cell_info (tree_column, cell_renderer));
1940 va_start (args, cell_renderer);
1941 pspp_sheet_view_column_set_attributesv (tree_column, cell_renderer, args);
1947 * pspp_sheet_view_column_set_cell_data_func:
1948 * @tree_column: A #PsppSheetViewColumn
1949 * @cell_renderer: A #GtkCellRenderer
1950 * @func: The #PsppSheetViewColumnFunc to use.
1951 * @func_data: The user data for @func.
1952 * @destroy: The destroy notification for @func_data
1954 * Sets the #PsppSheetViewColumnFunc to use for the column. This
1955 * function is used instead of the standard attributes mapping for
1956 * setting the column value, and should set the value of @tree_column's
1957 * cell renderer as appropriate. @func may be %NULL to remove an
1961 pspp_sheet_view_column_set_cell_data_func (PsppSheetViewColumn *tree_column,
1962 GtkCellRenderer *cell_renderer,
1963 PsppSheetCellDataFunc func,
1965 GDestroyNotify destroy)
1967 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (tree_column),
1969 (GtkCellLayoutDataFunc)func,
1970 func_data, destroy);
1975 * pspp_sheet_view_column_clear_attributes:
1976 * @tree_column: a #PsppSheetViewColumn
1977 * @cell_renderer: a #GtkCellRenderer to clear the attribute mapping on.
1979 * Clears all existing attributes previously set with
1980 * pspp_sheet_view_column_set_attributes().
1983 pspp_sheet_view_column_clear_attributes (PsppSheetViewColumn *tree_column,
1984 GtkCellRenderer *cell_renderer)
1986 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (tree_column),
1991 * pspp_sheet_view_column_set_spacing:
1992 * @tree_column: A #PsppSheetViewColumn.
1993 * @spacing: distance between cell renderers in pixels.
1995 * Sets the spacing field of @tree_column, which is the number of pixels to
1996 * place between cell renderers packed into it.
1999 pspp_sheet_view_column_set_spacing (PsppSheetViewColumn *tree_column,
2002 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2003 g_return_if_fail (spacing >= 0);
2005 if (tree_column->spacing == spacing)
2008 tree_column->spacing = spacing;
2009 if (tree_column->tree_view)
2010 _pspp_sheet_view_column_cell_set_dirty (tree_column);
2014 * pspp_sheet_view_column_get_spacing:
2015 * @tree_column: A #PsppSheetViewColumn.
2017 * Returns the spacing of @tree_column.
2019 * Return value: the spacing of @tree_column.
2022 pspp_sheet_view_column_get_spacing (PsppSheetViewColumn *tree_column)
2024 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0);
2026 return tree_column->spacing;
2029 /* Options for manipulating the columns */
2032 * pspp_sheet_view_column_set_visible:
2033 * @tree_column: A #PsppSheetViewColumn.
2034 * @visible: %TRUE if the @tree_column is visible.
2036 * Sets the visibility of @tree_column.
2039 pspp_sheet_view_column_set_visible (PsppSheetViewColumn *tree_column,
2042 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2044 visible = !! visible;
2046 if (tree_column->visible == visible)
2049 tree_column->visible = visible;
2051 if (tree_column->visible)
2052 _pspp_sheet_view_column_cell_set_dirty (tree_column);
2054 pspp_sheet_view_column_update_button (tree_column);
2055 g_object_notify (G_OBJECT (tree_column), "visible");
2059 * pspp_sheet_view_column_get_visible:
2060 * @tree_column: A #PsppSheetViewColumn.
2062 * Returns %TRUE if @tree_column is visible.
2064 * Return value: whether the column is visible or not. If it is visible, then
2065 * the tree will show the column.
2068 pspp_sheet_view_column_get_visible (PsppSheetViewColumn *tree_column)
2070 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2072 return tree_column->visible;
2076 * pspp_sheet_view_column_set_resizable:
2077 * @tree_column: A #PsppSheetViewColumn
2078 * @resizable: %TRUE, if the column can be resized
2080 * If @resizable is %TRUE, then the user can explicitly resize the column by
2081 * grabbing the outer edge of the column button.
2084 pspp_sheet_view_column_set_resizable (PsppSheetViewColumn *tree_column,
2087 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2089 resizable = !! resizable;
2091 if (tree_column->resizable == resizable)
2094 tree_column->resizable = resizable;
2096 pspp_sheet_view_column_update_button (tree_column);
2098 g_object_notify (G_OBJECT (tree_column), "resizable");
2102 * pspp_sheet_view_column_get_resizable:
2103 * @tree_column: A #PsppSheetViewColumn
2105 * Returns %TRUE if the @tree_column can be resized by the end user.
2107 * Return value: %TRUE, if the @tree_column can be resized.
2110 pspp_sheet_view_column_get_resizable (PsppSheetViewColumn *tree_column)
2112 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2114 return tree_column->resizable;
2119 * pspp_sheet_view_column_get_width:
2120 * @tree_column: A #PsppSheetViewColumn.
2122 * Returns the current size of @tree_column in pixels.
2124 * Return value: The current width of @tree_column.
2127 pspp_sheet_view_column_get_width (PsppSheetViewColumn *tree_column)
2129 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0);
2131 return tree_column->width;
2135 * pspp_sheet_view_column_set_fixed_width:
2136 * @tree_column: A #PsppSheetViewColumn.
2137 * @fixed_width: The size to set @tree_column to. Must be greater than 0.
2139 * Sets the size of the column in pixels. The size of the column is clamped to
2140 * the min/max width for the column. Please note that the min/max width of the
2141 * column doesn't actually affect the "fixed_width" property of the widget, just
2142 * the actual size when displayed.
2145 pspp_sheet_view_column_set_fixed_width (PsppSheetViewColumn *tree_column,
2148 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2149 g_return_if_fail (fixed_width > 0);
2151 tree_column->fixed_width = fixed_width;
2152 tree_column->use_resized_width = FALSE;
2154 if (tree_column->tree_view &&
2155 gtk_widget_get_realized (tree_column->tree_view))
2157 gtk_widget_queue_resize (tree_column->tree_view);
2160 g_object_notify (G_OBJECT (tree_column), "fixed-width");
2164 * pspp_sheet_view_column_get_fixed_width:
2165 * @tree_column: a #PsppSheetViewColumn
2167 * Gets the fixed width of the column. This value is only meaning may not be
2168 * the actual width of the column on the screen, just what is requested.
2170 * Return value: the fixed width of the column
2173 pspp_sheet_view_column_get_fixed_width (PsppSheetViewColumn *tree_column)
2175 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0);
2177 return tree_column->fixed_width;
2181 * pspp_sheet_view_column_set_min_width:
2182 * @tree_column: A #PsppSheetViewColumn.
2183 * @min_width: The minimum width of the column in pixels, or -1.
2185 * Sets the minimum width of the @tree_column. If @min_width is -1, then the
2186 * minimum width is unset.
2189 pspp_sheet_view_column_set_min_width (PsppSheetViewColumn *tree_column,
2192 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2193 g_return_if_fail (min_width >= -1);
2195 if (min_width == tree_column->min_width)
2198 if (tree_column->visible &&
2199 tree_column->tree_view != NULL &&
2200 gtk_widget_get_realized (tree_column->tree_view))
2202 if (min_width > tree_column->width)
2203 gtk_widget_queue_resize (tree_column->tree_view);
2206 tree_column->min_width = min_width;
2207 g_object_freeze_notify (G_OBJECT (tree_column));
2208 if (tree_column->max_width != -1 && tree_column->max_width < min_width)
2210 tree_column->max_width = min_width;
2211 g_object_notify (G_OBJECT (tree_column), "max-width");
2213 g_object_notify (G_OBJECT (tree_column), "min-width");
2214 g_object_thaw_notify (G_OBJECT (tree_column));
2218 * pspp_sheet_view_column_get_min_width:
2219 * @tree_column: A #PsppSheetViewColumn.
2221 * Returns the minimum width in pixels of the @tree_column, or -1 if no minimum
2224 * Return value: The minimum width of the @tree_column.
2227 pspp_sheet_view_column_get_min_width (PsppSheetViewColumn *tree_column)
2229 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), -1);
2231 return tree_column->min_width;
2235 * pspp_sheet_view_column_set_max_width:
2236 * @tree_column: A #PsppSheetViewColumn.
2237 * @max_width: The maximum width of the column in pixels, or -1.
2239 * Sets the maximum width of the @tree_column. If @max_width is -1, then the
2240 * maximum width is unset. Note, the column can actually be wider than max
2241 * width if it's the last column in a view. In this case, the column expands to
2242 * fill any extra space.
2245 pspp_sheet_view_column_set_max_width (PsppSheetViewColumn *tree_column,
2248 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2249 g_return_if_fail (max_width >= -1);
2251 if (max_width == tree_column->max_width)
2254 if (tree_column->visible &&
2255 tree_column->tree_view != NULL &&
2256 gtk_widget_get_realized (tree_column->tree_view))
2258 if (max_width != -1 && max_width < tree_column->width)
2259 gtk_widget_queue_resize (tree_column->tree_view);
2262 tree_column->max_width = max_width;
2263 g_object_freeze_notify (G_OBJECT (tree_column));
2264 if (max_width != -1 && max_width < tree_column->min_width)
2266 tree_column->min_width = max_width;
2267 g_object_notify (G_OBJECT (tree_column), "min-width");
2269 g_object_notify (G_OBJECT (tree_column), "max-width");
2270 g_object_thaw_notify (G_OBJECT (tree_column));
2274 * pspp_sheet_view_column_get_max_width:
2275 * @tree_column: A #PsppSheetViewColumn.
2277 * Returns the maximum width in pixels of the @tree_column, or -1 if no maximum
2280 * Return value: The maximum width of the @tree_column.
2283 pspp_sheet_view_column_get_max_width (PsppSheetViewColumn *tree_column)
2285 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), -1);
2287 return tree_column->max_width;
2291 * pspp_sheet_view_column_clicked:
2292 * @tree_column: a #PsppSheetViewColumn
2294 * Emits the "clicked" signal on the column. This function will only work if
2295 * @tree_column is clickable.
2298 pspp_sheet_view_column_clicked (PsppSheetViewColumn *tree_column)
2300 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2302 if (tree_column->visible &&
2303 tree_column->button &&
2304 tree_column->clickable)
2305 gtk_button_clicked (GTK_BUTTON (tree_column->button));
2309 * pspp_sheet_view_column_set_title:
2310 * @tree_column: A #PsppSheetViewColumn.
2311 * @title: The title of the @tree_column.
2313 * Sets the title of the @tree_column. If a custom widget has been set, then
2314 * this value is ignored.
2317 pspp_sheet_view_column_set_title (PsppSheetViewColumn *tree_column,
2322 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2324 new_title = g_strdup (title);
2325 g_free (tree_column->title);
2326 tree_column->title = new_title;
2328 pspp_sheet_view_column_update_button (tree_column);
2329 g_object_notify (G_OBJECT (tree_column), "title");
2333 * pspp_sheet_view_column_get_title:
2334 * @tree_column: A #PsppSheetViewColumn.
2336 * Returns the title of the widget.
2338 * Return value: the title of the column. This string should not be
2339 * modified or freed.
2341 G_CONST_RETURN gchar *
2342 pspp_sheet_view_column_get_title (PsppSheetViewColumn *tree_column)
2344 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), NULL);
2346 return tree_column->title;
2350 * pspp_sheet_view_column_set_expand:
2351 * @tree_column: A #PsppSheetViewColumn
2352 * @expand: %TRUE if the column should take available extra space, %FALSE if not
2354 * Sets the column to take available extra space. This space is shared equally
2355 * amongst all columns that have the expand set to %TRUE. If no column has this
2356 * option set, then the last column gets all extra space. By default, every
2357 * column is created with this %FALSE.
2362 pspp_sheet_view_column_set_expand (PsppSheetViewColumn *tree_column,
2365 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2367 expand = expand?TRUE:FALSE;
2368 if (tree_column->expand == expand)
2370 tree_column->expand = expand;
2372 if (tree_column->visible &&
2373 tree_column->tree_view != NULL &&
2374 gtk_widget_get_realized (tree_column->tree_view))
2376 /* We want to continue using the original width of the
2377 * column that includes additional space added by the user
2378 * resizing the columns and possibly extra (expanded) space, which
2379 * are not included in the resized width.
2381 tree_column->use_resized_width = FALSE;
2383 gtk_widget_queue_resize (tree_column->tree_view);
2386 g_object_notify (G_OBJECT (tree_column), "expand");
2390 * pspp_sheet_view_column_get_expand:
2391 * @tree_column: a #PsppSheetViewColumn
2393 * Return %TRUE if the column expands to take any available space.
2395 * Return value: %TRUE, if the column expands
2400 pspp_sheet_view_column_get_expand (PsppSheetViewColumn *tree_column)
2402 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2404 return tree_column->expand;
2408 * pspp_sheet_view_column_set_clickable:
2409 * @tree_column: A #PsppSheetViewColumn.
2410 * @clickable: %TRUE if the header is active.
2412 * Sets the header to be active if @active is %TRUE. When the header is active,
2413 * then it can take keyboard focus, and can be clicked.
2416 pspp_sheet_view_column_set_clickable (PsppSheetViewColumn *tree_column,
2419 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2421 clickable = !! clickable;
2422 if (tree_column->clickable == clickable)
2425 tree_column->clickable = clickable;
2426 pspp_sheet_view_column_update_button (tree_column);
2427 g_object_notify (G_OBJECT (tree_column), "clickable");
2431 * pspp_sheet_view_column_get_clickable:
2432 * @tree_column: a #PsppSheetViewColumn
2434 * Returns %TRUE if the user can click on the header for the column.
2436 * Return value: %TRUE if user can click the column header.
2439 pspp_sheet_view_column_get_clickable (PsppSheetViewColumn *tree_column)
2441 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2443 return tree_column->clickable;
2447 * pspp_sheet_view_column_set_widget:
2448 * @tree_column: A #PsppSheetViewColumn.
2449 * @widget: (allow-none): A child #GtkWidget, or %NULL.
2451 * Sets the widget in the header to be @widget. If widget is %NULL, then the
2452 * header button is set with a #GtkLabel set to the title of @tree_column.
2455 pspp_sheet_view_column_set_widget (PsppSheetViewColumn *tree_column,
2458 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2459 g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
2462 g_object_ref_sink (widget);
2464 if (tree_column->child)
2465 g_object_unref (tree_column->child);
2467 tree_column->child = widget;
2468 pspp_sheet_view_column_update_button (tree_column);
2469 g_object_notify (G_OBJECT (tree_column), "widget");
2473 * pspp_sheet_view_column_get_widget:
2474 * @tree_column: A #PsppSheetViewColumn.
2476 * Returns the #GtkWidget in the button on the column header. If a custom
2477 * widget has not been set then %NULL is returned.
2479 * Return value: The #GtkWidget in the column header, or %NULL
2482 pspp_sheet_view_column_get_widget (PsppSheetViewColumn *tree_column)
2484 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), NULL);
2486 return tree_column->child;
2490 * pspp_sheet_view_column_set_alignment:
2491 * @tree_column: A #PsppSheetViewColumn.
2492 * @xalign: The alignment, which is between [0.0 and 1.0] inclusive.
2494 * Sets the alignment of the title or custom widget inside the column header.
2495 * The alignment determines its location inside the button -- 0.0 for left, 0.5
2496 * for center, 1.0 for right.
2499 pspp_sheet_view_column_set_alignment (PsppSheetViewColumn *tree_column,
2502 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2504 xalign = CLAMP (xalign, 0.0, 1.0);
2506 if (tree_column->xalign == xalign)
2509 tree_column->xalign = xalign;
2510 pspp_sheet_view_column_update_button (tree_column);
2511 g_object_notify (G_OBJECT (tree_column), "alignment");
2515 * pspp_sheet_view_column_get_alignment:
2516 * @tree_column: A #PsppSheetViewColumn.
2518 * Returns the current x alignment of @tree_column. This value can range
2519 * between 0.0 and 1.0.
2521 * Return value: The current alignent of @tree_column.
2524 pspp_sheet_view_column_get_alignment (PsppSheetViewColumn *tree_column)
2526 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0.5);
2528 return tree_column->xalign;
2532 * pspp_sheet_view_column_set_reorderable:
2533 * @tree_column: A #PsppSheetViewColumn
2534 * @reorderable: %TRUE, if the column can be reordered.
2536 * If @reorderable is %TRUE, then the column can be reordered by the end user
2537 * dragging the header.
2540 pspp_sheet_view_column_set_reorderable (PsppSheetViewColumn *tree_column,
2541 gboolean reorderable)
2543 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2546 pspp_sheet_view_column_set_clickable (tree_column, TRUE);*/
2548 if (tree_column->reorderable == (reorderable?TRUE:FALSE))
2551 tree_column->reorderable = (reorderable?TRUE:FALSE);
2552 pspp_sheet_view_column_update_button (tree_column);
2553 g_object_notify (G_OBJECT (tree_column), "reorderable");
2557 * pspp_sheet_view_column_get_reorderable:
2558 * @tree_column: A #PsppSheetViewColumn
2560 * Returns %TRUE if the @tree_column can be reordered by the user.
2562 * Return value: %TRUE if the @tree_column can be reordered by the user.
2565 pspp_sheet_view_column_get_reorderable (PsppSheetViewColumn *tree_column)
2567 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2569 return tree_column->reorderable;
2573 * pspp_sheet_view_column_set_quick_edit:
2574 * @tree_column: A #PsppSheetViewColumn
2575 * @quick_edit: If true, editing starts upon the first click in the column. If
2576 * false, the first click selects the column and a second click is needed to
2577 * begin editing. This has no effect on cells that are not editable.
2580 pspp_sheet_view_column_set_quick_edit (PsppSheetViewColumn *tree_column,
2581 gboolean quick_edit)
2583 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2585 quick_edit = !!quick_edit;
2586 if (tree_column->quick_edit != quick_edit)
2588 tree_column->quick_edit = (quick_edit?TRUE:FALSE);
2589 g_object_notify (G_OBJECT (tree_column), "quick-edit");
2594 * pspp_sheet_view_column_get_quick_edit:
2595 * @tree_column: A #PsppSheetViewColumn
2597 * Returns %TRUE if editing starts upon the first click in the column. Returns
2598 * %FALSE, the first click selects the column and a second click is needed to
2599 * begin editing. This is not meaningful for cells that are not editable.
2601 * Return value: %TRUE if editing starts upon the first click.
2604 pspp_sheet_view_column_get_quick_edit (PsppSheetViewColumn *tree_column)
2606 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2608 return tree_column->quick_edit;
2613 * pspp_sheet_view_column_set_selected:
2614 * @tree_column: A #PsppSheetViewColumn
2615 * @selected: If true, the column is selected as part of a rectangular
2619 pspp_sheet_view_column_set_selected (PsppSheetViewColumn *tree_column,
2622 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2624 selected = !!selected;
2625 if (tree_column->selected != selected)
2627 PsppSheetSelection *selection;
2628 PsppSheetView *sheet_view;
2630 if (tree_column->tree_view != NULL)
2631 gtk_widget_queue_draw (GTK_WIDGET (tree_column->tree_view));
2632 tree_column->selected = (selected?TRUE:FALSE);
2633 g_object_notify (G_OBJECT (tree_column), "selected");
2635 sheet_view = PSPP_SHEET_VIEW (pspp_sheet_view_column_get_tree_view (
2637 selection = pspp_sheet_view_get_selection (sheet_view);
2638 _pspp_sheet_selection_emit_changed (selection);
2643 * pspp_sheet_view_column_get_selected:
2644 * @tree_column: A #PsppSheetViewColumn
2646 * Returns %TRUE if the column is selected as part of a rectangular
2649 * Return value: %TRUE if the column is selected as part of a rectangular
2653 pspp_sheet_view_column_get_selected (PsppSheetViewColumn *tree_column)
2655 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2657 return tree_column->selected;
2661 * pspp_sheet_view_column_set_selectable:
2662 * @tree_column: A #PsppSheetViewColumn
2663 * @selectable: If true, the column may be selected as part of a rectangular
2667 pspp_sheet_view_column_set_selectable (PsppSheetViewColumn *tree_column,
2668 gboolean selectable)
2670 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2672 selectable = !!selectable;
2673 if (tree_column->selectable != selectable)
2675 if (tree_column->tree_view != NULL)
2676 gtk_widget_queue_draw (GTK_WIDGET (tree_column->tree_view));
2677 tree_column->selectable = (selectable?TRUE:FALSE);
2678 g_object_notify (G_OBJECT (tree_column), "selectable");
2683 * pspp_sheet_view_column_get_selectable:
2684 * @tree_column: A #PsppSheetViewColumn
2686 * Returns %TRUE if the column may be selected as part of a rectangular
2689 * Return value: %TRUE if the column may be selected as part of a rectangular
2693 pspp_sheet_view_column_get_selectable (PsppSheetViewColumn *tree_column)
2695 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2697 return tree_column->selectable;
2702 * pspp_sheet_view_column_set_row_head:
2703 * @tree_column: A #PsppSheetViewColumn
2704 * @row_head: If true, the column is a "row head", analogous to a column head.
2705 * See the description of the row-head property for more information.
2708 pspp_sheet_view_column_set_row_head (PsppSheetViewColumn *tree_column,
2711 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2713 row_head = !!row_head;
2714 if (tree_column->row_head != row_head)
2716 tree_column->row_head = (row_head?TRUE:FALSE);
2717 g_object_notify (G_OBJECT (tree_column), "row_head");
2722 * pspp_sheet_view_column_get_row_head:
2723 * @tree_column: A #PsppSheetViewColumn
2725 * Returns %TRUE if the column is a row head.
2727 * Return value: %TRUE if the column is a row head.
2730 pspp_sheet_view_column_get_row_head (PsppSheetViewColumn *tree_column)
2732 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2734 return tree_column->row_head;
2739 * pspp_sheet_view_column_set_sort_column_id:
2740 * @tree_column: a #PsppSheetViewColumn
2741 * @sort_column_id: The @sort_column_id of the model to sort on.
2743 * Sets the logical @sort_column_id that this column sorts on when this column
2744 * is selected for sorting. Doing so makes the column header clickable.
2747 pspp_sheet_view_column_set_sort_column_id (PsppSheetViewColumn *tree_column,
2748 gint sort_column_id)
2750 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2751 g_return_if_fail (sort_column_id >= -1);
2753 if (tree_column->sort_column_id == sort_column_id)
2756 tree_column->sort_column_id = sort_column_id;
2758 /* Handle unsetting the id */
2759 if (sort_column_id == -1)
2761 GtkTreeModel *model = pspp_sheet_view_get_model (PSPP_SHEET_VIEW (tree_column->tree_view));
2763 if (tree_column->sort_clicked_signal)
2765 g_signal_handler_disconnect (tree_column, tree_column->sort_clicked_signal);
2766 tree_column->sort_clicked_signal = 0;
2769 if (tree_column->sort_column_changed_signal)
2771 g_signal_handler_disconnect (model, tree_column->sort_column_changed_signal);
2772 tree_column->sort_column_changed_signal = 0;
2775 pspp_sheet_view_column_set_sort_order (tree_column, GTK_SORT_ASCENDING);
2776 pspp_sheet_view_column_set_sort_indicator (tree_column, FALSE);
2777 pspp_sheet_view_column_set_clickable (tree_column, FALSE);
2778 g_object_notify (G_OBJECT (tree_column), "sort-column-id");
2782 pspp_sheet_view_column_set_clickable (tree_column, TRUE);
2784 if (! tree_column->sort_clicked_signal)
2785 tree_column->sort_clicked_signal = g_signal_connect (tree_column,
2787 G_CALLBACK (pspp_sheet_view_column_sort),
2790 pspp_sheet_view_column_setup_sort_column_id_callback (tree_column);
2791 g_object_notify (G_OBJECT (tree_column), "sort-column-id");
2795 * pspp_sheet_view_column_get_sort_column_id:
2796 * @tree_column: a #PsppSheetViewColumn
2798 * Gets the logical @sort_column_id that the model sorts on when this
2799 * column is selected for sorting.
2800 * See pspp_sheet_view_column_set_sort_column_id().
2802 * Return value: the current @sort_column_id for this column, or -1 if
2803 * this column can't be used for sorting.
2806 pspp_sheet_view_column_get_sort_column_id (PsppSheetViewColumn *tree_column)
2808 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0);
2810 return tree_column->sort_column_id;
2814 * pspp_sheet_view_column_set_sort_indicator:
2815 * @tree_column: a #PsppSheetViewColumn
2816 * @setting: %TRUE to display an indicator that the column is sorted
2818 * Call this function with a @setting of %TRUE to display an arrow in
2819 * the header button indicating the column is sorted. Call
2820 * pspp_sheet_view_column_set_sort_order() to change the direction of
2825 pspp_sheet_view_column_set_sort_indicator (PsppSheetViewColumn *tree_column,
2828 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2830 setting = setting != FALSE;
2832 if (setting == tree_column->show_sort_indicator)
2835 tree_column->show_sort_indicator = setting;
2836 pspp_sheet_view_column_update_button (tree_column);
2837 g_object_notify (G_OBJECT (tree_column), "sort-indicator");
2841 * pspp_sheet_view_column_get_sort_indicator:
2842 * @tree_column: a #PsppSheetViewColumn
2844 * Gets the value set by pspp_sheet_view_column_set_sort_indicator().
2846 * Return value: whether the sort indicator arrow is displayed
2849 pspp_sheet_view_column_get_sort_indicator (PsppSheetViewColumn *tree_column)
2851 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2853 return tree_column->show_sort_indicator;
2857 * pspp_sheet_view_column_set_sort_order:
2858 * @tree_column: a #PsppSheetViewColumn
2859 * @order: sort order that the sort indicator should indicate
2861 * Changes the appearance of the sort indicator.
2863 * This <emphasis>does not</emphasis> actually sort the model. Use
2864 * pspp_sheet_view_column_set_sort_column_id() if you want automatic sorting
2865 * support. This function is primarily for custom sorting behavior, and should
2866 * be used in conjunction with gtk_tree_sortable_set_sort_column() to do
2867 * that. For custom models, the mechanism will vary.
2869 * The sort indicator changes direction to indicate normal sort or reverse sort.
2870 * Note that you must have the sort indicator enabled to see anything when
2871 * calling this function; see pspp_sheet_view_column_set_sort_indicator().
2874 pspp_sheet_view_column_set_sort_order (PsppSheetViewColumn *tree_column,
2877 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2879 if (order == tree_column->sort_order)
2882 tree_column->sort_order = order;
2883 pspp_sheet_view_column_update_button (tree_column);
2884 g_object_notify (G_OBJECT (tree_column), "sort-order");
2888 * pspp_sheet_view_column_get_sort_order:
2889 * @tree_column: a #PsppSheetViewColumn
2891 * Gets the value set by pspp_sheet_view_column_set_sort_order().
2893 * Return value: the sort order the sort indicator is indicating
2896 pspp_sheet_view_column_get_sort_order (PsppSheetViewColumn *tree_column)
2898 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0);
2900 return tree_column->sort_order;
2904 * pspp_sheet_view_column_cell_set_cell_data:
2905 * @tree_column: A #PsppSheetViewColumn.
2906 * @tree_model: The #GtkTreeModel to to get the cell renderers attributes from.
2907 * @iter: The #GtkTreeIter to to get the cell renderer's attributes from.
2909 * Sets the cell renderer based on the @tree_model and @iter. That is, for
2910 * every attribute mapping in @tree_column, it will get a value from the set
2911 * column on the @iter, and use that value to set the attribute on the cell
2912 * renderer. This is used primarily by the #PsppSheetView.
2915 pspp_sheet_view_column_cell_set_cell_data (PsppSheetViewColumn *tree_column,
2916 GtkTreeModel *tree_model,
2920 GValue value = { 0, };
2923 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2925 if (tree_model == NULL)
2928 for (cell_list = tree_column->cell_list; cell_list; cell_list = cell_list->next)
2930 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) cell_list->data;
2931 GObject *cell = (GObject *) info->cell;
2933 list = info->attributes;
2935 g_object_freeze_notify (cell);
2937 while (list && list->next)
2939 gtk_tree_model_get_value (tree_model, iter,
2940 GPOINTER_TO_INT (list->next->data),
2942 g_object_set_property (cell, (gchar *) list->data, &value);
2943 g_value_unset (&value);
2944 list = list->next->next;
2948 (* info->func) (tree_column, info->cell, tree_model, iter, info->func_data);
2949 g_object_thaw_notify (G_OBJECT (info->cell));
2955 * pspp_sheet_view_column_cell_get_size:
2956 * @tree_column: A #PsppSheetViewColumn.
2957 * @cell_area: (allow-none): The area a cell in the column will be allocated, or %NULL
2958 * @x_offset: (allow-none): location to return x offset of a cell relative to @cell_area, or %NULL
2959 * @y_offset: (allow-none): location to return y offset of a cell relative to @cell_area, or %NULL
2960 * @width: (allow-none): location to return width needed to render a cell, or %NULL
2961 * @height: (allow-none): location to return height needed to render a cell, or %NULL
2963 * Obtains the width and height needed to render the column. This is used
2964 * primarily by the #PsppSheetView.
2967 pspp_sheet_view_column_cell_get_size (PsppSheetViewColumn *tree_column,
2968 const GdkRectangle *cell_area,
2975 gboolean first_cell = TRUE;
2976 gint focus_line_width;
2978 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2985 gtk_widget_style_get (tree_column->tree_view, "focus-line-width", &focus_line_width, NULL);
2987 for (list = tree_column->cell_list; list; list = list->next)
2989 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
2991 gint new_height = 0;
2993 g_object_get (info->cell, "visible", &visible, NULL);
2995 if (visible == FALSE)
2998 if (first_cell == FALSE && width)
2999 *width += tree_column->spacing;
3001 gtk_cell_renderer_get_size (info->cell,
3002 tree_column->tree_view,
3010 * height = MAX (*height, new_height + focus_line_width * 2);
3011 info->requested_width = MAX (info->requested_width, new_width + focus_line_width * 2);
3013 * width += info->requested_width;
3018 /* rendering, event handling and rendering focus are somewhat complicated, and
3019 * quite a bit of code. Rather than duplicate them, we put them together to
3020 * keep the code in one place.
3022 * To better understand what's going on, check out
3023 * docs/tree-column-sizing.png
3032 pspp_sheet_view_column_cell_process_action (PsppSheetViewColumn *tree_column,
3034 const GdkRectangle *background_area,
3035 const GdkRectangle *cell_area,
3038 const GdkRectangle *expose_area, /* RENDER */
3039 GdkRectangle *focus_rectangle, /* FOCUS */
3040 GtkCellEditable **editable_widget, /* EVENT */
3041 GdkEvent *event, /* EVENT */
3042 gchar *path_string) /* EVENT */
3045 GdkRectangle real_cell_area;
3046 GdkRectangle real_background_area;
3047 GdkRectangle real_expose_area = *cell_area;
3049 gint expand_cell_count = 0;
3050 gint full_requested_width = 0;
3052 gint min_x, min_y, max_x, max_y;
3053 gint focus_line_width;
3055 gint horizontal_separator;
3056 gboolean cursor_row = FALSE;
3057 gboolean first_cell = TRUE;
3059 /* If we have rtl text, we need to transform our areas */
3060 GdkRectangle rtl_cell_area;
3061 GdkRectangle rtl_background_area;
3068 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_column->tree_view)) == GTK_TEXT_DIR_RTL);
3069 special_cells = _pspp_sheet_view_column_count_special_cells (tree_column);
3071 if (special_cells > 1 && action == CELL_ACTION_FOCUS)
3073 PsppSheetViewColumnCellInfo *info = NULL;
3074 gboolean found_has_focus = FALSE;
3076 /* one should have focus */
3077 for (list = tree_column->cell_list; list; list = list->next)
3080 if (info && info->has_focus)
3082 found_has_focus = TRUE;
3087 if (!found_has_focus)
3089 /* give the first one focus */
3090 info = pspp_sheet_view_column_cell_first (tree_column)->data;
3091 info->has_focus = TRUE;
3095 cursor_row = flags & GTK_CELL_RENDERER_FOCUSED;
3097 gtk_widget_style_get (GTK_WIDGET (tree_column->tree_view),
3098 "focus-line-width", &focus_line_width,
3099 "horizontal-separator", &horizontal_separator,
3102 real_cell_area = *cell_area;
3103 real_background_area = *background_area;
3106 real_cell_area.x += focus_line_width;
3107 real_cell_area.y += focus_line_width;
3108 real_cell_area.height -= 2 * focus_line_width;
3111 depth = real_background_area.width - real_cell_area.width;
3113 depth = real_cell_area.x - real_background_area.x;
3115 /* Find out how much extra space we have to allocate */
3116 for (list = tree_column->cell_list; list; list = list->next)
3118 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *)list->data;
3120 if (! info->cell->visible)
3123 if (info->expand == TRUE)
3124 expand_cell_count ++;
3125 full_requested_width += info->requested_width;
3128 full_requested_width += tree_column->spacing;
3133 extra_space = cell_area->width - full_requested_width;
3134 if (extra_space < 0)
3136 else if (extra_space > 0 && expand_cell_count > 0)
3137 extra_space /= expand_cell_count;
3139 /* iterate list for GTK_PACK_START cells */
3140 for (list = tree_column->cell_list; list; list = list->next)
3142 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
3144 if (info->pack == GTK_PACK_END)
3147 if (! info->cell->visible)
3150 if ((info->has_focus || special_cells == 1) && cursor_row)
3151 flags |= GTK_CELL_RENDERER_FOCUSED;
3153 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3155 info->real_width = info->requested_width + (info->expand?extra_space:0);
3157 /* We constrain ourselves to only the width available */
3158 if (real_cell_area.x - focus_line_width + info->real_width > cell_area->x + cell_area->width)
3160 info->real_width = cell_area->x + cell_area->width - real_cell_area.x;
3163 if (real_cell_area.x > cell_area->x + cell_area->width)
3166 real_cell_area.width = info->real_width;
3167 real_cell_area.width -= 2 * focus_line_width;
3171 real_background_area.width = info->real_width + depth;
3175 /* fill the rest of background for the last cell */
3176 real_background_area.width = background_area->x + background_area->width - real_background_area.x;
3179 rtl_cell_area = real_cell_area;
3180 rtl_background_area = real_background_area;
3184 rtl_cell_area.x = cell_area->x + cell_area->width - (real_cell_area.x - cell_area->x) - real_cell_area.width;
3185 rtl_background_area.x = background_area->x + background_area->width - (real_background_area.x - background_area->x) - real_background_area.width;
3189 if (action == CELL_ACTION_RENDER)
3191 gtk_cell_renderer_render (info->cell,
3193 tree_column->tree_view,
3194 &rtl_background_area,
3200 else if (action == CELL_ACTION_FOCUS)
3202 gint x_offset, y_offset, width, height;
3204 gtk_cell_renderer_get_size (info->cell,
3205 tree_column->tree_view,
3207 &x_offset, &y_offset,
3210 if (special_cells > 1)
3212 if (info->has_focus)
3214 min_x = rtl_cell_area.x + x_offset;
3215 max_x = min_x + width;
3216 min_y = rtl_cell_area.y + y_offset;
3217 max_y = min_y + height;
3222 if (min_x > (rtl_cell_area.x + x_offset))
3223 min_x = rtl_cell_area.x + x_offset;
3224 if (max_x < rtl_cell_area.x + x_offset + width)
3225 max_x = rtl_cell_area.x + x_offset + width;
3226 if (min_y > (rtl_cell_area.y + y_offset))
3227 min_y = rtl_cell_area.y + y_offset;
3228 if (max_y < rtl_cell_area.y + y_offset + height)
3229 max_y = rtl_cell_area.y + y_offset + height;
3233 else if (action == CELL_ACTION_EVENT)
3235 gboolean try_event = FALSE;
3239 if (special_cells == 1)
3241 /* only 1 activatable cell -> whole column can activate */
3242 if (cell_area->x <= ((GdkEventButton *)event)->x &&
3243 cell_area->x + cell_area->width > ((GdkEventButton *)event)->x)
3246 else if (rtl_cell_area.x <= ((GdkEventButton *)event)->x &&
3247 rtl_cell_area.x + rtl_cell_area.width > ((GdkEventButton *)event)->x)
3248 /* only activate cell if the user clicked on an individual
3253 else if (special_cells > 1 && info->has_focus)
3255 else if (special_cells == 1)
3260 gboolean visible, mode;
3262 g_object_get (info->cell,
3263 "visible", &visible,
3266 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
3268 if (gtk_cell_renderer_activate (info->cell,
3270 tree_column->tree_view,
3272 &rtl_background_area,
3276 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3280 else if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
3283 gtk_cell_renderer_start_editing (info->cell,
3285 tree_column->tree_view,
3287 &rtl_background_area,
3291 if (*editable_widget != NULL)
3293 g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
3294 info->in_editing_mode = TRUE;
3295 pspp_sheet_view_column_focus_cell (tree_column, info->cell);
3297 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3305 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3307 real_cell_area.x += (real_cell_area.width + 2 * focus_line_width + tree_column->spacing);
3308 real_background_area.x += real_background_area.width + tree_column->spacing;
3310 /* Only needed for first cell */
3314 /* iterate list for PACK_END cells */
3315 for (list = g_list_last (tree_column->cell_list); list; list = list->prev)
3317 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
3319 if (info->pack == GTK_PACK_START)
3322 if (! info->cell->visible)
3325 if ((info->has_focus || special_cells == 1) && cursor_row)
3326 flags |= GTK_CELL_RENDERER_FOCUSED;
3328 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3330 info->real_width = info->requested_width + (info->expand?extra_space:0);
3332 /* We constrain ourselves to only the width available */
3333 if (real_cell_area.x - focus_line_width + info->real_width > cell_area->x + cell_area->width)
3335 info->real_width = cell_area->x + cell_area->width - real_cell_area.x;
3338 if (real_cell_area.x > cell_area->x + cell_area->width)
3341 real_cell_area.width = info->real_width;
3342 real_cell_area.width -= 2 * focus_line_width;
3343 real_background_area.width = info->real_width + depth;
3345 rtl_cell_area = real_cell_area;
3346 rtl_background_area = real_background_area;
3349 rtl_cell_area.x = cell_area->x + cell_area->width - (real_cell_area.x - cell_area->x) - real_cell_area.width;
3350 rtl_background_area.x = background_area->x + background_area->width - (real_background_area.x - background_area->x) - real_background_area.width;
3354 if (action == CELL_ACTION_RENDER)
3356 gtk_cell_renderer_render (info->cell,
3358 tree_column->tree_view,
3359 &rtl_background_area,
3365 else if (action == CELL_ACTION_FOCUS)
3367 gint x_offset, y_offset, width, height;
3369 gtk_cell_renderer_get_size (info->cell,
3370 tree_column->tree_view,
3372 &x_offset, &y_offset,
3375 if (special_cells > 1)
3377 if (info->has_focus)
3379 min_x = rtl_cell_area.x + x_offset;
3380 max_x = min_x + width;
3381 min_y = rtl_cell_area.y + y_offset;
3382 max_y = min_y + height;
3387 if (min_x > (rtl_cell_area.x + x_offset))
3388 min_x = rtl_cell_area.x + x_offset;
3389 if (max_x < rtl_cell_area.x + x_offset + width)
3390 max_x = rtl_cell_area.x + x_offset + width;
3391 if (min_y > (rtl_cell_area.y + y_offset))
3392 min_y = rtl_cell_area.y + y_offset;
3393 if (max_y < rtl_cell_area.y + y_offset + height)
3394 max_y = rtl_cell_area.y + y_offset + height;
3398 else if (action == CELL_ACTION_EVENT)
3400 gboolean try_event = FALSE;
3404 if (special_cells == 1)
3406 /* only 1 activatable cell -> whole column can activate */
3407 if (cell_area->x <= ((GdkEventButton *)event)->x &&
3408 cell_area->x + cell_area->width > ((GdkEventButton *)event)->x)
3411 else if (rtl_cell_area.x <= ((GdkEventButton *)event)->x &&
3412 rtl_cell_area.x + rtl_cell_area.width > ((GdkEventButton *)event)->x)
3413 /* only activate cell if the user clicked on an individual
3418 else if (special_cells > 1 && info->has_focus)
3420 else if (special_cells == 1)
3425 gboolean visible, mode;
3427 g_object_get (info->cell,
3428 "visible", &visible,
3431 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
3433 if (gtk_cell_renderer_activate (info->cell,
3435 tree_column->tree_view,
3437 &rtl_background_area,
3441 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3445 else if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
3448 gtk_cell_renderer_start_editing (info->cell,
3450 tree_column->tree_view,
3452 &rtl_background_area,
3456 if (*editable_widget != NULL)
3458 g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
3459 info->in_editing_mode = TRUE;
3460 pspp_sheet_view_column_focus_cell (tree_column, info->cell);
3462 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3469 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3471 real_cell_area.x += (real_cell_area.width + 2 * focus_line_width + tree_column->spacing);
3472 real_background_area.x += (real_background_area.width + tree_column->spacing);
3474 /* Only needed for first cell */
3478 /* fill focus_rectangle when required */
3479 if (action == CELL_ACTION_FOCUS)
3481 if (min_x >= max_x || min_y >= max_y)
3483 *focus_rectangle = *cell_area;
3484 /* don't change the focus_rectangle, just draw it nicely inside
3489 focus_rectangle->x = min_x - focus_line_width;
3490 focus_rectangle->y = min_y - focus_line_width;
3491 focus_rectangle->width = (max_x - min_x) + 2 * focus_line_width;
3492 focus_rectangle->height = (max_y - min_y) + 2 * focus_line_width;
3500 * pspp_sheet_view_column_cell_render:
3501 * @tree_column: A #PsppSheetViewColumn.
3502 * @window: a #GdkDrawable to draw to
3503 * @background_area: entire cell area (including tree expanders and maybe padding on the sides)
3504 * @cell_area: area normally rendered by a cell renderer
3505 * @expose_area: area that actually needs updating
3506 * @flags: flags that affect rendering
3508 * Renders the cell contained by #tree_column. This is used primarily by the
3512 _pspp_sheet_view_column_cell_render (PsppSheetViewColumn *tree_column,
3514 const GdkRectangle *background_area,
3515 const GdkRectangle *cell_area,
3516 const GdkRectangle *expose_area,
3519 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
3520 g_return_if_fail (background_area != NULL);
3521 g_return_if_fail (cell_area != NULL);
3522 g_return_if_fail (expose_area != NULL);
3524 pspp_sheet_view_column_cell_process_action (tree_column,
3531 NULL, NULL, NULL, NULL);
3535 _pspp_sheet_view_column_cell_event (PsppSheetViewColumn *tree_column,
3536 GtkCellEditable **editable_widget,
3539 const GdkRectangle *background_area,
3540 const GdkRectangle *cell_area,
3543 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
3545 return pspp_sheet_view_column_cell_process_action (tree_column,
3558 _pspp_sheet_view_column_get_focus_area (PsppSheetViewColumn *tree_column,
3559 const GdkRectangle *background_area,
3560 const GdkRectangle *cell_area,
3561 GdkRectangle *focus_area)
3563 pspp_sheet_view_column_cell_process_action (tree_column,
3575 /* cell list manipulation */
3577 pspp_sheet_view_column_cell_first (PsppSheetViewColumn *tree_column)
3579 GList *list = tree_column->cell_list;
3581 /* first GTK_PACK_START cell we find */
3582 for ( ; list; list = list->next)
3584 PsppSheetViewColumnCellInfo *info = list->data;
3585 if (info->pack == GTK_PACK_START)
3589 /* hmm, else the *last* GTK_PACK_END cell */
3590 list = g_list_last (tree_column->cell_list);
3592 for ( ; list; list = list->prev)
3594 PsppSheetViewColumnCellInfo *info = list->data;
3595 if (info->pack == GTK_PACK_END)
3603 pspp_sheet_view_column_cell_last (PsppSheetViewColumn *tree_column)
3605 GList *list = tree_column->cell_list;
3607 /* *first* GTK_PACK_END cell we find */
3608 for ( ; list ; list = list->next)
3610 PsppSheetViewColumnCellInfo *info = list->data;
3611 if (info->pack == GTK_PACK_END)
3615 /* hmm, else the last GTK_PACK_START cell */
3616 list = g_list_last (tree_column->cell_list);
3618 for ( ; list; list = list->prev)
3620 PsppSheetViewColumnCellInfo *info = list->data;
3621 if (info->pack == GTK_PACK_START)
3629 pspp_sheet_view_column_cell_next (PsppSheetViewColumn *tree_column,
3633 PsppSheetViewColumnCellInfo *info = current->data;
3635 if (info->pack == GTK_PACK_START)
3637 for (list = current->next; list; list = list->next)
3639 PsppSheetViewColumnCellInfo *inf = list->data;
3640 if (inf->pack == GTK_PACK_START)
3644 /* out of GTK_PACK_START cells, get *last* GTK_PACK_END one */
3645 list = g_list_last (tree_column->cell_list);
3646 for (; list; list = list->prev)
3648 PsppSheetViewColumnCellInfo *inf = list->data;
3649 if (inf->pack == GTK_PACK_END)
3654 for (list = current->prev; list; list = list->prev)
3656 PsppSheetViewColumnCellInfo *inf = list->data;
3657 if (inf->pack == GTK_PACK_END)
3665 pspp_sheet_view_column_cell_prev (PsppSheetViewColumn *tree_column,
3669 PsppSheetViewColumnCellInfo *info = current->data;
3671 if (info->pack == GTK_PACK_END)
3673 for (list = current->next; list; list = list->next)
3675 PsppSheetViewColumnCellInfo *inf = list->data;
3676 if (inf->pack == GTK_PACK_END)
3680 /* out of GTK_PACK_END, get last GTK_PACK_START one */
3681 list = g_list_last (tree_column->cell_list);
3682 for ( ; list; list = list->prev)
3684 PsppSheetViewColumnCellInfo *inf = list->data;
3685 if (inf->pack == GTK_PACK_START)
3690 for (list = current->prev; list; list = list->prev)
3692 PsppSheetViewColumnCellInfo *inf = list->data;
3693 if (inf->pack == GTK_PACK_START)
3701 _pspp_sheet_view_column_cell_focus (PsppSheetViewColumn *tree_column,
3709 count = _pspp_sheet_view_column_count_special_cells (tree_column);
3710 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_column->tree_view)) == GTK_TEXT_DIR_RTL;
3712 /* if we are the current focus column and have multiple editable cells,
3713 * try to select the next one, else move the focus to the next column
3715 if (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->focus_column == tree_column)
3720 GList *list = tree_column->cell_list;
3721 PsppSheetViewColumnCellInfo *info = NULL;
3723 /* find current focussed cell */
3724 for ( ; list; list = list->next)
3727 if (info->has_focus)
3731 /* not a focussed cell in the focus column? */
3732 if (!list || !info || !info->has_focus)
3737 prev = pspp_sheet_view_column_cell_next (tree_column, list);
3738 next = pspp_sheet_view_column_cell_prev (tree_column, list);
3742 next = pspp_sheet_view_column_cell_next (tree_column, list);
3743 prev = pspp_sheet_view_column_cell_prev (tree_column, list);
3746 info->has_focus = FALSE;
3747 if (direction > 0 && next)
3750 info->has_focus = TRUE;
3753 else if (direction > 0 && !next && !right)
3755 /* keep focus on last cell */
3757 info = pspp_sheet_view_column_cell_first (tree_column)->data;
3759 info = pspp_sheet_view_column_cell_last (tree_column)->data;
3761 info->has_focus = TRUE;
3764 else if (direction < 0 && prev)
3767 info->has_focus = TRUE;
3770 else if (direction < 0 && !prev && !left)
3772 /* keep focus on first cell */
3774 info = pspp_sheet_view_column_cell_last (tree_column)->data;
3776 info = pspp_sheet_view_column_cell_first (tree_column)->data;
3778 info->has_focus = TRUE;
3785 /* we get focus, if we have multiple editable cells, give the correct one
3790 GList *list = tree_column->cell_list;
3792 /* clear focus first */
3793 for ( ; list ; list = list->next)
3795 PsppSheetViewColumnCellInfo *info = list->data;
3796 if (info->has_focus)
3797 info->has_focus = FALSE;
3804 list = pspp_sheet_view_column_cell_last (tree_column);
3805 else if (direction < 0)
3806 list = pspp_sheet_view_column_cell_first (tree_column);
3811 list = pspp_sheet_view_column_cell_first (tree_column);
3812 else if (direction < 0)
3813 list = pspp_sheet_view_column_cell_last (tree_column);
3817 ((PsppSheetViewColumnCellInfo *) list->data)->has_focus = TRUE;
3824 _pspp_sheet_view_column_cell_draw_focus (PsppSheetViewColumn *tree_column,
3826 const GdkRectangle *background_area,
3827 const GdkRectangle *cell_area,
3828 const GdkRectangle *expose_area,
3831 gint focus_line_width;
3832 GtkStateType cell_state;
3834 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
3835 gtk_widget_style_get (GTK_WIDGET (tree_column->tree_view),
3836 "focus-line-width", &focus_line_width, NULL);
3837 if (tree_column->editable_widget)
3839 /* This function is only called on the editable row when editing.
3842 gtk_paint_focus (tree_column->tree_view->style,
3844 gtk_widget_get_state (tree_column->tree_view),
3846 tree_column->tree_view,
3848 cell_area->x - focus_line_width,
3849 cell_area->y - focus_line_width,
3850 cell_area->width + 2 * focus_line_width,
3851 cell_area->height + 2 * focus_line_width);
3856 GdkRectangle focus_rectangle;
3857 pspp_sheet_view_column_cell_process_action (tree_column,
3867 cell_state = flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
3868 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
3869 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL));
3870 gtk_paint_focus (tree_column->tree_view->style,
3874 tree_column->tree_view,
3878 focus_rectangle.width,
3879 focus_rectangle.height);
3884 * pspp_sheet_view_column_cell_is_visible:
3885 * @tree_column: A #PsppSheetViewColumn
3887 * Returns %TRUE if any of the cells packed into the @tree_column are visible.
3888 * For this to be meaningful, you must first initialize the cells with
3889 * pspp_sheet_view_column_cell_set_cell_data()
3891 * Return value: %TRUE, if any of the cells packed into the @tree_column are currently visible
3894 pspp_sheet_view_column_cell_is_visible (PsppSheetViewColumn *tree_column)
3898 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
3900 for (list = tree_column->cell_list; list; list = list->next)
3902 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
3904 if (info->cell->visible)
3912 * pspp_sheet_view_column_focus_cell:
3913 * @tree_column: A #PsppSheetViewColumn
3914 * @cell: A #GtkCellRenderer
3916 * Sets the current keyboard focus to be at @cell, if the column contains
3917 * 2 or more editable and activatable cells.
3922 pspp_sheet_view_column_focus_cell (PsppSheetViewColumn *tree_column,
3923 GtkCellRenderer *cell)
3926 gboolean found_cell = FALSE;
3928 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
3929 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
3931 if (_pspp_sheet_view_column_count_special_cells (tree_column) < 2)
3934 for (list = tree_column->cell_list; list; list = list->next)
3936 PsppSheetViewColumnCellInfo *info = list->data;
3938 if (info->cell == cell)
3940 info->has_focus = TRUE;
3948 for (list = tree_column->cell_list; list; list = list->next)
3950 PsppSheetViewColumnCellInfo *info = list->data;
3952 if (info->cell != cell)
3953 info->has_focus = FALSE;
3956 /* FIXME: redraw? */
3961 _pspp_sheet_view_column_cell_set_dirty (PsppSheetViewColumn *tree_column)
3965 for (list = tree_column->cell_list; list; list = list->next)
3967 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
3969 info->requested_width = 0;
3971 tree_column->dirty = TRUE;
3972 tree_column->requested_width = -1;
3973 tree_column->width = 0;
3975 if (tree_column->tree_view &&
3976 gtk_widget_get_realized (tree_column->tree_view))
3978 _pspp_sheet_view_install_mark_rows_col_dirty (PSPP_SHEET_VIEW (tree_column->tree_view));
3979 gtk_widget_queue_resize (tree_column->tree_view);
3984 _pspp_sheet_view_column_start_editing (PsppSheetViewColumn *tree_column,
3985 GtkCellEditable *cell_editable)
3987 g_return_if_fail (tree_column->editable_widget == NULL);
3989 tree_column->editable_widget = cell_editable;
3993 _pspp_sheet_view_column_stop_editing (PsppSheetViewColumn *tree_column)
3997 g_return_if_fail (tree_column->editable_widget != NULL);
3999 tree_column->editable_widget = NULL;
4000 for (list = tree_column->cell_list; list; list = list->next)
4001 ((PsppSheetViewColumnCellInfo *)list->data)->in_editing_mode = FALSE;
4005 _pspp_sheet_view_column_get_neighbor_sizes (PsppSheetViewColumn *column,
4006 GtkCellRenderer *cell,
4011 PsppSheetViewColumnCellInfo *info;
4017 list = pspp_sheet_view_column_cell_first (column);
4021 info = (PsppSheetViewColumnCellInfo *)list->data;
4023 list = pspp_sheet_view_column_cell_next (column, list);
4025 if (info->cell == cell)
4028 if (info->cell->visible)
4029 l += info->real_width + column->spacing;
4034 info = (PsppSheetViewColumnCellInfo *)list->data;
4036 list = pspp_sheet_view_column_cell_next (column, list);
4038 if (info->cell->visible)
4039 r += info->real_width + column->spacing;
4042 rtl = (gtk_widget_get_direction (GTK_WIDGET (column->tree_view)) == GTK_TEXT_DIR_RTL);
4044 *left = rtl ? r : l;
4047 *right = rtl ? l : r;
4051 * pspp_sheet_view_column_cell_get_position:
4052 * @tree_column: a #PsppSheetViewColumn
4053 * @cell_renderer: a #GtkCellRenderer
4054 * @start_pos: return location for the horizontal position of @cell within
4055 * @tree_column, may be %NULL
4056 * @width: return location for the width of @cell, may be %NULL
4058 * Obtains the horizontal position and size of a cell in a column. If the
4059 * cell is not found in the column, @start_pos and @width are not changed and
4060 * %FALSE is returned.
4062 * Return value: %TRUE if @cell belongs to @tree_column.
4065 pspp_sheet_view_column_cell_get_position (PsppSheetViewColumn *tree_column,
4066 GtkCellRenderer *cell_renderer,
4072 gboolean found_cell = FALSE;
4073 PsppSheetViewColumnCellInfo *cellinfo = NULL;
4075 list = pspp_sheet_view_column_cell_first (tree_column);
4076 for (; list; list = pspp_sheet_view_column_cell_next (tree_column, list))
4078 cellinfo = list->data;
4079 if (cellinfo->cell == cell_renderer)
4085 if (cellinfo->cell->visible)
4086 current_x += cellinfo->real_width;
4092 *start_pos = current_x;
4094 *width = cellinfo->real_width;
4101 * pspp_sheet_view_column_queue_resize:
4102 * @tree_column: A #PsppSheetViewColumn
4104 * Flags the column, and the cell renderers added to this column, to have
4105 * their sizes renegotiated.
4110 pspp_sheet_view_column_queue_resize (PsppSheetViewColumn *tree_column)
4112 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
4114 if (tree_column->tree_view)
4115 _pspp_sheet_view_column_cell_set_dirty (tree_column);
4119 * pspp_sheet_view_column_get_tree_view:
4120 * @tree_column: A #PsppSheetViewColumn
4122 * Returns the #PsppSheetView wherein @tree_column has been inserted. If
4123 * @column is currently not inserted in any tree view, %NULL is
4126 * Return value: The tree view wherein @column has been inserted if any,
4132 pspp_sheet_view_column_get_tree_view (PsppSheetViewColumn *tree_column)
4134 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), NULL);
4136 return tree_column->tree_view;
4140 GtkCellLayout *cell_layout;
4141 GtkCellRenderer *renderer;
4143 } AttributesSubParserData;
4146 attributes_start_element (GMarkupParseContext *context,
4147 const gchar *element_name,
4148 const gchar **names,
4149 const gchar **values,
4153 AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
4156 if (strcmp (element_name, "attribute") == 0)
4158 for (i = 0; names[i]; i++)
4159 if (strcmp (names[i], "name") == 0)
4160 parser_data->attr_name = g_strdup (values[i]);
4162 else if (strcmp (element_name, "attributes") == 0)
4165 g_warning ("Unsupported tag for GtkCellLayout: %s\n", element_name);
4169 attributes_text_element (GMarkupParseContext *context,
4175 AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
4180 if (!parser_data->attr_name)
4184 string = g_strndup (text, text_len);
4185 l = strtol (string, &endptr, 0);
4186 if (errno || endptr == string)
4190 GTK_BUILDER_ERROR_INVALID_VALUE,
4191 "Could not parse integer `%s'",
4198 gtk_cell_layout_add_attribute (parser_data->cell_layout,
4199 parser_data->renderer,
4200 parser_data->attr_name, l);
4201 g_free (parser_data->attr_name);
4202 parser_data->attr_name = NULL;
4205 static const GMarkupParser attributes_parser =
4207 attributes_start_element,
4209 attributes_text_element,
4213 _gtk_cell_layout_buildable_custom_tag_start (GtkBuildable *buildable,
4214 GtkBuilder *builder,
4216 const gchar *tagname,
4217 GMarkupParser *parser,
4220 AttributesSubParserData *parser_data;
4225 if (strcmp (tagname, "attributes") == 0)
4227 parser_data = g_slice_new0 (AttributesSubParserData);
4228 parser_data->cell_layout = GTK_CELL_LAYOUT (buildable);
4229 parser_data->renderer = GTK_CELL_RENDERER (child);
4230 parser_data->attr_name = NULL;
4232 *parser = attributes_parser;
4233 *data = parser_data;
4241 _gtk_cell_layout_buildable_custom_tag_end (GtkBuildable *buildable,
4242 GtkBuilder *builder,
4244 const gchar *tagname,
4247 AttributesSubParserData *parser_data;
4249 parser_data = (AttributesSubParserData*)data;
4250 g_assert (!parser_data->attr_name);
4251 g_slice_free (AttributesSubParserData, parser_data);
4255 _gtk_cell_layout_buildable_add_child (GtkBuildable *buildable,
4256 GtkBuilder *builder,
4260 GtkCellLayoutIface *iface;
4262 g_return_if_fail (GTK_IS_CELL_LAYOUT (buildable));
4263 g_return_if_fail (GTK_IS_CELL_RENDERER (child));
4265 iface = GTK_CELL_LAYOUT_GET_IFACE (buildable);
4266 g_return_if_fail (iface->pack_start != NULL);
4267 iface->pack_start (GTK_CELL_LAYOUT (buildable), GTK_CELL_RENDERER (child), FALSE);
4271 pspp_sheet_view_column_size_request (PsppSheetViewColumn *tree_column,
4272 GtkRequisition *request)
4274 GtkWidget *base = GTK_WIDGET (tree_column->tree_view);
4275 GtkRequisition label_req;
4276 GtkRequisition align_req;
4277 GtkRequisition arrow_req;
4278 GtkRequisition hbox_req;
4279 GtkStyle **button_style;
4281 if (tree_column->button)
4283 gtk_widget_size_request (tree_column->button, request);
4287 facade_label_get_size_request (0, 0, base, tree_column->title, &label_req);
4288 facade_alignment_get_size_request (0, 0, 0, 0, 0, &label_req, &align_req);
4289 facade_arrow_get_size_request (0, 0, &arrow_req);
4291 facade_hbox_get_base_size_request (0, 2, 2, &hbox_req);
4292 facade_hbox_add_child_size_request (0, &arrow_req, 0, &hbox_req);
4293 facade_hbox_add_child_size_request (0, &align_req, 0, &hbox_req);
4295 button_style = &PSPP_SHEET_VIEW (tree_column->tree_view)->priv->button_style;
4296 if (*button_style == NULL)
4298 *button_style = facade_get_style (base, GTK_TYPE_BUTTON, 0);
4299 g_object_ref (*button_style);
4301 facade_button_get_size_request (0, base, *button_style, &hbox_req, request);
4305 pspp_sheet_view_column_size_allocate (PsppSheetViewColumn *tree_column,
4306 GtkAllocation *allocation)
4308 tree_column->allocation = *allocation;
4309 if (tree_column->button)
4310 gtk_widget_size_allocate (tree_column->button, allocation);
4314 pspp_sheet_view_column_can_focus (PsppSheetViewColumn *tree_column)
4316 return tree_column->reorderable || tree_column->clickable;
4320 pspp_sheet_view_column_set_need_button (PsppSheetViewColumn *tree_column,
4321 gboolean need_button)
4323 if (tree_column->need_button != need_button)
4325 tree_column->need_button = need_button;
4326 pspp_sheet_view_column_update_button (tree_column);
4327 _pspp_sheet_view_column_realize_button (tree_column);