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