]> Pileus Git - ~andy/gtk/blob - gtk/gtktreeviewcolumn.c
Document.
[~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 <string.h>
21 #include "gtktreeviewcolumn.h"
22 #include "gtktreeview.h"
23 #include "gtktreeprivate.h"
24 #include "gtkbutton.h"
25 #include "gtkalignment.h"
26 #include "gtklabel.h"
27 #include "gtkhbox.h"
28 #include "gtkmarshalers.h"
29 #include "gtkarrow.h"
30 #include "gtkintl.h"
31
32 enum
33 {
34   PROP_0,
35   PROP_VISIBLE,
36   PROP_RESIZABLE,
37   PROP_WIDTH,
38   PROP_SIZING,
39   PROP_FIXED_WIDTH,
40   PROP_MIN_WIDTH,
41   PROP_MAX_WIDTH,
42   PROP_TITLE,
43   PROP_EXPAND,
44   PROP_CLICKABLE,
45   PROP_WIDGET,
46   PROP_ALIGNMENT,
47   PROP_REORDERABLE,
48   PROP_SORT_INDICATOR,
49   PROP_SORT_ORDER
50 };
51
52 enum
53 {
54   CLICKED,
55   LAST_SIGNAL
56 };
57
58 typedef struct _GtkTreeViewColumnCellInfo GtkTreeViewColumnCellInfo;
59 struct _GtkTreeViewColumnCellInfo
60 {
61   GtkCellRenderer *cell;
62   GSList *attributes;
63   GtkTreeCellDataFunc func;
64   gpointer func_data;
65   GtkDestroyNotify destroy;
66   gint requested_width;
67   gint real_width;
68   guint expand : 1;
69   guint pack : 1;
70   guint has_focus : 1;
71   guint in_editing_mode : 1;
72 };
73
74 /* Type methods */
75 static void gtk_tree_view_column_init                          (GtkTreeViewColumn       *tree_column);
76 static void gtk_tree_view_column_class_init                    (GtkTreeViewColumnClass  *klass);
77
78 /* GObject methods */
79 static void gtk_tree_view_column_set_property                  (GObject                 *object,
80                                                                 guint                    prop_id,
81                                                                 const GValue            *value,
82                                                                 GParamSpec              *pspec);
83 static void gtk_tree_view_column_get_property                  (GObject                 *object,
84                                                                 guint                    prop_id,
85                                                                 GValue                  *value,
86                                                                 GParamSpec              *pspec);
87 static void gtk_tree_view_column_finalize                      (GObject                 *object);
88
89 /* Button handling code */
90 static void gtk_tree_view_column_create_button                 (GtkTreeViewColumn       *tree_column);
91 static void gtk_tree_view_column_update_button                 (GtkTreeViewColumn       *tree_column);
92
93 /* Button signal handlers */
94 static gint gtk_tree_view_column_button_event                  (GtkWidget               *widget,
95                                                                 GdkEvent                *event,
96                                                                 gpointer                 data);
97 static void gtk_tree_view_column_button_clicked                (GtkWidget               *widget,
98                                                                 gpointer                 data);
99 static gboolean gtk_tree_view_column_mnemonic_activate         (GtkWidget *widget,
100                                                                 gboolean   group_cycling,
101                                                                 gpointer   data);
102
103 /* Property handlers */
104 static void gtk_tree_view_model_sort_column_changed            (GtkTreeSortable         *sortable,
105                                                                 GtkTreeViewColumn       *tree_column);
106
107 /* Internal functions */
108 static void gtk_tree_view_column_sort                          (GtkTreeViewColumn       *tree_column,
109                                                                 gpointer                 data);
110 static void gtk_tree_view_column_setup_sort_column_id_callback (GtkTreeViewColumn       *tree_column);
111 static void gtk_tree_view_column_set_attributesv               (GtkTreeViewColumn       *tree_column,
112                                                                 GtkCellRenderer         *cell_renderer,
113                                                                 va_list                  args);
114 static GtkTreeViewColumnCellInfo *gtk_tree_view_column_get_cell_info (GtkTreeViewColumn *tree_column,
115                                                                       GtkCellRenderer   *cell_renderer);
116
117 /* cell list manipulation */
118 static GList *gtk_tree_view_column_cell_first                  (GtkTreeViewColumn      *tree_column);
119 static GList *gtk_tree_view_column_cell_last                   (GtkTreeViewColumn      *tree_column);
120 static GList *gtk_tree_view_column_cell_next                   (GtkTreeViewColumn      *tree_column,
121                                                                 GList                  *current);
122 static GList *gtk_tree_view_column_cell_prev                   (GtkTreeViewColumn      *tree_column,
123                                                                 GList                  *current);
124 static void gtk_tree_view_column_clear_attributes_by_info      (GtkTreeViewColumn      *tree_column,
125                                                                 GtkTreeViewColumnCellInfo *info);
126
127 static GtkObjectClass *parent_class = NULL;
128 static guint tree_column_signals[LAST_SIGNAL] = { 0 };
129
130
131 GType
132 gtk_tree_view_column_get_type (void)
133 {
134   static GType tree_column_type = 0;
135
136   if (!tree_column_type)
137     {
138       static const GTypeInfo tree_column_info =
139       {
140         sizeof (GtkTreeViewColumnClass),
141         NULL,           /* base_init */
142         NULL,           /* base_finalize */
143         (GClassInitFunc) gtk_tree_view_column_class_init,
144         NULL,           /* class_finalize */
145         NULL,           /* class_data */
146         sizeof (GtkTreeViewColumn),
147         0,
148         (GInstanceInitFunc) gtk_tree_view_column_init,
149       };
150
151       tree_column_type =
152         g_type_register_static (GTK_TYPE_OBJECT, "GtkTreeViewColumn",
153                                 &tree_column_info, 0);
154     }
155
156   return tree_column_type;
157 }
158
159 static void
160 gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class)
161 {
162   GObjectClass *object_class;
163
164   object_class = (GObjectClass*) class;
165
166   parent_class = g_type_class_peek_parent (class);
167
168   class->clicked = NULL;
169
170   object_class->finalize = gtk_tree_view_column_finalize;
171   object_class->set_property = gtk_tree_view_column_set_property;
172   object_class->get_property = gtk_tree_view_column_get_property;
173   
174   tree_column_signals[CLICKED] =
175     g_signal_new ("clicked",
176                   G_OBJECT_CLASS_TYPE (object_class),
177                   G_SIGNAL_RUN_LAST,
178                   G_STRUCT_OFFSET (GtkTreeViewColumnClass, clicked),
179                   NULL, NULL,
180                   _gtk_marshal_VOID__VOID,
181                   G_TYPE_NONE, 0);
182
183   g_object_class_install_property (object_class,
184                                    PROP_VISIBLE,
185                                    g_param_spec_boolean ("visible",
186                                                         _("Visible"),
187                                                         _("Whether to display the column"),
188                                                          TRUE,
189                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
190   
191   g_object_class_install_property (object_class,
192                                    PROP_RESIZABLE,
193                                    g_param_spec_boolean ("resizable",
194                                                          _("Resizable"),
195                                                          _("Column is user-resizable"),
196                                                          FALSE,
197                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
198   
199   g_object_class_install_property (object_class,
200                                    PROP_WIDTH,
201                                    g_param_spec_int ("width",
202                                                      _("Width"),
203                                                      _("Current width of the column"),
204                                                      0,
205                                                      G_MAXINT,
206                                                      0,
207                                                      G_PARAM_READABLE));
208   g_object_class_install_property (object_class,
209                                    PROP_SIZING,
210                                    g_param_spec_enum ("sizing",
211                                                       _("Sizing"),
212                                                       _("Resize mode of the column"),
213                                                       GTK_TYPE_TREE_VIEW_COLUMN_SIZING,
214                                                       GTK_TREE_VIEW_COLUMN_AUTOSIZE,
215                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
216   
217   g_object_class_install_property (object_class,
218                                    PROP_FIXED_WIDTH,
219                                    g_param_spec_int ("fixed_width",
220                                                      _("Fixed Width"),
221                                                      _("Current fixed width of the column"),
222                                                      1,
223                                                      G_MAXINT,
224                                                      1, /* not useful */
225                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
226
227   g_object_class_install_property (object_class,
228                                    PROP_MIN_WIDTH,
229                                    g_param_spec_int ("min_width",
230                                                      _("Minimum Width"),
231                                                      _("Minimum allowed width of the column"),
232                                                      -1,
233                                                      G_MAXINT,
234                                                      -1,
235                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
236
237   g_object_class_install_property (object_class,
238                                    PROP_MAX_WIDTH,
239                                    g_param_spec_int ("max_width",
240                                                      _("Maximum Width"),
241                                                      _("Maximum allowed width of the column"),
242                                                      -1,
243                                                      G_MAXINT,
244                                                      -1,
245                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
246
247   g_object_class_install_property (object_class,
248                                    PROP_TITLE,
249                                    g_param_spec_string ("title",
250                                                         _("Title"),
251                                                         _("Title to appear in column header"),
252                                                         "",
253                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));
254   
255   g_object_class_install_property (object_class,
256                                    PROP_EXPAND,
257                                    g_param_spec_boolean ("expand",
258                                                          _("Expand"),
259                                                          _("Column gets share of extra width allocated to the widget"),
260                                                          FALSE,
261                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
262   
263   g_object_class_install_property (object_class,
264                                    PROP_CLICKABLE,
265                                    g_param_spec_boolean ("clickable",
266                                                         _("Clickable"),
267                                                         _("Whether the header can be clicked"),
268                                                          TRUE,
269                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
270   
271
272   g_object_class_install_property (object_class,
273                                    PROP_WIDGET,
274                                    g_param_spec_object ("widget",
275                                                         _("Widget"),
276                                                         _("Widget to put in column header button instead of column title"),
277                                                         GTK_TYPE_WIDGET,
278                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));
279
280   g_object_class_install_property (object_class,
281                                    PROP_ALIGNMENT,
282                                    g_param_spec_float ("alignment",
283                                                        _("Alignment"),
284                                                        _("X Alignment of the column header text or widget"),
285                                                        0.0,
286                                                        1.0,
287                                                        0.5,
288                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
289
290   g_object_class_install_property (object_class,
291                                    PROP_REORDERABLE,
292                                    g_param_spec_boolean ("reorderable",
293                                                          _("Reorderable"),
294                                                          _("Whether the column can be reordered around the headers"),
295                                                          FALSE,
296                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
297
298   g_object_class_install_property (object_class,
299                                    PROP_SORT_INDICATOR,
300                                    g_param_spec_boolean ("sort_indicator",
301                                                         _("Sort indicator"),
302                                                         _("Whether to show a sort indicator"),
303                                                          FALSE,
304                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
305
306   g_object_class_install_property (object_class,
307                                    PROP_SORT_ORDER,
308                                    g_param_spec_enum ("sort_order",
309                                                       _("Sort order"),
310                                                       _("Sort direction the sort indicator should indicate"),
311                                                       GTK_TYPE_SORT_TYPE,
312                                                       GTK_SORT_ASCENDING,
313                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
314   
315 }
316
317 static void
318 gtk_tree_view_column_init (GtkTreeViewColumn *tree_column)
319 {
320   tree_column->button = NULL;
321   tree_column->xalign = 0.0;
322   tree_column->width = 0;
323   tree_column->requested_width = -1;
324   tree_column->min_width = -1;
325   tree_column->max_width = -1;
326   tree_column->resized_width = 0;
327   tree_column->column_type = GTK_TREE_VIEW_COLUMN_GROW_ONLY;
328   tree_column->visible = TRUE;
329   tree_column->resizable = FALSE;
330   tree_column->clickable = FALSE;
331   tree_column->dirty = TRUE;
332   tree_column->sort_order = GTK_SORT_ASCENDING;
333   tree_column->show_sort_indicator = FALSE;
334   tree_column->property_changed_signal = 0;
335   tree_column->sort_clicked_signal = 0;
336   tree_column->sort_column_changed_signal = 0;
337   tree_column->sort_column_id = -1;
338   tree_column->reorderable = FALSE;
339   tree_column->maybe_reordered = FALSE;
340   tree_column->use_resized_width = FALSE;
341 }
342
343 static void
344 gtk_tree_view_column_finalize (GObject *object)
345 {
346   GtkTreeViewColumn *tree_column = (GtkTreeViewColumn *) object;
347   GList *list;
348
349   for (list = tree_column->cell_list; list; list = list->next)
350     {
351       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
352
353       if (info->destroy)
354         {
355           GtkDestroyNotify d = info->destroy;
356
357           info->destroy = NULL;
358           d (info->func_data);
359         }
360       gtk_tree_view_column_clear_attributes_by_info (tree_column, info);
361       g_object_unref (info->cell);
362       g_free (info);
363     }
364
365   g_free (tree_column->title);
366   g_list_free (tree_column->cell_list);
367
368   if (tree_column->child)
369     g_object_unref (tree_column->child);
370
371   G_OBJECT_CLASS (parent_class)->finalize (object);
372 }
373
374 static void
375 gtk_tree_view_column_set_property (GObject         *object,
376                                    guint            prop_id,
377                                    const GValue    *value,
378                                    GParamSpec      *pspec)
379 {
380   GtkTreeViewColumn *tree_column;
381
382   tree_column = GTK_TREE_VIEW_COLUMN (object);
383
384   switch (prop_id)
385     {
386     case PROP_VISIBLE:
387       gtk_tree_view_column_set_visible (tree_column,
388                                         g_value_get_boolean (value));
389       break;
390
391     case PROP_RESIZABLE:
392       gtk_tree_view_column_set_resizable (tree_column,
393                                           g_value_get_boolean (value));
394       break;
395
396     case PROP_SIZING:
397       gtk_tree_view_column_set_sizing (tree_column,
398                                        g_value_get_enum (value));
399       break;
400
401     case PROP_FIXED_WIDTH:
402       gtk_tree_view_column_set_fixed_width (tree_column,
403                                             g_value_get_int (value));
404       break;
405
406     case PROP_MIN_WIDTH:
407       gtk_tree_view_column_set_min_width (tree_column,
408                                           g_value_get_int (value));
409       break;
410
411     case PROP_MAX_WIDTH:
412       gtk_tree_view_column_set_max_width (tree_column,
413                                           g_value_get_int (value));
414       break;
415
416     case PROP_TITLE:
417       gtk_tree_view_column_set_title (tree_column,
418                                       g_value_get_string (value));
419       break;
420
421     case PROP_EXPAND:
422       gtk_tree_view_column_set_expand (tree_column,
423                                        g_value_get_boolean (value));
424       break;
425
426     case PROP_CLICKABLE:
427       gtk_tree_view_column_set_clickable (tree_column,
428                                           g_value_get_boolean (value));
429       break;
430
431     case PROP_WIDGET:
432       gtk_tree_view_column_set_widget (tree_column,
433                                        (GtkWidget*) g_value_get_object (value));
434       break;
435
436     case PROP_ALIGNMENT:
437       gtk_tree_view_column_set_alignment (tree_column,
438                                           g_value_get_float (value));
439       break;
440
441     case PROP_REORDERABLE:
442       gtk_tree_view_column_set_reorderable (tree_column,
443                                             g_value_get_boolean (value));
444       break;
445
446     case PROP_SORT_INDICATOR:
447       gtk_tree_view_column_set_sort_indicator (tree_column,
448                                                g_value_get_boolean (value));
449       break;
450
451     case PROP_SORT_ORDER:
452       gtk_tree_view_column_set_sort_order (tree_column,
453                                            g_value_get_enum (value));
454       break;
455       
456     default:
457       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
458       break;
459     }
460 }
461
462 static void
463 gtk_tree_view_column_get_property (GObject         *object,
464                                    guint            prop_id,
465                                    GValue          *value,
466                                    GParamSpec      *pspec)
467 {
468   GtkTreeViewColumn *tree_column;
469
470   tree_column = GTK_TREE_VIEW_COLUMN (object);
471
472   switch (prop_id)
473     {
474     case PROP_VISIBLE:
475       g_value_set_boolean (value,
476                            gtk_tree_view_column_get_visible (tree_column));
477       break;
478
479     case PROP_RESIZABLE:
480       g_value_set_boolean (value,
481                            gtk_tree_view_column_get_resizable (tree_column));
482       break;
483
484     case PROP_WIDTH:
485       g_value_set_int (value,
486                        gtk_tree_view_column_get_width (tree_column));
487       break;
488
489     case PROP_SIZING:
490       g_value_set_enum (value,
491                         gtk_tree_view_column_get_sizing (tree_column));
492       break;
493
494     case PROP_FIXED_WIDTH:
495       g_value_set_int (value,
496                        gtk_tree_view_column_get_fixed_width (tree_column));
497       break;
498
499     case PROP_MIN_WIDTH:
500       g_value_set_int (value,
501                        gtk_tree_view_column_get_min_width (tree_column));
502       break;
503
504     case PROP_MAX_WIDTH:
505       g_value_set_int (value,
506                        gtk_tree_view_column_get_max_width (tree_column));
507       break;
508
509     case PROP_TITLE:
510       g_value_set_string (value,
511                           gtk_tree_view_column_get_title (tree_column));
512       break;
513
514     case PROP_EXPAND:
515       g_value_set_boolean (value,
516                           gtk_tree_view_column_get_expand (tree_column));
517       break;
518
519     case PROP_CLICKABLE:
520       g_value_set_boolean (value,
521                            gtk_tree_view_column_get_clickable (tree_column));
522       break;
523
524     case PROP_WIDGET:
525       g_value_set_object (value,
526                           (GObject*) gtk_tree_view_column_get_widget (tree_column));
527       break;
528
529     case PROP_ALIGNMENT:
530       g_value_set_float (value,
531                          gtk_tree_view_column_get_alignment (tree_column));
532       break;
533
534     case PROP_REORDERABLE:
535       g_value_set_boolean (value,
536                            gtk_tree_view_column_get_reorderable (tree_column));
537       break;
538
539     case PROP_SORT_INDICATOR:
540       g_value_set_boolean (value,
541                            gtk_tree_view_column_get_sort_indicator (tree_column));
542       break;
543
544     case PROP_SORT_ORDER:
545       g_value_set_enum (value,
546                         gtk_tree_view_column_get_sort_order (tree_column));
547       break;
548       
549     default:
550       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
551       break;
552     }
553 }
554
555 /* Helper functions
556  */
557
558 /* Button handling code
559  */
560 static void
561 gtk_tree_view_column_create_button (GtkTreeViewColumn *tree_column)
562 {
563   GtkTreeView *tree_view;
564   GtkWidget *child;
565   GtkWidget *hbox;
566
567   tree_view = (GtkTreeView *) tree_column->tree_view;
568
569   g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
570   g_return_if_fail (tree_column->button == NULL);
571
572   gtk_widget_push_composite_child ();
573   tree_column->button = gtk_button_new ();
574   gtk_widget_add_events (tree_column->button, GDK_POINTER_MOTION_MASK);
575   gtk_widget_pop_composite_child ();
576
577   /* make sure we own a reference to it as well. */
578   if (tree_view->priv->header_window)
579     gtk_widget_set_parent_window (tree_column->button, tree_view->priv->header_window);
580   gtk_widget_set_parent (tree_column->button, GTK_WIDGET (tree_view));
581
582   g_signal_connect (tree_column->button, "event",
583                     G_CALLBACK (gtk_tree_view_column_button_event),
584                     tree_column);
585   g_signal_connect (tree_column->button, "clicked",
586                     G_CALLBACK (gtk_tree_view_column_button_clicked),
587                     tree_column);
588
589   tree_column->alignment = gtk_alignment_new (tree_column->xalign, 0.5, 0.0, 0.0);
590
591   hbox = gtk_hbox_new (FALSE, 2);
592   tree_column->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN);
593
594   if (tree_column->child)
595     child = tree_column->child;
596   else
597     {
598       child = gtk_label_new (tree_column->title);
599       gtk_widget_show (child);
600     }
601
602   g_signal_connect (child, "mnemonic_activate",
603                     G_CALLBACK (gtk_tree_view_column_mnemonic_activate),
604                     tree_column);
605
606   if (tree_column->xalign <= 0.5)
607     gtk_box_pack_end (GTK_BOX (hbox), tree_column->arrow, FALSE, FALSE, 0);
608   else
609     gtk_box_pack_start (GTK_BOX (hbox), tree_column->arrow, FALSE, FALSE, 0);
610
611   gtk_box_pack_start (GTK_BOX (hbox), tree_column->alignment, TRUE, TRUE, 0);
612         
613   gtk_container_add (GTK_CONTAINER (tree_column->alignment), child);
614   gtk_container_add (GTK_CONTAINER (tree_column->button), hbox);
615
616   gtk_widget_show (hbox);
617   gtk_widget_show (tree_column->alignment);
618   gtk_tree_view_column_update_button (tree_column);
619 }
620
621 static void 
622 gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column)
623 {
624   GtkWidget *hbox;
625   GtkWidget *alignment;
626   GtkWidget *arrow;
627   GtkWidget *current_child;
628
629   /* Create a button if necessary */
630   if (tree_column->visible &&
631       tree_column->button == NULL &&
632       tree_column->tree_view &&
633       GTK_WIDGET_REALIZED (tree_column->tree_view))
634     gtk_tree_view_column_create_button (tree_column);
635   
636   if (! tree_column->button)
637     return;
638
639   hbox = GTK_BIN (tree_column->button)->child;
640   alignment = tree_column->alignment;
641   arrow = tree_column->arrow;
642   current_child = GTK_BIN (alignment)->child;
643
644   /* Set up the actual button */
645   gtk_alignment_set (GTK_ALIGNMENT (alignment), tree_column->xalign,
646                      0.5, 0.0, 0.0);
647       
648   if (tree_column->child)
649     {
650       if (current_child != tree_column->child)
651         {
652           gtk_container_remove (GTK_CONTAINER (alignment),
653                                 current_child);
654           gtk_container_add (GTK_CONTAINER (alignment),
655                              tree_column->child);
656         }
657     }
658   else 
659     {
660       if (current_child == NULL)
661         {
662           current_child = gtk_label_new (NULL);
663           gtk_widget_show (current_child);
664           gtk_container_add (GTK_CONTAINER (alignment),
665                              current_child);
666         }
667
668       g_return_if_fail (GTK_IS_LABEL (current_child));
669
670       if (tree_column->title)
671         gtk_label_set_text_with_mnemonic (GTK_LABEL (current_child),
672                                           tree_column->title);
673       else
674         gtk_label_set_text_with_mnemonic (GTK_LABEL (current_child),
675                                           "");
676     }
677
678   switch (tree_column->sort_order)
679     {
680     case GTK_SORT_ASCENDING:
681       gtk_arrow_set (GTK_ARROW (arrow),
682                      GTK_ARROW_DOWN,
683                      GTK_SHADOW_IN);
684       break;
685
686     case GTK_SORT_DESCENDING:
687       gtk_arrow_set (GTK_ARROW (arrow),
688                      GTK_ARROW_UP,
689                      GTK_SHADOW_IN);
690       break;
691           
692     default:
693       g_warning (G_STRLOC": bad sort order");
694       break;
695     }
696
697   /* Put arrow on the right if the text is left-or-center justified, and on the
698    * left otherwise; do this by packing boxes, so flipping text direction will
699    * reverse things
700    */
701   g_object_ref (arrow);
702   gtk_container_remove (GTK_CONTAINER (hbox), arrow);
703
704   if (tree_column->xalign <= 0.5)
705     {
706       gtk_box_pack_end (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
707     }
708   else
709     {
710       gtk_box_pack_start (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
711       /* move it to the front */
712       gtk_box_reorder_child (GTK_BOX (hbox), arrow, 0);
713     }
714   g_object_unref (arrow);
715
716   if (tree_column->show_sort_indicator)
717     gtk_widget_show (arrow);
718   else
719     gtk_widget_hide (arrow);
720
721   /* It's always safe to hide the button.  It isn't always safe to show it, as
722    * if you show it before it's realized, it'll get the wrong window. */
723   if (tree_column->button &&
724       tree_column->tree_view != NULL &&
725       GTK_WIDGET_REALIZED (tree_column->tree_view))
726     {
727       if (tree_column->visible)
728         {
729           gtk_widget_show_now (tree_column->button);
730           if (tree_column->window)
731             {
732               if (tree_column->resizable)
733                 {
734                   gdk_window_show (tree_column->window);
735                   gdk_window_raise (tree_column->window);
736                 }
737               else
738                 {
739                   gdk_window_hide (tree_column->window);
740                 }
741             }
742         }
743       else
744         {
745           gtk_widget_hide (tree_column->button);
746           if (tree_column->window)
747             gdk_window_hide (tree_column->window);
748         }
749     }
750   
751   if (tree_column->reorderable || tree_column->clickable)
752     {
753       GTK_WIDGET_SET_FLAGS (tree_column->button, GTK_CAN_FOCUS);
754     }
755   else
756     {
757       GTK_WIDGET_UNSET_FLAGS (tree_column->button, GTK_CAN_FOCUS);
758       if (GTK_WIDGET_HAS_FOCUS (tree_column->button))
759         {
760           GtkWidget *toplevel = gtk_widget_get_toplevel (tree_column->tree_view);
761           if (GTK_WIDGET_TOPLEVEL (toplevel))
762             {
763               gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
764             }
765         }
766     }
767   /* Queue a resize on the assumption that we always want to catch all changes
768    * and columns don't change all that often.
769    */
770   if (GTK_WIDGET_REALIZED (tree_column->tree_view))
771      gtk_widget_queue_resize (tree_column->tree_view);
772
773 }
774
775 /* Button signal handlers
776  */
777
778 static gint
779 gtk_tree_view_column_button_event (GtkWidget *widget,
780                                    GdkEvent  *event,
781                                    gpointer   data)
782 {
783   GtkTreeViewColumn *column = (GtkTreeViewColumn *) data;
784
785   g_return_val_if_fail (event != NULL, FALSE);
786
787   if (event->type == GDK_BUTTON_PRESS &&
788       column->reorderable)
789     {
790       column->maybe_reordered = TRUE;
791       gdk_window_get_pointer (widget->window,
792                               &column->drag_x,
793                               &column->drag_y,
794                               NULL);
795       gtk_widget_grab_focus (widget);
796     }
797
798   if (event->type == GDK_BUTTON_RELEASE &&
799       column->maybe_reordered)
800     column->maybe_reordered = FALSE;
801
802   if (event->type == GDK_MOTION_NOTIFY &&
803       (column->maybe_reordered) &&
804       (gtk_drag_check_threshold (widget,
805                                  column->drag_x,
806                                  column->drag_y,
807                                  (gint) ((GdkEventMotion *)event)->x,
808                                  (gint) ((GdkEventMotion *)event)->y)))
809     {
810       column->maybe_reordered = FALSE;
811       /* this is to change our drag_x to be relative to
812        * tree_view->priv->bin_window, instead of our window.
813        */
814       column->drag_x -= column->button->allocation.x;
815       _gtk_tree_view_column_start_drag (GTK_TREE_VIEW (column->tree_view), column);
816       return TRUE;
817     }
818   if (column->clickable == FALSE)
819     {
820       switch (event->type)
821         {
822         case GDK_BUTTON_PRESS:
823         case GDK_2BUTTON_PRESS:
824         case GDK_3BUTTON_PRESS:
825         case GDK_MOTION_NOTIFY:
826         case GDK_BUTTON_RELEASE:
827         case GDK_ENTER_NOTIFY:
828         case GDK_LEAVE_NOTIFY:
829           return TRUE;
830         default:
831           return FALSE;
832         }
833     }
834   return FALSE;
835 }
836
837
838 static void
839 gtk_tree_view_column_button_clicked (GtkWidget *widget, gpointer data)
840 {
841   g_signal_emit_by_name (data, "clicked");
842 }
843
844 static gboolean
845 gtk_tree_view_column_mnemonic_activate (GtkWidget *widget,
846                                         gboolean   group_cycling,
847                                         gpointer   data)
848 {
849   GtkTreeViewColumn *column = (GtkTreeViewColumn *)data;
850
851   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (column), FALSE);
852
853   GTK_TREE_VIEW (column->tree_view)->priv->focus_column = column;
854   if (column->clickable)
855     gtk_button_clicked (GTK_BUTTON (column->button));
856   else if (GTK_WIDGET_CAN_FOCUS (column->button))
857     gtk_widget_grab_focus (column->button);
858   else
859     gtk_widget_grab_focus (column->tree_view);
860
861   return TRUE;
862 }
863
864 static void
865 gtk_tree_view_model_sort_column_changed (GtkTreeSortable   *sortable,
866                                          GtkTreeViewColumn *column)
867 {
868   gint sort_column_id;
869   GtkSortType order;
870
871   if (gtk_tree_sortable_get_sort_column_id (sortable,
872                                             &sort_column_id,
873                                             &order))
874     {
875       if (sort_column_id == column->sort_column_id)
876         {
877           gtk_tree_view_column_set_sort_indicator (column, TRUE);
878           gtk_tree_view_column_set_sort_order (column, order);
879         }
880       else
881         {
882           gtk_tree_view_column_set_sort_indicator (column, FALSE);
883         }
884     }
885   else
886     {
887       gtk_tree_view_column_set_sort_indicator (column, FALSE);
888     }
889 }
890
891 static void
892 gtk_tree_view_column_sort (GtkTreeViewColumn *tree_column,
893                            gpointer           data)
894 {
895   gint sort_column_id;
896   GtkSortType order;
897   gboolean has_sort_column;
898   gboolean has_default_sort_func;
899
900   g_return_if_fail (tree_column->tree_view != NULL);
901
902   has_sort_column =
903     gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (GTK_TREE_VIEW (tree_column->tree_view)->priv->model),
904                                           &sort_column_id,
905                                           &order);
906   has_default_sort_func =
907     gtk_tree_sortable_has_default_sort_func (GTK_TREE_SORTABLE (GTK_TREE_VIEW (tree_column->tree_view)->priv->model));
908
909   if (has_sort_column &&
910       sort_column_id == tree_column->sort_column_id)
911     {
912       if (order == GTK_SORT_ASCENDING)
913         gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GTK_TREE_VIEW (tree_column->tree_view)->priv->model),
914                                               tree_column->sort_column_id,
915                                               GTK_SORT_DESCENDING);
916       else if (order == GTK_SORT_DESCENDING && has_default_sort_func)
917         gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GTK_TREE_VIEW (tree_column->tree_view)->priv->model),
918                                               GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
919                                               GTK_SORT_ASCENDING);
920       else
921         gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GTK_TREE_VIEW (tree_column->tree_view)->priv->model),
922                                               tree_column->sort_column_id,
923                                               GTK_SORT_ASCENDING);
924     }
925   else
926     {
927       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GTK_TREE_VIEW (tree_column->tree_view)->priv->model),
928                                             tree_column->sort_column_id,
929                                             GTK_SORT_ASCENDING);
930     }
931 }
932
933
934 static void
935 gtk_tree_view_column_setup_sort_column_id_callback (GtkTreeViewColumn *tree_column)
936 {
937   GtkTreeModel *model;
938
939   if (tree_column->tree_view == NULL)
940     return;
941
942   model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_column->tree_view));
943
944   if (model == NULL)
945     return;
946
947   if (GTK_IS_TREE_SORTABLE (model) &&
948       tree_column->sort_column_id != -1)
949     {
950       gint real_sort_column_id;
951       GtkSortType real_order;
952
953       if (tree_column->sort_column_changed_signal == 0)
954         tree_column->sort_column_changed_signal =
955           g_signal_connect (model, "sort_column_changed",
956                             G_CALLBACK (gtk_tree_view_model_sort_column_changed),
957                             tree_column);
958       
959       if (gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model),
960                                                 &real_sort_column_id,
961                                                 &real_order) &&
962           (real_sort_column_id == tree_column->sort_column_id))
963         {
964           gtk_tree_view_column_set_sort_indicator (tree_column, TRUE);
965           gtk_tree_view_column_set_sort_order (tree_column, real_order);
966
967           return;
968         }
969     }
970 }
971
972
973 /* Exported Private Functions.
974  * These should only be called by gtktreeview.c or gtktreeviewcolumn.c
975  */
976
977 void
978 _gtk_tree_view_column_realize_button (GtkTreeViewColumn *column)
979 {
980   GtkTreeView *tree_view;
981   GdkWindowAttr attr;
982   guint attributes_mask;
983
984   tree_view = (GtkTreeView *)column->tree_view;
985
986   g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
987   g_return_if_fail (GTK_WIDGET_REALIZED (tree_view));
988   g_return_if_fail (tree_view->priv->header_window != NULL);
989   g_return_if_fail (column->button != NULL);
990
991   gtk_widget_set_parent_window (column->button, tree_view->priv->header_window);
992
993   if (column->visible)
994     gtk_widget_show (column->button);
995
996   attr.window_type = GDK_WINDOW_CHILD;
997   attr.wclass = GDK_INPUT_ONLY;
998   attr.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
999   attr.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
1000   attr.event_mask = gtk_widget_get_events (GTK_WIDGET (tree_view));
1001   attr.event_mask = (GDK_BUTTON_PRESS_MASK |
1002                      GDK_BUTTON_RELEASE_MASK |
1003                      GDK_POINTER_MOTION_MASK |
1004                      GDK_POINTER_MOTION_HINT_MASK |
1005                      GDK_KEY_PRESS_MASK);
1006   attributes_mask = GDK_WA_CURSOR | GDK_WA_X | GDK_WA_Y;
1007   attr.cursor = gdk_cursor_new_for_display (gdk_drawable_get_display (tree_view->priv->header_window),
1008                                             GDK_SB_H_DOUBLE_ARROW);
1009   attr.y = 0;
1010   attr.width = TREE_VIEW_DRAG_WIDTH;
1011   attr.height = tree_view->priv->header_height;
1012
1013   attr.x = (column->button->allocation.x + column->button->allocation.width) - 3;
1014           
1015   column->window = gdk_window_new (tree_view->priv->header_window,
1016                                    &attr, attributes_mask);
1017   gdk_window_set_user_data (column->window, tree_view);
1018
1019   gtk_tree_view_column_update_button (column);
1020
1021   gdk_cursor_unref (attr.cursor);
1022 }
1023
1024 void
1025 _gtk_tree_view_column_unrealize_button (GtkTreeViewColumn *column)
1026 {
1027   g_return_if_fail (column != NULL);
1028   g_return_if_fail (column->window != NULL);
1029
1030   gdk_window_set_user_data (column->window, NULL);
1031   gdk_window_destroy (column->window);
1032   column->window = NULL;
1033 }
1034
1035 void
1036 _gtk_tree_view_column_unset_model (GtkTreeViewColumn *column,
1037                                    GtkTreeModel      *old_model)
1038 {
1039   if (column->sort_column_changed_signal)
1040     {
1041       g_signal_handler_disconnect (old_model,
1042                                    column->sort_column_changed_signal);
1043       column->sort_column_changed_signal = 0;
1044     }
1045 }
1046
1047 void
1048 _gtk_tree_view_column_set_tree_view (GtkTreeViewColumn *column,
1049                                      GtkTreeView       *tree_view)
1050 {
1051   g_assert (column->tree_view == NULL);
1052
1053   column->tree_view = GTK_WIDGET (tree_view);
1054   gtk_tree_view_column_create_button (column);
1055
1056   column->property_changed_signal =
1057           g_signal_connect_swapped (tree_view,
1058                                     "notify::model",
1059                                     G_CALLBACK (gtk_tree_view_column_setup_sort_column_id_callback),
1060                                     column);
1061
1062   gtk_tree_view_column_setup_sort_column_id_callback (column);
1063 }
1064
1065 void
1066 _gtk_tree_view_column_unset_tree_view (GtkTreeViewColumn *column)
1067 {
1068   if (column->tree_view && column->button)
1069     {
1070       gtk_container_remove (GTK_CONTAINER (column->tree_view), column->button);
1071     }
1072   if (column->property_changed_signal)
1073     {
1074       g_signal_handler_disconnect (column->tree_view, column->property_changed_signal);
1075       column->property_changed_signal = 0;
1076     }
1077
1078   if (column->sort_column_changed_signal)
1079     {
1080       g_signal_handler_disconnect (gtk_tree_view_get_model (GTK_TREE_VIEW (column->tree_view)),
1081                                    column->sort_column_changed_signal);
1082       column->sort_column_changed_signal = 0;
1083     }
1084
1085   column->tree_view = NULL;
1086   column->button = NULL;
1087 }
1088
1089 gboolean
1090 _gtk_tree_view_column_has_editable_cell (GtkTreeViewColumn *column)
1091 {
1092   GList *list;
1093
1094   for (list = column->cell_list; list; list = list->next)
1095     if (((GtkTreeViewColumnCellInfo *)list->data)->cell->mode ==
1096         GTK_CELL_RENDERER_MODE_EDITABLE)
1097       return TRUE;
1098
1099   return FALSE;
1100 }
1101
1102 /* gets cell being edited */
1103 GtkCellRenderer *
1104 _gtk_tree_view_column_get_edited_cell (GtkTreeViewColumn *column)
1105 {
1106   GList *list;
1107
1108   for (list = column->cell_list; list; list = list->next)
1109     if (((GtkTreeViewColumnCellInfo *)list->data)->in_editing_mode)
1110       return ((GtkTreeViewColumnCellInfo *)list->data)->cell;
1111
1112   return NULL;
1113 }
1114
1115 gint
1116 _gtk_tree_view_column_count_special_cells (GtkTreeViewColumn *column)
1117 {
1118   gint i = 0;
1119   GList *list;
1120
1121   for (list = column->cell_list; list; list = list->next)
1122     {
1123       GtkTreeViewColumnCellInfo *cellinfo = list->data;
1124
1125       if ((cellinfo->cell->mode == GTK_CELL_RENDERER_MODE_EDITABLE ||
1126           cellinfo->cell->mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE) &&
1127           cellinfo->cell->visible)
1128         i++;
1129     }
1130
1131   return i;
1132 }
1133
1134 GtkCellRenderer *
1135 _gtk_tree_view_column_get_cell_at_pos (GtkTreeViewColumn *column,
1136                                        gint               x)
1137 {
1138   GList *list;
1139   gint current_x = 0;
1140
1141   list = gtk_tree_view_column_cell_first (column);
1142   for (; list; list = gtk_tree_view_column_cell_next (column, list))
1143    {
1144      GtkTreeViewColumnCellInfo *cellinfo = list->data;
1145      if (current_x <= x && x <= current_x + cellinfo->real_width)
1146        return cellinfo->cell;
1147      current_x += cellinfo->real_width;
1148    }
1149
1150   return NULL;
1151 }
1152
1153 /* Public Functions */
1154
1155
1156 /**
1157  * gtk_tree_view_column_new:
1158  * 
1159  * Creates a new #GtkTreeViewColumn.
1160  * 
1161  * Return value: A newly created #GtkTreeViewColumn.
1162  **/
1163 GtkTreeViewColumn *
1164 gtk_tree_view_column_new (void)
1165 {
1166   GtkTreeViewColumn *tree_column;
1167
1168   tree_column = g_object_new (GTK_TYPE_TREE_VIEW_COLUMN, NULL);
1169
1170   return tree_column;
1171 }
1172
1173 /**
1174  * gtk_tree_view_column_new_with_attributes:
1175  * @title: The title to set the header to.
1176  * @cell: The #GtkCellRenderer.
1177  * @Varargs: A %NULL-terminated list of attributes.
1178  * 
1179  * Creates a new #GtkTreeViewColumn with a number of default values.  This is
1180  * equivalent to calling gtk_tree_view_column_set_title(),
1181  * gtk_tree_view_column_pack_start(), and
1182  * gtk_tree_view_column_set_attributes() on the newly created #GtkTreeViewColumn.
1183  *
1184  * Here's a simple example:
1185  * <informalexample><programlisting>
1186  *  enum { TEXT_COLUMN, COLOR_COLUMN, N_COLUMNS };
1187  *  ...
1188  *  {
1189  *    GtkTreeViewColumn *column;
1190  *    GtkCellRenderer   *renderer = gtk_cell_renderer_text_new (<!-- -->);
1191  *  
1192  *    column = gtk_tree_view_column_new_with_attributes ("Title",
1193  *                                                       renderer,
1194  *                                                       "text", TEXT_COLUMN,
1195  *                                                       "foreground", COLOR_COLUMN,
1196  *                                                       NULL);
1197  *  }
1198  * </programlisting></informalexample>
1199  * 
1200  * Return value: A newly created #GtkTreeViewColumn.
1201  **/
1202 GtkTreeViewColumn *
1203 gtk_tree_view_column_new_with_attributes (const gchar     *title,
1204                                           GtkCellRenderer *cell,
1205                                           ...)
1206 {
1207   GtkTreeViewColumn *retval;
1208   va_list args;
1209
1210   retval = gtk_tree_view_column_new ();
1211
1212   gtk_tree_view_column_set_title (retval, title);
1213   gtk_tree_view_column_pack_start (retval, cell, TRUE);
1214
1215   va_start (args, cell);
1216   gtk_tree_view_column_set_attributesv (retval, cell, args);
1217   va_end (args);
1218
1219   return retval;
1220 }
1221
1222 static GtkTreeViewColumnCellInfo *
1223 gtk_tree_view_column_get_cell_info (GtkTreeViewColumn *tree_column,
1224                                     GtkCellRenderer   *cell_renderer)
1225 {
1226   GList *list;
1227   for (list = tree_column->cell_list; list; list = list->next)
1228     if (((GtkTreeViewColumnCellInfo *)list->data)->cell == cell_renderer)
1229       return (GtkTreeViewColumnCellInfo *) list->data;
1230   return NULL;
1231 }
1232
1233
1234 /**
1235  * gtk_tree_view_column_pack_start:
1236  * @tree_column: A #GtkTreeViewColumn.
1237  * @cell: The #GtkCellRenderer. 
1238  * @expand: %TRUE if @cell is to be given extra space allocated to box.
1239  *
1240  * Packs the @cell into the beginning of the column. If @expand is FALSE, then
1241  * the @cell is allocated no more space than it needs. Any unused space is divided
1242  * evenly between cells for which @expand is TRUE.
1243  **/
1244 void
1245 gtk_tree_view_column_pack_start (GtkTreeViewColumn *tree_column,
1246                                  GtkCellRenderer   *cell,
1247                                  gboolean           expand)
1248 {
1249   GtkTreeViewColumnCellInfo *cell_info;
1250
1251   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1252   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1253   g_return_if_fail (! gtk_tree_view_column_get_cell_info (tree_column, cell));
1254
1255   g_object_ref (cell);
1256   gtk_object_sink (GTK_OBJECT (cell));
1257
1258   cell_info = g_new0 (GtkTreeViewColumnCellInfo, 1);
1259   cell_info->cell = cell;
1260   cell_info->expand = expand ? TRUE : FALSE;
1261   cell_info->pack = GTK_PACK_START;
1262   cell_info->has_focus = 0;
1263   cell_info->attributes = NULL;
1264
1265   tree_column->cell_list = g_list_append (tree_column->cell_list, cell_info);
1266 }
1267
1268 /**
1269  * gtk_tree_view_column_pack_end:
1270  * @tree_column: A #GtkTreeViewColumn.
1271  * @cell: The #GtkCellRenderer. 
1272  * @expand: %TRUE if @cell is to be given extra space allocated to box.
1273  *
1274  * Adds the @cell to end of the column. If @expand is FALSE, then the @cell
1275  * is allocated no more space than it needs. Any unused space is divided
1276  * evenly between cells for which @expand is TRUE.
1277  **/
1278 void
1279 gtk_tree_view_column_pack_end (GtkTreeViewColumn  *tree_column,
1280                                GtkCellRenderer    *cell,
1281                                gboolean            expand)
1282 {
1283   GtkTreeViewColumnCellInfo *cell_info;
1284
1285   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1286   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1287   g_return_if_fail (! gtk_tree_view_column_get_cell_info (tree_column, cell));
1288
1289   g_object_ref (cell);
1290   gtk_object_sink (GTK_OBJECT (cell));
1291
1292   cell_info = g_new0 (GtkTreeViewColumnCellInfo, 1);
1293   cell_info->cell = cell;
1294   cell_info->expand = expand ? TRUE : FALSE;
1295   cell_info->pack = GTK_PACK_END;
1296   cell_info->has_focus = 0;
1297   cell_info->attributes = NULL;
1298
1299   tree_column->cell_list = g_list_append (tree_column->cell_list, cell_info);
1300 }
1301
1302
1303 /**
1304  * gtk_tree_view_column_clear:
1305  * @tree_column: A #GtkTreeViewColumn
1306  * 
1307  * Unsets all the mappings on all renderers on the @tree_column.
1308  **/
1309 void
1310 gtk_tree_view_column_clear (GtkTreeViewColumn *tree_column)
1311 {
1312   GList *list;
1313   g_return_if_fail (tree_column != NULL);
1314
1315   for (list = tree_column->cell_list; list; list = list->next)
1316     {
1317       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *)list->data;
1318
1319       gtk_tree_view_column_clear_attributes (tree_column, info->cell);
1320       g_object_unref (info->cell);
1321       g_free (info);
1322     }
1323
1324   g_list_free (tree_column->cell_list);
1325   tree_column->cell_list = NULL;
1326 }
1327
1328 /**
1329  * gtk_tree_view_column_get_cell_renderers:
1330  * @tree_column: A #GtkTreeViewColumn
1331  * 
1332  * Returns a newly-allocated #GList of all the cell renderers in the column, 
1333  * in no particular order.  The list must be freed with g_list_free().
1334  * 
1335  * Return value: A list of #GtkCellRenderers
1336  **/
1337 GList *
1338 gtk_tree_view_column_get_cell_renderers (GtkTreeViewColumn *tree_column)
1339 {
1340   GList *retval = NULL, *list;
1341
1342   g_return_val_if_fail (tree_column != NULL, NULL);
1343
1344   for (list = tree_column->cell_list; list; list = list->next)
1345     {
1346       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *)list->data;
1347
1348       retval = g_list_append (retval, info->cell);
1349     }
1350
1351   return retval;
1352 }
1353
1354 /**
1355  * gtk_tree_view_column_add_attribute:
1356  * @tree_column: A #GtkTreeViewColumn.
1357  * @cell_renderer: the #GtkCellRenderer to set attributes on
1358  * @attribute: An attribute on the renderer
1359  * @column: The column position on the model to get the attribute from.
1360  * 
1361  * Adds an attribute mapping to the list in @tree_column.  The @column is the
1362  * column of the model to get a value from, and the @attribute is the
1363  * parameter on @cell_renderer to be set from the value. So for example
1364  * if column 2 of the model contains strings, you could have the
1365  * "text" attribute of a #GtkCellRendererText get its values from
1366  * column 2.
1367  **/
1368 void
1369 gtk_tree_view_column_add_attribute (GtkTreeViewColumn *tree_column,
1370                                     GtkCellRenderer   *cell_renderer,
1371                                     const gchar       *attribute,
1372                                     gint               column)
1373 {
1374   GtkTreeViewColumnCellInfo *info;
1375
1376   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1377   info = gtk_tree_view_column_get_cell_info (tree_column, cell_renderer);
1378   g_return_if_fail (info != NULL);
1379
1380   info->attributes = g_slist_prepend (info->attributes, GINT_TO_POINTER (column));
1381   info->attributes = g_slist_prepend (info->attributes, g_strdup (attribute));
1382
1383   if (tree_column->tree_view)
1384     _gtk_tree_view_column_cell_set_dirty (tree_column, TRUE);
1385
1386 }
1387
1388 static void
1389 gtk_tree_view_column_set_attributesv (GtkTreeViewColumn *tree_column,
1390                                       GtkCellRenderer   *cell_renderer,
1391                                       va_list            args)
1392 {
1393   gchar *attribute;
1394   gint column;
1395
1396   attribute = va_arg (args, gchar *);
1397
1398   gtk_tree_view_column_clear_attributes (tree_column, cell_renderer);
1399   
1400   while (attribute != NULL)
1401     {
1402       column = va_arg (args, gint);
1403       gtk_tree_view_column_add_attribute (tree_column, cell_renderer, attribute, column);
1404       attribute = va_arg (args, gchar *);
1405     }
1406 }
1407
1408 /**
1409  * gtk_tree_view_column_set_attributes:
1410  * @tree_column: A #GtkTreeViewColumn.
1411  * @cell_renderer: the #GtkCellRenderer we're setting the attributes of
1412  * @Varargs: A %NULL-terminated list of attributes.
1413  * 
1414  * Sets the attributes in the list as the attributes of @tree_column.
1415  * The attributes should be in attribute/column order, as in
1416  * gtk_tree_view_column_add_attribute(). All existing attributes
1417  * are removed, and replaced with the new attributes.
1418  **/
1419 void
1420 gtk_tree_view_column_set_attributes (GtkTreeViewColumn *tree_column,
1421                                      GtkCellRenderer   *cell_renderer,
1422                                      ...)
1423 {
1424   va_list args;
1425
1426   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1427   g_return_if_fail (GTK_IS_CELL_RENDERER (cell_renderer));
1428   g_return_if_fail (gtk_tree_view_column_get_cell_info (tree_column, cell_renderer));
1429
1430   va_start (args, cell_renderer);
1431   gtk_tree_view_column_set_attributesv (tree_column, cell_renderer, args);
1432   va_end (args);
1433 }
1434
1435
1436 /**
1437  * gtk_tree_view_column_set_cell_data_func:
1438  * @tree_column: A #GtkTreeViewColumn
1439  * @cell_renderer: A #GtkCellRenderer
1440  * @func: The #GtkTreeViewColumnFunc to use. 
1441  * @func_data: The user data for @func.
1442  * @destroy: The destroy notification for @func_data
1443  * 
1444  * Sets the #GtkTreeViewColumnFunc to use for the column.  This
1445  * function is used instead of the standard attributes mapping for
1446  * setting the column value, and should set the value of @tree_column's
1447  * cell renderer as appropriate.  @func may be %NULL to remove an
1448  * older one.
1449  **/
1450 void
1451 gtk_tree_view_column_set_cell_data_func (GtkTreeViewColumn   *tree_column,
1452                                          GtkCellRenderer     *cell_renderer,
1453                                          GtkTreeCellDataFunc  func,
1454                                          gpointer             func_data,
1455                                          GtkDestroyNotify     destroy)
1456 {
1457   GtkTreeViewColumnCellInfo *info;
1458
1459   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1460   g_return_if_fail (GTK_IS_CELL_RENDERER (cell_renderer));
1461   info = gtk_tree_view_column_get_cell_info (tree_column, cell_renderer);
1462
1463   g_return_if_fail (info != NULL);
1464
1465   if (info->destroy)
1466     {
1467       GtkDestroyNotify d = info->destroy;
1468
1469       info->destroy = NULL;
1470       d (info->func_data);
1471     }
1472
1473   info->func = func;
1474   info->func_data = func_data;
1475   info->destroy = destroy;
1476
1477   if (tree_column->tree_view)
1478     _gtk_tree_view_column_cell_set_dirty (tree_column, TRUE);
1479 }
1480
1481
1482 /**
1483  * gtk_tree_view_column_clear_attributes:
1484  * @tree_column: a #GtkTreeViewColumn
1485  * @cell_renderer: a #GtkCellRenderer to clear the attribute mapping on.
1486  * 
1487  * Clears all existing attributes previously set with
1488  * gtk_tree_view_column_set_attributes().
1489  **/
1490 void
1491 gtk_tree_view_column_clear_attributes (GtkTreeViewColumn *tree_column,
1492                                        GtkCellRenderer   *cell_renderer)
1493 {
1494   GtkTreeViewColumnCellInfo *info;
1495
1496   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1497   g_return_if_fail (GTK_IS_CELL_RENDERER (cell_renderer));
1498
1499   info = gtk_tree_view_column_get_cell_info (tree_column, cell_renderer);
1500
1501   gtk_tree_view_column_clear_attributes_by_info (tree_column, info);
1502 }
1503
1504 static void 
1505 gtk_tree_view_column_clear_attributes_by_info (GtkTreeViewColumn *tree_column,
1506                                                GtkTreeViewColumnCellInfo *info)
1507 {
1508   GSList *list;
1509
1510   list = info->attributes;
1511
1512   while (list && list->next)
1513     {
1514       g_free (list->data);
1515       list = list->next->next;
1516     }
1517   g_slist_free (info->attributes);
1518   info->attributes = NULL;
1519
1520   if (tree_column->tree_view)
1521     _gtk_tree_view_column_cell_set_dirty (tree_column, TRUE);
1522 }
1523
1524
1525 /**
1526  * gtk_tree_view_column_set_spacing:
1527  * @tree_column: A #GtkTreeViewColumn.
1528  * @spacing: distance between cell renderers in pixels.
1529  * 
1530  * Sets the spacing field of @tree_column, which is the number of pixels to
1531  * place between cell renderers packed into it.
1532  **/
1533 void
1534 gtk_tree_view_column_set_spacing (GtkTreeViewColumn *tree_column,
1535                                   gint               spacing)
1536 {
1537   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1538   g_return_if_fail (spacing >= 0);
1539
1540   if (tree_column->spacing == spacing)
1541     return;
1542
1543   tree_column->spacing = spacing;
1544   if (tree_column->tree_view)
1545     _gtk_tree_view_column_cell_set_dirty (tree_column, TRUE);
1546 }
1547
1548 /**
1549  * gtk_tree_view_column_get_spacing:
1550  * @tree_column: A #GtkTreeViewColumn.
1551  * 
1552  * Returns the spacing of @tree_column.
1553  * 
1554  * Return value: the spacing of @tree_column.
1555  **/
1556 gint
1557 gtk_tree_view_column_get_spacing (GtkTreeViewColumn *tree_column)
1558 {
1559   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);
1560
1561   return tree_column->spacing;
1562 }
1563
1564 /* Options for manipulating the columns */
1565
1566 /**
1567  * gtk_tree_view_column_set_visible:
1568  * @tree_column: A #GtkTreeViewColumn.
1569  * @visible: %TRUE if the @tree_column is visible.
1570  * 
1571  * Sets the visibility of @tree_column.
1572  **/
1573 void
1574 gtk_tree_view_column_set_visible (GtkTreeViewColumn *tree_column,
1575                                   gboolean           visible)
1576 {
1577   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1578
1579   visible = !! visible;
1580   
1581   if (tree_column->visible == visible)
1582     return;
1583
1584   tree_column->visible = visible;
1585
1586   if (tree_column->visible)
1587     _gtk_tree_view_column_cell_set_dirty (tree_column, TRUE);
1588
1589   gtk_tree_view_column_update_button (tree_column);
1590   g_object_notify (G_OBJECT (tree_column), "visible");
1591 }
1592
1593 /**
1594  * gtk_tree_view_column_get_visible:
1595  * @tree_column: A #GtkTreeViewColumn.
1596  * 
1597  * Returns %TRUE if @tree_column is visible.
1598  * 
1599  * Return value: whether the column is visible or not.  If it is visible, then
1600  * the tree will show the column.
1601  **/
1602 gboolean
1603 gtk_tree_view_column_get_visible (GtkTreeViewColumn *tree_column)
1604 {
1605   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
1606
1607   return tree_column->visible;
1608 }
1609
1610 /**
1611  * gtk_tree_view_column_set_resizable:
1612  * @tree_column: A #GtkTreeViewColumn
1613  * @resizable: %TRUE, if the column can be resized
1614  * 
1615  * If @resizable is %TRUE, then the user can explicitly resize the column by
1616  * grabbing the outer edge of the column button.  If resizable is TRUE and
1617  * sizing mode of the column is #GTK_TREE_VIEW_COLUMN_AUTOSIZE, then the sizing
1618  * mode is changed to #GTK_TREE_VIEW_COLUMN_GROW_ONLY.
1619  **/
1620 void
1621 gtk_tree_view_column_set_resizable (GtkTreeViewColumn *tree_column,
1622                                     gboolean           resizable)
1623 {
1624   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1625
1626   resizable = !! resizable;
1627
1628   if (tree_column->resizable == resizable)
1629     return;
1630
1631   tree_column->resizable = resizable;
1632
1633   if (resizable && tree_column->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE)
1634     gtk_tree_view_column_set_sizing (tree_column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
1635
1636   gtk_tree_view_column_update_button (tree_column);
1637
1638   g_object_notify (G_OBJECT (tree_column), "resizable");
1639 }
1640
1641 /**
1642  * gtk_tree_view_column_get_resizable:
1643  * @tree_column: A #GtkTreeViewColumn
1644  * 
1645  * Returns %TRUE if the @tree_column can be resized by the end user.
1646  * 
1647  * Return value: %TRUE, if the @tree_column can be resized.
1648  **/
1649 gboolean
1650 gtk_tree_view_column_get_resizable (GtkTreeViewColumn *tree_column)
1651 {
1652   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
1653
1654   return tree_column->resizable;
1655 }
1656
1657
1658 /**
1659  * gtk_tree_view_column_set_sizing:
1660  * @tree_column: A #GtkTreeViewColumn.
1661  * @type: The #GtkTreeViewColumnSizing.
1662  * 
1663  * Sets the growth behavior of @tree_column to @type.
1664  **/
1665 void
1666 gtk_tree_view_column_set_sizing (GtkTreeViewColumn       *tree_column,
1667                                  GtkTreeViewColumnSizing  type)
1668 {
1669   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1670
1671   if (type == tree_column->column_type)
1672     return;
1673
1674   if (type == GTK_TREE_VIEW_COLUMN_AUTOSIZE)
1675     gtk_tree_view_column_set_resizable (tree_column, FALSE);
1676
1677 #if 0
1678   /* I was clearly on crack when I wrote this.  I'm not sure what's supposed to
1679    * be below so I'll leave it until I figure it out.
1680    */
1681   if (tree_column->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE &&
1682       tree_column->requested_width != -1)
1683     {
1684       gtk_tree_view_column_set_sizing (tree_column, tree_column->requested_width);
1685     }
1686 #endif
1687   tree_column->column_type = type;
1688
1689   gtk_tree_view_column_update_button (tree_column);
1690
1691   g_object_notify (G_OBJECT (tree_column), "sizing");
1692 }
1693
1694 /**
1695  * gtk_tree_view_column_get_sizing:
1696  * @tree_column: A #GtkTreeViewColumn.
1697  * 
1698  * Returns the current type of @tree_column.
1699  * 
1700  * Return value: The type of @tree_column.
1701  **/
1702 GtkTreeViewColumnSizing
1703 gtk_tree_view_column_get_sizing (GtkTreeViewColumn *tree_column)
1704 {
1705   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);
1706
1707   return tree_column->column_type;
1708 }
1709
1710 /**
1711  * gtk_tree_view_column_get_width:
1712  * @tree_column: A #GtkTreeViewColumn.
1713  * 
1714  * Returns the current size of @tree_column in pixels.
1715  * 
1716  * Return value: The current width of @tree_column.
1717  **/
1718 gint
1719 gtk_tree_view_column_get_width (GtkTreeViewColumn *tree_column)
1720 {
1721   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);
1722
1723   return tree_column->width;
1724 }
1725
1726 /**
1727  * gtk_tree_view_column_set_fixed_width:
1728  * @tree_column: A #GtkTreeViewColumn.
1729  * @fixed_width: The size to set @tree_column to. Must be greater than 0.
1730  * 
1731  * Sets the size of the column in pixels.  This is meaningful only if the sizing
1732  * type is #GTK_TREE_VIEW_COLUMN_FIXED.  The size of the column is clamped to
1733  * the min/max width for the column.  Please note that the min/max width of the
1734  * column doesn't actually affect the "fixed_width" property of the widget, just
1735  * the actual size when displayed.
1736  **/
1737 void
1738 gtk_tree_view_column_set_fixed_width (GtkTreeViewColumn *tree_column,
1739                                       gint               fixed_width)
1740 {
1741   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1742   g_return_if_fail (fixed_width > 0);
1743
1744   tree_column->fixed_width = fixed_width;
1745
1746   if (tree_column->tree_view &&
1747       GTK_WIDGET_REALIZED (tree_column->tree_view) &&
1748       tree_column->column_type == GTK_TREE_VIEW_COLUMN_FIXED)
1749     {
1750       gtk_widget_queue_resize (tree_column->tree_view);
1751     }
1752
1753   g_object_notify (G_OBJECT (tree_column), "fixed_width");
1754 }
1755
1756 /**
1757  * gtk_tree_view_column_get_fixed_width:
1758  * @tree_column: a #GtkTreeViewColumn
1759  * 
1760  * Gets the fixed width of the column.  This value is only meaning may not be
1761  * the actual width of the column on the screen, just what is requested.
1762  * 
1763  * Return value: the fixed width of the column
1764  **/
1765 gint
1766 gtk_tree_view_column_get_fixed_width (GtkTreeViewColumn *tree_column)
1767 {
1768   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);
1769
1770   return tree_column->fixed_width;
1771 }
1772
1773 /**
1774  * gtk_tree_view_column_set_min_width:
1775  * @tree_column: A #GtkTreeViewColumn.
1776  * @min_width: The minimum width of the column in pixels, or -1.
1777  * 
1778  * Sets the minimum width of the @tree_column.  If @min_width is -1, then the
1779  * minimum width is unset.
1780  **/
1781 void
1782 gtk_tree_view_column_set_min_width (GtkTreeViewColumn *tree_column,
1783                                     gint               min_width)
1784 {
1785   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1786   g_return_if_fail (min_width >= -1);
1787
1788   if (min_width == tree_column->min_width)
1789     return;
1790
1791   if (tree_column->visible &&
1792       tree_column->tree_view != NULL &&
1793       GTK_WIDGET_REALIZED (tree_column->tree_view))
1794     {
1795       if (min_width > tree_column->width)
1796         gtk_widget_queue_resize (tree_column->tree_view);
1797     }
1798
1799   tree_column->min_width = min_width;
1800   g_object_freeze_notify (G_OBJECT (tree_column));
1801   if (tree_column->max_width != -1 && tree_column->max_width < min_width)
1802     {
1803       tree_column->max_width = min_width;
1804       g_object_notify (G_OBJECT (tree_column), "max_width");
1805     }
1806   g_object_notify (G_OBJECT (tree_column), "min_width");
1807   g_object_thaw_notify (G_OBJECT (tree_column));
1808
1809   if (tree_column->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE)
1810     _gtk_tree_view_column_autosize (GTK_TREE_VIEW (tree_column->tree_view),
1811                                     tree_column);
1812 }
1813
1814 /**
1815  * gtk_tree_view_column_get_min_width:
1816  * @tree_column: A #GtkTreeViewColumn.
1817  * 
1818  * Returns the minimum width in pixels of the @tree_column, or -1 if no minimum
1819  * width is set.
1820  * 
1821  * Return value: The minimum width of the @tree_column.
1822  **/
1823 gint
1824 gtk_tree_view_column_get_min_width (GtkTreeViewColumn *tree_column)
1825 {
1826   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), -1);
1827
1828   return tree_column->min_width;
1829 }
1830
1831 /**
1832  * gtk_tree_view_column_set_max_width:
1833  * @tree_column: A #GtkTreeViewColumn.
1834  * @max_width: The maximum width of the column in pixels, or -1.
1835  * 
1836  * Sets the maximum width of the @tree_column.  If @max_width is -1, then the
1837  * maximum width is unset.  Note, the column can actually be wider than max
1838  * width if it's the last column in a view.  In this case, the column expands to
1839  * fill any extra space.
1840  **/
1841 void
1842 gtk_tree_view_column_set_max_width (GtkTreeViewColumn *tree_column,
1843                                     gint               max_width)
1844 {
1845   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1846   g_return_if_fail (max_width >= -1);
1847
1848   if (max_width == tree_column->max_width)
1849     return;
1850
1851   if (tree_column->visible &&
1852       tree_column->tree_view != NULL &&
1853       GTK_WIDGET_REALIZED (tree_column->tree_view))
1854     {
1855       if (max_width != -1 && max_width < tree_column->width)
1856         gtk_widget_queue_resize (tree_column->tree_view);
1857     }
1858
1859   tree_column->max_width = max_width;
1860   g_object_freeze_notify (G_OBJECT (tree_column));
1861   if (max_width != -1 && max_width < tree_column->min_width)
1862     {
1863       tree_column->min_width = max_width;
1864       g_object_notify (G_OBJECT (tree_column), "min_width");
1865     }
1866   g_object_notify (G_OBJECT (tree_column), "max_width");
1867   g_object_thaw_notify (G_OBJECT (tree_column));
1868
1869   if (tree_column->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE)
1870     _gtk_tree_view_column_autosize (GTK_TREE_VIEW (tree_column->tree_view),
1871                                     tree_column);
1872 }
1873
1874 /**
1875  * gtk_tree_view_column_get_max_width:
1876  * @tree_column: A #GtkTreeViewColumn.
1877  * 
1878  * Returns the maximum width in pixels of the @tree_column, or -1 if no maximum
1879  * width is set.
1880  * 
1881  * Return value: The maximum width of the @tree_column.
1882  **/
1883 gint
1884 gtk_tree_view_column_get_max_width (GtkTreeViewColumn *tree_column)
1885 {
1886   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), -1);
1887
1888   return tree_column->max_width;
1889 }
1890
1891 /**
1892  * gtk_tree_view_column_clicked:
1893  * @tree_column: a #GtkTreeViewColumn
1894  * 
1895  * Emits the "clicked" signal on the column.  This function will only work if
1896  * @tree_column is clickable.
1897  **/
1898 void
1899 gtk_tree_view_column_clicked (GtkTreeViewColumn *tree_column)
1900 {
1901   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1902
1903   if (tree_column->visible &&
1904       tree_column->button &&
1905       tree_column->clickable)
1906     gtk_button_clicked (GTK_BUTTON (tree_column->button));
1907 }
1908
1909 /**
1910  * gtk_tree_view_column_set_title:
1911  * @tree_column: A #GtkTreeViewColumn.
1912  * @title: The title of the @tree_column.
1913  * 
1914  * Sets the title of the @tree_column.  If a custom widget has been set, then
1915  * this value is ignored.
1916  **/
1917 void
1918 gtk_tree_view_column_set_title (GtkTreeViewColumn *tree_column,
1919                                 const gchar       *title)
1920 {
1921   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1922
1923   g_free (tree_column->title);
1924   if (title)
1925     tree_column->title = g_strdup (title);
1926   else
1927     tree_column->title = NULL;
1928
1929   gtk_tree_view_column_update_button (tree_column);
1930   g_object_notify (G_OBJECT (tree_column), "title");
1931 }
1932
1933 /**
1934  * gtk_tree_view_column_get_title:
1935  * @tree_column: A #GtkTreeViewColumn.
1936  * 
1937  * Returns the title of the widget.
1938  * 
1939  * Return value: the title of the column. This string should not be
1940  * modified or freed.
1941  **/
1942 G_CONST_RETURN gchar *
1943 gtk_tree_view_column_get_title (GtkTreeViewColumn *tree_column)
1944 {
1945   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), NULL);
1946
1947   return tree_column->title;
1948 }
1949
1950 /**
1951  * gtk_tree_view_column_set_expand:
1952  * @tree_column: A #GtkTreeViewColumn
1953  * @expand: 
1954  * 
1955  * Sets the column to take available extra space.  This space is shared equally
1956  * amongst all columns that have the expand set to %TRUE.  If no column has this
1957  * option set, then the last column gets all extra space.  By default, every
1958  * column is created with this %FALSE.
1959  *
1960  * Since: 2.4
1961  **/
1962 void
1963 gtk_tree_view_column_set_expand (GtkTreeViewColumn *tree_column,
1964                                  gboolean           expand)
1965 {
1966   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1967
1968   expand = expand?TRUE:FALSE;
1969   if (tree_column->expand == expand)
1970     return;
1971   tree_column->expand = expand;
1972
1973   if (tree_column->visible &&
1974       tree_column->tree_view != NULL &&
1975       GTK_WIDGET_REALIZED (tree_column->tree_view))
1976     {
1977       gtk_widget_queue_resize (tree_column->tree_view);
1978     }
1979
1980   g_object_notify (G_OBJECT (tree_column), "expand");
1981 }
1982
1983 /**
1984  * gtk_tree_view_column_get_expand:
1985  * @tree_column: 
1986  * 
1987  * Return %TRUE if the column expands to take any available space.
1988  * 
1989  * Return value: %TRUE, if the column expands
1990  *
1991  * Since: 2.4
1992  **/
1993 gboolean
1994 gtk_tree_view_column_get_expand (GtkTreeViewColumn *tree_column)
1995 {
1996   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
1997
1998   return tree_column->expand;
1999 }
2000
2001 /**
2002  * gtk_tree_view_column_set_clickable:
2003  * @tree_column: A #GtkTreeViewColumn.
2004  * @clickable: %TRUE if the header is active.
2005  * 
2006  * Sets the header to be active if @active is %TRUE.  When the header is active,
2007  * then it can take keyboard focus, and can be clicked.
2008  **/
2009 void
2010 gtk_tree_view_column_set_clickable (GtkTreeViewColumn *tree_column,
2011                                     gboolean           clickable)
2012 {
2013   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2014
2015   clickable = !! clickable;
2016   if (tree_column->clickable == clickable)
2017     return;
2018
2019   tree_column->clickable = clickable;
2020   gtk_tree_view_column_update_button (tree_column);
2021   g_object_notify (G_OBJECT (tree_column), "clickable");
2022 }
2023
2024 /**
2025  * gtk_tree_view_column_get_clickable:
2026  * @tree_column: a #GtkTreeViewColumn
2027  * 
2028  * Returns %TRUE if the user can click on the header for the column.
2029  * 
2030  * Return value: %TRUE if user can click the column header.
2031  **/
2032 gboolean
2033 gtk_tree_view_column_get_clickable (GtkTreeViewColumn *tree_column)
2034 {
2035   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
2036
2037   return tree_column->clickable;
2038 }
2039
2040 /**
2041  * gtk_tree_view_column_set_widget:
2042  * @tree_column: A #GtkTreeViewColumn.
2043  * @widget: A child #GtkWidget, or %NULL.
2044  * 
2045  * Sets the widget in the header to be @widget.  If widget is %NULL, then the
2046  * header button is set with a #GtkLabel set to the title of @tree_column.
2047  **/
2048 void
2049 gtk_tree_view_column_set_widget (GtkTreeViewColumn *tree_column,
2050                                  GtkWidget         *widget)
2051 {
2052   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2053   g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
2054
2055   if (widget)
2056     {
2057       g_object_ref (widget);
2058       gtk_object_sink (GTK_OBJECT (widget));
2059     }
2060
2061   if (tree_column->child)      
2062     g_object_unref (tree_column->child);
2063
2064   tree_column->child = widget;
2065   gtk_tree_view_column_update_button (tree_column);
2066   g_object_notify (G_OBJECT (tree_column), "widget");
2067 }
2068
2069 /**
2070  * gtk_tree_view_column_get_widget:
2071  * @tree_column: A #GtkTreeViewColumn.
2072  * 
2073  * Returns the #GtkWidget in the button on the column header.  If a custom
2074  * widget has not been set then %NULL is returned.
2075  * 
2076  * Return value: The #GtkWidget in the column header, or %NULL
2077  **/
2078 GtkWidget *
2079 gtk_tree_view_column_get_widget (GtkTreeViewColumn *tree_column)
2080 {
2081   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), NULL);
2082
2083   return tree_column->child;
2084 }
2085
2086 /**
2087  * gtk_tree_view_column_set_alignment:
2088  * @tree_column: A #GtkTreeViewColumn.
2089  * @xalign: The alignment, which is between [0.0 and 1.0] inclusive.
2090  * 
2091  * Sets the alignment of the title or custom widget inside the column header.
2092  * The alignment determines its location inside the button -- 0.0 for left, 0.5
2093  * for center, 1.0 for right.
2094  **/
2095 void
2096 gtk_tree_view_column_set_alignment (GtkTreeViewColumn *tree_column,
2097                                     gfloat             xalign)
2098 {
2099   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2100
2101   xalign = CLAMP (xalign, 0.0, 1.0);
2102
2103   if (tree_column->xalign == xalign)
2104     return;
2105
2106   tree_column->xalign = xalign;
2107   gtk_tree_view_column_update_button (tree_column);
2108   g_object_notify (G_OBJECT (tree_column), "alignment");
2109 }
2110
2111 /**
2112  * gtk_tree_view_column_get_alignment:
2113  * @tree_column: A #GtkTreeViewColumn.
2114  * 
2115  * Returns the current x alignment of @tree_column.  This value can range
2116  * between 0.0 and 1.0.
2117  * 
2118  * Return value: The current alignent of @tree_column.
2119  **/
2120 gfloat
2121 gtk_tree_view_column_get_alignment (GtkTreeViewColumn *tree_column)
2122 {
2123   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0.5);
2124
2125   return tree_column->xalign;
2126 }
2127
2128 /**
2129  * gtk_tree_view_column_set_reorderable:
2130  * @tree_column: A #GtkTreeViewColumn
2131  * @reorderable: %TRUE, if the column can be reordered.
2132  * 
2133  * If @reorderable is %TRUE, then the column can be reordered by the end user
2134  * dragging the header.
2135  **/
2136 void
2137 gtk_tree_view_column_set_reorderable (GtkTreeViewColumn *tree_column,
2138                                       gboolean           reorderable)
2139 {
2140   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2141
2142   /*  if (reorderable)
2143       gtk_tree_view_column_set_clickable (tree_column, TRUE);*/
2144
2145   if (tree_column->reorderable == (reorderable?TRUE:FALSE))
2146     return;
2147
2148   tree_column->reorderable = (reorderable?TRUE:FALSE);
2149   gtk_tree_view_column_update_button (tree_column);
2150   g_object_notify (G_OBJECT (tree_column), "reorderable");
2151 }
2152
2153 /**
2154  * gtk_tree_view_column_get_reorderable:
2155  * @tree_column: A #GtkTreeViewColumn
2156  * 
2157  * Returns %TRUE if the @tree_column can be reordered by the user.
2158  * 
2159  * Return value: %TRUE if the @tree_column can be reordered by the user.
2160  **/
2161 gboolean
2162 gtk_tree_view_column_get_reorderable (GtkTreeViewColumn *tree_column)
2163 {
2164   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
2165
2166   return tree_column->reorderable;
2167 }
2168
2169
2170 /**
2171  * gtk_tree_view_column_set_sort_column_id:
2172  * @tree_column: a #GtkTreeViewColumn
2173  * @sort_column_id: The @sort_column_id of the model to sort on.
2174  *
2175  * Sets the logical @sort_column_id that this column sorts on when this column 
2176  * is selected for sorting.  Doing so makes the column header clickable.
2177  **/
2178 void
2179 gtk_tree_view_column_set_sort_column_id (GtkTreeViewColumn *tree_column,
2180                                          gint               sort_column_id)
2181 {
2182   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2183   g_return_if_fail (sort_column_id >= -1);
2184
2185   if (tree_column->sort_column_id == sort_column_id)
2186     return;
2187
2188   tree_column->sort_column_id = sort_column_id;
2189
2190   /* Handle unsetting the id */
2191   if (sort_column_id == -1)
2192     {
2193       GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_column->tree_view));
2194
2195       if (tree_column->sort_clicked_signal)
2196         {
2197           g_signal_handler_disconnect (tree_column, tree_column->sort_clicked_signal);
2198           tree_column->sort_clicked_signal = 0;
2199         }
2200
2201       if (tree_column->sort_column_changed_signal)
2202         {
2203           g_signal_handler_disconnect (model, tree_column->sort_column_changed_signal);
2204           tree_column->sort_column_changed_signal = 0;
2205         }
2206
2207       gtk_tree_view_column_set_sort_order (tree_column, GTK_SORT_ASCENDING);
2208       gtk_tree_view_column_set_sort_indicator (tree_column, FALSE);
2209       gtk_tree_view_column_set_clickable (tree_column, FALSE);
2210       return;
2211     }
2212
2213   gtk_tree_view_column_set_clickable (tree_column, TRUE);
2214
2215   if (! tree_column->sort_clicked_signal)
2216     tree_column->sort_clicked_signal = g_signal_connect (tree_column,
2217                                                          "clicked",
2218                                                          G_CALLBACK (gtk_tree_view_column_sort),
2219                                                          NULL);
2220
2221   gtk_tree_view_column_setup_sort_column_id_callback (tree_column);
2222 }
2223
2224 /**
2225  * gtk_tree_view_column_get_sort_column_id:
2226  * @tree_column: a #GtkTreeViewColumn
2227  *
2228  * Gets the logical @sort_column_id that the model sorts on when this
2229  * column is selected for sorting.
2230  * See gtk_tree_view_column_set_sort_column_id().
2231  *
2232  * Return value: the current @sort_column_id for this column, or -1 if
2233  *               this column can't be used for sorting.
2234  **/
2235 gint
2236 gtk_tree_view_column_get_sort_column_id (GtkTreeViewColumn *tree_column)
2237 {
2238   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);
2239
2240   return tree_column->sort_column_id;
2241 }
2242
2243 /**
2244  * gtk_tree_view_column_set_sort_indicator:
2245  * @tree_column: a #GtkTreeViewColumn
2246  * @setting: %TRUE to display an indicator that the column is sorted
2247  *
2248  * Call this function with a @setting of %TRUE to display an arrow in
2249  * the header button indicating the column is sorted. Call
2250  * gtk_tree_view_column_set_sort_order() to change the direction of
2251  * the arrow.
2252  * 
2253  **/
2254 void
2255 gtk_tree_view_column_set_sort_indicator (GtkTreeViewColumn     *tree_column,
2256                                          gboolean               setting)
2257 {
2258   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2259
2260   setting = setting != FALSE;
2261
2262   if (setting == tree_column->show_sort_indicator)
2263     return;
2264
2265   tree_column->show_sort_indicator = setting;
2266   gtk_tree_view_column_update_button (tree_column);
2267   g_object_notify (G_OBJECT (tree_column), "sort_indicator");
2268 }
2269
2270 /**
2271  * gtk_tree_view_column_get_sort_indicator:
2272  * @tree_column: a #GtkTreeViewColumn
2273  * 
2274  * Gets the value set by gtk_tree_view_column_set_sort_indicator().
2275  * 
2276  * Return value: whether the sort indicator arrow is displayed
2277  **/
2278 gboolean
2279 gtk_tree_view_column_get_sort_indicator  (GtkTreeViewColumn     *tree_column)
2280 {
2281   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
2282
2283   return tree_column->show_sort_indicator;
2284 }
2285
2286 /**
2287  * gtk_tree_view_column_set_sort_order:
2288  * @tree_column: a #GtkTreeViewColumn
2289  * @order: sort order that the sort indicator should indicate
2290  *
2291  * Changes the appearance of the sort indicator. 
2292  * 
2293  * This <emphasis>does not</emphasis> actually sort the model.  Use
2294  * gtk_tree_view_column_set_sort_column_id() if you want automatic sorting
2295  * support.  This function is primarily for custom sorting behavior, and should
2296  * be used in conjunction with gtk_tree_sortable_set_sort_column() to do
2297  * that. For custom models, the mechanism will vary. 
2298  * 
2299  * The sort indicator changes direction to indicate normal sort or reverse sort.
2300  * Note that you must have the sort indicator enabled to see anything when 
2301  * calling this function; see gtk_tree_view_column_set_sort_indicator().
2302  **/
2303 void
2304 gtk_tree_view_column_set_sort_order      (GtkTreeViewColumn     *tree_column,
2305                                           GtkSortType            order)
2306 {
2307   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2308
2309   if (order == tree_column->sort_order)
2310     return;
2311
2312   tree_column->sort_order = order;
2313   gtk_tree_view_column_update_button (tree_column);
2314   g_object_notify (G_OBJECT (tree_column), "sort_order");
2315 }
2316
2317 /**
2318  * gtk_tree_view_column_get_sort_order:
2319  * @tree_column: a #GtkTreeViewColumn
2320  * 
2321  * Gets the value set by gtk_tree_view_column_set_sort_order().
2322  * 
2323  * Return value: the sort order the sort indicator is indicating
2324  **/
2325 GtkSortType
2326 gtk_tree_view_column_get_sort_order      (GtkTreeViewColumn     *tree_column)
2327 {
2328   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);
2329
2330   return tree_column->sort_order;
2331 }
2332
2333 /**
2334  * gtk_tree_view_column_cell_set_cell_data:
2335  * @tree_column: A #GtkTreeViewColumn.
2336  * @tree_model: The #GtkTreeModel to to get the cell renderers attributes from.
2337  * @iter: The #GtkTreeIter to to get the cell renderer's attributes from.
2338  * @is_expander: %TRUE, if the row has children
2339  * @is_expanded: %TRUE, if the row has visible children
2340  * 
2341  * Sets the cell renderer based on the @tree_model and @iter.  That is, for
2342  * every attribute mapping in @tree_column, it will get a value from the set
2343  * column on the @iter, and use that value to set the attribute on the cell
2344  * renderer.  This is used primarily by the #GtkTreeView.
2345  **/
2346 void
2347 gtk_tree_view_column_cell_set_cell_data (GtkTreeViewColumn *tree_column,
2348                                          GtkTreeModel      *tree_model,
2349                                          GtkTreeIter       *iter,
2350                                          gboolean           is_expander,
2351                                          gboolean           is_expanded)
2352 {
2353   GSList *list;
2354   GValue value = { 0, };
2355   GList *cell_list;
2356
2357   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2358   g_return_if_fail (tree_column->cell_list != NULL);
2359
2360   if (tree_model == NULL)
2361     return;
2362
2363   for (cell_list = tree_column->cell_list; cell_list; cell_list = cell_list->next)
2364     {
2365       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) cell_list->data;
2366       GObject *cell = (GObject *) info->cell;
2367
2368       list = info->attributes;
2369
2370       g_object_freeze_notify (cell);
2371       g_object_set (cell, "is_expander", is_expander, "is_expanded", is_expanded, NULL);
2372
2373       while (list && list->next)
2374         {
2375           gtk_tree_model_get_value (tree_model, iter,
2376                                     GPOINTER_TO_INT (list->next->data),
2377                                     &value);
2378           g_object_set_property (cell, (gchar *) list->data, &value);
2379           g_value_unset (&value);
2380           list = list->next->next;
2381         }
2382
2383       if (info->func)
2384         (* info->func) (tree_column, info->cell, tree_model, iter, info->func_data);
2385       g_object_thaw_notify (G_OBJECT (info->cell));
2386     }
2387
2388 }
2389
2390 /**
2391  * gtk_tree_view_column_cell_get_size:
2392  * @tree_column: A #GtkTreeViewColumn.
2393  * @cell_area: The area a cell in the column will be allocated, or %NULL
2394  * @x_offset: location to return x offset of a cell relative to @cell_area, or %NULL
2395  * @y_offset: location to return y offset of a cell relative to @cell_area, or %NULL
2396  * @width: location to return width needed to render a cell, or %NULL
2397  * @height: location to return height needed to render a cell, or %NULL
2398  * 
2399  * Obtains the width and height needed to render the column.  This is used
2400  * primarily by the #GtkTreeView.
2401  **/
2402 void
2403 gtk_tree_view_column_cell_get_size (GtkTreeViewColumn *tree_column,
2404                                     GdkRectangle      *cell_area,
2405                                     gint              *x_offset,
2406                                     gint              *y_offset,
2407                                     gint              *width,
2408                                     gint              *height)
2409 {
2410   GList *list;
2411   gboolean first_cell = TRUE;
2412   gint focus_line_width;
2413
2414   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2415
2416   if (height)
2417     * height = 0;
2418   if (width)
2419     * width = 0;
2420
2421   gtk_widget_style_get (tree_column->tree_view, "focus-line-width", &focus_line_width, NULL);
2422   
2423   for (list = tree_column->cell_list; list; list = list->next)
2424     {
2425       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
2426       gboolean visible;
2427       gint new_height = 0;
2428       gint new_width = 0;
2429       g_object_get (info->cell, "visible", &visible, NULL);
2430
2431       if (visible == FALSE)
2432         continue;
2433
2434       if (first_cell == FALSE && *width)
2435         *width += tree_column->spacing;
2436
2437       gtk_cell_renderer_get_size (info->cell,
2438                                   tree_column->tree_view,
2439                                   cell_area,
2440                                   x_offset,
2441                                   y_offset,
2442                                   &new_width,
2443                                   &new_height);
2444
2445       if (height)
2446         * height = MAX (*height, new_height + focus_line_width * 2);
2447       info->requested_width = MAX (info->requested_width, new_width + focus_line_width * 2);
2448       if (width)
2449         * width += info->requested_width;
2450       first_cell = FALSE;
2451     }
2452 }
2453
2454 /* rendering, event handling and rendering focus are somewhat complicated, and
2455  * quite a bit of code.  Rather than duplicate them, we put them together to
2456  * keep the code in one place.
2457  */
2458 enum {
2459   CELL_ACTION_RENDER,
2460   CELL_ACTION_FOCUS,
2461   CELL_ACTION_EVENT
2462 };
2463
2464 static gboolean
2465 gtk_tree_view_column_cell_process_action (GtkTreeViewColumn  *tree_column,
2466                                           GdkWindow          *window,
2467                                           GdkRectangle       *background_area,
2468                                           GdkRectangle       *cell_area,
2469                                           guint               flags,
2470                                           gint                action,
2471                                           GdkRectangle       *expose_area,     /* RENDER */
2472                                           GdkRectangle       *focus_rectangle, /* FOCUS  */
2473                                           GtkCellEditable   **editable_widget, /* EVENT  */
2474                                           GdkEvent           *event,           /* EVENT  */
2475                                           gchar              *path_string)     /* EVENT  */
2476 {
2477   GList *list;
2478   GdkRectangle real_cell_area;
2479   GdkRectangle real_background_area;
2480   gint expand_cell_count = 0;
2481   gint full_requested_width = 0;
2482   gint extra_space;
2483   gint min_x, min_y, max_x, max_y;
2484   gint focus_line_width;
2485   gint dx;
2486   gint special_cells;
2487   gboolean rtl;
2488   /* If we have rtl text, we need to transform our areas */
2489   GdkRectangle rtl_cell_area;
2490   GdkRectangle rtl_background_area;
2491
2492   min_x = G_MAXINT;
2493   min_y = G_MAXINT;
2494   max_x = 0;
2495   max_y = 0;
2496
2497   rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_column->tree_view)) == GTK_TEXT_DIR_RTL);
2498   special_cells = _gtk_tree_view_column_count_special_cells (tree_column);
2499
2500   if (special_cells > 1 && action == CELL_ACTION_FOCUS)
2501     {
2502       GtkTreeViewColumnCellInfo *info = NULL;
2503       gboolean found_has_focus = FALSE;
2504
2505       /* one should have focus */
2506       for (list = tree_column->cell_list; list; list = list->next)
2507         {
2508           info = list->data;
2509           if (info && info->has_focus)
2510             {
2511               found_has_focus = TRUE;
2512               break;
2513             }
2514         }
2515
2516       if (!found_has_focus)
2517         {
2518           /* give the first one focus */
2519           info = gtk_tree_view_column_cell_first (tree_column)->data;
2520           info->has_focus = TRUE;
2521         }
2522     }
2523
2524   gtk_widget_style_get (GTK_WIDGET (tree_column->tree_view),
2525                         "focus-line-width", &focus_line_width,
2526                         NULL);
2527
2528   real_cell_area = *cell_area;
2529   real_background_area = *background_area;
2530   /* HUH?  dx = real_cell_area.x - real_background_area.x - focus_line_width; */
2531
2532   real_cell_area.x += focus_line_width;
2533
2534   /* Find out how many extra space we have to allocate */
2535   for (list = tree_column->cell_list; list; list = list->next)
2536     {
2537       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *)list->data;
2538
2539       if (! info->cell->visible)
2540         continue;
2541
2542       if (info->expand == TRUE)
2543         expand_cell_count ++;
2544       full_requested_width += info->requested_width;
2545     }
2546
2547   extra_space = cell_area->width - full_requested_width;
2548
2549   if (extra_space < 0)
2550     extra_space = 0;
2551   else if (extra_space > 0 && expand_cell_count > 0)
2552     extra_space /= expand_cell_count;
2553
2554   /* iterate list for GTK_PACK_START cells */
2555   for (list = tree_column->cell_list; list; list = list->next)
2556     {
2557       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
2558
2559       if (info->pack == GTK_PACK_END)
2560         continue;
2561
2562       if (! info->cell->visible)
2563         continue;
2564
2565       if (info->has_focus)
2566         flags |= GTK_CELL_RENDERER_FOCUSED;
2567
2568       real_background_area.width = info->requested_width +
2569         (info->expand?extra_space:0);
2570       info->real_width = real_background_area.width;
2571
2572       real_cell_area.width = real_background_area.width;
2573       real_cell_area.width -= 2 * focus_line_width;
2574
2575       rtl_cell_area = real_cell_area;
2576       rtl_background_area = real_background_area;
2577       if (rtl)
2578         {
2579           rtl_cell_area.x = cell_area->x + cell_area->width - (real_cell_area.x - cell_area->x) - real_cell_area.width;
2580           rtl_background_area.x = background_area->x + background_area->width - (real_background_area.x - background_area->x) - real_background_area.width;
2581         }
2582
2583       /* RENDER */
2584       if (action == CELL_ACTION_RENDER)
2585         {
2586           gtk_cell_renderer_render (info->cell,
2587                                     window,
2588                                     tree_column->tree_view,
2589                                     &rtl_background_area,
2590                                     &rtl_cell_area,
2591                                     expose_area,
2592                                     flags);
2593         }
2594
2595       /* FOCUS */
2596       else if (action == CELL_ACTION_FOCUS)
2597         {
2598           gint x_offset, y_offset, width, height;
2599
2600           gtk_cell_renderer_get_size (info->cell,
2601                                       tree_column->tree_view,
2602                                       &rtl_cell_area,
2603                                       &x_offset, &y_offset,
2604                                       &width, &height);
2605
2606           if (special_cells > 1)
2607             {
2608               if (info->has_focus)
2609                 {
2610                   min_x = rtl_cell_area.x + x_offset;
2611                   max_x = min_x + width;
2612                   min_y = rtl_cell_area.y + y_offset;
2613                   max_y = min_y + height;
2614                 }
2615             }
2616           else
2617             {
2618               if (min_x > (rtl_cell_area.x + x_offset))
2619                 min_x = rtl_cell_area.x + x_offset;
2620               if (max_x < rtl_cell_area.x + x_offset + width)
2621                 max_x = rtl_cell_area.x + x_offset + width;
2622               if (min_y > (rtl_cell_area.y + y_offset))
2623                 min_y = rtl_cell_area.y + y_offset;
2624               if (max_y < rtl_cell_area.y + y_offset + height)
2625                 max_y = rtl_cell_area.y + y_offset + height;
2626             }
2627         }
2628       /* EVENT */
2629       else if (action == CELL_ACTION_EVENT)
2630         {
2631           gboolean try_event = FALSE;
2632
2633           if (event)
2634             {
2635               if (special_cells == 1)
2636                 {
2637                   /* only 1 activatable cell -> whole column can activate */
2638                   if (cell_area->x <= ((GdkEventButton *)event)->x &&
2639                       cell_area->x + cell_area->width > ((GdkEventButton *)event)->x)
2640                     try_event = TRUE;
2641                 }
2642               else if (rtl_cell_area.x <= ((GdkEventButton *)event)->x &&
2643                   rtl_cell_area.x + rtl_cell_area.width > ((GdkEventButton *)event)->x)
2644                   /* only activate cell if the user clicked on an individual
2645                    * cell
2646                    */
2647                 try_event = TRUE;
2648             }
2649           else if (special_cells > 1 && info->has_focus)
2650             try_event = TRUE;
2651           else if (special_cells == 1)
2652             try_event = TRUE;
2653
2654           if (try_event)
2655             {
2656               gboolean visible, mode;
2657
2658               g_object_get (info->cell,
2659                             "visible", &visible,
2660                             "mode", &mode,
2661                             NULL);
2662               if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2663                 {
2664                   if (gtk_cell_renderer_activate (info->cell,
2665                                                   event,
2666                                                   tree_column->tree_view,
2667                                                   path_string,
2668                                                   background_area,
2669                                                   cell_area,
2670                                                   flags))
2671                     {
2672                       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2673                       return TRUE;
2674                     }
2675                 }
2676               else if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2677                 {
2678                   *editable_widget =
2679                     gtk_cell_renderer_start_editing (info->cell,
2680                                                      event,
2681                                                      tree_column->tree_view,
2682                                                      path_string,
2683                                                      background_area,
2684                                                      cell_area,
2685                                                      flags);
2686
2687                   if (*editable_widget != NULL)
2688                     {
2689                       g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
2690                       info->in_editing_mode = TRUE;
2691                       gtk_tree_view_column_focus_cell (tree_column, info->cell);
2692                       
2693                       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2694
2695                       return TRUE;
2696                     }
2697                 }
2698             }
2699         }
2700
2701       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2702
2703       real_cell_area.x += (info->real_width + tree_column->spacing);
2704       real_background_area.x += (info->real_width + tree_column->spacing);
2705     }
2706
2707   /* iterate list for PACK_END cells */
2708   for (list = g_list_last (tree_column->cell_list); list; list = list->prev)
2709     {
2710       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
2711
2712       if (info->pack == GTK_PACK_START)
2713         continue;
2714
2715       if (! info->cell->visible)
2716         continue;
2717
2718       if (info->has_focus)
2719         flags |= GTK_CELL_RENDERER_FOCUSED;
2720
2721       real_background_area.width = info->requested_width +
2722         (info->expand?extra_space:0);
2723       info->real_width = real_background_area.width;
2724
2725       real_cell_area.width = real_background_area.width;
2726       real_cell_area.width -= 2 * focus_line_width;
2727
2728       rtl_cell_area = real_cell_area;
2729       rtl_background_area = real_background_area;
2730       if (rtl)
2731         {
2732           rtl_cell_area.x = cell_area->x + cell_area->width - (real_cell_area.x - cell_area->x) - real_cell_area.width;
2733           rtl_background_area.x = background_area->x + background_area->width - (real_background_area.x - background_area->x) - real_background_area.width;
2734         }
2735
2736       /* RENDER */
2737       if (action == CELL_ACTION_RENDER)
2738         {
2739           gtk_cell_renderer_render (info->cell,
2740                                     window,
2741                                     tree_column->tree_view,
2742                                     &rtl_background_area,
2743                                     &rtl_cell_area,
2744                                     expose_area,
2745                                     flags);
2746         }
2747       /* FOCUS */
2748       else if (action == CELL_ACTION_FOCUS)
2749         {
2750           gint x_offset, y_offset, width, height;
2751
2752           gtk_cell_renderer_get_size (info->cell,
2753                                       tree_column->tree_view,
2754                                       &rtl_cell_area,
2755                                       &x_offset, &y_offset,
2756                                       &width, &height);
2757
2758           if (special_cells > 1)
2759             {
2760               if (info->has_focus)
2761                 {
2762                   min_x = rtl_cell_area.x + x_offset;
2763                   max_x = min_x + width;
2764                   min_y = rtl_cell_area.y + y_offset;
2765                   max_y = min_y + height;
2766                 }
2767             }
2768           else
2769             {
2770               if (min_x > (rtl_cell_area.x + x_offset))
2771                 min_x = rtl_cell_area.x + x_offset;
2772               if (max_x < rtl_cell_area.x + x_offset + width)
2773                 max_x = rtl_cell_area.x + x_offset + width;
2774               if (min_y > (rtl_cell_area.y + y_offset))
2775                 min_y = rtl_cell_area.y + y_offset;
2776               if (max_y < rtl_cell_area.y + y_offset + height)
2777                 max_y = rtl_cell_area.y + y_offset + height;
2778             }
2779         }
2780       /* EVENT */
2781       else if (action == CELL_ACTION_EVENT)
2782         {
2783           gboolean try_event = FALSE;
2784
2785           if (event)
2786             {
2787               if (special_cells == 1)
2788                 {
2789                   /* only 1 activatable cell -> whole column can activate */
2790                   if (cell_area->x <= ((GdkEventButton *)event)->x &&
2791                       cell_area->x + cell_area->width > ((GdkEventButton *)event)->x)
2792                     try_event = TRUE;
2793                 }
2794               else if (real_cell_area.x <= ((GdkEventButton *)event)->x &&
2795                   real_cell_area.x + real_cell_area.width > ((GdkEventButton *)event)->x)
2796                 /* only activate cell if the user clicked on an individual
2797                  * cell
2798                  */
2799                 try_event = TRUE;
2800             }
2801           else if (special_cells > 1 && info->has_focus)
2802             try_event = TRUE;
2803           else if (special_cells == 1)
2804             try_event = TRUE;
2805
2806           if (try_event)
2807             {
2808               gboolean visible, mode;
2809
2810               g_object_get (info->cell,
2811                             "visible", &visible,
2812                             "mode", &mode,
2813                             NULL);
2814               if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2815                 {
2816                   if (gtk_cell_renderer_activate (info->cell,
2817                                                   event,
2818                                                   tree_column->tree_view,
2819                                                   path_string,
2820                                                   background_area,
2821                                                   cell_area,
2822                                                   flags))
2823                     {
2824                       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2825                       return TRUE;
2826                     }
2827                 }
2828               else if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2829                 {
2830                   *editable_widget =
2831                     gtk_cell_renderer_start_editing (info->cell,
2832                                                      event,
2833                                                      tree_column->tree_view,
2834                                                      path_string,
2835                                                      background_area,
2836                                                      cell_area,
2837                                                      flags);
2838
2839                   if (*editable_widget != NULL)
2840                     {
2841                       g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
2842                       info->in_editing_mode = TRUE;
2843                       gtk_tree_view_column_focus_cell (tree_column, info->cell);
2844
2845                       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2846                       return TRUE;
2847                     }
2848                 }
2849             }
2850         }
2851
2852       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2853
2854       real_cell_area.x += (info->real_width + tree_column->spacing);
2855       real_background_area.x += (info->real_width + tree_column->spacing);
2856     }
2857
2858   /* fill focus_rectangle when required */
2859   if (action == CELL_ACTION_FOCUS)
2860     {
2861       if (min_x >= max_x || min_y >= max_y)
2862         {
2863           *focus_rectangle = *cell_area;
2864           /* don't change the focus_rectangle, just draw it nicely inside
2865            * the cell area */
2866         }
2867       else
2868         {
2869           focus_rectangle->x = min_x - focus_line_width;
2870           focus_rectangle->y = min_y - focus_line_width;
2871           focus_rectangle->width = (max_x - min_x) + 2 * focus_line_width;
2872           focus_rectangle->height = (max_y - min_y) + 2 * focus_line_width;
2873         }
2874     }
2875
2876   return FALSE;
2877 }
2878
2879 /**
2880  * gtk_tree_view_column_cell_render:
2881  * @tree_column: A #GtkTreeViewColumn.
2882  * @window: a #GdkDrawable to draw to
2883  * @background_area: entire cell area (including tree expanders and maybe padding on the sides)
2884  * @cell_area: area normally rendered by a cell renderer
2885  * @expose_area: area that actually needs updating
2886  * @flags: flags that affect rendering
2887  * 
2888  * Renders the cell contained by #tree_column. This is used primarily by the
2889  * #GtkTreeView.
2890  **/
2891 void
2892 _gtk_tree_view_column_cell_render (GtkTreeViewColumn *tree_column,
2893                                    GdkWindow         *window,
2894                                    GdkRectangle      *background_area,
2895                                    GdkRectangle      *cell_area,
2896                                    GdkRectangle      *expose_area,
2897                                    guint              flags)
2898 {
2899   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2900   g_return_if_fail (background_area != NULL);
2901   g_return_if_fail (cell_area != NULL);
2902   g_return_if_fail (expose_area != NULL);
2903
2904   gtk_tree_view_column_cell_process_action (tree_column,
2905                                             window,
2906                                             background_area,
2907                                             cell_area,
2908                                             flags,
2909                                             CELL_ACTION_RENDER,
2910                                             expose_area,
2911                                             NULL, NULL, NULL, NULL);
2912 }
2913
2914 gboolean
2915 _gtk_tree_view_column_cell_event (GtkTreeViewColumn  *tree_column,
2916                                   GtkCellEditable   **editable_widget,
2917                                   GdkEvent           *event,
2918                                   gchar              *path_string,
2919                                   GdkRectangle       *background_area,
2920                                   GdkRectangle       *cell_area,
2921                                   guint               flags)
2922 {
2923   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
2924
2925   return gtk_tree_view_column_cell_process_action (tree_column,
2926                                                    NULL,
2927                                                    background_area,
2928                                                    cell_area,
2929                                                    flags,
2930                                                    CELL_ACTION_EVENT,
2931                                                    NULL, NULL,
2932                                                    editable_widget,
2933                                                    event,
2934                                                    path_string);
2935 }
2936
2937 /* cell list manipulation */
2938 static GList *
2939 gtk_tree_view_column_cell_first (GtkTreeViewColumn *tree_column)
2940 {
2941   GList *list = tree_column->cell_list;
2942
2943   /* first GTK_PACK_START cell we find */
2944   for ( ; list; list = list->next)
2945     {
2946       GtkTreeViewColumnCellInfo *info = list->data;
2947       if (info->pack == GTK_PACK_START)
2948         return list;
2949     }
2950
2951   /* hmm, else the *last* GTK_PACK_END cell */
2952   list = g_list_last (tree_column->cell_list);
2953
2954   for ( ; list; list = list->prev)
2955     {
2956       GtkTreeViewColumnCellInfo *info = list->data;
2957       if (info->pack == GTK_PACK_END)
2958         return list;
2959     }
2960
2961   return NULL;
2962 }
2963
2964 static GList *
2965 gtk_tree_view_column_cell_last (GtkTreeViewColumn *tree_column)
2966 {
2967   GList *list = tree_column->cell_list;
2968
2969   /* *first* GTK_PACK_END cell we find */
2970   for ( ; list ; list = list->next)
2971     {
2972       GtkTreeViewColumnCellInfo *info = list->data;
2973       if (info->pack == GTK_PACK_END)
2974         return list;
2975     }
2976
2977   /* hmm, else the last GTK_PACK_START cell */
2978   list = g_list_last (tree_column->cell_list);
2979
2980   for ( ; list; list = list->prev)
2981     {
2982       GtkTreeViewColumnCellInfo *info = list->data;
2983       if (info->pack == GTK_PACK_START)
2984         return list;
2985     }
2986
2987   return NULL;
2988 }
2989
2990 static GList *
2991 gtk_tree_view_column_cell_next (GtkTreeViewColumn *tree_column,
2992                                 GList             *current)
2993 {
2994   GList *list;
2995   GtkTreeViewColumnCellInfo *info = current->data;
2996
2997   if (info->pack == GTK_PACK_START)
2998     {
2999       for (list = current->next; list; list = list->next)
3000         {
3001           GtkTreeViewColumnCellInfo *inf = list->data;
3002           if (inf->pack == GTK_PACK_START)
3003             return list;
3004         }
3005
3006       /* out of GTK_PACK_START cells, get *last* GTK_PACK_END one */
3007       list = g_list_last (tree_column->cell_list);
3008       for (; list; list = list->prev)
3009         {
3010           GtkTreeViewColumnCellInfo *inf = list->data;
3011           if (inf->pack == GTK_PACK_END)
3012             return list;
3013         }
3014     }
3015
3016   for (list = current->prev; list; list = list->prev)
3017     {
3018       GtkTreeViewColumnCellInfo *inf = list->data;
3019       if (inf->pack == GTK_PACK_END)
3020         return list;
3021     }
3022
3023   return NULL;
3024 }
3025
3026 static GList *
3027 gtk_tree_view_column_cell_prev (GtkTreeViewColumn *tree_column,
3028                                 GList             *current)
3029 {
3030   GList *list;
3031   GtkTreeViewColumnCellInfo *info = current->data;
3032
3033   if (info->pack == GTK_PACK_END)
3034     {
3035       for (list = current->next; list; list = list->next)
3036         {
3037           GtkTreeViewColumnCellInfo *inf = list->data;
3038           if (inf->pack == GTK_PACK_END)
3039             return list;
3040         }
3041
3042       /* out of GTK_PACK_END, get last GTK_PACK_START one */
3043       list = g_list_last (tree_column->cell_list);
3044       for ( ; list; list = list->prev)
3045         {
3046           GtkTreeViewColumnCellInfo *inf = list->data;
3047           if (inf->pack == GTK_PACK_START)
3048             return list;
3049         }
3050     }
3051
3052   for (list = current->prev; list; list = list->prev)
3053     {
3054       GtkTreeViewColumnCellInfo *inf = list->data;
3055       if (inf->pack == GTK_PACK_START)
3056         return list;
3057     }
3058
3059   return NULL;
3060 }
3061
3062 gboolean
3063 _gtk_tree_view_column_cell_focus (GtkTreeViewColumn *tree_column,
3064                                   gint               direction,
3065                                   gboolean           left,
3066                                   gboolean           right)
3067 {
3068   gint count;
3069
3070   count = _gtk_tree_view_column_count_special_cells (tree_column);
3071
3072   /* if we are the current focus column and have multiple editable cells,
3073    * try to select the next one, else move the focus to the next column
3074    */
3075   if (GTK_TREE_VIEW (tree_column->tree_view)->priv->focus_column == tree_column)
3076     {
3077       if (count > 1)
3078         {
3079           GList *next, *prev;
3080           GList *list = tree_column->cell_list;
3081           GtkTreeViewColumnCellInfo *info = NULL;
3082
3083           /* find current focussed cell */
3084           for ( ; list; list = list->next)
3085             {
3086               info = list->data;
3087               if (info->has_focus)
3088                 break;
3089             }
3090
3091           /* not a focussed cell in the focus column? */
3092           if (!list || !info || !info->has_focus)
3093             return FALSE;
3094
3095           next = gtk_tree_view_column_cell_next (tree_column, list);
3096           prev = gtk_tree_view_column_cell_prev (tree_column, list);
3097
3098           info->has_focus = FALSE;
3099           if (direction > 0 && next)
3100             {
3101               info = next->data;
3102               info->has_focus = TRUE;
3103               return TRUE;
3104             }
3105           else if (direction > 0 && !next && !right)
3106             {
3107               /* keep focus on latest cell */
3108               info = gtk_tree_view_column_cell_last (tree_column)->data;
3109               info->has_focus = TRUE;
3110               return TRUE;
3111             }
3112           else if (direction < 0 && prev)
3113             {
3114               info = prev->data;
3115               info->has_focus = TRUE;
3116               return TRUE;
3117             }
3118           else if (direction < 0 && !prev && !left)
3119             {
3120               /* keep focus on first cell */
3121               info = gtk_tree_view_column_cell_first (tree_column)->data;
3122               info->has_focus = TRUE;
3123               return TRUE;
3124             }
3125         }
3126       return FALSE;
3127     }
3128
3129   /* we get focus, if we have multiple editable cells, give the correct one
3130    * focus
3131    */
3132   if (count > 1)
3133     {
3134       GList *list = tree_column->cell_list;
3135
3136       /* clear focus first */
3137       for ( ; list ; list = list->next)
3138         {
3139           GtkTreeViewColumnCellInfo *info = list->data;
3140           if (info->has_focus)
3141             info->has_focus = FALSE;
3142         }
3143
3144       if (direction > 0)
3145         ((GtkTreeViewColumnCellInfo *)gtk_tree_view_column_cell_first (tree_column)->data)->has_focus = TRUE;
3146       else if (direction < 0)
3147         ((GtkTreeViewColumnCellInfo *)gtk_tree_view_column_cell_last (tree_column)->data)->has_focus = TRUE;
3148     }
3149   return TRUE;
3150 }
3151
3152 void
3153 _gtk_tree_view_column_cell_draw_focus (GtkTreeViewColumn       *tree_column,
3154                                        GdkWindow               *window,
3155                                        GdkRectangle            *background_area,
3156                                        GdkRectangle            *cell_area,
3157                                        GdkRectangle            *expose_area,
3158                                        guint                    flags)
3159 {
3160   gint focus_line_width;
3161   GtkStateType cell_state;
3162   
3163   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
3164   gtk_widget_style_get (GTK_WIDGET (tree_column->tree_view),
3165                         "focus-line-width", &focus_line_width, NULL);
3166   if (tree_column->editable_widget)
3167     {
3168       /* This function is only called on the editable row when editing.
3169        */
3170 #if 0
3171       gtk_paint_focus (tree_column->tree_view->style,
3172                        window,
3173                        GTK_WIDGET_STATE (tree_column->tree_view),
3174                        NULL,
3175                        tree_column->tree_view,
3176                        "treeview",
3177                        cell_area->x - focus_line_width,
3178                        cell_area->y - focus_line_width,
3179                        cell_area->width + 2 * focus_line_width,
3180                        cell_area->height + 2 * focus_line_width);
3181 #endif      
3182     }
3183   else
3184     {
3185       GdkRectangle focus_rectangle;
3186       gtk_tree_view_column_cell_process_action (tree_column,
3187                                                 window,
3188                                                 background_area,
3189                                                 cell_area,
3190                                                 flags,
3191                                                 CELL_ACTION_FOCUS,
3192                                                 expose_area,
3193                                                 &focus_rectangle,
3194                                                 NULL, NULL, NULL);
3195
3196       cell_state = flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
3197               (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
3198               (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL));
3199       gtk_paint_focus (tree_column->tree_view->style,
3200                        window,
3201                        cell_state,
3202                        NULL,
3203                        tree_column->tree_view,
3204                        "treeview",
3205                        focus_rectangle.x,
3206                        focus_rectangle.y,
3207                        focus_rectangle.width,
3208                        focus_rectangle.height);
3209     }
3210 }
3211
3212 /**
3213  * gtk_tree_view_column_cell_is_visible:
3214  * @tree_column: A #GtkTreeViewColumn
3215  * 
3216  * Returns %TRUE if any of the cells packed into the @tree_column are visible.
3217  * For this to be meaningful, you must first initialize the cells with
3218  * gtk_tree_view_column_cell_set_cell_data()
3219  * 
3220  * Return value: %TRUE, if any of the cells packed into the @tree_column are currently visible
3221  **/
3222 gboolean
3223 gtk_tree_view_column_cell_is_visible (GtkTreeViewColumn *tree_column)
3224 {
3225   GList *list;
3226
3227   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
3228
3229   for (list = tree_column->cell_list; list; list = list->next)
3230     {
3231       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
3232
3233       if (info->cell->visible)
3234         return TRUE;
3235     }
3236
3237   return FALSE;
3238 }
3239
3240 /**
3241  * gtk_tree_view_column_focus_cell:
3242  * @tree_column: A #GtkTreeViewColumn
3243  * @cell: A #GtkCellRenderer
3244  *
3245  * Sets the current keyboard focus to be at @cell, if the column contains
3246  * 2 or more editable and activatable cells.
3247  *
3248  * Since: 2.2
3249  **/
3250 void
3251 gtk_tree_view_column_focus_cell (GtkTreeViewColumn *tree_column,
3252                                  GtkCellRenderer   *cell)
3253 {
3254   GList *list;
3255   gboolean found_cell = FALSE;
3256
3257   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
3258   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
3259
3260   if (_gtk_tree_view_column_count_special_cells (tree_column) < 2)
3261     return;
3262
3263   for (list = tree_column->cell_list; list; list = list->next)
3264     {
3265       GtkTreeViewColumnCellInfo *info = list->data;
3266
3267       if (info->cell == cell)
3268         {
3269           info->has_focus = TRUE;
3270           found_cell = TRUE;
3271           break;
3272         }
3273     }
3274
3275   if (found_cell)
3276     {
3277       for (list = tree_column->cell_list; list; list = list->next)
3278         {
3279           GtkTreeViewColumnCellInfo *info = list->data;
3280
3281           if (info->cell != cell)
3282             info->has_focus = FALSE;
3283         }
3284
3285       /* FIXME: redraw? */
3286     }
3287 }
3288
3289 void
3290 _gtk_tree_view_column_cell_set_dirty (GtkTreeViewColumn *tree_column,
3291                                       gboolean           install_handler)
3292 {
3293   GList *list;
3294
3295   for (list = tree_column->cell_list; list; list = list->next)
3296     {
3297       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
3298
3299       info->requested_width = 0;
3300     }
3301   tree_column->dirty = TRUE;
3302   tree_column->resized_width = MAX (tree_column->requested_width, tree_column->button_request);
3303   tree_column->requested_width = -1;
3304   tree_column->width = 0;
3305
3306   if (tree_column->tree_view &&
3307       GTK_WIDGET_REALIZED (tree_column->tree_view))
3308     {
3309       if (install_handler)
3310         _gtk_tree_view_install_mark_rows_col_dirty (GTK_TREE_VIEW (tree_column->tree_view));
3311       else
3312         GTK_TREE_VIEW (tree_column->tree_view)->priv->mark_rows_col_dirty = TRUE;
3313       gtk_widget_queue_resize (tree_column->tree_view);
3314     }
3315 }
3316
3317 void
3318 _gtk_tree_view_column_start_editing (GtkTreeViewColumn *tree_column,
3319                                      GtkCellEditable   *cell_editable)
3320 {
3321   g_return_if_fail (tree_column->editable_widget == NULL);
3322
3323   tree_column->editable_widget = cell_editable;
3324 }
3325
3326 void
3327 _gtk_tree_view_column_stop_editing (GtkTreeViewColumn *tree_column)
3328 {
3329   GList *list;
3330
3331   g_return_if_fail (tree_column->editable_widget != NULL);
3332
3333   tree_column->editable_widget = NULL;
3334   for (list = tree_column->cell_list; list; list = list->next)
3335     ((GtkTreeViewColumnCellInfo *)list->data)->in_editing_mode = FALSE;
3336 }
3337
3338 void
3339 _gtk_tree_view_column_get_neighbor_sizes (GtkTreeViewColumn *column,
3340                                           GtkCellRenderer   *cell,
3341                                           gint              *left,
3342                                           gint              *right)
3343 {
3344   GList *list;
3345
3346   if (left)
3347     {
3348       *left = 0;
3349       list = gtk_tree_view_column_cell_first (column);
3350
3351       for (; list; list = gtk_tree_view_column_cell_next (column, list))
3352         {
3353           GtkTreeViewColumnCellInfo *info =
3354             (GtkTreeViewColumnCellInfo *)list->data;
3355
3356           if (info->cell == cell)
3357             break;
3358
3359           if (info->cell->visible)
3360             *left += info->real_width;
3361         }
3362     }
3363
3364   if (right)
3365     {
3366       GList *next;
3367
3368       *right = 0;
3369       list = gtk_tree_view_column_cell_first (column);
3370
3371       for (; list; list = gtk_tree_view_column_cell_next (column, list))
3372         {
3373           GtkTreeViewColumnCellInfo *info =
3374             (GtkTreeViewColumnCellInfo *)list->data;
3375
3376           if (info->cell == cell)
3377             break;
3378         }
3379
3380       /* skip cell */
3381       next = gtk_tree_view_column_cell_next (column, list);
3382       if (list && next)
3383         {
3384           list = next;
3385           for ( ; list; list = gtk_tree_view_column_cell_next (column, list))
3386             {
3387               GtkTreeViewColumnCellInfo *info =
3388                 (GtkTreeViewColumnCellInfo *)list->data;
3389
3390               if (info->cell->visible)
3391                 *right += info->real_width;
3392             }
3393         }
3394     }
3395 }
3396
3397 /**
3398  * gtk_tree_view_column_cell_get_position:
3399  * @tree_column: a #GtkTreeViewColumn
3400  * @cell: a #GtkCellRenderer
3401  * @start_pos: return location for the horizontal position of @cell within
3402  *            @tree_column, may be %NULL
3403  * @width: return location for the width of @cell, may be %NULL
3404  *
3405  * Obtains the horizontal position and size of a cell in a column. If the
3406  * cell is not found in the column, @start_pos and @width are not changed and
3407  * %FALSE is returned.
3408  * 
3409  * Return value: %TRUE if @cell belongs to @tree_column.
3410  */
3411 gboolean
3412 gtk_tree_view_column_cell_get_position (GtkTreeViewColumn *tree_column,
3413                                         GtkCellRenderer   *cell_renderer,
3414                                         gint              *start_pos,
3415                                         gint              *width)
3416 {
3417   GList *list;
3418   gint current_x = 0;
3419   gboolean found_cell = FALSE;
3420   GtkTreeViewColumnCellInfo *cellinfo = NULL;
3421
3422   list = gtk_tree_view_column_cell_first (tree_column);
3423   for (; list; list = gtk_tree_view_column_cell_next (tree_column, list))
3424     {
3425       cellinfo = list->data;
3426       if (cellinfo->cell == cell_renderer)
3427         {
3428           found_cell = TRUE;
3429           break;
3430         }
3431
3432       if (cellinfo->cell->visible)
3433         current_x += cellinfo->real_width;
3434     }
3435
3436   if (found_cell)
3437     {
3438       if (start_pos)
3439         *start_pos = current_x;
3440       if (width)
3441         *width = cellinfo->real_width;
3442     }
3443
3444   return found_cell;
3445 }
3446