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"
Lars Hamann's avatar
Lars Hamann committed
27
#include "gtkmain.h"
28
#include "gtkdnd.h"
Tim Janik's avatar
Tim Janik committed
29
#include <gdk/gdkx.h>
30
#include <gdk/gdkkeysyms.h>
Tim Janik's avatar
Tim Janik committed
31 32

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

#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)
46
#define COLUMN_LEFT(clist, column) ((clist)->column[(column)].area.x)
Tim Janik's avatar
Tim Janik committed
47

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
static inline gint
COLUMN_FROM_XPIXEL (GtkCList * clist,
		    gint x)
{
  gint i, cx;

  for (i = 0; i < clist->columns; i++)
    if (clist->column[i].visible)
      {
	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;
}

68 69 70 71 72 73 74
#define GTK_CLIST_CLASS_FW(_widget_) GTK_CLIST_CLASS (((GtkObject*) (_widget_))->klass)
#define CLIST_UNFROZEN(clist)     (((GtkCList*) (clist))->freeze_count == 0)
#define CLIST_REFRESH(clist)    G_STMT_START { \
  if (CLIST_UNFROZEN (clist)) \
    GTK_CLIST_CLASS_FW (clist)->refresh ((GtkCList*) (clist)); \
} G_STMT_END

75

76 77 78 79 80 81 82 83 84 85 86
enum {
  ARG_0,
  ARG_N_COLUMNS,
  ARG_TREE_COLUMN,
  ARG_INDENT,
  ARG_SPACING,
  ARG_SHOW_STUB,
  ARG_LINE_STYLE,
  ARG_EXPANDER_STYLE
};

87

Tim Janik's avatar
Tim Janik committed
88 89
static void gtk_ctree_class_init        (GtkCTreeClass  *klass);
static void gtk_ctree_init              (GtkCTree       *ctree);
90 91 92 93 94 95
static void gtk_ctree_set_arg		(GtkObject      *object,
					 GtkArg         *arg,
					 guint           arg_id);
static void gtk_ctree_get_arg      	(GtkObject      *object,
					 GtkArg         *arg,
					 guint           arg_id);
96 97
static void gtk_ctree_realize           (GtkWidget      *widget);
static void gtk_ctree_unrealize         (GtkWidget      *widget);
Tim Janik's avatar
Tim Janik committed
98 99
static gint gtk_ctree_button_press      (GtkWidget      *widget,
					 GdkEventButton *event);
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
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);
137 138 139
static void draw_row                    (GtkCList       *clist,
					 GdkRectangle   *area,
					 gint            row,
140 141 142 143 144
					 GtkCListRow    *clist_row);
static void draw_drag_highlight         (GtkCList        *clist,
					 GtkCListRow     *dest_row,
					 gint             dest_row_number,
					 GtkCListDragPos  drag_pos);
145 146
static void tree_draw_node              (GtkCTree      *ctree,
					 GtkCTreeNode  *node);
147
static void set_cell_contents           (GtkCList      *clist,
Tim Janik's avatar
Tim Janik committed
148 149
					 GtkCListRow   *clist_row,
					 gint           column,
150
					 GtkCellType    type,
Tim Janik's avatar
Tim Janik committed
151
					 const gchar   *text,
Tim Janik's avatar
Tim Janik committed
152 153 154
					 guint8         spacing,
					 GdkPixmap     *pixmap,
					 GdkBitmap     *mask);
155
static void set_node_info               (GtkCTree      *ctree,
156
					 GtkCTreeNode  *node,
Tim Janik's avatar
Tim Janik committed
157
					 const gchar   *text,
158 159 160 161 162 163 164
					 guint8         spacing,
					 GdkPixmap     *pixmap_closed,
					 GdkBitmap     *mask_closed,
					 GdkPixmap     *pixmap_opened,
					 GdkBitmap     *mask_opened,
					 gboolean       is_leaf,
					 gboolean       expanded);
165 166 167 168
static GtkCTreeRow *row_new             (GtkCTree      *ctree);
static void row_delete                  (GtkCTree      *ctree,
				 	 GtkCTreeRow   *ctree_row);
static void tree_delete                 (GtkCTree      *ctree, 
169
					 GtkCTreeNode  *node, 
170 171
					 gpointer       data);
static void tree_delete_row             (GtkCTree      *ctree, 
172
					 GtkCTreeNode  *node, 
173
					 gpointer       data);
174
static void real_clear                  (GtkCList      *clist);
175
static void tree_update_level           (GtkCTree      *ctree, 
176
					 GtkCTreeNode  *node, 
177 178
					 gpointer       data);
static void tree_select                 (GtkCTree      *ctree, 
179
					 GtkCTreeNode  *node, 
180 181
					 gpointer       data);
static void tree_unselect               (GtkCTree      *ctree, 
182
					 GtkCTreeNode  *node, 
183
				         gpointer       data);
184 185
static void real_select_all             (GtkCList      *clist);
static void real_unselect_all           (GtkCList      *clist);
186
static void tree_expand                 (GtkCTree      *ctree, 
187
					 GtkCTreeNode  *node,
188 189
					 gpointer       data);
static void tree_collapse               (GtkCTree      *ctree, 
190
					 GtkCTreeNode  *node,
191
					 gpointer       data);
192
static void tree_collapse_to_depth      (GtkCTree      *ctree, 
193
					 GtkCTreeNode  *node, 
194
					 gint           depth);
195
static void tree_toggle_expansion       (GtkCTree      *ctree,
196
					 GtkCTreeNode  *node,
197 198
					 gpointer       data);
static void change_focus_row_expansion  (GtkCTree      *ctree,
199
				         GtkCTreeExpansionType expansion);
200 201 202 203 204 205 206 207
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);
208
static void real_tree_select            (GtkCTree      *ctree,
209
					 GtkCTreeNode  *node,
210 211
					 gint           column);
static void real_tree_unselect          (GtkCTree      *ctree,
212
					 GtkCTreeNode  *node,
213 214
					 gint           column);
static void real_tree_expand            (GtkCTree      *ctree,
215
					 GtkCTreeNode  *node);
216
static void real_tree_collapse          (GtkCTree      *ctree,
217
					 GtkCTreeNode  *node);
218
static void real_tree_move              (GtkCTree      *ctree,
219 220 221
					 GtkCTreeNode  *node,
					 GtkCTreeNode  *new_parent, 
					 GtkCTreeNode  *new_sibling);
222 223 224
static void real_row_move               (GtkCList      *clist,
					 gint           source_row,
					 gint           dest_row);
225
static void gtk_ctree_link              (GtkCTree      *ctree,
226 227 228
					 GtkCTreeNode  *node,
					 GtkCTreeNode  *parent,
					 GtkCTreeNode  *sibling,
229
					 gboolean       update_focus_row);
230
static void gtk_ctree_unlink            (GtkCTree      *ctree, 
231
					 GtkCTreeNode  *node,
232
					 gboolean       update_focus_row);
233 234
static GtkCTreeNode * gtk_ctree_last_visible (GtkCTree     *ctree,
					      GtkCTreeNode *node);
235
static gboolean ctree_is_hot_spot       (GtkCTree      *ctree, 
236
					 GtkCTreeNode  *node,
237 238 239 240
					 gint           row, 
					 gint           x, 
					 gint           y);
static void tree_sort                   (GtkCTree      *ctree,
241
					 GtkCTreeNode  *node,
242
					 gpointer       data);
243 244
static void fake_unselect_all           (GtkCList      *clist,
					 gint           row);
245
static GList * selection_find           (GtkCList      *clist,
246 247 248 249 250 251
					 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, 
252
					 GtkCTreeNode  *node, 
253
					 gpointer       data);
254 255 256 257 258 259
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);
260 261 262 263 264 265 266 267
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
268
static void auto_resize_columns         (GtkCList       *clist);
269

270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288

static gboolean check_drag               (GtkCTree         *ctree,
			                  GtkCTreeNode     *drag_source,
					  GtkCTreeNode     *drag_target,
					  GtkCListDragPos   insert_pos);
static void gtk_ctree_drag_begin         (GtkWidget        *widget,
					  GdkDragContext   *context);
static gint gtk_ctree_drag_motion        (GtkWidget        *widget,
					  GdkDragContext   *context,
					  gint              x,
					  gint              y,
					  guint             time);
static void gtk_ctree_drag_data_received (GtkWidget        *widget,
					  GdkDragContext   *context,
					  gint              x,
					  gint              y,
					  GtkSelectionData *selection_data,
					  guint             info,
					  guint32           time);
289
static void remove_grab                  (GtkCList         *clist);
290 291


Tim Janik's avatar
Tim Janik committed
292 293 294 295 296 297 298
enum
{
  TREE_SELECT_ROW,
  TREE_UNSELECT_ROW,
  TREE_EXPAND,
  TREE_COLLAPSE,
  TREE_MOVE,
299
  CHANGE_FOCUS_ROW_EXPANSION,
Tim Janik's avatar
Tim Janik committed
300 301 302 303 304 305 306 307 308
  LAST_SIGNAL
};

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


GtkType
309
gtk_ctree_get_type (void)
Tim Janik's avatar
Tim Janik committed
310 311 312 313 314
{
  static GtkType ctree_type = 0;

  if (!ctree_type)
    {
315
      static const GtkTypeInfo ctree_info =
Tim Janik's avatar
Tim Janik committed
316 317 318 319 320 321
      {
	"GtkCTree",
	sizeof (GtkCTree),
	sizeof (GtkCTreeClass),
	(GtkClassInitFunc) gtk_ctree_class_init,
	(GtkObjectInitFunc) gtk_ctree_init,
322 323
	/* reserved_1 */ NULL,
        /* reserved_2 */ NULL,
324
        (GtkClassInitFunc) NULL,
Tim Janik's avatar
Tim Janik committed
325 326
      };

327
      ctree_type = gtk_type_unique (GTK_TYPE_CLIST, &ctree_info);
Tim Janik's avatar
Tim Janik committed
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
    }

  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;

345 346
  parent_class = gtk_type_class (GTK_TYPE_CLIST);
  container_class = gtk_type_class (GTK_TYPE_CONTAINER);
Tim Janik's avatar
Tim Janik committed
347

348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
  gtk_object_add_arg_type ("GtkCTree::n_columns",
			   GTK_TYPE_UINT,
			   GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT_ONLY,
			   ARG_N_COLUMNS);
  gtk_object_add_arg_type ("GtkCTree::tree_column",
			   GTK_TYPE_UINT,
			   GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT_ONLY,
			   ARG_TREE_COLUMN);
  gtk_object_add_arg_type ("GtkCTree::indent",
			   GTK_TYPE_UINT,
			   GTK_ARG_READWRITE,
			   ARG_INDENT);
  gtk_object_add_arg_type ("GtkCTree::spacing",
			   GTK_TYPE_UINT,
			   GTK_ARG_READWRITE,
			   ARG_SPACING);
  gtk_object_add_arg_type ("GtkCTree::show_stub",
			   GTK_TYPE_BOOL,
			   GTK_ARG_READWRITE,
			   ARG_SHOW_STUB);
  gtk_object_add_arg_type ("GtkCTree::line_style",
369
			   GTK_TYPE_CTREE_LINE_STYLE,
370 371 372
			   GTK_ARG_READWRITE,
			   ARG_LINE_STYLE);
  gtk_object_add_arg_type ("GtkCTree::expander_style",
373
			   GTK_TYPE_CTREE_EXPANDER_STYLE,
374 375 376 377 378
			   GTK_ARG_READWRITE,
			   ARG_EXPANDER_STYLE);
  object_class->set_arg = gtk_ctree_set_arg;
  object_class->get_arg = gtk_ctree_get_arg;

Tim Janik's avatar
Tim Janik committed
379 380 381 382 383
  ctree_signals[TREE_SELECT_ROW] =
    gtk_signal_new ("tree_select_row",
		    GTK_RUN_FIRST,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCTreeClass, tree_select_row),
384
		    gtk_marshal_NONE__POINTER_INT,
385
		    GTK_TYPE_NONE, 2, GTK_TYPE_CTREE_NODE, GTK_TYPE_INT);
Tim Janik's avatar
Tim Janik committed
386 387 388 389 390
  ctree_signals[TREE_UNSELECT_ROW] =
    gtk_signal_new ("tree_unselect_row",
		    GTK_RUN_FIRST,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCTreeClass, tree_unselect_row),
391
		    gtk_marshal_NONE__POINTER_INT,
392
		    GTK_TYPE_NONE, 2, GTK_TYPE_CTREE_NODE, GTK_TYPE_INT);
Tim Janik's avatar
Tim Janik committed
393 394 395 396 397
  ctree_signals[TREE_EXPAND] =
    gtk_signal_new ("tree_expand",
		    GTK_RUN_LAST,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCTreeClass, tree_expand),
398
		    gtk_marshal_NONE__POINTER,
399
		    GTK_TYPE_NONE, 1, GTK_TYPE_CTREE_NODE);
Tim Janik's avatar
Tim Janik committed
400 401 402 403 404
  ctree_signals[TREE_COLLAPSE] =
    gtk_signal_new ("tree_collapse",
		    GTK_RUN_LAST,
		    object_class->type,
		    GTK_SIGNAL_OFFSET (GtkCTreeClass, tree_collapse),
405
		    gtk_marshal_NONE__POINTER,
Tim Janik's avatar
Tim Janik committed
406 407 408 409 410 411
		    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),
412
		    gtk_marshal_NONE__POINTER_POINTER_POINTER,
413 414
		    GTK_TYPE_NONE, 3, GTK_TYPE_CTREE_NODE,
		    GTK_TYPE_CTREE_NODE, GTK_TYPE_CTREE_NODE);
415 416 417 418 419 420
  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),
421
		    gtk_marshal_NONE__ENUM,
422
		    GTK_TYPE_NONE, 1, GTK_TYPE_CTREE_EXPANSION_TYPE);
Tim Janik's avatar
Tim Janik committed
423 424 425 426 427
  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;
428 429 430 431

  widget_class->drag_begin = gtk_ctree_drag_begin;
  widget_class->drag_motion = gtk_ctree_drag_motion;
  widget_class->drag_data_received = gtk_ctree_drag_data_received;
Tim Janik's avatar
Tim Janik committed
432

433 434
  clist_class->select_row = real_select_row;
  clist_class->unselect_row = real_unselect_row;
435
  clist_class->row_move = real_row_move;
436 437 438
  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
439 440
  clist_class->click_column = NULL;
  clist_class->draw_row = draw_row;
441
  clist_class->draw_drag_highlight = draw_drag_highlight;
442 443 444 445
  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;
446 447 448 449
  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;
450
  clist_class->cell_size_request = cell_size_request;
Tim Janik's avatar
Tim Janik committed
451

452 453
  klass->tree_select_row = real_tree_select;
  klass->tree_unselect_row = real_tree_unselect;
Tim Janik's avatar
Tim Janik committed
454 455 456
  klass->tree_expand = real_tree_expand;
  klass->tree_collapse = real_tree_collapse;
  klass->tree_move = real_tree_move;
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 503
  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
504 505
}

506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
static void
gtk_ctree_set_arg (GtkObject      *object,
		   GtkArg         *arg,
		   guint           arg_id)
{
  GtkCTree *ctree;

  ctree = GTK_CTREE (object);

  switch (arg_id)
    {
    case ARG_N_COLUMNS: /* construct-only arg, only set when !GTK_CONSTRUCTED */
      if (ctree->tree_column)
	gtk_ctree_construct (ctree,
			     MAX (1, GTK_VALUE_UINT (*arg)),
			     ctree->tree_column, NULL);
      else
	GTK_CLIST (ctree)->columns = MAX (1, GTK_VALUE_UINT (*arg));
      break;
    case ARG_TREE_COLUMN: /* construct-only arg, only set when !GTK_CONSTRUCTED */
      if (GTK_CLIST (ctree)->columns)
	gtk_ctree_construct (ctree,
			     GTK_CLIST (ctree)->columns,
			     MAX (1, GTK_VALUE_UINT (*arg)),
			     NULL);
      else
	ctree->tree_column = MAX (1, GTK_VALUE_UINT (*arg));
      break;
    case ARG_INDENT:
      gtk_ctree_set_indent (ctree, GTK_VALUE_UINT (*arg));
      break;
    case ARG_SPACING:
      gtk_ctree_set_spacing (ctree, GTK_VALUE_UINT (*arg));
      break;
    case ARG_SHOW_STUB:
      gtk_ctree_set_show_stub (ctree, GTK_VALUE_BOOL (*arg));
      break;
    case ARG_LINE_STYLE:
      gtk_ctree_set_line_style (ctree, GTK_VALUE_ENUM (*arg));
      break;
    case ARG_EXPANDER_STYLE:
      gtk_ctree_set_expander_style (ctree, GTK_VALUE_ENUM (*arg));
      break;
    default:
      break;
    }
}

static void
gtk_ctree_get_arg (GtkObject      *object,
		   GtkArg         *arg,
		   guint           arg_id)
{
  GtkCTree *ctree;

  ctree = GTK_CTREE (object);

  switch (arg_id)
    {
    case ARG_N_COLUMNS:
      GTK_VALUE_UINT (*arg) = GTK_CLIST (ctree)->columns;
      break;
    case ARG_TREE_COLUMN:
      GTK_VALUE_UINT (*arg) = ctree->tree_column;
      break;
    case ARG_INDENT:
      GTK_VALUE_UINT (*arg) = ctree->tree_indent;
      break;
    case ARG_SPACING:
      GTK_VALUE_UINT (*arg) = ctree->tree_spacing;
      break;
    case ARG_SHOW_STUB:
      GTK_VALUE_BOOL (*arg) = ctree->show_stub;
      break;
    case ARG_LINE_STYLE:
      GTK_VALUE_ENUM (*arg) = ctree->line_style;
      break;
    case ARG_EXPANDER_STYLE:
      GTK_VALUE_ENUM (*arg) = ctree->expander_style;
      break;
    default:
      arg->type = GTK_TYPE_INVALID;
      break;
    }
}

Tim Janik's avatar
Tim Janik committed
592 593 594
static void
gtk_ctree_init (GtkCTree *ctree)
{
595 596 597 598 599 600 601
  GtkCList *clist;

  GTK_CLIST_SET_FLAG (ctree, CLIST_DRAW_DRAG_RECT);
  GTK_CLIST_SET_FLAG (ctree, CLIST_DRAW_DRAG_LINE);

  clist = GTK_CLIST (ctree);

Tim Janik's avatar
Tim Janik committed
602
  ctree->tree_indent    = 20;
603
  ctree->tree_spacing   = 5;
Tim Janik's avatar
Tim Janik committed
604
  ctree->tree_column    = 0;
605
  ctree->line_style     = GTK_CTREE_LINES_SOLID;
606
  ctree->expander_style = GTK_CTREE_EXPANDER_SQUARE;
607
  ctree->drag_compare   = NULL;
608
  ctree->show_stub      = TRUE;
609 610

  clist->button_actions[0] |= GTK_BUTTON_EXPANDS;
Tim Janik's avatar
Tim Janik committed
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 657 658 659 660 661
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
662 663 664 665
static void
gtk_ctree_realize (GtkWidget *widget)
{
  GtkCTree *ctree;
666
  GtkCList *clist;
Tim Janik's avatar
Tim Janik committed
667
  GdkGCValues values;
668 669 670
  GtkCTreeNode *node;
  GtkCTreeNode *child;
  gint i;
Tim Janik's avatar
Tim Janik committed
671

672 673
  g_return_if_fail (widget != NULL);
  g_return_if_fail (GTK_IS_CTREE (widget));
Tim Janik's avatar
Tim Janik committed
674

675
  GTK_WIDGET_CLASS (parent_class)->realize (widget);
Tim Janik's avatar
Tim Janik committed
676

677
  ctree = GTK_CTREE (widget);
678 679 680 681 682 683 684 685 686 687 688
  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);
    }
689

Tim Janik's avatar
Tim Janik committed
690
  values.foreground = widget->style->fg[GTK_STATE_NORMAL];
691
  values.background = widget->style->base[GTK_STATE_NORMAL];
Tim Janik's avatar
Tim Janik committed
692 693 694 695 696 697 698 699 700 701 702 703 704
  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);
705
      gdk_gc_set_dashes (ctree->lines_gc, 0, "\1\1", 2);
Tim Janik's avatar
Tim Janik committed
706 707 708 709 710 711 712
    }
}

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

715 716
  g_return_if_fail (widget != NULL);
  g_return_if_fail (GTK_IS_CTREE (widget));
Tim Janik's avatar
Tim Janik committed
717

718
  GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
Tim Janik's avatar
Tim Janik committed
719

720
  ctree = GTK_CTREE (widget);
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
  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);
	}
    }
740

Tim Janik's avatar
Tim Janik committed
741 742 743 744 745 746 747 748 749
  gdk_gc_destroy (ctree->lines_gc);
}

static gint
gtk_ctree_button_press (GtkWidget      *widget,
			GdkEventButton *event)
{
  GtkCTree *ctree;
  GtkCList *clist;
750
  gint button_actions;
Tim Janik's avatar
Tim Janik committed
751 752 753 754 755 756 757 758

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

759 760 761 762 763
  button_actions = clist->button_actions[event->button - 1];

  if (button_actions == GTK_BUTTON_IGNORED)
    return FALSE;

Tim Janik's avatar
Tim Janik committed
764 765
  if (event->window == clist->clist_window)
    {
766
      GtkCTreeNode *work;
Tim Janik's avatar
Tim Janik committed
767 768 769 770 771 772 773 774
      gint x;
      gint y;
      gint row;
      gint column;

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

775 776 777
      if (!gtk_clist_get_selection_info (clist, x, y, &row, &column))
	return FALSE;

778
      work = GTK_CTREE_NODE (g_list_nth (clist->row_list, row));
Tim Janik's avatar
Tim Janik committed
779
	  
780 781 782 783
      if (button_actions & GTK_BUTTON_EXPANDS &&
	  (GTK_CTREE_ROW (work)->children && !GTK_CTREE_ROW (work)->is_leaf  &&
	   (event->type == GDK_2BUTTON_PRESS ||
	    ctree_is_hot_spot (ctree, work, row, x, y))))
784 785 786 787 788 789
	{
	  if (GTK_CTREE_ROW (work)->expanded)
	    gtk_ctree_collapse (ctree, work);
	  else
	    gtk_ctree_expand (ctree, work);

790
	  return FALSE;
Tim Janik's avatar
Tim Janik committed
791 792
	}
    }
793
  return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, event);
Tim Janik's avatar
Tim Janik committed
794 795 796
}

static void
797 798 799 800
draw_drag_highlight (GtkCList        *clist,
		     GtkCListRow     *dest_row,
		     gint             dest_row_number,
		     GtkCListDragPos  drag_pos)
Tim Janik's avatar
Tim Janik committed
801
{
802 803
  GtkCTree *ctree;
  GdkPoint points[4];
Tim Janik's avatar
Tim Janik committed
804
  gint level;
805
  gint i;
Tim Janik's avatar
Tim Janik committed
806 807
  gint y = 0;

808 809
  g_return_if_fail (clist != NULL);
  g_return_if_fail (GTK_IS_CTREE (clist));
Tim Janik's avatar
Tim Janik committed
810

811
  ctree = GTK_CTREE (clist);
Tim Janik's avatar
Tim Janik committed
812

813
  level = ((GtkCTreeRow *)(dest_row))->level;
Tim Janik's avatar
Tim Janik committed
814

815 816 817 818 819 820 821 822 823
  y = ROW_TOP_YPIXEL (clist, dest_row_number) - 1;

  switch (drag_pos)
    {
    case GTK_CLIST_DRAG_NONE:
      break;
    case GTK_CLIST_DRAG_AFTER:
      y += clist->row_height + 1;
    case GTK_CLIST_DRAG_BEFORE:
824
      
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
      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)
	      gdk_draw_line (clist->clist_window, clist->xor_gc, 
			     COLUMN_LEFT_XPIXEL(clist, 0), y,
			     COLUMN_LEFT_XPIXEL(clist, ctree->tree_column - 1)+
			     clist->column[ctree->tree_column - 1].area.width,
			     y);

	    gdk_draw_line (clist->clist_window, clist->xor_gc, 
			   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)
	      gdk_draw_line (clist->clist_window, clist->xor_gc, 
			     COLUMN_LEFT_XPIXEL(clist, ctree->tree_column + 1),
			     y,
			     COLUMN_LEFT_XPIXEL(clist, clist->columns - 1) +
			     clist->column[clist->columns - 1].area.width, y);
851
      
852 853 854 855 856 857 858 859
	    gdk_draw_line (clist->clist_window, clist->xor_gc, 
			   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
860
	gdk_draw_line (clist->clist_window, clist->xor_gc, 
861 862 863 864
		       0, y, clist->clist_window_width, y);
      break;
    case GTK_CLIST_DRAG_INTO:
      y = ROW_TOP_YPIXEL (clist, dest_row_number) + clist->row_height;
Tim Janik's avatar
Tim Janik committed
865

866 867
      if (clist->column[ctree->tree_column].visible)
	switch (clist->column[ctree->tree_column].justification)
868
	  {
869 870 871 872 873
	  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;
874 875 876
	    points[0].y = y;
	    points[3].x = points[0].x;
	    points[3].y = y - clist->row_height - 1;
877
	    points[1].x = clist->clist_window_width - 1;
878
	    points[1].y = points[0].y;
879
	    points[2].x = points[1].x;
880 881 882
	    points[2].y = points[3].y;

	    for (i = 0; i < 3; i++)
883
	      gdk_draw_line (clist->clist_window, clist->xor_gc,
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
			     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++)
		  gdk_draw_line (clist->clist_window, clist->xor_gc,
				 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;
910 911 912
	    points[0].y = y;
	    points[3].x = points[0].x;
	    points[3].y = y - clist->row_height - 1;
913
	    points[1].x = 0;
914
	    points[1].y = points[0].y;
915
	    points[2].x = 0;
916 917 918
	    points[2].y = points[3].y;

	    for (i = 0; i < 3; i++)
919
	      gdk_draw_line (clist->clist_window, clist->xor_gc,
920 921
			     points[i].x, points[i].y,
			     points[i+1].x, points[i+1].y);
922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939

	    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++)
		  gdk_draw_line (clist->clist_window, clist->xor_gc,
				 points[i].x, points[i].y,
				 points[i+1].x, points[i+1].y);
	      }
	    break;
940
	  }
941 942 943 944 945 946
      else
	gdk_draw_rectangle (clist->clist_window, clist->xor_gc, FALSE,
			    0, y - clist->row_height,
			    clist->clist_window_width - 1, clist->row_height);
      break;
    }
Tim Janik's avatar
Tim Janik committed
947 948
}

949 950 951 952 953 954 955 956 957 958
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
959
{
960 961
  gint xsrc = 0;
  gint ysrc = 0;
Tim Janik's avatar
Tim Janik committed
962

963 964 965 966 967 968 969 970 971 972 973 974 975
  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
976

977 978 979 980 981 982 983 984
  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
985

986 987 988 989
  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
990

991 992
  return x + MAX (width, 0);
}
Tim Janik's avatar
Tim Janik committed
993

994 995 996 997 998 999 1000 1001 1002
static void
get_cell_style (GtkCList     *clist,
		GtkCListRow  *clist_row,
		gint          state,
		gint          column,
		GtkStyle    **style,
		GdkGC       **fg_gc,
		GdkGC       **bg_gc)
{
1003 1004 1005 1006 1007 1008 1009 1010
  gint fg_state;

  if ((state == GTK_STATE_NORMAL) &&
      (GTK_WIDGET (clist)->state == GTK_STATE_INSENSITIVE))
    fg_state = GTK_STATE_INSENSITIVE;
  else
    fg_state = state;

1011 1012 1013 1014 1015
  if (clist_row->cell[column].style)
    {
      if (style)
	*style = clist_row->cell[column].style;
      if (fg_gc)
1016 1017 1018 1019 1020 1021 1022
	*fg_gc = clist_row->cell[column].style->fg_gc[fg_state];
      if (bg_gc) {
	if (state == GTK_STATE_SELECTED)
	  *bg_gc = clist_row->cell[column].style->bg_gc[state];
	else
	  *bg_gc = clist_row->cell[column].style->base_gc[state];
      }
1023 1024 1025 1026 1027 1028
    }
  else if (clist_row->style)
    {
      if (style)
	*style = clist_row->style;
      if (fg_gc)
1029 1030 1031 1032 1033 1034 1035
	*fg_gc = clist_row->style->fg_gc[fg_state];
      if (bg_gc) {
	if (state == GTK_STATE_SELECTED)
	  *bg_gc = clist_row->style->bg_gc[state];
	else
	  *bg_gc = clist_row->style->base_gc[state];
      }
1036 1037 1038 1039 1040 1041
    }
  else
    {
      if (style)
	*style = GTK_WIDGET (clist)->style;
      if (fg_gc)
1042 1043 1044 1045 1046 1047 1048
	*fg_gc = GTK_WIDGET (clist)->style->fg_gc[fg_state];
      if (bg_gc) {
	if (state == GTK_STATE_SELECTED)
	  *bg_gc = GTK_WIDGET (clist)->style->bg_gc[state];
	else
	  *bg_gc = GTK_WIDGET (clist)->style->base_gc[state];
      }
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058

      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
1059

1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
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
1071

1072 1073
 if (ctree->expander_style == GTK_CTREE_EXPANDER_NONE)
   return x;
Tim Janik's avatar
Tim Janik committed
1074

1075 1076 1077 1078 1079 1080 1081
  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
1082

1083
  if (!ctree_row->children)
Tim Janik's avatar
Tim Janik committed
1084
    {
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
      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
1095
    }
1096 1097 1098 1099 1100

  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
1101
    {
1102 1103 1104 1105
    case GTK_CTREE_EXPANDER_NONE:
      break;
    case GTK_CTREE_EXPANDER_TRIANGLE:
      if (ctree_row->expanded)
Tim Janik's avatar
Tim Janik committed
1106
	{
1107 1108 1109 1110 1111 1112 1113
	  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
1114 1115 1116
	}
      else
	{
1117 1118 1119 1120 1121 1122 1123
	  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
1124 1125
	}

1126 1127 1128 1129
      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
1130

1131 1132 1133 1134 1135 1136
      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
1137

1138 1139 1140 1141 1142 1143
      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
1144
	}