]> Pileus Git - ~andy/gtk/blob - gtk/gtktreeviewcolumn.c
Merge branch 'master' into treeview-refactor
[~andy/gtk] / gtk / gtktreeviewcolumn.c
1 /* gtktreeviewcolumn.c
2  * Copyright (C) 2000  Red Hat, Inc.,  Jonathan Blandford <jrb@redhat.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library 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 GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include "gtktreeviewcolumn.h"
23
24 #include <string.h>
25
26 #include "gtktreeview.h"
27 #include "gtktreeprivate.h"
28 #include "gtkcelllayout.h"
29 #include "gtkbutton.h"
30 #include "gtkalignment.h"
31 #include "gtklabel.h"
32 #include "gtkhbox.h"
33 #include "gtkmarshalers.h"
34 #include "gtkarrow.h"
35 #include "gtkcellareacontext.h"
36 #include "gtkcellareabox.h"
37 #include "gtkprivate.h"
38 #include "gtkintl.h"
39
40
41 /**
42  * SECTION:gtktreeviewcolumn
43  * @Short_description: A visible column in a GtkTreeView widget
44  * @Title: GtkTreeViewColumn
45  * @See_also: #GtkTreeView, #GtkTreeSelection, #GtkTreeDnd, #GtkTreeMode, #GtkTreeSortable,
46  *   #GtkTreeModelSort, #GtkListStore, #GtkTreeStore, #GtkCellRenderer, #GtkCellEditable,
47  *   #GtkCellRendererPixbuf, #GtkCellRendererText, #GtkCellRendererToggle
48  *
49  * The GtkTreeViewColumn object represents a visible column in a #GtkTreeView widget.
50  * It allows to set properties of the column header, and functions as a holding pen for
51  * the cell renderers which determine how the data in the column is displayed.
52  *
53  * Please refer to the <link linkend="TreeWidget">tree widget conceptual overview</link>
54  * for an overview of all the objects and data types related to the tree widget and how
55  * they work together.
56  */
57
58
59 enum
60 {
61   PROP_0,
62   PROP_VISIBLE,
63   PROP_RESIZABLE,
64   PROP_WIDTH,
65   PROP_SPACING,
66   PROP_SIZING,
67   PROP_FIXED_WIDTH,
68   PROP_MIN_WIDTH,
69   PROP_MAX_WIDTH,
70   PROP_TITLE,
71   PROP_EXPAND,
72   PROP_CLICKABLE,
73   PROP_WIDGET,
74   PROP_ALIGNMENT,
75   PROP_REORDERABLE,
76   PROP_SORT_INDICATOR,
77   PROP_SORT_ORDER,
78   PROP_SORT_COLUMN_ID
79 };
80
81 enum
82 {
83   CLICKED,
84   LAST_SIGNAL
85 };
86
87 /* Type methods */
88 static void gtk_tree_view_column_cell_layout_init              (GtkCellLayoutIface      *iface);
89
90 /* GObject methods */
91 static void gtk_tree_view_column_set_property                  (GObject                 *object,
92                                                                 guint                    prop_id,
93                                                                 const GValue            *value,
94                                                                 GParamSpec              *pspec);
95 static void gtk_tree_view_column_get_property                  (GObject                 *object,
96                                                                 guint                    prop_id,
97                                                                 GValue                  *value,
98                                                                 GParamSpec              *pspec);
99 static void gtk_tree_view_column_finalize                      (GObject                 *object);
100 static void gtk_tree_view_column_dispose                       (GObject                 *object);
101
102 /* GtkCellLayout implementation */
103 static GtkCellArea *gtk_tree_view_column_cell_layout_get_area  (GtkCellLayout           *cell_layout);
104
105 /* Button handling code */
106 static void gtk_tree_view_column_create_button                 (GtkTreeViewColumn       *tree_column);
107 static void gtk_tree_view_column_update_button                 (GtkTreeViewColumn       *tree_column);
108
109 /* Button signal handlers */
110 static gint gtk_tree_view_column_button_event                  (GtkWidget               *widget,
111                                                                 GdkEvent                *event,
112                                                                 gpointer                 data);
113 static void gtk_tree_view_column_button_clicked                (GtkWidget               *widget,
114                                                                 gpointer                 data);
115 static gboolean gtk_tree_view_column_mnemonic_activate         (GtkWidget *widget,
116                                                                 gboolean   group_cycling,
117                                                                 gpointer   data);
118
119 /* Property handlers */
120 static void gtk_tree_view_model_sort_column_changed            (GtkTreeSortable         *sortable,
121                                                                 GtkTreeViewColumn       *tree_column);
122
123 /* GtkCellArea/GtkCellAreaContext callbacks */
124 static void gtk_tree_view_column_context_changed               (GtkCellAreaContext      *context,
125                                                                 GParamSpec              *pspec,
126                                                                 GtkTreeViewColumn       *tree_column);
127 static void gtk_tree_view_column_add_editable_callback         (GtkCellArea             *area,
128                                                                 GtkCellRenderer         *renderer,
129                                                                 GtkCellEditable         *edit_widget,
130                                                                 GdkRectangle            *cell_area,
131                                                                 const gchar             *path_string,
132                                                                 gpointer                 user_data);
133 static void gtk_tree_view_column_remove_editable_callback      (GtkCellArea             *area,
134                                                                 GtkCellRenderer         *renderer,
135                                                                 GtkCellEditable         *edit_widget,
136                                                                 gpointer                 user_data);
137
138 /* Internal functions */
139 static void gtk_tree_view_column_sort                          (GtkTreeViewColumn       *tree_column,
140                                                                 gpointer                 data);
141 static void gtk_tree_view_column_setup_sort_column_id_callback (GtkTreeViewColumn       *tree_column);
142 static void gtk_tree_view_column_set_attributesv               (GtkTreeViewColumn       *tree_column,
143                                                                 GtkCellRenderer         *cell_renderer,
144                                                                 va_list                  args);
145
146 /* GtkBuildable implementation */
147 static void gtk_tree_view_column_buildable_init                 (GtkBuildableIface     *iface);
148
149 static guint tree_column_signals[LAST_SIGNAL] = { 0 };
150
151 G_DEFINE_TYPE_WITH_CODE (GtkTreeViewColumn, gtk_tree_view_column, G_TYPE_INITIALLY_UNOWNED,
152                          G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
153                                                 gtk_tree_view_column_cell_layout_init)
154                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
155                                                 gtk_tree_view_column_buildable_init))
156
157
158 static void
159 gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class)
160 {
161   GObjectClass *object_class;
162
163   object_class = (GObjectClass*) class;
164
165   class->clicked = NULL;
166
167   object_class->finalize = gtk_tree_view_column_finalize;
168   object_class->dispose = gtk_tree_view_column_dispose;
169   object_class->set_property = gtk_tree_view_column_set_property;
170   object_class->get_property = gtk_tree_view_column_get_property;
171   
172   tree_column_signals[CLICKED] =
173     g_signal_new (I_("clicked"),
174                   G_OBJECT_CLASS_TYPE (object_class),
175                   G_SIGNAL_RUN_LAST,
176                   G_STRUCT_OFFSET (GtkTreeViewColumnClass, clicked),
177                   NULL, NULL,
178                   _gtk_marshal_VOID__VOID,
179                   G_TYPE_NONE, 0);
180
181   g_object_class_install_property (object_class,
182                                    PROP_VISIBLE,
183                                    g_param_spec_boolean ("visible",
184                                                         P_("Visible"),
185                                                         P_("Whether to display the column"),
186                                                          TRUE,
187                                                          GTK_PARAM_READWRITE));
188   
189   g_object_class_install_property (object_class,
190                                    PROP_RESIZABLE,
191                                    g_param_spec_boolean ("resizable",
192                                                          P_("Resizable"),
193                                                          P_("Column is user-resizable"),
194                                                          FALSE,
195                                                          GTK_PARAM_READWRITE));
196   
197   g_object_class_install_property (object_class,
198                                    PROP_WIDTH,
199                                    g_param_spec_int ("width",
200                                                      P_("Width"),
201                                                      P_("Current width of the column"),
202                                                      0,
203                                                      G_MAXINT,
204                                                      0,
205                                                      GTK_PARAM_READABLE));
206   g_object_class_install_property (object_class,
207                                    PROP_SPACING,
208                                    g_param_spec_int ("spacing",
209                                                      P_("Spacing"),
210                                                      P_("Space which is inserted between cells"),
211                                                      0,
212                                                      G_MAXINT,
213                                                      0,
214                                                      GTK_PARAM_READWRITE));
215   g_object_class_install_property (object_class,
216                                    PROP_SIZING,
217                                    g_param_spec_enum ("sizing",
218                                                       P_("Sizing"),
219                                                       P_("Resize mode of the column"),
220                                                       GTK_TYPE_TREE_VIEW_COLUMN_SIZING,
221                                                       GTK_TREE_VIEW_COLUMN_GROW_ONLY,
222                                                       GTK_PARAM_READWRITE));
223   
224   g_object_class_install_property (object_class,
225                                    PROP_FIXED_WIDTH,
226                                    g_param_spec_int ("fixed-width",
227                                                      P_("Fixed Width"),
228                                                      P_("Current fixed width of the column"),
229                                                      1,
230                                                      G_MAXINT,
231                                                      1, /* not useful */
232                                                      GTK_PARAM_READWRITE));
233
234   g_object_class_install_property (object_class,
235                                    PROP_MIN_WIDTH,
236                                    g_param_spec_int ("min-width",
237                                                      P_("Minimum Width"),
238                                                      P_("Minimum allowed width of the column"),
239                                                      -1,
240                                                      G_MAXINT,
241                                                      -1,
242                                                      GTK_PARAM_READWRITE));
243
244   g_object_class_install_property (object_class,
245                                    PROP_MAX_WIDTH,
246                                    g_param_spec_int ("max-width",
247                                                      P_("Maximum Width"),
248                                                      P_("Maximum allowed width of the column"),
249                                                      -1,
250                                                      G_MAXINT,
251                                                      -1,
252                                                      GTK_PARAM_READWRITE));
253
254   g_object_class_install_property (object_class,
255                                    PROP_TITLE,
256                                    g_param_spec_string ("title",
257                                                         P_("Title"),
258                                                         P_("Title to appear in column header"),
259                                                         "",
260                                                         GTK_PARAM_READWRITE));
261   
262   g_object_class_install_property (object_class,
263                                    PROP_EXPAND,
264                                    g_param_spec_boolean ("expand",
265                                                          P_("Expand"),
266                                                          P_("Column gets share of extra width allocated to the widget"),
267                                                          FALSE,
268                                                          GTK_PARAM_READWRITE));
269   
270   g_object_class_install_property (object_class,
271                                    PROP_CLICKABLE,
272                                    g_param_spec_boolean ("clickable",
273                                                         P_("Clickable"),
274                                                         P_("Whether the header can be clicked"),
275                                                          FALSE,
276                                                          GTK_PARAM_READWRITE));
277   
278
279   g_object_class_install_property (object_class,
280                                    PROP_WIDGET,
281                                    g_param_spec_object ("widget",
282                                                         P_("Widget"),
283                                                         P_("Widget to put in column header button instead of column title"),
284                                                         GTK_TYPE_WIDGET,
285                                                         GTK_PARAM_READWRITE));
286
287   g_object_class_install_property (object_class,
288                                    PROP_ALIGNMENT,
289                                    g_param_spec_float ("alignment",
290                                                        P_("Alignment"),
291                                                        P_("X Alignment of the column header text or widget"),
292                                                        0.0,
293                                                        1.0,
294                                                        0.0,
295                                                        GTK_PARAM_READWRITE));
296
297   g_object_class_install_property (object_class,
298                                    PROP_REORDERABLE,
299                                    g_param_spec_boolean ("reorderable",
300                                                          P_("Reorderable"),
301                                                          P_("Whether the column can be reordered around the headers"),
302                                                          FALSE,
303                                                          GTK_PARAM_READWRITE));
304
305   g_object_class_install_property (object_class,
306                                    PROP_SORT_INDICATOR,
307                                    g_param_spec_boolean ("sort-indicator",
308                                                         P_("Sort indicator"),
309                                                         P_("Whether to show a sort indicator"),
310                                                          FALSE,
311                                                          GTK_PARAM_READWRITE));
312
313   g_object_class_install_property (object_class,
314                                    PROP_SORT_ORDER,
315                                    g_param_spec_enum ("sort-order",
316                                                       P_("Sort order"),
317                                                       P_("Sort direction the sort indicator should indicate"),
318                                                       GTK_TYPE_SORT_TYPE,
319                                                       GTK_SORT_ASCENDING,
320                                                       GTK_PARAM_READWRITE));
321
322   /**
323    * GtkTreeViewColumn:sort-column-id:
324    *
325    * Logical sort column ID this column sorts on when selected for sorting. Setting the sort column ID makes the column header
326    * clickable. Set to %-1 to make the column unsortable.
327    *
328    * Since: 2.18
329    **/
330   g_object_class_install_property (object_class,
331                                    PROP_SORT_COLUMN_ID,
332                                    g_param_spec_int ("sort-column-id",
333                                                      P_("Sort column ID"),
334                                                      P_("Logical sort column ID this column sorts on when selected for sorting"),
335                                                      -1,
336                                                      G_MAXINT,
337                                                      -1,
338                                                      GTK_PARAM_READWRITE));
339 }
340
341 static void
342 gtk_tree_view_column_buildable_init (GtkBuildableIface *iface)
343 {
344   iface->add_child = _gtk_cell_layout_buildable_add_child;
345   iface->custom_tag_start = _gtk_cell_layout_buildable_custom_tag_start;
346   iface->custom_tag_end = _gtk_cell_layout_buildable_custom_tag_end;
347 }
348
349 static void
350 gtk_tree_view_column_cell_layout_init (GtkCellLayoutIface *iface)
351 {
352   iface->get_area = gtk_tree_view_column_cell_layout_get_area;
353 }
354
355 static void
356 gtk_tree_view_column_init (GtkTreeViewColumn *tree_column)
357 {
358   tree_column->button = NULL;
359   tree_column->xalign = 0.0;
360   tree_column->width = 0;
361   tree_column->requested_width = -1;
362   tree_column->min_width = -1;
363   tree_column->max_width = -1;
364   tree_column->resized_width = 0;
365   tree_column->column_type = GTK_TREE_VIEW_COLUMN_GROW_ONLY;
366   tree_column->visible = TRUE;
367   tree_column->resizable = FALSE;
368   tree_column->expand = FALSE;
369   tree_column->clickable = FALSE;
370   tree_column->dirty = TRUE;
371   tree_column->sort_order = GTK_SORT_ASCENDING;
372   tree_column->show_sort_indicator = FALSE;
373   tree_column->property_changed_signal = 0;
374   tree_column->sort_clicked_signal = 0;
375   tree_column->sort_column_changed_signal = 0;
376   tree_column->sort_column_id = -1;
377   tree_column->reorderable = FALSE;
378   tree_column->maybe_reordered = FALSE;
379   tree_column->fixed_width = 1;
380   tree_column->use_resized_width = FALSE;
381   tree_column->title = g_strdup ("");
382
383   tree_column->cell_area = gtk_cell_area_box_new ();
384   gtk_cell_area_set_style_detail (tree_column->cell_area, "treeview");
385   tree_column->cell_area_context = gtk_cell_area_create_context (tree_column->cell_area);
386
387   tree_column->context_changed_signal =
388     g_signal_connect (tree_column->cell_area_context, "notify",
389                       G_CALLBACK (gtk_tree_view_column_context_changed), tree_column);
390
391 }
392
393 static void
394 gtk_tree_view_column_dispose (GObject *object)
395 {
396   GtkTreeViewColumn *tree_column = (GtkTreeViewColumn *) object;
397
398   if (tree_column->cell_area_context)
399     {
400       g_object_unref (tree_column->cell_area_context);
401
402       g_signal_handler_disconnect (tree_column->cell_area_context,
403                                    tree_column->context_changed_signal);
404       tree_column->context_changed_signal = 0;
405     }
406
407   if (tree_column->cell_area)
408     {
409       g_object_unref (tree_column->cell_area);
410     }
411
412   if (tree_column->child)
413     {
414       g_object_unref (tree_column->child);
415       tree_column->child = NULL;
416     }
417
418   G_OBJECT_CLASS (gtk_tree_view_column_parent_class)->dispose (object);
419 }
420
421 static void
422 gtk_tree_view_column_finalize (GObject *object)
423 {
424   GtkTreeViewColumn *tree_column = (GtkTreeViewColumn *) object;
425
426   g_free (tree_column->title);
427
428   G_OBJECT_CLASS (gtk_tree_view_column_parent_class)->finalize (object);
429 }
430
431 static void
432 gtk_tree_view_column_set_property (GObject         *object,
433                                    guint            prop_id,
434                                    const GValue    *value,
435                                    GParamSpec      *pspec)
436 {
437   GtkTreeViewColumn *tree_column;
438
439   tree_column = GTK_TREE_VIEW_COLUMN (object);
440
441   switch (prop_id)
442     {
443     case PROP_VISIBLE:
444       gtk_tree_view_column_set_visible (tree_column,
445                                         g_value_get_boolean (value));
446       break;
447
448     case PROP_RESIZABLE:
449       gtk_tree_view_column_set_resizable (tree_column,
450                                           g_value_get_boolean (value));
451       break;
452
453     case PROP_SIZING:
454       gtk_tree_view_column_set_sizing (tree_column,
455                                        g_value_get_enum (value));
456       break;
457
458     case PROP_FIXED_WIDTH:
459       gtk_tree_view_column_set_fixed_width (tree_column,
460                                             g_value_get_int (value));
461       break;
462
463     case PROP_MIN_WIDTH:
464       gtk_tree_view_column_set_min_width (tree_column,
465                                           g_value_get_int (value));
466       break;
467
468     case PROP_MAX_WIDTH:
469       gtk_tree_view_column_set_max_width (tree_column,
470                                           g_value_get_int (value));
471       break;
472
473     case PROP_SPACING:
474       gtk_tree_view_column_set_spacing (tree_column,
475                                         g_value_get_int (value));
476       break;
477
478     case PROP_TITLE:
479       gtk_tree_view_column_set_title (tree_column,
480                                       g_value_get_string (value));
481       break;
482
483     case PROP_EXPAND:
484       gtk_tree_view_column_set_expand (tree_column,
485                                        g_value_get_boolean (value));
486       break;
487
488     case PROP_CLICKABLE:
489       gtk_tree_view_column_set_clickable (tree_column,
490                                           g_value_get_boolean (value));
491       break;
492
493     case PROP_WIDGET:
494       gtk_tree_view_column_set_widget (tree_column,
495                                        (GtkWidget*) g_value_get_object (value));
496       break;
497
498     case PROP_ALIGNMENT:
499       gtk_tree_view_column_set_alignment (tree_column,
500                                           g_value_get_float (value));
501       break;
502
503     case PROP_REORDERABLE:
504       gtk_tree_view_column_set_reorderable (tree_column,
505                                             g_value_get_boolean (value));
506       break;
507
508     case PROP_SORT_INDICATOR:
509       gtk_tree_view_column_set_sort_indicator (tree_column,
510                                                g_value_get_boolean (value));
511       break;
512
513     case PROP_SORT_ORDER:
514       gtk_tree_view_column_set_sort_order (tree_column,
515                                            g_value_get_enum (value));
516       break;
517       
518     case PROP_SORT_COLUMN_ID:
519       gtk_tree_view_column_set_sort_column_id (tree_column,
520                                                g_value_get_int (value));
521       break;
522       
523     default:
524       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
525       break;
526     }
527 }
528
529 static void
530 gtk_tree_view_column_get_property (GObject         *object,
531                                    guint            prop_id,
532                                    GValue          *value,
533                                    GParamSpec      *pspec)
534 {
535   GtkTreeViewColumn *tree_column;
536
537   tree_column = GTK_TREE_VIEW_COLUMN (object);
538
539   switch (prop_id)
540     {
541     case PROP_VISIBLE:
542       g_value_set_boolean (value,
543                            gtk_tree_view_column_get_visible (tree_column));
544       break;
545
546     case PROP_RESIZABLE:
547       g_value_set_boolean (value,
548                            gtk_tree_view_column_get_resizable (tree_column));
549       break;
550
551     case PROP_WIDTH:
552       g_value_set_int (value,
553                        gtk_tree_view_column_get_width (tree_column));
554       break;
555
556     case PROP_SPACING:
557       g_value_set_int (value,
558                        gtk_tree_view_column_get_spacing (tree_column));
559       break;
560
561     case PROP_SIZING:
562       g_value_set_enum (value,
563                         gtk_tree_view_column_get_sizing (tree_column));
564       break;
565
566     case PROP_FIXED_WIDTH:
567       g_value_set_int (value,
568                        gtk_tree_view_column_get_fixed_width (tree_column));
569       break;
570
571     case PROP_MIN_WIDTH:
572       g_value_set_int (value,
573                        gtk_tree_view_column_get_min_width (tree_column));
574       break;
575
576     case PROP_MAX_WIDTH:
577       g_value_set_int (value,
578                        gtk_tree_view_column_get_max_width (tree_column));
579       break;
580
581     case PROP_TITLE:
582       g_value_set_string (value,
583                           gtk_tree_view_column_get_title (tree_column));
584       break;
585
586     case PROP_EXPAND:
587       g_value_set_boolean (value,
588                           gtk_tree_view_column_get_expand (tree_column));
589       break;
590
591     case PROP_CLICKABLE:
592       g_value_set_boolean (value,
593                            gtk_tree_view_column_get_clickable (tree_column));
594       break;
595
596     case PROP_WIDGET:
597       g_value_set_object (value,
598                           (GObject*) gtk_tree_view_column_get_widget (tree_column));
599       break;
600
601     case PROP_ALIGNMENT:
602       g_value_set_float (value,
603                          gtk_tree_view_column_get_alignment (tree_column));
604       break;
605
606     case PROP_REORDERABLE:
607       g_value_set_boolean (value,
608                            gtk_tree_view_column_get_reorderable (tree_column));
609       break;
610
611     case PROP_SORT_INDICATOR:
612       g_value_set_boolean (value,
613                            gtk_tree_view_column_get_sort_indicator (tree_column));
614       break;
615
616     case PROP_SORT_ORDER:
617       g_value_set_enum (value,
618                         gtk_tree_view_column_get_sort_order (tree_column));
619       break;
620       
621     case PROP_SORT_COLUMN_ID:
622       g_value_set_int (value,
623                        gtk_tree_view_column_get_sort_column_id (tree_column));
624       break;
625       
626     default:
627       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
628       break;
629     }
630 }
631
632 /* Implementation of GtkCellLayout interface
633  */
634 static GtkCellArea *
635 gtk_tree_view_column_cell_layout_get_area (GtkCellLayout   *cell_layout)
636 {
637   GtkTreeViewColumn *column;
638
639   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (cell_layout), NULL);
640   column = GTK_TREE_VIEW_COLUMN (cell_layout);
641
642   return column->cell_area;
643 }
644
645 /* Button handling code
646  */
647 static void
648 gtk_tree_view_column_create_button (GtkTreeViewColumn *tree_column)
649 {
650   GtkTreeView *tree_view;
651   GtkWidget *child;
652   GtkWidget *hbox;
653
654   tree_view = (GtkTreeView *) tree_column->tree_view;
655
656   g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
657   g_return_if_fail (tree_column->button == NULL);
658
659   gtk_widget_push_composite_child ();
660   tree_column->button = gtk_button_new ();
661   gtk_widget_add_events (tree_column->button, GDK_POINTER_MOTION_MASK);
662   gtk_widget_pop_composite_child ();
663
664   /* make sure we own a reference to it as well. */
665   if (tree_view->priv->header_window)
666     gtk_widget_set_parent_window (tree_column->button, tree_view->priv->header_window);
667   gtk_widget_set_parent (tree_column->button, GTK_WIDGET (tree_view));
668
669   g_signal_connect (tree_column->button, "event",
670                     G_CALLBACK (gtk_tree_view_column_button_event),
671                     tree_column);
672   g_signal_connect (tree_column->button, "clicked",
673                     G_CALLBACK (gtk_tree_view_column_button_clicked),
674                     tree_column);
675
676   tree_column->alignment = gtk_alignment_new (tree_column->xalign, 0.5, 0.0, 0.0);
677
678   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
679   tree_column->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN);
680
681   if (tree_column->child)
682     child = tree_column->child;
683   else
684     {
685       child = gtk_label_new (tree_column->title);
686       gtk_widget_show (child);
687     }
688
689   g_signal_connect (child, "mnemonic-activate",
690                     G_CALLBACK (gtk_tree_view_column_mnemonic_activate),
691                     tree_column);
692
693   if (tree_column->xalign <= 0.5)
694     gtk_box_pack_end (GTK_BOX (hbox), tree_column->arrow, FALSE, FALSE, 0);
695   else
696     gtk_box_pack_start (GTK_BOX (hbox), tree_column->arrow, FALSE, FALSE, 0);
697
698   gtk_box_pack_start (GTK_BOX (hbox), tree_column->alignment, TRUE, TRUE, 0);
699         
700   gtk_container_add (GTK_CONTAINER (tree_column->alignment), child);
701   gtk_container_add (GTK_CONTAINER (tree_column->button), hbox);
702
703   gtk_widget_show (hbox);
704   gtk_widget_show (tree_column->alignment);
705   gtk_tree_view_column_update_button (tree_column);
706 }
707
708 static void 
709 gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column)
710 {
711   gint sort_column_id = -1;
712   GtkWidget *hbox;
713   GtkWidget *alignment;
714   GtkWidget *arrow;
715   GtkWidget *current_child;
716   GtkArrowType arrow_type = GTK_ARROW_NONE;
717   GtkTreeModel *model;
718
719   if (tree_column->tree_view)
720     model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_column->tree_view));
721   else
722     model = NULL;
723
724   /* Create a button if necessary */
725   if (tree_column->visible &&
726       tree_column->button == NULL &&
727       tree_column->tree_view &&
728       gtk_widget_get_realized (tree_column->tree_view))
729     gtk_tree_view_column_create_button (tree_column);
730   
731   if (! tree_column->button)
732     return;
733
734   hbox = gtk_bin_get_child (GTK_BIN (tree_column->button));
735   alignment = tree_column->alignment;
736   arrow = tree_column->arrow;
737   current_child = gtk_bin_get_child (GTK_BIN (alignment));
738
739   /* Set up the actual button */
740   gtk_alignment_set (GTK_ALIGNMENT (alignment), tree_column->xalign,
741                      0.5, 0.0, 0.0);
742       
743   if (tree_column->child)
744     {
745       if (current_child != tree_column->child)
746         {
747           gtk_container_remove (GTK_CONTAINER (alignment),
748                                 current_child);
749           gtk_container_add (GTK_CONTAINER (alignment),
750                              tree_column->child);
751         }
752     }
753   else 
754     {
755       if (current_child == NULL)
756         {
757           current_child = gtk_label_new (NULL);
758           gtk_widget_show (current_child);
759           gtk_container_add (GTK_CONTAINER (alignment),
760                              current_child);
761         }
762
763       g_return_if_fail (GTK_IS_LABEL (current_child));
764
765       if (tree_column->title)
766         gtk_label_set_text_with_mnemonic (GTK_LABEL (current_child),
767                                           tree_column->title);
768       else
769         gtk_label_set_text_with_mnemonic (GTK_LABEL (current_child),
770                                           "");
771     }
772
773   if (GTK_IS_TREE_SORTABLE (model))
774     gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model),
775                                           &sort_column_id,
776                                           NULL);
777
778   if (tree_column->show_sort_indicator)
779     {
780       gboolean alternative;
781
782       g_object_get (gtk_widget_get_settings (tree_column->tree_view),
783                     "gtk-alternative-sort-arrows", &alternative,
784                     NULL);
785
786       switch (tree_column->sort_order)
787         {
788           case GTK_SORT_ASCENDING:
789             arrow_type = alternative ? GTK_ARROW_UP : GTK_ARROW_DOWN;
790             break;
791
792           case GTK_SORT_DESCENDING:
793             arrow_type = alternative ? GTK_ARROW_DOWN : GTK_ARROW_UP;
794             break;
795
796           default:
797             g_warning (G_STRLOC": bad sort order");
798             break;
799         }
800     }
801
802   gtk_arrow_set (GTK_ARROW (arrow),
803                  arrow_type,
804                  GTK_SHADOW_IN);
805
806   /* Put arrow on the right if the text is left-or-center justified, and on the
807    * left otherwise; do this by packing boxes, so flipping text direction will
808    * reverse things
809    */
810   g_object_ref (arrow);
811   gtk_container_remove (GTK_CONTAINER (hbox), arrow);
812
813   if (tree_column->xalign <= 0.5)
814     {
815       gtk_box_pack_end (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
816     }
817   else
818     {
819       gtk_box_pack_start (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
820       /* move it to the front */
821       gtk_box_reorder_child (GTK_BOX (hbox), arrow, 0);
822     }
823   g_object_unref (arrow);
824
825   if (tree_column->show_sort_indicator
826       || (GTK_IS_TREE_SORTABLE (model) && tree_column->sort_column_id >= 0))
827     gtk_widget_show (arrow);
828   else
829     gtk_widget_hide (arrow);
830
831   /* It's always safe to hide the button.  It isn't always safe to show it, as
832    * if you show it before it's realized, it'll get the wrong window. */
833   if (tree_column->button &&
834       tree_column->tree_view != NULL &&
835       gtk_widget_get_realized (tree_column->tree_view))
836     {
837       if (tree_column->visible)
838         {
839           gtk_widget_show_now (tree_column->button);
840           if (tree_column->window)
841             {
842               if (tree_column->resizable)
843                 {
844                   gdk_window_show (tree_column->window);
845                   gdk_window_raise (tree_column->window);
846                 }
847               else
848                 {
849                   gdk_window_hide (tree_column->window);
850                 }
851             }
852         }
853       else
854         {
855           gtk_widget_hide (tree_column->button);
856           if (tree_column->window)
857             gdk_window_hide (tree_column->window);
858         }
859     }
860   
861   if (tree_column->reorderable || tree_column->clickable)
862     {
863       gtk_widget_set_can_focus (tree_column->button, TRUE);
864     }
865   else
866     {
867       gtk_widget_set_can_focus (tree_column->button, FALSE);
868       if (gtk_widget_has_focus (tree_column->button))
869         {
870           GtkWidget *toplevel = gtk_widget_get_toplevel (tree_column->tree_view);
871           if (gtk_widget_is_toplevel (toplevel))
872             {
873               gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
874             }
875         }
876     }
877   /* Queue a resize on the assumption that we always want to catch all changes
878    * and columns don't change all that often.
879    */
880   if (gtk_widget_get_realized (tree_column->tree_view))
881      gtk_widget_queue_resize (tree_column->tree_view);
882
883 }
884
885 /* Button signal handlers
886  */
887
888 static gint
889 gtk_tree_view_column_button_event (GtkWidget *widget,
890                                    GdkEvent  *event,
891                                    gpointer   data)
892 {
893   GtkTreeViewColumn *column = (GtkTreeViewColumn *) data;
894
895   g_return_val_if_fail (event != NULL, FALSE);
896
897   if (event->type == GDK_BUTTON_PRESS &&
898       column->reorderable &&
899       ((GdkEventButton *)event)->button == 1)
900     {
901       column->maybe_reordered = TRUE;
902       gdk_window_get_pointer (gtk_button_get_event_window (GTK_BUTTON (widget)),
903                               &column->drag_x,
904                               &column->drag_y,
905                               NULL);
906       gtk_widget_grab_focus (widget);
907     }
908
909   if (event->type == GDK_BUTTON_RELEASE ||
910       event->type == GDK_LEAVE_NOTIFY)
911     column->maybe_reordered = FALSE;
912   
913   if (event->type == GDK_MOTION_NOTIFY &&
914       column->maybe_reordered &&
915       (gtk_drag_check_threshold (widget,
916                                  column->drag_x,
917                                  column->drag_y,
918                                  (gint) ((GdkEventMotion *)event)->x,
919                                  (gint) ((GdkEventMotion *)event)->y)))
920     {
921       column->maybe_reordered = FALSE;
922       _gtk_tree_view_column_start_drag (GTK_TREE_VIEW (column->tree_view), column,
923                                         event->motion.device);
924       return TRUE;
925     }
926   if (column->clickable == FALSE)
927     {
928       switch (event->type)
929         {
930         case GDK_BUTTON_PRESS:
931         case GDK_2BUTTON_PRESS:
932         case GDK_3BUTTON_PRESS:
933         case GDK_MOTION_NOTIFY:
934         case GDK_BUTTON_RELEASE:
935         case GDK_ENTER_NOTIFY:
936         case GDK_LEAVE_NOTIFY:
937           return TRUE;
938         default:
939           return FALSE;
940         }
941     }
942   return FALSE;
943 }
944
945
946 static void
947 gtk_tree_view_column_button_clicked (GtkWidget *widget, gpointer data)
948 {
949   g_signal_emit_by_name (data, "clicked");
950 }
951
952 static gboolean
953 gtk_tree_view_column_mnemonic_activate (GtkWidget *widget,
954                                         gboolean   group_cycling,
955                                         gpointer   data)
956 {
957   GtkTreeViewColumn *column = (GtkTreeViewColumn *)data;
958
959   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (column), FALSE);
960
961   GTK_TREE_VIEW (column->tree_view)->priv->focus_column = column;
962   if (column->clickable)
963     gtk_button_clicked (GTK_BUTTON (column->button));
964   else if (gtk_widget_get_can_focus (column->button))
965     gtk_widget_grab_focus (column->button);
966   else
967     gtk_widget_grab_focus (column->tree_view);
968
969   return TRUE;
970 }
971
972 static void
973 gtk_tree_view_model_sort_column_changed (GtkTreeSortable   *sortable,
974                                          GtkTreeViewColumn *column)
975 {
976   gint sort_column_id;
977   GtkSortType order;
978
979   if (gtk_tree_sortable_get_sort_column_id (sortable,
980                                             &sort_column_id,
981                                             &order))
982     {
983       if (sort_column_id == column->sort_column_id)
984         {
985           gtk_tree_view_column_set_sort_indicator (column, TRUE);
986           gtk_tree_view_column_set_sort_order (column, order);
987         }
988       else
989         {
990           gtk_tree_view_column_set_sort_indicator (column, FALSE);
991         }
992     }
993   else
994     {
995       gtk_tree_view_column_set_sort_indicator (column, FALSE);
996     }
997 }
998
999 static void
1000 gtk_tree_view_column_sort (GtkTreeViewColumn *tree_column,
1001                            gpointer           data)
1002 {
1003   gint sort_column_id;
1004   GtkSortType order;
1005   gboolean has_sort_column;
1006   gboolean has_default_sort_func;
1007
1008   g_return_if_fail (tree_column->tree_view != NULL);
1009
1010   has_sort_column =
1011     gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (GTK_TREE_VIEW (tree_column->tree_view)->priv->model),
1012                                           &sort_column_id,
1013                                           &order);
1014   has_default_sort_func =
1015     gtk_tree_sortable_has_default_sort_func (GTK_TREE_SORTABLE (GTK_TREE_VIEW (tree_column->tree_view)->priv->model));
1016
1017   if (has_sort_column &&
1018       sort_column_id == tree_column->sort_column_id)
1019     {
1020       if (order == GTK_SORT_ASCENDING)
1021         gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GTK_TREE_VIEW (tree_column->tree_view)->priv->model),
1022                                               tree_column->sort_column_id,
1023                                               GTK_SORT_DESCENDING);
1024       else if (order == GTK_SORT_DESCENDING && has_default_sort_func)
1025         gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GTK_TREE_VIEW (tree_column->tree_view)->priv->model),
1026                                               GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
1027                                               GTK_SORT_ASCENDING);
1028       else
1029         gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GTK_TREE_VIEW (tree_column->tree_view)->priv->model),
1030                                               tree_column->sort_column_id,
1031                                               GTK_SORT_ASCENDING);
1032     }
1033   else
1034     {
1035       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GTK_TREE_VIEW (tree_column->tree_view)->priv->model),
1036                                             tree_column->sort_column_id,
1037                                             GTK_SORT_ASCENDING);
1038     }
1039 }
1040
1041
1042 static void
1043 gtk_tree_view_column_setup_sort_column_id_callback (GtkTreeViewColumn *tree_column)
1044 {
1045   GtkTreeModel *model;
1046
1047   if (tree_column->tree_view == NULL)
1048     return;
1049
1050   model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_column->tree_view));
1051
1052   if (model == NULL)
1053     return;
1054
1055   if (GTK_IS_TREE_SORTABLE (model) &&
1056       tree_column->sort_column_id != -1)
1057     {
1058       gint real_sort_column_id;
1059       GtkSortType real_order;
1060
1061       if (tree_column->sort_column_changed_signal == 0)
1062         tree_column->sort_column_changed_signal =
1063           g_signal_connect (model, "sort-column-changed",
1064                             G_CALLBACK (gtk_tree_view_model_sort_column_changed),
1065                             tree_column);
1066       
1067       if (gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model),
1068                                                 &real_sort_column_id,
1069                                                 &real_order) &&
1070           (real_sort_column_id == tree_column->sort_column_id))
1071         {
1072           gtk_tree_view_column_set_sort_indicator (tree_column, TRUE);
1073           gtk_tree_view_column_set_sort_order (tree_column, real_order);
1074         }
1075       else 
1076         {
1077           gtk_tree_view_column_set_sort_indicator (tree_column, FALSE);
1078         }
1079    }
1080 }
1081
1082 static void
1083 gtk_tree_view_column_context_changed  (GtkCellAreaContext      *context,
1084                                        GParamSpec              *pspec,
1085                                        GtkTreeViewColumn       *tree_column)
1086 {
1087   if (!strcmp (pspec->name, "minimum-width") ||
1088       !strcmp (pspec->name, "natural-width") ||
1089       !strcmp (pspec->name, "minimum-height") ||
1090       !strcmp (pspec->name, "natural-height"))
1091     {
1092       /* XXX We want to do something specific if the size actually got cleared
1093        * or if it just grew a little bit because of a data change and we
1094        * are in GROW_ONLY mode. 
1095        */
1096       _gtk_tree_view_column_cell_set_dirty (tree_column, TRUE);
1097     }
1098 }
1099
1100 static void
1101 gtk_tree_view_column_add_editable_callback (GtkCellArea       *area,
1102                                             GtkCellRenderer   *renderer,
1103                                             GtkCellEditable   *edit_widget,
1104                                             GdkRectangle      *cell_area,
1105                                             const gchar       *path_string,
1106                                             gpointer           user_data)
1107 {
1108   GtkTreePath *path;
1109   GtkTreeViewColumn *column = user_data;
1110
1111   path = gtk_tree_path_new_from_string (path_string);
1112
1113   _gtk_tree_view_add_editable (GTK_TREE_VIEW (column->tree_view),
1114                                column,
1115                                path,
1116                                edit_widget,
1117                                cell_area);
1118
1119   gtk_tree_path_free (path);
1120 }
1121
1122 static void
1123 gtk_tree_view_column_remove_editable_callback (GtkCellArea     *area,
1124                                                GtkCellRenderer *renderer,
1125                                                GtkCellEditable *edit_widget,
1126                                                gpointer         user_data)
1127 {
1128   GtkTreeViewColumn *column = user_data;
1129
1130   _gtk_tree_view_remove_editable (GTK_TREE_VIEW (column->tree_view),
1131                                   column,
1132                                   edit_widget);
1133 }
1134
1135 /* Exported Private Functions.
1136  * These should only be called by gtktreeview.c or gtktreeviewcolumn.c
1137  */
1138
1139 void
1140 _gtk_tree_view_column_realize_button (GtkTreeViewColumn *column)
1141 {
1142   GtkAllocation allocation;
1143   GtkTreeView *tree_view;
1144   GdkWindowAttr attr;
1145   guint attributes_mask;
1146   gboolean rtl;
1147
1148   tree_view = (GtkTreeView *)column->tree_view;
1149   rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1150
1151   g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
1152   g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
1153   g_return_if_fail (tree_view->priv->header_window != NULL);
1154   g_return_if_fail (column->button != NULL);
1155
1156   gtk_widget_set_parent_window (column->button, tree_view->priv->header_window);
1157
1158   if (column->visible)
1159     gtk_widget_show (column->button);
1160
1161   attr.window_type = GDK_WINDOW_CHILD;
1162   attr.wclass = GDK_INPUT_ONLY;
1163   attr.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
1164   attr.event_mask = gtk_widget_get_events (GTK_WIDGET (tree_view)) |
1165                     (GDK_BUTTON_PRESS_MASK |
1166                      GDK_BUTTON_RELEASE_MASK |
1167                      GDK_POINTER_MOTION_MASK |
1168                      GDK_POINTER_MOTION_HINT_MASK |
1169                      GDK_KEY_PRESS_MASK);
1170   attributes_mask = GDK_WA_CURSOR | GDK_WA_X | GDK_WA_Y;
1171   attr.cursor = gdk_cursor_new_for_display (gdk_window_get_display (tree_view->priv->header_window),
1172                                             GDK_SB_H_DOUBLE_ARROW);
1173   attr.y = 0;
1174   attr.width = TREE_VIEW_DRAG_WIDTH;
1175   attr.height = tree_view->priv->header_height;
1176
1177   gtk_widget_get_allocation (column->button, &allocation);
1178   attr.x = (allocation.x + (rtl ? 0 : allocation.width)) - TREE_VIEW_DRAG_WIDTH / 2;
1179   column->window = gdk_window_new (tree_view->priv->header_window,
1180                                    &attr, attributes_mask);
1181   gdk_window_set_user_data (column->window, tree_view);
1182
1183   gtk_tree_view_column_update_button (column);
1184
1185   gdk_cursor_unref (attr.cursor);
1186 }
1187
1188 void
1189 _gtk_tree_view_column_unrealize_button (GtkTreeViewColumn *column)
1190 {
1191   g_return_if_fail (column != NULL);
1192   g_return_if_fail (column->window != NULL);
1193
1194   gdk_window_set_user_data (column->window, NULL);
1195   gdk_window_destroy (column->window);
1196   column->window = NULL;
1197 }
1198
1199 void
1200 _gtk_tree_view_column_unset_model (GtkTreeViewColumn *column,
1201                                    GtkTreeModel      *old_model)
1202 {
1203   if (column->sort_column_changed_signal)
1204     {
1205       g_signal_handler_disconnect (old_model,
1206                                    column->sort_column_changed_signal);
1207       column->sort_column_changed_signal = 0;
1208     }
1209   gtk_tree_view_column_set_sort_indicator (column, FALSE);
1210 }
1211
1212 void
1213 _gtk_tree_view_column_set_tree_view (GtkTreeViewColumn *column,
1214                                      GtkTreeView       *tree_view)
1215 {
1216   g_assert (column->tree_view == NULL);
1217
1218   column->tree_view = GTK_WIDGET (tree_view);
1219   gtk_tree_view_column_create_button (column);
1220
1221   column->add_editable_signal =
1222       g_signal_connect (column->cell_area, "add-editable",
1223                         G_CALLBACK (gtk_tree_view_column_add_editable_callback),
1224                         column);
1225   column->remove_editable_signal =
1226       g_signal_connect (column->cell_area, "remove-editable",
1227                         G_CALLBACK (gtk_tree_view_column_remove_editable_callback),
1228                         column);
1229
1230   column->property_changed_signal =
1231           g_signal_connect_swapped (tree_view,
1232                                     "notify::model",
1233                                     G_CALLBACK (gtk_tree_view_column_setup_sort_column_id_callback),
1234                                     column);
1235
1236   gtk_tree_view_column_setup_sort_column_id_callback (column);
1237 }
1238
1239 void
1240 _gtk_tree_view_column_unset_tree_view (GtkTreeViewColumn *column)
1241 {
1242   if (column->tree_view && column->button)
1243     {
1244       gtk_container_remove (GTK_CONTAINER (column->tree_view), column->button);
1245     }
1246   if (column->property_changed_signal)
1247     {
1248       g_signal_handler_disconnect (column->tree_view, column->property_changed_signal);
1249       column->property_changed_signal = 0;
1250     }
1251
1252   if (column->sort_column_changed_signal)
1253     {
1254       g_signal_handler_disconnect (gtk_tree_view_get_model (GTK_TREE_VIEW (column->tree_view)),
1255                                    column->sort_column_changed_signal);
1256       column->sort_column_changed_signal = 0;
1257     }
1258
1259   column->tree_view = NULL;
1260   column->button = NULL;
1261 }
1262
1263 gboolean
1264 _gtk_tree_view_column_has_editable_cell (GtkTreeViewColumn *column)
1265 {
1266   gboolean ret = FALSE;
1267   GList *list, *cells;
1268
1269   cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column->cell_area));
1270
1271   for (list = cells; list; list = list->next)
1272     {
1273       GtkCellRenderer *cell = list->data;
1274       GtkCellRendererMode mode;
1275
1276       g_object_get (cell, "mode", &mode, NULL);
1277
1278       if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1279         {
1280           ret = TRUE;
1281           break;
1282         }
1283     }
1284
1285   g_list_free (cells);
1286
1287   return ret;
1288 }
1289
1290 /* gets cell being edited */
1291 GtkCellRenderer *
1292 _gtk_tree_view_column_get_edited_cell (GtkTreeViewColumn *column)
1293 {
1294   return gtk_cell_area_get_edited_cell (column->cell_area);
1295 }
1296
1297 /* Public Functions */
1298
1299
1300 /**
1301  * gtk_tree_view_column_new:
1302  * 
1303  * Creates a new #GtkTreeViewColumn.
1304  * 
1305  * Return value: A newly created #GtkTreeViewColumn.
1306  **/
1307 GtkTreeViewColumn *
1308 gtk_tree_view_column_new (void)
1309 {
1310   GtkTreeViewColumn *tree_column;
1311
1312   tree_column = g_object_new (GTK_TYPE_TREE_VIEW_COLUMN, NULL);
1313
1314   return tree_column;
1315 }
1316
1317 /**
1318  * gtk_tree_view_column_new_with_attributes:
1319  * @title: The title to set the header to.
1320  * @cell: The #GtkCellRenderer.
1321  * @Varargs: A %NULL-terminated list of attributes.
1322  * 
1323  * Creates a new #GtkTreeViewColumn with a number of default values.  This is
1324  * equivalent to calling gtk_tree_view_column_set_title(),
1325  * gtk_tree_view_column_pack_start(), and
1326  * gtk_tree_view_column_set_attributes() on the newly created #GtkTreeViewColumn.
1327  *
1328  * Here's a simple example:
1329  * |[
1330  *  enum { TEXT_COLUMN, COLOR_COLUMN, N_COLUMNS };
1331  *  ...
1332  *  {
1333  *    GtkTreeViewColumn *column;
1334  *    GtkCellRenderer   *renderer = gtk_cell_renderer_text_new ();
1335  *  
1336  *    column = gtk_tree_view_column_new_with_attributes ("Title",
1337  *                                                       renderer,
1338  *                                                       "text", TEXT_COLUMN,
1339  *                                                       "foreground", COLOR_COLUMN,
1340  *                                                       NULL);
1341  *  }
1342  * ]|
1343  * 
1344  * Return value: A newly created #GtkTreeViewColumn.
1345  **/
1346 GtkTreeViewColumn *
1347 gtk_tree_view_column_new_with_attributes (const gchar     *title,
1348                                           GtkCellRenderer *cell,
1349                                           ...)
1350 {
1351   GtkTreeViewColumn *retval;
1352   va_list args;
1353
1354   retval = gtk_tree_view_column_new ();
1355
1356   gtk_tree_view_column_set_title (retval, title);
1357   gtk_tree_view_column_pack_start (retval, cell, TRUE);
1358
1359   va_start (args, cell);
1360   gtk_tree_view_column_set_attributesv (retval, cell, args);
1361   va_end (args);
1362
1363   return retval;
1364 }
1365
1366 /**
1367  * gtk_tree_view_column_pack_start:
1368  * @tree_column: A #GtkTreeViewColumn.
1369  * @cell: The #GtkCellRenderer. 
1370  * @expand: %TRUE if @cell is to be given extra space allocated to @tree_column.
1371  *
1372  * Packs the @cell into the beginning of the column. If @expand is %FALSE, then
1373  * the @cell is allocated no more space than it needs. Any unused space is divided
1374  * evenly between cells for which @expand is %TRUE.
1375  **/
1376 void
1377 gtk_tree_view_column_pack_start (GtkTreeViewColumn *tree_column,
1378                                  GtkCellRenderer   *cell,
1379                                  gboolean           expand)
1380 {
1381   gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (tree_column), cell, expand);
1382 }
1383
1384 /**
1385  * gtk_tree_view_column_pack_end:
1386  * @tree_column: A #GtkTreeViewColumn.
1387  * @cell: The #GtkCellRenderer. 
1388  * @expand: %TRUE if @cell is to be given extra space allocated to @tree_column.
1389  *
1390  * Adds the @cell to end of the column. If @expand is %FALSE, then the @cell
1391  * is allocated no more space than it needs. Any unused space is divided
1392  * evenly between cells for which @expand is %TRUE.
1393  **/
1394 void
1395 gtk_tree_view_column_pack_end (GtkTreeViewColumn  *tree_column,
1396                                GtkCellRenderer    *cell,
1397                                gboolean            expand)
1398 {
1399   gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (tree_column), cell, expand);
1400 }
1401
1402 /**
1403  * gtk_tree_view_column_clear:
1404  * @tree_column: A #GtkTreeViewColumn
1405  * 
1406  * Unsets all the mappings on all renderers on the @tree_column.
1407  **/
1408 void
1409 gtk_tree_view_column_clear (GtkTreeViewColumn *tree_column)
1410 {
1411   gtk_cell_layout_clear (GTK_CELL_LAYOUT (tree_column));
1412 }
1413
1414 /**
1415  * gtk_tree_view_column_add_attribute:
1416  * @tree_column: A #GtkTreeViewColumn.
1417  * @cell_renderer: the #GtkCellRenderer to set attributes on
1418  * @attribute: An attribute on the renderer
1419  * @column: The column position on the model to get the attribute from.
1420  * 
1421  * Adds an attribute mapping to the list in @tree_column.  The @column is the
1422  * column of the model to get a value from, and the @attribute is the
1423  * parameter on @cell_renderer to be set from the value. So for example
1424  * if column 2 of the model contains strings, you could have the
1425  * "text" attribute of a #GtkCellRendererText get its values from
1426  * column 2.
1427  **/
1428 void
1429 gtk_tree_view_column_add_attribute (GtkTreeViewColumn *tree_column,
1430                                     GtkCellRenderer   *cell_renderer,
1431                                     const gchar       *attribute,
1432                                     gint               column)
1433 {
1434   gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (tree_column),
1435                                  cell_renderer, attribute, column);
1436 }
1437
1438 static void
1439 gtk_tree_view_column_set_attributesv (GtkTreeViewColumn *tree_column,
1440                                       GtkCellRenderer   *cell_renderer,
1441                                       va_list            args)
1442 {
1443   gchar *attribute;
1444   gint column;
1445
1446   attribute = va_arg (args, gchar *);
1447
1448   gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (tree_column->cell_area),
1449                                     cell_renderer);
1450   
1451   while (attribute != NULL)
1452     {
1453       column = va_arg (args, gint);
1454       gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (tree_column->cell_area),
1455                                      cell_renderer, attribute, column);
1456       attribute = va_arg (args, gchar *);
1457     }
1458 }
1459
1460 /**
1461  * gtk_tree_view_column_set_attributes:
1462  * @tree_column: A #GtkTreeViewColumn.
1463  * @cell_renderer: the #GtkCellRenderer we're setting the attributes of
1464  * @Varargs: A %NULL-terminated list of attributes.
1465  * 
1466  * Sets the attributes in the list as the attributes of @tree_column.
1467  * The attributes should be in attribute/column order, as in
1468  * gtk_tree_view_column_add_attribute(). All existing attributes
1469  * are removed, and replaced with the new attributes.
1470  **/
1471 void
1472 gtk_tree_view_column_set_attributes (GtkTreeViewColumn *tree_column,
1473                                      GtkCellRenderer   *cell_renderer,
1474                                      ...)
1475 {
1476   va_list args;
1477
1478   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1479   g_return_if_fail (GTK_IS_CELL_RENDERER (cell_renderer));
1480
1481   va_start (args, cell_renderer);
1482   gtk_tree_view_column_set_attributesv (tree_column, cell_renderer, args);
1483   va_end (args);
1484 }
1485
1486
1487 /**
1488  * gtk_tree_view_column_set_cell_data_func:
1489  * @tree_column: A #GtkTreeViewColumn
1490  * @cell_renderer: A #GtkCellRenderer
1491  * @func: The #GtkTreeViewColumnFunc to use. 
1492  * @func_data: The user data for @func.
1493  * @destroy: The destroy notification for @func_data
1494  * 
1495  * Sets the #GtkTreeViewColumnFunc to use for the column.  This
1496  * function is used instead of the standard attributes mapping for
1497  * setting the column value, and should set the value of @tree_column's
1498  * cell renderer as appropriate.  @func may be %NULL to remove an
1499  * older one.
1500  **/
1501 void
1502 gtk_tree_view_column_set_cell_data_func (GtkTreeViewColumn   *tree_column,
1503                                          GtkCellRenderer     *cell_renderer,
1504                                          GtkTreeCellDataFunc  func,
1505                                          gpointer             func_data,
1506                                          GDestroyNotify       destroy)
1507 {
1508   gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (tree_column),
1509                                       cell_renderer,
1510                                       (GtkCellLayoutDataFunc)func,
1511                                       func_data, destroy);
1512 }
1513
1514
1515 /**
1516  * gtk_tree_view_column_clear_attributes:
1517  * @tree_column: a #GtkTreeViewColumn
1518  * @cell_renderer: a #GtkCellRenderer to clear the attribute mapping on.
1519  * 
1520  * Clears all existing attributes previously set with
1521  * gtk_tree_view_column_set_attributes().
1522  **/
1523 void
1524 gtk_tree_view_column_clear_attributes (GtkTreeViewColumn *tree_column,
1525                                        GtkCellRenderer   *cell_renderer)
1526 {
1527   gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (tree_column),
1528                                     cell_renderer);
1529 }
1530
1531 /**
1532  * gtk_tree_view_column_set_spacing:
1533  * @tree_column: A #GtkTreeViewColumn.
1534  * @spacing: distance between cell renderers in pixels.
1535  * 
1536  * Sets the spacing field of @tree_column, which is the number of pixels to
1537  * place between cell renderers packed into it.
1538  **/
1539 void
1540 gtk_tree_view_column_set_spacing (GtkTreeViewColumn *tree_column,
1541                                   gint               spacing)
1542 {
1543   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1544   g_return_if_fail (spacing >= 0);
1545
1546   gtk_cell_area_box_set_spacing (GTK_CELL_AREA_BOX (tree_column->cell_area),
1547                                  spacing);
1548   if (tree_column->tree_view)
1549     _gtk_tree_view_column_cell_set_dirty (tree_column, TRUE);
1550 }
1551
1552 /**
1553  * gtk_tree_view_column_get_spacing:
1554  * @tree_column: A #GtkTreeViewColumn.
1555  * 
1556  * Returns the spacing of @tree_column.
1557  * 
1558  * Return value: the spacing of @tree_column.
1559  **/
1560 gint
1561 gtk_tree_view_column_get_spacing (GtkTreeViewColumn *tree_column)
1562 {
1563   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);
1564
1565   return gtk_cell_area_box_get_spacing (GTK_CELL_AREA_BOX (tree_column->cell_area));
1566 }
1567
1568 /* Options for manipulating the columns */
1569
1570 /**
1571  * gtk_tree_view_column_set_visible:
1572  * @tree_column: A #GtkTreeViewColumn.
1573  * @visible: %TRUE if the @tree_column is visible.
1574  * 
1575  * Sets the visibility of @tree_column.
1576  **/
1577 void
1578 gtk_tree_view_column_set_visible (GtkTreeViewColumn *tree_column,
1579                                   gboolean           visible)
1580 {
1581   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1582
1583   visible = !! visible;
1584   
1585   if (tree_column->visible == visible)
1586     return;
1587
1588   tree_column->visible = visible;
1589
1590   if (tree_column->visible)
1591     _gtk_tree_view_column_cell_set_dirty (tree_column, TRUE);
1592
1593   gtk_tree_view_column_update_button (tree_column);
1594   g_object_notify (G_OBJECT (tree_column), "visible");
1595 }
1596
1597 /**
1598  * gtk_tree_view_column_get_visible:
1599  * @tree_column: A #GtkTreeViewColumn.
1600  * 
1601  * Returns %TRUE if @tree_column is visible.
1602  * 
1603  * Return value: whether the column is visible or not.  If it is visible, then
1604  * the tree will show the column.
1605  **/
1606 gboolean
1607 gtk_tree_view_column_get_visible (GtkTreeViewColumn *tree_column)
1608 {
1609   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
1610
1611   return tree_column->visible;
1612 }
1613
1614 /**
1615  * gtk_tree_view_column_set_resizable:
1616  * @tree_column: A #GtkTreeViewColumn
1617  * @resizable: %TRUE, if the column can be resized
1618  * 
1619  * If @resizable is %TRUE, then the user can explicitly resize the column by
1620  * grabbing the outer edge of the column button.  If resizable is %TRUE and
1621  * sizing mode of the column is #GTK_TREE_VIEW_COLUMN_AUTOSIZE, then the sizing
1622  * mode is changed to #GTK_TREE_VIEW_COLUMN_GROW_ONLY.
1623  **/
1624 void
1625 gtk_tree_view_column_set_resizable (GtkTreeViewColumn *tree_column,
1626                                     gboolean           resizable)
1627 {
1628   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1629
1630   resizable = !! resizable;
1631
1632   if (tree_column->resizable == resizable)
1633     return;
1634
1635   tree_column->resizable = resizable;
1636
1637   if (resizable && tree_column->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE)
1638     gtk_tree_view_column_set_sizing (tree_column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
1639
1640   gtk_tree_view_column_update_button (tree_column);
1641
1642   g_object_notify (G_OBJECT (tree_column), "resizable");
1643 }
1644
1645 /**
1646  * gtk_tree_view_column_get_resizable:
1647  * @tree_column: A #GtkTreeViewColumn
1648  * 
1649  * Returns %TRUE if the @tree_column can be resized by the end user.
1650  * 
1651  * Return value: %TRUE, if the @tree_column can be resized.
1652  **/
1653 gboolean
1654 gtk_tree_view_column_get_resizable (GtkTreeViewColumn *tree_column)
1655 {
1656   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
1657
1658   return tree_column->resizable;
1659 }
1660
1661
1662 /**
1663  * gtk_tree_view_column_set_sizing:
1664  * @tree_column: A #GtkTreeViewColumn.
1665  * @type: The #GtkTreeViewColumnSizing.
1666  * 
1667  * Sets the growth behavior of @tree_column to @type.
1668  **/
1669 void
1670 gtk_tree_view_column_set_sizing (GtkTreeViewColumn       *tree_column,
1671                                  GtkTreeViewColumnSizing  type)
1672 {
1673   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1674
1675   if (type == tree_column->column_type)
1676     return;
1677
1678   if (type == GTK_TREE_VIEW_COLUMN_AUTOSIZE)
1679     gtk_tree_view_column_set_resizable (tree_column, FALSE);
1680
1681 #if 0
1682   /* I was clearly on crack when I wrote this.  I'm not sure what's supposed to
1683    * be below so I'll leave it until I figure it out.
1684    */
1685   if (tree_column->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE &&
1686       tree_column->requested_width != -1)
1687     {
1688       gtk_tree_view_column_set_sizing (tree_column, tree_column->requested_width);
1689     }
1690 #endif
1691   tree_column->column_type = type;
1692
1693   gtk_tree_view_column_update_button (tree_column);
1694
1695   g_object_notify (G_OBJECT (tree_column), "sizing");
1696 }
1697
1698 /**
1699  * gtk_tree_view_column_get_sizing:
1700  * @tree_column: A #GtkTreeViewColumn.
1701  * 
1702  * Returns the current type of @tree_column.
1703  * 
1704  * Return value: The type of @tree_column.
1705  **/
1706 GtkTreeViewColumnSizing
1707 gtk_tree_view_column_get_sizing (GtkTreeViewColumn *tree_column)
1708 {
1709   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);
1710
1711   return tree_column->column_type;
1712 }
1713
1714 /**
1715  * gtk_tree_view_column_get_width:
1716  * @tree_column: A #GtkTreeViewColumn.
1717  * 
1718  * Returns the current size of @tree_column in pixels.
1719  * 
1720  * Return value: The current width of @tree_column.
1721  **/
1722 gint
1723 gtk_tree_view_column_get_width (GtkTreeViewColumn *tree_column)
1724 {
1725   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);
1726
1727   return tree_column->width;
1728 }
1729
1730 void
1731 _gtk_tree_view_column_set_width (GtkTreeViewColumn *tree_column,
1732                                  int                width,
1733                                  int                internal_width)
1734 {
1735   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1736
1737   gtk_cell_area_context_allocate (tree_column->cell_area_context, internal_width, -1);
1738   tree_column->width = width;
1739
1740   g_object_notify (G_OBJECT (tree_column), "width");
1741 }
1742
1743 /**
1744  * gtk_tree_view_column_set_fixed_width:
1745  * @tree_column: A #GtkTreeViewColumn.
1746  * @fixed_width: The size to set @tree_column to. Must be greater than 0.
1747  * 
1748  * Sets the size of the column in pixels.  This is meaningful only if the sizing
1749  * type is #GTK_TREE_VIEW_COLUMN_FIXED.  The size of the column is clamped to
1750  * the min/max width for the column.  Please note that the min/max width of the
1751  * column doesn't actually affect the "fixed_width" property of the widget, just
1752  * the actual size when displayed.
1753  **/
1754 void
1755 gtk_tree_view_column_set_fixed_width (GtkTreeViewColumn *tree_column,
1756                                       gint               fixed_width)
1757 {
1758   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1759   g_return_if_fail (fixed_width > 0);
1760
1761   tree_column->fixed_width = fixed_width;
1762   tree_column->use_resized_width = FALSE;
1763
1764   if (tree_column->tree_view &&
1765       gtk_widget_get_realized (tree_column->tree_view) &&
1766       tree_column->column_type == GTK_TREE_VIEW_COLUMN_FIXED)
1767     {
1768       gtk_widget_queue_resize (tree_column->tree_view);
1769     }
1770
1771   g_object_notify (G_OBJECT (tree_column), "fixed-width");
1772 }
1773
1774 /**
1775  * gtk_tree_view_column_get_fixed_width:
1776  * @tree_column: a #GtkTreeViewColumn
1777  * 
1778  * Gets the fixed width of the column.  This value is only meaning may not be
1779  * the actual width of the column on the screen, just what is requested.
1780  * 
1781  * Return value: the fixed width of the column
1782  **/
1783 gint
1784 gtk_tree_view_column_get_fixed_width (GtkTreeViewColumn *tree_column)
1785 {
1786   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);
1787
1788   return tree_column->fixed_width;
1789 }
1790
1791 /**
1792  * gtk_tree_view_column_set_min_width:
1793  * @tree_column: A #GtkTreeViewColumn.
1794  * @min_width: The minimum width of the column in pixels, or -1.
1795  * 
1796  * Sets the minimum width of the @tree_column.  If @min_width is -1, then the
1797  * minimum width is unset.
1798  **/
1799 void
1800 gtk_tree_view_column_set_min_width (GtkTreeViewColumn *tree_column,
1801                                     gint               min_width)
1802 {
1803   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1804   g_return_if_fail (min_width >= -1);
1805
1806   if (min_width == tree_column->min_width)
1807     return;
1808
1809   if (tree_column->visible &&
1810       tree_column->tree_view != NULL &&
1811       gtk_widget_get_realized (tree_column->tree_view))
1812     {
1813       if (min_width > tree_column->width)
1814         gtk_widget_queue_resize (tree_column->tree_view);
1815     }
1816
1817   tree_column->min_width = min_width;
1818   g_object_freeze_notify (G_OBJECT (tree_column));
1819   if (tree_column->max_width != -1 && tree_column->max_width < min_width)
1820     {
1821       tree_column->max_width = min_width;
1822       g_object_notify (G_OBJECT (tree_column), "max-width");
1823     }
1824   g_object_notify (G_OBJECT (tree_column), "min-width");
1825   g_object_thaw_notify (G_OBJECT (tree_column));
1826
1827   if (tree_column->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE)
1828     _gtk_tree_view_column_autosize (GTK_TREE_VIEW (tree_column->tree_view),
1829                                     tree_column);
1830 }
1831
1832 /**
1833  * gtk_tree_view_column_get_min_width:
1834  * @tree_column: A #GtkTreeViewColumn.
1835  * 
1836  * Returns the minimum width in pixels of the @tree_column, or -1 if no minimum
1837  * width is set.
1838  * 
1839  * Return value: The minimum width of the @tree_column.
1840  **/
1841 gint
1842 gtk_tree_view_column_get_min_width (GtkTreeViewColumn *tree_column)
1843 {
1844   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), -1);
1845
1846   return tree_column->min_width;
1847 }
1848
1849 /**
1850  * gtk_tree_view_column_set_max_width:
1851  * @tree_column: A #GtkTreeViewColumn.
1852  * @max_width: The maximum width of the column in pixels, or -1.
1853  * 
1854  * Sets the maximum width of the @tree_column.  If @max_width is -1, then the
1855  * maximum width is unset.  Note, the column can actually be wider than max
1856  * width if it's the last column in a view.  In this case, the column expands to
1857  * fill any extra space.
1858  **/
1859 void
1860 gtk_tree_view_column_set_max_width (GtkTreeViewColumn *tree_column,
1861                                     gint               max_width)
1862 {
1863   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1864   g_return_if_fail (max_width >= -1);
1865
1866   if (max_width == tree_column->max_width)
1867     return;
1868
1869   if (tree_column->visible &&
1870       tree_column->tree_view != NULL &&
1871       gtk_widget_get_realized (tree_column->tree_view))
1872     {
1873       if (max_width != -1 && max_width < tree_column->width)
1874         gtk_widget_queue_resize (tree_column->tree_view);
1875     }
1876
1877   tree_column->max_width = max_width;
1878   g_object_freeze_notify (G_OBJECT (tree_column));
1879   if (max_width != -1 && max_width < tree_column->min_width)
1880     {
1881       tree_column->min_width = max_width;
1882       g_object_notify (G_OBJECT (tree_column), "min-width");
1883     }
1884   g_object_notify (G_OBJECT (tree_column), "max-width");
1885   g_object_thaw_notify (G_OBJECT (tree_column));
1886
1887   if (tree_column->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE)
1888     _gtk_tree_view_column_autosize (GTK_TREE_VIEW (tree_column->tree_view),
1889                                     tree_column);
1890 }
1891
1892 /**
1893  * gtk_tree_view_column_get_max_width:
1894  * @tree_column: A #GtkTreeViewColumn.
1895  * 
1896  * Returns the maximum width in pixels of the @tree_column, or -1 if no maximum
1897  * width is set.
1898  * 
1899  * Return value: The maximum width of the @tree_column.
1900  **/
1901 gint
1902 gtk_tree_view_column_get_max_width (GtkTreeViewColumn *tree_column)
1903 {
1904   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), -1);
1905
1906   return tree_column->max_width;
1907 }
1908
1909 /**
1910  * gtk_tree_view_column_clicked:
1911  * @tree_column: a #GtkTreeViewColumn
1912  * 
1913  * Emits the "clicked" signal on the column.  This function will only work if
1914  * @tree_column is clickable.
1915  **/
1916 void
1917 gtk_tree_view_column_clicked (GtkTreeViewColumn *tree_column)
1918 {
1919   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1920
1921   if (tree_column->visible &&
1922       tree_column->button &&
1923       tree_column->clickable)
1924     gtk_button_clicked (GTK_BUTTON (tree_column->button));
1925 }
1926
1927 /**
1928  * gtk_tree_view_column_set_title:
1929  * @tree_column: A #GtkTreeViewColumn.
1930  * @title: The title of the @tree_column.
1931  * 
1932  * Sets the title of the @tree_column.  If a custom widget has been set, then
1933  * this value is ignored.
1934  **/
1935 void
1936 gtk_tree_view_column_set_title (GtkTreeViewColumn *tree_column,
1937                                 const gchar       *title)
1938 {
1939   gchar *new_title;
1940   
1941   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1942
1943   new_title = g_strdup (title);
1944   g_free (tree_column->title);
1945   tree_column->title = new_title;
1946
1947   gtk_tree_view_column_update_button (tree_column);
1948   g_object_notify (G_OBJECT (tree_column), "title");
1949 }
1950
1951 /**
1952  * gtk_tree_view_column_get_title:
1953  * @tree_column: A #GtkTreeViewColumn.
1954  * 
1955  * Returns the title of the widget.
1956  * 
1957  * Return value: the title of the column. This string should not be
1958  * modified or freed.
1959  **/
1960 G_CONST_RETURN gchar *
1961 gtk_tree_view_column_get_title (GtkTreeViewColumn *tree_column)
1962 {
1963   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), NULL);
1964
1965   return tree_column->title;
1966 }
1967
1968 /**
1969  * gtk_tree_view_column_set_expand:
1970  * @tree_column: A #GtkTreeViewColumn
1971  * @expand: %TRUE if the column should take available extra space, %FALSE if not
1972  * 
1973  * Sets the column to take available extra space.  This space is shared equally
1974  * amongst all columns that have the expand set to %TRUE.  If no column has this
1975  * option set, then the last column gets all extra space.  By default, every
1976  * column is created with this %FALSE.
1977  *
1978  * Since: 2.4
1979  **/
1980 void
1981 gtk_tree_view_column_set_expand (GtkTreeViewColumn *tree_column,
1982                                  gboolean           expand)
1983 {
1984   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1985
1986   expand = expand?TRUE:FALSE;
1987   if (tree_column->expand == expand)
1988     return;
1989   tree_column->expand = expand;
1990
1991   if (tree_column->visible &&
1992       tree_column->tree_view != NULL &&
1993       gtk_widget_get_realized (tree_column->tree_view))
1994     {
1995       /* We want to continue using the original width of the
1996        * column that includes additional space added by the user
1997        * resizing the columns and possibly extra (expanded) space, which
1998        * are not included in the resized width.
1999        */
2000       tree_column->use_resized_width = FALSE;
2001
2002       gtk_widget_queue_resize (tree_column->tree_view);
2003     }
2004
2005   g_object_notify (G_OBJECT (tree_column), "expand");
2006 }
2007
2008 /**
2009  * gtk_tree_view_column_get_expand:
2010  * @tree_column: a #GtkTreeViewColumn
2011  * 
2012  * Return %TRUE if the column expands to take any available space.
2013  * 
2014  * Return value: %TRUE, if the column expands
2015  *
2016  * Since: 2.4
2017  **/
2018 gboolean
2019 gtk_tree_view_column_get_expand (GtkTreeViewColumn *tree_column)
2020 {
2021   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
2022
2023   return tree_column->expand;
2024 }
2025
2026 /**
2027  * gtk_tree_view_column_set_clickable:
2028  * @tree_column: A #GtkTreeViewColumn.
2029  * @clickable: %TRUE if the header is active.
2030  * 
2031  * Sets the header to be active if @active is %TRUE.  When the header is active,
2032  * then it can take keyboard focus, and can be clicked.
2033  **/
2034 void
2035 gtk_tree_view_column_set_clickable (GtkTreeViewColumn *tree_column,
2036                                     gboolean           clickable)
2037 {
2038   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2039
2040   clickable = !! clickable;
2041   if (tree_column->clickable == clickable)
2042     return;
2043
2044   tree_column->clickable = clickable;
2045   gtk_tree_view_column_update_button (tree_column);
2046   g_object_notify (G_OBJECT (tree_column), "clickable");
2047 }
2048
2049 /**
2050  * gtk_tree_view_column_get_clickable:
2051  * @tree_column: a #GtkTreeViewColumn
2052  * 
2053  * Returns %TRUE if the user can click on the header for the column.
2054  * 
2055  * Return value: %TRUE if user can click the column header.
2056  **/
2057 gboolean
2058 gtk_tree_view_column_get_clickable (GtkTreeViewColumn *tree_column)
2059 {
2060   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
2061
2062   return tree_column->clickable;
2063 }
2064
2065 /**
2066  * gtk_tree_view_column_set_widget:
2067  * @tree_column: A #GtkTreeViewColumn.
2068  * @widget: (allow-none): A child #GtkWidget, or %NULL.
2069  *
2070  * Sets the widget in the header to be @widget.  If widget is %NULL, then the
2071  * header button is set with a #GtkLabel set to the title of @tree_column.
2072  **/
2073 void
2074 gtk_tree_view_column_set_widget (GtkTreeViewColumn *tree_column,
2075                                  GtkWidget         *widget)
2076 {
2077   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2078   g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
2079
2080   if (widget)
2081     g_object_ref_sink (widget);
2082
2083   if (tree_column->child)      
2084     g_object_unref (tree_column->child);
2085
2086   tree_column->child = widget;
2087   gtk_tree_view_column_update_button (tree_column);
2088   g_object_notify (G_OBJECT (tree_column), "widget");
2089 }
2090
2091 /**
2092  * gtk_tree_view_column_get_widget:
2093  * @tree_column: A #GtkTreeViewColumn.
2094  *
2095  * Returns the #GtkWidget in the button on the column header.
2096  * If a custom widget has not been set then %NULL is returned.
2097  *
2098  * Return value: (transfer none): The #GtkWidget in the column
2099  *     header, or %NULL
2100  **/
2101 GtkWidget *
2102 gtk_tree_view_column_get_widget (GtkTreeViewColumn *tree_column)
2103 {
2104   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), NULL);
2105
2106   return tree_column->child;
2107 }
2108
2109 /**
2110  * gtk_tree_view_column_set_alignment:
2111  * @tree_column: A #GtkTreeViewColumn.
2112  * @xalign: The alignment, which is between [0.0 and 1.0] inclusive.
2113  * 
2114  * Sets the alignment of the title or custom widget inside the column header.
2115  * The alignment determines its location inside the button -- 0.0 for left, 0.5
2116  * for center, 1.0 for right.
2117  **/
2118 void
2119 gtk_tree_view_column_set_alignment (GtkTreeViewColumn *tree_column,
2120                                     gfloat             xalign)
2121 {
2122   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2123
2124   xalign = CLAMP (xalign, 0.0, 1.0);
2125
2126   if (tree_column->xalign == xalign)
2127     return;
2128
2129   tree_column->xalign = xalign;
2130   gtk_tree_view_column_update_button (tree_column);
2131   g_object_notify (G_OBJECT (tree_column), "alignment");
2132 }
2133
2134 /**
2135  * gtk_tree_view_column_get_alignment:
2136  * @tree_column: A #GtkTreeViewColumn.
2137  * 
2138  * Returns the current x alignment of @tree_column.  This value can range
2139  * between 0.0 and 1.0.
2140  * 
2141  * Return value: The current alignent of @tree_column.
2142  **/
2143 gfloat
2144 gtk_tree_view_column_get_alignment (GtkTreeViewColumn *tree_column)
2145 {
2146   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0.5);
2147
2148   return tree_column->xalign;
2149 }
2150
2151 /**
2152  * gtk_tree_view_column_set_reorderable:
2153  * @tree_column: A #GtkTreeViewColumn
2154  * @reorderable: %TRUE, if the column can be reordered.
2155  * 
2156  * If @reorderable is %TRUE, then the column can be reordered by the end user
2157  * dragging the header.
2158  **/
2159 void
2160 gtk_tree_view_column_set_reorderable (GtkTreeViewColumn *tree_column,
2161                                       gboolean           reorderable)
2162 {
2163   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2164
2165   /*  if (reorderable)
2166       gtk_tree_view_column_set_clickable (tree_column, TRUE);*/
2167
2168   if (tree_column->reorderable == (reorderable?TRUE:FALSE))
2169     return;
2170
2171   tree_column->reorderable = (reorderable?TRUE:FALSE);
2172   gtk_tree_view_column_update_button (tree_column);
2173   g_object_notify (G_OBJECT (tree_column), "reorderable");
2174 }
2175
2176 /**
2177  * gtk_tree_view_column_get_reorderable:
2178  * @tree_column: A #GtkTreeViewColumn
2179  * 
2180  * Returns %TRUE if the @tree_column can be reordered by the user.
2181  * 
2182  * Return value: %TRUE if the @tree_column can be reordered by the user.
2183  **/
2184 gboolean
2185 gtk_tree_view_column_get_reorderable (GtkTreeViewColumn *tree_column)
2186 {
2187   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
2188
2189   return tree_column->reorderable;
2190 }
2191
2192
2193 /**
2194  * gtk_tree_view_column_set_sort_column_id:
2195  * @tree_column: a #GtkTreeViewColumn
2196  * @sort_column_id: The @sort_column_id of the model to sort on.
2197  *
2198  * Sets the logical @sort_column_id that this column sorts on when this column 
2199  * is selected for sorting.  Doing so makes the column header clickable.
2200  **/
2201 void
2202 gtk_tree_view_column_set_sort_column_id (GtkTreeViewColumn *tree_column,
2203                                          gint               sort_column_id)
2204 {
2205   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2206   g_return_if_fail (sort_column_id >= -1);
2207
2208   if (tree_column->sort_column_id == sort_column_id)
2209     return;
2210
2211   tree_column->sort_column_id = sort_column_id;
2212
2213   /* Handle unsetting the id */
2214   if (sort_column_id == -1)
2215     {
2216       GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_column->tree_view));
2217
2218       if (tree_column->sort_clicked_signal)
2219         {
2220           g_signal_handler_disconnect (tree_column, tree_column->sort_clicked_signal);
2221           tree_column->sort_clicked_signal = 0;
2222         }
2223
2224       if (tree_column->sort_column_changed_signal)
2225         {
2226           g_signal_handler_disconnect (model, tree_column->sort_column_changed_signal);
2227           tree_column->sort_column_changed_signal = 0;
2228         }
2229
2230       gtk_tree_view_column_set_sort_order (tree_column, GTK_SORT_ASCENDING);
2231       gtk_tree_view_column_set_sort_indicator (tree_column, FALSE);
2232       gtk_tree_view_column_set_clickable (tree_column, FALSE);
2233       g_object_notify (G_OBJECT (tree_column), "sort-column-id");
2234       return;
2235     }
2236
2237   gtk_tree_view_column_set_clickable (tree_column, TRUE);
2238
2239   if (! tree_column->sort_clicked_signal)
2240     tree_column->sort_clicked_signal = g_signal_connect (tree_column,
2241                                                          "clicked",
2242                                                          G_CALLBACK (gtk_tree_view_column_sort),
2243                                                          NULL);
2244
2245   gtk_tree_view_column_setup_sort_column_id_callback (tree_column);
2246   g_object_notify (G_OBJECT (tree_column), "sort-column-id");
2247 }
2248
2249 /**
2250  * gtk_tree_view_column_get_sort_column_id:
2251  * @tree_column: a #GtkTreeViewColumn
2252  *
2253  * Gets the logical @sort_column_id that the model sorts on when this
2254  * column is selected for sorting.
2255  * See gtk_tree_view_column_set_sort_column_id().
2256  *
2257  * Return value: the current @sort_column_id for this column, or -1 if
2258  *               this column can't be used for sorting.
2259  **/
2260 gint
2261 gtk_tree_view_column_get_sort_column_id (GtkTreeViewColumn *tree_column)
2262 {
2263   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);
2264
2265   return tree_column->sort_column_id;
2266 }
2267
2268 /**
2269  * gtk_tree_view_column_set_sort_indicator:
2270  * @tree_column: a #GtkTreeViewColumn
2271  * @setting: %TRUE to display an indicator that the column is sorted
2272  *
2273  * Call this function with a @setting of %TRUE to display an arrow in
2274  * the header button indicating the column is sorted. Call
2275  * gtk_tree_view_column_set_sort_order() to change the direction of
2276  * the arrow.
2277  * 
2278  **/
2279 void
2280 gtk_tree_view_column_set_sort_indicator (GtkTreeViewColumn     *tree_column,
2281                                          gboolean               setting)
2282 {
2283   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2284
2285   setting = setting != FALSE;
2286
2287   if (setting == tree_column->show_sort_indicator)
2288     return;
2289
2290   tree_column->show_sort_indicator = setting;
2291   gtk_tree_view_column_update_button (tree_column);
2292   g_object_notify (G_OBJECT (tree_column), "sort-indicator");
2293 }
2294
2295 /**
2296  * gtk_tree_view_column_get_sort_indicator:
2297  * @tree_column: a #GtkTreeViewColumn
2298  * 
2299  * Gets the value set by gtk_tree_view_column_set_sort_indicator().
2300  * 
2301  * Return value: whether the sort indicator arrow is displayed
2302  **/
2303 gboolean
2304 gtk_tree_view_column_get_sort_indicator  (GtkTreeViewColumn     *tree_column)
2305 {
2306   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
2307
2308   return tree_column->show_sort_indicator;
2309 }
2310
2311 /**
2312  * gtk_tree_view_column_set_sort_order:
2313  * @tree_column: a #GtkTreeViewColumn
2314  * @order: sort order that the sort indicator should indicate
2315  *
2316  * Changes the appearance of the sort indicator. 
2317  * 
2318  * This <emphasis>does not</emphasis> actually sort the model.  Use
2319  * gtk_tree_view_column_set_sort_column_id() if you want automatic sorting
2320  * support.  This function is primarily for custom sorting behavior, and should
2321  * be used in conjunction with gtk_tree_sortable_set_sort_column() to do
2322  * that. For custom models, the mechanism will vary. 
2323  * 
2324  * The sort indicator changes direction to indicate normal sort or reverse sort.
2325  * Note that you must have the sort indicator enabled to see anything when 
2326  * calling this function; see gtk_tree_view_column_set_sort_indicator().
2327  **/
2328 void
2329 gtk_tree_view_column_set_sort_order      (GtkTreeViewColumn     *tree_column,
2330                                           GtkSortType            order)
2331 {
2332   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2333
2334   if (order == tree_column->sort_order)
2335     return;
2336
2337   tree_column->sort_order = order;
2338   gtk_tree_view_column_update_button (tree_column);
2339   g_object_notify (G_OBJECT (tree_column), "sort-order");
2340 }
2341
2342 /**
2343  * gtk_tree_view_column_get_sort_order:
2344  * @tree_column: a #GtkTreeViewColumn
2345  * 
2346  * Gets the value set by gtk_tree_view_column_set_sort_order().
2347  * 
2348  * Return value: the sort order the sort indicator is indicating
2349  **/
2350 GtkSortType
2351 gtk_tree_view_column_get_sort_order      (GtkTreeViewColumn     *tree_column)
2352 {
2353   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);
2354
2355   return tree_column->sort_order;
2356 }
2357
2358 /**
2359  * gtk_tree_view_column_cell_set_cell_data:
2360  * @tree_column: A #GtkTreeViewColumn.
2361  * @tree_model: The #GtkTreeModel to to get the cell renderers attributes from.
2362  * @iter: The #GtkTreeIter to to get the cell renderer's attributes from.
2363  * @is_expander: %TRUE, if the row has children
2364  * @is_expanded: %TRUE, if the row has visible children
2365  * 
2366  * Sets the cell renderer based on the @tree_model and @iter.  That is, for
2367  * every attribute mapping in @tree_column, it will get a value from the set
2368  * column on the @iter, and use that value to set the attribute on the cell
2369  * renderer.  This is used primarily by the #GtkTreeView.
2370  **/
2371 void
2372 gtk_tree_view_column_cell_set_cell_data (GtkTreeViewColumn *tree_column,
2373                                          GtkTreeModel      *tree_model,
2374                                          GtkTreeIter       *iter,
2375                                          gboolean           is_expander,
2376                                          gboolean           is_expanded)
2377 {
2378   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2379
2380   if (tree_model == NULL)
2381     return;
2382
2383   gtk_cell_area_apply_attributes (tree_column->cell_area, tree_model, iter,
2384                                   is_expander, is_expanded);
2385 }
2386
2387 /**
2388  * gtk_tree_view_column_cell_get_size:
2389  * @tree_column: A #GtkTreeViewColumn.
2390  * @cell_area: (allow-none): The area a cell in the column will be allocated, or %NULL
2391  * @x_offset: (allow-none): location to return x offset of a cell relative to @cell_area, or %NULL
2392  * @y_offset: (allow-none): location to return y offset of a cell relative to @cell_area, or %NULL
2393  * @width: (allow-none): location to return width needed to render a cell, or %NULL
2394  * @height: (allow-none): location to return height needed to render a cell, or %NULL
2395  * 
2396  * Obtains the width and height needed to render the column.  This is used
2397  * primarily by the #GtkTreeView.
2398  **/
2399 void
2400 gtk_tree_view_column_cell_get_size (GtkTreeViewColumn  *tree_column,
2401                                     const GdkRectangle *cell_area,
2402                                     gint               *x_offset,
2403                                     gint               *y_offset,
2404                                     gint               *width,
2405                                     gint               *height)
2406 {
2407   int focus_line_width;
2408
2409   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2410
2411   if (height)
2412     * height = 0;
2413   if (width)
2414     * width = 0;
2415
2416   /* FIXME: This is a temporary hack to get things to allocate mostly right.
2417    *
2418    * We will add twice the focus-line-width to the for-width
2419    * parameter below.  If we do not do this, the height returned is the
2420    * height for two lines of text instead of one.  It feels like some lines
2421    * get less width than expected (due to subtraction of focus_line_width?)
2422    * and will unnecessarily wrap.
2423    */
2424   gtk_widget_style_get (tree_column->tree_view,
2425                         "focus-line-width", &focus_line_width,
2426                         NULL);
2427
2428   g_signal_handler_block (tree_column->cell_area_context, 
2429                           tree_column->context_changed_signal);
2430
2431   gtk_cell_area_get_preferred_width (tree_column->cell_area,
2432                                      tree_column->cell_area_context,
2433                                      tree_column->tree_view,
2434                                      width, NULL);
2435   gtk_cell_area_get_preferred_height_for_width (tree_column->cell_area,
2436                                                 tree_column->cell_area_context,
2437                                                 tree_column->tree_view,
2438                                                 *width + focus_line_width * 2,
2439                                                 height,
2440                                                 NULL);
2441
2442   g_signal_handler_unblock (tree_column->cell_area_context, 
2443                             tree_column->context_changed_signal);
2444
2445 }
2446
2447 /**
2448  * gtk_tree_view_column_cell_render:
2449  * @tree_column: A #GtkTreeViewColumn.
2450  * @cr: cairo context to draw to
2451  * @background_area: entire cell area (including tree expanders and maybe padding on the sides)
2452  * @cell_area: area normally rendered by a cell renderer
2453  * @flags: flags that affect rendering
2454  * 
2455  * Renders the cell contained by #tree_column. This is used primarily by the
2456  * #GtkTreeView.
2457  **/
2458 void
2459 _gtk_tree_view_column_cell_render (GtkTreeViewColumn  *tree_column,
2460                                    cairo_t            *cr,
2461                                    const GdkRectangle *background_area,
2462                                    const GdkRectangle *cell_area,
2463                                    guint               flags,
2464                                    gboolean            draw_focus)
2465 {
2466   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2467   g_return_if_fail (cr != NULL);
2468   g_return_if_fail (background_area != NULL);
2469   g_return_if_fail (cell_area != NULL);
2470
2471   cairo_save (cr);
2472
2473   gtk_cell_area_render (tree_column->cell_area, tree_column->cell_area_context,
2474                         tree_column->tree_view, cr,
2475                         background_area, cell_area, flags,
2476                         draw_focus);
2477
2478   cairo_restore (cr);
2479 }
2480
2481 gboolean
2482 _gtk_tree_view_column_cell_event (GtkTreeViewColumn  *tree_column,
2483                                   GtkCellEditable   **editable_widget,
2484                                   GdkEvent           *event,
2485                                   gchar              *path_string,
2486                                   const GdkRectangle *background_area,
2487                                   const GdkRectangle *cell_area,
2488                                   guint               flags)
2489 {
2490   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
2491
2492   /* FIXME: Should we pass background area here as well?
2493    * What will happen to the path_string and editable widget
2494    * variables?
2495    */
2496   return gtk_cell_area_event (tree_column->cell_area,
2497                               tree_column->cell_area_context,
2498                               tree_column->tree_view,
2499                               event,
2500                               cell_area,
2501                               flags);
2502 }
2503
2504 void
2505 _gtk_tree_view_column_get_focus_area (GtkTreeViewColumn  *tree_column,
2506                                       const GdkRectangle *background_area,
2507                                       const GdkRectangle *cell_area,
2508                                       GdkRectangle       *focus_area)
2509 {
2510   /* FIXME */
2511 #if 0
2512   gtk_tree_view_column_cell_process_action (tree_column,
2513                                             NULL,
2514                                             background_area,
2515                                             cell_area,
2516                                             0,
2517                                             CELL_ACTION_FOCUS,
2518                                             focus_area,
2519                                             NULL, NULL, NULL);
2520 #endif
2521 }
2522
2523
2524 gboolean
2525 _gtk_tree_view_column_cell_focus (GtkTreeViewColumn *tree_column,
2526                                   gint               count,
2527                                   gboolean           left,
2528                                   gboolean           right)
2529 {
2530   gboolean rtl;
2531   GtkDirectionType direction = 0;
2532
2533   rtl = gtk_widget_get_direction (GTK_WIDGET (tree_column->tree_view)) == GTK_TEXT_DIR_RTL;
2534
2535   switch (count)
2536     {
2537       case -1:
2538         direction = GTK_DIR_LEFT;
2539         break;
2540
2541       case 1:
2542         direction = GTK_DIR_RIGHT;
2543         break;
2544     }
2545
2546   /* if we are the current focus column and have multiple editable cells,
2547    * try to select the next one, else move the focus to the next column
2548    */
2549   if (GTK_TREE_VIEW (tree_column->tree_view)->priv->focus_column == tree_column)
2550     {
2551       if (gtk_cell_area_focus (tree_column->cell_area, direction))
2552         /* Focus stays in this column, so we are done */
2553         return TRUE;
2554
2555       /* FIXME: RTL support for the following: */
2556       if (count == -1 && !left)
2557         {
2558           direction = GTK_DIR_RIGHT;
2559           gtk_cell_area_focus (tree_column->cell_area, direction);
2560         }
2561       else if (count == 1 && !right)
2562         {
2563           direction = GTK_DIR_LEFT;
2564           gtk_cell_area_focus (tree_column->cell_area, direction);
2565         }
2566
2567       return FALSE;
2568     }
2569
2570   return gtk_cell_area_focus (tree_column->cell_area, direction);
2571 }
2572
2573 /**
2574  * gtk_tree_view_column_cell_is_visible:
2575  * @tree_column: A #GtkTreeViewColumn
2576  * 
2577  * Returns %TRUE if any of the cells packed into the @tree_column are visible.
2578  * For this to be meaningful, you must first initialize the cells with
2579  * gtk_tree_view_column_cell_set_cell_data()
2580  * 
2581  * Return value: %TRUE, if any of the cells packed into the @tree_column are currently visible
2582  **/
2583 gboolean
2584 gtk_tree_view_column_cell_is_visible (GtkTreeViewColumn *tree_column)
2585 {
2586   GList *list;
2587   GList *cells;
2588
2589   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
2590
2591   cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tree_column->cell_area));
2592   for (list = cells; list; list = list->next)
2593     {
2594       if (gtk_cell_renderer_get_visible (list->data))
2595         {
2596           g_list_free (cells);
2597           return TRUE;
2598         }
2599     }
2600
2601   g_list_free (cells);
2602
2603   return FALSE;
2604 }
2605
2606 /**
2607  * gtk_tree_view_column_focus_cell:
2608  * @tree_column: A #GtkTreeViewColumn
2609  * @cell: A #GtkCellRenderer
2610  *
2611  * Sets the current keyboard focus to be at @cell, if the column contains
2612  * 2 or more editable and activatable cells.
2613  *
2614  * Since: 2.2
2615  **/
2616 void
2617 gtk_tree_view_column_focus_cell (GtkTreeViewColumn *tree_column,
2618                                  GtkCellRenderer   *cell)
2619 {
2620   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2621   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
2622
2623   gtk_cell_area_set_focus_cell (tree_column->cell_area, cell);
2624 }
2625
2626 void
2627 _gtk_tree_view_column_cell_set_dirty (GtkTreeViewColumn *tree_column,
2628                                       gboolean           install_handler)
2629 {
2630   tree_column->dirty = TRUE;
2631   tree_column->requested_width = -1;
2632   tree_column->width = 0;
2633
2634   if (tree_column->tree_view &&
2635       gtk_widget_get_realized (tree_column->tree_view))
2636     {
2637       if (install_handler)
2638         _gtk_tree_view_install_mark_rows_col_dirty (GTK_TREE_VIEW (tree_column->tree_view));
2639       else
2640         GTK_TREE_VIEW (tree_column->tree_view)->priv->mark_rows_col_dirty = TRUE;
2641       gtk_widget_queue_resize (tree_column->tree_view);
2642     }
2643 }
2644
2645 /**
2646  * gtk_tree_view_column_cell_get_position:
2647  * @tree_column: a #GtkTreeViewColumn
2648  * @cell_renderer: a #GtkCellRenderer
2649  * @start_pos: return location for the horizontal position of @cell within
2650  *            @tree_column, may be %NULL
2651  * @width: return location for the width of @cell, may be %NULL
2652  *
2653  * Obtains the horizontal position and size of a cell in a column. If the
2654  * cell is not found in the column, @start_pos and @width are not changed and
2655  * %FALSE is returned.
2656  * 
2657  * Return value: %TRUE if @cell belongs to @tree_column.
2658  */
2659 gboolean
2660 gtk_tree_view_column_cell_get_position (GtkTreeViewColumn *tree_column,
2661                                         GtkCellRenderer   *cell_renderer,
2662                                         gint              *start_pos,
2663                                         gint              *width)
2664 {
2665   GdkRectangle zero_cell_area = { 0, };
2666   GdkRectangle allocation;
2667
2668   /* FIXME: Could use a boolean return value for invalid cells */
2669   gtk_cell_area_get_cell_allocation (tree_column->cell_area,
2670                                      tree_column->cell_area_context,
2671                                      tree_column->tree_view,
2672                                      cell_renderer,
2673                                      &zero_cell_area,
2674                                      &allocation);
2675
2676   if (start_pos)
2677     *start_pos = allocation.x;
2678   if (width)
2679     *width = allocation.width;
2680
2681   return TRUE;
2682 }
2683
2684 /**
2685  * gtk_tree_view_column_queue_resize:
2686  * @tree_column: A #GtkTreeViewColumn
2687  *
2688  * Flags the column, and the cell renderers added to this column, to have
2689  * their sizes renegotiated.
2690  *
2691  * Since: 2.8
2692  **/
2693 void
2694 gtk_tree_view_column_queue_resize (GtkTreeViewColumn *tree_column)
2695 {
2696   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2697
2698   if (tree_column->tree_view)
2699     _gtk_tree_view_column_cell_set_dirty (tree_column, TRUE);
2700 }
2701
2702 /**
2703  * gtk_tree_view_column_get_tree_view:
2704  * @tree_column: A #GtkTreeViewColumn
2705  *
2706  * Returns the #GtkTreeView wherein @tree_column has been inserted.
2707  * If @column is currently not inserted in any tree view, %NULL is
2708  * returned.
2709  *
2710  * Return value: (transfer none): The tree view wherein @column has
2711  *     been inserted if any, %NULL otherwise.
2712  *
2713  * Since: 2.12
2714  */
2715 GtkWidget *
2716 gtk_tree_view_column_get_tree_view (GtkTreeViewColumn *tree_column)
2717 {
2718   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), NULL);
2719
2720   return tree_column->tree_view;
2721 }