1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011, 2012 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* gtktreeviewcolumn.c
18 * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Library General Public
22 * License as published by the Free Software Foundation; either
23 * version 2 of the License, or (at your option) any later version.
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Library General Public License for more details.
30 * You should have received a copy of the GNU Library General Public
31 * License along with this library; if not, write to the
32 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
33 * Boston, MA 02111-1307, USA.
38 #include "ui/gui/pspp-sheet-private.h"
45 #include "ui/gui/psppire-marshal.h"
46 #include "ui/gui/pspp-sheet-selection.h"
47 #include "ui/gui/pspp-widget-facade.h"
49 #define P_(STRING) STRING
50 #define GTK_PARAM_READABLE G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
51 #define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
88 typedef struct _PsppSheetViewColumnCellInfo PsppSheetViewColumnCellInfo;
89 struct _PsppSheetViewColumnCellInfo
91 GtkCellRenderer *cell;
93 PsppSheetCellDataFunc func;
95 GDestroyNotify destroy;
101 guint in_editing_mode : 1;
105 static void pspp_sheet_view_column_cell_layout_init (GtkCellLayoutIface *iface);
107 /* GObject methods */
108 static void pspp_sheet_view_column_set_property (GObject *object,
112 static void pspp_sheet_view_column_get_property (GObject *object,
116 static void pspp_sheet_view_column_finalize (GObject *object);
118 /* GtkCellLayout implementation */
119 static void pspp_sheet_view_column_cell_layout_pack_start (GtkCellLayout *cell_layout,
120 GtkCellRenderer *cell,
122 static void pspp_sheet_view_column_cell_layout_pack_end (GtkCellLayout *cell_layout,
123 GtkCellRenderer *cell,
125 static void pspp_sheet_view_column_cell_layout_clear (GtkCellLayout *cell_layout);
126 static void pspp_sheet_view_column_cell_layout_add_attribute (GtkCellLayout *cell_layout,
127 GtkCellRenderer *cell,
128 const gchar *attribute,
130 static void pspp_sheet_view_column_cell_layout_set_cell_data_func (GtkCellLayout *cell_layout,
131 GtkCellRenderer *cell,
132 GtkCellLayoutDataFunc func,
134 GDestroyNotify destroy);
135 static void pspp_sheet_view_column_cell_layout_clear_attributes (GtkCellLayout *cell_layout,
136 GtkCellRenderer *cell);
137 static void pspp_sheet_view_column_cell_layout_reorder (GtkCellLayout *cell_layout,
138 GtkCellRenderer *cell,
140 static GList *pspp_sheet_view_column_cell_layout_get_cells (GtkCellLayout *cell_layout);
142 /* Button handling code */
143 static void pspp_sheet_view_column_create_button (PsppSheetViewColumn *tree_column);
144 void pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
146 /* Button signal handlers */
147 static gint pspp_sheet_view_column_button_event (GtkWidget *widget,
150 static void pspp_sheet_view_column_button_clicked (GtkWidget *widget,
152 static void pspp_sheet_view_column_button_popup_menu (GtkWidget *widget,
154 static gboolean pspp_sheet_view_column_mnemonic_activate (GtkWidget *widget,
155 gboolean group_cycling,
157 static gboolean on_pspp_sheet_view_column_button_clicked (PsppSheetViewColumn *);
158 static gboolean on_pspp_sheet_view_column_button_press_event (PsppSheetViewColumn *,
161 /* Property handlers */
162 static void pspp_sheet_view_model_sort_column_changed (GtkTreeSortable *sortable,
163 PsppSheetViewColumn *tree_column);
165 /* Internal functions */
166 static void pspp_sheet_view_column_sort (PsppSheetViewColumn *tree_column,
168 static void pspp_sheet_view_column_setup_sort_column_id_callback (PsppSheetViewColumn *tree_column);
169 static void pspp_sheet_view_column_set_attributesv (PsppSheetViewColumn *tree_column,
170 GtkCellRenderer *cell_renderer,
172 static PsppSheetViewColumnCellInfo *pspp_sheet_view_column_get_cell_info (PsppSheetViewColumn *tree_column,
173 GtkCellRenderer *cell_renderer);
175 /* cell list manipulation */
176 static GList *pspp_sheet_view_column_cell_first (PsppSheetViewColumn *tree_column);
177 static GList *pspp_sheet_view_column_cell_last (PsppSheetViewColumn *tree_column);
178 static GList *pspp_sheet_view_column_cell_next (PsppSheetViewColumn *tree_column,
180 static GList *pspp_sheet_view_column_cell_prev (PsppSheetViewColumn *tree_column,
182 static void pspp_sheet_view_column_clear_attributes_by_info (PsppSheetViewColumn *tree_column,
183 PsppSheetViewColumnCellInfo *info);
184 /* GtkBuildable implementation */
185 static void pspp_sheet_view_column_buildable_init (GtkBuildableIface *iface);
187 static guint tree_column_signals[LAST_SIGNAL] = { 0 };
189 G_DEFINE_TYPE_WITH_CODE (PsppSheetViewColumn, pspp_sheet_view_column, GTK_TYPE_OBJECT,
190 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
191 pspp_sheet_view_column_cell_layout_init)
192 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
193 pspp_sheet_view_column_buildable_init))
197 pspp_sheet_view_column_class_init (PsppSheetViewColumnClass *class)
199 GObjectClass *object_class;
201 object_class = (GObjectClass*) class;
203 class->clicked = on_pspp_sheet_view_column_button_clicked;
204 class->button_press_event = on_pspp_sheet_view_column_button_press_event;
206 object_class->finalize = pspp_sheet_view_column_finalize;
207 object_class->set_property = pspp_sheet_view_column_set_property;
208 object_class->get_property = pspp_sheet_view_column_get_property;
210 tree_column_signals[CLICKED] =
211 g_signal_new ("clicked",
212 G_OBJECT_CLASS_TYPE (object_class),
214 G_STRUCT_OFFSET (PsppSheetViewColumnClass, clicked),
215 g_signal_accumulator_true_handled, NULL,
216 psppire_marshal_BOOLEAN__VOID,
219 tree_column_signals[POPUP_MENU] =
220 g_signal_new ("popup-menu",
221 G_OBJECT_CLASS_TYPE (object_class),
225 g_cclosure_marshal_VOID__VOID,
228 tree_column_signals[QUERY_TOOLTIP] =
229 g_signal_new ("query-tooltip",
230 G_OBJECT_CLASS_TYPE (object_class),
233 g_signal_accumulator_true_handled, NULL,
234 psppire_marshal_BOOLEAN__OBJECT,
238 tree_column_signals[BUTTON_PRESS_EVENT] =
239 g_signal_new ("button-press-event",
240 G_OBJECT_CLASS_TYPE (object_class),
241 G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
242 G_STRUCT_OFFSET (PsppSheetViewColumnClass, button_press_event),
243 g_signal_accumulator_true_handled, NULL,
244 psppire_marshal_BOOLEAN__BOXED,
246 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
248 g_object_class_install_property (object_class,
250 g_param_spec_boolean ("visible",
252 P_("Whether to display the column"),
254 GTK_PARAM_READWRITE));
256 g_object_class_install_property (object_class,
258 g_param_spec_boolean ("resizable",
260 P_("Column is user-resizable"),
262 GTK_PARAM_READWRITE));
264 g_object_class_install_property (object_class,
266 g_param_spec_int ("width",
268 P_("Current width of the column"),
272 GTK_PARAM_READABLE));
273 g_object_class_install_property (object_class,
275 g_param_spec_int ("spacing",
277 P_("Space which is inserted between cells"),
281 GTK_PARAM_READWRITE));
283 g_object_class_install_property (object_class,
285 g_param_spec_int ("fixed-width",
287 P_("Current fixed width of the column"),
291 GTK_PARAM_READWRITE));
293 g_object_class_install_property (object_class,
295 g_param_spec_int ("min-width",
297 P_("Minimum allowed width of the column"),
301 GTK_PARAM_READWRITE));
303 g_object_class_install_property (object_class,
305 g_param_spec_int ("max-width",
307 P_("Maximum allowed width of the column"),
311 GTK_PARAM_READWRITE));
313 g_object_class_install_property (object_class,
315 g_param_spec_string ("title",
317 P_("Title to appear in column header"),
319 GTK_PARAM_READWRITE));
321 g_object_class_install_property (object_class,
323 g_param_spec_boolean ("expand",
325 P_("Column gets share of extra width allocated to the widget"),
327 GTK_PARAM_READWRITE));
329 g_object_class_install_property (object_class,
331 g_param_spec_boolean ("clickable",
333 P_("Whether the header can be clicked"),
335 GTK_PARAM_READWRITE));
338 g_object_class_install_property (object_class,
340 g_param_spec_object ("widget",
342 P_("Widget to put in column header button instead of column title"),
344 GTK_PARAM_READWRITE));
346 g_object_class_install_property (object_class,
348 g_param_spec_float ("alignment",
350 P_("X Alignment of the column header text or widget"),
354 GTK_PARAM_READWRITE));
356 g_object_class_install_property (object_class,
358 g_param_spec_boolean ("reorderable",
360 P_("Whether the column can be reordered around the headers"),
362 GTK_PARAM_READWRITE));
364 g_object_class_install_property (object_class,
366 g_param_spec_boolean ("sort-indicator",
367 P_("Sort indicator"),
368 P_("Whether to show a sort indicator"),
370 GTK_PARAM_READWRITE));
372 g_object_class_install_property (object_class,
374 g_param_spec_enum ("sort-order",
376 P_("Sort direction the sort indicator should indicate"),
379 GTK_PARAM_READWRITE));
382 * PsppSheetViewColumn:sort-column-id:
384 * Logical sort column ID this column sorts on when selected for sorting. Setting the sort column ID makes the column header
385 * clickable. Set to %-1 to make the column unsortable.
389 g_object_class_install_property (object_class,
391 g_param_spec_int ("sort-column-id",
392 P_("Sort column ID"),
393 P_("Logical sort column ID this column sorts on when selected for sorting"),
397 GTK_PARAM_READWRITE));
399 g_object_class_install_property (object_class,
401 g_param_spec_boolean ("quick-edit",
403 P_("If true, editing starts upon the first click in the column. If false, the first click selects the column and a second click is needed to begin editing. This has no effect on cells that are not editable."),
405 GTK_PARAM_READWRITE));
407 g_object_class_install_property (object_class,
409 g_param_spec_boolean ("selected",
411 P_("If true, this column is selected as part of a rectangular selection."),
413 GTK_PARAM_READWRITE));
415 g_object_class_install_property (object_class,
417 g_param_spec_boolean ("selectable",
419 P_("If true, this column may be selected as part of a rectangular selection."),
421 GTK_PARAM_READWRITE));
423 g_object_class_install_property (object_class,
425 g_param_spec_boolean ("row-head",
427 P_("If true, this column is a \"row head\", equivalent to a column head. If rectangular selection is enabled, then shift+click and control+click in the column select row ranges and toggle row selection, respectively. The column should ordinarily include a button cell; clicking on the button will select the row (and deselect all other rows)."),
429 GTK_PARAM_READWRITE));
431 g_object_class_install_property (object_class,
433 g_param_spec_boolean ("tabbable",
435 P_("If true, Tab and Shift+Tab visit this column. If false, Tab and Shift+Tab skip this column."),
437 GTK_PARAM_READWRITE));
441 pspp_sheet_view_column_buildable_init (GtkBuildableIface *iface)
443 iface->add_child = _gtk_cell_layout_buildable_add_child;
444 iface->custom_tag_start = _gtk_cell_layout_buildable_custom_tag_start;
445 iface->custom_tag_end = _gtk_cell_layout_buildable_custom_tag_end;
449 pspp_sheet_view_column_cell_layout_init (GtkCellLayoutIface *iface)
451 iface->pack_start = pspp_sheet_view_column_cell_layout_pack_start;
452 iface->pack_end = pspp_sheet_view_column_cell_layout_pack_end;
453 iface->clear = pspp_sheet_view_column_cell_layout_clear;
454 iface->add_attribute = pspp_sheet_view_column_cell_layout_add_attribute;
455 iface->set_cell_data_func = pspp_sheet_view_column_cell_layout_set_cell_data_func;
456 iface->clear_attributes = pspp_sheet_view_column_cell_layout_clear_attributes;
457 iface->reorder = pspp_sheet_view_column_cell_layout_reorder;
458 iface->get_cells = pspp_sheet_view_column_cell_layout_get_cells;
462 pspp_sheet_view_column_init (PsppSheetViewColumn *tree_column)
464 tree_column->button = NULL;
465 tree_column->xalign = 0.0;
466 tree_column->width = 0;
467 tree_column->spacing = 0;
468 tree_column->requested_width = -1;
469 tree_column->min_width = -1;
470 tree_column->max_width = -1;
471 tree_column->resized_width = 0;
472 tree_column->visible = TRUE;
473 tree_column->resizable = FALSE;
474 tree_column->expand = FALSE;
475 tree_column->clickable = FALSE;
476 tree_column->dirty = TRUE;
477 tree_column->selected = FALSE;
478 tree_column->selectable = TRUE;
479 tree_column->row_head = FALSE;
480 tree_column->tabbable = TRUE;
481 tree_column->sort_order = GTK_SORT_ASCENDING;
482 tree_column->show_sort_indicator = FALSE;
483 tree_column->property_changed_signal = 0;
484 tree_column->sort_clicked_signal = 0;
485 tree_column->sort_column_changed_signal = 0;
486 tree_column->sort_column_id = -1;
487 tree_column->reorderable = FALSE;
488 tree_column->maybe_reordered = FALSE;
489 tree_column->fixed_width = 1;
490 tree_column->use_resized_width = FALSE;
491 tree_column->title = g_strdup ("");
492 tree_column->quick_edit = TRUE;
493 tree_column->need_button = FALSE;
497 pspp_sheet_view_column_finalize (GObject *object)
499 PsppSheetViewColumn *tree_column = (PsppSheetViewColumn *) object;
502 for (list = tree_column->cell_list; list; list = list->next)
504 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
508 GDestroyNotify d = info->destroy;
510 info->destroy = NULL;
513 pspp_sheet_view_column_clear_attributes_by_info (tree_column, info);
514 g_object_unref (info->cell);
518 g_free (tree_column->title);
519 g_list_free (tree_column->cell_list);
521 if (tree_column->child)
522 g_object_unref (tree_column->child);
524 G_OBJECT_CLASS (pspp_sheet_view_column_parent_class)->finalize (object);
528 pspp_sheet_view_column_set_property (GObject *object,
533 PsppSheetViewColumn *tree_column;
535 tree_column = PSPP_SHEET_VIEW_COLUMN (object);
540 pspp_sheet_view_column_set_visible (tree_column,
541 g_value_get_boolean (value));
545 pspp_sheet_view_column_set_resizable (tree_column,
546 g_value_get_boolean (value));
549 case PROP_FIXED_WIDTH:
550 pspp_sheet_view_column_set_fixed_width (tree_column,
551 g_value_get_int (value));
555 pspp_sheet_view_column_set_min_width (tree_column,
556 g_value_get_int (value));
560 pspp_sheet_view_column_set_max_width (tree_column,
561 g_value_get_int (value));
565 pspp_sheet_view_column_set_spacing (tree_column,
566 g_value_get_int (value));
570 pspp_sheet_view_column_set_title (tree_column,
571 g_value_get_string (value));
575 pspp_sheet_view_column_set_expand (tree_column,
576 g_value_get_boolean (value));
580 pspp_sheet_view_column_set_clickable (tree_column,
581 g_value_get_boolean (value));
585 pspp_sheet_view_column_set_widget (tree_column,
586 (GtkWidget*) g_value_get_object (value));
590 pspp_sheet_view_column_set_alignment (tree_column,
591 g_value_get_float (value));
594 case PROP_REORDERABLE:
595 pspp_sheet_view_column_set_reorderable (tree_column,
596 g_value_get_boolean (value));
599 case PROP_SORT_INDICATOR:
600 pspp_sheet_view_column_set_sort_indicator (tree_column,
601 g_value_get_boolean (value));
604 case PROP_SORT_ORDER:
605 pspp_sheet_view_column_set_sort_order (tree_column,
606 g_value_get_enum (value));
609 case PROP_SORT_COLUMN_ID:
610 pspp_sheet_view_column_set_sort_column_id (tree_column,
611 g_value_get_int (value));
614 case PROP_QUICK_EDIT:
615 pspp_sheet_view_column_set_quick_edit (tree_column,
616 g_value_get_boolean (value));
620 pspp_sheet_view_column_set_selected (tree_column,
621 g_value_get_boolean (value));
624 case PROP_SELECTABLE:
625 pspp_sheet_view_column_set_selectable (tree_column,
626 g_value_get_boolean (value));
630 pspp_sheet_view_column_set_row_head (tree_column,
631 g_value_get_boolean (value));
635 pspp_sheet_view_column_set_tabbable (tree_column,
636 g_value_get_boolean (value));
640 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
646 pspp_sheet_view_column_get_property (GObject *object,
651 PsppSheetViewColumn *tree_column;
653 tree_column = PSPP_SHEET_VIEW_COLUMN (object);
658 g_value_set_boolean (value,
659 pspp_sheet_view_column_get_visible (tree_column));
663 g_value_set_boolean (value,
664 pspp_sheet_view_column_get_resizable (tree_column));
668 g_value_set_int (value,
669 pspp_sheet_view_column_get_width (tree_column));
673 g_value_set_int (value,
674 pspp_sheet_view_column_get_spacing (tree_column));
677 case PROP_FIXED_WIDTH:
678 g_value_set_int (value,
679 pspp_sheet_view_column_get_fixed_width (tree_column));
683 g_value_set_int (value,
684 pspp_sheet_view_column_get_min_width (tree_column));
688 g_value_set_int (value,
689 pspp_sheet_view_column_get_max_width (tree_column));
693 g_value_set_string (value,
694 pspp_sheet_view_column_get_title (tree_column));
698 g_value_set_boolean (value,
699 pspp_sheet_view_column_get_expand (tree_column));
703 g_value_set_boolean (value,
704 pspp_sheet_view_column_get_clickable (tree_column));
708 g_value_set_object (value,
709 (GObject*) pspp_sheet_view_column_get_widget (tree_column));
713 g_value_set_float (value,
714 pspp_sheet_view_column_get_alignment (tree_column));
717 case PROP_REORDERABLE:
718 g_value_set_boolean (value,
719 pspp_sheet_view_column_get_reorderable (tree_column));
722 case PROP_SORT_INDICATOR:
723 g_value_set_boolean (value,
724 pspp_sheet_view_column_get_sort_indicator (tree_column));
727 case PROP_SORT_ORDER:
728 g_value_set_enum (value,
729 pspp_sheet_view_column_get_sort_order (tree_column));
732 case PROP_SORT_COLUMN_ID:
733 g_value_set_int (value,
734 pspp_sheet_view_column_get_sort_column_id (tree_column));
737 case PROP_QUICK_EDIT:
738 g_value_set_boolean (value,
739 pspp_sheet_view_column_get_quick_edit (tree_column));
743 g_value_set_boolean (value,
744 pspp_sheet_view_column_get_selected (tree_column));
747 case PROP_SELECTABLE:
748 g_value_set_boolean (value,
749 pspp_sheet_view_column_get_selectable (tree_column));
753 g_value_set_boolean (value,
754 pspp_sheet_view_column_get_row_head (tree_column));
758 g_value_set_boolean (value,
759 pspp_sheet_view_column_get_tabbable (tree_column));
763 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
768 /* Implementation of GtkCellLayout interface
772 pspp_sheet_view_column_cell_layout_pack_start (GtkCellLayout *cell_layout,
773 GtkCellRenderer *cell,
776 PsppSheetViewColumn *column;
777 PsppSheetViewColumnCellInfo *cell_info;
779 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
780 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
781 g_return_if_fail (! pspp_sheet_view_column_get_cell_info (column, cell));
783 g_object_ref_sink (cell);
785 cell_info = g_new0 (PsppSheetViewColumnCellInfo, 1);
786 cell_info->cell = cell;
787 cell_info->expand = expand ? TRUE : FALSE;
788 cell_info->pack = GTK_PACK_START;
789 cell_info->has_focus = 0;
790 cell_info->attributes = NULL;
792 column->cell_list = g_list_append (column->cell_list, cell_info);
796 pspp_sheet_view_column_cell_layout_pack_end (GtkCellLayout *cell_layout,
797 GtkCellRenderer *cell,
800 PsppSheetViewColumn *column;
801 PsppSheetViewColumnCellInfo *cell_info;
803 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
804 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
805 g_return_if_fail (! pspp_sheet_view_column_get_cell_info (column, cell));
807 g_object_ref_sink (cell);
809 cell_info = g_new0 (PsppSheetViewColumnCellInfo, 1);
810 cell_info->cell = cell;
811 cell_info->expand = expand ? TRUE : FALSE;
812 cell_info->pack = GTK_PACK_END;
813 cell_info->has_focus = 0;
814 cell_info->attributes = NULL;
816 column->cell_list = g_list_append (column->cell_list, cell_info);
820 pspp_sheet_view_column_cell_layout_clear (GtkCellLayout *cell_layout)
822 PsppSheetViewColumn *column;
824 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
825 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
827 while (column->cell_list)
829 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *)column->cell_list->data;
831 pspp_sheet_view_column_cell_layout_clear_attributes (cell_layout, info->cell);
832 g_object_unref (info->cell);
834 column->cell_list = g_list_delete_link (column->cell_list,
840 pspp_sheet_view_column_cell_layout_add_attribute (GtkCellLayout *cell_layout,
841 GtkCellRenderer *cell,
842 const gchar *attribute,
845 PsppSheetViewColumn *tree_column;
846 PsppSheetViewColumnCellInfo *info;
848 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
849 tree_column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
851 info = pspp_sheet_view_column_get_cell_info (tree_column, cell);
852 g_return_if_fail (info != NULL);
854 info->attributes = g_slist_prepend (info->attributes, GINT_TO_POINTER (column));
855 info->attributes = g_slist_prepend (info->attributes, g_strdup (attribute));
857 if (tree_column->tree_view)
858 _pspp_sheet_view_column_cell_set_dirty (tree_column);
862 pspp_sheet_view_column_cell_layout_set_cell_data_func (GtkCellLayout *cell_layout,
863 GtkCellRenderer *cell,
864 GtkCellLayoutDataFunc func,
866 GDestroyNotify destroy)
868 PsppSheetViewColumn *column;
869 PsppSheetViewColumnCellInfo *info;
871 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
872 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
874 info = pspp_sheet_view_column_get_cell_info (column, cell);
875 g_return_if_fail (info != NULL);
879 GDestroyNotify d = info->destroy;
881 info->destroy = NULL;
885 info->func = (PsppSheetCellDataFunc)func;
886 info->func_data = func_data;
887 info->destroy = destroy;
889 if (column->tree_view)
890 _pspp_sheet_view_column_cell_set_dirty (column);
894 pspp_sheet_view_column_cell_layout_clear_attributes (GtkCellLayout *cell_layout,
895 GtkCellRenderer *cell_renderer)
897 PsppSheetViewColumn *column;
898 PsppSheetViewColumnCellInfo *info;
900 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
901 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
903 info = pspp_sheet_view_column_get_cell_info (column, cell_renderer);
905 pspp_sheet_view_column_clear_attributes_by_info (column, info);
909 pspp_sheet_view_column_cell_layout_reorder (GtkCellLayout *cell_layout,
910 GtkCellRenderer *cell,
914 PsppSheetViewColumn *column;
915 PsppSheetViewColumnCellInfo *info;
917 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (cell_layout));
918 column = PSPP_SHEET_VIEW_COLUMN (cell_layout);
920 info = pspp_sheet_view_column_get_cell_info (column, cell);
922 g_return_if_fail (info != NULL);
923 g_return_if_fail (position >= 0);
925 link = g_list_find (column->cell_list, info);
927 g_return_if_fail (link != NULL);
929 column->cell_list = g_list_delete_link (column->cell_list, link);
930 column->cell_list = g_list_insert (column->cell_list, info, position);
932 if (column->tree_view)
933 gtk_widget_queue_draw (column->tree_view);
937 pspp_sheet_view_column_clear_attributes_by_info (PsppSheetViewColumn *tree_column,
938 PsppSheetViewColumnCellInfo *info)
942 list = info->attributes;
944 while (list && list->next)
947 list = list->next->next;
949 g_slist_free (info->attributes);
950 info->attributes = NULL;
952 if (tree_column->tree_view)
953 _pspp_sheet_view_column_cell_set_dirty (tree_column);
957 on_query_tooltip (GtkWidget *widget,
960 gboolean keyboard_mode,
964 PsppSheetViewColumn *tree_column = user_data;
967 g_signal_emit (tree_column, tree_column_signals[QUERY_TOOLTIP], 0,
973 on_button_pressed (GtkWidget *widget, GdkEventButton *event,
976 PsppSheetViewColumn *tree_column = user_data;
979 /* XXX See "Implement GtkWidget::popup_menu" in GTK+ reference manual. */
980 g_signal_emit (tree_column, tree_column_signals[BUTTON_PRESS_EVENT],
988 /* Button handling code
991 pspp_sheet_view_column_create_button (PsppSheetViewColumn *tree_column)
993 PsppSheetView *tree_view;
997 tree_view = (PsppSheetView *) tree_column->tree_view;
999 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
1000 g_return_if_fail (tree_column->button == NULL);
1002 gtk_widget_push_composite_child ();
1003 tree_column->button = gtk_button_new ();
1004 gtk_widget_add_events (tree_column->button, GDK_POINTER_MOTION_MASK);
1005 gtk_widget_pop_composite_child ();
1007 /* make sure we own a reference to it as well. */
1008 if (tree_view->priv->header_window)
1009 gtk_widget_set_parent_window (tree_column->button, tree_view->priv->header_window);
1010 gtk_widget_set_parent (tree_column->button, GTK_WIDGET (tree_view));
1012 g_signal_connect (tree_column->button, "event",
1013 G_CALLBACK (pspp_sheet_view_column_button_event),
1015 g_signal_connect (tree_column->button, "clicked",
1016 G_CALLBACK (pspp_sheet_view_column_button_clicked),
1018 g_signal_connect (tree_column->button, "popup-menu",
1019 G_CALLBACK (pspp_sheet_view_column_button_popup_menu),
1021 g_signal_connect (tree_column->button, "button-press-event",
1022 G_CALLBACK (on_button_pressed), tree_column);
1024 g_signal_connect (tree_column->button, "query-tooltip",
1025 G_CALLBACK (on_query_tooltip), tree_column);
1026 g_object_set (tree_column->button, "has-tooltip", TRUE, NULL);
1028 tree_column->alignment = gtk_alignment_new (tree_column->xalign, 0.5, 0.0, 0.0);
1030 hbox = gtk_hbox_new (FALSE, 2);
1031 tree_column->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN);
1033 if (tree_column->child)
1034 child = tree_column->child;
1037 child = gtk_label_new (tree_column->title);
1038 gtk_widget_show (child);
1041 g_signal_connect (child, "mnemonic-activate",
1042 G_CALLBACK (pspp_sheet_view_column_mnemonic_activate),
1045 if (tree_column->xalign <= 0.5)
1046 gtk_box_pack_end (GTK_BOX (hbox), tree_column->arrow, FALSE, FALSE, 0);
1048 gtk_box_pack_start (GTK_BOX (hbox), tree_column->arrow, FALSE, FALSE, 0);
1050 gtk_box_pack_start (GTK_BOX (hbox), tree_column->alignment, TRUE, TRUE, 0);
1052 gtk_container_add (GTK_CONTAINER (tree_column->alignment), child);
1053 gtk_container_add (GTK_CONTAINER (tree_column->button), hbox);
1055 gtk_widget_show (hbox);
1056 gtk_widget_show (tree_column->alignment);
1057 pspp_sheet_view_column_update_button (tree_column);
1061 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column)
1063 gint sort_column_id = -1;
1065 GtkWidget *alignment;
1067 GtkWidget *current_child;
1068 GtkArrowType arrow_type = GTK_ARROW_NONE;
1069 GtkTreeModel *model;
1072 if (tree_column->tree_view)
1073 model = pspp_sheet_view_get_model (PSPP_SHEET_VIEW (tree_column->tree_view));
1077 /* Create a button if necessary */
1078 if (tree_column->need_button &&
1079 tree_column->visible &&
1080 tree_column->button == NULL &&
1081 tree_column->tree_view &&
1082 gtk_widget_get_realized (tree_column->tree_view))
1083 pspp_sheet_view_column_create_button (tree_column);
1085 if (! tree_column->button)
1088 hbox = gtk_bin_get_child (GTK_BIN (tree_column->button));
1089 alignment = tree_column->alignment;
1090 arrow = tree_column->arrow;
1091 current_child = gtk_bin_get_child (GTK_BIN (alignment));
1093 /* Set up the actual button */
1094 gtk_alignment_set (GTK_ALIGNMENT (alignment), tree_column->xalign,
1097 if (tree_column->child)
1099 if (current_child != tree_column->child)
1101 gtk_container_remove (GTK_CONTAINER (alignment),
1103 gtk_container_add (GTK_CONTAINER (alignment),
1104 tree_column->child);
1109 if (current_child == NULL)
1111 current_child = gtk_label_new (NULL);
1112 gtk_widget_show (current_child);
1113 gtk_container_add (GTK_CONTAINER (alignment),
1117 g_return_if_fail (GTK_IS_LABEL (current_child));
1119 if (tree_column->title)
1120 gtk_label_set_text_with_mnemonic (GTK_LABEL (current_child),
1121 tree_column->title);
1123 gtk_label_set_text_with_mnemonic (GTK_LABEL (current_child),
1127 if (GTK_IS_TREE_SORTABLE (model))
1128 gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model),
1132 if (tree_column->show_sort_indicator)
1134 gboolean alternative;
1136 g_object_get (gtk_widget_get_settings (tree_column->tree_view),
1137 "gtk-alternative-sort-arrows", &alternative,
1140 switch (tree_column->sort_order)
1142 case GTK_SORT_ASCENDING:
1143 arrow_type = alternative ? GTK_ARROW_UP : GTK_ARROW_DOWN;
1146 case GTK_SORT_DESCENDING:
1147 arrow_type = alternative ? GTK_ARROW_DOWN : GTK_ARROW_UP;
1151 g_warning (G_STRLOC": bad sort order");
1156 gtk_arrow_set (GTK_ARROW (arrow),
1160 /* Put arrow on the right if the text is left-or-center justified, and on the
1161 * left otherwise; do this by packing boxes, so flipping text direction will
1164 g_object_ref (arrow);
1165 gtk_container_remove (GTK_CONTAINER (hbox), arrow);
1167 if (tree_column->xalign <= 0.5)
1169 gtk_box_pack_end (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
1173 gtk_box_pack_start (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
1174 /* move it to the front */
1175 gtk_box_reorder_child (GTK_BOX (hbox), arrow, 0);
1177 g_object_unref (arrow);
1179 if (tree_column->show_sort_indicator
1180 || (GTK_IS_TREE_SORTABLE (model) && tree_column->sort_column_id >= 0))
1181 gtk_widget_show (arrow);
1183 gtk_widget_hide (arrow);
1185 /* It's always safe to hide the button. It isn't always safe to show it, as
1186 * if you show it before it's realized, it'll get the wrong window. */
1187 if (tree_column->button &&
1188 tree_column->tree_view != NULL &&
1189 gtk_widget_get_realized (tree_column->tree_view))
1191 if (tree_column->visible)
1193 gtk_widget_show_now (tree_column->button);
1194 if (tree_column->window)
1196 if (tree_column->resizable)
1198 gdk_window_show (tree_column->window);
1199 gdk_window_raise (tree_column->window);
1203 gdk_window_hide (tree_column->window);
1209 gtk_widget_hide (tree_column->button);
1210 if (tree_column->window)
1211 gdk_window_hide (tree_column->window);
1215 can_focus = pspp_sheet_view_column_can_focus (tree_column);
1216 gtk_widget_set_can_focus (tree_column->button, can_focus);
1217 if (!can_focus && gtk_widget_has_focus (tree_column->button))
1219 GtkWidget *toplevel = gtk_widget_get_toplevel (tree_column->tree_view);
1220 if (gtk_widget_is_toplevel (toplevel))
1222 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
1226 /* Queue a resize on the assumption that we always want to catch all changes
1227 * and columns don't change all that often.
1229 if (gtk_widget_get_realized (tree_column->tree_view))
1230 gtk_widget_queue_resize (tree_column->tree_view);
1234 /* Button signal handlers
1238 pspp_sheet_view_column_button_event (GtkWidget *widget,
1242 PsppSheetViewColumn *column = (PsppSheetViewColumn *) data;
1244 g_return_val_if_fail (event != NULL, FALSE);
1246 if (event->type == GDK_BUTTON_PRESS &&
1247 column->reorderable &&
1248 ((GdkEventButton *)event)->button == 1)
1250 column->maybe_reordered = TRUE;
1251 gdk_window_get_pointer (gtk_button_get_event_window (GTK_BUTTON (widget)),
1255 gtk_widget_grab_focus (widget);
1258 if (event->type == GDK_BUTTON_RELEASE ||
1259 event->type == GDK_LEAVE_NOTIFY)
1260 column->maybe_reordered = FALSE;
1262 if (event->type == GDK_MOTION_NOTIFY &&
1263 column->maybe_reordered &&
1264 (gtk_drag_check_threshold (widget,
1267 (gint) ((GdkEventMotion *)event)->x,
1268 (gint) ((GdkEventMotion *)event)->y)))
1270 column->maybe_reordered = FALSE;
1271 _pspp_sheet_view_column_start_drag (PSPP_SHEET_VIEW (column->tree_view), column);
1274 if (column->clickable == FALSE)
1276 switch (event->type)
1278 case GDK_MOTION_NOTIFY:
1279 case GDK_BUTTON_RELEASE:
1280 case GDK_ENTER_NOTIFY:
1281 case GDK_LEAVE_NOTIFY:
1291 all_rows_selected (PsppSheetView *sheet_view)
1293 PsppSheetSelection *selection = sheet_view->priv->selection;
1294 gint n_rows, n_selected_rows;
1296 n_rows = sheet_view->priv->row_count;
1297 n_selected_rows = pspp_sheet_selection_count_selected_rows (selection);
1299 return n_rows > 0 && n_selected_rows >= n_rows;
1303 on_pspp_sheet_view_column_button_press_event (PsppSheetViewColumn *column,
1304 GdkEventButton *event)
1306 PsppSheetView *sheet_view = PSPP_SHEET_VIEW (column->tree_view);
1307 PsppSheetSelection *selection;
1308 GSignalInvocationHint *hint;
1311 /* We only want to run first, not last, but combining that with return type
1312 `gboolean' makes GObject warn, so just ignore the run_last call. */
1313 hint = g_signal_get_invocation_hint (column);
1314 g_return_val_if_fail (hint != NULL, FALSE);
1315 if (hint->run_type != G_SIGNAL_RUN_FIRST)
1318 g_return_val_if_fail (sheet_view != NULL, FALSE);
1320 selection = sheet_view->priv->selection;
1321 g_return_val_if_fail (selection != NULL, FALSE);
1323 if (pspp_sheet_selection_get_mode (selection) != PSPP_SHEET_SELECTION_RECTANGLE)
1326 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
1327 if (event->type == GDK_BUTTON_PRESS && event->button == 3)
1329 if (pspp_sheet_selection_count_selected_columns (selection) <= 1
1330 || !all_rows_selected (sheet_view))
1332 pspp_sheet_selection_select_all (selection);
1333 pspp_sheet_selection_unselect_all_columns (selection);
1334 pspp_sheet_selection_select_column (selection, column);
1335 sheet_view->priv->anchor_column = column;
1339 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
1340 && modifiers == GDK_CONTROL_MASK)
1342 gboolean is_selected;
1344 if (!all_rows_selected (sheet_view))
1346 pspp_sheet_selection_select_all (selection);
1347 pspp_sheet_selection_unselect_all_columns (selection);
1349 sheet_view->priv->anchor_column = column;
1351 is_selected = pspp_sheet_view_column_get_selected (column);
1352 pspp_sheet_view_column_set_selected (column, !is_selected);
1356 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
1357 && modifiers == GDK_SHIFT_MASK)
1359 if (!all_rows_selected (sheet_view))
1361 pspp_sheet_selection_select_all (selection);
1362 pspp_sheet_selection_unselect_all_columns (selection);
1363 sheet_view->priv->anchor_column = column;
1365 else if (sheet_view->priv->anchor_column == NULL)
1366 sheet_view->priv->anchor_column = column;
1368 pspp_sheet_selection_unselect_all_columns (selection);
1369 pspp_sheet_selection_select_column_range (selection,
1370 sheet_view->priv->anchor_column,
1379 on_pspp_sheet_view_column_button_clicked (PsppSheetViewColumn *column)
1381 PsppSheetSelection *selection;
1382 PsppSheetView *sheet_view;
1384 sheet_view = PSPP_SHEET_VIEW (pspp_sheet_view_column_get_tree_view (column));
1385 selection = pspp_sheet_view_get_selection (sheet_view);
1386 if (pspp_sheet_selection_get_mode (selection) == PSPP_SHEET_SELECTION_RECTANGLE)
1388 pspp_sheet_selection_select_all (selection);
1389 if (pspp_sheet_view_column_get_row_head (column))
1390 pspp_sheet_selection_select_all_columns (selection);
1393 pspp_sheet_selection_unselect_all_columns (selection);
1394 pspp_sheet_selection_select_column (selection, column);
1396 sheet_view->priv->anchor_column = column;
1403 pspp_sheet_view_column_button_clicked (GtkWidget *widget, gpointer data)
1405 PsppSheetViewColumn *column = data;
1408 g_signal_emit (column, tree_column_signals[CLICKED], 0, &handled);
1412 pspp_sheet_view_column_button_popup_menu (GtkWidget *widget, gpointer data)
1414 g_signal_emit_by_name (data, "popup-menu");
1418 pspp_sheet_view_column_mnemonic_activate (GtkWidget *widget,
1419 gboolean group_cycling,
1422 PsppSheetViewColumn *column = (PsppSheetViewColumn *)data;
1424 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), FALSE);
1426 PSPP_SHEET_VIEW (column->tree_view)->priv->focus_column = column;
1427 if (column->clickable)
1428 gtk_button_clicked (GTK_BUTTON (column->button));
1429 else if (gtk_widget_get_can_focus (column->button))
1430 gtk_widget_grab_focus (column->button);
1432 gtk_widget_grab_focus (column->tree_view);
1438 pspp_sheet_view_model_sort_column_changed (GtkTreeSortable *sortable,
1439 PsppSheetViewColumn *column)
1441 gint sort_column_id;
1444 if (gtk_tree_sortable_get_sort_column_id (sortable,
1448 if (sort_column_id == column->sort_column_id)
1450 pspp_sheet_view_column_set_sort_indicator (column, TRUE);
1451 pspp_sheet_view_column_set_sort_order (column, order);
1455 pspp_sheet_view_column_set_sort_indicator (column, FALSE);
1460 pspp_sheet_view_column_set_sort_indicator (column, FALSE);
1465 pspp_sheet_view_column_sort (PsppSheetViewColumn *tree_column,
1468 gint sort_column_id;
1470 gboolean has_sort_column;
1471 gboolean has_default_sort_func;
1473 g_return_if_fail (tree_column->tree_view != NULL);
1476 gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model),
1479 has_default_sort_func =
1480 gtk_tree_sortable_has_default_sort_func (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model));
1482 if (has_sort_column &&
1483 sort_column_id == tree_column->sort_column_id)
1485 if (order == GTK_SORT_ASCENDING)
1486 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model),
1487 tree_column->sort_column_id,
1488 GTK_SORT_DESCENDING);
1489 else if (order == GTK_SORT_DESCENDING && has_default_sort_func)
1490 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model),
1491 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
1492 GTK_SORT_ASCENDING);
1494 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model),
1495 tree_column->sort_column_id,
1496 GTK_SORT_ASCENDING);
1500 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->model),
1501 tree_column->sort_column_id,
1502 GTK_SORT_ASCENDING);
1508 pspp_sheet_view_column_setup_sort_column_id_callback (PsppSheetViewColumn *tree_column)
1510 GtkTreeModel *model;
1512 if (tree_column->tree_view == NULL)
1515 model = pspp_sheet_view_get_model (PSPP_SHEET_VIEW (tree_column->tree_view));
1520 if (GTK_IS_TREE_SORTABLE (model) &&
1521 tree_column->sort_column_id != -1)
1523 gint real_sort_column_id;
1524 GtkSortType real_order;
1526 if (tree_column->sort_column_changed_signal == 0)
1527 tree_column->sort_column_changed_signal =
1528 g_signal_connect (model, "sort-column-changed",
1529 G_CALLBACK (pspp_sheet_view_model_sort_column_changed),
1532 if (gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model),
1533 &real_sort_column_id,
1535 (real_sort_column_id == tree_column->sort_column_id))
1537 pspp_sheet_view_column_set_sort_indicator (tree_column, TRUE);
1538 pspp_sheet_view_column_set_sort_order (tree_column, real_order);
1542 pspp_sheet_view_column_set_sort_indicator (tree_column, FALSE);
1548 /* Exported Private Functions.
1549 * These should only be called by gtktreeview.c or gtktreeviewcolumn.c
1553 _pspp_sheet_view_column_realize_button (PsppSheetViewColumn *column)
1555 GtkAllocation allocation;
1556 PsppSheetView *tree_view;
1558 guint attributes_mask;
1561 tree_view = (PsppSheetView *)column->tree_view;
1562 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1564 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
1565 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
1566 g_return_if_fail (tree_view->priv->header_window != NULL);
1567 if (!column->need_button || !column->button)
1570 g_return_if_fail (column->button != NULL);
1572 gtk_widget_set_parent_window (column->button, tree_view->priv->header_window);
1574 if (column->visible)
1575 gtk_widget_show (column->button);
1577 attr.window_type = GDK_WINDOW_CHILD;
1578 attr.wclass = GDK_INPUT_ONLY;
1579 attr.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
1580 attr.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
1581 attr.event_mask = gtk_widget_get_events (GTK_WIDGET (tree_view)) |
1582 (GDK_BUTTON_PRESS_MASK |
1583 GDK_BUTTON_RELEASE_MASK |
1584 GDK_POINTER_MOTION_MASK |
1585 GDK_POINTER_MOTION_HINT_MASK |
1586 GDK_KEY_PRESS_MASK);
1587 attributes_mask = GDK_WA_CURSOR | GDK_WA_X | GDK_WA_Y;
1588 attr.cursor = gdk_cursor_new_for_display (gdk_window_get_display (tree_view->priv->header_window),
1589 GDK_SB_H_DOUBLE_ARROW);
1591 attr.width = TREE_VIEW_DRAG_WIDTH;
1592 attr.height = tree_view->priv->header_height;
1593 gtk_widget_get_allocation (column->button, &allocation);
1594 attr.x = (allocation.x + (rtl ? 0 : allocation.width)) - TREE_VIEW_DRAG_WIDTH / 2;
1595 column->window = gdk_window_new (tree_view->priv->header_window,
1596 &attr, attributes_mask);
1597 gdk_window_set_user_data (column->window, tree_view);
1599 pspp_sheet_view_column_update_button (column);
1601 gdk_cursor_unref (attr.cursor);
1605 _pspp_sheet_view_column_unrealize_button (PsppSheetViewColumn *column)
1607 g_return_if_fail (column != NULL);
1608 if (column->window != NULL)
1610 gdk_window_set_user_data (column->window, NULL);
1611 gdk_window_destroy (column->window);
1612 column->window = NULL;
1617 _pspp_sheet_view_column_unset_model (PsppSheetViewColumn *column,
1618 GtkTreeModel *old_model)
1620 if (column->sort_column_changed_signal)
1622 g_signal_handler_disconnect (old_model,
1623 column->sort_column_changed_signal);
1624 column->sort_column_changed_signal = 0;
1626 pspp_sheet_view_column_set_sort_indicator (column, FALSE);
1630 _pspp_sheet_view_column_set_tree_view (PsppSheetViewColumn *column,
1631 PsppSheetView *tree_view)
1633 g_assert (column->tree_view == NULL);
1635 column->tree_view = GTK_WIDGET (tree_view);
1636 if (column->need_button)
1637 pspp_sheet_view_column_create_button (column);
1639 column->property_changed_signal =
1640 g_signal_connect_swapped (tree_view,
1642 G_CALLBACK (pspp_sheet_view_column_setup_sort_column_id_callback),
1645 pspp_sheet_view_column_setup_sort_column_id_callback (column);
1649 _pspp_sheet_view_column_unset_tree_view (PsppSheetViewColumn *column)
1651 if (column->tree_view && column->button)
1653 gtk_container_remove (GTK_CONTAINER (column->tree_view), column->button);
1655 if (column->property_changed_signal)
1657 g_signal_handler_disconnect (column->tree_view, column->property_changed_signal);
1658 column->property_changed_signal = 0;
1661 if (column->sort_column_changed_signal)
1663 g_signal_handler_disconnect (pspp_sheet_view_get_model (PSPP_SHEET_VIEW (column->tree_view)),
1664 column->sort_column_changed_signal);
1665 column->sort_column_changed_signal = 0;
1668 column->tree_view = NULL;
1669 column->button = NULL;
1673 _pspp_sheet_view_column_has_editable_cell (PsppSheetViewColumn *column)
1677 for (list = column->cell_list; list; list = list->next)
1679 GtkCellRendererMode mode;
1680 g_object_get (((PsppSheetViewColumnCellInfo *)list->data)->cell, "mode", &mode, NULL);
1681 if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1688 /* gets cell being edited */
1690 _pspp_sheet_view_column_get_edited_cell (PsppSheetViewColumn *column)
1694 for (list = column->cell_list; list; list = list->next)
1695 if (((PsppSheetViewColumnCellInfo *)list->data)->in_editing_mode)
1696 return ((PsppSheetViewColumnCellInfo *)list->data)->cell;
1702 _pspp_sheet_view_column_count_special_cells (PsppSheetViewColumn *column)
1707 for (list = column->cell_list; list; list = list->next)
1709 PsppSheetViewColumnCellInfo *cellinfo = list->data;
1711 GtkCellRendererMode mode;
1712 g_object_get (cellinfo->cell, "mode", &mode, NULL);
1714 if ((mode == GTK_CELL_RENDERER_MODE_EDITABLE ||
1715 mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE) &&
1716 gtk_cell_renderer_get_visible (cellinfo->cell))
1724 _pspp_sheet_view_column_get_cell_at_pos (PsppSheetViewColumn *column,
1730 list = pspp_sheet_view_column_cell_first (column);
1731 for (; list; list = pspp_sheet_view_column_cell_next (column, list))
1733 PsppSheetViewColumnCellInfo *cellinfo = list->data;
1734 if (current_x <= x && x <= current_x + cellinfo->real_width)
1735 return cellinfo->cell;
1736 current_x += cellinfo->real_width;
1742 /* Public Functions */
1746 * pspp_sheet_view_column_new:
1748 * Creates a new #PsppSheetViewColumn.
1750 * Return value: A newly created #PsppSheetViewColumn.
1752 PsppSheetViewColumn *
1753 pspp_sheet_view_column_new (void)
1755 PsppSheetViewColumn *tree_column;
1757 tree_column = g_object_new (PSPP_TYPE_SHEET_VIEW_COLUMN, NULL);
1763 * pspp_sheet_view_column_new_with_attributes:
1764 * @title: The title to set the header to.
1765 * @cell: The #GtkCellRenderer.
1766 * @Varargs: A %NULL-terminated list of attributes.
1768 * Creates a new #PsppSheetViewColumn with a number of default values. This is
1769 * equivalent to calling pspp_sheet_view_column_set_title(),
1770 * pspp_sheet_view_column_pack_start(), and
1771 * pspp_sheet_view_column_set_attributes() on the newly created #PsppSheetViewColumn.
1773 * Here's a simple example:
1775 * enum { TEXT_COLUMN, COLOR_COLUMN, N_COLUMNS };
1778 * PsppSheetViewColumn *column;
1779 * GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
1781 * column = pspp_sheet_view_column_new_with_attributes ("Title",
1783 * "text", TEXT_COLUMN,
1784 * "foreground", COLOR_COLUMN,
1789 * Return value: A newly created #PsppSheetViewColumn.
1791 PsppSheetViewColumn *
1792 pspp_sheet_view_column_new_with_attributes (const gchar *title,
1793 GtkCellRenderer *cell,
1796 PsppSheetViewColumn *retval;
1799 retval = pspp_sheet_view_column_new ();
1801 pspp_sheet_view_column_set_title (retval, title);
1802 pspp_sheet_view_column_pack_start (retval, cell, TRUE);
1804 va_start (args, cell);
1805 pspp_sheet_view_column_set_attributesv (retval, cell, args);
1811 static PsppSheetViewColumnCellInfo *
1812 pspp_sheet_view_column_get_cell_info (PsppSheetViewColumn *tree_column,
1813 GtkCellRenderer *cell_renderer)
1816 for (list = tree_column->cell_list; list; list = list->next)
1817 if (((PsppSheetViewColumnCellInfo *)list->data)->cell == cell_renderer)
1818 return (PsppSheetViewColumnCellInfo *) list->data;
1824 * pspp_sheet_view_column_pack_start:
1825 * @tree_column: A #PsppSheetViewColumn.
1826 * @cell: The #GtkCellRenderer.
1827 * @expand: %TRUE if @cell is to be given extra space allocated to @tree_column.
1829 * Packs the @cell into the beginning of the column. If @expand is %FALSE, then
1830 * the @cell is allocated no more space than it needs. Any unused space is divided
1831 * evenly between cells for which @expand is %TRUE.
1834 pspp_sheet_view_column_pack_start (PsppSheetViewColumn *tree_column,
1835 GtkCellRenderer *cell,
1838 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (tree_column), cell, expand);
1842 * pspp_sheet_view_column_pack_end:
1843 * @tree_column: A #PsppSheetViewColumn.
1844 * @cell: The #GtkCellRenderer.
1845 * @expand: %TRUE if @cell is to be given extra space allocated to @tree_column.
1847 * Adds the @cell to end of the column. If @expand is %FALSE, then the @cell
1848 * is allocated no more space than it needs. Any unused space is divided
1849 * evenly between cells for which @expand is %TRUE.
1852 pspp_sheet_view_column_pack_end (PsppSheetViewColumn *tree_column,
1853 GtkCellRenderer *cell,
1856 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (tree_column), cell, expand);
1860 * pspp_sheet_view_column_clear:
1861 * @tree_column: A #PsppSheetViewColumn
1863 * Unsets all the mappings on all renderers on the @tree_column.
1866 pspp_sheet_view_column_clear (PsppSheetViewColumn *tree_column)
1868 gtk_cell_layout_clear (GTK_CELL_LAYOUT (tree_column));
1872 pspp_sheet_view_column_cell_layout_get_cells (GtkCellLayout *layout)
1874 PsppSheetViewColumn *tree_column = PSPP_SHEET_VIEW_COLUMN (layout);
1875 GList *retval = NULL, *list;
1877 g_return_val_if_fail (tree_column != NULL, NULL);
1879 for (list = tree_column->cell_list; list; list = list->next)
1881 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *)list->data;
1883 retval = g_list_append (retval, info->cell);
1890 * pspp_sheet_view_column_get_cell_renderers:
1891 * @tree_column: A #PsppSheetViewColumn
1893 * Returns a newly-allocated #GList of all the cell renderers in the column,
1894 * in no particular order. The list must be freed with g_list_free().
1896 * Return value: A list of #GtkCellRenderers
1898 * Deprecated: 2.18: use gtk_cell_layout_get_cells() instead.
1901 pspp_sheet_view_column_get_cell_renderers (PsppSheetViewColumn *tree_column)
1903 return pspp_sheet_view_column_cell_layout_get_cells (GTK_CELL_LAYOUT (tree_column));
1907 * pspp_sheet_view_column_add_attribute:
1908 * @tree_column: A #PsppSheetViewColumn.
1909 * @cell_renderer: the #GtkCellRenderer to set attributes on
1910 * @attribute: An attribute on the renderer
1911 * @column: The column position on the model to get the attribute from.
1913 * Adds an attribute mapping to the list in @tree_column. The @column is the
1914 * column of the model to get a value from, and the @attribute is the
1915 * parameter on @cell_renderer to be set from the value. So for example
1916 * if column 2 of the model contains strings, you could have the
1917 * "text" attribute of a #GtkCellRendererText get its values from
1921 pspp_sheet_view_column_add_attribute (PsppSheetViewColumn *tree_column,
1922 GtkCellRenderer *cell_renderer,
1923 const gchar *attribute,
1926 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (tree_column),
1927 cell_renderer, attribute, column);
1931 pspp_sheet_view_column_set_attributesv (PsppSheetViewColumn *tree_column,
1932 GtkCellRenderer *cell_renderer,
1938 attribute = va_arg (args, gchar *);
1940 pspp_sheet_view_column_clear_attributes (tree_column, cell_renderer);
1942 while (attribute != NULL)
1944 column = va_arg (args, gint);
1945 pspp_sheet_view_column_add_attribute (tree_column, cell_renderer, attribute, column);
1946 attribute = va_arg (args, gchar *);
1951 * pspp_sheet_view_column_set_attributes:
1952 * @tree_column: A #PsppSheetViewColumn.
1953 * @cell_renderer: the #GtkCellRenderer we're setting the attributes of
1954 * @Varargs: A %NULL-terminated list of attributes.
1956 * Sets the attributes in the list as the attributes of @tree_column.
1957 * The attributes should be in attribute/column order, as in
1958 * pspp_sheet_view_column_add_attribute(). All existing attributes
1959 * are removed, and replaced with the new attributes.
1962 pspp_sheet_view_column_set_attributes (PsppSheetViewColumn *tree_column,
1963 GtkCellRenderer *cell_renderer,
1968 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
1969 g_return_if_fail (GTK_IS_CELL_RENDERER (cell_renderer));
1970 g_return_if_fail (pspp_sheet_view_column_get_cell_info (tree_column, cell_renderer));
1972 va_start (args, cell_renderer);
1973 pspp_sheet_view_column_set_attributesv (tree_column, cell_renderer, args);
1979 * pspp_sheet_view_column_set_cell_data_func:
1980 * @tree_column: A #PsppSheetViewColumn
1981 * @cell_renderer: A #GtkCellRenderer
1982 * @func: The #PsppSheetViewColumnFunc to use.
1983 * @func_data: The user data for @func.
1984 * @destroy: The destroy notification for @func_data
1986 * Sets the #PsppSheetViewColumnFunc to use for the column. This
1987 * function is used instead of the standard attributes mapping for
1988 * setting the column value, and should set the value of @tree_column's
1989 * cell renderer as appropriate. @func may be %NULL to remove an
1993 pspp_sheet_view_column_set_cell_data_func (PsppSheetViewColumn *tree_column,
1994 GtkCellRenderer *cell_renderer,
1995 PsppSheetCellDataFunc func,
1997 GDestroyNotify destroy)
1999 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (tree_column),
2001 (GtkCellLayoutDataFunc)func,
2002 func_data, destroy);
2007 * pspp_sheet_view_column_clear_attributes:
2008 * @tree_column: a #PsppSheetViewColumn
2009 * @cell_renderer: a #GtkCellRenderer to clear the attribute mapping on.
2011 * Clears all existing attributes previously set with
2012 * pspp_sheet_view_column_set_attributes().
2015 pspp_sheet_view_column_clear_attributes (PsppSheetViewColumn *tree_column,
2016 GtkCellRenderer *cell_renderer)
2018 gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (tree_column),
2023 * pspp_sheet_view_column_set_spacing:
2024 * @tree_column: A #PsppSheetViewColumn.
2025 * @spacing: distance between cell renderers in pixels.
2027 * Sets the spacing field of @tree_column, which is the number of pixels to
2028 * place between cell renderers packed into it.
2031 pspp_sheet_view_column_set_spacing (PsppSheetViewColumn *tree_column,
2034 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2035 g_return_if_fail (spacing >= 0);
2037 if (tree_column->spacing == spacing)
2040 tree_column->spacing = spacing;
2041 if (tree_column->tree_view)
2042 _pspp_sheet_view_column_cell_set_dirty (tree_column);
2046 * pspp_sheet_view_column_get_spacing:
2047 * @tree_column: A #PsppSheetViewColumn.
2049 * Returns the spacing of @tree_column.
2051 * Return value: the spacing of @tree_column.
2054 pspp_sheet_view_column_get_spacing (PsppSheetViewColumn *tree_column)
2056 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0);
2058 return tree_column->spacing;
2061 /* Options for manipulating the columns */
2064 * pspp_sheet_view_column_set_visible:
2065 * @tree_column: A #PsppSheetViewColumn.
2066 * @visible: %TRUE if the @tree_column is visible.
2068 * Sets the visibility of @tree_column.
2071 pspp_sheet_view_column_set_visible (PsppSheetViewColumn *tree_column,
2074 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2076 visible = !! visible;
2078 if (tree_column->visible == visible)
2081 tree_column->visible = visible;
2083 if (tree_column->visible)
2084 _pspp_sheet_view_column_cell_set_dirty (tree_column);
2086 pspp_sheet_view_column_update_button (tree_column);
2087 g_object_notify (G_OBJECT (tree_column), "visible");
2091 * pspp_sheet_view_column_get_visible:
2092 * @tree_column: A #PsppSheetViewColumn.
2094 * Returns %TRUE if @tree_column is visible.
2096 * Return value: whether the column is visible or not. If it is visible, then
2097 * the tree will show the column.
2100 pspp_sheet_view_column_get_visible (PsppSheetViewColumn *tree_column)
2102 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2104 return tree_column->visible;
2108 * pspp_sheet_view_column_set_resizable:
2109 * @tree_column: A #PsppSheetViewColumn
2110 * @resizable: %TRUE, if the column can be resized
2112 * If @resizable is %TRUE, then the user can explicitly resize the column by
2113 * grabbing the outer edge of the column button.
2116 pspp_sheet_view_column_set_resizable (PsppSheetViewColumn *tree_column,
2119 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2121 resizable = !! resizable;
2123 if (tree_column->resizable == resizable)
2126 tree_column->resizable = resizable;
2128 pspp_sheet_view_column_update_button (tree_column);
2130 g_object_notify (G_OBJECT (tree_column), "resizable");
2134 * pspp_sheet_view_column_get_resizable:
2135 * @tree_column: A #PsppSheetViewColumn
2137 * Returns %TRUE if the @tree_column can be resized by the end user.
2139 * Return value: %TRUE, if the @tree_column can be resized.
2142 pspp_sheet_view_column_get_resizable (PsppSheetViewColumn *tree_column)
2144 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2146 return tree_column->resizable;
2151 * pspp_sheet_view_column_get_width:
2152 * @tree_column: A #PsppSheetViewColumn.
2154 * Returns the current size of @tree_column in pixels.
2156 * Return value: The current width of @tree_column.
2159 pspp_sheet_view_column_get_width (PsppSheetViewColumn *tree_column)
2161 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0);
2163 return tree_column->width;
2167 * pspp_sheet_view_column_set_fixed_width:
2168 * @tree_column: A #PsppSheetViewColumn.
2169 * @fixed_width: The size to set @tree_column to. Must be greater than 0.
2171 * Sets the size of the column in pixels. The size of the column is clamped to
2172 * the min/max width for the column. Please note that the min/max width of the
2173 * column doesn't actually affect the "fixed_width" property of the widget, just
2174 * the actual size when displayed.
2177 pspp_sheet_view_column_set_fixed_width (PsppSheetViewColumn *tree_column,
2180 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2181 g_return_if_fail (fixed_width > 0);
2183 tree_column->fixed_width = fixed_width;
2184 tree_column->use_resized_width = FALSE;
2186 if (tree_column->tree_view &&
2187 gtk_widget_get_realized (tree_column->tree_view))
2189 gtk_widget_queue_resize (tree_column->tree_view);
2192 g_object_notify (G_OBJECT (tree_column), "fixed-width");
2196 * pspp_sheet_view_column_get_fixed_width:
2197 * @tree_column: a #PsppSheetViewColumn
2199 * Gets the fixed width of the column. This value is only meaning may not be
2200 * the actual width of the column on the screen, just what is requested.
2202 * Return value: the fixed width of the column
2205 pspp_sheet_view_column_get_fixed_width (PsppSheetViewColumn *tree_column)
2207 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0);
2209 return tree_column->fixed_width;
2213 * pspp_sheet_view_column_set_min_width:
2214 * @tree_column: A #PsppSheetViewColumn.
2215 * @min_width: The minimum width of the column in pixels, or -1.
2217 * Sets the minimum width of the @tree_column. If @min_width is -1, then the
2218 * minimum width is unset.
2221 pspp_sheet_view_column_set_min_width (PsppSheetViewColumn *tree_column,
2224 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2225 g_return_if_fail (min_width >= -1);
2227 if (min_width == tree_column->min_width)
2230 if (tree_column->visible &&
2231 tree_column->tree_view != NULL &&
2232 gtk_widget_get_realized (tree_column->tree_view))
2234 if (min_width > tree_column->width)
2235 gtk_widget_queue_resize (tree_column->tree_view);
2238 tree_column->min_width = min_width;
2239 g_object_freeze_notify (G_OBJECT (tree_column));
2240 if (tree_column->max_width != -1 && tree_column->max_width < min_width)
2242 tree_column->max_width = min_width;
2243 g_object_notify (G_OBJECT (tree_column), "max-width");
2245 g_object_notify (G_OBJECT (tree_column), "min-width");
2246 g_object_thaw_notify (G_OBJECT (tree_column));
2250 * pspp_sheet_view_column_get_min_width:
2251 * @tree_column: A #PsppSheetViewColumn.
2253 * Returns the minimum width in pixels of the @tree_column, or -1 if no minimum
2256 * Return value: The minimum width of the @tree_column.
2259 pspp_sheet_view_column_get_min_width (PsppSheetViewColumn *tree_column)
2261 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), -1);
2263 return tree_column->min_width;
2267 * pspp_sheet_view_column_set_max_width:
2268 * @tree_column: A #PsppSheetViewColumn.
2269 * @max_width: The maximum width of the column in pixels, or -1.
2271 * Sets the maximum width of the @tree_column. If @max_width is -1, then the
2272 * maximum width is unset. Note, the column can actually be wider than max
2273 * width if it's the last column in a view. In this case, the column expands to
2274 * fill any extra space.
2277 pspp_sheet_view_column_set_max_width (PsppSheetViewColumn *tree_column,
2280 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2281 g_return_if_fail (max_width >= -1);
2283 if (max_width == tree_column->max_width)
2286 if (tree_column->visible &&
2287 tree_column->tree_view != NULL &&
2288 gtk_widget_get_realized (tree_column->tree_view))
2290 if (max_width != -1 && max_width < tree_column->width)
2291 gtk_widget_queue_resize (tree_column->tree_view);
2294 tree_column->max_width = max_width;
2295 g_object_freeze_notify (G_OBJECT (tree_column));
2296 if (max_width != -1 && max_width < tree_column->min_width)
2298 tree_column->min_width = max_width;
2299 g_object_notify (G_OBJECT (tree_column), "min-width");
2301 g_object_notify (G_OBJECT (tree_column), "max-width");
2302 g_object_thaw_notify (G_OBJECT (tree_column));
2306 * pspp_sheet_view_column_get_max_width:
2307 * @tree_column: A #PsppSheetViewColumn.
2309 * Returns the maximum width in pixels of the @tree_column, or -1 if no maximum
2312 * Return value: The maximum width of the @tree_column.
2315 pspp_sheet_view_column_get_max_width (PsppSheetViewColumn *tree_column)
2317 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), -1);
2319 return tree_column->max_width;
2323 * pspp_sheet_view_column_clicked:
2324 * @tree_column: a #PsppSheetViewColumn
2326 * Emits the "clicked" signal on the column. This function will only work if
2327 * @tree_column is clickable.
2330 pspp_sheet_view_column_clicked (PsppSheetViewColumn *tree_column)
2332 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2334 if (tree_column->visible &&
2335 tree_column->button &&
2336 tree_column->clickable)
2337 gtk_button_clicked (GTK_BUTTON (tree_column->button));
2341 * pspp_sheet_view_column_set_title:
2342 * @tree_column: A #PsppSheetViewColumn.
2343 * @title: The title of the @tree_column.
2345 * Sets the title of the @tree_column. If a custom widget has been set, then
2346 * this value is ignored.
2349 pspp_sheet_view_column_set_title (PsppSheetViewColumn *tree_column,
2354 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2356 new_title = g_strdup (title);
2357 g_free (tree_column->title);
2358 tree_column->title = new_title;
2360 pspp_sheet_view_column_update_button (tree_column);
2361 g_object_notify (G_OBJECT (tree_column), "title");
2365 * pspp_sheet_view_column_get_title:
2366 * @tree_column: A #PsppSheetViewColumn.
2368 * Returns the title of the widget.
2370 * Return value: the title of the column. This string should not be
2371 * modified or freed.
2374 pspp_sheet_view_column_get_title (PsppSheetViewColumn *tree_column)
2376 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), NULL);
2378 return tree_column->title;
2382 * pspp_sheet_view_column_set_expand:
2383 * @tree_column: A #PsppSheetViewColumn
2384 * @expand: %TRUE if the column should take available extra space, %FALSE if not
2386 * Sets the column to take available extra space. This space is shared equally
2387 * amongst all columns that have the expand set to %TRUE. If no column has this
2388 * option set, then the last column gets all extra space. By default, every
2389 * column is created with this %FALSE.
2394 pspp_sheet_view_column_set_expand (PsppSheetViewColumn *tree_column,
2397 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2400 if (tree_column->expand == expand)
2402 tree_column->expand = expand;
2404 if (tree_column->visible &&
2405 tree_column->tree_view != NULL &&
2406 gtk_widget_get_realized (tree_column->tree_view))
2408 /* We want to continue using the original width of the
2409 * column that includes additional space added by the user
2410 * resizing the columns and possibly extra (expanded) space, which
2411 * are not included in the resized width.
2413 tree_column->use_resized_width = FALSE;
2415 gtk_widget_queue_resize (tree_column->tree_view);
2418 g_object_notify (G_OBJECT (tree_column), "expand");
2422 * pspp_sheet_view_column_get_expand:
2423 * @tree_column: a #PsppSheetViewColumn
2425 * Return %TRUE if the column expands to take any available space.
2427 * Return value: %TRUE, if the column expands
2432 pspp_sheet_view_column_get_expand (PsppSheetViewColumn *tree_column)
2434 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2436 return tree_column->expand;
2440 * pspp_sheet_view_column_set_clickable:
2441 * @tree_column: A #PsppSheetViewColumn.
2442 * @clickable: %TRUE if the header is active.
2444 * Sets the header to be active if @active is %TRUE. When the header is active,
2445 * then it can take keyboard focus, and can be clicked.
2448 pspp_sheet_view_column_set_clickable (PsppSheetViewColumn *tree_column,
2451 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2453 clickable = !! clickable;
2454 if (tree_column->clickable == clickable)
2457 tree_column->clickable = clickable;
2458 pspp_sheet_view_column_update_button (tree_column);
2459 g_object_notify (G_OBJECT (tree_column), "clickable");
2463 * pspp_sheet_view_column_get_clickable:
2464 * @tree_column: a #PsppSheetViewColumn
2466 * Returns %TRUE if the user can click on the header for the column.
2468 * Return value: %TRUE if user can click the column header.
2471 pspp_sheet_view_column_get_clickable (PsppSheetViewColumn *tree_column)
2473 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2475 return tree_column->clickable;
2479 * pspp_sheet_view_column_set_widget:
2480 * @tree_column: A #PsppSheetViewColumn.
2481 * @widget: (allow-none): A child #GtkWidget, or %NULL.
2483 * Sets the widget in the header to be @widget. If widget is %NULL, then the
2484 * header button is set with a #GtkLabel set to the title of @tree_column.
2487 pspp_sheet_view_column_set_widget (PsppSheetViewColumn *tree_column,
2490 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2491 g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
2494 g_object_ref_sink (widget);
2496 if (tree_column->child)
2497 g_object_unref (tree_column->child);
2499 tree_column->child = widget;
2500 pspp_sheet_view_column_update_button (tree_column);
2501 g_object_notify (G_OBJECT (tree_column), "widget");
2505 * pspp_sheet_view_column_get_widget:
2506 * @tree_column: A #PsppSheetViewColumn.
2508 * Returns the #GtkWidget in the button on the column header. If a custom
2509 * widget has not been set then %NULL is returned.
2511 * Return value: The #GtkWidget in the column header, or %NULL
2514 pspp_sheet_view_column_get_widget (PsppSheetViewColumn *tree_column)
2516 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), NULL);
2518 return tree_column->child;
2522 * pspp_sheet_view_column_set_alignment:
2523 * @tree_column: A #PsppSheetViewColumn.
2524 * @xalign: The alignment, which is between [0.0 and 1.0] inclusive.
2526 * Sets the alignment of the title or custom widget inside the column header.
2527 * The alignment determines its location inside the button -- 0.0 for left, 0.5
2528 * for center, 1.0 for right.
2531 pspp_sheet_view_column_set_alignment (PsppSheetViewColumn *tree_column,
2534 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2536 xalign = CLAMP (xalign, 0.0, 1.0);
2538 if (tree_column->xalign == xalign)
2541 tree_column->xalign = xalign;
2542 pspp_sheet_view_column_update_button (tree_column);
2543 g_object_notify (G_OBJECT (tree_column), "alignment");
2547 * pspp_sheet_view_column_get_alignment:
2548 * @tree_column: A #PsppSheetViewColumn.
2550 * Returns the current x alignment of @tree_column. This value can range
2551 * between 0.0 and 1.0.
2553 * Return value: The current alignent of @tree_column.
2556 pspp_sheet_view_column_get_alignment (PsppSheetViewColumn *tree_column)
2558 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0.5);
2560 return tree_column->xalign;
2564 * pspp_sheet_view_column_set_reorderable:
2565 * @tree_column: A #PsppSheetViewColumn
2566 * @reorderable: %TRUE, if the column can be reordered.
2568 * If @reorderable is %TRUE, then the column can be reordered by the end user
2569 * dragging the header.
2572 pspp_sheet_view_column_set_reorderable (PsppSheetViewColumn *tree_column,
2573 gboolean reorderable)
2575 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2578 pspp_sheet_view_column_set_clickable (tree_column, TRUE);*/
2580 reorderable = !!reorderable;
2581 if (tree_column->reorderable == reorderable)
2584 tree_column->reorderable = reorderable;
2585 pspp_sheet_view_column_update_button (tree_column);
2586 g_object_notify (G_OBJECT (tree_column), "reorderable");
2590 * pspp_sheet_view_column_get_reorderable:
2591 * @tree_column: A #PsppSheetViewColumn
2593 * Returns %TRUE if the @tree_column can be reordered by the user.
2595 * Return value: %TRUE if the @tree_column can be reordered by the user.
2598 pspp_sheet_view_column_get_reorderable (PsppSheetViewColumn *tree_column)
2600 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2602 return tree_column->reorderable;
2606 * pspp_sheet_view_column_set_quick_edit:
2607 * @tree_column: A #PsppSheetViewColumn
2608 * @quick_edit: If true, editing starts upon the first click in the column. If
2609 * false, the first click selects the column and a second click is needed to
2610 * begin editing. This has no effect on cells that are not editable.
2613 pspp_sheet_view_column_set_quick_edit (PsppSheetViewColumn *tree_column,
2614 gboolean quick_edit)
2616 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2618 quick_edit = !!quick_edit;
2619 if (tree_column->quick_edit != quick_edit)
2621 tree_column->quick_edit = quick_edit;
2622 g_object_notify (G_OBJECT (tree_column), "quick-edit");
2627 * pspp_sheet_view_column_get_quick_edit:
2628 * @tree_column: A #PsppSheetViewColumn
2630 * Returns %TRUE if editing starts upon the first click in the column. Returns
2631 * %FALSE, the first click selects the column and a second click is needed to
2632 * begin editing. This is not meaningful for cells that are not editable.
2634 * Return value: %TRUE if editing starts upon the first click.
2637 pspp_sheet_view_column_get_quick_edit (PsppSheetViewColumn *tree_column)
2639 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2641 return tree_column->quick_edit;
2646 * pspp_sheet_view_column_set_selected:
2647 * @tree_column: A #PsppSheetViewColumn
2648 * @selected: If true, the column is selected as part of a rectangular
2652 pspp_sheet_view_column_set_selected (PsppSheetViewColumn *tree_column,
2655 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2657 selected = !!selected;
2658 if (tree_column->selected != selected)
2660 PsppSheetSelection *selection;
2661 PsppSheetView *sheet_view;
2663 if (tree_column->tree_view != NULL)
2664 gtk_widget_queue_draw (GTK_WIDGET (tree_column->tree_view));
2665 tree_column->selected = selected;
2666 g_object_notify (G_OBJECT (tree_column), "selected");
2668 sheet_view = PSPP_SHEET_VIEW (pspp_sheet_view_column_get_tree_view (
2670 selection = pspp_sheet_view_get_selection (sheet_view);
2671 _pspp_sheet_selection_emit_changed (selection);
2676 * pspp_sheet_view_column_get_selected:
2677 * @tree_column: A #PsppSheetViewColumn
2679 * Returns %TRUE if the column is selected as part of a rectangular
2682 * Return value: %TRUE if the column is selected as part of a rectangular
2686 pspp_sheet_view_column_get_selected (PsppSheetViewColumn *tree_column)
2688 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2690 return tree_column->selected;
2694 * pspp_sheet_view_column_set_selectable:
2695 * @tree_column: A #PsppSheetViewColumn
2696 * @selectable: If true, the column may be selected as part of a rectangular
2700 pspp_sheet_view_column_set_selectable (PsppSheetViewColumn *tree_column,
2701 gboolean selectable)
2703 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2705 selectable = !!selectable;
2706 if (tree_column->selectable != selectable)
2708 if (tree_column->tree_view != NULL)
2709 gtk_widget_queue_draw (GTK_WIDGET (tree_column->tree_view));
2710 tree_column->selectable = selectable;
2711 g_object_notify (G_OBJECT (tree_column), "selectable");
2716 * pspp_sheet_view_column_get_selectable:
2717 * @tree_column: A #PsppSheetViewColumn
2719 * Returns %TRUE if the column may be selected as part of a rectangular
2722 * Return value: %TRUE if the column may be selected as part of a rectangular
2726 pspp_sheet_view_column_get_selectable (PsppSheetViewColumn *tree_column)
2728 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2730 return tree_column->selectable;
2735 * pspp_sheet_view_column_set_row_head:
2736 * @tree_column: A #PsppSheetViewColumn
2737 * @row_head: If true, the column is a "row head", analogous to a column head.
2738 * See the description of the row-head property for more information.
2741 pspp_sheet_view_column_set_row_head (PsppSheetViewColumn *tree_column,
2744 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2746 row_head = !!row_head;
2747 if (tree_column->row_head != row_head)
2749 tree_column->row_head = row_head;
2750 g_object_notify (G_OBJECT (tree_column), "row_head");
2755 * pspp_sheet_view_column_get_row_head:
2756 * @tree_column: A #PsppSheetViewColumn
2758 * Returns %TRUE if the column is a row head.
2760 * Return value: %TRUE if the column is a row head.
2763 pspp_sheet_view_column_get_row_head (PsppSheetViewColumn *tree_column)
2765 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2767 return tree_column->row_head;
2772 * pspp_sheet_view_column_set_tabbable:
2773 * @tree_column: A #PsppSheetViewColumn
2774 * @tabbable: If true, the column is "tabbable", meaning that Tab and Shift+Tab
2775 * in the sheet visit this column. If false, Tab and Shift+Tab skip this
2779 pspp_sheet_view_column_set_tabbable (PsppSheetViewColumn *tree_column,
2782 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2784 tabbable = !!tabbable;
2785 if (tree_column->tabbable != tabbable)
2787 tree_column->tabbable = tabbable;
2788 g_object_notify (G_OBJECT (tree_column), "tabbable");
2793 * pspp_sheet_view_column_get_tabbable:
2794 * @tree_column: A #PsppSheetViewColumn
2796 * Returns %TRUE if the column is tabbable.
2798 * Return value: %TRUE if the column is tabbable.
2801 pspp_sheet_view_column_get_tabbable (PsppSheetViewColumn *tree_column)
2803 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2805 return tree_column->tabbable;
2810 * pspp_sheet_view_column_set_sort_column_id:
2811 * @tree_column: a #PsppSheetViewColumn
2812 * @sort_column_id: The @sort_column_id of the model to sort on.
2814 * Sets the logical @sort_column_id that this column sorts on when this column
2815 * is selected for sorting. Doing so makes the column header clickable.
2818 pspp_sheet_view_column_set_sort_column_id (PsppSheetViewColumn *tree_column,
2819 gint sort_column_id)
2821 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2822 g_return_if_fail (sort_column_id >= -1);
2824 if (tree_column->sort_column_id == sort_column_id)
2827 tree_column->sort_column_id = sort_column_id;
2829 /* Handle unsetting the id */
2830 if (sort_column_id == -1)
2832 GtkTreeModel *model = pspp_sheet_view_get_model (PSPP_SHEET_VIEW (tree_column->tree_view));
2834 if (tree_column->sort_clicked_signal)
2836 g_signal_handler_disconnect (tree_column, tree_column->sort_clicked_signal);
2837 tree_column->sort_clicked_signal = 0;
2840 if (tree_column->sort_column_changed_signal)
2842 g_signal_handler_disconnect (model, tree_column->sort_column_changed_signal);
2843 tree_column->sort_column_changed_signal = 0;
2846 pspp_sheet_view_column_set_sort_order (tree_column, GTK_SORT_ASCENDING);
2847 pspp_sheet_view_column_set_sort_indicator (tree_column, FALSE);
2848 pspp_sheet_view_column_set_clickable (tree_column, FALSE);
2849 g_object_notify (G_OBJECT (tree_column), "sort-column-id");
2853 pspp_sheet_view_column_set_clickable (tree_column, TRUE);
2855 if (! tree_column->sort_clicked_signal)
2856 tree_column->sort_clicked_signal = g_signal_connect (tree_column,
2858 G_CALLBACK (pspp_sheet_view_column_sort),
2861 pspp_sheet_view_column_setup_sort_column_id_callback (tree_column);
2862 g_object_notify (G_OBJECT (tree_column), "sort-column-id");
2866 * pspp_sheet_view_column_get_sort_column_id:
2867 * @tree_column: a #PsppSheetViewColumn
2869 * Gets the logical @sort_column_id that the model sorts on when this
2870 * column is selected for sorting.
2871 * See pspp_sheet_view_column_set_sort_column_id().
2873 * Return value: the current @sort_column_id for this column, or -1 if
2874 * this column can't be used for sorting.
2877 pspp_sheet_view_column_get_sort_column_id (PsppSheetViewColumn *tree_column)
2879 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0);
2881 return tree_column->sort_column_id;
2885 * pspp_sheet_view_column_set_sort_indicator:
2886 * @tree_column: a #PsppSheetViewColumn
2887 * @setting: %TRUE to display an indicator that the column is sorted
2889 * Call this function with a @setting of %TRUE to display an arrow in
2890 * the header button indicating the column is sorted. Call
2891 * pspp_sheet_view_column_set_sort_order() to change the direction of
2896 pspp_sheet_view_column_set_sort_indicator (PsppSheetViewColumn *tree_column,
2899 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2901 setting = setting != FALSE;
2903 if (setting == tree_column->show_sort_indicator)
2906 tree_column->show_sort_indicator = setting;
2907 pspp_sheet_view_column_update_button (tree_column);
2908 g_object_notify (G_OBJECT (tree_column), "sort-indicator");
2912 * pspp_sheet_view_column_get_sort_indicator:
2913 * @tree_column: a #PsppSheetViewColumn
2915 * Gets the value set by pspp_sheet_view_column_set_sort_indicator().
2917 * Return value: whether the sort indicator arrow is displayed
2920 pspp_sheet_view_column_get_sort_indicator (PsppSheetViewColumn *tree_column)
2922 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
2924 return tree_column->show_sort_indicator;
2928 * pspp_sheet_view_column_set_sort_order:
2929 * @tree_column: a #PsppSheetViewColumn
2930 * @order: sort order that the sort indicator should indicate
2932 * Changes the appearance of the sort indicator.
2934 * This <emphasis>does not</emphasis> actually sort the model. Use
2935 * pspp_sheet_view_column_set_sort_column_id() if you want automatic sorting
2936 * support. This function is primarily for custom sorting behavior, and should
2937 * be used in conjunction with gtk_tree_sortable_set_sort_column() to do
2938 * that. For custom models, the mechanism will vary.
2940 * The sort indicator changes direction to indicate normal sort or reverse sort.
2941 * Note that you must have the sort indicator enabled to see anything when
2942 * calling this function; see pspp_sheet_view_column_set_sort_indicator().
2945 pspp_sheet_view_column_set_sort_order (PsppSheetViewColumn *tree_column,
2948 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2950 if (order == tree_column->sort_order)
2953 tree_column->sort_order = order;
2954 pspp_sheet_view_column_update_button (tree_column);
2955 g_object_notify (G_OBJECT (tree_column), "sort-order");
2959 * pspp_sheet_view_column_get_sort_order:
2960 * @tree_column: a #PsppSheetViewColumn
2962 * Gets the value set by pspp_sheet_view_column_set_sort_order().
2964 * Return value: the sort order the sort indicator is indicating
2967 pspp_sheet_view_column_get_sort_order (PsppSheetViewColumn *tree_column)
2969 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0);
2971 return tree_column->sort_order;
2975 * pspp_sheet_view_column_cell_set_cell_data:
2976 * @tree_column: A #PsppSheetViewColumn.
2977 * @tree_model: The #GtkTreeModel to to get the cell renderers attributes from.
2978 * @iter: The #GtkTreeIter to to get the cell renderer's attributes from.
2980 * Sets the cell renderer based on the @tree_model and @iter. That is, for
2981 * every attribute mapping in @tree_column, it will get a value from the set
2982 * column on the @iter, and use that value to set the attribute on the cell
2983 * renderer. This is used primarily by the #PsppSheetView.
2986 pspp_sheet_view_column_cell_set_cell_data (PsppSheetViewColumn *tree_column,
2987 GtkTreeModel *tree_model,
2991 GValue value = { 0, };
2994 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
2996 if (tree_model == NULL)
2999 for (cell_list = tree_column->cell_list; cell_list; cell_list = cell_list->next)
3001 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) cell_list->data;
3002 GObject *cell = (GObject *) info->cell;
3004 list = info->attributes;
3006 g_object_freeze_notify (cell);
3008 while (list && list->next)
3010 gtk_tree_model_get_value (tree_model, iter,
3011 GPOINTER_TO_INT (list->next->data),
3013 g_object_set_property (cell, (gchar *) list->data, &value);
3014 g_value_unset (&value);
3015 list = list->next->next;
3019 (* info->func) (tree_column, info->cell, tree_model, iter, info->func_data);
3020 g_object_thaw_notify (G_OBJECT (info->cell));
3026 * pspp_sheet_view_column_cell_get_size:
3027 * @tree_column: A #PsppSheetViewColumn.
3028 * @cell_area: (allow-none): The area a cell in the column will be allocated, or %NULL
3029 * @x_offset: (allow-none): location to return x offset of a cell relative to @cell_area, or %NULL
3030 * @y_offset: (allow-none): location to return y offset of a cell relative to @cell_area, or %NULL
3031 * @width: (allow-none): location to return width needed to render a cell, or %NULL
3032 * @height: (allow-none): location to return height needed to render a cell, or %NULL
3034 * Obtains the width and height needed to render the column. This is used
3035 * primarily by the #PsppSheetView.
3038 pspp_sheet_view_column_cell_get_size (PsppSheetViewColumn *tree_column,
3039 const GdkRectangle *cell_area,
3046 gboolean first_cell = TRUE;
3047 gint focus_line_width;
3049 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
3056 gtk_widget_style_get (tree_column->tree_view, "focus-line-width", &focus_line_width, NULL);
3058 for (list = tree_column->cell_list; list; list = list->next)
3060 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
3062 gint new_height = 0;
3064 g_object_get (info->cell, "visible", &visible, NULL);
3066 if (visible == FALSE)
3069 if (first_cell == FALSE && width)
3070 *width += tree_column->spacing;
3072 gtk_cell_renderer_get_size (info->cell,
3073 tree_column->tree_view,
3081 * height = MAX (*height, new_height + focus_line_width * 2);
3082 info->requested_width = MAX (info->requested_width, new_width + focus_line_width * 2);
3084 * width += info->requested_width;
3089 /* rendering, event handling and rendering focus are somewhat complicated, and
3090 * quite a bit of code. Rather than duplicate them, we put them together to
3091 * keep the code in one place.
3093 * To better understand what's going on, check out
3094 * docs/tree-column-sizing.png
3103 pspp_sheet_view_column_cell_process_action (PsppSheetViewColumn *tree_column,
3105 const GdkRectangle *background_area,
3106 const GdkRectangle *cell_area,
3109 const GdkRectangle *expose_area, /* RENDER */
3110 GdkRectangle *focus_rectangle, /* FOCUS */
3111 GtkCellEditable **editable_widget, /* EVENT */
3112 GdkEvent *event, /* EVENT */
3113 gchar *path_string) /* EVENT */
3116 GdkRectangle real_cell_area;
3117 GdkRectangle real_background_area;
3118 GdkRectangle real_expose_area = *cell_area;
3120 gint expand_cell_count = 0;
3121 gint full_requested_width = 0;
3123 gint min_x, min_y, max_x, max_y;
3124 gint focus_line_width;
3126 gint horizontal_separator;
3127 gboolean cursor_row = FALSE;
3128 gboolean first_cell = TRUE;
3130 /* If we have rtl text, we need to transform our areas */
3131 GdkRectangle rtl_cell_area;
3132 GdkRectangle rtl_background_area;
3139 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_column->tree_view)) == GTK_TEXT_DIR_RTL);
3140 special_cells = _pspp_sheet_view_column_count_special_cells (tree_column);
3142 if (special_cells > 1 && action == CELL_ACTION_FOCUS)
3144 PsppSheetViewColumnCellInfo *info = NULL;
3145 gboolean found_has_focus = FALSE;
3147 /* one should have focus */
3148 for (list = tree_column->cell_list; list; list = list->next)
3151 if (info && info->has_focus)
3153 found_has_focus = TRUE;
3158 if (!found_has_focus)
3160 /* give the first one focus */
3161 info = pspp_sheet_view_column_cell_first (tree_column)->data;
3162 info->has_focus = TRUE;
3166 cursor_row = flags & GTK_CELL_RENDERER_FOCUSED;
3168 gtk_widget_style_get (GTK_WIDGET (tree_column->tree_view),
3169 "focus-line-width", &focus_line_width,
3170 "horizontal-separator", &horizontal_separator,
3173 real_cell_area = *cell_area;
3174 real_background_area = *background_area;
3177 real_cell_area.x += focus_line_width;
3178 real_cell_area.y += focus_line_width;
3179 real_cell_area.height -= 2 * focus_line_width;
3182 depth = real_background_area.width - real_cell_area.width;
3184 depth = real_cell_area.x - real_background_area.x;
3186 /* Find out how much extra space we have to allocate */
3187 for (list = tree_column->cell_list; list; list = list->next)
3189 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *)list->data;
3191 if (! gtk_cell_renderer_get_visible (info->cell))
3194 if (info->expand == TRUE)
3195 expand_cell_count ++;
3196 full_requested_width += info->requested_width;
3199 full_requested_width += tree_column->spacing;
3204 extra_space = cell_area->width - full_requested_width;
3205 if (extra_space < 0)
3207 else if (extra_space > 0 && expand_cell_count > 0)
3208 extra_space /= expand_cell_count;
3210 /* iterate list for GTK_PACK_START cells */
3211 for (list = tree_column->cell_list; list; list = list->next)
3213 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
3215 if (info->pack == GTK_PACK_END)
3218 if (! gtk_cell_renderer_get_visible (info->cell))
3221 if ((info->has_focus || special_cells == 1) && cursor_row)
3222 flags |= GTK_CELL_RENDERER_FOCUSED;
3224 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3226 info->real_width = info->requested_width + (info->expand?extra_space:0);
3228 /* We constrain ourselves to only the width available */
3229 if (real_cell_area.x - focus_line_width + info->real_width > cell_area->x + cell_area->width)
3231 info->real_width = cell_area->x + cell_area->width - real_cell_area.x;
3234 if (real_cell_area.x > cell_area->x + cell_area->width)
3237 real_cell_area.width = info->real_width;
3238 real_cell_area.width -= 2 * focus_line_width;
3242 real_background_area.width = info->real_width + depth;
3246 /* fill the rest of background for the last cell */
3247 real_background_area.width = background_area->x + background_area->width - real_background_area.x;
3250 rtl_cell_area = real_cell_area;
3251 rtl_background_area = real_background_area;
3255 rtl_cell_area.x = cell_area->x + cell_area->width - (real_cell_area.x - cell_area->x) - real_cell_area.width;
3256 rtl_background_area.x = background_area->x + background_area->width - (real_background_area.x - background_area->x) - real_background_area.width;
3260 if (action == CELL_ACTION_RENDER)
3262 gtk_cell_renderer_render (info->cell,
3264 tree_column->tree_view,
3265 &rtl_background_area,
3271 else if (action == CELL_ACTION_FOCUS)
3273 gint x_offset, y_offset, width, height;
3275 gtk_cell_renderer_get_size (info->cell,
3276 tree_column->tree_view,
3278 &x_offset, &y_offset,
3281 if (special_cells > 1)
3283 if (info->has_focus)
3285 min_x = rtl_cell_area.x + x_offset;
3286 max_x = min_x + width;
3287 min_y = rtl_cell_area.y + y_offset;
3288 max_y = min_y + height;
3293 if (min_x > (rtl_cell_area.x + x_offset))
3294 min_x = rtl_cell_area.x + x_offset;
3295 if (max_x < rtl_cell_area.x + x_offset + width)
3296 max_x = rtl_cell_area.x + x_offset + width;
3297 if (min_y > (rtl_cell_area.y + y_offset))
3298 min_y = rtl_cell_area.y + y_offset;
3299 if (max_y < rtl_cell_area.y + y_offset + height)
3300 max_y = rtl_cell_area.y + y_offset + height;
3304 else if (action == CELL_ACTION_EVENT)
3306 gboolean try_event = FALSE;
3310 if (special_cells == 1)
3312 /* only 1 activatable cell -> whole column can activate */
3313 if (cell_area->x <= ((GdkEventButton *)event)->x &&
3314 cell_area->x + cell_area->width > ((GdkEventButton *)event)->x)
3317 else if (rtl_cell_area.x <= ((GdkEventButton *)event)->x &&
3318 rtl_cell_area.x + rtl_cell_area.width > ((GdkEventButton *)event)->x)
3319 /* only activate cell if the user clicked on an individual
3324 else if (special_cells > 1 && info->has_focus)
3326 else if (special_cells == 1)
3331 gboolean visible, mode;
3333 g_object_get (info->cell,
3334 "visible", &visible,
3337 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
3339 if (gtk_cell_renderer_activate (info->cell,
3341 tree_column->tree_view,
3343 &rtl_background_area,
3347 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3351 else if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
3354 gtk_cell_renderer_start_editing (info->cell,
3356 tree_column->tree_view,
3358 &rtl_background_area,
3362 if (*editable_widget != NULL)
3364 g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
3365 info->in_editing_mode = TRUE;
3366 pspp_sheet_view_column_focus_cell (tree_column, info->cell);
3368 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3376 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3378 real_cell_area.x += (real_cell_area.width + 2 * focus_line_width + tree_column->spacing);
3379 real_background_area.x += real_background_area.width + tree_column->spacing;
3381 /* Only needed for first cell */
3385 /* iterate list for PACK_END cells */
3386 for (list = g_list_last (tree_column->cell_list); list; list = list->prev)
3388 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
3390 if (info->pack == GTK_PACK_START)
3393 if (! gtk_cell_renderer_get_visible (info->cell))
3396 if ((info->has_focus || special_cells == 1) && cursor_row)
3397 flags |= GTK_CELL_RENDERER_FOCUSED;
3399 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3401 info->real_width = info->requested_width + (info->expand?extra_space:0);
3403 /* We constrain ourselves to only the width available */
3404 if (real_cell_area.x - focus_line_width + info->real_width > cell_area->x + cell_area->width)
3406 info->real_width = cell_area->x + cell_area->width - real_cell_area.x;
3409 if (real_cell_area.x > cell_area->x + cell_area->width)
3412 real_cell_area.width = info->real_width;
3413 real_cell_area.width -= 2 * focus_line_width;
3414 real_background_area.width = info->real_width + depth;
3416 rtl_cell_area = real_cell_area;
3417 rtl_background_area = real_background_area;
3420 rtl_cell_area.x = cell_area->x + cell_area->width - (real_cell_area.x - cell_area->x) - real_cell_area.width;
3421 rtl_background_area.x = background_area->x + background_area->width - (real_background_area.x - background_area->x) - real_background_area.width;
3425 if (action == CELL_ACTION_RENDER)
3427 gtk_cell_renderer_render (info->cell,
3429 tree_column->tree_view,
3430 &rtl_background_area,
3436 else if (action == CELL_ACTION_FOCUS)
3438 gint x_offset, y_offset, width, height;
3440 gtk_cell_renderer_get_size (info->cell,
3441 tree_column->tree_view,
3443 &x_offset, &y_offset,
3446 if (special_cells > 1)
3448 if (info->has_focus)
3450 min_x = rtl_cell_area.x + x_offset;
3451 max_x = min_x + width;
3452 min_y = rtl_cell_area.y + y_offset;
3453 max_y = min_y + height;
3458 if (min_x > (rtl_cell_area.x + x_offset))
3459 min_x = rtl_cell_area.x + x_offset;
3460 if (max_x < rtl_cell_area.x + x_offset + width)
3461 max_x = rtl_cell_area.x + x_offset + width;
3462 if (min_y > (rtl_cell_area.y + y_offset))
3463 min_y = rtl_cell_area.y + y_offset;
3464 if (max_y < rtl_cell_area.y + y_offset + height)
3465 max_y = rtl_cell_area.y + y_offset + height;
3469 else if (action == CELL_ACTION_EVENT)
3471 gboolean try_event = FALSE;
3475 if (special_cells == 1)
3477 /* only 1 activatable cell -> whole column can activate */
3478 if (cell_area->x <= ((GdkEventButton *)event)->x &&
3479 cell_area->x + cell_area->width > ((GdkEventButton *)event)->x)
3482 else if (rtl_cell_area.x <= ((GdkEventButton *)event)->x &&
3483 rtl_cell_area.x + rtl_cell_area.width > ((GdkEventButton *)event)->x)
3484 /* only activate cell if the user clicked on an individual
3489 else if (special_cells > 1 && info->has_focus)
3491 else if (special_cells == 1)
3496 gboolean visible, mode;
3498 g_object_get (info->cell,
3499 "visible", &visible,
3502 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
3504 if (gtk_cell_renderer_activate (info->cell,
3506 tree_column->tree_view,
3508 &rtl_background_area,
3512 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3516 else if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
3519 gtk_cell_renderer_start_editing (info->cell,
3521 tree_column->tree_view,
3523 &rtl_background_area,
3527 if (*editable_widget != NULL)
3529 g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
3530 info->in_editing_mode = TRUE;
3531 pspp_sheet_view_column_focus_cell (tree_column, info->cell);
3533 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3540 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3542 real_cell_area.x += (real_cell_area.width + 2 * focus_line_width + tree_column->spacing);
3543 real_background_area.x += (real_background_area.width + tree_column->spacing);
3545 /* Only needed for first cell */
3549 /* fill focus_rectangle when required */
3550 if (action == CELL_ACTION_FOCUS)
3552 if (min_x >= max_x || min_y >= max_y)
3554 *focus_rectangle = *cell_area;
3555 /* don't change the focus_rectangle, just draw it nicely inside
3560 focus_rectangle->x = min_x - focus_line_width;
3561 focus_rectangle->y = min_y - focus_line_width;
3562 focus_rectangle->width = (max_x - min_x) + 2 * focus_line_width;
3563 focus_rectangle->height = (max_y - min_y) + 2 * focus_line_width;
3571 * pspp_sheet_view_column_cell_render:
3572 * @tree_column: A #PsppSheetViewColumn.
3573 * @window: a #GdkDrawable to draw to
3574 * @background_area: entire cell area (including tree expanders and maybe padding on the sides)
3575 * @cell_area: area normally rendered by a cell renderer
3576 * @expose_area: area that actually needs updating
3577 * @flags: flags that affect rendering
3579 * Renders the cell contained by #tree_column. This is used primarily by the
3583 _pspp_sheet_view_column_cell_render (PsppSheetViewColumn *tree_column,
3585 const GdkRectangle *background_area,
3586 const GdkRectangle *cell_area,
3587 const GdkRectangle *expose_area,
3590 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
3591 g_return_if_fail (background_area != NULL);
3592 g_return_if_fail (cell_area != NULL);
3593 g_return_if_fail (expose_area != NULL);
3595 pspp_sheet_view_column_cell_process_action (tree_column,
3602 NULL, NULL, NULL, NULL);
3606 _pspp_sheet_view_column_cell_event (PsppSheetViewColumn *tree_column,
3607 GtkCellEditable **editable_widget,
3610 const GdkRectangle *background_area,
3611 const GdkRectangle *cell_area,
3614 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
3616 return pspp_sheet_view_column_cell_process_action (tree_column,
3629 _pspp_sheet_view_column_get_focus_area (PsppSheetViewColumn *tree_column,
3630 const GdkRectangle *background_area,
3631 const GdkRectangle *cell_area,
3632 GdkRectangle *focus_area)
3634 pspp_sheet_view_column_cell_process_action (tree_column,
3646 /* cell list manipulation */
3648 pspp_sheet_view_column_cell_first (PsppSheetViewColumn *tree_column)
3650 GList *list = tree_column->cell_list;
3652 /* first GTK_PACK_START cell we find */
3653 for ( ; list; list = list->next)
3655 PsppSheetViewColumnCellInfo *info = list->data;
3656 if (info->pack == GTK_PACK_START)
3660 /* hmm, else the *last* GTK_PACK_END cell */
3661 list = g_list_last (tree_column->cell_list);
3663 for ( ; list; list = list->prev)
3665 PsppSheetViewColumnCellInfo *info = list->data;
3666 if (info->pack == GTK_PACK_END)
3674 pspp_sheet_view_column_cell_last (PsppSheetViewColumn *tree_column)
3676 GList *list = tree_column->cell_list;
3678 /* *first* GTK_PACK_END cell we find */
3679 for ( ; list ; list = list->next)
3681 PsppSheetViewColumnCellInfo *info = list->data;
3682 if (info->pack == GTK_PACK_END)
3686 /* hmm, else the last GTK_PACK_START cell */
3687 list = g_list_last (tree_column->cell_list);
3689 for ( ; list; list = list->prev)
3691 PsppSheetViewColumnCellInfo *info = list->data;
3692 if (info->pack == GTK_PACK_START)
3700 pspp_sheet_view_column_cell_next (PsppSheetViewColumn *tree_column,
3704 PsppSheetViewColumnCellInfo *info = current->data;
3706 if (info->pack == GTK_PACK_START)
3708 for (list = current->next; list; list = list->next)
3710 PsppSheetViewColumnCellInfo *inf = list->data;
3711 if (inf->pack == GTK_PACK_START)
3715 /* out of GTK_PACK_START cells, get *last* GTK_PACK_END one */
3716 list = g_list_last (tree_column->cell_list);
3717 for (; list; list = list->prev)
3719 PsppSheetViewColumnCellInfo *inf = list->data;
3720 if (inf->pack == GTK_PACK_END)
3725 for (list = current->prev; list; list = list->prev)
3727 PsppSheetViewColumnCellInfo *inf = list->data;
3728 if (inf->pack == GTK_PACK_END)
3736 pspp_sheet_view_column_cell_prev (PsppSheetViewColumn *tree_column,
3740 PsppSheetViewColumnCellInfo *info = current->data;
3742 if (info->pack == GTK_PACK_END)
3744 for (list = current->next; list; list = list->next)
3746 PsppSheetViewColumnCellInfo *inf = list->data;
3747 if (inf->pack == GTK_PACK_END)
3751 /* out of GTK_PACK_END, get last GTK_PACK_START one */
3752 list = g_list_last (tree_column->cell_list);
3753 for ( ; list; list = list->prev)
3755 PsppSheetViewColumnCellInfo *inf = list->data;
3756 if (inf->pack == GTK_PACK_START)
3761 for (list = current->prev; list; list = list->prev)
3763 PsppSheetViewColumnCellInfo *inf = list->data;
3764 if (inf->pack == GTK_PACK_START)
3772 _pspp_sheet_view_column_cell_focus (PsppSheetViewColumn *tree_column,
3780 count = _pspp_sheet_view_column_count_special_cells (tree_column);
3781 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_column->tree_view)) == GTK_TEXT_DIR_RTL;
3783 /* if we are the current focus column and have multiple editable cells,
3784 * try to select the next one, else move the focus to the next column
3786 if (PSPP_SHEET_VIEW (tree_column->tree_view)->priv->focus_column == tree_column)
3791 GList *list = tree_column->cell_list;
3792 PsppSheetViewColumnCellInfo *info = NULL;
3794 /* find current focussed cell */
3795 for ( ; list; list = list->next)
3798 if (info->has_focus)
3802 /* not a focussed cell in the focus column? */
3803 if (!list || !info || !info->has_focus)
3808 prev = pspp_sheet_view_column_cell_next (tree_column, list);
3809 next = pspp_sheet_view_column_cell_prev (tree_column, list);
3813 next = pspp_sheet_view_column_cell_next (tree_column, list);
3814 prev = pspp_sheet_view_column_cell_prev (tree_column, list);
3817 info->has_focus = FALSE;
3818 if (direction > 0 && next)
3821 info->has_focus = TRUE;
3824 else if (direction > 0 && !next && !right)
3826 /* keep focus on last cell */
3828 info = pspp_sheet_view_column_cell_first (tree_column)->data;
3830 info = pspp_sheet_view_column_cell_last (tree_column)->data;
3832 info->has_focus = TRUE;
3835 else if (direction < 0 && prev)
3838 info->has_focus = TRUE;
3841 else if (direction < 0 && !prev && !left)
3843 /* keep focus on first cell */
3845 info = pspp_sheet_view_column_cell_last (tree_column)->data;
3847 info = pspp_sheet_view_column_cell_first (tree_column)->data;
3849 info->has_focus = TRUE;
3856 /* we get focus, if we have multiple editable cells, give the correct one
3861 GList *list = tree_column->cell_list;
3863 /* clear focus first */
3864 for ( ; list ; list = list->next)
3866 PsppSheetViewColumnCellInfo *info = list->data;
3867 if (info->has_focus)
3868 info->has_focus = FALSE;
3875 list = pspp_sheet_view_column_cell_last (tree_column);
3876 else if (direction < 0)
3877 list = pspp_sheet_view_column_cell_first (tree_column);
3882 list = pspp_sheet_view_column_cell_first (tree_column);
3883 else if (direction < 0)
3884 list = pspp_sheet_view_column_cell_last (tree_column);
3888 ((PsppSheetViewColumnCellInfo *) list->data)->has_focus = TRUE;
3895 _pspp_sheet_view_column_cell_draw_focus (PsppSheetViewColumn *tree_column,
3897 const GdkRectangle *background_area,
3898 const GdkRectangle *cell_area,
3899 const GdkRectangle *expose_area,
3902 gint focus_line_width;
3903 GtkStateType cell_state;
3905 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
3906 gtk_widget_style_get (GTK_WIDGET (tree_column->tree_view),
3907 "focus-line-width", &focus_line_width, NULL);
3908 if (tree_column->editable_widget)
3910 /* This function is only called on the editable row when editing.
3913 gtk_paint_focus (tree_column->tree_view->style,
3915 gtk_widget_get_state (tree_column->tree_view),
3917 tree_column->tree_view,
3919 cell_area->x - focus_line_width,
3920 cell_area->y - focus_line_width,
3921 cell_area->width + 2 * focus_line_width,
3922 cell_area->height + 2 * focus_line_width);
3927 GdkRectangle focus_rectangle;
3928 pspp_sheet_view_column_cell_process_action (tree_column,
3938 cell_state = flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
3939 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
3940 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL));
3941 gtk_paint_focus (gtk_widget_get_style (GTK_WIDGET (tree_column->tree_view)),
3945 tree_column->tree_view,
3949 focus_rectangle.width,
3950 focus_rectangle.height);
3955 * pspp_sheet_view_column_cell_is_visible:
3956 * @tree_column: A #PsppSheetViewColumn
3958 * Returns %TRUE if any of the cells packed into the @tree_column are visible.
3959 * For this to be meaningful, you must first initialize the cells with
3960 * pspp_sheet_view_column_cell_set_cell_data()
3962 * Return value: %TRUE, if any of the cells packed into the @tree_column are currently visible
3965 pspp_sheet_view_column_cell_is_visible (PsppSheetViewColumn *tree_column)
3969 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE);
3971 for (list = tree_column->cell_list; list; list = list->next)
3973 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
3975 if (gtk_cell_renderer_get_visible (info->cell))
3983 * pspp_sheet_view_column_focus_cell:
3984 * @tree_column: A #PsppSheetViewColumn
3985 * @cell: A #GtkCellRenderer
3987 * Sets the current keyboard focus to be at @cell, if the column contains
3988 * 2 or more editable and activatable cells.
3993 pspp_sheet_view_column_focus_cell (PsppSheetViewColumn *tree_column,
3994 GtkCellRenderer *cell)
3997 gboolean found_cell = FALSE;
3999 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
4000 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4002 if (_pspp_sheet_view_column_count_special_cells (tree_column) < 2)
4005 for (list = tree_column->cell_list; list; list = list->next)
4007 PsppSheetViewColumnCellInfo *info = list->data;
4009 if (info->cell == cell)
4011 info->has_focus = TRUE;
4019 for (list = tree_column->cell_list; list; list = list->next)
4021 PsppSheetViewColumnCellInfo *info = list->data;
4023 if (info->cell != cell)
4024 info->has_focus = FALSE;
4027 /* FIXME: redraw? */
4032 _pspp_sheet_view_column_cell_set_dirty (PsppSheetViewColumn *tree_column)
4036 for (list = tree_column->cell_list; list; list = list->next)
4038 PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data;
4040 info->requested_width = 0;
4042 tree_column->dirty = TRUE;
4043 tree_column->requested_width = -1;
4044 tree_column->width = 0;
4046 if (tree_column->tree_view &&
4047 gtk_widget_get_realized (tree_column->tree_view))
4049 _pspp_sheet_view_install_mark_rows_col_dirty (PSPP_SHEET_VIEW (tree_column->tree_view));
4050 gtk_widget_queue_resize (tree_column->tree_view);
4055 _pspp_sheet_view_column_start_editing (PsppSheetViewColumn *tree_column,
4056 GtkCellEditable *cell_editable)
4058 g_return_if_fail (tree_column->editable_widget == NULL);
4060 tree_column->editable_widget = cell_editable;
4064 _pspp_sheet_view_column_stop_editing (PsppSheetViewColumn *tree_column)
4068 g_return_if_fail (tree_column->editable_widget != NULL);
4070 tree_column->editable_widget = NULL;
4071 for (list = tree_column->cell_list; list; list = list->next)
4072 ((PsppSheetViewColumnCellInfo *)list->data)->in_editing_mode = FALSE;
4076 _pspp_sheet_view_column_get_neighbor_sizes (PsppSheetViewColumn *column,
4077 GtkCellRenderer *cell,
4082 PsppSheetViewColumnCellInfo *info;
4088 list = pspp_sheet_view_column_cell_first (column);
4092 info = (PsppSheetViewColumnCellInfo *)list->data;
4094 list = pspp_sheet_view_column_cell_next (column, list);
4096 if (info->cell == cell)
4099 if (gtk_cell_renderer_get_visible (info->cell))
4100 l += info->real_width + column->spacing;
4105 info = (PsppSheetViewColumnCellInfo *)list->data;
4107 list = pspp_sheet_view_column_cell_next (column, list);
4109 if (gtk_cell_renderer_get_visible (info->cell))
4110 r += info->real_width + column->spacing;
4113 rtl = (gtk_widget_get_direction (GTK_WIDGET (column->tree_view)) == GTK_TEXT_DIR_RTL);
4115 *left = rtl ? r : l;
4118 *right = rtl ? l : r;
4122 * pspp_sheet_view_column_cell_get_position:
4123 * @tree_column: a #PsppSheetViewColumn
4124 * @cell_renderer: a #GtkCellRenderer
4125 * @start_pos: return location for the horizontal position of @cell within
4126 * @tree_column, may be %NULL
4127 * @width: return location for the width of @cell, may be %NULL
4129 * Obtains the horizontal position and size of a cell in a column. If the
4130 * cell is not found in the column, @start_pos and @width are not changed and
4131 * %FALSE is returned.
4133 * Return value: %TRUE if @cell belongs to @tree_column.
4136 pspp_sheet_view_column_cell_get_position (PsppSheetViewColumn *tree_column,
4137 GtkCellRenderer *cell_renderer,
4143 gboolean found_cell = FALSE;
4144 PsppSheetViewColumnCellInfo *cellinfo = NULL;
4146 list = pspp_sheet_view_column_cell_first (tree_column);
4147 for (; list; list = pspp_sheet_view_column_cell_next (tree_column, list))
4149 cellinfo = list->data;
4150 if (cellinfo->cell == cell_renderer)
4156 if (gtk_cell_renderer_get_visible (cellinfo->cell))
4157 current_x += cellinfo->real_width;
4163 *start_pos = current_x;
4165 *width = cellinfo->real_width;
4172 * pspp_sheet_view_column_queue_resize:
4173 * @tree_column: A #PsppSheetViewColumn
4175 * Flags the column, and the cell renderers added to this column, to have
4176 * their sizes renegotiated.
4181 pspp_sheet_view_column_queue_resize (PsppSheetViewColumn *tree_column)
4183 g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
4185 if (tree_column->tree_view)
4186 _pspp_sheet_view_column_cell_set_dirty (tree_column);
4190 * pspp_sheet_view_column_get_tree_view:
4191 * @tree_column: A #PsppSheetViewColumn
4193 * Returns the #PsppSheetView wherein @tree_column has been inserted. If
4194 * @column is currently not inserted in any tree view, %NULL is
4197 * Return value: The tree view wherein @column has been inserted if any,
4203 pspp_sheet_view_column_get_tree_view (PsppSheetViewColumn *tree_column)
4205 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), NULL);
4207 return tree_column->tree_view;
4211 GtkCellLayout *cell_layout;
4212 GtkCellRenderer *renderer;
4214 } AttributesSubParserData;
4217 attributes_start_element (GMarkupParseContext *context,
4218 const gchar *element_name,
4219 const gchar **names,
4220 const gchar **values,
4224 AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
4227 if (strcmp (element_name, "attribute") == 0)
4229 for (i = 0; names[i]; i++)
4230 if (strcmp (names[i], "name") == 0)
4231 parser_data->attr_name = g_strdup (values[i]);
4233 else if (strcmp (element_name, "attributes") == 0)
4236 g_warning ("Unsupported tag for GtkCellLayout: %s\n", element_name);
4240 attributes_text_element (GMarkupParseContext *context,
4246 AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
4251 if (!parser_data->attr_name)
4255 string = g_strndup (text, text_len);
4256 l = strtol (string, &endptr, 0);
4257 if (errno || endptr == string)
4261 GTK_BUILDER_ERROR_INVALID_VALUE,
4262 "Could not parse integer `%s'",
4269 gtk_cell_layout_add_attribute (parser_data->cell_layout,
4270 parser_data->renderer,
4271 parser_data->attr_name, l);
4272 g_free (parser_data->attr_name);
4273 parser_data->attr_name = NULL;
4276 static const GMarkupParser attributes_parser =
4278 attributes_start_element,
4280 attributes_text_element,
4284 _gtk_cell_layout_buildable_custom_tag_start (GtkBuildable *buildable,
4285 GtkBuilder *builder,
4287 const gchar *tagname,
4288 GMarkupParser *parser,
4291 AttributesSubParserData *parser_data;
4296 if (strcmp (tagname, "attributes") == 0)
4298 parser_data = g_slice_new0 (AttributesSubParserData);
4299 parser_data->cell_layout = GTK_CELL_LAYOUT (buildable);
4300 parser_data->renderer = GTK_CELL_RENDERER (child);
4301 parser_data->attr_name = NULL;
4303 *parser = attributes_parser;
4304 *data = parser_data;
4312 _gtk_cell_layout_buildable_custom_tag_end (GtkBuildable *buildable,
4313 GtkBuilder *builder,
4315 const gchar *tagname,
4318 AttributesSubParserData *parser_data;
4320 parser_data = (AttributesSubParserData*)data;
4321 g_assert (!parser_data->attr_name);
4322 g_slice_free (AttributesSubParserData, parser_data);
4326 _gtk_cell_layout_buildable_add_child (GtkBuildable *buildable,
4327 GtkBuilder *builder,
4331 GtkCellLayoutIface *iface;
4333 g_return_if_fail (GTK_IS_CELL_LAYOUT (buildable));
4334 g_return_if_fail (GTK_IS_CELL_RENDERER (child));
4336 iface = GTK_CELL_LAYOUT_GET_IFACE (buildable);
4337 g_return_if_fail (iface->pack_start != NULL);
4338 iface->pack_start (GTK_CELL_LAYOUT (buildable), GTK_CELL_RENDERER (child), FALSE);
4342 pspp_sheet_view_column_size_request (PsppSheetViewColumn *tree_column,
4343 GtkRequisition *request)
4345 GtkWidget *base = GTK_WIDGET (tree_column->tree_view);
4346 GtkRequisition label_req;
4347 GtkRequisition align_req;
4348 GtkRequisition arrow_req;
4349 GtkRequisition hbox_req;
4350 GtkStyle **button_style;
4352 if (tree_column->button)
4354 gtk_widget_size_request (tree_column->button, request);
4358 facade_label_get_size_request (0, 0, base, tree_column->title, &label_req);
4359 facade_alignment_get_size_request (0, 0, 0, 0, 0, &label_req, &align_req);
4360 facade_arrow_get_size_request (0, 0, &arrow_req);
4362 facade_hbox_get_base_size_request (0, 2, 2, &hbox_req);
4363 facade_hbox_add_child_size_request (0, &arrow_req, 0, &hbox_req);
4364 facade_hbox_add_child_size_request (0, &align_req, 0, &hbox_req);
4366 button_style = &PSPP_SHEET_VIEW (tree_column->tree_view)->priv->button_style;
4367 if (*button_style == NULL)
4369 *button_style = facade_get_style (base, GTK_TYPE_BUTTON, 0);
4370 g_object_ref (*button_style);
4372 facade_button_get_size_request (0, base, *button_style, &hbox_req, request);
4376 pspp_sheet_view_column_size_allocate (PsppSheetViewColumn *tree_column,
4377 GtkAllocation *allocation)
4379 tree_column->allocation = *allocation;
4380 if (tree_column->button)
4381 gtk_widget_size_allocate (tree_column->button, allocation);
4385 pspp_sheet_view_column_can_focus (PsppSheetViewColumn *tree_column)
4387 return tree_column->reorderable || tree_column->clickable;
4391 pspp_sheet_view_column_set_need_button (PsppSheetViewColumn *tree_column,
4392 gboolean need_button)
4394 if (tree_column->need_button != need_button)
4396 tree_column->need_button = need_button;
4397 pspp_sheet_view_column_update_button (tree_column);
4398 _pspp_sheet_view_column_realize_button (tree_column);