gtkclist.c 81.3 KB
Newer Older
1 2
/* GTK - The GIMP Toolkit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball, Josh MacDonald, 
3
 * Copyright (C) 1997-1998 Jay Painter <jpaint@serv.net><jpaint@gimp.org>  
4
 *
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#include <stdlib.h>
20
#include "../config.h"
21 22
#include "gtkclist.h"

23 24 25
/* the number rows memchunk expands at a time */
#define CLIST_OPTIMUM_SIZE 512

26
/* the width of the column resize windows */
27
#define DRAG_WIDTH  6
28 29 30 31 32 33 34 35 36 37

/* minimum allowed width of a column */
#define COLUMN_MIN_WIDTH 5

/* this defigns the base grid spacing */
#define CELL_SPACING 1

/* added the horizontal space at the beginning and end of a row*/
#define COLUMN_INSET 3

38 39
/* scrollbar spacing class macro */
#define SCROLLBAR_SPACING(w) (GTK_CLIST_CLASS (GTK_OBJECT (w)->klass)->scrollbar_spacing)
40 41 42

/* gives the top pixel of the given row in context of
 * the clist's voffset */
43 44
#define ROW_TOP_YPIXEL(clist, row) (((clist)->row_height * (row)) + \
				    (((row) + 1) * CELL_SPACING) + \
45 46 47 48
				    (clist)->voffset)

/* returns the row index from a y pixel location in the 
 * context of the clist's voffset */
49
#define ROW_FROM_YPIXEL(clist, y)  (((y) - (clist)->voffset) / \
50 51 52 53
				    ((clist)->row_height + CELL_SPACING))

/* gives the left pixel of the given column in context of
 * the clist's hoffset */
54
#define COLUMN_LEFT_XPIXEL(clist, column)  ((clist)->column[(column)].area.x + \
55 56 57 58
					    (clist)->hoffset)

/* returns the column index from a x pixel location in the 
 * context of the clist's hoffset */
59
static inline gint
60 61 62 63 64 65 66 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 93 94 95 96 97 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 124 125 126 127 128 129 130 131 132 133 134
COLUMN_FROM_XPIXEL (GtkCList * clist,
		    gint x)
{
  gint i, cx;

  for (i = 0; i < clist->columns; i++)
    {
      cx = clist->column[i].area.x + clist->hoffset;

      if (x >= (cx - (COLUMN_INSET + CELL_SPACING)) &&
	  x <= (cx + clist->column[i].area.width + COLUMN_INSET))
	return i;
    }

  /* no match */
  return -1;
}

/* returns the top pixel of the given row in the context of
 * the list height */
#define ROW_TOP(clist, row)        (((clist)->row_height + CELL_SPACING) * (row))

/* returns the left pixel of the given column in the context of
 * the list width */
#define COLUMN_LEFT(clist, column) ((clist)->column[(column)].area.x)

/* returns the total height of the list */
#define LIST_HEIGHT(clist)         (((clist)->row_height * ((clist)->rows)) + \
				    (CELL_SPACING * ((clist)->rows + 1)))

/* returns the total width of the list */
#define LIST_WIDTH(clist)          ((clist)->column[(clist)->columns - 1].area.x + \
				    (clist)->column[(clist)->columns - 1].area.width + \
				    COLUMN_INSET + CELL_SPACING)


/* Signals */
enum
{
  SELECT_ROW,
  UNSELECT_ROW,
  CLICK_COLUMN,
  LAST_SIGNAL
};

typedef void (*GtkCListSignal1) (GtkObject * object,
				 gint arg1,
				 gint arg2,
				 GdkEventButton * arg3,
				 gpointer data);

typedef void (*GtkCListSignal2) (GtkObject * object,
				 gint arg1,
				 gpointer data);


/* GtkCList Methods */
static void gtk_clist_class_init (GtkCListClass * klass);
static void gtk_clist_init (GtkCList * clist);

/* GtkObject Methods */
static void gtk_clist_destroy (GtkObject * object);


/* GtkWidget Methods */
static void gtk_clist_realize (GtkWidget * widget);
static void gtk_clist_unrealize (GtkWidget * widget);
static void gtk_clist_map (GtkWidget * widget);
static void gtk_clist_unmap (GtkWidget * widget);
static void gtk_clist_draw (GtkWidget * widget,
			    GdkRectangle * area);
static gint gtk_clist_expose (GtkWidget * widget,
			      GdkEventExpose * event);
static gint gtk_clist_button_press (GtkWidget * widget,
				    GdkEventButton * event);
135 136 137 138
static gint gtk_clist_button_release (GtkWidget * widget,
				      GdkEventButton * event);
static gint gtk_clist_motion (GtkWidget * widget, 
			      GdkEventMotion * event);
139 140 141 142 143 144 145 146 147 148 149

static void gtk_clist_size_request (GtkWidget * widget,
				    GtkRequisition * requisition);
static void gtk_clist_size_allocate (GtkWidget * widget,
				     GtkAllocation * allocation);

/* GtkContainer Methods */
static void gtk_clist_foreach (GtkContainer * container,
			       GtkCallback callback,
			       gpointer callback_data);

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
/* Drawing */
static void draw_row (GtkCList * clist,
		      GdkRectangle * area,
		      gint row,
		      GtkCListRow * clist_row);
static void draw_rows (GtkCList * clist,
		       GdkRectangle * area);

/* Size Allocation */
static void size_allocate_title_buttons (GtkCList * clist);
static void size_allocate_columns (GtkCList * clist);

/* Selection */
static void real_select_row (GtkCList * clist,
			     gint row,
			     gint column,
			     GdkEventButton * event);
static void real_unselect_row (GtkCList * clist,
			       gint row,
			       gint column,
			       GdkEventButton * event);
static gint get_selection_info (GtkCList * clist,
				gint x,
				gint y,
				gint * row,
				gint * column);

/* Resize Columns */
178 179 180
static void draw_xor_line (GtkCList * clist);
static gint new_column_width (GtkCList * clist,
			      gint column,
181 182
			      gint * x,
			      gint * visible);
183 184 185
static void resize_column (GtkCList * clist,
			   gint column,
			   gint width);
186 187

/* Buttons */
188 189 190 191
static void column_button_create (GtkCList * clist,
				  gint column);
static void column_button_clicked (GtkWidget * widget,
				   gpointer data);
192 193

/* Scrollbars */
Jay Painter's avatar
Jay Painter committed
194 195 196 197 198 199 200 201 202 203
static void create_scrollbars (GtkCList * clist);
static void adjust_scrollbars (GtkCList * clist);
static void vadjustment_changed (GtkAdjustment * adjustment,
				 gpointer data);
static void vadjustment_value_changed (GtkAdjustment * adjustment,
				       gpointer data);
static void hadjustment_changed (GtkAdjustment * adjustment,
				 gpointer data);
static void hadjustment_value_changed (GtkAdjustment * adjustment,
				       gpointer data);
204 205 206


/* Memory Allocation/Distruction Routines */
207
static GtkCListColumn *columns_new (GtkCList * clist);
208

209 210 211 212
static void column_title_new (GtkCList * clist,
			      gint column,
			      gchar * title);
static void columns_delete (GtkCList * clist);
213

214
static GtkCListRow *row_new (GtkCList * clist);
215

216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
static void row_delete (GtkCList * clist,
			GtkCListRow * clist_row);
static void cell_empty (GtkCList * clist,
			GtkCListRow * clist_row,
			gint column);
static void cell_set_text (GtkCList * clist,
			   GtkCListRow * clist_row,
			   gint column,
			   gchar * text);
static void cell_set_pixmap (GtkCList * clist,
			     GtkCListRow * clist_row,
			     gint column,
			     GdkPixmap * pixmap,
			     GdkBitmap * mask);
static void cell_set_pixtext (GtkCList * clist,
			      GtkCListRow * clist_row,
			      gint column,
			      gchar * text,
			      guint8 spacing,
			      GdkPixmap * pixmap,
			      GdkBitmap * mask);
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

/* Signals */
static void gtk_clist_marshal_signal_1 (GtkObject * object,
					GtkSignalFunc func,
					gpointer func_data,
					GtkArg * args);
static void gtk_clist_marshal_signal_2 (GtkObject * object,
					GtkSignalFunc func,
					gpointer func_data,
					GtkArg * args);

static GtkContainerClass *parent_class = NULL;
static gint clist_signals[LAST_SIGNAL] = {0};


guint
gtk_clist_get_type ()
{
  static guint clist_type = 0;

  if (!clist_type)
    {
      GtkTypeInfo clist_info =
      {
	"GtkCList",
	sizeof (GtkCList),
	sizeof (GtkCListClass),
	(GtkClassInitFunc) gtk_clist_class_init,
	(GtkObjectInitFunc) gtk_clist_init,
266 267
	(GtkArgSetFunc) NULL,
        (GtkArgGetFunc) NULL,
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
      };

      clist_type = gtk_type_unique (gtk_container_get_type (), &clist_info);
    }

  return clist_type;
}

static void
gtk_clist_class_init (GtkCListClass * klass)
{
  GtkObjectClass *object_class;
  GtkWidgetClass *widget_class;
  GtkContainerClass *container_class;

  object_class = (GtkObjectClass *) klass;
  widget_class = (GtkWidgetClass *) klass;
  container_class = (GtkContainerClass *) klass;

  parent_class = gtk_type_class (gtk_container_get_type ());

  clist_signals[SELECT_ROW] =
    gtk_signal_new ("select_row",
		    GTK_RUN_LAST,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCListClass, select_row),
		    gtk_clist_marshal_signal_1,
	    GTK_TYPE_NONE, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER);
  clist_signals[UNSELECT_ROW] =
    gtk_signal_new ("unselect_row",
		    GTK_RUN_LAST,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCListClass, unselect_row),
		    gtk_clist_marshal_signal_1,
	    GTK_TYPE_NONE, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER);
  clist_signals[CLICK_COLUMN] =
    gtk_signal_new ("click_column",
		    GTK_RUN_LAST,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCListClass, click_column),
		    gtk_clist_marshal_signal_2,
		    GTK_TYPE_NONE, 1, GTK_TYPE_INT);

  gtk_object_class_add_signals (object_class, clist_signals, LAST_SIGNAL);

  object_class->destroy = gtk_clist_destroy;

  widget_class->realize = gtk_clist_realize;
  widget_class->unrealize = gtk_clist_unrealize;
  widget_class->map = gtk_clist_map;
  widget_class->unmap = gtk_clist_unmap;
  widget_class->draw = gtk_clist_draw;
  widget_class->button_press_event = gtk_clist_button_press;
321 322
  widget_class->button_release_event = gtk_clist_button_release;
  widget_class->motion_notify_event = gtk_clist_motion;
323 324 325 326 327 328 329 330
  widget_class->expose_event = gtk_clist_expose;
  widget_class->size_request = gtk_clist_size_request;
  widget_class->size_allocate = gtk_clist_size_allocate;

  container_class->add = NULL;
  container_class->remove = NULL;
  container_class->foreach = gtk_clist_foreach;

331 332
  klass->select_row = real_select_row;
  klass->unselect_row = real_unselect_row;
333
  klass->click_column = NULL;
334 335

  klass->scrollbar_spacing = 5;
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 370 371 372 373 374 375 376 377 378 379 380 381 382 383
}

static void
gtk_clist_marshal_signal_1 (GtkObject * object,
			    GtkSignalFunc func,
			    gpointer func_data,
			    GtkArg * args)
{
  GtkCListSignal1 rfunc;

  rfunc = (GtkCListSignal1) func;

  (*rfunc) (object, GTK_VALUE_INT (args[0]),
	    GTK_VALUE_INT (args[1]),
	    GTK_VALUE_POINTER (args[2]),
	    func_data);
}

static void
gtk_clist_marshal_signal_2 (GtkObject * object,
			    GtkSignalFunc func,
			    gpointer func_data,
			    GtkArg * args)
{
  GtkCListSignal2 rfunc;

  rfunc = (GtkCListSignal2) func;

  (*rfunc) (object, GTK_VALUE_INT (args[0]),
	    func_data);
}

static void
gtk_clist_init (GtkCList * clist)
{
  clist->flags = 0;

  GTK_WIDGET_UNSET_FLAGS (clist, GTK_NO_WINDOW);
  GTK_CLIST_SET_FLAGS (clist, CLIST_FROZEN);

  clist->rows = 0;
  clist->row_center_offset = 0;
  clist->row_height = 0;
  clist->row_list = NULL;
  clist->row_list_end = NULL;

  clist->columns = 0;

384
  clist->title_window = NULL;
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
  clist->column_title_area.x = 0;
  clist->column_title_area.y = 0;
  clist->column_title_area.width = 0;
  clist->column_title_area.height = 0;

  clist->clist_window = NULL;
  clist->clist_window_width = 0;
  clist->clist_window_height = 0;

  clist->hoffset = 0;
  clist->voffset = 0;

  clist->shadow_type = GTK_SHADOW_IN;
  clist->hscrollbar_policy = GTK_POLICY_ALWAYS;
  clist->vscrollbar_policy = GTK_POLICY_ALWAYS;

  clist->cursor_drag = NULL;
  clist->xor_gc = NULL;
  clist->fg_gc = NULL;
  clist->bg_gc = NULL;
  clist->x_drag = 0;

  clist->selection_mode = GTK_SELECTION_SINGLE;
408
  clist->selection = NULL;
409 410
}

411 412 413 414 415
/*
 * GTKCLIST PUBLIC INTERFACE
 *   gtk_clist_new_with_titles
 *   gtk_clist_new
 */
416
GtkWidget *
417 418
gtk_clist_new_with_titles (int columns,
			   gchar * titles[])
419 420
{
  int i;
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
  GtkWidget *widget;
  GtkCList *clist;

  if (titles == NULL)
    return NULL;

  widget = gtk_clist_new (columns);
  if (!widget)
    return NULL;
  else
    clist = GTK_CLIST (widget);

  /* set column titles */
  GTK_CLIST_SET_FLAGS (clist, CLIST_SHOW_TITLES);
  for (i = 0; i < columns; i++)
    {
      gtk_clist_set_column_title (clist, i, titles[i]);
      clist->column[i].width = gdk_string_width (GTK_WIDGET (clist)->style->font, clist->column[i].title);
    }

  return widget;
}

GtkWidget *
gtk_clist_new (int columns)
{
447 448 449
  GtkCList *clist;

  /* sanity check */
450
  if (columns < 1)
451 452 453
    return NULL;

  clist = gtk_type_new (gtk_clist_get_type ());
454
  GTK_CLIST_UNSET_FLAGS (clist, CLIST_SHOW_TITLES);
455 456 457

  /* initalize memory chunks */
  clist->row_mem_chunk = g_mem_chunk_new ("clist row mem chunk",
458 459
					  sizeof (GtkCListRow),
					  sizeof (GtkCListRow) * CLIST_OPTIMUM_SIZE, 
460
					  G_ALLOC_AND_FREE);
461

462 463
  clist->cell_mem_chunk = g_mem_chunk_new ("clist cell mem chunk",
					   sizeof (GtkCell) * columns,
464
					   sizeof (GtkCell) * columns * CLIST_OPTIMUM_SIZE, 
465
					   G_ALLOC_AND_FREE);
466 467 468

  /* set number of columns, allocate memory */
  clist->columns = columns;
469
  clist->column = columns_new (clist);
470

471 472 473 474
  /* there needs to be at least one column button 
   * because there is alot of code that will break if it
   * isn't there*/
  column_button_create (clist, 0);
475

Jay Painter's avatar
Jay Painter committed
476 477
  /* create scrollbars */
  create_scrollbars (clist);
478 479 480 481 482 483 484 485 486 487 488 489 490 491 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

  return GTK_WIDGET (clist);
}

void
gtk_clist_set_border (GtkCList * clist,
		      GtkShadowType border)
{
  g_return_if_fail (clist != NULL);

  clist->shadow_type = border;

  if (GTK_WIDGET_VISIBLE (clist))
    gtk_widget_queue_resize (GTK_WIDGET (clist));
}

void
gtk_clist_set_selection_mode (GtkCList * clist,
			      GtkSelectionMode mode)
{
  g_return_if_fail (clist != NULL);

  clist->selection_mode = mode;
}

void
gtk_clist_freeze (GtkCList * clist)
{
  g_return_if_fail (clist != NULL);

  GTK_CLIST_SET_FLAGS (clist, CLIST_FROZEN);
}

void
gtk_clist_thaw (GtkCList * clist)
{
  g_return_if_fail (clist != NULL);

  GTK_CLIST_UNSET_FLAGS (clist, CLIST_FROZEN);

Jay Painter's avatar
Jay Painter committed
518
  adjust_scrollbars (clist);
519
  draw_rows (clist, NULL);
520 521
}

522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
void
gtk_clist_column_titles_show (GtkCList * clist)
{
  g_return_if_fail (clist != NULL);

  if (!GTK_CLIST_SHOW_TITLES (clist))
    {
      GTK_CLIST_SET_FLAGS (clist, CLIST_SHOW_TITLES);
      gdk_window_show (clist->title_window);
      gtk_widget_queue_resize (GTK_WIDGET (clist));
    }
}

void 
gtk_clist_column_titles_hide (GtkCList * clist)
{
Jay Painter's avatar
Jay Painter committed
538 539
  g_return_if_fail (clist != NULL);

540 541 542 543 544 545 546
  if (GTK_CLIST_SHOW_TITLES (clist))
    {
      GTK_CLIST_UNSET_FLAGS (clist, CLIST_SHOW_TITLES);
      gdk_window_hide (clist->title_window);
      gtk_widget_queue_resize (GTK_WIDGET (clist));
    }
}
547

Jay Painter's avatar
Jay Painter committed
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
void
gtk_clist_column_title_active (GtkCList * clist,
			       gint column)
{
  g_return_if_fail (clist != NULL);

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

  if (!GTK_WIDGET_SENSITIVE (clist->column[column].button) ||
      !GTK_WIDGET_CAN_FOCUS (clist->column[column].button))
    {
      GTK_WIDGET_SET_FLAGS (clist->column[column].button, GTK_SENSITIVE | GTK_CAN_FOCUS);
      if (GTK_WIDGET_VISIBLE (clist))
	gtk_widget_queue_draw (clist->column[column].button);
    }
}

void
gtk_clist_column_title_passive (GtkCList * clist,
				gint column)
{
  g_return_if_fail (clist != NULL);

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

  if (GTK_WIDGET_SENSITIVE (clist->column[column].button) ||
      GTK_WIDGET_CAN_FOCUS (clist->column[column].button))
    {
      GTK_WIDGET_UNSET_FLAGS (clist->column[column].button, GTK_SENSITIVE | GTK_CAN_FOCUS);
      if (GTK_WIDGET_VISIBLE (clist))
	gtk_widget_queue_draw (clist->column[column].button);
    }
}

void
gtk_clist_column_titles_active (GtkCList * clist)
{
  gint i;

  g_return_if_fail (clist != NULL);

  for (i = 0; i < clist->columns; i++)
    if (clist->column[i].button)
      gtk_clist_column_title_active (clist, i);
}

void
gtk_clist_column_titles_passive (GtkCList * clist)
{
  gint i;

  g_return_if_fail (clist != NULL);

  for (i = 0; i < clist->columns; i++)
    if (clist->column[i].button)
      gtk_clist_column_title_passive (clist, i);
}

608 609 610 611 612
void
gtk_clist_set_column_title (GtkCList * clist,
			    gint column,
			    gchar * title)
{
613
  gint new_button = 0;
614
  GtkWidget *old_widget;
615
  GtkWidget *alignment = NULL;
616 617 618 619 620 621 622
  GtkWidget *label;

  g_return_if_fail (clist != NULL);

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

623 624 625 626 627 628 629 630
  /* if the column button doesn't currently exhist,
   * it has to be created first */
  if (!clist->column[column].button)
    {
      column_button_create (clist, column);
      new_button = 1;
    }

631
  column_title_new (clist, column, title);
632 633 634 635 636 637 638 639 640

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

641
  /* create new alignment based no column justification */
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
  switch (clist->column[column].justification)
    {
    case GTK_JUSTIFY_LEFT:
      alignment = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
      break;

    case GTK_JUSTIFY_RIGHT:
      alignment = gtk_alignment_new (1.0, 0.5, 0.0, 0.0);
      break;

    case GTK_JUSTIFY_CENTER:
      alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
      break;

    case GTK_JUSTIFY_FILL:
      alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
      break;
    }

661 662 663 664 665 666 667 668 669
  label = gtk_label_new (clist->column[column].title);
  gtk_container_add (GTK_CONTAINER (alignment), label);
  gtk_container_add (GTK_CONTAINER (clist->column[column].button), alignment);
  gtk_widget_show (label);
  gtk_widget_show (alignment);

  /* if this button didn't previously exhist, then the
   * column button positions have to be re-computed */
  if (GTK_WIDGET_VISIBLE (clist) && new_button)
Jay Painter's avatar
Jay Painter committed
670
    size_allocate_title_buttons (clist);
671 672 673 674 675 676 677
}

void
gtk_clist_set_column_widget (GtkCList * clist,
			     gint column,
			     GtkWidget * widget)
{
678
  gint new_button = 0;
679 680 681 682 683 684 685
  GtkWidget *old_widget;

  g_return_if_fail (clist != NULL);

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

686 687 688 689 690 691 692 693
  /* if the column button doesn't currently exhist,
   * it has to be created first */
  if (!clist->column[column].button)
    {
      column_button_create (clist, column);
      new_button = 1;
    }

694
  column_title_new (clist, column, NULL);
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709

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

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

  /* if this button didn't previously exhist, then the
   * column button positions have to be re-computed */
  if (GTK_WIDGET_VISIBLE (clist) && new_button)
Jay Painter's avatar
Jay Painter committed
714
    size_allocate_title_buttons (clist);
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
}

void
gtk_clist_set_column_justification (GtkCList * clist,
				    gint column,
				    GtkJustification justification)
{
  GtkWidget *alignment;

  g_return_if_fail (clist != NULL);

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

  clist->column[column].justification = justification;

  /* change the alinment of the button title if it's not a
   * custom widget */
  if (clist->column[column].title)
    {
      alignment = GTK_BUTTON (clist->column[column].button)->child;

      switch (clist->column[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;
	}
    }

  if (!GTK_CLIST_FROZEN (clist))
761
    draw_rows (clist, NULL);
762 763 764 765 766 767 768 769 770 771 772 773 774 775
}

void
gtk_clist_set_column_width (GtkCList * clist,
			    gint column,
			    gint width)
{
  g_return_if_fail (clist != NULL);

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

  clist->column[column].width = width;

Jay Painter's avatar
Jay Painter committed
776 777
  size_allocate_columns (clist);
  size_allocate_title_buttons (clist);
778 779 780

  if (!GTK_CLIST_FROZEN (clist))
    {
Jay Painter's avatar
Jay Painter committed
781
      adjust_scrollbars (clist);
782
      draw_rows (clist, NULL);
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806
    }
}

void
gtk_clist_set_row_height (GtkCList * clist,
			  gint height)
{
  gint text_height;

  g_return_if_fail (clist != NULL);

  if (height > 0)
    clist->row_height = height;
  else
    return;

  GTK_CLIST_SET_FLAGS (clist, CLIST_ROW_HEIGHT_SET);

  text_height = height - (GTK_WIDGET (clist)->style->font->ascent +
			  GTK_WIDGET (clist) ->style->font->descent + 1);
  clist->row_center_offset = (text_height / 2) + GTK_WIDGET (clist)->style->font->ascent + 1.5;

  if (!GTK_CLIST_FROZEN (clist))
    {
Jay Painter's avatar
Jay Painter committed
807
      adjust_scrollbars (clist);
808
      draw_rows (clist, NULL);
809 810 811 812 813 814 815 816 817 818 819 820 821 822
    }
}

void
gtk_clist_moveto (GtkCList * clist,
		  gint row,
		  gint column,
		  gfloat row_align,
		  gfloat col_align)
{
  gint x, y;

  g_return_if_fail (clist != NULL);

823
  if (row < -1 || row >= clist->rows)
824
    return;
825
  if (column < -1 || column >= clist->columns)
826 827 828
    return;

  /* adjust vertical scrollbar */
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845
  if (row >= 0)
    {
      x = ROW_TOP (clist, row) - (row_align * (clist->clist_window_height - 
					       (clist->row_height + 2 * CELL_SPACING)));
      
      if (x < 0)
	GTK_RANGE (clist->vscrollbar)->adjustment->value = 0.0;
      else if (x > LIST_HEIGHT (clist) - clist->clist_window_height)
	GTK_RANGE (clist->vscrollbar)->adjustment->value = LIST_HEIGHT (clist) - 
	  clist->clist_window_height;
      else
	GTK_RANGE (clist->vscrollbar)->adjustment->value = x;
      
      gtk_signal_emit_by_name (GTK_OBJECT (GTK_RANGE (clist->vscrollbar)->adjustment), 
			       "value_changed");
    } 
     
846
  /* adjust horizontal scrollbar */
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863
  if (column >= 0)
    {
      y = COLUMN_LEFT (clist, column) - (col_align * (clist->clist_window_width - 
						      clist->column[column].area.width + 
						      2 * (CELL_SPACING + COLUMN_INSET)));
      
      if (y < 0)
	GTK_RANGE (clist->hscrollbar)->adjustment->value = 0.0;
      else if (y > LIST_WIDTH (clist) - clist->clist_window_width)
	GTK_RANGE (clist->hscrollbar)->adjustment->value = LIST_WIDTH (clist) - 
	  clist->clist_window_width;
      else
	GTK_RANGE (clist->hscrollbar)->adjustment->value = y;
      
      gtk_signal_emit_by_name (GTK_OBJECT (GTK_RANGE (clist->hscrollbar)->adjustment), 
			       "value_changed");
    }
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
}

void
gtk_clist_set_text (GtkCList * clist,
		    gint row,
		    gint column,
		    gchar * text)
{
  GtkCListRow *clist_row;

  g_return_if_fail (clist != NULL);

  if (row < 0 || row >= clist->rows)
    return;
  if (column < 0 || column >= clist->columns)
    return;

  clist_row = (g_list_nth (clist->row_list, row))->data;

  /* if text is null, then the cell is empty */
  if (text)
885
    cell_set_text (clist, clist_row, column, text);
886
  else
887
    cell_empty (clist, clist_row, column);
888 889 890 891 892

  /* redraw the list if it's not frozen */
  if (!GTK_CLIST_FROZEN (clist))
    {
      if (gtk_clist_row_isvisable (clist, row))
893
	draw_row (clist, NULL, row, clist_row);
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
    }
}

void
gtk_clist_set_pixmap (GtkCList * clist,
		      gint row,
		      gint column,
		      GdkPixmap * pixmap,
		      GdkBitmap * mask)
{
  GtkCListRow *clist_row;

  g_return_if_fail (clist != NULL);

  if (row < 0 || row >= clist->rows)
    return;
  if (column < 0 || column >= clist->columns)
    return;

  clist_row = (g_list_nth (clist->row_list, row))->data;
  
  gdk_pixmap_ref (pixmap);
  gdk_pixmap_ref (mask);
917
  cell_set_pixmap (clist, clist_row, column, pixmap, mask);
918 919 920 921 922

  /* redraw the list if it's not frozen */
  if (!GTK_CLIST_FROZEN (clist))
    {
      if (gtk_clist_row_isvisable (clist, row))
923
	draw_row (clist, NULL, row, clist_row);
924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
    }
}

void
gtk_clist_set_pixtext (GtkCList * clist,
		       gint row,
		       gint column,
		       gchar * text,
		       guint8 spacing,
		       GdkPixmap * pixmap,
		       GdkBitmap * mask)
{
  GtkCListRow *clist_row;

  g_return_if_fail (clist != NULL);

  if (row < 0 || row >= clist->rows)
    return;
  if (column < 0 || column >= clist->columns)
    return;

  clist_row = (g_list_nth (clist->row_list, row))->data;
  
  gdk_pixmap_ref (pixmap);
  gdk_pixmap_ref (mask);
949
  cell_set_pixtext (clist, clist_row, column, text, spacing, pixmap, mask);
950 951 952 953 954

  /* redraw the list if it's not frozen */
  if (!GTK_CLIST_FROZEN (clist))
    {
      if (gtk_clist_row_isvisable (clist, row))
955
	draw_row (clist, NULL, row, clist_row);
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
    }
}

void
gtk_clist_set_foreground (GtkCList * clist,
			  gint row,
			  GdkColor * color)
{
  GtkCListRow *clist_row;

  g_return_if_fail (clist != NULL);
  g_return_if_fail (color != NULL);

  if (row < 0 || row >= clist->rows)
    return;

  clist_row = (g_list_nth (clist->row_list, row))->data;
  clist_row->foreground = *color;

975 976
  if (!GTK_CLIST_FROZEN (clist) && gtk_clist_row_isvisable (clist, row))
    draw_row (clist, NULL, row, clist_row);
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993
}

void gtk_clist_set_background (GtkCList * clist,
			       gint row,
			       GdkColor * color)
{
  GtkCListRow *clist_row;

  g_return_if_fail (clist != NULL);
  g_return_if_fail (color != NULL);

  if (row < 0 || row >= clist->rows)
    return;

  clist_row = (g_list_nth (clist->row_list, row))->data;
  clist_row->background = *color;

994 995
  if (!GTK_CLIST_FROZEN (clist) && gtk_clist_row_isvisable (clist, row))
    draw_row (clist, NULL, row, clist_row);
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
}

void
gtk_clist_set_shift (GtkCList * clist,
		     gint row,
		     gint column,
		     gint verticle,
		     gint horizontal)
{
  GtkCListRow *clist_row;

  g_return_if_fail (clist != NULL);

  if (row < 0 || row >= clist->rows)
    return;
  if (column < 0 || column >= clist->columns)
    return;

  clist_row = (g_list_nth (clist->row_list, row))->data;

  clist_row->cell[column].verticle = verticle;
  clist_row->cell[column].horizontal = horizontal;

1019 1020
  if (!GTK_CLIST_FROZEN (clist) && gtk_clist_row_isvisable (clist, row))
    draw_row (clist, NULL, row, clist_row);
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
}

gint
gtk_clist_append (GtkCList * clist,
		  gchar * text[])
{
  gint i;
  GtkCListRow *clist_row;

  g_return_val_if_fail (clist != NULL, -1);

1032
  clist_row = row_new (clist);
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
  clist->rows++;

  /* keeps track of the end of the list so the list 
   * doesn't have to be traversed every time a item is added */
  if (!clist->row_list)
    {
      clist->row_list = g_list_append (clist->row_list, clist_row);
      clist->row_list_end = clist->row_list;

      /* check the selection mode to see if we should select
       * the first row automaticly */
      switch (clist->selection_mode)
	{
	case GTK_SELECTION_BROWSE:
	  gtk_clist_select_row (clist, 0, -1);
	  break;

	default:
	  break;
	}
    }
  else
    clist->row_list_end = (g_list_append (clist->row_list_end, clist_row))->next;

  /* set the text in the row's columns */
1058
  if (text)
1059 1060
    for (i = 0; i < clist->columns; i++)
      if (text[i])
1061
        cell_set_text (clist, clist_row, i, text[i]);
1062
  
1063 1064 1065
  /* redraw the list if it's not frozen */
  if (!GTK_CLIST_FROZEN (clist))
    {
Jay Painter's avatar
Jay Painter committed
1066
      adjust_scrollbars (clist);
1067 1068

      if (gtk_clist_row_isvisable (clist, clist->rows - 1))
1069
	draw_rows (clist, NULL);
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
    }

  /* return index of the row */
  return clist->rows - 1;
}

void
gtk_clist_insert (GtkCList * clist,
		  gint row,
		  gchar * text[])
{
  gint i;
  GtkCListRow *clist_row;

  g_return_if_fail (clist != NULL);
  g_return_if_fail (text != NULL);

1087
  /* return if out of bounds */
1088 1089 1090 1091
  if (row < 0 || row > (clist->rows - 1))
    return;

  /* create the row */
1092
  clist_row = row_new (clist);
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103

  /* reset the row end pointer if we're inserting at the
   * end of the list */
  if (row == clist->rows)
    clist->row_list_end = (g_list_append (clist->row_list_end, clist_row))->next;
  else
    clist->row_list = g_list_insert (clist->row_list, clist_row, row);

  clist->rows++;

  /* set the text in the row's columns */
1104 1105 1106
  if (text)
    for (i = 0; i < clist->columns; i++)
      if (text[i])
1107
	cell_set_text (clist, clist_row, i, text[i]);
1108 1109 1110 1111

  /* redraw the list if it isn't frozen */
  if (!GTK_CLIST_FROZEN (clist))
    {
Jay Painter's avatar
Jay Painter committed
1112
      adjust_scrollbars (clist);
1113 1114

      if (gtk_clist_row_isvisable (clist, row))
1115
	draw_rows (clist, NULL);
1116 1117 1118 1119 1120 1121 1122
    }
}

void
gtk_clist_remove (GtkCList * clist,
		  gint row)
{
1123
  gint was_visible;
1124 1125 1126 1127 1128 1129 1130 1131 1132
  GList *list;
  GtkCListRow *clist_row;

  g_return_if_fail (clist != NULL);

  /* return if out of bounds */
  if (row < 0 || row > (clist->rows - 1))
    return;

1133 1134
  was_visible = gtk_clist_row_isvisable (clist, row);

1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149
  /* get the row we're going to delete */
  list = g_list_nth (clist->row_list, row);
  clist_row = list->data;

  /* reset the row end pointer if we're removing at the
   * end of the list */
  if (row == clist->rows - 1)
    clist->row_list_end = list->prev;

  clist->row_list = g_list_remove (clist->row_list, clist_row);
  clist->rows--;

  /* redraw the row if it isn't frozen */
  if (!GTK_CLIST_FROZEN (clist))
    {
Jay Painter's avatar
Jay Painter committed
1150
      adjust_scrollbars (clist);
1151

1152
      if (was_visible)
1153
	draw_rows (clist, NULL);
1154
    }
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173

  if (clist_row->state == GTK_STATE_SELECTED)
    {
      switch (clist->selection_mode)
	{
	case GTK_SELECTION_BROWSE:
	  if (row >= clist->rows)
	    row--;
	  gtk_clist_select_row (clist, row, -1);
	  break;
	  
	default:
	  break;
	}

      /* remove from selection list */
      clist->selection = g_list_remove (clist->selection, clist_row);
    }

1174
  row_delete (clist, clist_row);
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184
}

void
gtk_clist_clear (GtkCList * clist)
{
  GList *list;
  GtkCListRow *clist_row;

  g_return_if_fail (clist != NULL);

1185
  /* remove all the rows */
1186 1187 1188 1189 1190 1191
  list = clist->row_list;
  while (list)
    {
      clist_row = list->data;
      list = list->next;

1192
      row_delete (clist, clist_row);
1193 1194 1195
    }
  g_list_free (clist->row_list);

1196 1197 1198
  /* free up the selection list */
  g_list_free (clist->selection);

1199 1200
  clist->row_list = NULL;
  clist->row_list_end = NULL;
1201
  clist->selection = NULL;
1202 1203 1204 1205 1206 1207 1208 1209 1210
  clist->voffset = 0;
  clist->rows = 0;

  /* zero-out the scrollbars */
  GTK_RANGE (clist->vscrollbar)->adjustment->value = 0.0;
  gtk_signal_emit_by_name (GTK_OBJECT (GTK_RANGE (clist->vscrollbar)->adjustment), "changed");

  if (!GTK_CLIST_FROZEN (clist))
    {
Jay Painter's avatar
Jay Painter committed
1211
      adjust_scrollbars (clist);
1212
      draw_rows (clist, NULL);
1213 1214 1215 1216 1217 1218 1219 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 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286
    }
}

void
gtk_clist_set_row_data (GtkCList * clist,
			gint row,
			gpointer data)
{
  GtkCListRow *clist_row;

  g_return_if_fail (clist != NULL);

  if (row < 0 || row > (clist->rows - 1))
    return;

  clist_row = (g_list_nth (clist->row_list, row))->data;
  clist_row->data = data;

  /*
   * re-send the selected signal if data is changed/added
   * so the application can respond to the new data -- 
   * this could be questionable behavior
   */
  if (clist_row->state == GTK_STATE_SELECTED)
    gtk_clist_select_row (clist, 0, 0);
}

gpointer
gtk_clist_get_row_data (GtkCList * clist,
			gint row)
{
  GtkCListRow *clist_row;

  g_return_val_if_fail (clist != NULL, NULL);

  if (row < 0 || row > (clist->rows - 1))
    return NULL;

  clist_row = (g_list_nth (clist->row_list, row))->data;
  return clist_row->data;
}

void
gtk_clist_select_row (GtkCList * clist,
		      gint row,
		      gint column)
{
  g_return_if_fail (clist != NULL);

  if (row < 0 || row >= clist->rows)
    return;

  if (column < -1 || column >= clist->columns)
    return;

  gtk_signal_emit (GTK_OBJECT (clist), clist_signals[SELECT_ROW], row, column, NULL);
}

void
gtk_clist_unselect_row (GtkCList * clist,
			gint row,
			gint column)
{
  g_return_if_fail (clist != NULL);

  if (row < 0 || row >= clist->rows)
    return;

  if (column < -1 || column >= clist->columns)
    return;

  gtk_signal_emit (GTK_OBJECT (clist), clist_signals[UNSELECT_ROW], row, column, NULL);
}

1287
gint
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350
gtk_clist_row_isvisable (GtkCList * clist,
			 gint row)
{
  g_return_val_if_fail (clist != NULL, 0);

  if (row < 0 || row >= clist->rows)
    return 0;

  if (clist->row_height == 0)
    return 0;

  if (row < ROW_FROM_YPIXEL (clist, 0))
    return 0;

  if (row > ROW_FROM_YPIXEL (clist, clist->clist_window_height))
    return 0;

  return 1;
}

GtkAdjustment *
gtk_clist_get_vadjustment (GtkCList * clist)
{
  g_return_val_if_fail (clist != NULL, NULL);
  g_return_val_if_fail (GTK_IS_CLIST (clist), NULL);

  return gtk_range_get_adjustment (GTK_RANGE (clist->vscrollbar));
}

GtkAdjustment *
gtk_clist_get_hadjustment (GtkCList * clist)
{
  g_return_val_if_fail (clist != NULL, NULL);
  g_return_val_if_fail (GTK_IS_CLIST (clist), NULL);

  return gtk_range_get_adjustment (GTK_RANGE (clist->hscrollbar));
}

void
gtk_clist_set_policy (GtkCList * clist,
		      GtkPolicyType vscrollbar_policy,
		      GtkPolicyType hscrollbar_policy)
{
  g_return_if_fail (clist != NULL);
  g_return_if_fail (GTK_IS_CLIST (clist));

  if (clist->vscrollbar_policy != vscrollbar_policy)
    {
      clist->vscrollbar_policy = vscrollbar_policy;

      if (GTK_WIDGET (clist)->parent)
	gtk_widget_queue_resize (GTK_WIDGET (clist));
    }

  if (clist->hscrollbar_policy != hscrollbar_policy)
    {
      clist->hscrollbar_policy = hscrollbar_policy;

      if (GTK_WIDGET (clist)->parent)
	gtk_widget_queue_resize (GTK_WIDGET (clist));
    }
}

1351 1352 1353 1354
/*
 * GTKOBJECT
 *   gtk_clist_destroy
 */
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368
static void
gtk_clist_destroy (GtkObject * object)
{
  gint i;
  GtkCList *clist;

  g_return_if_fail (object != NULL);
  g_return_if_fail (GTK_IS_CLIST (object));

  clist = GTK_CLIST (object);

  /* freeze the list */
  GTK_CLIST_SET_FLAGS (clist, CLIST_FROZEN);

1369 1370 1371
  /* get rid of all the rows */
  gtk_clist_clear (clist);

1372 1373 1374 1375 1376 1377
  /* destroy the scrollbars */
  gtk_widget_destroy (clist->vscrollbar);
  gtk_widget_destroy (clist->hscrollbar);

  /* get rid of all the column buttons */
  for (i = 0; i < clist->columns; i++)
1378 1379
    if (clist->column[i].button)
      gtk_widget_destroy (clist->column[i].button);
1380

1381
  columns_delete (clist);
1382 1383 1384 1385 1386 1387 1388 1389

  g_mem_chunk_destroy (clist->cell_mem_chunk);
  g_mem_chunk_destroy (clist->row_mem_chunk);

  if (GTK_OBJECT_CLASS (parent_class)->destroy)
    (*GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}

1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403
/*
 * GTKWIDGET
 *   gtk_clist_realize
 *   gtk_clist_unrealize
 *   gtk_clist_map
 *   gtk_clist_unmap
 *   gtk_clist_draw
 *   gtk_clist_expose
 *   gtk_clist_button_press
 *   gtk_clist_button_release
 *   gtk_clist_button_motion
 *   gtk_clist_size_request
 *   gtk_clist_size_allocate
 */
1404 1405 1406
static void
gtk_clist_realize (GtkWidget * widget)
{
1407
  gint i;
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436
  GtkCList *clist;
  GdkWindowAttr attributes;
  gint attributes_mask;
  GdkGCValues values;

  g_return_if_fail (widget != NULL);
  g_return_if_fail (GTK_IS_CLIST (widget));

  clist = GTK_CLIST (widget);

  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);

  attributes.window_type = GDK_WINDOW_CHILD;
  attributes.x = widget->allocation.x;
  attributes.y = widget->allocation.y;
  attributes.width = widget->allocation.width;
  attributes.height = widget->allocation.height;
  attributes.wclass = GDK_INPUT_OUTPUT;
  attributes.visual = gtk_widget_get_visual (widget);
  attributes.colormap = gtk_widget_get_colormap (widget);
  attributes.event_mask = gtk_widget_get_events (widget);
  attributes.event_mask |= (GDK_EXPOSURE_MASK |
			    GDK_BUTTON_PRESS_MASK |
			    GDK_BUTTON_RELEASE_MASK |
			    GDK_KEY_PRESS_MASK);
  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;


  /* main window */
1437
  widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450
  gdk_window_set_user_data (widget->window, clist);

  widget->style = gtk_style_attach (widget->style, widget->window);

  gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);

  /* column-title window */
  clist->title_window = gdk_window_new (widget->window, &attributes, attributes_mask);
  gdk_window_set_user_data (clist->title_window, clist);

  gtk_style_set_background (widget->style, clist->title_window, GTK_STATE_SELECTED);
  gdk_window_show (clist->title_window);

1451 1452
  /* set things up so column buttons are drawn in title window */
  for (i = 0; i < clist->columns; i++)
1453 1454
    if (clist->column[i].button)
      gtk_widget_set_parent_window (clist->column[i].button, clist->title_window);
1455

1456 1457 1458 1459 1460 1461 1462 1463 1464
  /* clist-window */
  clist->clist_window = gdk_window_new (widget->window, &attributes, attributes_mask);
  gdk_window_set_user_data (clist->clist_window, clist);

  gdk_window_set_background (clist->clist_window, &widget->style->white);
  gdk_window_show (clist->clist_window);
  gdk_window_get_size (clist->clist_window, &clist->clist_window_width,
		       &clist->clist_window_height);

1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479
  /* create resize windows */
  attributes.wclass = GDK_INPUT_ONLY;
  attributes.event_mask = (GDK_BUTTON_PRESS_MASK |
			   GDK_BUTTON_RELEASE_MASK |
			   GDK_POINTER_MOTION_MASK |
			   GDK_POINTER_MOTION_HINT_MASK);
  attributes.cursor = clist->cursor_drag = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW);
  attributes_mask = GDK_WA_CURSOR;
  
  for (i = 0; i < clist->columns; i++)
    {
      clist->column[i].window = gdk_window_new (clist->title_window, &attributes, attributes_mask);
      gdk_window_set_user_data (clist->column[i].window, clist);
      gdk_window_show (clist->column[i].window);
    }
1480

1481
  /* GCs */
1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500