]> Pileus Git - ~andy/gtk/blob - gtk/gtktreeviewcolumn.c
handle rtl code.
[~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 void
1961 gtk_tree_view_column_set_expand (GtkTreeViewColumn *tree_column,
1962                                  gboolean           expand)
1963 {
1964   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
1965
1966   expand = expand?TRUE:FALSE;
1967   if (tree_column->expand == expand)
1968     return;
1969   tree_column->expand = expand;
1970
1971   if (tree_column->visible &&
1972       tree_column->tree_view != NULL &&
1973       GTK_WIDGET_REALIZED (tree_column->tree_view))
1974     {
1975       gtk_widget_queue_resize (tree_column->tree_view);
1976     }
1977
1978   g_object_notify (G_OBJECT (tree_column), "expand");
1979 }
1980
1981 /**
1982  * gtk_tree_view_column_get_expand:
1983  * @tree_column: 
1984  * 
1985  * Return %TRUE if the column expands to take any available space.
1986  * 
1987  * Return value: %TRUE, if the column expands
1988  **/
1989 gboolean
1990 gtk_tree_view_column_get_expand (GtkTreeViewColumn *tree_column)
1991 {
1992   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
1993
1994   return tree_column->expand;
1995 }
1996
1997 /**
1998  * gtk_tree_view_column_set_clickable:
1999  * @tree_column: A #GtkTreeViewColumn.
2000  * @clickable: %TRUE if the header is active.
2001  * 
2002  * Sets the header to be active if @active is %TRUE.  When the header is active,
2003  * then it can take keyboard focus, and can be clicked.
2004  **/
2005 void
2006 gtk_tree_view_column_set_clickable (GtkTreeViewColumn *tree_column,
2007                                     gboolean           clickable)
2008 {
2009   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2010
2011   clickable = !! clickable;
2012   if (tree_column->clickable == clickable)
2013     return;
2014
2015   tree_column->clickable = clickable;
2016   gtk_tree_view_column_update_button (tree_column);
2017   g_object_notify (G_OBJECT (tree_column), "clickable");
2018 }
2019
2020 /**
2021  * gtk_tree_view_column_get_clickable:
2022  * @tree_column: a #GtkTreeViewColumn
2023  * 
2024  * Returns %TRUE if the user can click on the header for the column.
2025  * 
2026  * Return value: %TRUE if user can click the column header.
2027  **/
2028 gboolean
2029 gtk_tree_view_column_get_clickable (GtkTreeViewColumn *tree_column)
2030 {
2031   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
2032
2033   return tree_column->clickable;
2034 }
2035
2036 /**
2037  * gtk_tree_view_column_set_widget:
2038  * @tree_column: A #GtkTreeViewColumn.
2039  * @widget: A child #GtkWidget, or %NULL.
2040  * 
2041  * Sets the widget in the header to be @widget.  If widget is %NULL, then the
2042  * header button is set with a #GtkLabel set to the title of @tree_column.
2043  **/
2044 void
2045 gtk_tree_view_column_set_widget (GtkTreeViewColumn *tree_column,
2046                                  GtkWidget         *widget)
2047 {
2048   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2049   g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
2050
2051   if (widget)
2052     {
2053       g_object_ref (widget);
2054       gtk_object_sink (GTK_OBJECT (widget));
2055     }
2056
2057   if (tree_column->child)      
2058     g_object_unref (tree_column->child);
2059
2060   tree_column->child = widget;
2061   gtk_tree_view_column_update_button (tree_column);
2062   g_object_notify (G_OBJECT (tree_column), "widget");
2063 }
2064
2065 /**
2066  * gtk_tree_view_column_get_widget:
2067  * @tree_column: A #GtkTreeViewColumn.
2068  * 
2069  * Returns the #GtkWidget in the button on the column header.  If a custom
2070  * widget has not been set then %NULL is returned.
2071  * 
2072  * Return value: The #GtkWidget in the column header, or %NULL
2073  **/
2074 GtkWidget *
2075 gtk_tree_view_column_get_widget (GtkTreeViewColumn *tree_column)
2076 {
2077   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), NULL);
2078
2079   return tree_column->child;
2080 }
2081
2082 /**
2083  * gtk_tree_view_column_set_alignment:
2084  * @tree_column: A #GtkTreeViewColumn.
2085  * @xalign: The alignment, which is between [0.0 and 1.0] inclusive.
2086  * 
2087  * Sets the alignment of the title or custom widget inside the column header.
2088  * The alignment determines its location inside the button -- 0.0 for left, 0.5
2089  * for center, 1.0 for right.
2090  **/
2091 void
2092 gtk_tree_view_column_set_alignment (GtkTreeViewColumn *tree_column,
2093                                     gfloat             xalign)
2094 {
2095   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2096
2097   xalign = CLAMP (xalign, 0.0, 1.0);
2098
2099   if (tree_column->xalign == xalign)
2100     return;
2101
2102   tree_column->xalign = xalign;
2103   gtk_tree_view_column_update_button (tree_column);
2104   g_object_notify (G_OBJECT (tree_column), "alignment");
2105 }
2106
2107 /**
2108  * gtk_tree_view_column_get_alignment:
2109  * @tree_column: A #GtkTreeViewColumn.
2110  * 
2111  * Returns the current x alignment of @tree_column.  This value can range
2112  * between 0.0 and 1.0.
2113  * 
2114  * Return value: The current alignent of @tree_column.
2115  **/
2116 gfloat
2117 gtk_tree_view_column_get_alignment (GtkTreeViewColumn *tree_column)
2118 {
2119   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0.5);
2120
2121   return tree_column->xalign;
2122 }
2123
2124 /**
2125  * gtk_tree_view_column_set_reorderable:
2126  * @tree_column: A #GtkTreeViewColumn
2127  * @reorderable: #TRUE, if the column can be reordered.
2128  * 
2129  * If @reorderable is #TRUE, then the column can be reordered by the end user
2130  * dragging the header.
2131  **/
2132 void
2133 gtk_tree_view_column_set_reorderable (GtkTreeViewColumn *tree_column,
2134                                       gboolean           reorderable)
2135 {
2136   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2137
2138   /*  if (reorderable)
2139       gtk_tree_view_column_set_clickable (tree_column, TRUE);*/
2140
2141   if (tree_column->reorderable == (reorderable?TRUE:FALSE))
2142     return;
2143
2144   tree_column->reorderable = (reorderable?TRUE:FALSE);
2145   gtk_tree_view_column_update_button (tree_column);
2146   g_object_notify (G_OBJECT (tree_column), "reorderable");
2147 }
2148
2149 /**
2150  * gtk_tree_view_column_get_reorderable:
2151  * @tree_column: A #GtkTreeViewColumn
2152  * 
2153  * Returns #TRUE if the @tree_column can be reordered by the user.
2154  * 
2155  * Return value: #TRUE if the @tree_column can be reordered by the user.
2156  **/
2157 gboolean
2158 gtk_tree_view_column_get_reorderable (GtkTreeViewColumn *tree_column)
2159 {
2160   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
2161
2162   return tree_column->reorderable;
2163 }
2164
2165
2166 /**
2167  * gtk_tree_view_column_set_sort_column_id:
2168  * @tree_column: a #GtkTreeViewColumn
2169  * @sort_column_id: The @sort_column_id of the model to sort on.
2170  *
2171  * Sets the logical @sort_column_id that this column sorts on when this column 
2172  * is selected for sorting.  Doing so makes the column header clickable.
2173  **/
2174 void
2175 gtk_tree_view_column_set_sort_column_id (GtkTreeViewColumn *tree_column,
2176                                          gint               sort_column_id)
2177 {
2178   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2179   g_return_if_fail (sort_column_id >= -1);
2180
2181   if (tree_column->sort_column_id == sort_column_id)
2182     return;
2183
2184   tree_column->sort_column_id = sort_column_id;
2185
2186   /* Handle unsetting the id */
2187   if (sort_column_id == -1)
2188     {
2189       GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_column->tree_view));
2190
2191       if (tree_column->sort_clicked_signal)
2192         {
2193           g_signal_handler_disconnect (tree_column, tree_column->sort_clicked_signal);
2194           tree_column->sort_clicked_signal = 0;
2195         }
2196
2197       if (tree_column->sort_column_changed_signal)
2198         {
2199           g_signal_handler_disconnect (model, tree_column->sort_column_changed_signal);
2200           tree_column->sort_column_changed_signal = 0;
2201         }
2202
2203       gtk_tree_view_column_set_sort_order (tree_column, GTK_SORT_ASCENDING);
2204       gtk_tree_view_column_set_sort_indicator (tree_column, FALSE);
2205       gtk_tree_view_column_set_clickable (tree_column, FALSE);
2206       return;
2207     }
2208
2209   gtk_tree_view_column_set_clickable (tree_column, TRUE);
2210
2211   if (! tree_column->sort_clicked_signal)
2212     tree_column->sort_clicked_signal = g_signal_connect (tree_column,
2213                                                          "clicked",
2214                                                          G_CALLBACK (gtk_tree_view_column_sort),
2215                                                          NULL);
2216
2217   gtk_tree_view_column_setup_sort_column_id_callback (tree_column);
2218 }
2219
2220 /**
2221  * gtk_tree_view_column_get_sort_column_id:
2222  * @tree_column: a #GtkTreeViewColumn
2223  *
2224  * Gets the logical @sort_column_id that the model sorts on when this
2225  * column is selected for sorting.
2226  * See gtk_tree_view_column_set_sort_column_id().
2227  *
2228  * Return value: the current @sort_column_id for this column, or -1 if
2229  *               this column can't be used for sorting.
2230  **/
2231 gint
2232 gtk_tree_view_column_get_sort_column_id (GtkTreeViewColumn *tree_column)
2233 {
2234   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);
2235
2236   return tree_column->sort_column_id;
2237 }
2238
2239 /**
2240  * gtk_tree_view_column_set_sort_indicator:
2241  * @tree_column: a #GtkTreeViewColumn
2242  * @setting: %TRUE to display an indicator that the column is sorted
2243  *
2244  * Call this function with a @setting of %TRUE to display an arrow in
2245  * the header button indicating the column is sorted. Call
2246  * gtk_tree_view_column_set_sort_order() to change the direction of
2247  * the arrow.
2248  * 
2249  **/
2250 void
2251 gtk_tree_view_column_set_sort_indicator (GtkTreeViewColumn     *tree_column,
2252                                          gboolean               setting)
2253 {
2254   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2255
2256   setting = setting != FALSE;
2257
2258   if (setting == tree_column->show_sort_indicator)
2259     return;
2260
2261   tree_column->show_sort_indicator = setting;
2262   gtk_tree_view_column_update_button (tree_column);
2263   g_object_notify (G_OBJECT (tree_column), "sort_indicator");
2264 }
2265
2266 /**
2267  * gtk_tree_view_column_get_sort_indicator:
2268  * @tree_column: a #GtkTreeViewColumn
2269  * 
2270  * Gets the value set by gtk_tree_view_column_set_sort_indicator().
2271  * 
2272  * Return value: whether the sort indicator arrow is displayed
2273  **/
2274 gboolean
2275 gtk_tree_view_column_get_sort_indicator  (GtkTreeViewColumn     *tree_column)
2276 {
2277   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
2278
2279   return tree_column->show_sort_indicator;
2280 }
2281
2282 /**
2283  * gtk_tree_view_column_set_sort_order:
2284  * @tree_column: a #GtkTreeViewColumn
2285  * @order: sort order that the sort indicator should indicate
2286  *
2287  * Changes the appearance of the sort indicator. 
2288  * 
2289  * This <emphasis>does not</emphasis> actually sort the model.  Use
2290  * gtk_tree_view_column_set_sort_column_id() if you want automatic sorting
2291  * support.  This function is primarily for custom sorting behavior, and should
2292  * be used in conjunction with gtk_tree_sortable_set_sort_column() to do
2293  * that. For custom models, the mechanism will vary. 
2294  * 
2295  * The sort indicator changes direction to indicate normal sort or reverse sort.
2296  * Note that you must have the sort indicator enabled to see anything when 
2297  * calling this function; see gtk_tree_view_column_set_sort_indicator().
2298  **/
2299 void
2300 gtk_tree_view_column_set_sort_order      (GtkTreeViewColumn     *tree_column,
2301                                           GtkSortType            order)
2302 {
2303   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2304
2305   if (order == tree_column->sort_order)
2306     return;
2307
2308   tree_column->sort_order = order;
2309   gtk_tree_view_column_update_button (tree_column);
2310   g_object_notify (G_OBJECT (tree_column), "sort_order");
2311 }
2312
2313 /**
2314  * gtk_tree_view_column_get_sort_order:
2315  * @tree_column: a #GtkTreeViewColumn
2316  * 
2317  * Gets the value set by gtk_tree_view_column_set_sort_order().
2318  * 
2319  * Return value: the sort order the sort indicator is indicating
2320  **/
2321 GtkSortType
2322 gtk_tree_view_column_get_sort_order      (GtkTreeViewColumn     *tree_column)
2323 {
2324   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);
2325
2326   return tree_column->sort_order;
2327 }
2328
2329 /**
2330  * gtk_tree_view_column_cell_set_cell_data:
2331  * @tree_column: A #GtkTreeViewColumn.
2332  * @tree_model: The #GtkTreeModel to to get the cell renderers attributes from.
2333  * @iter: The #GtkTreeIter to to get the cell renderer's attributes from.
2334  * @is_expander: %TRUE, if the row has children
2335  * @is_expanded: %TRUE, if the row has visible children
2336  * 
2337  * Sets the cell renderer based on the @tree_model and @iter.  That is, for
2338  * every attribute mapping in @tree_column, it will get a value from the set
2339  * column on the @iter, and use that value to set the attribute on the cell
2340  * renderer.  This is used primarily by the #GtkTreeView.
2341  **/
2342 void
2343 gtk_tree_view_column_cell_set_cell_data (GtkTreeViewColumn *tree_column,
2344                                          GtkTreeModel      *tree_model,
2345                                          GtkTreeIter       *iter,
2346                                          gboolean           is_expander,
2347                                          gboolean           is_expanded)
2348 {
2349   GSList *list;
2350   GValue value = { 0, };
2351   GList *cell_list;
2352
2353   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2354   g_return_if_fail (tree_column->cell_list != NULL);
2355
2356   if (tree_model == NULL)
2357     return;
2358
2359   for (cell_list = tree_column->cell_list; cell_list; cell_list = cell_list->next)
2360     {
2361       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) cell_list->data;
2362       GObject *cell = (GObject *) info->cell;
2363
2364       list = info->attributes;
2365
2366       g_object_freeze_notify (cell);
2367       g_object_set (cell, "is_expander", is_expander, "is_expanded", is_expanded, NULL);
2368
2369       while (list && list->next)
2370         {
2371           gtk_tree_model_get_value (tree_model, iter,
2372                                     GPOINTER_TO_INT (list->next->data),
2373                                     &value);
2374           g_object_set_property (cell, (gchar *) list->data, &value);
2375           g_value_unset (&value);
2376           list = list->next->next;
2377         }
2378
2379       if (info->func)
2380         (* info->func) (tree_column, info->cell, tree_model, iter, info->func_data);
2381       g_object_thaw_notify (G_OBJECT (info->cell));
2382     }
2383
2384 }
2385
2386 /**
2387  * gtk_tree_view_column_cell_get_size:
2388  * @tree_column: A #GtkTreeViewColumn.
2389  * @cell_area: The area a cell in the column will be allocated, or %NULL
2390  * @x_offset: location to return x offset of a cell relative to @cell_area, or %NULL
2391  * @y_offset: location to return y offset of a cell relative to @cell_area, or %NULL
2392  * @width: location to return width needed to render a cell, or %NULL
2393  * @height: location to return height needed to render a cell, or %NULL
2394  * 
2395  * Obtains the width and height needed to render the column.  This is used
2396  * primarily by the #GtkTreeView.
2397  **/
2398 void
2399 gtk_tree_view_column_cell_get_size (GtkTreeViewColumn *tree_column,
2400                                     GdkRectangle      *cell_area,
2401                                     gint              *x_offset,
2402                                     gint              *y_offset,
2403                                     gint              *width,
2404                                     gint              *height)
2405 {
2406   GList *list;
2407   gboolean first_cell = TRUE;
2408   gint focus_line_width;
2409
2410   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2411
2412   if (height)
2413     * height = 0;
2414   if (width)
2415     * width = 0;
2416
2417   gtk_widget_style_get (tree_column->tree_view, "focus-line-width", &focus_line_width, NULL);
2418   
2419   for (list = tree_column->cell_list; list; list = list->next)
2420     {
2421       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
2422       gboolean visible;
2423       gint new_height = 0;
2424       gint new_width = 0;
2425       g_object_get (info->cell, "visible", &visible, NULL);
2426
2427       if (visible == FALSE)
2428         continue;
2429
2430       if (first_cell == FALSE && *width)
2431         *width += tree_column->spacing;
2432
2433       gtk_cell_renderer_get_size (info->cell,
2434                                   tree_column->tree_view,
2435                                   cell_area,
2436                                   x_offset,
2437                                   y_offset,
2438                                   &new_width,
2439                                   &new_height);
2440
2441       if (height)
2442         * height = MAX (*height, new_height + focus_line_width * 2);
2443       info->requested_width = MAX (info->requested_width, new_width + focus_line_width * 2);
2444       if (width)
2445         * width += info->requested_width;
2446       first_cell = FALSE;
2447     }
2448 }
2449
2450 /* rendering, event handling and rendering focus are somewhat complicated, and
2451  * quite a bit of code.  Rather than duplicate them, we put them together to
2452  * keep the code in one place.
2453  */
2454 enum {
2455   CELL_ACTION_RENDER,
2456   CELL_ACTION_FOCUS,
2457   CELL_ACTION_EVENT
2458 };
2459
2460 static gboolean
2461 gtk_tree_view_column_cell_process_action (GtkTreeViewColumn  *tree_column,
2462                                           GdkWindow          *window,
2463                                           GdkRectangle       *background_area,
2464                                           GdkRectangle       *cell_area,
2465                                           guint               flags,
2466                                           gint                action,
2467                                           GdkRectangle       *expose_area,     /* RENDER */
2468                                           GdkRectangle       *focus_rectangle, /* FOCUS  */
2469                                           GtkCellEditable   **editable_widget, /* EVENT  */
2470                                           GdkEvent           *event,           /* EVENT  */
2471                                           gchar              *path_string)     /* EVENT  */
2472 {
2473   GList *list;
2474   GdkRectangle real_cell_area;
2475   GdkRectangle real_background_area;
2476   gint expand_cell_count = 0;
2477   gint full_requested_width = 0;
2478   gint extra_space;
2479   gint min_x, min_y, max_x, max_y;
2480   gint focus_line_width;
2481   gint dx;
2482   gint special_cells;
2483   gboolean rtl;
2484   /* If we have rtl text, we need to transform our areas */
2485   GdkRectangle rtl_cell_area;
2486   GdkRectangle rtl_background_area;
2487
2488   min_x = G_MAXINT;
2489   min_y = G_MAXINT;
2490   max_x = 0;
2491   max_y = 0;
2492
2493   rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_column->tree_view)) == GTK_TEXT_DIR_RTL);
2494   special_cells = _gtk_tree_view_column_count_special_cells (tree_column);
2495
2496   if (special_cells > 1 && action == CELL_ACTION_FOCUS)
2497     {
2498       GtkTreeViewColumnCellInfo *info = NULL;
2499       gboolean found_has_focus = FALSE;
2500
2501       /* one should have focus */
2502       for (list = tree_column->cell_list; list; list = list->next)
2503         {
2504           info = list->data;
2505           if (info && info->has_focus)
2506             {
2507               found_has_focus = TRUE;
2508               break;
2509             }
2510         }
2511
2512       if (!found_has_focus)
2513         {
2514           /* give the first one focus */
2515           info = gtk_tree_view_column_cell_first (tree_column)->data;
2516           info->has_focus = TRUE;
2517         }
2518     }
2519
2520   gtk_widget_style_get (GTK_WIDGET (tree_column->tree_view),
2521                         "focus-line-width", &focus_line_width,
2522                         NULL);
2523
2524   real_cell_area = *cell_area;
2525   real_background_area = *background_area;
2526   /* HUH?  dx = real_cell_area.x - real_background_area.x - focus_line_width; */
2527
2528   real_cell_area.x += focus_line_width;
2529
2530   /* Find out how many extra space we have to allocate */
2531   for (list = tree_column->cell_list; list; list = list->next)
2532     {
2533       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *)list->data;
2534
2535       if (! info->cell->visible)
2536         continue;
2537
2538       if (info->expand == TRUE)
2539         expand_cell_count ++;
2540       full_requested_width += info->requested_width;
2541     }
2542
2543   extra_space = cell_area->width - full_requested_width;
2544
2545   if (extra_space < 0)
2546     extra_space = 0;
2547   else if (extra_space > 0 && expand_cell_count > 0)
2548     extra_space /= expand_cell_count;
2549
2550   /* iterate list for GTK_PACK_START cells */
2551   for (list = tree_column->cell_list; list; list = list->next)
2552     {
2553       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
2554
2555       if (info->pack == GTK_PACK_END)
2556         continue;
2557
2558       if (! info->cell->visible)
2559         continue;
2560
2561       if (info->has_focus)
2562         flags |= GTK_CELL_RENDERER_FOCUSED;
2563
2564       real_background_area.width = info->requested_width +
2565         (info->expand?extra_space:0);
2566       info->real_width = real_background_area.width;
2567
2568       real_cell_area.width = real_background_area.width;
2569       real_cell_area.width -= 2 * focus_line_width;
2570
2571       rtl_cell_area = real_cell_area;
2572       rtl_background_area = real_background_area;
2573       if (rtl)
2574         {
2575           rtl_cell_area.x = cell_area->x + cell_area->width - (real_cell_area.x - cell_area->x) - real_cell_area.width;
2576           rtl_background_area.x = background_area->x + background_area->width - (real_background_area.x - background_area->x) - real_background_area.width;
2577         }
2578
2579       /* RENDER */
2580       if (action == CELL_ACTION_RENDER)
2581         {
2582           gtk_cell_renderer_render (info->cell,
2583                                     window,
2584                                     tree_column->tree_view,
2585                                     &rtl_background_area,
2586                                     &rtl_cell_area,
2587                                     expose_area,
2588                                     flags);
2589         }
2590
2591       /* FOCUS */
2592       else if (action == CELL_ACTION_FOCUS)
2593         {
2594           gint x_offset, y_offset, width, height;
2595
2596           gtk_cell_renderer_get_size (info->cell,
2597                                       tree_column->tree_view,
2598                                       &rtl_cell_area,
2599                                       &x_offset, &y_offset,
2600                                       &width, &height);
2601
2602           if (special_cells > 1)
2603             {
2604               if (info->has_focus)
2605                 {
2606                   min_x = rtl_cell_area.x + x_offset;
2607                   max_x = min_x + width;
2608                   min_y = rtl_cell_area.y + y_offset;
2609                   max_y = min_y + height;
2610                 }
2611             }
2612           else
2613             {
2614               if (min_x > (rtl_cell_area.x + x_offset))
2615                 min_x = rtl_cell_area.x + x_offset;
2616               if (max_x < rtl_cell_area.x + x_offset + width)
2617                 max_x = rtl_cell_area.x + x_offset + width;
2618               if (min_y > (rtl_cell_area.y + y_offset))
2619                 min_y = rtl_cell_area.y + y_offset;
2620               if (max_y < rtl_cell_area.y + y_offset + height)
2621                 max_y = rtl_cell_area.y + y_offset + height;
2622             }
2623         }
2624       /* EVENT */
2625       else if (action == CELL_ACTION_EVENT)
2626         {
2627           gboolean try_event = FALSE;
2628
2629           if (event)
2630             {
2631               if (special_cells == 1)
2632                 {
2633                   /* only 1 activatable cell -> whole column can activate */
2634                   if (cell_area->x <= ((GdkEventButton *)event)->x &&
2635                       cell_area->x + cell_area->width > ((GdkEventButton *)event)->x)
2636                     try_event = TRUE;
2637                 }
2638               else if (rtl_cell_area.x <= ((GdkEventButton *)event)->x &&
2639                   rtl_cell_area.x + rtl_cell_area.width > ((GdkEventButton *)event)->x)
2640                   /* only activate cell if the user clicked on an individual
2641                    * cell
2642                    */
2643                 try_event = TRUE;
2644             }
2645           else if (special_cells > 1 && info->has_focus)
2646             try_event = TRUE;
2647           else if (special_cells == 1)
2648             try_event = TRUE;
2649
2650           if (try_event)
2651             {
2652               gboolean visible, mode;
2653
2654               g_object_get (info->cell,
2655                             "visible", &visible,
2656                             "mode", &mode,
2657                             NULL);
2658               if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2659                 {
2660                   if (gtk_cell_renderer_activate (info->cell,
2661                                                   event,
2662                                                   tree_column->tree_view,
2663                                                   path_string,
2664                                                   background_area,
2665                                                   cell_area,
2666                                                   flags))
2667                     {
2668                       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2669                       return TRUE;
2670                     }
2671                 }
2672               else if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2673                 {
2674                   *editable_widget =
2675                     gtk_cell_renderer_start_editing (info->cell,
2676                                                      event,
2677                                                      tree_column->tree_view,
2678                                                      path_string,
2679                                                      background_area,
2680                                                      cell_area,
2681                                                      flags);
2682
2683                   if (*editable_widget != NULL)
2684                     {
2685                       g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
2686                       info->in_editing_mode = TRUE;
2687                       gtk_tree_view_column_focus_cell (tree_column, info->cell);
2688                       
2689                       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2690
2691                       return TRUE;
2692                     }
2693                 }
2694             }
2695         }
2696
2697       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2698
2699       real_cell_area.x += (info->real_width + tree_column->spacing);
2700       real_background_area.x += (info->real_width + tree_column->spacing);
2701     }
2702
2703   /* iterate list for PACK_END cells */
2704   for (list = g_list_last (tree_column->cell_list); list; list = list->prev)
2705     {
2706       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
2707
2708       if (info->pack == GTK_PACK_START)
2709         continue;
2710
2711       if (! info->cell->visible)
2712         continue;
2713
2714       if (info->has_focus)
2715         flags |= GTK_CELL_RENDERER_FOCUSED;
2716
2717       real_background_area.width = info->requested_width +
2718         (info->expand?extra_space:0);
2719       info->real_width = real_background_area.width;
2720
2721       real_cell_area.width = real_background_area.width;
2722       real_cell_area.width -= 2 * focus_line_width;
2723
2724       rtl_cell_area = real_cell_area;
2725       rtl_background_area = real_background_area;
2726       if (rtl)
2727         {
2728           rtl_cell_area.x = cell_area->x + cell_area->width - (real_cell_area.x - cell_area->x) - real_cell_area.width;
2729           rtl_background_area.x = background_area->x + background_area->width - (real_background_area.x - background_area->x) - real_background_area.width;
2730         }
2731
2732       /* RENDER */
2733       if (action == CELL_ACTION_RENDER)
2734         {
2735           gtk_cell_renderer_render (info->cell,
2736                                     window,
2737                                     tree_column->tree_view,
2738                                     &rtl_background_area,
2739                                     &rtl_cell_area,
2740                                     expose_area,
2741                                     flags);
2742         }
2743       /* FOCUS */
2744       else if (action == CELL_ACTION_FOCUS)
2745         {
2746           gint x_offset, y_offset, width, height;
2747
2748           gtk_cell_renderer_get_size (info->cell,
2749                                       tree_column->tree_view,
2750                                       &rtl_cell_area,
2751                                       &x_offset, &y_offset,
2752                                       &width, &height);
2753
2754           if (special_cells > 1)
2755             {
2756               if (info->has_focus)
2757                 {
2758                   min_x = rtl_cell_area.x + x_offset;
2759                   max_x = min_x + width;
2760                   min_y = rtl_cell_area.y + y_offset;
2761                   max_y = min_y + height;
2762                 }
2763             }
2764           else
2765             {
2766               if (min_x > (rtl_cell_area.x + x_offset))
2767                 min_x = rtl_cell_area.x + x_offset;
2768               if (max_x < rtl_cell_area.x + x_offset + width)
2769                 max_x = rtl_cell_area.x + x_offset + width;
2770               if (min_y > (rtl_cell_area.y + y_offset))
2771                 min_y = rtl_cell_area.y + y_offset;
2772               if (max_y < rtl_cell_area.y + y_offset + height)
2773                 max_y = rtl_cell_area.y + y_offset + height;
2774             }
2775         }
2776       /* EVENT */
2777       else if (action == CELL_ACTION_EVENT)
2778         {
2779           gboolean try_event = FALSE;
2780
2781           if (event)
2782             {
2783               if (special_cells == 1)
2784                 {
2785                   /* only 1 activatable cell -> whole column can activate */
2786                   if (cell_area->x <= ((GdkEventButton *)event)->x &&
2787                       cell_area->x + cell_area->width > ((GdkEventButton *)event)->x)
2788                     try_event = TRUE;
2789                 }
2790               else if (real_cell_area.x <= ((GdkEventButton *)event)->x &&
2791                   real_cell_area.x + real_cell_area.width > ((GdkEventButton *)event)->x)
2792                 /* only activate cell if the user clicked on an individual
2793                  * cell
2794                  */
2795                 try_event = TRUE;
2796             }
2797           else if (special_cells > 1 && info->has_focus)
2798             try_event = TRUE;
2799           else if (special_cells == 1)
2800             try_event = TRUE;
2801
2802           if (try_event)
2803             {
2804               gboolean visible, mode;
2805
2806               g_object_get (info->cell,
2807                             "visible", &visible,
2808                             "mode", &mode,
2809                             NULL);
2810               if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2811                 {
2812                   if (gtk_cell_renderer_activate (info->cell,
2813                                                   event,
2814                                                   tree_column->tree_view,
2815                                                   path_string,
2816                                                   background_area,
2817                                                   cell_area,
2818                                                   flags))
2819                     {
2820                       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2821                       return TRUE;
2822                     }
2823                 }
2824               else if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2825                 {
2826                   *editable_widget =
2827                     gtk_cell_renderer_start_editing (info->cell,
2828                                                      event,
2829                                                      tree_column->tree_view,
2830                                                      path_string,
2831                                                      background_area,
2832                                                      cell_area,
2833                                                      flags);
2834
2835                   if (*editable_widget != NULL)
2836                     {
2837                       g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
2838                       info->in_editing_mode = TRUE;
2839                       gtk_tree_view_column_focus_cell (tree_column, info->cell);
2840
2841                       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2842                       return TRUE;
2843                     }
2844                 }
2845             }
2846         }
2847
2848       flags &= ~GTK_CELL_RENDERER_FOCUSED;
2849
2850       real_cell_area.x += (info->real_width + tree_column->spacing);
2851       real_background_area.x += (info->real_width + tree_column->spacing);
2852     }
2853
2854   /* fill focus_rectangle when required */
2855   if (action == CELL_ACTION_FOCUS)
2856     {
2857       if (min_x >= max_x || min_y >= max_y)
2858         {
2859           *focus_rectangle = *cell_area;
2860           /* don't change the focus_rectangle, just draw it nicely inside
2861            * the cell area */
2862         }
2863       else
2864         {
2865           focus_rectangle->x = min_x - focus_line_width;
2866           focus_rectangle->y = min_y - focus_line_width;
2867           focus_rectangle->width = (max_x - min_x) + 2 * focus_line_width;
2868           focus_rectangle->height = (max_y - min_y) + 2 * focus_line_width;
2869         }
2870     }
2871
2872   return FALSE;
2873 }
2874
2875 /**
2876  * gtk_tree_view_column_cell_render:
2877  * @tree_column: A #GtkTreeViewColumn.
2878  * @window: a #GdkDrawable to draw to
2879  * @background_area: entire cell area (including tree expanders and maybe padding on the sides)
2880  * @cell_area: area normally rendered by a cell renderer
2881  * @expose_area: area that actually needs updating
2882  * @flags: flags that affect rendering
2883  * 
2884  * Renders the cell contained by #tree_column. This is used primarily by the
2885  * #GtkTreeView.
2886  **/
2887 void
2888 _gtk_tree_view_column_cell_render (GtkTreeViewColumn *tree_column,
2889                                    GdkWindow         *window,
2890                                    GdkRectangle      *background_area,
2891                                    GdkRectangle      *cell_area,
2892                                    GdkRectangle      *expose_area,
2893                                    guint              flags)
2894 {
2895   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
2896   g_return_if_fail (background_area != NULL);
2897   g_return_if_fail (cell_area != NULL);
2898   g_return_if_fail (expose_area != NULL);
2899
2900   gtk_tree_view_column_cell_process_action (tree_column,
2901                                             window,
2902                                             background_area,
2903                                             cell_area,
2904                                             flags,
2905                                             CELL_ACTION_RENDER,
2906                                             expose_area,
2907                                             NULL, NULL, NULL, NULL);
2908 }
2909
2910 gboolean
2911 _gtk_tree_view_column_cell_event (GtkTreeViewColumn  *tree_column,
2912                                   GtkCellEditable   **editable_widget,
2913                                   GdkEvent           *event,
2914                                   gchar              *path_string,
2915                                   GdkRectangle       *background_area,
2916                                   GdkRectangle       *cell_area,
2917                                   guint               flags)
2918 {
2919   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
2920
2921   return gtk_tree_view_column_cell_process_action (tree_column,
2922                                                    NULL,
2923                                                    background_area,
2924                                                    cell_area,
2925                                                    flags,
2926                                                    CELL_ACTION_EVENT,
2927                                                    NULL, NULL,
2928                                                    editable_widget,
2929                                                    event,
2930                                                    path_string);
2931 }
2932
2933 /* cell list manipulation */
2934 static GList *
2935 gtk_tree_view_column_cell_first (GtkTreeViewColumn *tree_column)
2936 {
2937   GList *list = tree_column->cell_list;
2938
2939   /* first GTK_PACK_START cell we find */
2940   for ( ; list; list = list->next)
2941     {
2942       GtkTreeViewColumnCellInfo *info = list->data;
2943       if (info->pack == GTK_PACK_START)
2944         return list;
2945     }
2946
2947   /* hmm, else the *last* GTK_PACK_END cell */
2948   list = g_list_last (tree_column->cell_list);
2949
2950   for ( ; list; list = list->prev)
2951     {
2952       GtkTreeViewColumnCellInfo *info = list->data;
2953       if (info->pack == GTK_PACK_END)
2954         return list;
2955     }
2956
2957   return NULL;
2958 }
2959
2960 static GList *
2961 gtk_tree_view_column_cell_last (GtkTreeViewColumn *tree_column)
2962 {
2963   GList *list = tree_column->cell_list;
2964
2965   /* *first* GTK_PACK_END cell we find */
2966   for ( ; list ; list = list->next)
2967     {
2968       GtkTreeViewColumnCellInfo *info = list->data;
2969       if (info->pack == GTK_PACK_END)
2970         return list;
2971     }
2972
2973   /* hmm, else the last GTK_PACK_START cell */
2974   list = g_list_last (tree_column->cell_list);
2975
2976   for ( ; list; list = list->prev)
2977     {
2978       GtkTreeViewColumnCellInfo *info = list->data;
2979       if (info->pack == GTK_PACK_START)
2980         return list;
2981     }
2982
2983   return NULL;
2984 }
2985
2986 static GList *
2987 gtk_tree_view_column_cell_next (GtkTreeViewColumn *tree_column,
2988                                 GList             *current)
2989 {
2990   GList *list;
2991   GtkTreeViewColumnCellInfo *info = current->data;
2992
2993   if (info->pack == GTK_PACK_START)
2994     {
2995       for (list = current->next; list; list = list->next)
2996         {
2997           GtkTreeViewColumnCellInfo *inf = list->data;
2998           if (inf->pack == GTK_PACK_START)
2999             return list;
3000         }
3001
3002       /* out of GTK_PACK_START cells, get *last* GTK_PACK_END one */
3003       list = g_list_last (tree_column->cell_list);
3004       for (; list; list = list->prev)
3005         {
3006           GtkTreeViewColumnCellInfo *inf = list->data;
3007           if (inf->pack == GTK_PACK_END)
3008             return list;
3009         }
3010     }
3011
3012   for (list = current->prev; list; list = list->prev)
3013     {
3014       GtkTreeViewColumnCellInfo *inf = list->data;
3015       if (inf->pack == GTK_PACK_END)
3016         return list;
3017     }
3018
3019   return NULL;
3020 }
3021
3022 static GList *
3023 gtk_tree_view_column_cell_prev (GtkTreeViewColumn *tree_column,
3024                                 GList             *current)
3025 {
3026   GList *list;
3027   GtkTreeViewColumnCellInfo *info = current->data;
3028
3029   if (info->pack == GTK_PACK_END)
3030     {
3031       for (list = current->next; list; list = list->next)
3032         {
3033           GtkTreeViewColumnCellInfo *inf = list->data;
3034           if (inf->pack == GTK_PACK_END)
3035             return list;
3036         }
3037
3038       /* out of GTK_PACK_END, get last GTK_PACK_START one */
3039       list = g_list_last (tree_column->cell_list);
3040       for ( ; list; list = list->prev)
3041         {
3042           GtkTreeViewColumnCellInfo *inf = list->data;
3043           if (inf->pack == GTK_PACK_START)
3044             return list;
3045         }
3046     }
3047
3048   for (list = current->prev; list; list = list->prev)
3049     {
3050       GtkTreeViewColumnCellInfo *inf = list->data;
3051       if (inf->pack == GTK_PACK_START)
3052         return list;
3053     }
3054
3055   return NULL;
3056 }
3057
3058 gboolean
3059 _gtk_tree_view_column_cell_focus (GtkTreeViewColumn *tree_column,
3060                                   gint               direction,
3061                                   gboolean           left,
3062                                   gboolean           right)
3063 {
3064   gint count;
3065
3066   count = _gtk_tree_view_column_count_special_cells (tree_column);
3067
3068   /* if we are the current focus column and have multiple editable cells,
3069    * try to select the next one, else move the focus to the next column
3070    */
3071   if (GTK_TREE_VIEW (tree_column->tree_view)->priv->focus_column == tree_column)
3072     {
3073       if (count > 1)
3074         {
3075           GList *next, *prev;
3076           GList *list = tree_column->cell_list;
3077           GtkTreeViewColumnCellInfo *info = NULL;
3078
3079           /* find current focussed cell */
3080           for ( ; list; list = list->next)
3081             {
3082               info = list->data;
3083               if (info->has_focus)
3084                 break;
3085             }
3086
3087           /* not a focussed cell in the focus column? */
3088           if (!list || !info || !info->has_focus)
3089             return FALSE;
3090
3091           next = gtk_tree_view_column_cell_next (tree_column, list);
3092           prev = gtk_tree_view_column_cell_prev (tree_column, list);
3093
3094           info->has_focus = FALSE;
3095           if (direction > 0 && next)
3096             {
3097               info = next->data;
3098               info->has_focus = TRUE;
3099               return TRUE;
3100             }
3101           else if (direction > 0 && !next && !right)
3102             {
3103               /* keep focus on latest cell */
3104               info = gtk_tree_view_column_cell_last (tree_column)->data;
3105               info->has_focus = TRUE;
3106               return TRUE;
3107             }
3108           else if (direction < 0 && prev)
3109             {
3110               info = prev->data;
3111               info->has_focus = TRUE;
3112               return TRUE;
3113             }
3114           else if (direction < 0 && !prev && !left)
3115             {
3116               /* keep focus on first cell */
3117               info = gtk_tree_view_column_cell_first (tree_column)->data;
3118               info->has_focus = TRUE;
3119               return TRUE;
3120             }
3121         }
3122       return FALSE;
3123     }
3124
3125   /* we get focus, if we have multiple editable cells, give the correct one
3126    * focus
3127    */
3128   if (count > 1)
3129     {
3130       GList *list = tree_column->cell_list;
3131
3132       /* clear focus first */
3133       for ( ; list ; list = list->next)
3134         {
3135           GtkTreeViewColumnCellInfo *info = list->data;
3136           if (info->has_focus)
3137             info->has_focus = FALSE;
3138         }
3139
3140       if (direction > 0)
3141         ((GtkTreeViewColumnCellInfo *)gtk_tree_view_column_cell_first (tree_column)->data)->has_focus = TRUE;
3142       else if (direction < 0)
3143         ((GtkTreeViewColumnCellInfo *)gtk_tree_view_column_cell_last (tree_column)->data)->has_focus = TRUE;
3144     }
3145   return TRUE;
3146 }
3147
3148 void
3149 _gtk_tree_view_column_cell_draw_focus (GtkTreeViewColumn       *tree_column,
3150                                        GdkWindow               *window,
3151                                        GdkRectangle            *background_area,
3152                                        GdkRectangle            *cell_area,
3153                                        GdkRectangle            *expose_area,
3154                                        guint                    flags)
3155 {
3156   gint focus_line_width;
3157   GtkStateType cell_state;
3158   
3159   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
3160   gtk_widget_style_get (GTK_WIDGET (tree_column->tree_view),
3161                         "focus-line-width", &focus_line_width, NULL);
3162   if (tree_column->editable_widget)
3163     {
3164       /* This function is only called on the editable row when editing.
3165        */
3166 #if 0
3167       gtk_paint_focus (tree_column->tree_view->style,
3168                        window,
3169                        GTK_WIDGET_STATE (tree_column->tree_view),
3170                        NULL,
3171                        tree_column->tree_view,
3172                        "treeview",
3173                        cell_area->x - focus_line_width,
3174                        cell_area->y - focus_line_width,
3175                        cell_area->width + 2 * focus_line_width,
3176                        cell_area->height + 2 * focus_line_width);
3177 #endif      
3178     }
3179   else
3180     {
3181       GdkRectangle focus_rectangle;
3182       gtk_tree_view_column_cell_process_action (tree_column,
3183                                                 window,
3184                                                 background_area,
3185                                                 cell_area,
3186                                                 flags,
3187                                                 CELL_ACTION_FOCUS,
3188                                                 expose_area,
3189                                                 &focus_rectangle,
3190                                                 NULL, NULL, NULL);
3191
3192       cell_state = flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
3193               (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
3194               (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL));
3195       gtk_paint_focus (tree_column->tree_view->style,
3196                        window,
3197                        cell_state,
3198                        NULL,
3199                        tree_column->tree_view,
3200                        "treeview",
3201                        focus_rectangle.x,
3202                        focus_rectangle.y,
3203                        focus_rectangle.width,
3204                        focus_rectangle.height);
3205     }
3206 }
3207
3208 /**
3209  * gtk_tree_view_column_cell_is_visible:
3210  * @tree_column: A #GtkTreeViewColumn
3211  * 
3212  * Returns #TRUE if any of the cells packed into the @tree_column are visible.
3213  * For this to be meaningful, you must first initialize the cells with
3214  * gtk_tree_view_column_cell_set_cell_data()
3215  * 
3216  * Return value: #TRUE, if any of the cells packed into the @tree_column are currently visible
3217  **/
3218 gboolean
3219 gtk_tree_view_column_cell_is_visible (GtkTreeViewColumn *tree_column)
3220 {
3221   GList *list;
3222
3223   g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);
3224
3225   for (list = tree_column->cell_list; list; list = list->next)
3226     {
3227       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
3228
3229       if (info->cell->visible)
3230         return TRUE;
3231     }
3232
3233   return FALSE;
3234 }
3235
3236 /**
3237  * gtk_tree_view_column_focus_cell:
3238  * @tree_column: A #GtkTreeViewColumn
3239  * @cell: A #GtkCellRenderer
3240  *
3241  * Sets the current keyboard focus to be at @cell, if the column contains
3242  * 2 or more editable and activatable cells.
3243  *
3244  * Since: 2.2
3245  **/
3246 void
3247 gtk_tree_view_column_focus_cell (GtkTreeViewColumn *tree_column,
3248                                  GtkCellRenderer   *cell)
3249 {
3250   GList *list;
3251   gboolean found_cell = FALSE;
3252
3253   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
3254   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
3255
3256   if (_gtk_tree_view_column_count_special_cells (tree_column) < 2)
3257     return;
3258
3259   for (list = tree_column->cell_list; list; list = list->next)
3260     {
3261       GtkTreeViewColumnCellInfo *info = list->data;
3262
3263       if (info->cell == cell)
3264         {
3265           info->has_focus = TRUE;
3266           found_cell = TRUE;
3267           break;
3268         }
3269     }
3270
3271   if (found_cell)
3272     {
3273       for (list = tree_column->cell_list; list; list = list->next)
3274         {
3275           GtkTreeViewColumnCellInfo *info = list->data;
3276
3277           if (info->cell != cell)
3278             info->has_focus = FALSE;
3279         }
3280
3281       /* FIXME: redraw? */
3282     }
3283 }
3284
3285 void
3286 _gtk_tree_view_column_cell_set_dirty (GtkTreeViewColumn *tree_column,
3287                                       gboolean           install_handler)
3288 {
3289   GList *list;
3290
3291   for (list = tree_column->cell_list; list; list = list->next)
3292     {
3293       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
3294
3295       info->requested_width = 0;
3296     }
3297   tree_column->dirty = TRUE;
3298   tree_column->resized_width = MAX (tree_column->requested_width, tree_column->button_request);
3299   tree_column->requested_width = -1;
3300   tree_column->width = 0;
3301
3302   if (tree_column->tree_view &&
3303       GTK_WIDGET_REALIZED (tree_column->tree_view))
3304     {
3305       if (install_handler)
3306         _gtk_tree_view_install_mark_rows_col_dirty (GTK_TREE_VIEW (tree_column->tree_view));
3307       else
3308         GTK_TREE_VIEW (tree_column->tree_view)->priv->mark_rows_col_dirty = TRUE;
3309       gtk_widget_queue_resize (tree_column->tree_view);
3310     }
3311 }
3312
3313 void
3314 _gtk_tree_view_column_start_editing (GtkTreeViewColumn *tree_column,
3315                                      GtkCellEditable   *cell_editable)
3316 {
3317   g_return_if_fail (tree_column->editable_widget == NULL);
3318
3319   tree_column->editable_widget = cell_editable;
3320 }
3321
3322 void
3323 _gtk_tree_view_column_stop_editing (GtkTreeViewColumn *tree_column)
3324 {
3325   GList *list;
3326
3327   g_return_if_fail (tree_column->editable_widget != NULL);
3328
3329   tree_column->editable_widget = NULL;
3330   for (list = tree_column->cell_list; list; list = list->next)
3331     ((GtkTreeViewColumnCellInfo *)list->data)->in_editing_mode = FALSE;
3332 }
3333
3334 void
3335 _gtk_tree_view_column_get_neighbor_sizes (GtkTreeViewColumn *column,
3336                                           GtkCellRenderer   *cell,
3337                                           gint              *left,
3338                                           gint              *right)
3339 {
3340   GList *list;
3341
3342   if (left)
3343     {
3344       *left = 0;
3345       list = gtk_tree_view_column_cell_first (column);
3346
3347       for (; list; list = gtk_tree_view_column_cell_next (column, list))
3348         {
3349           GtkTreeViewColumnCellInfo *info =
3350             (GtkTreeViewColumnCellInfo *)list->data;
3351
3352           if (info->cell == cell)
3353             break;
3354
3355           if (info->cell->visible)
3356             *left += info->real_width;
3357         }
3358     }
3359
3360   if (right)
3361     {
3362       GList *next;
3363
3364       *right = 0;
3365       list = gtk_tree_view_column_cell_first (column);
3366
3367       for (; list; list = gtk_tree_view_column_cell_next (column, list))
3368         {
3369           GtkTreeViewColumnCellInfo *info =
3370             (GtkTreeViewColumnCellInfo *)list->data;
3371
3372           if (info->cell == cell)
3373             break;
3374         }
3375
3376       /* skip cell */
3377       next = gtk_tree_view_column_cell_next (column, list);
3378       if (list && next)
3379         {
3380           list = next;
3381           for ( ; list; list = gtk_tree_view_column_cell_next (column, list))
3382             {
3383               GtkTreeViewColumnCellInfo *info =
3384                 (GtkTreeViewColumnCellInfo *)list->data;
3385
3386               if (info->cell->visible)
3387                 *right += info->real_width;
3388             }
3389         }
3390     }
3391 }
3392
3393 gboolean
3394 gtk_tree_view_column_cell_get_position (GtkTreeViewColumn *tree_column,
3395                                         GtkCellRenderer   *cell_renderer,
3396                                         gint              *start_pos,
3397                                         gint              *width)
3398 {
3399   GList *list;
3400   gint current_x = 0;
3401   gboolean found_cell = FALSE;
3402   GtkTreeViewColumnCellInfo *cellinfo = NULL;
3403
3404   list = gtk_tree_view_column_cell_first (tree_column);
3405   for (; list; list = gtk_tree_view_column_cell_next (tree_column, list))
3406     {
3407       cellinfo = list->data;
3408       if (cellinfo->cell == cell_renderer)
3409         {
3410           found_cell = TRUE;
3411           break;
3412         }
3413
3414       if (cellinfo->cell->visible)
3415         current_x += cellinfo->real_width;
3416     }
3417
3418   if (found_cell)
3419     {
3420       if (start_pos)
3421         *start_pos = current_x;
3422       if (width)
3423         *width = cellinfo->real_width;
3424     }
3425
3426   return found_cell;
3427 }