]> Pileus Git - ~andy/gtk/blob - gtk/gtktreeviewcolumn.c
Merged from stable.
[~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 special_cells;
2486   gint horizontal_separator;
2487   gboolean cursor_row = FALSE;
2488   gboolean rtl;
2489   /* If we have rtl text, we need to transform our areas */
2490   GdkRectangle rtl_cell_area;
2491   GdkRectangle rtl_background_area;
2492
2493   min_x = G_MAXINT;
2494   min_y = G_MAXINT;
2495   max_x = 0;
2496   max_y = 0;
2497
2498   rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_column->tree_view)) == GTK_TEXT_DIR_RTL);
2499   special_cells = _gtk_tree_view_column_count_special_cells (tree_column);
2500
2501   if (special_cells > 1 && action == CELL_ACTION_FOCUS)
2502     {
2503       GtkTreeViewColumnCellInfo *info = NULL;
2504       gboolean found_has_focus = FALSE;
2505
2506       /* one should have focus */
2507       for (list = tree_column->cell_list; list; list = list->next)
2508         {
2509           info = list->data;
2510           if (info && info->has_focus)
2511             {
2512               found_has_focus = TRUE;
2513               break;
2514             }
2515         }
2516
2517       if (!found_has_focus)
2518         {
2519           /* give the first one focus */
2520           info = gtk_tree_view_column_cell_first (tree_column)->data;
2521           info->has_focus = TRUE;
2522         }
2523     }
2524
2525   cursor_row = flags & GTK_CELL_RENDERER_FOCUSED;
2526
2527   gtk_widget_style_get (GTK_WIDGET (tree_column->tree_view),
2528                         "focus-line-width", &focus_line_width,
2529                         "horizontal-seperator", &horizontal_separator,
2530                         NULL);
2531
2532   real_cell_area = *cell_area;
2533   real_background_area = *background_area;
2534
2535   real_cell_area.x += focus_line_width;
2536
2537   /* Find out how many extra space we have to allocate */
2538   for (list = tree_column->cell_list; list; list = list->next)
2539     {
2540       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *)list->data;
2541
2542       if (! info->cell->visible)
2543         continue;
2544
2545       if (info->expand == TRUE)
2546         expand_cell_count ++;
2547       full_requested_width += info->requested_width;
2548     }
2549
2550   extra_space = cell_area->width + horizontal_separator - full_requested_width;
2551
2552   if (extra_space < 0)
2553     extra_space = 0;
2554   else if (extra_space > 0 && expand_cell_count > 0)
2555     extra_space /= expand_cell_count;
2556
2557   /* iterate list for GTK_PACK_START cells */
2558   for (list = tree_column->cell_list; list; list = list->next)
2559     {
2560       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
2561
2562       if (info->pack == GTK_PACK_END)
2563         continue;
2564
2565       if (! info->cell->visible)
2566         continue;
2567
2568       if ((info->has_focus || special_cells == 1) && cursor_row)
2569         flags |= GTK_CELL_RENDERER_FOCUSED;
2570       else
2571         flags &= ~GTK_CELL_RENDERER_FOCUSED;
2572
2573       info->real_width = info->requested_width + (info->expand?extra_space:0);
2574
2575       real_cell_area.width = info->real_width;
2576       real_background_area.width=
2577         real_cell_area.x + real_cell_area.width - real_background_area.x;
2578       real_cell_area.width -= 2 * focus_line_width;
2579
2580       rtl_cell_area = real_cell_area;
2581       rtl_background_area = real_background_area;
2582       if (rtl)
2583         {
2584           rtl_cell_area.x = cell_area->x + cell_area->width - (real_cell_area.x - cell_area->x) - real_cell_area.width;
2585           rtl_background_area.x = background_area->x + background_area->width - (real_background_area.x - background_area->x) - real_background_area.width;
2586         }
2587
2588       /* RENDER */
2589       if (action == CELL_ACTION_RENDER)
2590         {
2591           gtk_cell_renderer_render (info->cell,
2592                                     window,
2593                                     tree_column->tree_view,
2594                                     &rtl_background_area,
2595                                     &rtl_cell_area,
2596                                     expose_area,
2597                                     flags);
2598         }
2599
2600       /* FOCUS */
2601       else if (action == CELL_ACTION_FOCUS)
2602         {
2603           gint x_offset, y_offset, width, height;
2604
2605           gtk_cell_renderer_get_size (info->cell,
2606                                       tree_column->tree_view,
2607                                       &rtl_cell_area,
2608                                       &x_offset, &y_offset,
2609                                       &width, &height);
2610
2611           if (special_cells > 1)
2612             {
2613               if (info->has_focus)
2614                 {
2615                   min_x = rtl_cell_area.x + x_offset;
2616                   max_x = min_x + width;
2617                   min_y = rtl_cell_area.y + y_offset;
2618                   max_y = min_y + height;
2619                 }
2620             }
2621           else
2622             {
2623               if (min_x > (rtl_cell_area.x + x_offset))
2624                 min_x = rtl_cell_area.x + x_offset;
2625               if (max_x < rtl_cell_area.x + x_offset + width)
2626                 max_x = rtl_cell_area.x + x_offset + width;
2627               if (min_y > (rtl_cell_area.y + y_offset))
2628                 min_y = rtl_cell_area.y + y_offset;
2629               if (max_y < rtl_cell_area.y + y_offset + height)
2630                 max_y = rtl_cell_area.y + y_offset + height;
2631             }
2632         }
2633       /* EVENT */
2634       else if (action == CELL_ACTION_EVENT)
2635         {
2636           gboolean try_event = FALSE;
2637
2638           if (event)
2639             {
2640               if (special_cells == 1)
2641                 {
2642                   /* only 1 activatable cell -> whole column can activate */
2643                   if (cell_area->x <= ((GdkEventButton *)event)->x &&
2644                       cell_area->x + cell_area->width > ((GdkEventButton *)event)->x)
2645                     try_event = TRUE;
2646                 }
2647               else if (rtl_cell_area.x <= ((GdkEventButton *)event)->x &&
2648                   rtl_cell_area.x + rtl_cell_area.width > ((GdkEventButton *)event)->x)
2649                   /* only activate cell if the user clicked on an individual
2650                    * cell
2651                    */
2652                 try_event = TRUE;
2653             }
2654           else if (special_cells > 1 && info->has_focus)
2655             try_event = TRUE;
2656           else if (special_cells == 1)
2657             try_event = TRUE;
2658
2659           if (try_event)
2660             {
2661               gboolean visible, mode;
2662
2663               g_object_get (info->cell,
2664                             "visible", &visible,
2665                             "mode", &mode,
2666                             NULL);
2667               if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2668                 {
2669                   if (gtk_cell_renderer_activate (info->cell,
2670                                                   event,
2671                                                   tree_column->tree_view,
2672                                                   path_string,
2673                                                   background_area,
2674                                                   cell_area,
2675                                                   flags))
2676                     {
2677                       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2678                       return TRUE;
2679                     }
2680                 }
2681               else if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2682                 {
2683                   *editable_widget =
2684                     gtk_cell_renderer_start_editing (info->cell,
2685                                                      event,
2686                                                      tree_column->tree_view,
2687                                                      path_string,
2688                                                      background_area,
2689                                                      cell_area,
2690                                                      flags);
2691
2692                   if (*editable_widget != NULL)
2693                     {
2694                       g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
2695                       info->in_editing_mode = TRUE;
2696                       gtk_tree_view_column_focus_cell (tree_column, info->cell);
2697                       
2698                       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2699
2700                       return TRUE;
2701                     }
2702                 }
2703             }
2704         }
2705
2706       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2707
2708       real_cell_area.x += (real_cell_area.width + tree_column->spacing);
2709       real_background_area.x += (real_background_area.width + tree_column->spacing);
2710     }
2711
2712   /* iterate list for PACK_END cells */
2713   for (list = g_list_last (tree_column->cell_list); list; list = list->prev)
2714     {
2715       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
2716
2717       if (info->pack == GTK_PACK_START)
2718         continue;
2719
2720       if (! info->cell->visible)
2721         continue;
2722
2723       if ((info->has_focus || special_cells == 1) && cursor_row)
2724         flags |= GTK_CELL_RENDERER_FOCUSED;
2725       else
2726         flags &= ~GTK_CELL_RENDERER_FOCUSED;
2727
2728       info->real_width = info->requested_width + (info->expand?extra_space:0);
2729
2730       real_cell_area.width = info->real_width;
2731       real_background_area.width =
2732         real_cell_area.x + real_cell_area.width - real_background_area.x;
2733       real_cell_area.width -= 2 * focus_line_width;
2734
2735       rtl_cell_area = real_cell_area;
2736       rtl_background_area = real_background_area;
2737       if (rtl)
2738         {
2739           rtl_cell_area.x = cell_area->x + cell_area->width - (real_cell_area.x - cell_area->x) - real_cell_area.width;
2740           rtl_background_area.x = background_area->x + background_area->width - (real_background_area.x - background_area->x) - real_background_area.width;
2741         }
2742
2743       /* RENDER */
2744       if (action == CELL_ACTION_RENDER)
2745         {
2746           gtk_cell_renderer_render (info->cell,
2747                                     window,
2748                                     tree_column->tree_view,
2749                                     &rtl_background_area,
2750                                     &rtl_cell_area,
2751                                     expose_area,
2752                                     flags);
2753         }
2754       /* FOCUS */
2755       else if (action == CELL_ACTION_FOCUS)
2756         {
2757           gint x_offset, y_offset, width, height;
2758
2759           gtk_cell_renderer_get_size (info->cell,
2760                                       tree_column->tree_view,
2761                                       &rtl_cell_area,
2762                                       &x_offset, &y_offset,
2763                                       &width, &height);
2764
2765           if (special_cells > 1)
2766             {
2767               if (info->has_focus)
2768                 {
2769                   min_x = rtl_cell_area.x + x_offset;
2770                   max_x = min_x + width;
2771                   min_y = rtl_cell_area.y + y_offset;
2772                   max_y = min_y + height;
2773                 }
2774             }
2775           else
2776             {
2777               if (min_x > (rtl_cell_area.x + x_offset))
2778                 min_x = rtl_cell_area.x + x_offset;
2779               if (max_x < rtl_cell_area.x + x_offset + width)
2780                 max_x = rtl_cell_area.x + x_offset + width;
2781               if (min_y > (rtl_cell_area.y + y_offset))
2782                 min_y = rtl_cell_area.y + y_offset;
2783               if (max_y < rtl_cell_area.y + y_offset + height)
2784                 max_y = rtl_cell_area.y + y_offset + height;
2785             }
2786         }
2787       /* EVENT */
2788       else if (action == CELL_ACTION_EVENT)
2789         {
2790           gboolean try_event = FALSE;
2791
2792           if (event)
2793             {
2794               if (special_cells == 1)
2795                 {
2796                   /* only 1 activatable cell -> whole column can activate */
2797                   if (cell_area->x <= ((GdkEventButton *)event)->x &&
2798                       cell_area->x + cell_area->width > ((GdkEventButton *)event)->x)
2799                     try_event = TRUE;
2800                 }
2801               else if (real_cell_area.x <= ((GdkEventButton *)event)->x &&
2802                   real_cell_area.x + real_cell_area.width > ((GdkEventButton *)event)->x)
2803                 /* only activate cell if the user clicked on an individual
2804                  * cell
2805                  */
2806                 try_event = TRUE;
2807             }
2808           else if (special_cells > 1 && info->has_focus)
2809             try_event = TRUE;
2810           else if (special_cells == 1)
2811             try_event = TRUE;
2812
2813           if (try_event)
2814             {
2815               gboolean visible, mode;
2816
2817               g_object_get (info->cell,
2818                             "visible", &visible,
2819                             "mode", &mode,
2820                             NULL);
2821               if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2822                 {
2823                   if (gtk_cell_renderer_activate (info->cell,
2824                                                   event,
2825                                                   tree_column->tree_view,
2826                                                   path_string,
2827                                                   background_area,
2828                                                   cell_area,
2829                                                   flags))
2830                     {
2831                       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2832                       return TRUE;
2833                     }
2834                 }
2835               else if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2836                 {
2837                   *editable_widget =
2838                     gtk_cell_renderer_start_editing (info->cell,
2839                                                      event,
2840                                                      tree_column->tree_view,
2841                                                      path_string,
2842                                                      background_area,
2843                                                      cell_area,
2844                                                      flags);
2845
2846                   if (*editable_widget != NULL)
2847                     {
2848                       g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
2849                       info->in_editing_mode = TRUE;
2850                       gtk_tree_view_column_focus_cell (tree_column, info->cell);
2851
2852                       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2853                       return TRUE;
2854                     }
2855                 }
2856             }
2857         }
2858
2859       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2860
2861       real_cell_area.x += (real_cell_area.width + tree_column->spacing);
2862       real_background_area.x += (real_background_area.width + tree_column->spacing);
2863     }
2864
2865   /* fill focus_rectangle when required */
2866   if (action == CELL_ACTION_FOCUS)
2867     {
2868       if (min_x >= max_x || min_y >= max_y)
2869         {
2870           *focus_rectangle = *cell_area;
2871           /* don't change the focus_rectangle, just draw it nicely inside
2872            * the cell area */
2873         }
2874       else
2875         {
2876           focus_rectangle->x = min_x - focus_line_width;
2877           focus_rectangle->y = min_y - focus_line_width;
2878           focus_rectangle->width = (max_x - min_x) + 2 * focus_line_width;
2879           focus_rectangle->height = (max_y - min_y) + 2 * focus_line_width;
2880         }
2881     }
2882
2883   return FALSE;
2884 }
2885
2886 /**
2887  * gtk_tree_view_column_cell_render:
2888  * @tree_column: A #GtkTreeViewColumn.
2889  * @window: a #GdkDrawable to draw to
2890  * @background_area: entire cell area (including tree expanders and maybe padding on the sides)
2891  * @cell_area: area normally rendered by a cell renderer
2892  * @expose_area: area that actually needs updating
2893  * @flags: flags that affect rendering
2894  * 
2895  * Renders the cell contained by #tree_column. This is used primarily by the
2896  * #GtkTreeView.
2897  **/
2898 void
2899 _gtk_tree_view_column_cell_render (GtkTreeViewColumn *tree_column,
2900                                    GdkWindow         *window,
2901                                    GdkRectangle      *background_area,
2902                                    GdkRectangle      *cell_area,
2903                                    GdkRectangle      *expose_area,
2904                                    guint              flags)
2905 {
2906   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2907   g_return_if_fail (background_area != NULL);
2908   g_return_if_fail (cell_area != NULL);
2909   g_return_if_fail (expose_area != NULL);
2910
2911   gtk_tree_view_column_cell_process_action (tree_column,
2912                                             window,
2913                                             background_area,
2914                                             cell_area,
2915                                             flags,
2916                                             CELL_ACTION_RENDER,
2917                                             expose_area,
2918                                             NULL, NULL, NULL, NULL);
2919 }
2920
2921 gboolean
2922 _gtk_tree_view_column_cell_event (GtkTreeViewColumn  *tree_column,
2923                                   GtkCellEditable   **editable_widget,
2924                                   GdkEvent           *event,
2925                                   gchar              *path_string,
2926                                   GdkRectangle       *background_area,
2927                                   GdkRectangle       *cell_area,
2928                                   guint               flags)
2929 {
2930   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
2931
2932   return gtk_tree_view_column_cell_process_action (tree_column,
2933                                                    NULL,
2934                                                    background_area,
2935                                                    cell_area,
2936                                                    flags,
2937                                                    CELL_ACTION_EVENT,
2938                                                    NULL, NULL,
2939                                                    editable_widget,
2940                                                    event,
2941                                                    path_string);
2942 }
2943
2944 /* cell list manipulation */
2945 static GList *
2946 gtk_tree_view_column_cell_first (GtkTreeViewColumn *tree_column)
2947 {
2948   GList *list = tree_column->cell_list;
2949
2950   /* first GTK_PACK_START cell we find */
2951   for ( ; list; list = list->next)
2952     {
2953       GtkTreeViewColumnCellInfo *info = list->data;
2954       if (info->pack == GTK_PACK_START)
2955         return list;
2956     }
2957
2958   /* hmm, else the *last* GTK_PACK_END cell */
2959   list = g_list_last (tree_column->cell_list);
2960
2961   for ( ; list; list = list->prev)
2962     {
2963       GtkTreeViewColumnCellInfo *info = list->data;
2964       if (info->pack == GTK_PACK_END)
2965         return list;
2966     }
2967
2968   return NULL;
2969 }
2970
2971 static GList *
2972 gtk_tree_view_column_cell_last (GtkTreeViewColumn *tree_column)
2973 {
2974   GList *list = tree_column->cell_list;
2975
2976   /* *first* GTK_PACK_END cell we find */
2977   for ( ; list ; list = list->next)
2978     {
2979       GtkTreeViewColumnCellInfo *info = list->data;
2980       if (info->pack == GTK_PACK_END)
2981         return list;
2982     }
2983
2984   /* hmm, else the last GTK_PACK_START cell */
2985   list = g_list_last (tree_column->cell_list);
2986
2987   for ( ; list; list = list->prev)
2988     {
2989       GtkTreeViewColumnCellInfo *info = list->data;
2990       if (info->pack == GTK_PACK_START)
2991         return list;
2992     }
2993
2994   return NULL;
2995 }
2996
2997 static GList *
2998 gtk_tree_view_column_cell_next (GtkTreeViewColumn *tree_column,
2999                                 GList             *current)
3000 {
3001   GList *list;
3002   GtkTreeViewColumnCellInfo *info = current->data;
3003
3004   if (info->pack == GTK_PACK_START)
3005     {
3006       for (list = current->next; list; list = list->next)
3007         {
3008           GtkTreeViewColumnCellInfo *inf = list->data;
3009           if (inf->pack == GTK_PACK_START)
3010             return list;
3011         }
3012
3013       /* out of GTK_PACK_START cells, get *last* GTK_PACK_END one */
3014       list = g_list_last (tree_column->cell_list);
3015       for (; list; list = list->prev)
3016         {
3017           GtkTreeViewColumnCellInfo *inf = list->data;
3018           if (inf->pack == GTK_PACK_END)
3019             return list;
3020         }
3021     }
3022
3023   for (list = current->prev; list; list = list->prev)
3024     {
3025       GtkTreeViewColumnCellInfo *inf = list->data;
3026       if (inf->pack == GTK_PACK_END)
3027         return list;
3028     }
3029
3030   return NULL;
3031 }
3032
3033 static GList *
3034 gtk_tree_view_column_cell_prev (GtkTreeViewColumn *tree_column,
3035                                 GList             *current)
3036 {
3037   GList *list;
3038   GtkTreeViewColumnCellInfo *info = current->data;
3039
3040   if (info->pack == GTK_PACK_END)
3041     {
3042       for (list = current->next; list; list = list->next)
3043         {
3044           GtkTreeViewColumnCellInfo *inf = list->data;
3045           if (inf->pack == GTK_PACK_END)
3046             return list;
3047         }
3048
3049       /* out of GTK_PACK_END, get last GTK_PACK_START one */
3050       list = g_list_last (tree_column->cell_list);
3051       for ( ; list; list = list->prev)
3052         {
3053           GtkTreeViewColumnCellInfo *inf = list->data;
3054           if (inf->pack == GTK_PACK_START)
3055             return list;
3056         }
3057     }
3058
3059   for (list = current->prev; list; list = list->prev)
3060     {
3061       GtkTreeViewColumnCellInfo *inf = list->data;
3062       if (inf->pack == GTK_PACK_START)
3063         return list;
3064     }
3065
3066   return NULL;
3067 }
3068
3069 gboolean
3070 _gtk_tree_view_column_cell_focus (GtkTreeViewColumn *tree_column,
3071                                   gint               direction,
3072                                   gboolean           left,
3073                                   gboolean           right)
3074 {
3075   gint count;
3076
3077   count = _gtk_tree_view_column_count_special_cells (tree_column);
3078
3079   /* if we are the current focus column and have multiple editable cells,
3080    * try to select the next one, else move the focus to the next column
3081    */
3082   if (GTK_TREE_VIEW (tree_column->tree_view)->priv->focus_column == tree_column)
3083     {
3084       if (count > 1)
3085         {
3086           GList *next, *prev;
3087           GList *list = tree_column->cell_list;
3088           GtkTreeViewColumnCellInfo *info = NULL;
3089
3090           /* find current focussed cell */
3091           for ( ; list; list = list->next)
3092             {
3093               info = list->data;
3094               if (info->has_focus)
3095                 break;
3096             }
3097
3098           /* not a focussed cell in the focus column? */
3099           if (!list || !info || !info->has_focus)
3100             return FALSE;
3101
3102           next = gtk_tree_view_column_cell_next (tree_column, list);
3103           prev = gtk_tree_view_column_cell_prev (tree_column, list);
3104
3105           info->has_focus = FALSE;
3106           if (direction > 0 && next)
3107             {
3108               info = next->data;
3109               info->has_focus = TRUE;
3110               return TRUE;
3111             }
3112           else if (direction > 0 && !next && !right)
3113             {
3114               /* keep focus on latest cell */
3115               info = gtk_tree_view_column_cell_last (tree_column)->data;
3116               info->has_focus = TRUE;
3117               return TRUE;
3118             }
3119           else if (direction < 0 && prev)
3120             {
3121               info = prev->data;
3122               info->has_focus = TRUE;
3123               return TRUE;
3124             }
3125           else if (direction < 0 && !prev && !left)
3126             {
3127               /* keep focus on first cell */
3128               info = gtk_tree_view_column_cell_first (tree_column)->data;
3129               info->has_focus = TRUE;
3130               return TRUE;
3131             }
3132         }
3133       return FALSE;
3134     }
3135
3136   /* we get focus, if we have multiple editable cells, give the correct one
3137    * focus
3138    */
3139   if (count > 1)
3140     {
3141       GList *list = tree_column->cell_list;
3142
3143       /* clear focus first */
3144       for ( ; list ; list = list->next)
3145         {
3146           GtkTreeViewColumnCellInfo *info = list->data;
3147           if (info->has_focus)
3148             info->has_focus = FALSE;
3149         }
3150
3151       if (direction > 0)
3152         ((GtkTreeViewColumnCellInfo *)gtk_tree_view_column_cell_first (tree_column)->data)->has_focus = TRUE;
3153       else if (direction < 0)
3154         ((GtkTreeViewColumnCellInfo *)gtk_tree_view_column_cell_last (tree_column)->data)->has_focus = TRUE;
3155     }
3156   return TRUE;
3157 }
3158
3159 void
3160 _gtk_tree_view_column_cell_draw_focus (GtkTreeViewColumn       *tree_column,
3161                                        GdkWindow               *window,
3162                                        GdkRectangle            *background_area,
3163                                        GdkRectangle            *cell_area,
3164                                        GdkRectangle            *expose_area,
3165                                        guint                    flags)
3166 {
3167   gint focus_line_width;
3168   GtkStateType cell_state;
3169   
3170   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
3171   gtk_widget_style_get (GTK_WIDGET (tree_column->tree_view),
3172                         "focus-line-width", &focus_line_width, NULL);
3173   if (tree_column->editable_widget)
3174     {
3175       /* This function is only called on the editable row when editing.
3176        */
3177 #if 0
3178       gtk_paint_focus (tree_column->tree_view->style,
3179                        window,
3180                        GTK_WIDGET_STATE (tree_column->tree_view),
3181                        NULL,
3182                        tree_column->tree_view,
3183                        "treeview",
3184                        cell_area->x - focus_line_width,
3185                        cell_area->y - focus_line_width,
3186                        cell_area->width + 2 * focus_line_width,
3187                        cell_area->height + 2 * focus_line_width);
3188 #endif      
3189     }
3190   else
3191     {
3192       GdkRectangle focus_rectangle;
3193       gtk_tree_view_column_cell_process_action (tree_column,
3194                                                 window,
3195                                                 background_area,
3196                                                 cell_area,
3197                                                 flags,
3198                                                 CELL_ACTION_FOCUS,
3199                                                 expose_area,
3200                                                 &focus_rectangle,
3201                                                 NULL, NULL, NULL);
3202
3203       cell_state = flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
3204               (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
3205               (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL));
3206       gtk_paint_focus (tree_column->tree_view->style,
3207                        window,
3208                        cell_state,
3209                        NULL,
3210                        tree_column->tree_view,
3211                        "treeview",
3212                        focus_rectangle.x,
3213                        focus_rectangle.y,
3214                        focus_rectangle.width,
3215                        focus_rectangle.height);
3216     }
3217 }
3218
3219 /**
3220  * gtk_tree_view_column_cell_is_visible:
3221  * @tree_column: A #GtkTreeViewColumn
3222  * 
3223  * Returns %TRUE if any of the cells packed into the @tree_column are visible.
3224  * For this to be meaningful, you must first initialize the cells with
3225  * gtk_tree_view_column_cell_set_cell_data()
3226  * 
3227  * Return value: %TRUE, if any of the cells packed into the @tree_column are currently visible
3228  **/
3229 gboolean
3230 gtk_tree_view_column_cell_is_visible (GtkTreeViewColumn *tree_column)
3231 {
3232   GList *list;
3233
3234   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
3235
3236   for (list = tree_column->cell_list; list; list = list->next)
3237     {
3238       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
3239
3240       if (info->cell->visible)
3241         return TRUE;
3242     }
3243
3244   return FALSE;
3245 }
3246
3247 /**
3248  * gtk_tree_view_column_focus_cell:
3249  * @tree_column: A #GtkTreeViewColumn
3250  * @cell: A #GtkCellRenderer
3251  *
3252  * Sets the current keyboard focus to be at @cell, if the column contains
3253  * 2 or more editable and activatable cells.
3254  *
3255  * Since: 2.2
3256  **/
3257 void
3258 gtk_tree_view_column_focus_cell (GtkTreeViewColumn *tree_column,
3259                                  GtkCellRenderer   *cell)
3260 {
3261   GList *list;
3262   gboolean found_cell = FALSE;
3263
3264   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
3265   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
3266
3267   if (_gtk_tree_view_column_count_special_cells (tree_column) < 2)
3268     return;
3269
3270   for (list = tree_column->cell_list; list; list = list->next)
3271     {
3272       GtkTreeViewColumnCellInfo *info = list->data;
3273
3274       if (info->cell == cell)
3275         {
3276           info->has_focus = TRUE;
3277           found_cell = TRUE;
3278           break;
3279         }
3280     }
3281
3282   if (found_cell)
3283     {
3284       for (list = tree_column->cell_list; list; list = list->next)
3285         {
3286           GtkTreeViewColumnCellInfo *info = list->data;
3287
3288           if (info->cell != cell)
3289             info->has_focus = FALSE;
3290         }
3291
3292       /* FIXME: redraw? */
3293     }
3294 }
3295
3296 void
3297 _gtk_tree_view_column_cell_set_dirty (GtkTreeViewColumn *tree_column,
3298                                       gboolean           install_handler)
3299 {
3300   GList *list;
3301
3302   for (list = tree_column->cell_list; list; list = list->next)
3303     {
3304       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
3305
3306       info->requested_width = 0;
3307     }
3308   tree_column->dirty = TRUE;
3309   tree_column->resized_width = MAX (tree_column->requested_width, tree_column->button_request);
3310   tree_column->requested_width = -1;
3311   tree_column->width = 0;
3312
3313   if (tree_column->tree_view &&
3314       GTK_WIDGET_REALIZED (tree_column->tree_view))
3315     {
3316       if (install_handler)
3317         _gtk_tree_view_install_mark_rows_col_dirty (GTK_TREE_VIEW (tree_column->tree_view));
3318       else
3319         GTK_TREE_VIEW (tree_column->tree_view)->priv->mark_rows_col_dirty = TRUE;
3320       gtk_widget_queue_resize (tree_column->tree_view);
3321     }
3322 }
3323
3324 void
3325 _gtk_tree_view_column_start_editing (GtkTreeViewColumn *tree_column,
3326                                      GtkCellEditable   *cell_editable)
3327 {
3328   g_return_if_fail (tree_column->editable_widget == NULL);
3329
3330   tree_column->editable_widget = cell_editable;
3331 }
3332
3333 void
3334 _gtk_tree_view_column_stop_editing (GtkTreeViewColumn *tree_column)
3335 {
3336   GList *list;
3337
3338   g_return_if_fail (tree_column->editable_widget != NULL);
3339
3340   tree_column->editable_widget = NULL;
3341   for (list = tree_column->cell_list; list; list = list->next)
3342     ((GtkTreeViewColumnCellInfo *)list->data)->in_editing_mode = FALSE;
3343 }
3344
3345 void
3346 _gtk_tree_view_column_get_neighbor_sizes (GtkTreeViewColumn *column,
3347                                           GtkCellRenderer   *cell,
3348                                           gint              *left,
3349                                           gint              *right)
3350 {
3351   GList *list;
3352
3353   if (left)
3354     {
3355       *left = 0;
3356       list = gtk_tree_view_column_cell_first (column);
3357
3358       for (; list; list = gtk_tree_view_column_cell_next (column, list))
3359         {
3360           GtkTreeViewColumnCellInfo *info =
3361             (GtkTreeViewColumnCellInfo *)list->data;
3362
3363           if (info->cell == cell)
3364             break;
3365
3366           if (info->cell->visible)
3367             *left += info->real_width;
3368         }
3369     }
3370
3371   if (right)
3372     {
3373       GList *next;
3374
3375       *right = 0;
3376       list = gtk_tree_view_column_cell_first (column);
3377
3378       for (; list; list = gtk_tree_view_column_cell_next (column, list))
3379         {
3380           GtkTreeViewColumnCellInfo *info =
3381             (GtkTreeViewColumnCellInfo *)list->data;
3382
3383           if (info->cell == cell)
3384             break;
3385         }
3386
3387       /* skip cell */
3388       next = gtk_tree_view_column_cell_next (column, list);
3389       if (list && next)
3390         {
3391           list = next;
3392           for ( ; list; list = gtk_tree_view_column_cell_next (column, list))
3393             {
3394               GtkTreeViewColumnCellInfo *info =
3395                 (GtkTreeViewColumnCellInfo *)list->data;
3396
3397               if (info->cell->visible)
3398                 *right += info->real_width;
3399             }
3400         }
3401     }
3402 }
3403
3404 /**
3405  * gtk_tree_view_column_cell_get_position:
3406  * @tree_column: a #GtkTreeViewColumn
3407  * @cell_renderer: a #GtkCellRenderer
3408  * @start_pos: return location for the horizontal position of @cell within
3409  *            @tree_column, may be %NULL
3410  * @width: return location for the width of @cell, may be %NULL
3411  *
3412  * Obtains the horizontal position and size of a cell in a column. If the
3413  * cell is not found in the column, @start_pos and @width are not changed and
3414  * %FALSE is returned.
3415  * 
3416  * Return value: %TRUE if @cell belongs to @tree_column.
3417  */
3418 gboolean
3419 gtk_tree_view_column_cell_get_position (GtkTreeViewColumn *tree_column,
3420                                         GtkCellRenderer   *cell_renderer,
3421                                         gint              *start_pos,
3422                                         gint              *width)
3423 {
3424   GList *list;
3425   gint current_x = 0;
3426   gboolean found_cell = FALSE;
3427   GtkTreeViewColumnCellInfo *cellinfo = NULL;
3428
3429   list = gtk_tree_view_column_cell_first (tree_column);
3430   for (; list; list = gtk_tree_view_column_cell_next (tree_column, list))
3431     {
3432       cellinfo = list->data;
3433       if (cellinfo->cell == cell_renderer)
3434         {
3435           found_cell = TRUE;
3436           break;
3437         }
3438
3439       if (cellinfo->cell->visible)
3440         current_x += cellinfo->real_width;
3441     }
3442
3443   if (found_cell)
3444     {
3445       if (start_pos)
3446         *start_pos = current_x;
3447       if (width)
3448         *width = cellinfo->real_width;
3449     }
3450
3451   return found_cell;
3452 }
3453