gtktreeviewcolumn.c 61.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* gtktreeviewcolumn.c
 * Copyright (C) 2000  Red Hat, Inc.,  Jonathan Blandford <jrb@redhat.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "gtktreeviewcolumn.h"
21
#include "gtktreeview.h"
22 23 24 25
#include "gtktreeprivate.h"
#include "gtksignal.h"
#include "gtkbutton.h"
#include "gtkalignment.h"
26
#include "gtklabel.h"
Havoc Pennington's avatar
Havoc Pennington committed
27 28
#include "gtkhbox.h"
#include "gtkarrow.h"
29
#include "gtkintl.h"
30
#include <string.h>
Jonathan Blandford's avatar
Jonathan Blandford committed
31

32 33 34 35 36 37 38 39 40 41 42 43 44
enum
{
  PROP_0,
  
  PROP_CELL_RENDERER,
  PROP_VISIBLE,
  PROP_SIZING,
  PROP_WIDTH,
  PROP_MIN_WIDTH,
  PROP_MAX_WIDTH,
  PROP_TITLE,
  PROP_CLICKABLE,
  PROP_WIDGET,
Havoc Pennington's avatar
Havoc Pennington committed
45
  PROP_ALIGNMENT,
46
  PROP_REORDERABLE,
Havoc Pennington's avatar
Havoc Pennington committed
47 48
  PROP_SORT_INDICATOR,
  PROP_SORT_ORDER
49 50 51 52
};

enum
{
53 54 55 56 57
  CLICKED,
  LAST_SIGNAL
};


58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
/* Type methods */
static void gtk_tree_view_column_init                          (GtkTreeViewColumn       *tree_column);
static void gtk_tree_view_column_class_init                    (GtkTreeViewColumnClass  *klass);

/* GObject methods */
static void gtk_tree_view_column_set_property                  (GObject                 *object,
								guint                    prop_id,
								const GValue            *value,
								GParamSpec              *pspec);
static void gtk_tree_view_column_get_property                  (GObject                 *object,
								guint                    prop_id,
								GValue                  *value,
								GParamSpec              *pspec);
static void gtk_tree_view_column_finalize                      (GObject                 *object);

/* Button handling code */ 
static void gtk_tree_view_column_create_button                 (GtkTreeViewColumn       *tree_column);
static void gtk_tree_view_column_update_button                 (GtkTreeViewColumn       *tree_column);

/* Button signal handlers */
78
static gint gtk_tree_view_column_button_event                  (GtkWidget               *widget,
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
								GdkEvent                *event,
								gpointer                 data);
static void gtk_tree_view_column_button_realize                (GtkWidget               *widget,
								gpointer                 data);
static void gtk_tree_view_column_button_clicked                (GtkWidget               *widget,
								gpointer                 data);

/* Property handlers */
static void gtk_tree_view_model_sort_column_changed            (GtkTreeSortable         *sortable,
								GtkTreeViewColumn       *tree_column);

/* Internal functions */
static void gtk_tree_view_column_sort                          (GtkTreeViewColumn       *tree_column,
								gpointer                 data);
static void gtk_tree_view_column_setup_sort_column_id_callback (GtkTreeViewColumn       *tree_column);
static void gtk_tree_view_column_set_attributesv               (GtkTreeViewColumn       *tree_column,
								va_list                  args);


98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123


static GtkObjectClass *parent_class = NULL;
static guint tree_column_signals[LAST_SIGNAL] = { 0 };


GtkType
gtk_tree_view_column_get_type (void)
{
  static GtkType tree_column_type = 0;

  if (!tree_column_type)
    {
      static const GTypeInfo tree_column_info =
      {
	sizeof (GtkTreeViewColumnClass),
	NULL,		/* base_init */
	NULL,		/* base_finalize */
	(GClassInitFunc) gtk_tree_view_column_class_init,
	NULL,		/* class_finalize */
	NULL,		/* class_data */
	sizeof (GtkTreeViewColumn),
	0,
	(GInstanceInitFunc) gtk_tree_view_column_init,
      };

124
      tree_column_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkTreeViewColumn", &tree_column_info, 0);
125 126 127 128 129 130 131 132
    }

  return tree_column_type;
}

static void
gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class)
{
133
  GObjectClass *object_class;
134

135
  object_class = (GObjectClass*) class;
136 137 138

  parent_class = g_type_class_peek_parent (class);

139
  class->clicked = NULL;
140

141
  object_class->finalize = gtk_tree_view_column_finalize;
142 143 144
  object_class->set_property = gtk_tree_view_column_set_property;
  object_class->get_property = gtk_tree_view_column_get_property;
  
145
  tree_column_signals[CLICKED] =
146 147 148 149
    g_signal_newc ("clicked",
                   GTK_CLASS_TYPE (object_class),
                   G_SIGNAL_RUN_LAST,
                   G_STRUCT_OFFSET (GtkTreeViewColumnClass, clicked),
150 151
		   NULL, NULL,
		   gtk_marshal_VOID__VOID,
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
                   GTK_TYPE_NONE, 0);

  g_object_class_install_property (object_class,
                                   PROP_CELL_RENDERER,
                                   g_param_spec_object ("cell_renderer",
                                                        _("Cell renderer"),
                                                        _("Cell renderer object to use for rendering the cell"),
                                                        GTK_TYPE_CELL_RENDERER,
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
  
  g_object_class_install_property (object_class,
                                   PROP_VISIBLE,
                                   g_param_spec_boolean ("visible",
                                                        _("Visible"),
                                                        _("Whether to display the colomn"),
                                                         TRUE,
                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));
  
  g_object_class_install_property (object_class,
                                   PROP_SIZING,
                                   g_param_spec_enum ("sizing",
                                                      _("Sizing"),
                                                      _("Resize mode of the column"),
                                                      GTK_TYPE_TREE_VIEW_COLUMN_SIZING,
                                                      GTK_TREE_VIEW_COLUMN_AUTOSIZE,
                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
  
  g_object_class_install_property (object_class,
                                   PROP_WIDTH,
                                   g_param_spec_int ("width",
                                                     _("Width"),
                                                     _("Current width of the column"),
                                                     1,
                                                     G_MAXINT,
                                                     1, /* not useful */
                                                     G_PARAM_READABLE | G_PARAM_WRITABLE));

  g_object_class_install_property (object_class,
                                   PROP_MIN_WIDTH,
                                   g_param_spec_int ("min_width",
                                                     _("Minimum Width"),
                                                     _("Minimum allowed width of the column"),
                                                     -1,
                                                     G_MAXINT,
                                                     1,
                                                     G_PARAM_READABLE | G_PARAM_WRITABLE));

  g_object_class_install_property (object_class,
                                   PROP_MAX_WIDTH,
                                   g_param_spec_int ("max_width",
                                                     _("Maximum Width"),
                                                     _("Maximum allowed width of the column"),
                                                     -1,
                                                     G_MAXINT,
                                                     G_MAXINT,
                                                     G_PARAM_READABLE | G_PARAM_WRITABLE));

  g_object_class_install_property (object_class,
                                   PROP_TITLE,
                                   g_param_spec_string ("title",
                                                        _("Title"),
                                                        _("Title to appear in column header"),
                                                        "",
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
  
  g_object_class_install_property (object_class,
                                   PROP_CLICKABLE,
                                   g_param_spec_boolean ("clickable",
                                                        _("Clickable"),
                                                        _("Whether the header can be clicked"),
                                                         TRUE,
                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));
  

  g_object_class_install_property (object_class,
                                   PROP_WIDGET,
                                   g_param_spec_object ("widget",
                                                        _("Widget"),
                                                        _("Widget to put in column header button instead of column title"),
                                                        GTK_TYPE_WIDGET,
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));

  g_object_class_install_property (object_class,
Havoc Pennington's avatar
Havoc Pennington committed
235 236 237
                                   PROP_ALIGNMENT,
                                   g_param_spec_float ("alignment",
                                                       _("Alignment"),
238
                                                       _("X Alignment of the column header text or widget"),
Havoc Pennington's avatar
Havoc Pennington committed
239 240 241 242 243
                                                       0.0,
                                                       1.0,
                                                       0.5,
                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));

244 245 246 247 248 249 250 251
  g_object_class_install_property (object_class,
                                   PROP_REORDERABLE,
                                   g_param_spec_boolean ("reorderable",
							 _("Reorderable"),
							 _("Wether the column can be reordered around the headers"),
							 FALSE,
							 G_PARAM_READABLE | G_PARAM_WRITABLE));

Havoc Pennington's avatar
Havoc Pennington committed
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
  g_object_class_install_property (object_class,
                                   PROP_SORT_INDICATOR,
                                   g_param_spec_boolean ("sort_indicator",
                                                        _("Sort indicator"),
                                                        _("Whether to show a sort indicator"),
                                                         FALSE,
                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));

  g_object_class_install_property (object_class,
                                   PROP_SORT_ORDER,
                                   g_param_spec_enum ("sort_order",
                                                      _("Sort order"),
                                                      _("Sort direction the sort indicator should indicate"),
                                                      GTK_TYPE_TREE_SORT_ORDER,
                                                      GTK_TREE_SORT_ASCENDING,
267
                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
Havoc Pennington's avatar
Havoc Pennington committed
268
  
269 270 271 272 273
}

static void
gtk_tree_view_column_init (GtkTreeViewColumn *tree_column)
{
Havoc Pennington's avatar
Havoc Pennington committed
274 275 276 277
  /* FIXME remove on port to GtkObject */
  gtk_object_ref (GTK_OBJECT (tree_column));
  gtk_object_sink (GTK_OBJECT (tree_column));
  
278
  tree_column->button = NULL;
Havoc Pennington's avatar
Havoc Pennington committed
279
  tree_column->xalign = 0.0;
280
  tree_column->width = 1;
281
  tree_column->requested_width = -1;
282 283 284 285 286 287
  tree_column->min_width = -1;
  tree_column->max_width = -1;
  tree_column->cell = NULL;
  tree_column->attributes = NULL;
  tree_column->column_type = GTK_TREE_VIEW_COLUMN_AUTOSIZE;
  tree_column->visible = TRUE;
288
  tree_column->clickable = FALSE;
289
  tree_column->dirty = TRUE;
Havoc Pennington's avatar
Havoc Pennington committed
290 291
  tree_column->sort_order = GTK_TREE_SORT_ASCENDING;
  tree_column->show_sort_indicator = FALSE;
292
  tree_column->property_changed_signal = 0;
293 294
  tree_column->sort_clicked_signal = 0;
  tree_column->sort_column_changed_signal = 0;
295
  tree_column->sort_column_id = -1;
296 297 298 299 300 301 302 303 304 305 306 307 308 309
  tree_column->reorderable = FALSE;
  tree_column->maybe_reordered = FALSE;
}

static void
gtk_tree_view_column_finalize (GObject *object)
{
  GtkTreeViewColumn *tree_column = (GtkTreeViewColumn *) object;

  if (tree_column->func_data && tree_column->destroy)
    (tree_column->destroy) (tree_column->func_data);

  g_slist_free (tree_column->attributes);
  g_free (tree_column->title);
310 311
}

312 313 314 315
static void
gtk_tree_view_column_set_property (GObject         *object,
                                   guint            prop_id,
                                   const GValue    *value,
Tim Janik's avatar
Tim Janik committed
316
                                   GParamSpec      *pspec)
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
{
  GtkTreeViewColumn *tree_column;

  tree_column = GTK_TREE_VIEW_COLUMN (object);

  switch (prop_id)
    {
    case PROP_CELL_RENDERER:
      gtk_tree_view_column_set_cell_renderer (tree_column,
                                              (GtkCellRenderer*)
                                              g_value_get_object (value));
      break;

    case PROP_VISIBLE:
      gtk_tree_view_column_set_visible (tree_column,
                                        g_value_get_boolean (value));
      break;

    case PROP_SIZING:
      gtk_tree_view_column_set_sizing (tree_column,
                                       g_value_get_enum (value));
      break;

    case PROP_WIDTH:
      gtk_tree_view_column_set_width (tree_column,
                                      g_value_get_int (value));
      break;

    case PROP_MIN_WIDTH:
      gtk_tree_view_column_set_min_width (tree_column,
                                          g_value_get_int (value));
      break;

    case PROP_MAX_WIDTH:
      gtk_tree_view_column_set_max_width (tree_column,
                                          g_value_get_int (value));
      break;

    case PROP_TITLE:
      gtk_tree_view_column_set_title (tree_column,
                                      g_value_get_string (value));
      break;

    case PROP_CLICKABLE:
      gtk_tree_view_column_set_clickable (tree_column,
                                          g_value_get_boolean (value));
      break;

    case PROP_WIDGET:
      gtk_tree_view_column_set_widget (tree_column,
                                       (GtkWidget*) g_value_get_object (value));
      break;

Havoc Pennington's avatar
Havoc Pennington committed
370 371 372 373 374
    case PROP_ALIGNMENT:
      gtk_tree_view_column_set_alignment (tree_column,
                                          g_value_get_float (value));
      break;

375 376 377 378 379
    case PROP_REORDERABLE:
      gtk_tree_view_column_set_reorderable (tree_column,
					    g_value_get_boolean (value));
      break;

Havoc Pennington's avatar
Havoc Pennington committed
380 381 382
    case PROP_SORT_INDICATOR:
      gtk_tree_view_column_set_sort_indicator (tree_column,
                                               g_value_get_boolean (value));
383 384
      break;

Havoc Pennington's avatar
Havoc Pennington committed
385 386 387 388 389
    case PROP_SORT_ORDER:
      gtk_tree_view_column_set_sort_order (tree_column,
                                           g_value_get_enum (value));
      break;
      
390 391 392 393 394 395 396 397 398 399
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
gtk_tree_view_column_get_property (GObject         *object,
                                   guint            prop_id,
                                   GValue          *value,
Tim Janik's avatar
Tim Janik committed
400
                                   GParamSpec      *pspec)
401 402 403 404 405 406 407 408
{
  GtkTreeViewColumn *tree_column;

  tree_column = GTK_TREE_VIEW_COLUMN (object);

  switch (prop_id)
    {
    case PROP_CELL_RENDERER:
Havoc Pennington's avatar
Havoc Pennington committed
409 410
      g_value_set_object (value,
                          (GObject*) gtk_tree_view_column_get_cell_renderer (tree_column));
411 412 413
      break;

    case PROP_VISIBLE:
Havoc Pennington's avatar
Havoc Pennington committed
414 415
      g_value_set_boolean (value,
                           gtk_tree_view_column_get_visible (tree_column));
416 417 418
      break;

    case PROP_SIZING:
Havoc Pennington's avatar
Havoc Pennington committed
419 420
      g_value_set_enum (value,
                        gtk_tree_view_column_get_sizing (tree_column));
421 422 423
      break;

    case PROP_WIDTH:
Havoc Pennington's avatar
Havoc Pennington committed
424 425
      g_value_set_int (value,
                       gtk_tree_view_column_get_width (tree_column));
426 427 428
      break;

    case PROP_MIN_WIDTH:
Havoc Pennington's avatar
Havoc Pennington committed
429 430
      g_value_set_int (value,
                       gtk_tree_view_column_get_min_width (tree_column));
431 432 433
      break;

    case PROP_MAX_WIDTH:
Havoc Pennington's avatar
Havoc Pennington committed
434 435
      g_value_set_int (value,
                       gtk_tree_view_column_get_max_width (tree_column));
436 437 438
      break;

    case PROP_TITLE:
Havoc Pennington's avatar
Havoc Pennington committed
439 440
      g_value_set_string (value,
                          gtk_tree_view_column_get_title (tree_column));
441 442 443
      break;

    case PROP_CLICKABLE:
Havoc Pennington's avatar
Havoc Pennington committed
444 445
      g_value_set_boolean (value,
                           gtk_tree_view_column_get_clickable (tree_column));
446 447 448
      break;

    case PROP_WIDGET:
Havoc Pennington's avatar
Havoc Pennington committed
449 450
      g_value_set_object (value,
                          (GObject*) gtk_tree_view_column_get_widget (tree_column));
451 452
      break;

Havoc Pennington's avatar
Havoc Pennington committed
453 454 455
    case PROP_ALIGNMENT:
      g_value_set_float (value,
                         gtk_tree_view_column_get_alignment (tree_column));
456 457
      break;

458 459 460 461 462
    case PROP_REORDERABLE:
      g_value_set_boolean (value,
			   gtk_tree_view_column_get_reorderable (tree_column));
      break;

Havoc Pennington's avatar
Havoc Pennington committed
463 464 465 466 467 468 469 470 471 472
    case PROP_SORT_INDICATOR:
      g_value_set_boolean (value,
                           gtk_tree_view_column_get_sort_indicator (tree_column));
      break;

    case PROP_SORT_ORDER:
      g_value_set_enum (value,
                        gtk_tree_view_column_get_sort_order (tree_column));
      break;
      
473 474 475 476 477 478
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

479 480 481 482 483
/* Helper functions
 */

/* Button handling code
 */
484
static void
485
gtk_tree_view_column_create_button (GtkTreeViewColumn *tree_column)
486
{
487 488 489
  GtkTreeView *tree_view;
  GtkWidget *child;
  GtkWidget *hbox;
490

491
  tree_view = (GtkTreeView *) tree_column->tree_view;
492

493 494 495 496 497 498 499 500 501 502
  g_return_if_fail (tree_view != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
  g_return_if_fail (tree_column->button == NULL);

  gtk_widget_push_composite_child ();
  tree_column->button = gtk_button_new ();
  gtk_widget_pop_composite_child ();

  /* make sure we own a reference to it as well. */
  gtk_widget_set_parent (tree_column->button, GTK_WIDGET (tree_view));
503 504
  if (tree_view->priv->header_window)
    gtk_widget_set_parent_window (tree_column->button, tree_view->priv->header_window);
505 506 507 508
  
  gtk_signal_connect (GTK_OBJECT (tree_column->button), "realize",
		      (GtkSignalFunc) gtk_tree_view_column_button_realize,
		      NULL);
509 510 511 512 513

  gtk_signal_connect (GTK_OBJECT (tree_column->button), "event",
		      (GtkSignalFunc) gtk_tree_view_column_button_event,
		      (gpointer) tree_column);
  
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
  gtk_signal_connect (GTK_OBJECT (tree_column->button), "clicked",
		      (GtkSignalFunc) gtk_tree_view_column_button_clicked,
		      (gpointer) tree_column);

  tree_column->alignment = gtk_alignment_new (tree_column->xalign, 0.5, 0.0, 0.0);

  hbox = gtk_hbox_new (FALSE, 2);
  tree_column->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN);

  if (tree_column->child)
    child = tree_column->child;
  else
    {
      child = gtk_label_new (tree_column->title);
      gtk_widget_show (child);
    }

  if (tree_column->xalign <= 0.5)
    gtk_box_pack_end (GTK_BOX (hbox), tree_column->arrow, FALSE, FALSE, 0);
  else
    gtk_box_pack_start (GTK_BOX (hbox), tree_column->arrow, FALSE, FALSE, 0);

  gtk_box_pack_start (GTK_BOX (hbox), tree_column->alignment, TRUE, TRUE, 0);
        
  gtk_container_add (GTK_CONTAINER (tree_column->alignment), child);
  gtk_container_add (GTK_CONTAINER (tree_column->button), hbox);

  gtk_widget_show (hbox);
  gtk_widget_show (tree_column->alignment);
  gtk_tree_view_column_update_button (tree_column);
544 545
}

546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
static void 
gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column)
{
  GtkWidget *hbox;
  GtkWidget *alignment;
  GtkWidget *arrow;
  GtkWidget *current_child;

  /* Create a button if necessary */
  if (tree_column->visible &&
      tree_column->button == NULL &&
      tree_column->tree_view &&
      GTK_WIDGET_REALIZED (tree_column->tree_view))
    gtk_tree_view_column_create_button (tree_column);
  
  if (! tree_column->button)
    return;

  hbox = GTK_BIN (tree_column->button)->child;
  alignment = tree_column->alignment;
  arrow = tree_column->arrow;
  current_child = GTK_BIN (alignment)->child;

  /* Set up the actual button */
  gtk_alignment_set (GTK_ALIGNMENT (alignment), tree_column->xalign,
		     0.5, 0.0, 0.0);
      
  if (tree_column->child)
    {
      if (current_child != tree_column->child)
	{
	  gtk_container_remove (GTK_CONTAINER (alignment),
				current_child);
	  gtk_container_add (GTK_CONTAINER (alignment),
			     tree_column->child);
	}
    }
  else 
    {
      if (current_child == NULL)
	{
	  current_child = gtk_label_new (NULL);
	  gtk_widget_show (current_child);
	  gtk_container_add (GTK_CONTAINER (alignment),
			     current_child);
	}

      g_return_if_fail (GTK_IS_LABEL (current_child));

      if (tree_column->title)
	gtk_label_set_text (GTK_LABEL (current_child),
			    tree_column->title);
      else
	gtk_label_set_text (GTK_LABEL (current_child),
			    "");
    }

  switch (tree_column->sort_order)
    {
    case GTK_TREE_SORT_ASCENDING:
      gtk_arrow_set (GTK_ARROW (arrow),
		     GTK_ARROW_DOWN,
		     GTK_SHADOW_IN);
      break;

    case GTK_TREE_SORT_DESCENDING:
      gtk_arrow_set (GTK_ARROW (arrow),
		     GTK_ARROW_UP,
		     GTK_SHADOW_IN);
      break;
          
    default:
      g_warning (G_STRLOC": bad sort order");
      break;
    }

  /* Put arrow on the right if the text is left-or-center justified,
       * and on the left otherwise; do this by packing boxes, so flipping
       * text direction will reverse things
       */
  gtk_widget_ref (arrow);
  gtk_container_remove (GTK_CONTAINER (hbox), arrow);

  if (tree_column->xalign <= 0.5)
    {
      gtk_box_pack_end (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
    }
  else
    {
      gtk_box_pack_start (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
      /* move it to the front */
      gtk_box_reorder_child (GTK_BOX (hbox), arrow, 0);
    }
  gtk_widget_unref (arrow);

  if (tree_column->show_sort_indicator)
    gtk_widget_show (arrow);
  else
    gtk_widget_hide (arrow);

  /* It's always safe to hide the button.  It isn't always safe to show it, as if you show it
   * before it's realized, it'll get the wrong window. */
  if (tree_column->button &&
      tree_column->tree_view != NULL &&
      GTK_WIDGET_REALIZED (tree_column->tree_view))
    {
      if (tree_column->visible)
	{
654
	  gtk_widget_show_now (tree_column->button);
655 656
	  if (tree_column->window)
	    {
Havoc Pennington's avatar
Havoc Pennington committed
657
	      if (tree_column->column_type == GTK_TREE_VIEW_COLUMN_RESIZABLE)
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
		{
		  gdk_window_show (tree_column->window);
		  gdk_window_raise (tree_column->window);
		}
	      else
		{
		  gdk_window_hide (tree_column->window);
		}
	    }
	}
      else
	{
	  gtk_widget_hide (tree_column->button);
	  if (tree_column->window)
	    gdk_window_hide (tree_column->window);
	}
    }
675 676
  
  if (tree_column->reorderable || tree_column->clickable)
677 678 679
    {
      GTK_WIDGET_SET_FLAGS (tree_column->button, GTK_CAN_FOCUS);
    }
680
  else
681 682 683 684 685
    {
      GTK_WIDGET_UNSET_FLAGS (tree_column->button, GTK_CAN_FOCUS);
      if (GTK_WIDGET_HAS_FOCUS (tree_column->button))
	gtk_window_set_focus (GTK_WINDOW (gtk_widget_get_toplevel (tree_column->tree_view)), NULL);
    }
686 687 688 689 690 691 692

  tree_column->dirty = TRUE;
  gtk_widget_queue_resize (tree_column->tree_view);
}

/* Button signal handlers
 */
693 694

static gint
695 696 697
gtk_tree_view_column_button_event (GtkWidget *widget,
				   GdkEvent  *event,
				   gpointer   data)
698
{
699 700
  GtkTreeViewColumn *column = (GtkTreeViewColumn *) data;

701 702
  g_return_val_if_fail (event != NULL, FALSE);

703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
  if (event->type == GDK_BUTTON_PRESS &&
      column->reorderable)
    {
      column->maybe_reordered = TRUE;
      gdk_window_get_pointer (widget->window,
			      &column->drag_x,
			      &column->drag_y,
			      NULL);
      gtk_widget_grab_focus (widget);
    }

  if (event->type == GDK_BUTTON_RELEASE &&
      column->maybe_reordered)
    column->maybe_reordered = FALSE;

  if (event->type == GDK_MOTION_NOTIFY &&
      (column->maybe_reordered) &&
      (gtk_drag_check_threshold (widget,
				 column->drag_x,
				 column->drag_y,
				 (gint) ((GdkEventMotion *)event)->x,
				 (gint) ((GdkEventMotion *)event)->y)))
725
    {
726 727
      column->maybe_reordered = FALSE;
      _gtk_tree_view_column_start_drag (GTK_TREE_VIEW (column->tree_view), column);
728
      return TRUE;
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
    }
  if (column->clickable == FALSE)
    {
      switch (event->type)
	{
	case GDK_BUTTON_PRESS:
	case GDK_2BUTTON_PRESS:
	case GDK_3BUTTON_PRESS:
	case GDK_MOTION_NOTIFY:
	case GDK_BUTTON_RELEASE:
	case GDK_ENTER_NOTIFY:
	case GDK_LEAVE_NOTIFY:
	  return TRUE;
	default:
	  return FALSE;
	}
745 746 747 748 749
    }
  return FALSE;
}

static void
750
gtk_tree_view_column_button_realize (GtkWidget *widget, gpointer data)
751
{
752
  gdk_window_set_events (widget->window, gdk_window_get_events (widget->window) | GDK_POINTER_MOTION_MASK);
753 754
}

755 756 757 758
static void
gtk_tree_view_column_button_clicked (GtkWidget *widget, gpointer data)
{
  g_signal_emit_by_name (G_OBJECT (data), "clicked");
Jonathan Blandford's avatar
Jonathan Blandford committed
759
}
760

Jonathan Blandford's avatar
Jonathan Blandford committed
761
static void
762 763
gtk_tree_view_model_sort_column_changed (GtkTreeSortable   *sortable,
					  GtkTreeViewColumn *column)
Jonathan Blandford's avatar
Jonathan Blandford committed
764
{
765 766
  gint sort_column_id;
  GtkTreeSortOrder order;
Jonathan Blandford's avatar
Jonathan Blandford committed
767

768 769 770 771 772 773 774 775 776 777 778 779 780 781
  if (gtk_tree_sortable_get_sort_column_id (sortable,
					    &sort_column_id,
					    &order))
    {
      if (sort_column_id == column->sort_column_id)
	{
	  gtk_tree_view_column_set_sort_indicator (column, TRUE);
	  gtk_tree_view_column_set_sort_order (column, order);
	}
      else
	{
	  gtk_tree_view_column_set_sort_indicator (column, FALSE);
	}
    }
Jonathan Blandford's avatar
Jonathan Blandford committed
782 783
}

784 785 786
static void
gtk_tree_view_column_sort (GtkTreeViewColumn *tree_column,
			   gpointer           data)
787
{
788
  GList *list;
789

790
  g_return_if_fail (tree_column->tree_view != NULL);
791

792 793 794 795 796 797 798 799 800 801 802 803
  if (tree_column->show_sort_indicator)
    {
      if (tree_column->sort_order == GTK_TREE_SORT_ASCENDING)
	gtk_tree_view_column_set_sort_order (tree_column, GTK_TREE_SORT_DESCENDING);
      else
	gtk_tree_view_column_set_sort_order (tree_column, GTK_TREE_SORT_ASCENDING);
    }
  else
    {
      gtk_tree_view_column_set_sort_order (tree_column, GTK_TREE_SORT_ASCENDING);
      gtk_tree_view_column_set_sort_indicator (tree_column, TRUE);
    }
804

805 806 807 808 809
  list = (GTK_TREE_VIEW (tree_column->tree_view)->priv->columns);
  g_assert (list);
  while (list)
    {
      GtkTreeViewColumn *tmp_column;
810

811 812 813
      tmp_column = GTK_TREE_VIEW_COLUMN (list->data);
      if (tmp_column->visible && tmp_column != tree_column)
	gtk_tree_view_column_set_sort_indicator (tmp_column, FALSE);
814

815 816
      list = list->next;
    }
817

818 819 820 821
  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GTK_TREE_VIEW (tree_column->tree_view)->priv->model),
					tree_column->sort_column_id,
					tree_column->sort_order);
}
822

823 824 825 826 827 828 829 830 831 832 833 834

static void
gtk_tree_view_column_setup_sort_column_id_callback (GtkTreeViewColumn *tree_column)
{
  GtkTreeModel *model;

  if (tree_column->tree_view == NULL)
    return;

  model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_column->tree_view));

  if (model == NULL)
835
    {
836 837 838 839 840 841
      if (tree_column->sort_column_changed_signal)
	{
	  g_signal_handler_disconnect (G_OBJECT (tree_column), tree_column->sort_column_changed_signal);
	  tree_column->sort_column_changed_signal = 0;
	}
      return;
842 843
    }

844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862
  if (GTK_IS_TREE_SORTABLE (model) &&
      tree_column->sort_column_id != -1)
    {
      gint real_sort_column_id;
      GtkTreeSortOrder real_order;

      if (tree_column->sort_column_changed_signal == 0)
	tree_column->sort_column_changed_signal =
	  g_signal_connectc (G_OBJECT (model), "sort_column_changed",
			     GTK_SIGNAL_FUNC (gtk_tree_view_model_sort_column_changed),
			     tree_column, FALSE);

      if (gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model),
						&real_sort_column_id,
						&real_order) &&
	  (real_sort_column_id == tree_column->sort_column_id))
	{
	  gtk_tree_view_column_set_sort_indicator (tree_column, TRUE);
	  gtk_tree_view_column_set_sort_order (tree_column, real_order);
863

864 865 866 867
	  return;
	}
    }
}
868 869


870 871 872
/* Exported Private Functions.
 * These should only be called by gtktreeview.c or gtktreeviewcolumn.c
 */
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888

void
_gtk_tree_view_column_realize_button (GtkTreeViewColumn *column)
{
  GtkTreeView *tree_view;
  GdkWindowAttr attr;
  guint attributes_mask;

  tree_view = (GtkTreeView *)column->tree_view;

  g_return_if_fail (tree_view != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
  g_return_if_fail (GTK_WIDGET_REALIZED (tree_view));
  g_return_if_fail (tree_view->priv->header_window != NULL);
  g_return_if_fail (column->button != NULL);

889 890 891 892 893
  gtk_widget_set_parent_window (column->button, tree_view->priv->header_window);

  if (column->visible)
    gtk_widget_show (column->button);

894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
  attr.window_type = GDK_WINDOW_CHILD;
  attr.wclass = GDK_INPUT_ONLY;
  attr.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
  attr.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
  attr.event_mask = gtk_widget_get_events (GTK_WIDGET (tree_view));
  attr.event_mask = (GDK_BUTTON_PRESS_MASK |
		     GDK_BUTTON_RELEASE_MASK |
		     GDK_POINTER_MOTION_MASK |
		     GDK_POINTER_MOTION_HINT_MASK |
		     GDK_KEY_PRESS_MASK);
  attributes_mask = GDK_WA_CURSOR | GDK_WA_X | GDK_WA_Y;
  attr.cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW);
  tree_view->priv->cursor_drag = attr.cursor;

  attr.y = 0;
  attr.width = TREE_VIEW_DRAG_WIDTH;
  attr.height = tree_view->priv->header_height;

  attr.x = (column->button->allocation.x + column->button->allocation.width) - 3;
          
  column->window = gdk_window_new (tree_view->priv->header_window,
				   &attr, attributes_mask);
  gdk_window_set_user_data (column->window, tree_view);
917 918

  gtk_tree_view_column_update_button (column);
919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935
}

void
_gtk_tree_view_column_unrealize_button (GtkTreeViewColumn *column)
{
  g_return_if_fail (column != NULL);
  g_return_if_fail (column->window != NULL);

  gdk_window_set_user_data (column->window, NULL);
  gdk_window_destroy (column->window);
  column->window = NULL;
}

void
_gtk_tree_view_column_set_tree_view (GtkTreeViewColumn *column,
				     GtkTreeView       *tree_view)
{
936
  g_assert (column->tree_view == NULL);
937

938 939
  column->tree_view = GTK_WIDGET (tree_view);
  gtk_tree_view_column_create_button (column);
940

941 942 943 944 945
  column->property_changed_signal =
	  g_signal_connect_data (GTK_OBJECT (tree_view),
				 "notify::model",
				 GTK_SIGNAL_FUNC (gtk_tree_view_column_setup_sort_column_id_callback),
				 column, NULL, TRUE, FALSE);
946

947
  gtk_tree_view_column_setup_sort_column_id_callback (column);
948 949 950 951 952 953 954 955 956
}

void
_gtk_tree_view_column_unset_tree_view (GtkTreeViewColumn *column)
{
  if (column->tree_view && column->button)
    {
      gtk_container_remove (GTK_CONTAINER (column->tree_view), column->button);
    }
957 958 959 960 961 962 963 964 965 966 967 968
  if (column->property_changed_signal)
    {
      g_signal_handler_disconnect (G_OBJECT (column->tree_view), column->property_changed_signal);
      column->property_changed_signal = 0;
    }

  if (column->sort_column_changed_signal)
    {
      g_signal_handler_disconnect (G_OBJECT (column), column->sort_column_changed_signal);
      column->sort_column_changed_signal = 0;
    }

969 970 971 972
  column->tree_view = NULL;
  column->button = NULL;
}

973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
void
_gtk_tree_view_column_set_width (GtkTreeViewColumn *tree_column,
				 gint               width)
{
  if (tree_column->min_width != -1 &&
      width <= tree_column->min_width)
    width = tree_column->min_width;
  else if (tree_column->max_width != -1 &&
           width > tree_column->max_width)
    width = tree_column->max_width;
  
  if (tree_column->width == width)
    return;
  
  tree_column->width = width;

  g_object_notify (G_OBJECT (tree_column), "width");

  if (tree_column->tree_view != NULL)
    gtk_widget_queue_resize (tree_column->tree_view);
993

994
}
995 996 997 998

/* Public Functions */


999 1000 1001 1002 1003 1004 1005
/**
 * gtk_tree_view_column_new:
 * 
 * Creates a new #GtkTreeViewColumn.
 * 
 * Return value: A newly created #GtkTreeViewColumn.
 **/
1006
GtkTreeViewColumn *
1007 1008
gtk_tree_view_column_new (void)
{
1009
  GtkTreeViewColumn *tree_column;
1010

1011
  tree_column = GTK_TREE_VIEW_COLUMN (gtk_type_new (GTK_TYPE_TREE_VIEW_COLUMN));
1012

1013
  return tree_column;
1014 1015
}

1016 1017 1018 1019
/**
 * gtk_tree_view_column_new_with_attributes:
 * @title: The title to set the header to.
 * @cell: The #GtkCellRenderer.
Jonathan Blandford's avatar
Jonathan Blandford committed
1020
 * @Varargs: A NULL terminated list of attributes.
1021 1022 1023 1024 1025 1026 1027 1028
 * 
 * Creates a new #GtkTreeViewColumn with a number of default values.  This is
 * equivalent to calling @gtk_tree_view_column_set_title,
 * @gtk_tree_view_column_set_cell_renderer, and
 * @gtk_tree_view_column_set_attributes on the newly created #GtkTreeViewColumn.
 * 
 * Return value: A newly created #GtkTreeViewColumn.
 **/
1029
GtkTreeViewColumn *
1030
gtk_tree_view_column_new_with_attributes (const gchar     *title,
1031 1032 1033
					  GtkCellRenderer *cell,
					  ...)
{
1034
  GtkTreeViewColumn *retval;
1035 1036 1037 1038
  va_list args;

  retval = gtk_tree_view_column_new ();

1039 1040
  gtk_tree_view_column_set_title (retval, title);
  gtk_tree_view_column_set_cell_renderer (retval, cell);
1041 1042

  va_start (args, cell);
1043
  gtk_tree_view_column_set_attributesv (retval, args);
1044 1045 1046 1047 1048
  va_end (args);

  return retval;
}

1049 1050 1051 1052 1053
/**
 * gtk_tree_view_column_set_cell_renderer:
 * @tree_column: A #GtkTreeViewColumn.
 * @cell: The #GtkCellRenderer, or NULL.
 * 
1054 1055 1056
 * Sets the cell renderer of the @tree_column.  If there is a cell
 * renderer already set, then it is removed.  If @cell is NULL, then
 * the cell renderer is unset.
1057
 **/
1058 1059 1060 1061 1062
void
gtk_tree_view_column_set_cell_renderer (GtkTreeViewColumn *tree_column,
					GtkCellRenderer   *cell)
{
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
Havoc Pennington's avatar
Havoc Pennington committed
1063

1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
  if (cell)
    g_return_if_fail (GTK_IS_CELL_RENDERER (cell));

  if (cell)
    g_object_ref (G_OBJECT (cell));

  if (tree_column->cell)
    g_object_unref (G_OBJECT (tree_column->cell));

  tree_column->cell = cell;
1074

1075 1076 1077 1078 1079 1080
  if (tree_column->tree_view)
    {
      tree_column->dirty = TRUE;
      gtk_widget_queue_resize (tree_column->tree_view);
    }

1081
  g_object_notify (G_OBJECT (tree_column), "cell_renderer");
1082 1083
}

Havoc Pennington's avatar
Havoc Pennington committed
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
/**
 * gtk_tree_view_column_get_cell_renderer:
 * @tree_column: a #GtkTreeViewColumn
 * 
 * Gets the value set with gtk_tree_view_column_set_cell_renderer().
 * 
 * Return value: cell renderer for the column, or %NULL if unset
 **/
GtkCellRenderer*
gtk_tree_view_column_get_cell_renderer (GtkTreeViewColumn *tree_column)
{
  g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), NULL);
  
  return tree_column->cell;
}

1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
/**
 * gtk_tree_view_column_add_attribute:
 * @tree_column: A #GtkTreeViewColumn.
 * @attribute: An attribute on the columns cell
 * @column: The column position on the model to get the attribute from.
 * 
 * Adds an attribute mapping to the list in @tree_column.  The @column is the
 * column position on the model to get a value from, and the @attribute is the
 * parameter on the @tree_column's cell renderer to set that value to.
 **/
1110 1111
void
gtk_tree_view_column_add_attribute (GtkTreeViewColumn *tree_column,
1112
				    const gchar       *attribute,
1113 1114 1115 1116 1117
				    gint               column)
{
  g_return_if_fail (tree_column != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));

1118 1119 1120 1121
  tree_column->attributes = g_slist_prepend (tree_column->attributes,
					     GINT_TO_POINTER (column));
  tree_column->attributes = g_slist_prepend (tree_column->attributes,
					     g_strdup (attribute));
1122 1123 1124 1125 1126 1127 1128

  if (tree_column->tree_view)
    {
      tree_column->dirty = TRUE;
      gtk_widget_queue_resize (tree_column->tree_view);
    }

1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
}

static void
gtk_tree_view_column_set_attributesv (GtkTreeViewColumn *tree_column,
				      va_list            args)
{
  gchar *attribute;
  gint column;

  g_return_if_fail (tree_column != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));

  attribute = va_arg (args, gchar *);

1143 1144
  gtk_tree_view_column_clear_attributes (tree_column);
  
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
  while (attribute != NULL)
    {
      column = va_arg (args, gint);
      gtk_tree_view_column_add_attribute (tree_column,
					  attribute,
					  column);
      attribute = va_arg (args, gchar *);
    }
}

1155 1156 1157
/**
 * gtk_tree_view_column_set_attributes:
 * @tree_column: A #GtkTreeViewColumn.
1158
 * @Varargs: A NULL terminated listing of attributes.
1159
 * 
1160 1161 1162 1163
 * Sets the attributes in the list as the attributes of @tree_column.
 * The attributes should be in attribute/column order, as in
 * @gtk_tree_view_column_add_attribute. All existing attributes
 * are removed, and replaced with the new attributes.
1164
 **/
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
void
gtk_tree_view_column_set_attributes (GtkTreeViewColumn *tree_column,
				     ...)
{
  va_list args;

  g_return_if_fail (tree_column != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));

  va_start (args, tree_column);

  gtk_tree_view_column_set_attributesv (tree_column, args);

  va_end (args);
}

1181 1182

/**
1183
 * gtk_tree_view_column_set_cell_data_func:
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194
 * @tree_column: A #GtkTreeViewColumn
 * @func: The #GtkTreeViewColumnFunc to use. 
 * @func_data: The user data for @func.
 * @destroy: The destroy notification for @func_data
 * 
 * Sets the #GtkTreeViewColumnFunc to use for the column.  This function is used
 * instead of the standard attributes mapping for setting the column value, and
 * should set the value of @tree_column 's cell renderer as appropriate.  @func
 * may be NULL to remove an older one.
 **/
void
1195 1196 1197 1198
gtk_tree_view_column_set_cell_data_func (GtkTreeViewColumn   *tree_column,
					 GtkTreeCellDataFunc  func,
					 gpointer             func_data,
					 GtkDestroyNotify     destroy)
1199 1200 1201 1202
{
  g_return_if_fail (tree_column != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));

1203 1204 1205 1206 1207
  if (func == tree_column->func &&
      func_data == tree_column->func_data &&
      destroy == tree_column->destroy)
    return;

1208 1209 1210 1211 1212 1213
  if (tree_column->func_data && tree_column->destroy)
    (tree_column->destroy) (tree_column->func_data);

  tree_column->func = func;
  tree_column->func_data = func_data;
  tree_column->destroy = destroy;
1214 1215 1216 1217 1218 1219

  if (tree_column->tree_view)
    {
      tree_column->dirty = TRUE;
      gtk_widget_queue_resize (tree_column->tree_view);
    }
1220 1221 1222
}


1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245
/**
 * gtk_tree_view_column_clear_attributes:
 * @tree_column: a #GtkTreeViewColumn
 * 
 * Clears all existing attributes previously set with
 * gtk_tree_view_column_set_attributes().
 **/
void
gtk_tree_view_column_clear_attributes (GtkTreeViewColumn *tree_column)
{
  GSList *list;
  
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));

  list = tree_column->attributes;

  while (list && list->next)
    {
      g_free (list->data);
      list = list->next->next;
    }
  g_slist_free (tree_column->attributes);
  tree_column->attributes = NULL;
1246 1247 1248 1249 1250 1251

  if (tree_column->tree_view)
    {
      tree_column->dirty = TRUE;
      gtk_widget_queue_resize (tree_column->tree_view);
    }
1252 1253
}

1254 1255
/* Options for manipulating the columns */

1256 1257 1258 1259 1260 1261 1262
/**
 * gtk_tree_view_column_set_visible:
 * @tree_column: A #GtkTreeViewColumn.
 * @visible: TRUE if the @tree_column is visible.
 * 
 * Sets the visibility of @tree_column.
 **/
1263 1264 1265 1266 1267 1268 1269
void
gtk_tree_view_column_set_visible (GtkTreeViewColumn *tree_column,
				  gboolean           visible)
{
  g_return_if_fail (tree_column != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));

1270 1271
  visible = !! visible;
  
1272
  if (tree_column->visible == visible)
1273
    return;
1274

1275
  tree_column->visible = visible;
1276

1277
  gtk_tree_view_column_update_button (tree_column);
1278
  g_object_notify (G_OBJECT (tree_column), "visible");
1279 1280
}

1281 1282 1283 1284 1285 1286 1287 1288 1289
/**
 * gtk_tree_view_column_get_visible:
 * @tree_column: A #GtkTreeViewColumn.
 * 
 * Returns TRUE if @tree_column is visible.
 * 
 * Return value: whether the column is visible or not.  If it is visible, then
 * the tree will show the column.
 **/
1290 1291 1292 1293 1294 1295 1296 1297 1298
gboolean
gtk_tree_view_column_get_visible (GtkTreeViewColumn *tree_column)
{
  g_return_val_if_fail (tree_column != NULL, FALSE);
  g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);

  return tree_column->visible;
}

1299
/**
Havoc Pennington's avatar
Havoc Pennington committed
1300
 * gtk_tree_view_column_set_sizing:
1301
 * @tree_column: A #GtkTreeViewColumn.
Havoc Pennington's avatar
Havoc Pennington committed
1302
 * @type: The #GtkTreeViewColumnSizing.
1303 1304 1305
 * 
 * Sets the growth behavior of @tree_column to @type.
 **/
1306
void
1307
gtk_tree_view_column_set_sizing (GtkTreeViewColumn       *tree_column,
1308
                                 GtkTreeViewColumnSizing  type)
1309 1310 1311 1312 1313 1314 1315
{
  g_return_if_fail (tree_column != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));

  if (type == tree_column->column_type)
    return;

1316 1317
  if (tree_column->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE &&
      tree_column->requested_width != -1)
1318
    {
1319
      gtk_tree_view_column_set_sizing (tree_column, tree_column->requested_width);
1320
    }
1321
  tree_column->column_type = type;
1322