gtkctree.c 160 KB
Newer Older
Tim Janik's avatar
Tim Janik committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/* GTK - The GIMP Toolkit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball, Josh MacDonald, 
 * Copyright (C) 1997-1998 Jay Painter <jpaint@serv.net><jpaint@gimp.org>  
 *
 * GtkCTree widget for GTK+
 * Copyright (C) 1998 Lars Hamann and Stefan Jeske
 *
 * 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 <stdlib.h>
#include "gtkctree.h"
26
#include "gtkbindings.h"
27
#include "gtkmain.h"
Tim Janik's avatar
Tim Janik committed
28
#include <gdk/gdkx.h>
29
#include <gdk/gdkkeysyms.h>
Tim Janik's avatar
Tim Janik committed
30 31

#define PM_SIZE                    8
32
#define TAB_SIZE                   (PM_SIZE + 6)
Tim Janik's avatar
Tim Janik committed
33 34
#define CELL_SPACING               1
#define CLIST_OPTIMUM_SIZE         512
35 36
#define COLUMN_INSET               3
#define DRAG_WIDTH                 6
Tim Janik's avatar
Tim Janik committed
37 38 39 40 41 42 43 44

#define ROW_TOP_YPIXEL(clist, row) (((clist)->row_height * (row)) + \
				    (((row) + 1) * CELL_SPACING) + \
				    (clist)->voffset)
#define ROW_FROM_YPIXEL(clist, y)  (((y) - (clist)->voffset) / \
                                    ((clist)->row_height + CELL_SPACING))
#define COLUMN_LEFT_XPIXEL(clist, col)  ((clist)->column[(col)].area.x \
                                    + (clist)->hoffset)
45
#define COLUMN_LEFT(clist, column) ((clist)->column[(column)].area.x)
Tim Janik's avatar
Tim Janik committed
46

47 48 49
#define GTK_CLIST_CLASS_FW(_widget_) GTK_CLIST_CLASS (GTK_OBJECT (_widget_)->klass)


Tim Janik's avatar
Tim Janik committed
50 51
static void gtk_ctree_class_init        (GtkCTreeClass  *klass);
static void gtk_ctree_init              (GtkCTree       *ctree);
52 53
static void gtk_ctree_realize           (GtkWidget      *widget);
static void gtk_ctree_unrealize         (GtkWidget      *widget);
Tim Janik's avatar
Tim Janik committed
54 55 56 57 58 59
static gint gtk_ctree_button_press      (GtkWidget      *widget,
					 GdkEventButton *event);
static gint gtk_ctree_button_release    (GtkWidget      *widget,
					 GdkEventButton *event);
static gint gtk_ctree_button_motion     (GtkWidget      *widget, 
					 GdkEventMotion *event);
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
static void ctree_attach_styles         (GtkCTree       *ctree,
					 GtkCTreeNode   *node,
					 gpointer        data);
static void ctree_detach_styles         (GtkCTree       *ctree,
					 GtkCTreeNode   *node, 
					 gpointer        data);
static gint draw_cell_pixmap            (GdkWindow      *window,
					 GdkRectangle   *clip_rectangle,
					 GdkGC          *fg_gc,
					 GdkPixmap      *pixmap,
					 GdkBitmap      *mask,
					 gint            x,
					 gint            y,
					 gint            width,
					 gint            height);
static void get_cell_style              (GtkCList       *clist,
					 GtkCListRow    *clist_row,
					 gint            state,
					 gint            column,
					 GtkStyle      **style,
					 GdkGC         **fg_gc,
					 GdkGC         **bg_gc);
static gint gtk_ctree_draw_expander     (GtkCTree       *ctree,
					 GtkCTreeRow    *ctree_row,
					 GtkStyle       *style,
					 GdkRectangle   *clip_rectangle,
					 gint            x);
static gint gtk_ctree_draw_lines        (GtkCTree       *ctree,
					 GtkCTreeRow    *ctree_row,
					 gint            row,
					 gint            column,
					 gint            state,
					 GdkRectangle   *clip_rectangle,
					 GdkRectangle   *cell_rectangle,
					 GdkRectangle   *crect,
					 GdkRectangle   *area,
					 GtkStyle       *style);
97 98 99 100
static void draw_row                    (GtkCList       *clist,
					 GdkRectangle   *area,
					 gint            row,
					 GtkCListRow   *clist_row);
Tim Janik's avatar
Tim Janik committed
101 102 103 104
static void draw_xor_line               (GtkCTree       *ctree);
static void draw_xor_rect               (GtkCTree       *ctree);
static void create_drag_icon            (GtkCTree       *ctree,
					 GtkCTreeRow    *row);
105 106
static void tree_draw_node              (GtkCTree      *ctree,
					 GtkCTreeNode  *node);
107
static void set_cell_contents           (GtkCList      *clist,
Tim Janik's avatar
Tim Janik committed
108 109
					 GtkCListRow   *clist_row,
					 gint           column,
110
					 GtkCellType    type,
Tim Janik's avatar
Tim Janik committed
111
					 const gchar   *text,
Tim Janik's avatar
Tim Janik committed
112 113 114
					 guint8         spacing,
					 GdkPixmap     *pixmap,
					 GdkBitmap     *mask);
115
static void set_node_info               (GtkCTree      *ctree,
116
					 GtkCTreeNode  *node,
Tim Janik's avatar
Tim Janik committed
117
					 const gchar   *text,
118 119 120 121 122 123 124
					 guint8         spacing,
					 GdkPixmap     *pixmap_closed,
					 GdkBitmap     *mask_closed,
					 GdkPixmap     *pixmap_opened,
					 GdkBitmap     *mask_opened,
					 gboolean       is_leaf,
					 gboolean       expanded);
125 126 127 128
static GtkCTreeRow *row_new             (GtkCTree      *ctree);
static void row_delete                  (GtkCTree      *ctree,
				 	 GtkCTreeRow   *ctree_row);
static void tree_delete                 (GtkCTree      *ctree, 
129
					 GtkCTreeNode  *node, 
130 131
					 gpointer       data);
static void tree_delete_row             (GtkCTree      *ctree, 
132
					 GtkCTreeNode  *node, 
133
					 gpointer       data);
134
static void real_clear                  (GtkCList      *clist);
135
static void tree_update_level           (GtkCTree      *ctree, 
136
					 GtkCTreeNode  *node, 
137 138
					 gpointer       data);
static void tree_select                 (GtkCTree      *ctree, 
139
					 GtkCTreeNode  *node, 
140 141
					 gpointer       data);
static void tree_unselect               (GtkCTree      *ctree, 
142
					 GtkCTreeNode  *node, 
143
				         gpointer       data);
144 145
static void real_select_all             (GtkCList      *clist);
static void real_unselect_all           (GtkCList      *clist);
146
static void tree_expand                 (GtkCTree      *ctree, 
147
					 GtkCTreeNode  *node,
148 149
					 gpointer       data);
static void tree_collapse               (GtkCTree      *ctree, 
150
					 GtkCTreeNode  *node,
151
					 gpointer       data);
152
static void tree_collapse_to_depth      (GtkCTree      *ctree, 
153
					 GtkCTreeNode  *node, 
154
					 gint           depth);
155
static void tree_toggle_expansion       (GtkCTree      *ctree,
156
					 GtkCTreeNode  *node,
157 158
					 gpointer       data);
static void change_focus_row_expansion  (GtkCTree      *ctree,
159
				         GtkCTreeExpansionType expansion);
160 161 162 163 164 165 166 167
static void real_select_row             (GtkCList      *clist,
					 gint           row,
					 gint           column,
					 GdkEvent      *event);
static void real_unselect_row           (GtkCList      *clist,
					 gint           row,
					 gint           column,
					 GdkEvent      *event);
168
static void real_tree_select            (GtkCTree      *ctree,
169
					 GtkCTreeNode  *node,
170 171
					 gint           column);
static void real_tree_unselect          (GtkCTree      *ctree,
172
					 GtkCTreeNode  *node,
173 174
					 gint           column);
static void tree_toggle_selection       (GtkCTree      *ctree, 
175
					 GtkCTreeNode  *node, 
176 177
				         gint           column);
static void real_tree_expand            (GtkCTree      *ctree,
178
					 GtkCTreeNode  *node);
179
static void real_tree_collapse          (GtkCTree      *ctree,
180
					 GtkCTreeNode  *node);
181
static void real_tree_move              (GtkCTree      *ctree,
182 183 184
					 GtkCTreeNode  *node,
					 GtkCTreeNode  *new_parent, 
					 GtkCTreeNode  *new_sibling);
185
static void gtk_ctree_link              (GtkCTree      *ctree,
186 187 188
					 GtkCTreeNode  *node,
					 GtkCTreeNode  *parent,
					 GtkCTreeNode  *sibling,
189
					 gboolean       update_focus_row);
190
static void gtk_ctree_unlink            (GtkCTree      *ctree, 
191
					 GtkCTreeNode  *node,
192
					 gboolean       update_focus_row);
193 194
static GtkCTreeNode * gtk_ctree_last_visible (GtkCTree     *ctree,
					      GtkCTreeNode *node);
195
static gboolean ctree_is_hot_spot       (GtkCTree      *ctree, 
196
					 GtkCTreeNode  *node,
197 198 199 200
					 gint           row, 
					 gint           x, 
					 gint           y);
static void tree_sort                   (GtkCTree      *ctree,
201
					 GtkCTreeNode  *node,
202
					 gpointer       data);
203 204
static void fake_unselect_all           (GtkCList      *clist,
					 gint           row);
205
static GList * selection_find           (GtkCList      *clist,
206 207 208 209 210 211
					 gint           row_number,
					 GList         *row_list_element);
static void resync_selection            (GtkCList      *clist,
					 GdkEvent      *event);
static void real_undo_selection         (GtkCList      *clist);
static void select_row_recursive        (GtkCTree      *ctree, 
212
					 GtkCTreeNode  *node, 
213
					 gpointer       data);
214 215 216 217 218 219
static gint real_insert_row             (GtkCList      *clist,
					 gint           row,
					 gchar         *text[]);
static void real_remove_row             (GtkCList      *clist,
					 gint           row);
static void real_sort_list              (GtkCList      *clist);
220 221 222
static void set_mouse_cursor		(GtkCTree	*ctree,
					 gboolean	enable);
static void check_cursor		(GtkCTree	*ctree);
223 224 225 226 227 228 229 230
static void cell_size_request           (GtkCList       *clist,
					 GtkCListRow    *clist_row,
					 gint            column,
					 GtkRequisition *requisition);
static void column_auto_resize          (GtkCList       *clist,
					 GtkCListRow    *clist_row,
					 gint            column,
					 gint            old_width);
Lars Hamann's avatar
Lars Hamann committed
231
static void auto_resize_columns         (GtkCList       *clist);
232

Tim Janik's avatar
Tim Janik committed
233 234 235 236 237 238 239
enum
{
  TREE_SELECT_ROW,
  TREE_UNSELECT_ROW,
  TREE_EXPAND,
  TREE_COLLAPSE,
  TREE_MOVE,
240
  CHANGE_FOCUS_ROW_EXPANSION,
Tim Janik's avatar
Tim Janik committed
241 242 243
  LAST_SIGNAL
};

244 245 246 247
typedef void (*GtkCTreeSignal1) (GtkObject    *object,
				 GtkCTreeNode *arg1,
				 gint          arg2,
				 gpointer      data);
248

249 250 251 252 253
typedef void (*GtkCTreeSignal2) (GtkObject    *object,
				 GtkCTreeNode *arg1,
				 GtkCTreeNode *arg2,
				 GtkCTreeNode *arg3,
				 gpointer      data);
254

255 256 257
typedef void (*GtkCTreeSignal3) (GtkObject    *object,
				 GtkCTreeNode *arg1,
				 gpointer      data);
Tim Janik's avatar
Tim Janik committed
258

259
typedef void (*GtkCTreeSignal4) (GtkObject         *object,
260
				 GtkCTreeExpansionType arg1,
261 262
				 gpointer           data);

Tim Janik's avatar
Tim Janik committed
263 264 265 266 267 268 269

static GtkCListClass *parent_class = NULL;
static GtkContainerClass *container_class = NULL;
static guint ctree_signals[LAST_SIGNAL] = {0};


GtkType
270
gtk_ctree_get_type (void)
Tim Janik's avatar
Tim Janik committed
271 272 273 274 275 276 277 278 279 280 281 282
{
  static GtkType ctree_type = 0;

  if (!ctree_type)
    {
      GtkTypeInfo ctree_info =
      {
	"GtkCTree",
	sizeof (GtkCTree),
	sizeof (GtkCTreeClass),
	(GtkClassInitFunc) gtk_ctree_class_init,
	(GtkObjectInitFunc) gtk_ctree_init,
283 284
	/* reserved_1 */ NULL,
        /* reserved_2 */ NULL,
285
        (GtkClassInitFunc) NULL,
Tim Janik's avatar
Tim Janik committed
286 287
      };

288
      ctree_type = gtk_type_unique (GTK_TYPE_CLIST, &ctree_info);
Tim Janik's avatar
Tim Janik committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
    }

  return ctree_type;
}

static void
gtk_ctree_class_init (GtkCTreeClass *klass)
{
  GtkObjectClass *object_class;
  GtkWidgetClass *widget_class;
  GtkCListClass *clist_class;

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

306 307
  parent_class = gtk_type_class (GTK_TYPE_CLIST);
  container_class = gtk_type_class (GTK_TYPE_CONTAINER);
Tim Janik's avatar
Tim Janik committed
308 309 310 311 312 313

  ctree_signals[TREE_SELECT_ROW] =
    gtk_signal_new ("tree_select_row",
		    GTK_RUN_FIRST,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCTreeClass, tree_select_row),
314
		    gtk_marshal_NONE__POINTER_INT,
Tim Janik's avatar
Tim Janik committed
315 316 317 318 319 320
		    GTK_TYPE_NONE, 2, GTK_TYPE_POINTER, GTK_TYPE_INT);
  ctree_signals[TREE_UNSELECT_ROW] =
    gtk_signal_new ("tree_unselect_row",
		    GTK_RUN_FIRST,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCTreeClass, tree_unselect_row),
321
		    gtk_marshal_NONE__POINTER_INT,
Tim Janik's avatar
Tim Janik committed
322 323 324 325 326 327
		    GTK_TYPE_NONE, 2, GTK_TYPE_POINTER, GTK_TYPE_INT);
  ctree_signals[TREE_EXPAND] =
    gtk_signal_new ("tree_expand",
		    GTK_RUN_LAST,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCTreeClass, tree_expand),
328
		    gtk_marshal_NONE__POINTER,
Tim Janik's avatar
Tim Janik committed
329 330 331 332 333 334
		    GTK_TYPE_NONE, 1, GTK_TYPE_POINTER);
  ctree_signals[TREE_COLLAPSE] =
    gtk_signal_new ("tree_collapse",
		    GTK_RUN_LAST,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCTreeClass, tree_collapse),
335
		    gtk_marshal_NONE__POINTER,
Tim Janik's avatar
Tim Janik committed
336 337 338 339 340 341
		    GTK_TYPE_NONE, 1, GTK_TYPE_POINTER);
  ctree_signals[TREE_MOVE] =
    gtk_signal_new ("tree_move",
		    GTK_RUN_LAST,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCTreeClass, tree_move),
342
		    gtk_marshal_NONE__POINTER_POINTER_POINTER,
Tim Janik's avatar
Tim Janik committed
343 344
		    GTK_TYPE_NONE, 3, GTK_TYPE_POINTER, GTK_TYPE_POINTER, 
		    GTK_TYPE_POINTER);
345 346 347 348 349 350
  ctree_signals[CHANGE_FOCUS_ROW_EXPANSION] =
    gtk_signal_new ("change_focus_row_expansion",
		    GTK_RUN_LAST | GTK_RUN_ACTION,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCTreeClass,
				       change_focus_row_expansion),
351
		    gtk_marshal_NONE__ENUM,
352
		    GTK_TYPE_NONE, 1, GTK_TYPE_C_TREE_EXPANSION_TYPE);
Tim Janik's avatar
Tim Janik committed
353 354 355 356 357 358 359 360 361

  gtk_object_class_add_signals (object_class, ctree_signals, LAST_SIGNAL);

  widget_class->realize = gtk_ctree_realize;
  widget_class->unrealize = gtk_ctree_unrealize;
  widget_class->button_press_event = gtk_ctree_button_press;
  widget_class->button_release_event = gtk_ctree_button_release;
  widget_class->motion_notify_event = gtk_ctree_button_motion;

362 363 364 365 366
  clist_class->select_row = real_select_row;
  clist_class->unselect_row = real_unselect_row;
  clist_class->undo_selection = real_undo_selection;
  clist_class->resync_selection = resync_selection;
  clist_class->selection_find = selection_find;
Tim Janik's avatar
Tim Janik committed
367 368
  clist_class->click_column = NULL;
  clist_class->draw_row = draw_row;
369 370 371 372
  clist_class->clear = real_clear;
  clist_class->select_all = real_select_all;
  clist_class->unselect_all = real_unselect_all;
  clist_class->fake_unselect_all = fake_unselect_all;
373 374 375 376
  clist_class->insert_row = real_insert_row;
  clist_class->remove_row = real_remove_row;
  clist_class->sort_list = real_sort_list;
  clist_class->set_cell_contents = set_cell_contents;
377
  clist_class->cell_size_request = cell_size_request;
Tim Janik's avatar
Tim Janik committed
378

379 380
  klass->tree_select_row = real_tree_select;
  klass->tree_unselect_row = real_tree_unselect;
Tim Janik's avatar
Tim Janik committed
381 382 383
  klass->tree_expand = real_tree_expand;
  klass->tree_collapse = real_tree_collapse;
  klass->tree_move = real_tree_move;
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
  klass->change_focus_row_expansion = change_focus_row_expansion;

  {
    GtkBindingSet *binding_set;

    binding_set = gtk_binding_set_by_class (klass);
    gtk_binding_entry_add_signal (binding_set,
				  '+', GDK_SHIFT_MASK,
				  "change_focus_row_expansion", 1,
				  GTK_TYPE_ENUM, GTK_CTREE_EXPANSION_EXPAND);
    gtk_binding_entry_add_signal (binding_set,
				  GDK_KP_Add, 0,
				  "change_focus_row_expansion", 1,
				  GTK_TYPE_ENUM, GTK_CTREE_EXPANSION_EXPAND);
    gtk_binding_entry_add_signal (binding_set,
				  GDK_KP_Add, GDK_CONTROL_MASK,
				  "change_focus_row_expansion", 1,
				  GTK_TYPE_ENUM,
				  GTK_CTREE_EXPANSION_EXPAND_RECURSIVE);
    gtk_binding_entry_add_signal (binding_set,
				  '-', 0,
				  "change_focus_row_expansion", 1,
				  GTK_TYPE_ENUM, GTK_CTREE_EXPANSION_COLLAPSE);
    gtk_binding_entry_add_signal (binding_set,
				  GDK_KP_Subtract, 0,
				  "change_focus_row_expansion", 1,
				  GTK_TYPE_ENUM, GTK_CTREE_EXPANSION_COLLAPSE);
    gtk_binding_entry_add_signal (binding_set,
				  GDK_KP_Subtract, GDK_CONTROL_MASK,
				  "change_focus_row_expansion", 1,
				  GTK_TYPE_ENUM,
				  GTK_CTREE_EXPANSION_COLLAPSE_RECURSIVE);
    gtk_binding_entry_add_signal (binding_set,
				  '=', 0,
				  "change_focus_row_expansion", 1,
				  GTK_TYPE_ENUM, GTK_CTREE_EXPANSION_TOGGLE);
    gtk_binding_entry_add_signal (binding_set,
				  GDK_KP_Multiply, 0,
				  "change_focus_row_expansion", 1,
				  GTK_TYPE_ENUM, GTK_CTREE_EXPANSION_TOGGLE);
    gtk_binding_entry_add_signal (binding_set,
				  GDK_KP_Multiply, GDK_CONTROL_MASK,
				  "change_focus_row_expansion", 1,
				  GTK_TYPE_ENUM,
				  GTK_CTREE_EXPANSION_TOGGLE_RECURSIVE);
  }

Tim Janik's avatar
Tim Janik committed
431 432 433 434 435
}

static void
gtk_ctree_init (GtkCTree *ctree)
{
436
  ctree->drag_icon      = NULL;
Tim Janik's avatar
Tim Janik committed
437
  ctree->tree_indent    = 20;
438
  ctree->tree_spacing   = 5;
Tim Janik's avatar
Tim Janik committed
439 440 441 442 443
  ctree->tree_column    = 0;
  ctree->drag_row       = -1;
  ctree->drag_source    = NULL;
  ctree->drag_target    = NULL;
  ctree->insert_pos     = GTK_CTREE_POS_AS_CHILD;
444 445 446 447 448
  ctree->reorderable    = FALSE;
  ctree->use_icons      = TRUE;
  ctree->in_drag        = FALSE;
  ctree->drag_rect      = FALSE;
  ctree->line_style     = GTK_CTREE_LINES_SOLID;
449
  ctree->expander_style = GTK_CTREE_EXPANDER_SQUARE;
450
  ctree->drag_compare   = NULL;
451
  ctree->show_stub      = TRUE;
Tim Janik's avatar
Tim Janik committed
452 453
}

454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 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
static void
ctree_attach_styles (GtkCTree     *ctree,
		     GtkCTreeNode *node,
		     gpointer      data)
{
  GtkCList *clist;
  gint i;

  clist = GTK_CLIST (ctree);

  if (GTK_CTREE_ROW (node)->row.style)
    GTK_CTREE_ROW (node)->row.style =
      gtk_style_attach (GTK_CTREE_ROW (node)->row.style, clist->clist_window);

  if (GTK_CTREE_ROW (node)->row.fg_set || GTK_CTREE_ROW (node)->row.bg_set)
    {
      GdkColormap *colormap;

      colormap = gtk_widget_get_colormap (GTK_WIDGET (ctree));
      if (GTK_CTREE_ROW (node)->row.fg_set)
	gdk_color_alloc (colormap, &(GTK_CTREE_ROW (node)->row.foreground));
      if (GTK_CTREE_ROW (node)->row.bg_set)
	gdk_color_alloc (colormap, &(GTK_CTREE_ROW (node)->row.background));
    }

  for (i = 0; i < clist->columns; i++)
    if  (GTK_CTREE_ROW (node)->row.cell[i].style)
      GTK_CTREE_ROW (node)->row.cell[i].style =
	gtk_style_attach (GTK_CTREE_ROW (node)->row.cell[i].style,
			  clist->clist_window);
}

static void
ctree_detach_styles (GtkCTree     *ctree,
		     GtkCTreeNode *node,
		     gpointer      data)
{
  GtkCList *clist;
  gint i;

  clist = GTK_CLIST (ctree);

  if (GTK_CTREE_ROW (node)->row.style)
    gtk_style_detach (GTK_CTREE_ROW (node)->row.style);
  for (i = 0; i < clist->columns; i++)
    if  (GTK_CTREE_ROW (node)->row.cell[i].style)
      gtk_style_detach (GTK_CTREE_ROW (node)->row.cell[i].style);
}

Tim Janik's avatar
Tim Janik committed
503 504 505 506
static void
gtk_ctree_realize (GtkWidget *widget)
{
  GtkCTree *ctree;
507
  GtkCList *clist;
Tim Janik's avatar
Tim Janik committed
508
  GdkGCValues values;
509 510 511
  GtkCTreeNode *node;
  GtkCTreeNode *child;
  gint i;
Tim Janik's avatar
Tim Janik committed
512

513 514
  g_return_if_fail (widget != NULL);
  g_return_if_fail (GTK_IS_CTREE (widget));
Tim Janik's avatar
Tim Janik committed
515 516 517

  (* GTK_WIDGET_CLASS (parent_class)->realize) (widget);

518
  ctree = GTK_CTREE (widget);
519 520 521 522 523 524 525 526 527 528 529
  clist = GTK_CLIST (widget);

  node = GTK_CTREE_NODE (clist->row_list);
  for (i = 0; i < clist->rows; i++)
    {
      if (GTK_CTREE_ROW (node)->children && !GTK_CTREE_ROW (node)->expanded)
	for (child = GTK_CTREE_ROW (node)->children; child;
	     child = GTK_CTREE_ROW (child)->sibling)
	  gtk_ctree_pre_recursive (ctree, child, ctree_attach_styles, NULL);
      node = GTK_CTREE_NODE_NEXT (node);
    }
530

Tim Janik's avatar
Tim Janik committed
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
  values.foreground = widget->style->fg[GTK_STATE_NORMAL];
  values.background = widget->style->bg[GTK_STATE_NORMAL];
  values.subwindow_mode = GDK_INCLUDE_INFERIORS;
  values.line_style = GDK_LINE_SOLID;
  ctree->lines_gc = gdk_gc_new_with_values (GTK_CLIST(widget)->clist_window, 
					    &values,
					    GDK_GC_FOREGROUND |
					    GDK_GC_BACKGROUND |
					    GDK_GC_SUBWINDOW |
					    GDK_GC_LINE_STYLE);

  if (ctree->line_style == GTK_CTREE_LINES_DOTTED)
    {
      gdk_gc_set_line_attributes (ctree->lines_gc, 1, 
				  GDK_LINE_ON_OFF_DASH, None, None);
546
      gdk_gc_set_dashes (ctree->lines_gc, 0, "\1\1", 2);
Tim Janik's avatar
Tim Janik committed
547 548 549 550 551 552 553
    }
}

static void
gtk_ctree_unrealize (GtkWidget *widget)
{
  GtkCTree *ctree;
554
  GtkCList *clist;
Tim Janik's avatar
Tim Janik committed
555

556 557
  g_return_if_fail (widget != NULL);
  g_return_if_fail (GTK_IS_CTREE (widget));
Tim Janik's avatar
Tim Janik committed
558 559 560

  (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);

561
  ctree = GTK_CTREE (widget);
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
  clist = GTK_CLIST (widget);

  if (GTK_WIDGET_REALIZED (widget))
    {
      GtkCTreeNode *node;
      GtkCTreeNode *child;
      gint i;

      node = GTK_CTREE_NODE (clist->row_list);
      for (i = 0; i < clist->rows; i++)
	{
	  if (GTK_CTREE_ROW (node)->children &&
	      !GTK_CTREE_ROW (node)->expanded)
	    for (child = GTK_CTREE_ROW (node)->children; child;
		 child = GTK_CTREE_ROW (child)->sibling)
	      gtk_ctree_pre_recursive(ctree, child, ctree_detach_styles, NULL);
	  node = GTK_CTREE_NODE_NEXT (node);
	}
    }
581

Tim Janik's avatar
Tim Janik committed
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
  gdk_gc_destroy (ctree->lines_gc);
}

static gint
gtk_ctree_button_press (GtkWidget      *widget,
			GdkEventButton *event)
{
  GtkCTree *ctree;
  GtkCList *clist;

  g_return_val_if_fail (widget != NULL, FALSE);
  g_return_val_if_fail (GTK_IS_CTREE (widget), FALSE);
  g_return_val_if_fail (event != NULL, FALSE);

  ctree = GTK_CTREE (widget);
  clist = GTK_CLIST (widget);

  if (event->window == clist->clist_window)
    {
601
      gboolean collapse_expand = FALSE;
602
      GtkCTreeNode *work;
Tim Janik's avatar
Tim Janik committed
603 604 605 606 607 608 609 610
      gint x;
      gint y;
      gint row;
      gint column;

      x = event->x;
      y = event->y;

611 612 613 614 615 616
      if (!gtk_clist_get_selection_info (clist, x, y, &row, &column))
	return FALSE;

      if (event->button == 2)
	ctree->drag_row = - 1 - ROW_FROM_YPIXEL (clist, y);

617
      work = GTK_CTREE_NODE (g_list_nth (clist->row_list, row));
Tim Janik's avatar
Tim Janik committed
618
	  
619 620 621 622 623 624 625
      if (ctree->reorderable && event->button == 2 && !ctree->in_drag &&
	  clist->anchor == -1)
	{
	  gdk_pointer_grab (event->window, FALSE,
			    GDK_POINTER_MOTION_HINT_MASK |
			    GDK_BUTTON2_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
			    NULL, NULL, event->time);
Lars Hamann's avatar
Lars Hamann committed
626
	  gtk_grab_add (widget);
627 628 629
	  ctree->in_drag = TRUE;
	  ctree->drag_source = work;
	  ctree->drag_target = NULL;
630 631 632
	  gdk_gc_set_line_attributes (clist->xor_gc, 1, GDK_LINE_ON_OFF_DASH, 
				      None, None);
	  gdk_gc_set_dashes (clist->xor_gc, 0, "\2\2", 2);
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
	  return FALSE;
	}
      else if (event->button == 1 &&
	       (GTK_CTREE_ROW (work)->children &&
		(event->type == GDK_2BUTTON_PRESS ||
		 ctree_is_hot_spot (ctree, work, row, x, y))))
	{
	  if (GTK_CTREE_ROW (work)->expanded)
	    gtk_ctree_collapse (ctree, work);
	  else
	    gtk_ctree_expand (ctree, work);

	  collapse_expand = TRUE;
	}
      if (event->button == 1)
	{
	  gint old_row = clist->focus_row;
	  gboolean no_focus_row = FALSE;

	  switch (clist->selection_mode)
Tim Janik's avatar
Tim Janik committed
653
	    {
654 655 656 657 658 659 660 661 662 663 664 665 666
	    case GTK_SELECTION_MULTIPLE:
	    case GTK_SELECTION_SINGLE:
	      if (!collapse_expand)
		break;

	      if (clist->focus_row == -1)
		{
		  old_row = row;
		  no_focus_row = TRUE;
		}
		  
	      GTK_CLIST_SET_FLAG (clist, CLIST_DRAG_SELECTION);
	      gdk_pointer_grab (clist->clist_window, FALSE,
Tim Janik's avatar
Tim Janik committed
667 668 669 670
				GDK_POINTER_MOTION_HINT_MASK |
				GDK_BUTTON1_MOTION_MASK |
				GDK_BUTTON_RELEASE_MASK,
				NULL, NULL, event->time);
Lars Hamann's avatar
Lars Hamann committed
671
	      gtk_grab_add (widget);
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

	      if (GTK_CLIST_ADD_MODE (clist))
		{
		  GTK_CLIST_UNSET_FLAG (clist, CLIST_ADD_MODE);
		  if (GTK_WIDGET_HAS_FOCUS (widget))
		    {
		      gtk_widget_draw_focus (widget);
		      gdk_gc_set_line_attributes (clist->xor_gc, 1,
						  GDK_LINE_SOLID, 0, 0);
		      clist->focus_row = row;
		      gtk_widget_draw_focus (widget);
		    }
		  else
		    {
		      gdk_gc_set_line_attributes (clist->xor_gc, 1,
						  GDK_LINE_SOLID, 0, 0);
		      clist->focus_row = row;
		    }
		}
	      else if (row != clist->focus_row)
		{
		  if (GTK_WIDGET_HAS_FOCUS (widget))
		    {
		      gtk_widget_draw_focus (widget);
		      clist->focus_row = row;
		      gtk_widget_draw_focus (widget);
		    }
		  else
		    clist->focus_row = row;
		}

	      if (!GTK_WIDGET_HAS_FOCUS (widget))
		gtk_widget_grab_focus (widget);

Tim Janik's avatar
Tim Janik committed
706
	      return FALSE;
707 708 709

	    default:
	      break;
Tim Janik's avatar
Tim Janik committed
710 711 712
	    }
	}
    }
713
  return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, event);
Tim Janik's avatar
Tim Janik committed
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
}

static gint
gtk_ctree_button_motion (GtkWidget      *widget, 
			 GdkEventMotion *event)
{
  GtkCTree *ctree;
  GtkCList *clist;
  gint x;
  gint y;
  gint row;
  gint insert_pos = GTK_CTREE_POS_AS_CHILD;

  g_return_val_if_fail (widget != NULL, FALSE);
  g_return_val_if_fail (GTK_IS_CTREE (widget), FALSE);
  g_return_val_if_fail (event != NULL, FALSE);

  ctree = GTK_CTREE (widget);
  clist = GTK_CLIST (widget);

734 735 736
  if (GTK_CLIST_IN_DRAG (clist))
    return  GTK_WIDGET_CLASS (parent_class)->motion_notify_event
      (widget, event);
Tim Janik's avatar
Tim Janik committed
737

738 739
  if (event->window == clist->clist_window && 
      ctree->in_drag && ctree->reorderable)
Tim Janik's avatar
Tim Janik committed
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
    {
      GdkModifierType modmask;
      gint root_x;
      gint root_y;

      x = event->x;
      y = event->y;
      if (event->is_hint)
	gdk_window_get_pointer (event->window, &x, &y, NULL);

      /* delayed drag start */
      if (!ctree->drag_target &&
	  y >= ROW_TOP_YPIXEL (clist, -ctree->drag_row-1) &&
	  y <= ROW_TOP_YPIXEL (clist, -ctree->drag_row-1) + clist->row_height)
	return 
755
	  GTK_WIDGET_CLASS (parent_class)->motion_notify_event (widget, event);
Tim Janik's avatar
Tim Janik committed
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791

      if (ctree->use_icons)
	{
	  if (!ctree->drag_icon)
	    create_drag_icon (ctree, GTK_CTREE_ROW (ctree->drag_source));
	  else
	    {
	      gdk_window_get_pointer (NULL, &root_x, &root_y, &modmask);
	      gdk_window_move (ctree->drag_icon, root_x - ctree->icon_width /2,
			       root_y - ctree->icon_height);
	    }
	}

      /* out of bounds check */
      if (x < 0 || y < -3 || x > clist->clist_window_width ||
	  y > clist->clist_window_height + 3 ||
	  y > ROW_TOP_YPIXEL (clist, clist->rows-1) + clist->row_height + 3)
	{
	  if (ctree->drag_row >= 0)
	    {
	      if (ctree->drag_rect)
		{
		  draw_xor_rect (ctree);
		  ctree->drag_rect = FALSE;
		}
	      else
		draw_xor_line (ctree);
	      ctree->drag_row = -1;
	    }
	  return 
	    (* GTK_WIDGET_CLASS (parent_class)->motion_notify_event) 
	    (widget, event);
	}

      row = ROW_FROM_YPIXEL (clist, y);

792
      /* re-calculate target (mouse left the window) */
Tim Janik's avatar
Tim Janik committed
793
      if (ctree->drag_target && ctree->drag_row == -1)
794
	ctree->drag_target = GTK_CTREE_NODE (g_list_nth (clist->row_list,row));
Tim Janik's avatar
Tim Janik committed
795 796 797 798
      
      if (y < 0 || y > clist->clist_window_height || 
	  ROW_TOP_YPIXEL (clist, row + 1) > clist->clist_window_height
	  || row >= clist->rows)
799
	return GTK_WIDGET_CLASS (parent_class)->motion_notify_event
Tim Janik's avatar
Tim Janik committed
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823
	  (widget, event);

      if (y - ROW_TOP_YPIXEL (clist, row) < clist->row_height / 4)
	insert_pos = GTK_CTREE_POS_BEFORE;
      else if (ROW_TOP_YPIXEL (clist, row) + clist->row_height - y 
	       < clist->row_height / 4)
	insert_pos = GTK_CTREE_POS_AFTER;

      if (row != ctree->drag_row || 
	  (row == ctree->drag_row && ctree->insert_pos != insert_pos))
	{
	  if (insert_pos != GTK_CTREE_POS_AS_CHILD)
	    {
	      if (ctree->drag_row >= 0)
		{
		  if (ctree->drag_rect)
		    {
		      draw_xor_rect (ctree);
		      ctree->drag_rect = FALSE;
		    }
		  else
		    draw_xor_line (ctree);
		}
	      ctree->insert_pos = insert_pos;
824 825
	      ctree->drag_target =
		GTK_CTREE_NODE (g_list_nth (clist->row_list, row));
Tim Janik's avatar
Tim Janik committed
826 827
	      ctree->drag_row = row;
	      draw_xor_line (ctree);
828
	      check_cursor(ctree);
Tim Janik's avatar
Tim Janik committed
829 830 831 832 833 834 835 836 837 838 839 840 841
	    }
	  else if (ctree->drag_target &&
		   !GTK_CTREE_ROW (ctree->drag_target)->is_leaf)
	    {
	      if (ctree->drag_row >= 0)
		{
		  if (ctree->drag_rect)
		    draw_xor_rect (ctree);
		  else
		    draw_xor_line (ctree);
		}
	      ctree->drag_rect = TRUE;
	      ctree->insert_pos = insert_pos;
842 843
	      ctree->drag_target =
		GTK_CTREE_NODE (g_list_nth (clist->row_list, row));
Tim Janik's avatar
Tim Janik committed
844 845
	      ctree->drag_row = row;
	      draw_xor_rect (ctree);
846
	      check_cursor(ctree);
Tim Janik's avatar
Tim Janik committed
847 848 849
	    }
	}
    }
850
  return GTK_WIDGET_CLASS (parent_class)->motion_notify_event (widget, event);
Tim Janik's avatar
Tim Janik committed
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
}

static gint
gtk_ctree_button_release (GtkWidget      *widget, 
			  GdkEventButton *event)
{
  GtkCTree *ctree;
  GtkCList *clist;

  g_return_val_if_fail (widget != NULL, FALSE);
  g_return_val_if_fail (GTK_IS_CTREE (widget), FALSE);
  g_return_val_if_fail (event != NULL, FALSE);

  ctree = GTK_CTREE (widget);
  clist = GTK_CLIST (widget);

867
  if (event->button == 2 && clist->anchor == -1)
Tim Janik's avatar
Tim Janik committed
868
    {
Lars Hamann's avatar
Lars Hamann committed
869
      gtk_grab_remove (widget);
Tim Janik's avatar
Tim Janik committed
870
      gdk_pointer_ungrab (event->time);
Lars Hamann's avatar
Lars Hamann committed
871

Tim Janik's avatar
Tim Janik committed
872 873
      ctree->in_drag = FALSE;

874 875
      set_mouse_cursor(ctree, TRUE);

Tim Janik's avatar
Tim Janik committed
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893
      if (ctree->use_icons && ctree->drag_icon)
	{
	  gdk_window_destroy (ctree->drag_icon);
	  ctree->drag_icon = NULL;
	}

      if (ctree->drag_row >= 0)
	{
	  if (ctree->drag_rect)
	    {
	      draw_xor_rect (ctree);
	      ctree->drag_rect = FALSE;
	    }
	  else
	    draw_xor_line (ctree);
	  ctree->drag_row = -1;
	}

894 895 896 897 898 899
      if (GTK_CLIST_ADD_MODE (clist))
	gdk_gc_set_dashes (clist->xor_gc, 0, "\4\4", 2);
      else
	gdk_gc_set_line_attributes (clist->xor_gc, 1,
				    GDK_LINE_SOLID, 0, 0);

900
      /* nop if out of bounds / source == target */
Tim Janik's avatar
Tim Janik committed
901 902 903
      if (event->x < 0 || event->y < -3 ||
	  event->x > clist->clist_window_width ||
	  event->y > clist->clist_window_height + 3 ||
904 905
	  ctree->drag_target == ctree->drag_source ||
	  !ctree->drag_target)
906
	return GTK_WIDGET_CLASS (parent_class)->button_release_event
Tim Janik's avatar
Tim Janik committed
907 908 909 910 911 912 913 914 915 916
	  (widget, event);

      if (!GTK_CTREE_ROW (ctree->drag_source)->children ||
	  !gtk_ctree_is_ancestor (ctree, ctree->drag_source,
				  ctree->drag_target))
	{
	  if (ctree->insert_pos == GTK_CTREE_POS_AFTER)
	    {
	      if (GTK_CTREE_ROW (ctree->drag_target)->sibling != 
		  ctree->drag_source)
917 918 919 920 921 922 923 924 925 926
		if (!ctree->drag_compare ||
		    ctree->drag_compare (ctree,
					 ctree->drag_source,
					 GTK_CTREE_ROW (ctree->drag_target)->parent,
					 GTK_CTREE_ROW (ctree->drag_target)->sibling))
		  gtk_signal_emit (GTK_OBJECT (ctree), 
				   ctree_signals[TREE_MOVE],
				   ctree->drag_source,
				   GTK_CTREE_ROW (ctree->drag_target)->parent,
				   GTK_CTREE_ROW (ctree->drag_target)->sibling);
Tim Janik's avatar
Tim Janik committed
927 928 929 930 931
	    }
	  else if (ctree->insert_pos == GTK_CTREE_POS_BEFORE)
	    {
	      if (GTK_CTREE_ROW (ctree->drag_source)->sibling != 
		  ctree->drag_target)
932 933 934 935 936 937 938 939 940 941
		if (!ctree->drag_compare ||
		    ctree->drag_compare (ctree,
					 ctree->drag_source,
					 GTK_CTREE_ROW (ctree->drag_target)->parent,
					 ctree->drag_target))
		  gtk_signal_emit (GTK_OBJECT (ctree), 
				   ctree_signals[TREE_MOVE],
				   ctree->drag_source,
				   GTK_CTREE_ROW (ctree->drag_target)->parent,
				   ctree->drag_target);
Tim Janik's avatar
Tim Janik committed
942 943 944 945 946
	    }
	  else if (!GTK_CTREE_ROW (ctree->drag_target)->is_leaf)
	    {
	      if (GTK_CTREE_ROW (ctree->drag_target)->children !=
		  ctree->drag_source)
947 948 949 950 951 952 953 954 955 956
		if (!ctree->drag_compare ||
		    ctree->drag_compare (ctree,
					 ctree->drag_source,
					 ctree->drag_target,
					 GTK_CTREE_ROW (ctree->drag_target)->children))
		  gtk_signal_emit (GTK_OBJECT (ctree), 
				   ctree_signals[TREE_MOVE],
				   ctree->drag_source,
				   ctree->drag_target,
				   GTK_CTREE_ROW (ctree->drag_target)->children);
Tim Janik's avatar
Tim Janik committed
957 958 959 960 961
	    }
	}
      ctree->drag_source = NULL;
      ctree->drag_target = NULL;
    }
962 963 964 965 966 967
  else if (event->button == 1 && GTK_CLIST_DRAG_SELECTION (clist) &&
	   (clist->selection_mode == GTK_SELECTION_SINGLE ||
	    clist->selection_mode == GTK_SELECTION_MULTIPLE))
    {
      gint row;
      gint column;
968
      GtkCTreeNode *work;
969 970 971 972 973

      if (gtk_clist_get_selection_info
	  (clist, event->x, event->y, &row, &column))
	{
	  if (clist->anchor == clist->focus_row &&
974
	      (work = GTK_CTREE_NODE (g_list_nth (clist->row_list, row))))
975 976 977 978 979
	    tree_toggle_selection (ctree, work, column);
	}
      clist->anchor = -1;
    }
  return GTK_WIDGET_CLASS (parent_class)->button_release_event (widget, event);
Tim Janik's avatar
Tim Janik committed
980 981 982 983 984 985
}

static void
create_drag_icon (GtkCTree    *ctree,
		  GtkCTreeRow *row)
{
986 987
  GtkCList *clist;
  GtkWidget *widget;
Tim Janik's avatar
Tim Janik committed
988 989 990 991 992 993 994 995 996 997 998 999
  GdkWindow *window = NULL;
  GdkWindowAttr attributes;
  gint attributes_mask;
  GdkPixmap *pixmap;
  GdkBitmap *mask;
  GdkModifierType modmask;
  gint root_x;
  gint root_y;

  clist  = GTK_CLIST (ctree);
  widget = GTK_WIDGET (ctree);

1000
  if (!(pixmap = GTK_CELL_PIXTEXT (row->row.cell[ctree->tree_column])->pixmap))
Tim Janik's avatar
Tim Janik committed
1001
    return;
1002
  mask = GTK_CELL_PIXTEXT (row->row.cell[ctree->tree_column])->mask;
Tim Janik's avatar
Tim Janik committed
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043

  gdk_window_get_pointer (NULL, &root_x, &root_y, &modmask);
  gdk_window_get_size (pixmap, &ctree->icon_width, &ctree->icon_height);

  attributes.window_type = GDK_WINDOW_TEMP;
  attributes.x = root_x - ctree->icon_width / 2;
  attributes.y = root_y - ctree->icon_height;
  attributes.width = ctree->icon_width;
  attributes.height = ctree->icon_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_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;

  window = gdk_window_new (widget->window, &attributes, attributes_mask);
  gdk_window_set_back_pixmap (window, pixmap, FALSE);
  if (mask)
    gdk_window_shape_combine_mask (window, mask, 0, 0);
  gdk_window_show (window);

  ctree->drag_icon = window;
}

static void
draw_xor_line (GtkCTree *ctree)
{
  GtkCList *clist;
  gint level;
  gint y = 0;

  clist = GTK_CLIST (ctree);

  level = GTK_CTREE_ROW (ctree->drag_target)->level;

  if (ctree->insert_pos == GTK_CTREE_POS_AFTER)
    y = ROW_TOP_YPIXEL (clist, ctree->drag_row) + clist->row_height;
  else 
    y = ROW_TOP_YPIXEL (clist, ctree->drag_row) - 1;

1044 1045 1046 1047 1048 1049 1050
  if (clist->column[ctree->tree_column].visible)
    switch (clist->column[ctree->tree_column].justification)
      {
      case GTK_JUSTIFY_CENTER:
      case GTK_JUSTIFY_FILL:
      case GTK_JUSTIFY_LEFT:
	if (ctree->tree_column > 0)
1051
	  gdk_draw_line (clist->clist_window, clist->xor_gc, 
1052 1053 1054
			 COLUMN_LEFT_XPIXEL(clist, 0), y,
			 COLUMN_LEFT_XPIXEL(clist, ctree->tree_column - 1) +
			 clist->column[ctree->tree_column - 1].area.width, y);
1055
      
1056
	gdk_draw_line (clist->clist_window, clist->xor_gc, 
1057 1058 1059 1060 1061 1062 1063
		       COLUMN_LEFT_XPIXEL(clist, ctree->tree_column) + 
		       ctree->tree_indent * level -
		       (ctree->tree_indent - PM_SIZE) / 2, y,
		       GTK_WIDGET (ctree)->allocation.width, y);
	break;
      case GTK_JUSTIFY_RIGHT:
	if (ctree->tree_column < clist->columns - 1)
1064
	  gdk_draw_line (clist->clist_window, clist->xor_gc, 
1065 1066 1067
			 COLUMN_LEFT_XPIXEL(clist, ctree->tree_column + 1), y,
			 COLUMN_LEFT_XPIXEL(clist, clist->columns - 1) +
			 clist->column[clist->columns - 1].area.width, y);
1068
      
1069
	gdk_draw_line (clist->clist_window, clist->xor_gc, 
1070 1071 1072 1073 1074 1075 1076
		       0, y, COLUMN_LEFT_XPIXEL(clist, ctree->tree_column)
		       + clist->column[ctree->tree_column].area.width -
		       ctree->tree_indent * level +
		       (ctree->tree_indent - PM_SIZE) / 2, y);
	break;
      }
  else
1077
    gdk_draw_line (clist->clist_window, clist->xor_gc, 
1078
		   0, y, clist->clist_window_width, y);
Tim Janik's avatar
Tim Janik committed
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
}

static void
draw_xor_rect (GtkCTree *ctree)
{
  GtkCList *clist;
  GdkPoint points[4];
  guint level;
  gint i;
  gint y;

  clist = GTK_CLIST (ctree);

  level = GTK_CTREE_ROW (ctree->drag_target)->level;

  y = ROW_TOP_YPIXEL (clist, ctree->drag_row) + clist->row_height;

1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
  if (clist->column[ctree->tree_column].visible)
    switch (clist->column[ctree->tree_column].justification)
      {
      case GTK_JUSTIFY_CENTER:
      case GTK_JUSTIFY_FILL:
      case GTK_JUSTIFY_LEFT:
	points[0].x =  COLUMN_LEFT_XPIXEL(clist, ctree->tree_column) + 
	  ctree->tree_indent * level - (ctree->tree_indent - PM_SIZE) / 2;
	points[0].y = y;
	points[3].x = points[0].x;
	points[3].y = y - clist->row_height - 1;
	points[1].x = clist->clist_window_width - 1;
	points[1].y = points[0].y;
	points[2].x = points[1].x;
	points[2].y = points[3].y;

	for (i = 0; i < 3; i++)
1113
	  gdk_draw_line (clist->clist_window, clist->xor_gc,
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129
			 points[i].x, points[i].y,
			 points[i+1].x, points[i+1].y);

	if (ctree->tree_column > 0)
	  {
	    points[0].x = COLUMN_LEFT_XPIXEL(clist, ctree->tree_column - 1) +
	      clist->column[ctree->tree_column - 1].area.width ;
	    points[0].y = y;
	    points[3].x = points[0].x;
	    points[3].y = y - clist->row_height - 1;
	    points[1].x = 0;
	    points[1].y = points[0].y;
	    points[2].x = 0;
	    points[2].y = points[3].y;

	    for (i = 0; i < 3; i++)
1130
	      gdk_draw_line (clist->clist_window, clist->xor_gc,
1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
			     points[i].x, points[i].y, points[i+1].x, 
			     points[i+1].y);
	  }
	break;
      case GTK_JUSTIFY_RIGHT:
	points[0].x =  COLUMN_LEFT_XPIXEL(clist, ctree->tree_column) - 
	  ctree->tree_indent * level + (ctree->tree_indent - PM_SIZE) / 2  +
	  clist->column[ctree->tree_column].area.width;
	points[0].y = y;
	points[3].x = points[0].x;
	points[3].y = y - clist->row_height - 1;
	points[1].x = 0;
	points[1].y = points[0].y;
	points[2].x = 0;
	points[2].y = points[3].y;

	for (i = 0; i < 3; i++)
1148
	  gdk_draw_line (clist->clist_window, clist->xor_gc,
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163
			 points[i].x, points[i].y,
			 points[i+1].x, points[i+1].y);

	if (ctree->tree_column < clist->columns - 1)
	  {
	    points[0].x = COLUMN_LEFT_XPIXEL(clist, ctree->tree_column + 1);
	    points[0].y = y;
	    points[3].x = points[0].x;
	    points[3].y = y - clist->row_height - 1;
	    points[1].x = clist->clist_window_width - 1;
	    points[1].y = points[0].y;
	    points[2].x = points[1].x;
	    points[2].y = points[3].y;

	    for (i = 0; i < 3; i++)
1164
	      gdk_draw_line (clist->clist_window, clist->xor_gc,
1165 1166 1167 1168 1169 1170
			     points[i].x, points[i].y,
			     points[i+1].x, points[i+1].y);
	  }
	break;
      }      
  else
1171
    gdk_draw_rectangle (clist->clist_window, clist->xor_gc, FALSE,
1172 1173
			0, y - clist->row_height,
			clist->clist_window_width - 1, clist->row_height);
Tim Janik's avatar
Tim Janik committed
1174 1175
}

1176 1177 1178 1179 1180 1181 1182 1183 1184 1185
static gint
draw_cell_pixmap (GdkWindow    *window,
		  GdkRectangle *clip_rectangle,
		  GdkGC        *fg_gc,
		  GdkPixmap    *pixmap,
		  GdkBitmap    *mask,
		  gint          x,
		  gint          y,
		  gint          width,
		  gint          height)
Tim Janik's avatar
Tim Janik committed
1186
{
1187 1188
  gint xsrc = 0;
  gint ysrc = 0;
Tim Janik's avatar
Tim Janik committed
1189

1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
  if (mask)
    {
      gdk_gc_set_clip_mask (fg_gc, mask);
      gdk_gc_set_clip_origin (fg_gc, x, y);
    }
  if (x < clip_rectangle->x)
    {
      xsrc = clip_rectangle->x - x;
      width -= xsrc;
      x = clip_rectangle->x;
    }
  if (x + width > clip_rectangle->x + clip_rectangle->width)
    width = clip_rectangle->x + clip_rectangle->width - x;
Tim Janik's avatar
Tim Janik committed
1203

1204 1205 1206 1207 1208 1209 1210 1211
  if (y < clip_rectangle->y)
    {
      ysrc = clip_rectangle->y - y;
      height -= ysrc;
      y = clip_rectangle->y;
    }
  if (y + height > clip_rectangle->y + clip_rectangle->height)
    height = clip_rectangle->y + clip_rectangle->height - y;
Tim Janik's avatar
Tim Janik committed
1212

1213 1214 1215 1216
  if (width > 0 && height > 0)
    gdk_draw_pixmap (window, fg_gc, pixmap, xsrc, ysrc, x, y, width, height);
    
  gdk_gc_set_clip_origin (fg_gc, 0, 0);
Tim Janik's avatar
Tim Janik committed
1217

1218 1219
  return x + MAX (width, 0);
}
Tim Janik's avatar
Tim Janik committed
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
static void
get_cell_style (GtkCList     *clist,
		GtkCListRow  *clist_row,
		gint          state,
		gint          column,
		GtkStyle    **style,
		GdkGC       **fg_gc,
		GdkGC       **bg_gc)
{
  if (clist_row->cell[column].style)
    {
      if (style)
	*style = clist_row->cell[column].style;
      if (fg_gc)
	*fg_gc = clist_row->cell[column].style->fg_gc[state];
      if (bg_gc)
	*bg_gc = clist_row->cell[column].style->bg_gc[state];
    }
  else if (clist_row->style)
    {
      if (style)
	*style = clist_row->style;
      if (fg_gc)
	*fg_gc = clist_row->style->fg_gc[state];
      if (bg_gc)
	*bg_gc = clist_row->style->bg_gc[state];
    }
  else
    {
      if (style)
	*style = GTK_WIDGET (clist)->style;
      if (fg_gc)
	*fg_gc = GTK_WIDGET (clist)->style->fg_gc[state];
      if (bg_gc)
	*bg_gc = GTK_WIDGET (clist)->style->bg_gc[state];

      if (state != GTK_STATE_SELECTED)
	{
	  if (fg_gc && clist_row->fg_set)
	    *fg_gc = clist->fg_gc;
	  if (bg_gc && clist_row->bg_set)
	    *bg_gc = clist->bg_gc;
	}
    }
}
Tim Janik's avatar
Tim Janik committed
1266

1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277
static gint
gtk_ctree_draw_expander (GtkCTree     *ctree,
			 GtkCTreeRow  *ctree_row,
			 GtkStyle     *style,
			 GdkRectangle *clip_rectangle,
			 gint          x)
{
  GtkCList *clist;
  GdkPoint points[3];
  gint justification_factor;
  gint y;
Tim Janik's avatar
Tim Janik committed
1278

1279 1280
 if (ctree->expander_style == GTK_CTREE_EXPANDER_NONE)
   return x;
Tim Janik's avatar
Tim Janik committed
1281

1282 1283 1284 1285 1286 1287 1288
  clist = GTK_CLIST (ctree);
  if (clist->column[ctree->tree_column].justification == GTK_JUSTIFY_RIGHT)
    justification_factor = -1;
  else
    justification_factor = 1;
  y = (clip_rectangle->y + (clip_rectangle->height - PM_SIZE) / 2 -
       (clip_rectangle->height + 1) % 2);
Tim Janik's avatar
Tim Janik committed
1289

1290
  if (!ctree_row->children)
Tim Janik's avatar
Tim Janik committed
1291
    {
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301
      switch (ctree->expander_style)
	{
	case GTK_CTREE_EXPANDER_NONE:
	  return x;
	case GTK_CTREE_EXPANDER_TRIANGLE:
	  return x + justification_factor * (PM_SIZE + 3);
	case GTK_CTREE_EXPANDER_SQUARE:
	case GTK_CTREE_EXPANDER_CIRCULAR:
	  return x + justification_factor * (PM_SIZE + 1);
	}
Tim Janik's avatar
Tim Janik committed
1302
    }
1303 1304 1305 1306 1307

  gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], clip_rectangle);
  gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], clip_rectangle);

  switch (ctree->expander_style)
Tim Janik's avatar
Tim Janik committed
1308
    {
1309 1310 1311 1312
    case GTK_CTREE_EXPANDER_NONE:
      break;
    case GTK_CTREE_EXPANDER_TRIANGLE:
      if (ctree_row->expanded)
Tim Janik's avatar
Tim Janik committed
1313
	{
1314 1315 1316 1317 1318 1319 1320
	  points[0].x = x;
	  points[0].y = y + (PM_SIZE + 2) / 6;
	  points[1].x = points[0].x + justification_factor * (PM_SIZE + 2);
	  points[1].y = points[0].y;
	  points[2].x = (points[0].x +
			 justification_factor * (PM_SIZE + 2) / 2);
	  points[2].y = y + 2 * (PM_SIZE + 2) / 3;
Tim Janik's avatar
Tim Janik committed
1321 1322 1323
	}
      else
	{
1324 1325 1326 1327 1328 1329 1330
	  points[0].x = x + justification_factor * ((PM_SIZE + 2) / 6 + 2);
	  points[0].y = y - 1;
	  points[1].x = points[0].x;
	  points[1].y = points[0].y + (PM_SIZE + 2);
	  points[2].x = (points[0].x +
			 justification_factor * (2 * (PM_SIZE + 2) / 3 - 1));
	  points[2].y = points[0].y + (PM_SIZE + 2) / 2;
Tim Janik's avatar
Tim Janik committed
1331 1332
	}

1333 1334 1335 1336
      gdk_draw_polygon (clist->clist_window, style->base_gc[GTK_STATE_NORMAL],
			TRUE, points, 3);
      gdk_draw_polygon (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
			FALSE, points, 3);
Tim Janik's avatar
Tim Janik committed
1337

1338 1339 1340 1341 1342 1343
      x += justification_factor * (PM_SIZE + 3);
      break;
    case GTK_CTREE_EXPANDER_SQUARE:
    case GTK_CTREE_EXPANDER_CIRCULAR:
      if (justification_factor == -1)
	x += justification_factor * (PM_SIZE + 1);
Tim Janik's avatar
Tim Janik committed
1344

1345 1346 1347 1348 1349 1350
      if (ctree->expander_style == GTK_CTREE_EXPANDER_CIRCULAR)
	{
	  gdk_draw_arc (clist->clist_window, style->base_gc[GTK_STATE_NORMAL],
			TRUE, x, y, PM_SIZE, PM_SIZE, 0, 360 * 64);
	  gdk_draw_arc (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
			FALSE, x, y, PM_SIZE, PM_SIZE, 0, 360 * 64);
Tim Janik's avatar
Tim Janik committed
1351
	}
1352
      else
Tim Janik's avatar
Tim Janik committed
1353
	{
1354 1355 1356 1357 1358 1359
	  gdk_draw_rectangle (clist->clist_window,
			      style->base_gc[GTK_STATE_NORMAL], TRUE,
			      x, y, PM_SIZE, PM_SIZE);
	  gdk_draw_rectangle (clist->clist_window,
			      style->fg_gc[GTK_STATE_NORMAL], FALSE,
			      x, y, PM_SIZE, PM_SIZE);
Tim Janik's avatar
Tim Janik committed
1360
	}
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419

      gdk_draw_line (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL], 
		     x + 2, y + PM_SIZE / 2, x + PM_SIZE - 2, y + PM_SIZE / 2);

      if (!ctree_row->expanded)
	gdk_draw_line (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
		       x + PM_SIZE / 2, y + 2,
		       x + PM_SIZE / 2, y + PM_SIZE - 2);

      if (justification_factor == 1)
	x += justification_factor * (PM_SIZE + 1);
      break;
    }

  gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
  gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);

  return x;
}


static gint
gtk_ctree_draw_lines (GtkCTree     *ctree,
		      GtkCTreeRow  *ctree_row,
		      gint          row,
		      gint          column,
		      gint          state,
		      GdkRectangle *clip_rectangle,
		      GdkRectangle *cell_rectangle,
		      GdkRectangle *crect,
		      GdkRectangle *area,
		      GtkStyle     *style)
{
  GtkCList *clist;
  GtkCTreeNode *node;
  GtkCTreeNode *parent;
  GdkRectangle tree_rectangle;
  GdkRectangle tc_rectangle;
  GdkGC *bg_gc;
  gint offset;
  gint offset_x;
  gint offset_y;
  gint xcenter;
  gint ycenter;
  gint next_level;
  gint column_right;
  gint column_left;
  gint justify_right;
  gint justification_factor;
  
  clist = GTK_CLIST (ctree);
  ycenter = clip_rectangle->y + (clip_rectangle->height / 2);
  justify_right = (clist->column[column].justification == GTK_JUSTIFY_RIGHT);

  if (justify_right)
    {
      offset = (clip_rectangle->x + clip_rectangle->width - 1 -
		ctree->tree_indent * (ctree_row->level - 1));
      justification_factor = -1;
Tim Janik's avatar
Tim Janik committed
1420 1421 1422
    }
  else
    {
1423 1424
      offset = clip_rectangle->x + ctree->tree_indent * (ctree_row->level - 1);
      justification_factor = 1;
Tim Janik's avatar
Tim Janik committed
1425 1426
    }

1427
  switch (ctree->line_style)
Tim Janik's avatar
Tim Janik committed
1428
    {
1429 1430 1431 1432
    case GTK_CTREE_LINES_NONE:
      break;
    case GTK_CTREE_LINES_TABBED:
      xcenter = offset + justification_factor * TAB_SIZE;
Tim Janik's avatar
Tim Janik committed
1433

1434 1435 1436 1437 1438
      column_right = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) +
		      clist->column[ctree->tree_column].area.width +
		      COLUMN_INSET);
      column_left = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) -
		     COLUMN_INSET - CELL_SPACING);
Tim Janik's avatar
Tim Janik committed
1439

1440
      if (area)
1441
	{
1442 1443
	  tree_rectangle.y = crect->y;
	  tree_rectangle.height = crect->height;
1444

1445
	  if (justify_right)
1446
	    {
1447 1448
	      tree_rectangle.x = xcenter;
	      tree_rectangle.width = column_right - xcenter;
1449 1450 1451
	    }
	  else
	    {
1452 1453
	      tree_rectangle.x = column_left;
	      tree_rectangle.width = xcenter - column_left;
1454 1455
	    }

1456
	  if (!gdk_rectangle_intersect (area, &tree_rectangle, &tc_rectangle))
1457
	    {
1458 1459
	      offset += justification_factor * 3;
	      break;
1460 1461 1462
	    }
	}

1463 1464 1465 1466 1467
      gdk_gc_set_clip_rectangle (ctree->lines_gc, crect);

      next_level = ctree_row->level;

      if (!ctree_row->sibling || (ctree_row->children && ctree_row->expanded))
Tim Janik's avatar
Tim Janik committed
1468
	{
1469 1470 1471 1472 1473
	  node = gtk_ctree_find_node_ptr (ctree, ctree_row);
	  if (GTK_CTREE_NODE_NEXT (node))
	    next_level = GTK_CTREE_ROW (GTK_CTREE_NODE_NEXT (node))->level;
	  else
	    next_level = 0;
Tim Janik's avatar
Tim Janik committed
1474
	}
1475 1476

      if (ctree->tree_indent > 0)
Tim Janik's avatar
Tim Janik committed
1477
	{
1478 1479 1480 1481
	  node = ctree_row->parent;
	  while (node)
	    {
	      xcenter -= (justification_factor * ctree->tree_indent);
Tim Janik's avatar
Tim Janik committed
1482

1483 1484 1485 1486 1487 1488
	      if ((justify_right && xcenter < column_left) ||
		  (!justify_right && xcenter > column_right))
		{
		  node = GTK_CTREE_ROW (node)->parent;
		  continue;
		}
Tim Janik's avatar
Tim Janik committed
1489

1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504
	      tree_rectangle.y = cell_rectangle->y;
	      tree_rectangle.height = cell_rectangle->height;
	      if (justify_right)
		{
		  tree_rectangle.x = MAX (xcenter - ctree->tree_indent + 1,
					  column_left);
		  tree_rectangle.width = MIN (xcenter - column_left,
					      ctree->tree_indent);
		}
	      else
		{
		  tree_rectangle.x = xcenter;
		  tree_rectangle.width = MIN (column_right - xcenter,
					      ctree->tree_indent);
		}
Tim Janik's avatar
Tim Janik committed
1505

1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535
	      if (!area || gdk_rectangle_intersect (area, &tree_rectangle,
						    &tc_rectangle))
		{
		  get_cell_style (clist, &GTK_CTREE_ROW (node)->row,
				  state, column, NULL, NULL, &bg_gc);

		  if (bg_gc == clist->bg_gc)
		    gdk_gc_set_foreground
		      (clist->bg_gc, &GTK_CTREE_ROW (node)->row.background);

		  if (!area)
		    gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
					tree_rectangle.x,
					tree_rectangle.y,
					tree_rectangle.width,
					tree_rectangle.height);
		  else 
		    gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
					tc_rectangle.x,
					tc_rectangle.y,
					tc_rectangle.width,
					tc_rectangle.height);
		}
	      if (next_level > GTK_CTREE_ROW (node)->level)
		gdk_draw_line (clist->clist_window, ctree->lines_gc,
			       xcenter, crect->y,
			       xcenter, crect->y + crect->height);
	      else
		{
		  gint width;
Tim Janik's avatar
Tim Janik committed
1536

1537 1538
		  offset_x = MIN (ctree->tree_indent, 2 * TAB_SIZE);
		  width = offset_x / 2 + offset_x % 2;
Tim Janik's avatar
Tim Janik committed
1539

1540
		  parent = GTK_CTREE_ROW (node)->parent;
Tim Janik's avatar
Tim Janik committed
1541

1542 1543 1544
		  tree_rectangle.y = ycenter;
		  tree_rectangle.height = (cell_rectangle->y - ycenter +
					   cell_rectangle->height);
Tim Janik's avatar
Tim Janik committed
1545

1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557
		  if (justify_right)
		    {
		      tree_rectangle.x = MAX(xcenter + 1 - width, column_left);
		      tree_rectangle.width = MIN (xcenter + 1 - column_left,
						  width);
		    }
		  else
		    {
		      tree_rectangle.x = xcenter;
		      tree_rectangle.width = MIN (column_right - xcenter,
						  width);
		    }
Tim Janik's avatar
Tim Janik committed
1558

1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620
		  if (!area ||
		      gdk_rectangle_intersect (area, &tree_rectangle,
					       &tc_rectangle))
		    {
		      if (parent)
			{
			  get_cell_style (clist, &GTK_CTREE_ROW (parent)->row,
					  state, column, NULL, NULL, &bg_gc);
			  if (bg_gc == clist->bg_gc)
			    gdk_gc_set_foreground
			      (clist->bg_gc,
			       &GTK_CTREE_ROW (parent)->row.background);
			}
		      else if (state == GTK_STATE_SELECTED)
			bg_gc = style->bg_gc[state];
		      else
			bg_gc = GTK_WIDGET (clist)->style->bg_gc[state];

		      if (!area)
			gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
					    tree_rectangle.x,
					    tree_rectangle.y,
					    tree_rectangle.width,
					    tree_rectangle.height);
		      else
			gdk_draw_rectangle (clist->clist_window,
					    bg_gc, TRUE,
					    tc_rectangle.x,
					    tc_rectangle.y,
					    tc_rectangle.width,
					    tc_rectangle.height);
		    }

		  get_cell_style (clist, &GTK_CTREE_ROW (node)->row,
				  state, column, NULL, NULL, &bg_gc);
		  if (bg_gc == clist->bg_gc)
		    gdk_gc_set_foreground
		      (clist->bg_gc, &GTK_CTREE_ROW (node)->row.background);

		  gdk_gc_set_clip_rectangle (bg_gc, crect);
		  gdk_draw_arc (clist->clist_window, bg_gc, TRUE,
				xcenter - (justify_right * offset_x),
				cell_rectangle->y,
				offset_x, clist->row_height,
				(180 + (justify_right * 90)) * 64, 90 * 64);
		  gdk_gc_set_clip_rectangle (bg_gc, NULL);

		  gdk_draw_line (clist->clist_window, ctree->lines_gc, 
				 xcenter, cell_rectangle->y, xcenter, ycenter);

		  if (justify_right)
		    gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
				  xcenter - offset_x, cell_rectangle->y,
				  offset_x, clist->row_height,
				  270 * 64, 90 * 64);
		  else
		    gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
				  xcenter, cell_rectangle->y,
				  offset_x, clist->row_height,
				  180 * 64, 90 * 64);
		}
	      node = GTK_CTREE_ROW (node)->parent;
Tim Janik's avatar
Tim Janik committed
1621
	    }
1622
	}
Tim Janik's avatar
Tim Janik committed
1623

1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635
      if (state != GTK_STATE_SELECTED)
	{
	  tree_rectangle.y = clip_rectangle->y;
	  tree_rectangle.height = clip_rectangle->height;
	  tree_rectangle.width = COLUMN_INSET + CELL_SPACING +
	    MIN (clist->column[ctree->tree_column].area.width + COLUMN_INSET,
		 TAB_SIZE);

	  if (justify_right)
	    tree_rectangle.x = MAX (xcenter + 1, column_left);
	  else
	    tree_rectangle.x = column_left;
Tim Janik's avatar
Tim Janik committed
1636

1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655
	  if (!area)
	    gdk_draw_rectangle (clist->clist_window,
				GTK_WIDGET
				(ctree)->style->bg_gc[GTK_STATE_PRELIGHT],
				TRUE,
				tree_rectangle.x,
				tree_rectangle.y,
				tree_rectangle.width,
				tree_rectangle.height);
	  else if (gdk_rectangle_intersect (area, &tree_rectangle,
					    &tc_rectangle))
	    gdk_draw_rectangle (clist->clist_window,
				GTK_WIDGET
				(ctree)->style->bg_gc[GTK_STATE_PRELIGHT],
				TRUE,
				tc_rectangle.x,
				tc_rectangle.y,
				tc_rectangle.width,
				tc_rectangle.height);
Tim Janik's avatar
Tim Janik committed
1656 1657
	}

1658 1659 1660 1661 1662 1663 1664 1665 1666
      xcenter = offset + (justification_factor * ctree->tree_indent / 2);

      get_cell_style (clist, &ctree_row->row, state, column, NULL, NULL,
		      &bg_gc);
      if (bg_gc == clist->bg_gc)
	gdk_gc_set_foreground (clist->bg_gc, &ctree_row->row.background);

      gdk_gc_set_clip_rectangle (bg_gc, crect);
      if (ctree_row->is_leaf)
Tim Janik's avatar
Tim Janik committed
1667
	{
1668
	  GdkPoint points[6];
Tim Janik's avatar
Tim Janik committed
1669

1670 1671
	  points[0].x = offset + justification_factor * TAB_SIZE;
	  points[0].y = cell_rectangle->y;
Tim Janik's avatar
Tim Janik committed
1672

1673 1674
	  points[1].x = points[0].x - justification_factor * 4;
	  points[1].y = points[0].y;
Tim Janik's avatar
Tim Janik committed
1675

1676 1677
	  points[2].x = points[1].x - justification_factor * 2;
	  points[2].y = points[1].y + 3;
Tim Janik's avatar
Tim Janik committed
1678

1679 1680
	  points[3].x = points[2].x;
	  points[3].y = points[2].y + clist->row_height - 5;
Tim Janik's avatar
Tim Janik committed
1681

1682 1683 1684 1685 1686 1687 1688 1689 1690 1691
	  points[4].x = points[3].x + justification_factor * 2;
	  points[4].y = points[3].y + 3;

	  points[5].x = points[4].x + justification_factor * 4;
	  points[5].y = points[4].y;

	  gdk_draw_polygon (clist->clist_window, bg_gc, TRUE, points, 6);
	  gdk_draw_lines (clist->clist_window, ctree->lines_gc, points, 6);
	}
      else 
Tim Janik's avatar
Tim Janik committed
1692
	{
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705
	  gdk_draw_arc (clist->clist_window, bg_gc, TRUE,
			offset - (justify_right * 2 * TAB_SIZE),
			cell_rectangle->y,
			2 * TAB_SIZE, clist->row_height,
			(90 + (180 * justify_right)) * 64, 180 * 64);
	  gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
			offset - (justify_right * 2 * TAB_SIZE),
			cell_rectangle->y,
			2 * TAB_SIZE, clist->row_height,
			(90 + (180 * justify_right)) * 64, 180 * 64);
	}
      gdk_gc_set_clip_rectangle (bg_gc, NULL);
      gdk_gc_set_clip_rectangle (ctree->lines_gc, NULL);
1706

1707 1708 1709 1710