gtkclist.c 165 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
 * 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
16 17 18
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
19 20
 */
#include <stdlib.h>
21
#include <string.h>
22
#include "../config.h"
23
#include "gtkmain.h"
24
#include "gtkclist.h"
25 26
#include "gtkbindings.h"
#include <gdk/gdkkeysyms.h>
27

28 29 30
/* the number rows memchunk expands at a time */
#define CLIST_OPTIMUM_SIZE 512

31
/* the width of the column resize windows */
32
#define DRAG_WIDTH  6
33 34 35 36 37 38 39 40 41 42

/* 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

43 44 45
/* used for auto-scrolling */
#define SCROLL_TIME  100

46 47
/* scrollbar spacing class macro */
#define SCROLLBAR_SPACING(w) (GTK_CLIST_CLASS (GTK_OBJECT (w)->klass)->scrollbar_spacing)
48 49 50

/* gives the top pixel of the given row in context of
 * the clist's voffset */
51 52
#define ROW_TOP_YPIXEL(clist, row) (((clist)->row_height * (row)) + \
				    (((row) + 1) * CELL_SPACING) + \
53 54 55 56
				    (clist)->voffset)

/* returns the row index from a y pixel location in the 
 * context of the clist's voffset */
57
#define ROW_FROM_YPIXEL(clist, y)  (((y) - (clist)->voffset) / \
58 59 60 61
				    ((clist)->row_height + CELL_SPACING))

/* gives the left pixel of the given column in context of
 * the clist's hoffset */
62
#define COLUMN_LEFT_XPIXEL(clist, colnum)  ((clist)->column[(colnum)].area.x + \
63 64 65 66
					    (clist)->hoffset)

/* returns the column index from a x pixel location in the 
 * context of the clist's hoffset */
67
static inline gint
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
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 */
92
#define COLUMN_LEFT(clist, colnum) ((clist)->column[(colnum)].area.x)
93 94 95 96 97 98 99 100 101 102

/* 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)

103

104 105 106
#define GTK_CLIST_CLASS_FW(_widget_) GTK_CLIST_CLASS (GTK_OBJECT (_widget_)->klass)


107 108 109 110 111 112
/* Signals */
enum
{
  SELECT_ROW,
  UNSELECT_ROW,
  CLICK_COLUMN,
113 114 115 116 117 118 119 120 121 122 123
  TOGGLE_FOCUS_ROW,
  SELECT_ALL,
  UNSELECT_ALL,
  UNDO_SELECTION,
  START_SELECTION,
  END_SELECTION,
  TOGGLE_ADD_MODE,
  EXTEND_SELECTION,
  SCROLL_VERTICAL,
  SCROLL_HORIZONTAL,
  ABORT_COLUMN_RESIZE,
124 125 126
  LAST_SIGNAL
};

127 128 129 130 131 132 133
enum
{
  SYNC_REMOVE,
  SYNC_INSERT
};


134 135 136
typedef void (*GtkCListSignal1) (GtkObject * object,
				 gint arg1,
				 gint arg2,
137
				 GdkEvent * arg3,
138 139
				 gpointer data);

140 141 142 143 144 145 146 147 148 149 150
typedef void (*GtkCListSignal2) (GtkObject *object,
				 gpointer data); 

typedef void (*GtkCListSignal3) (GtkObject * object,
				 gint arg1,
				 gpointer data);
typedef void (*GtkCListSignal4) (GtkObject * object,
				 gint arg1,
				 gfloat arg2,
				 gpointer data);
typedef void (*GtkCListSignal5) (GtkObject * object,
151
				 gint arg1,
152 153
				 gfloat arg2,
				 gboolean arg3,
154 155 156
				 gpointer data);


157 158 159 160
static void sync_selection (GtkCList * clist,
	                    gint row,
                            gint mode);

161 162 163
/* GtkCList Methods */
static void gtk_clist_class_init (GtkCListClass * klass);
static void gtk_clist_init (GtkCList * clist);
164
static void real_clear (GtkCList * clist);
165 166 167

/* GtkObject Methods */
static void gtk_clist_destroy (GtkObject * object);
168
static void gtk_clist_finalize (GtkObject * object);
169 170 171 172 173 174 175 176 177 178 179 180 181


/* 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);
182 183 184 185
static gint gtk_clist_button_release (GtkWidget * widget,
				      GdkEventButton * event);
static gint gtk_clist_motion (GtkWidget * widget, 
			      GdkEventMotion * event);
186 187 188 189
static void gtk_clist_size_request (GtkWidget * widget,
				    GtkRequisition * requisition);
static void gtk_clist_size_allocate (GtkWidget * widget,
				     GtkAllocation * allocation);
190 191 192 193 194
static gint get_selection_info (GtkCList * clist,
				gint x,
				gint y,
				gint * row,
				gint * column);
195 196

/* GtkContainer Methods */
197 198 199 200
static void gtk_clist_forall (GtkContainer *container,
			      gboolean      include_internals,
			      GtkCallback   callback,
			      gpointer      callback_data);
201

202 203 204 205 206 207 208 209 210 211 212 213 214
/* 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 */
215 216 217
static void toggle_row (GtkCList * clist,
			gint row,
			gint column,
218
			GdkEvent * event);
219 220 221
static void select_row (GtkCList * clist,
			gint row,
			gint column,
222
			GdkEvent * event);
223 224 225
static void unselect_row (GtkCList * clist,
			  gint row,
			  gint column,
226
			  GdkEvent * event);
227 228 229
static void real_select_row (GtkCList * clist,
			     gint row,
			     gint column,
230
			     GdkEvent * event);
231 232 233
static void real_unselect_row (GtkCList * clist,
			       gint row,
			       gint column,
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
			       GdkEvent * event);
static void update_extended_selection (GtkCList *clist,
				       gint row);
static GList * selection_find (GtkCList *clist,
			       gint row_number,
			       GList *row_list_element);
static void real_select_all (GtkCList * clist);
static void real_unselect_all (GtkCList * clist);
static void move_vertical (GtkCList *clist,
			   gint row,
			   gfloat align);
static void move_horizontal (GtkCList *clist,
			     gint diff);
static void real_undo_selection (GtkCList * clist);
static void fake_unselect_all (GtkCList *clist,
			       gint row);
static void fake_toggle_row (GtkCList *clist,
			     gint row);
static void resync_selection (GtkCList *clist,
			      GdkEvent *event);
254

255
/* Resize Columns */
256 257 258
static void draw_xor_line (GtkCList * clist);
static gint new_column_width (GtkCList * clist,
			      gint column,
259 260
			      gint * x,
			      gint * visible);
261 262 263
static void resize_column (GtkCList * clist,
			   gint column,
			   gint width);
264
static void abort_column_resize (GtkCList *clist);
265 266

/* Buttons */
267 268 269 270
static void column_button_create (GtkCList * clist,
				  gint column);
static void column_button_clicked (GtkWidget * widget,
				   gpointer data);
271 272

/* Scrollbars */
Jay Painter's avatar
Jay Painter committed
273 274
static void create_scrollbars (GtkCList * clist);
static void adjust_scrollbars (GtkCList * clist);
275
static void check_exposures   (GtkCList * clist);
Jay Painter's avatar
Jay Painter committed
276 277 278 279 280 281 282 283
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);
284 285

/* Memory Allocation/Distruction Routines */
286
static GtkCListColumn *columns_new (GtkCList * clist);
287

Tim Janik's avatar
Tim Janik committed
288 289 290
static void column_title_new (GtkCList    *clist,
			      gint         column,
			      const gchar *title);
291
static void columns_delete (GtkCList * clist);
292

293
static GtkCListRow *row_new (GtkCList * clist);
294

295 296
static void row_delete (GtkCList * clist,
			GtkCListRow * clist_row);
Tim Janik's avatar
Tim Janik committed
297 298 299 300 301 302 303 304
static void set_cell_contents (GtkCList    *clist,
			       GtkCListRow *clist_row,
			       gint         column,
			       GtkCellType  type,
			       const gchar *text,
			       guint8       spacing,
			       GdkPixmap   *pixmap,
			       GdkBitmap   *mask);
305 306 307 308 309
static gint real_insert_row (GtkCList * clist,
			     gint row,
			     gchar * text[]);
static void real_remove_row (GtkCList * clist,
			     gint row);
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
/* Focus handling */
static void gtk_clist_draw_focus (GtkWidget *widget);
static gint gtk_clist_focus_in   (GtkWidget     *widget,
				  GdkEventFocus *event);
static gint gtk_clist_focus_out  (GtkWidget     *widget,
				  GdkEventFocus *event);
static gint gtk_clist_focus      (GtkContainer     *container,
				  GtkDirectionType  direction);
static void gtk_clist_set_focus_child (GtkContainer *container,
				       GtkWidget    *child);
static gint gtk_clist_key_press  (GtkWidget   *widget,
				  GdkEventKey *event);

/* Selection handling */
static void set_anchor (GtkCList *clist,
			gboolean  add_mode,
			gint      anchor,
			gint      undo_anchor);
static void start_selection (GtkCList *clist);
static void end_selection (GtkCList *clist);

static void toggle_add_mode (GtkCList *clist);
static void toggle_focus_row (GtkCList *clist);
static void move_focus_row (GtkCList      *clist,
			    GtkScrollType  scroll_type,
			    gfloat         position);
static void scroll_horizontal (GtkCList      *clist,
			       GtkScrollType  scroll_type,
			       gfloat         position);
static void scroll_vertical (GtkCList      *clist,
			     GtkScrollType  scroll_type,
			     gfloat         position);
static void extend_selection (GtkCList      *clist,
			      GtkScrollType  scroll_type,
			      gfloat         position,
			      gboolean       auto_start_selection);

Stefan Jeske's avatar
Stefan Jeske committed
348 349 350 351
/* Sorting */
static gint default_compare (GtkCList     *clist,
			     gconstpointer row1,
			     gconstpointer row2);
352 353 354 355 356 357
static GList * gtk_clist_merge (GtkCList *clist,
				GList    *a,
				GList    *b);
static GList * gtk_clist_mergesort (GtkCList *clist,
				    GList    *list,
				    gint      num);
358
static void real_sort_list (GtkCList *clist);
Stefan Jeske's avatar
Stefan Jeske committed
359

360
/* Fill in data after widget is realized and has style */
361

362 363
static void add_style_data (GtkCList * clist);

364
static GtkContainerClass *parent_class = NULL;
365
static guint clist_signals[LAST_SIGNAL] = {0};
366

367

368
GtkType
369
gtk_clist_get_type (void)
370
{
371
  static GtkType clist_type = 0;
372 373 374 375 376 377 378 379 380 381

  if (!clist_type)
    {
      GtkTypeInfo clist_info =
      {
	"GtkCList",
	sizeof (GtkCList),
	sizeof (GtkCListClass),
	(GtkClassInitFunc) gtk_clist_class_init,
	(GtkObjectInitFunc) gtk_clist_init,
382
	/* reserved_1 */ NULL,
383 384
	/* reserved_2 */ NULL,
	(GtkClassInitFunc) NULL,
385 386
      };

387
      clist_type = gtk_type_unique (GTK_TYPE_CONTAINER, &clist_info);
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
    }

  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;

404
  parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
405

406 407
  clist_signals[SELECT_ROW] =
    gtk_signal_new ("select_row",
408
		    GTK_RUN_FIRST,
409 410
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCListClass, select_row),
411 412 413 414 415
		    gtk_marshal_NONE__INT_INT_POINTER,
		    GTK_TYPE_NONE, 3,
		    GTK_TYPE_INT,
		    GTK_TYPE_INT,
		    GTK_TYPE_GDK_EVENT);
416 417
  clist_signals[UNSELECT_ROW] =
    gtk_signal_new ("unselect_row",
418
		    GTK_RUN_FIRST,
419 420
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCListClass, unselect_row),
421
		    gtk_marshal_NONE__INT_INT_POINTER,
422
	    GTK_TYPE_NONE, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_GDK_EVENT);
423 424
  clist_signals[CLICK_COLUMN] =
    gtk_signal_new ("click_column",
425
		    GTK_RUN_FIRST,
426 427
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCListClass, click_column),
428
		    gtk_marshal_NONE__INT,
429 430
		    GTK_TYPE_NONE, 1, GTK_TYPE_INT);

431 432 433 434 435
  clist_signals[TOGGLE_FOCUS_ROW] =
    gtk_signal_new ("toggle_focus_row",
                    GTK_RUN_LAST | GTK_RUN_ACTION,
                    object_class->type,
                    GTK_SIGNAL_OFFSET (GtkCListClass, toggle_focus_row),
436
                    gtk_marshal_NONE__NONE,
437 438 439 440 441 442
                    GTK_TYPE_NONE, 0);
  clist_signals[SELECT_ALL] =
    gtk_signal_new ("select_all",
                    GTK_RUN_LAST | GTK_RUN_ACTION,
                    object_class->type,
                    GTK_SIGNAL_OFFSET (GtkCListClass, select_all),
443
                    gtk_marshal_NONE__NONE,
444 445 446 447 448 449
                    GTK_TYPE_NONE, 0);
  clist_signals[UNSELECT_ALL] =
    gtk_signal_new ("unselect_all",
                    GTK_RUN_LAST | GTK_RUN_ACTION,
                    object_class->type,
                    GTK_SIGNAL_OFFSET (GtkCListClass, unselect_all),
450
                    gtk_marshal_NONE__NONE,
451 452 453 454 455 456
                    GTK_TYPE_NONE, 0);
  clist_signals[UNDO_SELECTION] =
    gtk_signal_new ("undo_selection",
		    GTK_RUN_LAST | GTK_RUN_ACTION,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCListClass, undo_selection),
457
		    gtk_marshal_NONE__NONE,
458 459 460 461 462 463
		    GTK_TYPE_NONE, 0);
  clist_signals[START_SELECTION] =
    gtk_signal_new ("start_selection",
		    GTK_RUN_LAST | GTK_RUN_ACTION,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCListClass, start_selection),
464
		    gtk_marshal_NONE__NONE,
465 466 467 468 469 470
		    GTK_TYPE_NONE, 0);
  clist_signals[END_SELECTION] =
    gtk_signal_new ("end_selection",
		    GTK_RUN_LAST | GTK_RUN_ACTION,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCListClass, end_selection),
471
		    gtk_marshal_NONE__NONE,
472 473 474 475 476 477
		    GTK_TYPE_NONE, 0);
  clist_signals[TOGGLE_ADD_MODE] =
    gtk_signal_new ("toggle_add_mode",
		    GTK_RUN_LAST | GTK_RUN_ACTION,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCListClass, toggle_add_mode),
478
		    gtk_marshal_NONE__NONE,
479 480 481 482 483 484
		    GTK_TYPE_NONE, 0);
  clist_signals[EXTEND_SELECTION] =
    gtk_signal_new ("extend_selection",
                    GTK_RUN_LAST | GTK_RUN_ACTION,
                    object_class->type,
                    GTK_SIGNAL_OFFSET (GtkCListClass, extend_selection),
485
                    gtk_marshal_NONE__ENUM_FLOAT_BOOL,
486
                    GTK_TYPE_NONE, 3,
487
		    GTK_TYPE_SCROLL_TYPE, GTK_TYPE_FLOAT, GTK_TYPE_BOOL);
488 489 490 491 492
  clist_signals[SCROLL_VERTICAL] =
    gtk_signal_new ("scroll_vertical",
                    GTK_RUN_LAST | GTK_RUN_ACTION,
                    object_class->type,
                    GTK_SIGNAL_OFFSET (GtkCListClass, scroll_vertical),
493
                    gtk_marshal_NONE__ENUM_FLOAT,
494
                    GTK_TYPE_NONE, 2, GTK_TYPE_SCROLL_TYPE, GTK_TYPE_FLOAT);
495 496 497 498 499
  clist_signals[SCROLL_HORIZONTAL] =
    gtk_signal_new ("scroll_horizontal",
                    GTK_RUN_LAST | GTK_RUN_ACTION,
                    object_class->type,
                    GTK_SIGNAL_OFFSET (GtkCListClass, scroll_horizontal),
500
                    gtk_marshal_NONE__ENUM_FLOAT,
501
                    GTK_TYPE_NONE, 2, GTK_TYPE_SCROLL_TYPE, GTK_TYPE_FLOAT);
502 503 504 505 506
  clist_signals[ABORT_COLUMN_RESIZE] =
    gtk_signal_new ("abort_column_resize",
                    GTK_RUN_LAST | GTK_RUN_ACTION,
                    object_class->type,
                    GTK_SIGNAL_OFFSET (GtkCListClass, abort_column_resize),
507
                    gtk_marshal_NONE__NONE,
508 509 510
                    GTK_TYPE_NONE, 0);


511 512 513
  gtk_object_class_add_signals (object_class, clist_signals, LAST_SIGNAL);

  object_class->destroy = gtk_clist_destroy;
514
  object_class->finalize = gtk_clist_finalize;
515 516 517 518 519 520 521

  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;
522 523
  widget_class->button_release_event = gtk_clist_button_release;
  widget_class->motion_notify_event = gtk_clist_motion;
524 525 526
  widget_class->expose_event = gtk_clist_expose;
  widget_class->size_request = gtk_clist_size_request;
  widget_class->size_allocate = gtk_clist_size_allocate;
527 528 529 530
  widget_class->key_press_event = gtk_clist_key_press;
  widget_class->focus_in_event = gtk_clist_focus_in;
  widget_class->focus_out_event = gtk_clist_focus_out;
  widget_class->draw_focus = gtk_clist_draw_focus;
531

532 533
  /* container_class->add = NULL; use the default GtkContainerClass warning */
  /* container_class->remove = NULL; use the default GtkContainerClass warning */
534
  container_class->forall = gtk_clist_forall;
535 536
  container_class->focus = gtk_clist_focus;
  container_class->set_focus_child = gtk_clist_set_focus_child;
537

538 539
  klass->select_row = real_select_row;
  klass->unselect_row = real_unselect_row;
540 541 542
  klass->undo_selection = real_undo_selection;
  klass->resync_selection = resync_selection;
  klass->selection_find = selection_find;
543
  klass->click_column = NULL;
544
  klass->draw_row = draw_row;
545 546
  klass->insert_row = real_insert_row;
  klass->remove_row = real_remove_row;
547
  klass->clear = real_clear;
548
  klass->sort_list = real_sort_list;
549 550 551 552 553 554 555 556 557 558 559
  klass->select_all = real_select_all;
  klass->unselect_all = real_unselect_all;
  klass->fake_unselect_all = fake_unselect_all;
  klass->scroll_horizontal = scroll_horizontal;
  klass->scroll_vertical = scroll_vertical;
  klass->extend_selection = extend_selection;
  klass->toggle_focus_row = toggle_focus_row;
  klass->toggle_add_mode = toggle_add_mode;
  klass->start_selection = start_selection;
  klass->end_selection = end_selection;
  klass->abort_column_resize = abort_column_resize;
560
  klass->set_cell_contents = set_cell_contents;
561

562
  klass->scrollbar_spacing = 5;
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 654 655 656

  {
    GtkBindingSet *binding_set;

    binding_set = gtk_binding_set_by_class (klass);
    gtk_binding_entry_add_signal (binding_set, GDK_Up, 0,
				  "scroll_vertical", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_STEP_BACKWARD,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_Down, 0,
				  "scroll_vertical", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_STEP_FORWARD,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_Page_Up, 0,
				  "scroll_vertical", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_PAGE_BACKWARD,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_Page_Down, 0,
				  "scroll_vertical", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_PAGE_FORWARD,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_Home, GDK_CONTROL_MASK,
				  "scroll_vertical", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_End, GDK_CONTROL_MASK,
				  "scroll_vertical", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
                                  GTK_TYPE_FLOAT, 1.0);

    gtk_binding_entry_add_signal (binding_set, GDK_Up, GDK_SHIFT_MASK,
				  "extend_selection", 3,
				  GTK_TYPE_ENUM, GTK_SCROLL_STEP_BACKWARD,
                                  GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
    gtk_binding_entry_add_signal (binding_set, GDK_Down, GDK_SHIFT_MASK,
				  "extend_selection", 3,
				  GTK_TYPE_ENUM, GTK_SCROLL_STEP_FORWARD,
                                  GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
    gtk_binding_entry_add_signal (binding_set, GDK_Page_Up, GDK_SHIFT_MASK,
				  "extend_selection", 3,
				  GTK_TYPE_ENUM, GTK_SCROLL_PAGE_BACKWARD,
                                  GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
    gtk_binding_entry_add_signal (binding_set, GDK_Page_Down, GDK_SHIFT_MASK,
				  "extend_selection", 3,
				  GTK_TYPE_ENUM, GTK_SCROLL_PAGE_FORWARD,
                                  GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
    gtk_binding_entry_add_signal (binding_set, GDK_Home,
				  GDK_SHIFT_MASK | GDK_CONTROL_MASK,
				  "extend_selection", 3,
				  GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
                                  GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
    gtk_binding_entry_add_signal (binding_set, GDK_End,
				  GDK_SHIFT_MASK | GDK_CONTROL_MASK,
				  "extend_selection", 3,
				  GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
                                  GTK_TYPE_FLOAT, 1.0, GTK_TYPE_BOOL, TRUE);


    gtk_binding_entry_add_signal (binding_set, GDK_Left, 0,
				  "scroll_horizontal", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_STEP_BACKWARD,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_Right, 0,
				  "scroll_horizontal", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_STEP_FORWARD,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
				  "scroll_horizontal", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
				  "scroll_horizontal", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
                                  GTK_TYPE_FLOAT, 1.0);


    gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0,
				  "undo_selection", 0);
    gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0,
				  "abort_column_resize", 0);
    gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
				  "toggle_focus_row", 0);
    gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
				  "toggle_add_mode", 0);
    gtk_binding_entry_add_signal (binding_set, '/', GDK_CONTROL_MASK,
				  "select_all", 0);
    gtk_binding_entry_add_signal (binding_set, '\\', GDK_CONTROL_MASK,
				  "unselect_all", 0);
    gtk_binding_entry_add_signal (binding_set, GDK_Shift_L,
				  GDK_RELEASE_MASK | GDK_SHIFT_MASK,
				  "end_selection", 0);
    gtk_binding_entry_add_signal (binding_set, GDK_Shift_R,
				  GDK_RELEASE_MASK | GDK_SHIFT_MASK,
				  "end_selection", 0);
Lars Hamann's avatar
Lars Hamann committed
657 658 659 660 661 662 663 664
    gtk_binding_entry_add_signal (binding_set, GDK_Shift_L,
				  GDK_RELEASE_MASK | GDK_SHIFT_MASK |
				  GDK_CONTROL_MASK,
				  "end_selection", 0);
    gtk_binding_entry_add_signal (binding_set, GDK_Shift_R,
				  GDK_RELEASE_MASK | GDK_SHIFT_MASK |
				  GDK_CONTROL_MASK,
				  "end_selection", 0);
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 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 761 762
  }

  /*
  {
    GtkBindingSet *binding_set;

    binding_set = gtk_binding_set_by_class (klass);
    gtk_binding_entry_add_signal (binding_set, GDK_Up, 0,
				  "scroll_vertical", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_STEP_BACKWARD,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_Down, 0,
				  "scroll_vertical", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_STEP_FORWARD,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_Page_Up, 0,
				  "scroll_vertical", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_PAGE_BACKWARD,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_Page_Down, 0,
				  "scroll_vertical", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_PAGE_FORWARD,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_Home, GDK_CONTROL_MASK,
				  "scroll_vertical", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_End, GDK_CONTROL_MASK,
				  "scroll_vertical", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
                                  GTK_TYPE_FLOAT, 0);

    gtk_binding_entry_add_signal (binding_set, GDK_KP_Up, 0,
				  "extend_selection", 3,
				  GTK_TYPE_ENUM, GTK_SCROLL_STEP_BACKWARD,
                                  GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
    gtk_binding_entry_add_signal (binding_set, GDK_KP_Down, 0,
				  "extend_selection", 3,
				  GTK_TYPE_ENUM, GTK_SCROLL_STEP_FORWARD,
                                  GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
    gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Up, 0,
				  "extend_selection", 3,
				  GTK_TYPE_ENUM, GTK_SCROLL_PAGE_BACKWARD,
                                  GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
    gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Down, 0,
				  "extend_selection", 3,
				  GTK_TYPE_ENUM, GTK_SCROLL_PAGE_FORWARD,
                                  GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
    gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
				  "extend_selection", 3,
				  GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
                                  GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
    gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
				  "extend_selection", 3,
				  GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
                                  GTK_TYPE_FLOAT, 1.0, GTK_TYPE_BOOL, TRUE);

    gtk_binding_entry_add_signal (binding_set, GDK_Left, 0,
				  "scroll_horizontal", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_STEP_BACKWARD,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_KP_Left, 0,
				  "scroll_horizontal", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_STEP_BACKWARD,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_Right, 0,
				  "scroll_horizontal", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_STEP_FORWARD,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_KP_Right, 0,
				  "scroll_horizontal", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_STEP_FORWARD,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
				  "scroll_horizontal", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
                                  GTK_TYPE_FLOAT, 0.0);
    gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
				  "sroll_horizontal", 2,
				  GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
                                  GTK_TYPE_FLOAT, 1.0);

    gtk_binding_entry_add_signal (binding_set, GDK_KP_Divide, 0,
				  "undo_selection", 0);
    gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0,
				  "abort_column_resize", 0);
    gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
				  "toggle_focus_row", 0);
    gtk_binding_entry_add_signal (binding_set, GDK_KP_Multiply, 0,
				  "toggle_add_mode", 0);
    gtk_binding_entry_add_signal (binding_set, GDK_KP_Add, 0,
				  "select_all", 0);
    gtk_binding_entry_add_signal (binding_set, GDK_KP_Subtract, 0,
				  "unselect_all", 0);
    gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
				  "end_selection", 0);
  }
  */
763 764 765 766 767 768 769 770
}

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

  GTK_WIDGET_UNSET_FLAGS (clist, GTK_NO_WINDOW);
771
  GTK_CLIST_SET_FLAG (clist, CLIST_FROZEN);
772

Tim Janik's avatar
Tim Janik committed
773 774 775
  clist->row_mem_chunk = NULL;
  clist->cell_mem_chunk = NULL;

776 777 778 779 780 781 782 783
  clist->rows = 0;
  clist->row_center_offset = 0;
  clist->row_height = 0;
  clist->row_list = NULL;
  clist->row_list_end = NULL;

  clist->columns = 0;

784
  clist->title_window = NULL;
785 786
  clist->column_title_area.x = 0;
  clist->column_title_area.y = 0;
Owen Taylor's avatar
Owen Taylor committed
787 788
  clist->column_title_area.width = 1;
  clist->column_title_area.height = 1;
789 790

  clist->clist_window = NULL;
Owen Taylor's avatar
Owen Taylor committed
791 792
  clist->clist_window_width = 1;
  clist->clist_window_height = 1;
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807

  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;
808
  clist->selection = NULL;
809 810 811 812 813 814 815 816 817 818 819 820 821 822
  clist->selection_end = NULL;
  clist->undo_selection = NULL;
  clist->undo_unselection = NULL;

  GTK_WIDGET_SET_FLAGS (clist, GTK_CAN_FOCUS);
  GTK_CLIST_SET_FLAG (clist, CLIST_CHILD_HAS_FOCUS);
  clist->focus_row = -1;
  clist->undo_anchor = -1;

  clist->anchor = -1;
  clist->anchor_state = GTK_STATE_SELECTED;
  clist->drag_pos = -1;
  clist->htimer = 0;
  clist->vtimer = 0;
Stefan Jeske's avatar
Stefan Jeske committed
823 824 825 826

  clist->compare = default_compare;
  clist->sort_type = GTK_SORT_ASCENDING;
  clist->sort_column = 0;
827 828
}

829 830 831 832 833 834 835 836
/* Constructors */
void
gtk_clist_construct (GtkCList * clist,
		     gint columns,
		     gchar *titles[])
{
  int i;

Tim Janik's avatar
Tim Janik committed
837 838
  g_return_if_fail (clist != NULL);
  g_return_if_fail (GTK_IS_CLIST (clist));
839
  g_return_if_fail (GTK_CLIST_CONSTRUCTED (clist) == FALSE);
Tim Janik's avatar
Tim Janik committed
840

841
  GTK_CLIST_SET_FLAG (clist, CLIST_CONSTRUCTED);
842

843 844 845 846 847 848 849 850 851 852 853 854 855 856
  /* initalize memory chunks, if this has not been done by any
   * possibly derived widget
   */
  if (!clist->row_mem_chunk)
    clist->row_mem_chunk = g_mem_chunk_new ("clist row mem chunk",
					    sizeof (GtkCListRow),
					    sizeof (GtkCListRow) * CLIST_OPTIMUM_SIZE, 
					    G_ALLOC_AND_FREE);

  if (!clist->cell_mem_chunk)
    clist->cell_mem_chunk = g_mem_chunk_new ("clist cell mem chunk",
					     sizeof (GtkCell) * columns,
					     sizeof (GtkCell) * columns * CLIST_OPTIMUM_SIZE, 
					     G_ALLOC_AND_FREE);
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871

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

  /* 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);

  /* create scrollbars */
  create_scrollbars (clist);

  if (titles)
    {
872
      GTK_CLIST_SET_FLAG (clist, CLIST_SHOW_TITLES);
873 874 875 876 877
      for (i = 0; i < columns; i++)
	gtk_clist_set_column_title (clist, i, titles[i]);
    }
  else
    {
878
      GTK_CLIST_UNSET_FLAG (clist, CLIST_SHOW_TITLES);
879 880 881
    }
}

882 883 884 885 886
/*
 * GTKCLIST PUBLIC INTERFACE
 *   gtk_clist_new_with_titles
 *   gtk_clist_new
 */
887
GtkWidget *
888
gtk_clist_new_with_titles (gint columns,
889
			   gchar * titles[])
890
{
891
  GtkWidget *widget;
892

893 894
  g_return_val_if_fail (titles != NULL, NULL);
  
895
  widget = gtk_type_new (GTK_TYPE_CLIST);
896 897
  
  gtk_clist_construct (GTK_CLIST (widget), columns, titles);
898 899 900 901 902

  return widget;
}

GtkWidget *
903
gtk_clist_new (gint columns)
904
{
905 906
  GtkCList *clist;

907
  if (columns < 1)
908 909
    return NULL;

910
  clist = gtk_type_new (GTK_TYPE_CLIST);
911
  gtk_clist_construct (clist, columns, NULL);
912 913 914 915 916 917 918 919
  return GTK_WIDGET (clist);
}

void
gtk_clist_set_border (GtkCList * clist,
		      GtkShadowType border)
{
  g_return_if_fail (clist != NULL);
920
  g_return_if_fail (GTK_IS_CLIST (clist));
921 922 923 924 925 926 927 928 929 930 931 932

  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);
933 934 935 936
  g_return_if_fail (GTK_IS_CLIST (clist));

  if (mode == clist->selection_mode)
    return;
937 938

  clist->selection_mode = mode;
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
  clist->anchor = -1;
  clist->anchor_state = GTK_STATE_SELECTED;
  clist->drag_pos = -1;
  clist->undo_anchor = clist->focus_row;

  g_list_free (clist->undo_selection);
  g_list_free (clist->undo_unselection);
  clist->undo_selection = NULL;
  clist->undo_unselection = NULL;

  switch (mode)
    {
    case GTK_SELECTION_MULTIPLE:
    case GTK_SELECTION_EXTENDED:
      return;
    case GTK_SELECTION_BROWSE:
    case GTK_SELECTION_SINGLE:
      gtk_clist_unselect_all (clist);
      break;
    }
959 960 961 962 963 964
}

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

967
  GTK_CLIST_SET_FLAG (clist, CLIST_FROZEN);
968 969 970 971 972 973
}

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

976
  GTK_CLIST_UNSET_FLAG (clist, CLIST_FROZEN);
977

Jay Painter's avatar
Jay Painter committed
978
  adjust_scrollbars (clist);
979
  draw_rows (clist, NULL);
980 981
}

982 983 984 985
void
gtk_clist_column_titles_show (GtkCList * clist)
{
  g_return_if_fail (clist != NULL);
986
  g_return_if_fail (GTK_IS_CLIST (clist));
987 988 989

  if (!GTK_CLIST_SHOW_TITLES (clist))
    {
990
      GTK_CLIST_SET_FLAG (clist, CLIST_SHOW_TITLES);
991 992
      if (clist->title_window)
	      gdk_window_show (clist->title_window);
993 994 995 996 997 998 999
      gtk_widget_queue_resize (GTK_WIDGET (clist));
    }
}

void 
gtk_clist_column_titles_hide (GtkCList * clist)
{
Jay Painter's avatar
Jay Painter committed
1000
  g_return_if_fail (clist != NULL);
1001
  g_return_if_fail (GTK_IS_CLIST (clist));
Jay Painter's avatar
Jay Painter committed
1002

1003 1004
  if (GTK_CLIST_SHOW_TITLES (clist))
    {
1005
      GTK_CLIST_UNSET_FLAG (clist, CLIST_SHOW_TITLES);
1006 1007
      if (clist->title_window)
	      gdk_window_hide (clist->title_window);
1008 1009 1010
      gtk_widget_queue_resize (GTK_WIDGET (clist));
    }
}
1011

Martin Baulig's avatar
Martin Baulig committed
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
void
gtk_clist_set_column_visibility (GtkCList * clist, gint column, gint visible)
{
  g_return_if_fail (clist != NULL);
  g_return_if_fail (GTK_IS_CLIST (clist));

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

  if (clist->column[column].visible && !visible)
    gtk_widget_hide (clist->column[column].button);
  else if (!clist->column[column].visible && visible)
    gtk_widget_show (clist->column[column].button);

  clist->column[column].visible = visible ? TRUE : FALSE;
}

Jay Painter's avatar
Jay Painter committed
1029 1030 1031 1032 1033
void
gtk_clist_column_title_active (GtkCList * clist,
			       gint column)
{
  g_return_if_fail (clist != NULL);
1034
  g_return_if_fail (GTK_IS_CLIST (clist));
Jay Painter's avatar
Jay Painter committed
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052

  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);
1053
  g_return_if_fail (GTK_IS_CLIST (clist));
Jay Painter's avatar
Jay Painter committed
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072

  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);
1073
  g_return_if_fail (GTK_IS_CLIST (clist));
Jay Painter's avatar
Jay Painter committed
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085

  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);
1086
  g_return_if_fail (GTK_IS_CLIST (clist));
Jay Painter's avatar
Jay Painter committed
1087 1088 1089 1090 1091 1092

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

1093
void
Tim Janik's avatar
Tim Janik committed
1094 1095 1096
gtk_clist_set_column_title (GtkCList    *clist,
			    gint         column,
			    const gchar *title)
1097
{
1098
  gint new_button = 0;
1099
  GtkWidget *old_widget;
1100
  GtkWidget *alignment = NULL;
1101 1102 1103
  GtkWidget *label;

  g_return_if_fail (clist != NULL);
1104
  g_return_if_fail (GTK_IS_CLIST (clist));
1105 1106 1107 1108

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

1109
  /* if the column button doesn't currently exist,
1110 1111 1112 1113 1114 1115 1116
   * it has to be created first */
  if (!clist->column[column].button)
    {
      column_button_create (clist, column);
      new_button = 1;
    }

1117
  column_title_new (clist, column, title);
1118 1119

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

1124
  /* create new alignment based no column justification */
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
  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;
    }

1144 1145 1146 1147 1148 1149
  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);

1150
  /* if this button didn't previously exist, then the
1151 1152
   * column button positions have to be re-computed */
  if (GTK_WIDGET_VISIBLE (clist) && new_button)
Jay Painter's avatar
Jay Painter committed
1153
    size_allocate_title_buttons (clist);
1154 1155 1156 1157 1158 1159 1160
}

void
gtk_clist_set_column_widget (GtkCList * clist,
			     gint column,
			     GtkWidget * widget)
{
1161
  gint new_button = 0;
1162 1163 1164
  GtkWidget *old_widget;

  g_return_if_fail (clist != NULL);
1165
  g_return_if_fail (GTK_IS_CLIST (clist));
1166 1167 1168 1169

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

1170
  /* if the column button doesn't currently exist,
1171 1172 1173 1174 1175 1176 1177
   * it has to be created first */
  if (!clist->column[column].button)
    {
      column_button_create (clist, column);
      new_button = 1;
    }

1178
  column_title_new (clist, column, NULL);
1179 1180

  /* remove and destroy the old widget */
1181
  old_widget = GTK_BIN (clist->column[column].button)->child;
1182
  if (old_widget)
1183
    gtk_container_remove (GTK_CONTAINER (clist->column[column].button), old_widget);
1184 1185 1186 1187 1188 1189 1190

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

1192
  /* if this button didn't previously exist, then the
1193 1194
   * column button positions have to be re-computed */
  if (GTK_WIDGET_VISIBLE (clist) && new_button)
Jay Painter's avatar
Jay Painter committed
1195
    size_allocate_title_buttons (clist);
1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
}

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

  g_return_if_fail (clist != NULL);
1206
  g_return_if_fail (GTK_IS_CLIST (clist));
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216

  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)
    {
1217
      alignment = GTK_BIN (clist->column[column].button)->child;
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

      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))
1243
    draw_rows (clist, NULL);
1244 1245 1246 1247 1248 1249 1250 1251
}

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