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