gtktreeviewcolumn.c 34.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/* 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"
#include "gtktreeprivate.h"
#include "gtksignal.h"
#include "gtkbutton.h"
#include "gtkalignment.h"
25
#include "gtklabel.h"
26
#include "gtkintl.h"
27

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
enum
{
  PROP_0,
  
  PROP_CELL_RENDERER,
  PROP_VISIBLE,
  PROP_SIZING,
  PROP_WIDTH,
  PROP_MIN_WIDTH,
  PROP_MAX_WIDTH,
  PROP_TITLE,
  PROP_CLICKABLE,
  PROP_WIDGET,
  PROP_JUSTIFICATION
};

enum
{
46 47 48 49 50 51 52 53 54 55
  CLICKED,
  LAST_SIGNAL
};


static void gtk_tree_view_column_init            (GtkTreeViewColumn      *tree_column);
static void gtk_tree_view_column_class_init      (GtkTreeViewColumnClass *klass);
static void gtk_tree_view_column_set_attributesv (GtkTreeViewColumn      *tree_column,
						  va_list                 args);
static void gtk_real_tree_column_clicked         (GtkTreeViewColumn      *tree_column);
56 57 58 59 60 61 62 63 64 65 66
static void gtk_tree_view_column_set_property    (GObject         *object,
                                                  guint            prop_id,
                                                  const GValue    *value,
                                                  GParamSpec      *pspec,
                                                  const gchar     *trailer);
static void gtk_tree_view_column_get_property    (GObject         *object,
                                                  guint            prop_id,
                                                  GValue          *value,
                                                  GParamSpec      *pspec,
                                                  const gchar     *trailer);

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92


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,
      };

93
      tree_column_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkTreeViewColumn", &tree_column_info, 0);
94 95 96 97 98 99 100 101
    }

  return tree_column_type;
}

static void
gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class)
{
102
  GObjectClass *object_class;
103

104
  object_class = (GObjectClass*) class;
105 106 107

  parent_class = g_type_class_peek_parent (class);

108 109
  class->clicked = gtk_real_tree_column_clicked;

110 111 112
  object_class->set_property = gtk_tree_view_column_set_property;
  object_class->get_property = gtk_tree_view_column_get_property;
  
113
  tree_column_signals[CLICKED] =
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 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
    g_signal_newc ("clicked",
                   GTK_CLASS_TYPE (object_class),
                   G_SIGNAL_RUN_LAST,
                   G_STRUCT_OFFSET (GtkTreeViewColumnClass, clicked),
                   NULL,
                   gtk_marshal_VOID__VOID,
                   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,
                                   PROP_JUSTIFICATION,
                                   g_param_spec_enum ("justification",
                                                      _("Justification"),
                                                      _("Justification of the column"),
                                                      GTK_TYPE_JUSTIFICATION,
                                                      GTK_JUSTIFY_LEFT,
                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
210 211 212 213 214 215 216
}

static void
gtk_tree_view_column_init (GtkTreeViewColumn *tree_column)
{
  tree_column->button = NULL;
  tree_column->justification = GTK_JUSTIFY_LEFT;
217
  tree_column->width = 1;
218 219 220 221 222 223 224 225 226 227
  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;
  tree_column->button_active = FALSE;
  tree_column->dirty = TRUE;
}

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 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
static void
gtk_tree_view_column_set_property (GObject         *object,
                                   guint            prop_id,
                                   const GValue    *value,
                                   GParamSpec      *pspec,
                                   const gchar     *trailer)
{
  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;

    case PROP_JUSTIFICATION:
      gtk_tree_view_column_set_justification (tree_column,
                                              g_value_get_enum (value));
      break;

    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,
                                   GParamSpec      *pspec,
                                   const gchar     *trailer)
{
  GtkTreeViewColumn *tree_column;

  tree_column = GTK_TREE_VIEW_COLUMN (object);

  switch (prop_id)
    {
    case PROP_CELL_RENDERER:
      g_value_set_object (value, (GObject*) tree_column->cell);
      break;

    case PROP_VISIBLE:
      g_value_set_boolean (value, tree_column->visible);
      break;

    case PROP_SIZING:
      g_value_set_enum (value, tree_column->column_type);
      break;

    case PROP_WIDTH:
      g_value_set_int (value, tree_column->width);
      break;

    case PROP_MIN_WIDTH:
      g_value_set_int (value, tree_column->min_width);
      break;

    case PROP_MAX_WIDTH:
      g_value_set_int (value, tree_column->max_width);
      break;

    case PROP_TITLE:
      g_value_set_string (value, tree_column->title);
      break;

    case PROP_CLICKABLE:
      g_value_set_boolean (value, tree_column->button_active);
      break;

    case PROP_WIDGET:
      g_warning ("FIXME");
      break;

    case PROP_JUSTIFICATION:
      g_value_set_enum (value, tree_column->justification);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }

}

358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
/* used to make the buttons 'unclickable' */

static gint
gtk_tree_view_passive_func (GtkWidget *widget,
			    GdkEvent  *event,
			    gpointer   data)
{
  g_return_val_if_fail (event != NULL, FALSE);

  switch (event->type)
    {
    case GDK_MOTION_NOTIFY:
    case GDK_BUTTON_PRESS:
    case GDK_2BUTTON_PRESS:
    case GDK_3BUTTON_PRESS:
    case GDK_BUTTON_RELEASE:
    case GDK_ENTER_NOTIFY:
    case GDK_LEAVE_NOTIFY:
      return TRUE;
    default:
      break;
    }
  return FALSE;
}

static void
gtk_real_tree_column_clicked (GtkTreeViewColumn *tree_column)
{
  g_return_if_fail (tree_column != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));

}

391 392 393 394 395 396 397
/**
 * gtk_tree_view_column_new:
 * 
 * Creates a new #GtkTreeViewColumn.
 * 
 * Return value: A newly created #GtkTreeViewColumn.
 **/
398
GtkTreeViewColumn *
399 400
gtk_tree_view_column_new (void)
{
401
  GtkTreeViewColumn *retval;
402

403
  retval = GTK_TREE_VIEW_COLUMN (gtk_type_new (GTK_TYPE_TREE_COLUMN));
404 405 406 407

  return retval;
}

408 409 410 411
/**
 * 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
412
 * @Varargs: A NULL terminated list of attributes.
413 414 415 416 417 418 419 420
 * 
 * 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.
 **/
421
GtkTreeViewColumn *
422 423 424 425
gtk_tree_view_column_new_with_attributes (gchar           *title,
					  GtkCellRenderer *cell,
					  ...)
{
426
  GtkTreeViewColumn *retval;
427 428 429 430
  va_list args;

  retval = gtk_tree_view_column_new ();

431 432
  gtk_tree_view_column_set_title (retval, title);
  gtk_tree_view_column_set_cell_renderer (retval, cell);
433 434

  va_start (args, cell);
435
  gtk_tree_view_column_set_attributesv (retval, args);
436 437 438 439 440
  va_end (args);

  return retval;
}

441 442 443 444 445
/**
 * gtk_tree_view_column_set_cell_renderer:
 * @tree_column: A #GtkTreeViewColumn.
 * @cell: The #GtkCellRenderer, or NULL.
 * 
446 447 448
 * 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.
449
 **/
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
void
gtk_tree_view_column_set_cell_renderer (GtkTreeViewColumn *tree_column,
					GtkCellRenderer   *cell)
{
  g_return_if_fail (tree_column != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
  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;
466

467
  g_object_notify (G_OBJECT (tree_column), "cell_renderer");
468 469
}

470 471 472 473 474 475 476 477 478 479
/**
 * 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.
 **/
480 481 482 483 484 485 486 487
void
gtk_tree_view_column_add_attribute (GtkTreeViewColumn *tree_column,
				    gchar             *attribute,
				    gint               column)
{
  g_return_if_fail (tree_column != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));

488 489 490 491
  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));
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
}

static void
gtk_tree_view_column_set_attributesv (GtkTreeViewColumn *tree_column,
				      va_list            args)
{
  GSList *list;
  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 *);

  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;

  while (attribute != NULL)
    {
      column = va_arg (args, gint);
      gtk_tree_view_column_add_attribute (tree_column,
					  attribute,
					  column);
      attribute = va_arg (args, gchar *);
    }
}

527 528 529
/**
 * gtk_tree_view_column_set_attributes:
 * @tree_column: A #GtkTreeViewColumn.
530
 * @Varargs: A NULL terminated listing of attributes.
531
 * 
532 533 534 535
 * 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.
536
 **/
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
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);
}

553 554 555 556
/**
 * gtk_tree_view_column_set_cell_data:
 * @tree_column: A #GtkTreeViewColumn.
 * @tree_model: The #GtkTreeModel to to get the cell renderers attributes from.
Jonathan Blandford's avatar
Jonathan Blandford committed
557
 * @iter: The #GtkTreeIter to to get the cell renderer's attributes from.
558 559 560 561 562 563
 * 
 * Sets the cell renderer based on the @tree_model and @tree_node.  That is, for
 * every attribute mapping in @tree_column, it will get a value from the set
 * column on the @tree_node, and use that value to set the attribute on the cell
 * renderer.
 **/
564 565 566
void
gtk_tree_view_column_set_cell_data (GtkTreeViewColumn *tree_column,
				    GtkTreeModel      *tree_model,
567
				    GtkTreeIter       *iter)
568 569 570 571 572 573 574 575 576
{
  GSList *list;
  GValue value = { 0, };
  GObject *cell;

  g_return_if_fail (tree_column != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
  g_return_if_fail (tree_column->cell != NULL);

577 578 579
  if (tree_model == NULL)
    return;

580 581
  if (tree_column->func && (* tree_column->func) (tree_column,
						  tree_model,
582
						  iter,
583 584 585 586 587 588 589 590
						  tree_column->func_data))
    return;

  cell = (GObject *) tree_column->cell;
  list = tree_column->attributes;

  while (list && list->next)
    {
591 592 593
      gtk_tree_model_get_value (tree_model, iter,
				GPOINTER_TO_INT (list->next->data),
				&value);
594
      g_object_set_property (cell, (gchar *) list->data, &value);
595 596 597 598 599 600 601
      g_value_unset (&value);
      list = list->next->next;
    }
}

/* Options for manipulating the columns */

602 603 604 605 606 607 608
/**
 * gtk_tree_view_column_set_visible:
 * @tree_column: A #GtkTreeViewColumn.
 * @visible: TRUE if the @tree_column is visible.
 * 
 * Sets the visibility of @tree_column.
 **/
609 610 611 612 613 614 615
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));

616 617
  visible = !! visible;
  
618 619 620 621 622 623 624 625
  if (tree_column->visible == visible)
    return;

  tree_column->visible = visible;

  if (visible)
    {
      gtk_widget_show (tree_column->button);
626 627
      if (GTK_WIDGET_REALIZED (tree_column->tree_view))
        gdk_window_show (tree_column->window);
628 629 630 631
    }
  else
    {
      gtk_widget_hide (tree_column->button);
632 633
      if (GTK_WIDGET_REALIZED (tree_column->tree_view))
        gdk_window_hide (tree_column->window);
634 635 636
    }

  if (GTK_WIDGET_REALIZED (tree_column->tree_view))
637
    _gtk_tree_view_set_size (GTK_TREE_VIEW (tree_column->tree_view), -1, -1);
638 639

  g_object_notify (G_OBJECT (tree_column), "visible");
640 641
}

642 643 644 645 646 647 648 649 650
/**
 * 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.
 **/
651 652 653 654 655 656 657 658 659
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;
}

660
/**
Havoc Pennington's avatar
Havoc Pennington committed
661
 * gtk_tree_view_column_set_sizing:
662
 * @tree_column: A #GtkTreeViewColumn.
Havoc Pennington's avatar
Havoc Pennington committed
663
 * @type: The #GtkTreeViewColumnSizing.
664 665 666
 * 
 * Sets the growth behavior of @tree_column to @type.
 **/
667
void
Havoc Pennington's avatar
Havoc Pennington committed
668
gtk_tree_view_column_set_sizing (GtkTreeViewColumn     *tree_column,
669
                                 GtkTreeViewColumnSizing  type)
670 671 672 673 674 675 676 677 678 679 680 681 682
{
  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;

  tree_column->column_type = type;
  switch (type)
    {
    case GTK_TREE_VIEW_COLUMN_AUTOSIZE:
      tree_column->dirty = TRUE;
    case GTK_TREE_VIEW_COLUMN_FIXED:
683 684
      if (GTK_WIDGET_REALIZED (tree_column->tree_view))
        gdk_window_hide (tree_column->window);
685 686
      break;
    default:
687 688 689 690 691
      if (GTK_WIDGET_REALIZED (tree_column->tree_view))
        {
          gdk_window_show (tree_column->window);
          gdk_window_raise (tree_column->window);
        }
692 693 694 695
      break;
    }

  gtk_widget_queue_resize (tree_column->tree_view);
696 697

  g_object_notify (G_OBJECT (tree_column), "sizing");
698 699
}

700
/**
701
 * gtk_tree_view_column_get_sizing:
702 703 704 705 706 707
 * @tree_column: A #GtkTreeViewColumn.
 * 
 * Returns the current type of @tree_column.
 * 
 * Return value: The type of @tree_column.
 **/
708
gint
709
gtk_tree_view_column_get_sizing (GtkTreeViewColumn *tree_column)
710 711 712 713 714 715 716
{
  g_return_val_if_fail (tree_column != NULL, 0);
  g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);

  return tree_column->column_type;
}

717 718 719 720 721 722 723 724
/**
 * gtk_tree_view_column_get_size:
 * @tree_column: A #GtkTreeViewColumn.
 * 
 * Returns the current size of the @tree_column in pixels.
 * 
 * Return value: The current size of the @tree_column.
 **/
725 726 727 728 729 730
gint
gtk_tree_view_column_get_size (GtkTreeViewColumn *tree_column)
{
  g_return_val_if_fail (tree_column != NULL, 0);
  g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), 0);

Havoc Pennington's avatar
Havoc Pennington committed
731
  return tree_column->width;
732 733
}

734
/**
Havoc Pennington's avatar
Havoc Pennington committed
735
 * gtk_tree_view_column_set_width:
736 737 738 739 740
 * @tree_column: A #GtkTreeViewColumn.
 * @size: The size to set the @tree_column to.
 * 
 * Sets the size of the column in pixels, unless the the column type is
 * #GTK_TREE_VIEW_COLUMN_AUTOSIZE.  In this case, the value is discarded as the
741 742
 * size of the column is based on the calculated width of the column. The
 * width is clamped to the min/max width for the column.
743
 **/
744
void
Havoc Pennington's avatar
Havoc Pennington committed
745
gtk_tree_view_column_set_width (GtkTreeViewColumn *tree_column,
746
                                gint               size)
747 748 749 750
{
  g_return_if_fail (tree_column != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
  g_return_if_fail (size > 0);
751 752 753 754 755 756 757 758 759
  
  if (tree_column->min_width != -1 &&
      size < tree_column->min_width)
    size = tree_column->min_width;
  else if (tree_column->max_width != -1 &&
           size > tree_column->max_width)
    size = tree_column->max_width;
  
  if (tree_column->width == size)
760
    return;
761
  
Havoc Pennington's avatar
Havoc Pennington committed
762
  tree_column->width = size;
763
  
764 765
  if (GTK_WIDGET_REALIZED (tree_column->tree_view))
    gtk_widget_queue_resize (tree_column->tree_view);
766 767
  
  g_object_notify (G_OBJECT (tree_column), "width");
768 769
}

770 771 772 773 774 775 776 777
/**
 * gtk_tree_view_column_set_min_width:
 * @tree_column: A #GtkTreeViewColumn.
 * @min_width: The minimum width of the column in pixels, or -1.
 * 
 * Sets the minimum width of the @tree_column.  If @min_width is -1, then the
 * minimum width is unset.
 **/
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
void
gtk_tree_view_column_set_min_width (GtkTreeViewColumn *tree_column,
				    gint               min_width)
{
  gint real_min_width;

  g_return_if_fail (tree_column != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
  g_return_if_fail (min_width >= -1);

  if (min_width == tree_column->min_width)
    return;

  real_min_width = (tree_column->min_width == -1) ?
    tree_column->button->requisition.width : tree_column->min_width;

  /* We want to queue a resize if the either the old min_size or the
   * new min_size determined the size of the column */
  if (GTK_WIDGET_REALIZED (tree_column->tree_view) &&
Havoc Pennington's avatar
Havoc Pennington committed
797
      ((tree_column->min_width > tree_column->width) ||
798
       (tree_column->min_width == -1 &&
Havoc Pennington's avatar
Havoc Pennington committed
799 800
	tree_column->button->requisition.width > tree_column->width) ||
       (min_width > tree_column->width) ||
801
       (min_width == -1 &&
Havoc Pennington's avatar
Havoc Pennington committed
802
	tree_column->button->requisition.width > tree_column->width)))
803 804 805 806 807 808 809
    gtk_widget_queue_resize (tree_column->tree_view);

  if (tree_column->max_width != -1 &&
      tree_column->max_width < real_min_width)
    tree_column->max_width = real_min_width;

  tree_column->min_width = min_width;
810 811

  g_object_notify (G_OBJECT (tree_column), "min_width");
812 813
}

814 815 816 817 818 819 820 821 822
/**
 * gtk_tree_view_column_get_min_width:
 * @tree_column: A #GtkTreeViewColumn.
 * 
 * Returns the minimum width in pixels of the @tree_column, or -1 if no minimum
 * width is set.
 * 
 * Return value: The minimum width of the @tree_column.
 **/
823 824 825 826 827 828 829 830 831
gint
gtk_tree_view_column_get_min_width (GtkTreeViewColumn *tree_column)
{
  g_return_val_if_fail (tree_column != NULL, -1);
  g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), -1);

  return tree_column->min_width;
}

832 833 834 835 836 837 838 839
/**
 * gtk_tree_view_column_set_max_width:
 * @tree_column: A #GtkTreeViewColumn.
 * @max_width: The maximum width of the column in pixels, or -1.
 * 
 * Sets the maximum width of the @tree_column.  If @max_width is -1, then the
 * maximum width is unset.
 **/
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
void
gtk_tree_view_column_set_max_width (GtkTreeViewColumn *tree_column,
				    gint               max_width)
{
  gint real_min_width;

  g_return_if_fail (tree_column != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
  g_return_if_fail (max_width >= -1);

  if (max_width == tree_column->max_width)
    return;

  real_min_width = tree_column->min_width == -1 ?
    tree_column->button->requisition.width : tree_column->min_width;

  if (GTK_WIDGET_REALIZED (tree_column->tree_view) &&
Havoc Pennington's avatar
Havoc Pennington committed
857 858
      ((tree_column->max_width < tree_column->width) ||
       (max_width != -1 && max_width < tree_column->width)))
859 860 861 862 863 864
    gtk_widget_queue_resize (tree_column->tree_view);

  tree_column->max_width = max_width;

  if (real_min_width > max_width)
    tree_column->min_width = max_width;
865 866

  g_object_notify (G_OBJECT (tree_column), "max_width");
867 868
}

869 870 871 872 873 874 875 876 877
/**
 * gtk_tree_view_column_get_max_width:
 * @tree_column: A #GtkTreeViewColumn.
 * 
 * Returns the maximum width in pixels of the @tree_column, or -1 if no maximum
 * width is set.
 * 
 * Return value: The maximum width of the @tree_column.
 **/
878 879 880 881 882 883 884 885 886
gint
gtk_tree_view_column_get_max_width (GtkTreeViewColumn *tree_column)
{
  g_return_val_if_fail (tree_column != NULL, -1);
  g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), -1);

  return tree_column->max_width;
}

887 888 889 890 891 892 893 894 895 896 897 898 899 900
/**
 * gtk_tree_view_column_clicked:
 * @tree_column: a #GtkTreeViewColumn
 * 
 * Emits the "clicked" signal on the column.
 **/
void
gtk_tree_view_column_clicked (GtkTreeViewColumn *tree_column)
{
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));

  gtk_signal_emit (GTK_OBJECT (tree_column), tree_column_signals[CLICKED]);
}

901 902 903 904 905 906 907 908
/**
 * gtk_tree_view_column_set_title:
 * @tree_column: A #GtkTreeViewColumn.
 * @title: The title of the @tree_column.
 * 
 * Sets the title of the @tree_column.  If a custom widget has been set, then
 * this value is ignored.
 **/
909 910 911 912 913 914 915 916 917 918 919 920
void
gtk_tree_view_column_set_title (GtkTreeViewColumn *tree_column,
				gchar         *title)
{
  g_return_if_fail (tree_column != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));

  g_free (tree_column->title);
  if (title)
    tree_column->title = g_strdup (title);
  else
    tree_column->title = NULL;
921 922 923 924 925 926 927 928 929 930

  /* Hmmm.  This is a little ugly... */
  if (tree_column->button)
    {
      if (GTK_BIN (tree_column->button)->child &&
	  GTK_IS_ALIGNMENT (GTK_BIN (tree_column->button)->child))
	{
	  if (GTK_BIN (GTK_BIN (tree_column->button)->child)->child &&
	      GTK_IS_LABEL (GTK_BIN (GTK_BIN (tree_column->button)->child)->child))
	    {
931 932
	      gtk_label_set_text (GTK_LABEL (GTK_BIN (GTK_BIN (tree_column->button)->child)->child),
                                  tree_column->title);
933 934 935
	    }
	}
    }
936 937

  g_object_notify (G_OBJECT (tree_column), "title");
938 939
}

940 941 942 943 944 945 946 947
/**
 * gtk_tree_view_column_get_title:
 * @tree_column: A #GtkTreeViewColumn.
 * 
 * Returns the title of the widget.  This value should not be modified.
 * 
 * Return value: the title of the column.
 **/
948 949 950 951 952 953 954 955 956
gchar *
gtk_tree_view_column_get_title (GtkTreeViewColumn *tree_column)
{
  g_return_val_if_fail (tree_column != NULL, NULL);
  g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), NULL);

  return tree_column->title;
}

957
/**
958
 * gtk_tree_view_column_set_clickable:
959 960 961 962 963 964
 * @tree_column: A #GtkTreeViewColumn.
 * @active: TRUE if the header is active.
 * 
 * Sets the header to be active if @active is TRUE.  When the header is active,
 * then it can take keyboard focus, and can be clicked.
 **/
965
void
966 967
gtk_tree_view_column_set_clickable (GtkTreeViewColumn *tree_column,
                                    gboolean           active)
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001
{
  g_return_if_fail (tree_column != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));

  if (!tree_column->button)
    return;

  if (tree_column->button_active == active)
    return;

  tree_column->button_active = active;
  if (active)
    {
      gtk_signal_disconnect_by_func (GTK_OBJECT (tree_column->button),
				     (GtkSignalFunc) gtk_tree_view_passive_func,
				     NULL);

      GTK_WIDGET_SET_FLAGS (tree_column->button, GTK_CAN_FOCUS);

      if (GTK_WIDGET_VISIBLE (tree_column->tree_view))
	gtk_widget_queue_draw (tree_column->button);
    }
  else
    {
      gtk_signal_connect (GTK_OBJECT (tree_column->button),
			  "event",
			  (GtkSignalFunc) gtk_tree_view_passive_func,
			  NULL);

      GTK_WIDGET_UNSET_FLAGS (tree_column->button, GTK_CAN_FOCUS);

      if (GTK_WIDGET_VISIBLE (tree_column->tree_view))
	gtk_widget_queue_draw (tree_column->button);
    }
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019

  g_object_notify (G_OBJECT (tree_column), "clickable");
}

/**
 * gtk_tree_view_column_get_clickable:
 * @tree_column: a #GtkTreeViewColumn
 * 
 * Returns %TRUE if the user can click on the header for the column.
 * 
 * Return value: whether the user can click the column header
 **/
gboolean
gtk_tree_view_column_get_clickable (GtkTreeViewColumn *tree_column)
{
  g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), FALSE);

  return tree_column->button_active;
1020 1021
}

1022 1023 1024 1025 1026 1027 1028 1029
/**
 * gtk_tree_view_column_set_widget:
 * @tree_column: A #GtkTreeViewColumn.
 * @widget: A child #GtkWidget, or NULL.
 * 
 * Sets the widget in the header to be @widget.  If widget is NULL, then the
 * header button is set with a #GtkLabel set to the title of @tree_column.
 **/
1030 1031 1032 1033
void
gtk_tree_view_column_set_widget (GtkTreeViewColumn *tree_column,
				 GtkWidget         *widget)
{
1034
  /* FIXME: Implement this function. */
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
#if 0
  gint new_button = 0;
  GtkWidget *old_widget;

  g_return_if_fail (tree_view != NULL);
  g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));

  if (column < 0 || column >= tree_view->priv->columns)
    return;

  /* if the column button doesn't currently exist,
   * it has to be created first */
  if (!column->button)
    {
      column_button_create (tree_view, column);
      new_button = 1;
    }

  column_title_new (clist, column, NULL);

  /* remove and destroy the old widget */
  old_widget = GTK_BIN (clist->column[column].button)->child;
  if (old_widget)
    gtk_container_remove (GTK_CONTAINER (clist->column[column].button),
			  old_widget);

  /* add and show the widget */
  if (widget)
    {
      gtk_container_add (GTK_CONTAINER (clist->column[column].button), widget);
      gtk_widget_show (widget);
    }

  /* if this button didn't previously exist, then the
   * column button positions have to be re-computed */
  if (GTK_WIDGET_VISIBLE (clist) && new_button)
    size_allocate_title_buttons (clist);
#endif
1073 1074

  g_object_notify (G_OBJECT (tree_column), "widget");
1075 1076
}

1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
/**
 * gtk_tree_view_column_get_widget:
 * @tree_column: A #GtkTreeViewColumn.
 * 
 * Returns the #GtkWidget in the button in the column header.  If a custom
 * widget has not been set, then this will be a #GtkAlignment with a #GtkLabel
 * in it.
 * 
 * Return value: The #GtkWidget in the column header.
 **/
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
GtkWidget *
gtk_tree_view_column_get_widget (GtkTreeViewColumn *tree_column)
{
  g_return_val_if_fail (tree_column != NULL, NULL);
  g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column), NULL);

  if (tree_column->button)
    return GTK_BUTTON (tree_column->button)->child;

  return NULL;
}

1099 1100 1101 1102 1103 1104 1105 1106
/**
 * gtk_tree_view_column_set_justification:
 * @tree_column: A #GtkTreeViewColumn.
 * @justification: The justification of the title.
 * 
 * Sets the justification of the title inside the column header.  If a custom
 * widget has been set, then this value is discarded.
 **/
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
void
gtk_tree_view_column_set_justification (GtkTreeViewColumn *tree_column,
					GtkJustification   justification)
{
  GtkWidget *alignment;

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

  if (tree_column->justification == justification)
    return;

  tree_column->justification = justification;

  /* change the alignment of the button title if it's not a
   * custom widget */
  alignment = GTK_BIN (tree_column->button)->child;

  if (GTK_IS_ALIGNMENT (alignment))
    {
      switch (tree_column->justification)
	{
	case GTK_JUSTIFY_LEFT:
	  gtk_alignment_set (GTK_ALIGNMENT (alignment), 0.0, 0.5, 0.0, 0.0);
	  break;

	case GTK_JUSTIFY_RIGHT:
	  gtk_alignment_set (GTK_ALIGNMENT (alignment), 1.0, 0.5, 0.0, 0.0);
	  break;

	case GTK_JUSTIFY_CENTER:
	  gtk_alignment_set (GTK_ALIGNMENT (alignment), 0.5, 0.5, 0.0, 0.0);
	  break;

	case GTK_JUSTIFY_FILL:
	  gtk_alignment_set (GTK_ALIGNMENT (alignment), 0.5, 0.5, 0.0, 0.0);
	  break;

	default:
	  break;
	}
    }
1149 1150

  g_object_notify (G_OBJECT (tree_column), "justification");
1151
}