2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
4 * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
6 * Parts of this file from gtk/gtkctree.c and gtk/gtkclist.c:
7 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball, Josh MacDonald,
8 * Copyright (C) 1997-1998 Jay Painter <jpaint@serv.net><jpaint@gimp.org>
10 * Parts of this file from gtkflist.c:
11 * Copyright (C) 1999 The Free Software Foundation
12 * Author: Federico Mena <federico@nuclecu.unam.mx>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #include "gtksctree.h"
32 #include "claws-marshal.h"
33 #include "stock_pixmap.h"
34 #include "prefs_common.h"
37 #define CLIST_UNFROZEN(clist) (((GtkCMCList*) (clist))->freeze_count == 0)
38 #define CLIST_REFRESH(clist) G_STMT_START { \
39 if (CLIST_UNFROZEN (clist)) \
40 GTK_CMCLIST_GET_CLASS (clist)->refresh ((GtkCMCList*) (clist)); \
42 #define CELL_SPACING 1
43 #define CLIST_OPTIMUM_SIZE 64
44 #define COLUMN_INSET 3
46 #define TAB_SIZE (PM_SIZE + 6)
47 #define ROW_TOP_YPIXEL(clist, row) (((clist)->row_height * (row)) + \
48 (((row) + 1) * CELL_SPACING) + \
50 #define ROW_FROM_YPIXEL(clist, y) (((y) - (clist)->voffset) / \
51 ((clist)->row_height + CELL_SPACING))
52 #define COLUMN_LEFT_XPIXEL(clist, col) ((clist)->column[(col)].area.x \
54 #define COLUMN_LEFT(clist, column) ((clist)->column[(column)].area.x)
64 static GdkPixmap *emptyxpm = NULL;
65 static GdkBitmap *emptyxpmmask = NULL;
67 static void gtk_sctree_class_init (GtkSCTreeClass *class);
68 static void gtk_sctree_init (GtkSCTree *sctree);
70 static gint gtk_sctree_button_press (GtkWidget *widget, GdkEventButton *event);
71 static gint gtk_sctree_button_release (GtkWidget *widget, GdkEventButton *event);
72 static gint gtk_sctree_motion (GtkWidget *widget, GdkEventMotion *event);
73 static void gtk_sctree_drag_begin (GtkWidget *widget, GdkDragContext *context);
74 static void gtk_sctree_drag_end (GtkWidget *widget, GdkDragContext *context);
75 static void gtk_sctree_drag_data_get (GtkWidget *widget, GdkDragContext *context,
76 GtkSelectionData *data, guint info, guint time);
77 static void gtk_sctree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time);
78 static gboolean gtk_sctree_drag_motion (GtkWidget *widget, GdkDragContext *context,
79 gint x, gint y, guint time);
80 static gboolean gtk_sctree_drag_drop (GtkWidget *widget, GdkDragContext *context,
81 gint x, gint y, guint time);
82 static void gtk_sctree_drag_data_received (GtkWidget *widget, GdkDragContext *context,
83 gint x, gint y, GtkSelectionData *data,
84 guint info, guint time);
86 static void gtk_sctree_clear (GtkCMCList *clist);
87 static void gtk_sctree_real_unselect_all (GtkCMCList *clist);
88 static void gtk_sctree_collapse (GtkCMCTree *ctree, GtkCMCTreeNode *node);
90 static void stree_sort (GtkCMCTree *ctree, GtkCMCTreeNode *node, gpointer data);
91 void gtk_sctree_sort_node (GtkCMCTree *ctree, GtkCMCTreeNode *node);
92 void gtk_sctree_sort_recursive (GtkCMCTree *ctree, GtkCMCTreeNode *node);
94 static void gtk_sctree_link (GtkCMCTree *ctree,
96 GtkCMCTreeNode *parent,
97 GtkCMCTreeNode *sibling,
98 gboolean update_focus_row);
100 static void gtk_sctree_unlink (GtkCMCTree *ctree,
101 GtkCMCTreeNode *node,
102 gboolean update_focus_row);
104 static void stree_update_level (GtkCMCTree *ctree,
105 GtkCMCTreeNode *node,
108 static GtkCMCTreeNode * gtk_sctree_last_visible (GtkCMCTree *ctree,
109 GtkCMCTreeNode *node);
110 static void gtk_sctree_real_tree_expand (GtkCMCTree *ctree,
111 GtkCMCTreeNode *node);
113 sreal_tree_move (GtkCMCTree *ctree,
114 GtkCMCTreeNode *node,
115 GtkCMCTreeNode *new_parent,
116 GtkCMCTreeNode *new_sibling);
118 static GtkCMCTreeClass *parent_class;
120 static guint sctree_signals[LAST_SIGNAL];
123 * gtk_sctree_get_type:
126 * Creates the GtkSCTree class and its type information
128 * Return value: The type ID for GtkSCTreeClass
131 gtk_sctree_get_type (void)
133 static GType sctree_type = 0;
136 GTypeInfo sctree_info = {
137 sizeof (GtkSCTreeClass),
139 (GBaseInitFunc) NULL,
140 (GBaseFinalizeFunc) NULL,
142 (GClassInitFunc) gtk_sctree_class_init,
143 (GClassFinalizeFunc) NULL,
144 NULL, /* class_data */
148 (GInstanceInitFunc) gtk_sctree_init,
151 sctree_type = g_type_register_static (GTK_TYPE_CMCTREE, "GtkSCTree", &sctree_info, (GTypeFlags)0);
158 gtk_sctree_draw_cell_pixmap (GdkWindow *window,
159 GdkRectangle *clip_rectangle,
173 gdk_gc_set_clip_mask (fg_gc, mask);
174 gdk_gc_set_clip_origin (fg_gc, x, y);
176 if (x < clip_rectangle->x)
178 xsrc = clip_rectangle->x - x;
180 x = clip_rectangle->x;
182 if (x + width > clip_rectangle->x + clip_rectangle->width)
183 width = clip_rectangle->x + clip_rectangle->width - x;
185 if (y < clip_rectangle->y)
187 ysrc = clip_rectangle->y - y;
189 y = clip_rectangle->y;
191 if (y + height > clip_rectangle->y + clip_rectangle->height)
192 height = clip_rectangle->y + clip_rectangle->height - y;
194 if (width > 0 && height > 0)
195 gdk_draw_drawable (window, fg_gc, pixmap, xsrc, ysrc, x, y, width, height);
199 gdk_gc_set_clip_rectangle (fg_gc, NULL);
200 gdk_gc_set_clip_origin (fg_gc, 0, 0);
203 return x + MAX (width, 0);
207 gtk_sctree_get_cell_style (GtkCMCList *clist,
208 GtkCMCListRow *clist_row,
218 if ((state == GTK_STATE_NORMAL) &&
219 (GTK_WIDGET (clist)->state == GTK_STATE_INSENSITIVE))
220 fg_state = GTK_STATE_INSENSITIVE;
224 if (clist_row->cell[column].style)
227 *style = clist_row->cell[column].style;
229 *fg_gc = clist_row->cell[column].style->fg_gc[fg_state];
231 if (state == GTK_STATE_SELECTED)
232 *bg_gc = clist_row->cell[column].style->bg_gc[state];
235 else if (clist_row->style)
238 *style = clist_row->style;
240 *fg_gc = clist_row->style->fg_gc[fg_state];
242 if (state == GTK_STATE_SELECTED)
243 *bg_gc = clist_row->style->bg_gc[state];
245 *bg_gc = clist_row->bg_set ?
246 clist->bg_gc : clist_row->style->base_gc[state];
252 *style = GTK_WIDGET (clist)->style;
254 *fg_gc = GTK_WIDGET (clist)->style->fg_gc[fg_state];
256 if (state == GTK_STATE_SELECTED)
257 *bg_gc = GTK_WIDGET (clist)->style->bg_gc[state];
259 *bg_gc = GTK_WIDGET (clist)->style->base_gc[state];
262 if (state != GTK_STATE_SELECTED)
264 if (fg_gc && clist_row->fg_set)
265 *fg_gc = clist->fg_gc;
266 if (bg_gc && clist_row->bg_set)
267 *bg_gc = clist->bg_gc;
273 gtk_sctree_draw_expander (GtkCMCTree *ctree,
274 GtkCMCTreeRow *ctree_row,
276 GdkRectangle *clip_rectangle,
281 gint justification_factor;
284 if (ctree->expander_style == GTK_CMCTREE_EXPANDER_NONE)
287 clist = GTK_CMCLIST (ctree);
288 if (clist->column[ctree->tree_column].justification == GTK_JUSTIFY_RIGHT)
289 justification_factor = -1;
291 justification_factor = 1;
292 if (!GTK_CMCLIST_ROW_HEIGHT_SET(GTK_CMCLIST(clist)))
293 y = (clip_rectangle->y + (clip_rectangle->height - PM_SIZE) / 2 -
294 (clip_rectangle->height + 1) % 2);
296 y = (clip_rectangle->y + (clip_rectangle->height/2 - PM_SIZE) / 2 -
297 (clip_rectangle->height/2 + 1) % 2);
299 if (!ctree_row->children)
301 switch (ctree->expander_style)
303 case GTK_CMCTREE_EXPANDER_NONE:
305 case GTK_CMCTREE_EXPANDER_TRIANGLE:
306 return x + justification_factor * (PM_SIZE + 3);
307 case GTK_CMCTREE_EXPANDER_SQUARE:
308 case GTK_CMCTREE_EXPANDER_CIRCULAR:
309 return x + justification_factor * (PM_SIZE + 1);
313 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], clip_rectangle);
314 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], clip_rectangle);
316 switch (ctree->expander_style)
318 case GTK_CMCTREE_EXPANDER_NONE:
320 case GTK_CMCTREE_EXPANDER_TRIANGLE:
321 if (ctree_row->expanded)
324 points[0].y = y + (PM_SIZE + 2) / 6;
325 points[1].x = points[0].x + justification_factor * (PM_SIZE + 2);
326 points[1].y = points[0].y;
327 points[2].x = (points[0].x +
328 justification_factor * (PM_SIZE + 2) / 2);
329 points[2].y = y + 2 * (PM_SIZE + 2) / 3;
333 points[0].x = x + justification_factor * ((PM_SIZE + 2) / 6 + 2);
335 points[1].x = points[0].x;
336 points[1].y = points[0].y + (PM_SIZE + 2);
337 points[2].x = (points[0].x +
338 justification_factor * (2 * (PM_SIZE + 2) / 3 - 1));
339 points[2].y = points[0].y + (PM_SIZE + 2) / 2;
342 gdk_draw_polygon (clist->clist_window, style->base_gc[GTK_STATE_NORMAL],
344 gdk_draw_polygon (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
347 x += justification_factor * (PM_SIZE + 3);
349 case GTK_CMCTREE_EXPANDER_SQUARE:
350 case GTK_CMCTREE_EXPANDER_CIRCULAR:
351 if (justification_factor == -1)
352 x += justification_factor * (PM_SIZE + 1);
354 if (ctree->expander_style == GTK_CMCTREE_EXPANDER_CIRCULAR)
356 gdk_draw_arc (clist->clist_window, style->base_gc[GTK_STATE_NORMAL],
357 TRUE, x, y, PM_SIZE, PM_SIZE, 0, 360 * 64);
358 gdk_draw_arc (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
359 FALSE, x, y, PM_SIZE, PM_SIZE, 0, 360 * 64);
363 gdk_draw_rectangle (clist->clist_window,
364 style->base_gc[GTK_STATE_NORMAL], TRUE,
365 x, y, PM_SIZE, PM_SIZE);
366 gdk_draw_rectangle (clist->clist_window,
367 style->fg_gc[GTK_STATE_NORMAL], FALSE,
368 x, y, PM_SIZE, PM_SIZE);
371 gdk_draw_line (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
372 x + 2, y + PM_SIZE / 2, x + PM_SIZE - 2, y + PM_SIZE / 2);
374 if (!ctree_row->expanded)
375 gdk_draw_line (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
376 x + PM_SIZE / 2, y + 2,
377 x + PM_SIZE / 2, y + PM_SIZE - 2);
379 if (justification_factor == 1)
380 x += justification_factor * (PM_SIZE + 1);
384 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
385 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
391 gtk_sctree_draw_lines (GtkCMCTree *ctree,
392 GtkCMCTreeRow *ctree_row,
396 GdkRectangle *clip_rectangle,
397 GdkRectangle *cell_rectangle,
403 GtkCMCTreeNode *node;
404 GtkCMCTreeNode *parent;
405 GdkRectangle tree_rectangle;
406 GdkRectangle tc_rectangle;
417 gint justification_factor;
419 clist = GTK_CMCLIST (ctree);
420 ycenter = clip_rectangle->y + (clip_rectangle->height / 2);
421 justify_right = (clist->column[column].justification == GTK_JUSTIFY_RIGHT);
425 offset = (clip_rectangle->x + clip_rectangle->width - 1 -
426 ctree->tree_indent * (ctree_row->level - 1));
427 justification_factor = -1;
431 offset = clip_rectangle->x + ctree->tree_indent * (ctree_row->level - 1);
432 justification_factor = 1;
435 switch (ctree->line_style)
437 case GTK_CMCTREE_LINES_NONE:
439 case GTK_CMCTREE_LINES_TABBED:
440 xcenter = offset + justification_factor * TAB_SIZE;
442 column_right = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) +
443 clist->column[ctree->tree_column].area.width +
445 column_left = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) -
446 COLUMN_INSET - CELL_SPACING);
450 tree_rectangle.y = crect->y;
451 tree_rectangle.height = crect->height;
455 tree_rectangle.x = xcenter;
456 tree_rectangle.width = column_right - xcenter;
460 tree_rectangle.x = column_left;
461 tree_rectangle.width = xcenter - column_left;
464 if (!gdk_rectangle_intersect (area, &tree_rectangle, &tc_rectangle))
466 offset += justification_factor * 3;
471 gdk_gc_set_clip_rectangle (ctree->lines_gc, crect);
473 next_level = ctree_row->level;
475 if (!ctree_row->sibling || (ctree_row->children && ctree_row->expanded))
477 node = gtk_cmctree_find_node_ptr (ctree, ctree_row);
478 if (GTK_CMCTREE_NODE_NEXT (node))
479 next_level = GTK_CMCTREE_ROW (GTK_CMCTREE_NODE_NEXT (node))->level;
484 if (ctree->tree_indent > 0)
486 node = ctree_row->parent;
489 xcenter -= (justification_factor * ctree->tree_indent);
491 if ((justify_right && xcenter < column_left) ||
492 (!justify_right && xcenter > column_right))
494 node = GTK_CMCTREE_ROW (node)->parent;
498 tree_rectangle.y = cell_rectangle->y;
499 tree_rectangle.height = cell_rectangle->height;
502 tree_rectangle.x = MAX (xcenter - ctree->tree_indent + 1,
504 tree_rectangle.width = MIN (xcenter - column_left,
509 tree_rectangle.x = xcenter;
510 tree_rectangle.width = MIN (column_right - xcenter,
514 if (!area || gdk_rectangle_intersect (area, &tree_rectangle,
517 gtk_sctree_get_cell_style (clist, >K_CMCTREE_ROW (node)->row,
518 state, row, column, NULL, NULL, &bg_gc);
520 if (bg_gc == clist->bg_gc)
521 gdk_gc_set_foreground
522 (clist->bg_gc, >K_CMCTREE_ROW (node)->row.background);
525 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
528 tree_rectangle.width,
529 tree_rectangle.height);
531 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
535 tc_rectangle.height);
537 if (next_level > GTK_CMCTREE_ROW (node)->level)
538 gdk_draw_line (clist->clist_window, ctree->lines_gc,
540 xcenter, crect->y + crect->height);
545 offset_x = MIN (ctree->tree_indent, 2 * TAB_SIZE);
546 width = offset_x / 2 + offset_x % 2;
548 parent = GTK_CMCTREE_ROW (node)->parent;
550 tree_rectangle.y = ycenter;
551 tree_rectangle.height = (cell_rectangle->y - ycenter +
552 cell_rectangle->height);
556 tree_rectangle.x = MAX(xcenter + 1 - width, column_left);
557 tree_rectangle.width = MIN (xcenter + 1 - column_left,
562 tree_rectangle.x = xcenter;
563 tree_rectangle.width = MIN (column_right - xcenter,
568 gdk_rectangle_intersect (area, &tree_rectangle,
573 gtk_sctree_get_cell_style (clist, >K_CMCTREE_ROW (parent)->row,
574 state, row, column, NULL, NULL, &bg_gc);
575 if (bg_gc == clist->bg_gc)
576 gdk_gc_set_foreground
578 >K_CMCTREE_ROW (parent)->row.background);
580 else if (state == GTK_STATE_SELECTED)
581 bg_gc = style->base_gc[state];
583 bg_gc = GTK_WIDGET (clist)->style->base_gc[state];
586 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
589 tree_rectangle.width,
590 tree_rectangle.height);
592 gdk_draw_rectangle (clist->clist_window,
597 tc_rectangle.height);
600 gtk_sctree_get_cell_style (clist, >K_CMCTREE_ROW (node)->row,
601 state, row, column, NULL, NULL, &bg_gc);
602 if (bg_gc == clist->bg_gc)
603 gdk_gc_set_foreground
604 (clist->bg_gc, >K_CMCTREE_ROW (node)->row.background);
606 gdk_gc_set_clip_rectangle (bg_gc, crect);
607 gdk_draw_arc (clist->clist_window, bg_gc, TRUE,
608 xcenter - (justify_right * offset_x),
610 offset_x, clist->row_height,
611 (180 + (justify_right * 90)) * 64, 90 * 64);
612 gdk_gc_set_clip_rectangle (bg_gc, NULL);
614 gdk_draw_line (clist->clist_window, ctree->lines_gc,
615 xcenter, cell_rectangle->y, xcenter, ycenter);
618 gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
619 xcenter - offset_x, cell_rectangle->y,
620 offset_x, clist->row_height,
623 gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
624 xcenter, cell_rectangle->y,
625 offset_x, clist->row_height,
628 node = GTK_CMCTREE_ROW (node)->parent;
632 if (state != GTK_STATE_SELECTED)
634 tree_rectangle.y = clip_rectangle->y;
635 tree_rectangle.height = clip_rectangle->height;
636 tree_rectangle.width = COLUMN_INSET + CELL_SPACING +
637 MIN (clist->column[ctree->tree_column].area.width + COLUMN_INSET,
641 tree_rectangle.x = MAX (xcenter + 1, column_left);
643 tree_rectangle.x = column_left;
646 gdk_draw_rectangle (clist->clist_window,
648 (ctree)->style->base_gc[GTK_STATE_NORMAL],
652 tree_rectangle.width,
653 tree_rectangle.height);
654 else if (gdk_rectangle_intersect (area, &tree_rectangle,
656 gdk_draw_rectangle (clist->clist_window,
658 (ctree)->style->base_gc[GTK_STATE_NORMAL],
663 tc_rectangle.height);
666 xcenter = offset + (justification_factor * ctree->tree_indent / 2);
668 gtk_sctree_get_cell_style (clist, &ctree_row->row, state, row, column, NULL, NULL,
670 if (bg_gc == clist->bg_gc)
671 gdk_gc_set_foreground (clist->bg_gc, &ctree_row->row.background);
673 gdk_gc_set_clip_rectangle (bg_gc, crect);
674 if (ctree_row->is_leaf)
678 points[0].x = offset + justification_factor * TAB_SIZE;
679 points[0].y = cell_rectangle->y;
681 points[1].x = points[0].x - justification_factor * 4;
682 points[1].y = points[0].y;
684 points[2].x = points[1].x - justification_factor * 2;
685 points[2].y = points[1].y + 3;
687 points[3].x = points[2].x;
688 points[3].y = points[2].y + clist->row_height - 5;
690 points[4].x = points[3].x + justification_factor * 2;
691 points[4].y = points[3].y + 3;
693 points[5].x = points[4].x + justification_factor * 4;
694 points[5].y = points[4].y;
696 gdk_draw_polygon (clist->clist_window, bg_gc, TRUE, points, 6);
697 gdk_draw_lines (clist->clist_window, ctree->lines_gc, points, 6);
701 gdk_draw_arc (clist->clist_window, bg_gc, TRUE,
702 offset - (justify_right * 2 * TAB_SIZE),
704 2 * TAB_SIZE, clist->row_height,
705 (90 + (180 * justify_right)) * 64, 180 * 64);
706 gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
707 offset - (justify_right * 2 * TAB_SIZE),
709 2 * TAB_SIZE, clist->row_height,
710 (90 + (180 * justify_right)) * 64, 180 * 64);
712 gdk_gc_set_clip_rectangle (bg_gc, NULL);
713 gdk_gc_set_clip_rectangle (ctree->lines_gc, NULL);
715 offset += justification_factor * 3;
718 xcenter = offset + justification_factor * PM_SIZE / 2;
722 tree_rectangle.y = crect->y;
723 tree_rectangle.height = crect->height;
727 tree_rectangle.x = xcenter - PM_SIZE / 2 - 2;
728 tree_rectangle.width = (clip_rectangle->x +
729 clip_rectangle->width -tree_rectangle.x);
733 tree_rectangle.x = clip_rectangle->x + PM_SIZE / 2;
734 tree_rectangle.width = (xcenter + PM_SIZE / 2 + 2 -
738 if (!gdk_rectangle_intersect (area, &tree_rectangle, &tc_rectangle))
744 if (ctree->line_style == GTK_CMCTREE_LINES_DOTTED)
746 offset_x += abs((clip_rectangle->x + clist->hoffset) % 2);
747 offset_y = abs((cell_rectangle->y + clist->voffset) % 2);
751 clip_rectangle->height++;
752 gdk_gc_set_clip_rectangle (ctree->lines_gc, clip_rectangle);
753 gdk_draw_line (clist->clist_window, ctree->lines_gc,
755 (ctree->show_stub || clist->row_list->data != ctree_row) ?
756 cell_rectangle->y + offset_y : ycenter,
758 (ctree_row->sibling) ? crect->y +crect->height : ycenter);
760 gdk_draw_line (clist->clist_window, ctree->lines_gc,
761 xcenter + (justification_factor * offset_x), ycenter,
762 xcenter + (justification_factor * (PM_SIZE / 2 + 2)),
765 node = ctree_row->parent;
768 xcenter -= (justification_factor * ctree->tree_indent);
770 if (GTK_CMCTREE_ROW (node)->sibling)
771 gdk_draw_line (clist->clist_window, ctree->lines_gc,
772 xcenter, cell_rectangle->y + offset_y,
773 xcenter, crect->y + crect->height);
774 node = GTK_CMCTREE_ROW (node)->parent;
776 gdk_gc_set_clip_rectangle (ctree->lines_gc, NULL);
778 clip_rectangle->height--;
784 static gboolean filter_fg (PangoAttribute *attribute, gpointer data)
786 const PangoAttrClass *klass = attribute->klass;
787 if (klass->type == PANGO_ATTR_FOREGROUND)
794 sc_gtk_cmclist_create_cell_layout (GtkCMCList *clist,
795 GtkCMCListRow *clist_row,
803 gtk_sctree_get_cell_style (clist, clist_row, GTK_STATE_NORMAL, 0, column, &style,
807 cell = &clist_row->cell[column];
810 case GTK_CMCELL_TEXT:
811 case GTK_CMCELL_PIXTEXT:
812 text = ((cell->type == GTK_CMCELL_PIXTEXT) ?
813 GTK_CMCELL_PIXTEXT (*cell)->text :
814 GTK_CMCELL_TEXT (*cell)->text);
819 if (!GTK_SCTREE(clist)->use_markup[column]) {
820 layout = gtk_widget_create_pango_layout (GTK_WIDGET (clist),
821 ((cell->type == GTK_CMCELL_PIXTEXT) ?
822 GTK_CMCELL_PIXTEXT (*cell)->text :
823 GTK_CMCELL_TEXT (*cell)->text));
824 pango_layout_set_font_description (layout, style->font_desc);
826 PangoContext *context = gtk_widget_get_pango_context (GTK_WIDGET(clist));
827 layout = pango_layout_new (context);
828 pango_layout_set_markup (layout, text, -1);
829 pango_layout_set_font_description (layout, style->font_desc);
830 if (clist_row->state == GTK_STATE_SELECTED) {
831 /* for selected row, we should remove any forced foreground color
832 * or it looks like shit */
833 PangoAttrList *list = pango_layout_get_attributes(layout);
834 PangoAttrList *rem = pango_attr_list_filter(list, filter_fg, NULL);
836 pango_attr_list_unref(rem);
848 gtk_sctree_draw_row (GtkCMCList *clist,
851 GtkCMCListRow *clist_row)
857 GdkRectangle row_rectangle;
858 GdkRectangle cell_rectangle;
859 GdkRectangle clip_rectangle;
860 GdkRectangle intersect_rectangle;
862 gint column_left = 0;
863 gint column_right = 0;
867 static GdkColor greybg={0, 0, 0, 0};
868 static gboolean color_change = TRUE;
870 if (greybg.pixel == 0 &&
874 GdkColor normalbg = {0, 0xffff, 0xffff, 0xffff};
875 if (GTK_WIDGET (clist)->style) {
876 normalbg = GTK_WIDGET (clist)->style->base[GTK_STATE_NORMAL];
878 if (normalbg.red > 0x8888 && normalbg.green > 0x8888 && normalbg.blue > 0x8888) {
879 greybg.pixel = normalbg.pixel;
880 greybg.red = normalbg.red - prefs_common.stripes_color_offset;
881 greybg.green = normalbg.green - prefs_common.stripes_color_offset;
882 greybg.blue = normalbg.blue - prefs_common.stripes_color_offset;
883 } else if (normalbg.red < 0x8888 && normalbg.green < 0x8888 && normalbg.blue < 0x8888) {
884 greybg.pixel = normalbg.pixel;
885 greybg.red = normalbg.red + prefs_common.stripes_color_offset;
886 greybg.green = normalbg.green + prefs_common.stripes_color_offset;
887 greybg.blue = normalbg.blue + prefs_common.stripes_color_offset;
889 color_change = FALSE;
893 g_return_if_fail (clist != NULL);
895 /* bail now if we arn't drawable yet */
896 if (!GTK_WIDGET_DRAWABLE (clist) || row < 0 || row >= clist->rows)
899 widget = GTK_WIDGET (clist);
900 ctree = GTK_CMCTREE (clist);
902 /* if the function is passed the pointer to the row instead of null,
903 * it avoids this expensive lookup */
905 clist_row = (g_list_nth (clist->row_list, row))->data;
907 /* rectangle of the entire row */
909 row_rectangle.y = ROW_TOP_YPIXEL (clist, row);
910 row_rectangle.width = clist->clist_window_width;
911 row_rectangle.height = clist->row_height;
913 /* rectangle of the cell spacing above the row */
914 cell_rectangle.x = 0;
915 cell_rectangle.y = row_rectangle.y - CELL_SPACING;
916 cell_rectangle.width = row_rectangle.width;
917 cell_rectangle.height = CELL_SPACING;
919 /* rectangle used to clip drawing operations, its y and height
920 * positions only need to be set once, so we set them once here.
921 * the x and width are set withing the drawing loop below once per
923 clip_rectangle.y = row_rectangle.y;
924 clip_rectangle.height = row_rectangle.height;
926 if (prefs_common.use_stripes_everywhere && GTK_SCTREE(ctree)->show_stripes
927 && color_change && row % 2) {
928 clist_row->background = greybg;
929 clist_row->bg_set = TRUE;
931 clist_row->bg_set = FALSE;
933 if (clist_row->state == GTK_STATE_NORMAL)
935 if (clist_row->fg_set)
936 gdk_gc_set_foreground (clist->fg_gc, &clist_row->foreground);
937 if (clist_row->bg_set)
938 gdk_gc_set_rgb_fg_color (clist->bg_gc, &clist_row->background);
941 state = clist_row->state;
943 gdk_gc_set_foreground (ctree->lines_gc,
944 &widget->style->fg[clist_row->state]);
946 /* draw the cell borders */
949 rect = &intersect_rectangle;
950 crect = &intersect_rectangle;
952 if (gdk_rectangle_intersect (area, &cell_rectangle, crect))
953 gdk_draw_rectangle (clist->clist_window,
954 widget->style->base_gc[GTK_STATE_NORMAL], TRUE,
955 crect->x, crect->y, crect->width, crect->height);
959 rect = &clip_rectangle;
960 crect = &cell_rectangle;
962 gdk_draw_rectangle (clist->clist_window,
963 widget->style->base_gc[GTK_STATE_NORMAL], TRUE,
964 crect->x, crect->y, crect->width, crect->height);
967 /* horizontal black lines */
968 if (ctree->line_style == GTK_CMCTREE_LINES_TABBED)
971 column_right = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) +
972 clist->column[ctree->tree_column].area.width +
974 column_left = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) -
975 COLUMN_INSET - (ctree->tree_column != 0) * CELL_SPACING);
977 switch (clist->column[ctree->tree_column].justification)
979 case GTK_JUSTIFY_CENTER:
980 case GTK_JUSTIFY_FILL:
981 case GTK_JUSTIFY_LEFT:
982 offset = (column_left + ctree->tree_indent *
983 (((GtkCMCTreeRow *)clist_row)->level - 1));
985 gdk_draw_line (clist->clist_window, ctree->lines_gc,
986 MIN (offset + TAB_SIZE, column_right),
988 clist->clist_window_width, cell_rectangle.y);
990 case GTK_JUSTIFY_RIGHT:
991 offset = (column_right - 1 - ctree->tree_indent *
992 (((GtkCMCTreeRow *)clist_row)->level - 1));
994 gdk_draw_line (clist->clist_window, ctree->lines_gc,
995 -1, cell_rectangle.y,
996 MAX (offset - TAB_SIZE, column_left),
1002 /* the last row has to clear its bottom cell spacing too */
1003 if (clist_row == clist->row_list_end->data)
1005 cell_rectangle.y += clist->row_height + CELL_SPACING;
1007 if (!area || gdk_rectangle_intersect (area, &cell_rectangle, crect))
1009 gdk_draw_rectangle (clist->clist_window,
1010 widget->style->base_gc[GTK_STATE_NORMAL], TRUE,
1011 crect->x, crect->y, crect->width, crect->height);
1013 /* horizontal black lines */
1014 if (ctree->line_style == GTK_CMCTREE_LINES_TABBED)
1016 switch (clist->column[ctree->tree_column].justification)
1018 case GTK_JUSTIFY_CENTER:
1019 case GTK_JUSTIFY_FILL:
1020 case GTK_JUSTIFY_LEFT:
1021 gdk_draw_line (clist->clist_window, ctree->lines_gc,
1022 MIN (column_left + TAB_SIZE + COLUMN_INSET +
1023 (((GtkCMCTreeRow *)clist_row)->level > 1) *
1024 MIN (ctree->tree_indent / 2, TAB_SIZE),
1027 clist->clist_window_width, cell_rectangle.y);
1029 case GTK_JUSTIFY_RIGHT:
1030 gdk_draw_line (clist->clist_window, ctree->lines_gc,
1031 -1, cell_rectangle.y,
1032 MAX (column_right - TAB_SIZE - 1 -
1034 (((GtkCMCTreeRow *)clist_row)->level > 1) *
1035 MIN (ctree->tree_indent / 2, TAB_SIZE),
1036 column_left - 1), cell_rectangle.y);
1043 for (last_column = clist->columns - 1;
1044 last_column >= 0 && !clist->column[last_column].visible; last_column--)
1047 /* iterate and draw all the columns (row cells) and draw their contents */
1048 for (i = 0; i < clist->columns; i++)
1053 PangoLayout *layout = NULL;
1054 PangoRectangle logical_rect;
1062 if (!clist->column[i].visible)
1065 gtk_sctree_get_cell_style (clist, clist_row, state, row, i, &style, &fg_gc, &bg_gc);
1067 /* calculate clipping region */
1068 clip_rectangle.x = clist->column[i].area.x + clist->hoffset;
1069 clip_rectangle.width = clist->column[i].area.width;
1071 cell_rectangle.x = clip_rectangle.x - COLUMN_INSET - CELL_SPACING;
1072 cell_rectangle.width = (clip_rectangle.width + 2 * COLUMN_INSET +
1073 (1 + (i == last_column)) * CELL_SPACING);
1074 cell_rectangle.y = clip_rectangle.y;
1075 cell_rectangle.height = clip_rectangle.height;
1080 if (area && !gdk_rectangle_intersect (area, &cell_rectangle,
1081 &intersect_rectangle))
1083 if (i != ctree->tree_column)
1088 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
1089 crect->x, crect->y, crect->width, crect->height);
1092 layout = sc_gtk_cmclist_create_cell_layout (clist, clist_row, i);
1095 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1096 width = logical_rect.width;
1101 switch (clist_row->cell[i].type)
1103 case GTK_CMCELL_PIXMAP:
1104 gdk_drawable_get_size
1105 (GTK_CMCELL_PIXMAP (clist_row->cell[i])->pixmap, &pixmap_width,
1107 width += pixmap_width;
1109 case GTK_CMCELL_PIXTEXT:
1110 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixmap)
1112 gdk_drawable_get_size
1113 (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixmap,
1114 &pixmap_width, &height);
1115 width += pixmap_width;
1118 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->text &&
1119 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixmap)
1120 width += GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1122 if (i == ctree->tree_column)
1123 width += (ctree->tree_indent *
1124 ((GtkCMCTreeRow *)clist_row)->level);
1130 switch (clist->column[i].justification)
1132 case GTK_JUSTIFY_LEFT:
1133 offset = clip_rectangle.x + clist_row->cell[i].horizontal;
1135 case GTK_JUSTIFY_RIGHT:
1136 offset = (clip_rectangle.x + clist_row->cell[i].horizontal +
1137 clip_rectangle.width - width);
1139 case GTK_JUSTIFY_CENTER:
1140 case GTK_JUSTIFY_FILL:
1141 offset = (clip_rectangle.x + clist_row->cell[i].horizontal +
1142 (clip_rectangle.width / 2) - (width / 2));
1146 if (i != ctree->tree_column)
1148 int start_y = (clip_rectangle.height - height) / 2;
1149 if (GTK_CMCLIST_ROW_HEIGHT_SET(GTK_CMCLIST(clist)))
1150 start_y = (clip_rectangle.height/2 - height) / 2;
1152 offset += clist_row->cell[i].horizontal;
1153 switch (clist_row->cell[i].type)
1155 case GTK_CMCELL_PIXMAP:
1156 gtk_sctree_draw_cell_pixmap
1157 (clist->clist_window, &clip_rectangle, fg_gc,
1158 GTK_CMCELL_PIXMAP (clist_row->cell[i])->pixmap,
1159 GTK_CMCELL_PIXMAP (clist_row->cell[i])->mask,
1161 clip_rectangle.y + clist_row->cell[i].vertical +
1163 pixmap_width, height);
1165 case GTK_CMCELL_PIXTEXT:
1166 offset = gtk_sctree_draw_cell_pixmap
1167 (clist->clist_window, &clip_rectangle, fg_gc,
1168 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixmap,
1169 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->mask,
1171 clip_rectangle.y + clist_row->cell[i].vertical +
1173 pixmap_width, height);
1174 offset += GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1177 case GTK_CMCELL_TEXT:
1180 gint row_center_offset = (clist->row_height - logical_rect.height) / 2;
1182 gdk_gc_set_clip_rectangle (fg_gc, &clip_rectangle);
1183 gdk_draw_layout (clist->clist_window, fg_gc,
1185 row_rectangle.y + row_center_offset + clist_row->cell[i].vertical,
1187 gdk_gc_set_clip_rectangle (fg_gc, NULL);
1188 g_object_unref (G_OBJECT (layout));
1198 if (bg_gc == clist->bg_gc)
1199 gdk_gc_set_background (ctree->lines_gc, &clist_row->background);
1201 /* draw ctree->tree_column */
1202 cell_rectangle.y -= CELL_SPACING;
1203 cell_rectangle.height += CELL_SPACING;
1205 if (area && !gdk_rectangle_intersect (area, &cell_rectangle,
1206 &intersect_rectangle))
1209 g_object_unref (G_OBJECT (layout));
1214 offset = gtk_sctree_draw_lines (ctree, (GtkCMCTreeRow *)clist_row, row, i,
1215 state, &clip_rectangle, &cell_rectangle,
1216 crect, area, style);
1219 offset = gtk_sctree_draw_expander (ctree, (GtkCMCTreeRow *)clist_row,
1220 style, &clip_rectangle, offset);
1222 if (clist->column[i].justification == GTK_JUSTIFY_RIGHT)
1223 offset -= ctree->tree_spacing;
1225 offset += ctree->tree_spacing;
1227 if (clist->column[i].justification == GTK_JUSTIFY_RIGHT)
1228 offset -= (pixmap_width + clist_row->cell[i].horizontal);
1230 offset += clist_row->cell[i].horizontal;
1232 old_offset = offset;
1233 offset = gtk_sctree_draw_cell_pixmap (clist->clist_window, &clip_rectangle, fg_gc,
1234 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixmap,
1235 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->mask,
1237 clip_rectangle.y + clist_row->cell[i].vertical
1238 + (clip_rectangle.height - height) / 2,
1239 pixmap_width, height);
1243 gint row_center_offset = (clist->row_height - logical_rect.height) / 2;
1245 if (clist->column[i].justification == GTK_JUSTIFY_RIGHT)
1247 offset = (old_offset - string_width);
1248 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixmap)
1249 offset -= GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1253 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixmap)
1254 offset += GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1257 gdk_gc_set_clip_rectangle (fg_gc, &clip_rectangle);
1258 gdk_draw_layout (clist->clist_window, fg_gc,
1260 row_rectangle.y + row_center_offset + clist_row->cell[i].vertical,
1263 g_object_unref (G_OBJECT (layout));
1265 gdk_gc_set_clip_rectangle (fg_gc, NULL);
1268 /* draw focus rectangle */
1269 if (clist->focus_row == row &&
1270 GTK_WIDGET_CAN_FOCUS (widget) && GTK_WIDGET_HAS_FOCUS (widget))
1273 gdk_draw_rectangle (clist->clist_window, clist->xor_gc, FALSE,
1274 row_rectangle.x, row_rectangle.y,
1275 row_rectangle.width - 1, row_rectangle.height - 1);
1276 else if (gdk_rectangle_intersect (area, &row_rectangle,
1277 &intersect_rectangle))
1279 gdk_gc_set_clip_rectangle (clist->xor_gc, &intersect_rectangle);
1280 gdk_draw_rectangle (clist->clist_window, clist->xor_gc, FALSE,
1281 row_rectangle.x, row_rectangle.y,
1282 row_rectangle.width - 1,
1283 row_rectangle.height - 1);
1284 gdk_gc_set_clip_rectangle (clist->xor_gc, NULL);
1290 gtk_sctree_change_focus_row_expansion (GtkCMCTree *ctree,
1291 GtkCMCTreeExpansionType action)
1294 GtkCMCTreeNode *node;
1296 g_return_if_fail (GTK_IS_CMCTREE (ctree));
1298 clist = GTK_CMCLIST (ctree);
1300 if (gdk_display_pointer_is_grabbed (gtk_widget_get_display (GTK_WIDGET (ctree))) &&
1301 GTK_WIDGET_HAS_GRAB (ctree))
1305 GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row))) ||
1306 GTK_CMCTREE_ROW (node)->is_leaf || !(GTK_CMCTREE_ROW (node)->children))
1311 case GTK_CMCTREE_EXPANSION_EXPAND:
1312 if (GTK_SCTREE(ctree)->always_expand_recursively)
1313 gtk_cmctree_expand_recursive (ctree, node);
1315 gtk_cmctree_expand (ctree, node);
1318 case GTK_CMCTREE_EXPANSION_EXPAND_RECURSIVE:
1319 gtk_cmctree_expand_recursive (ctree, node);
1321 case GTK_CMCTREE_EXPANSION_COLLAPSE:
1322 gtk_cmctree_collapse (ctree, node);
1324 case GTK_CMCTREE_EXPANSION_COLLAPSE_RECURSIVE:
1325 gtk_cmctree_collapse_recursive (ctree, node);
1327 case GTK_CMCTREE_EXPANSION_TOGGLE:
1328 if (GTK_SCTREE(ctree)->always_expand_recursively)
1329 gtk_cmctree_toggle_expansion_recursive (ctree, node);
1331 gtk_cmctree_toggle_expansion (ctree, node);
1333 case GTK_CMCTREE_EXPANSION_TOGGLE_RECURSIVE:
1334 gtk_cmctree_toggle_expansion_recursive (ctree, node);
1339 static void gtk_sctree_finalize(GObject *object)
1341 GtkSCTree *sctree = GTK_SCTREE(object);
1342 g_free(sctree->use_markup);
1343 sctree->use_markup = NULL;
1344 G_OBJECT_CLASS (parent_class)->finalize (object);
1347 /* Standard class initialization function */
1349 gtk_sctree_class_init (GtkSCTreeClass *klass)
1351 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1352 GtkObjectClass *object_class;
1353 GtkWidgetClass *widget_class;
1354 GtkCMCListClass *clist_class;
1355 GtkCMCTreeClass *ctree_class;
1357 object_class = (GtkObjectClass *) klass;
1358 widget_class = (GtkWidgetClass *) klass;
1359 clist_class = (GtkCMCListClass *) klass;
1360 ctree_class = (GtkCMCTreeClass *) klass;
1362 parent_class = gtk_type_class (gtk_cmctree_get_type ());
1364 sctree_signals[ROW_POPUP_MENU] =
1365 g_signal_new ("row_popup_menu",
1366 G_TYPE_FROM_CLASS (klass),
1368 G_STRUCT_OFFSET (GtkSCTreeClass, row_popup_menu),
1370 claws_marshal_VOID__POINTER,
1373 sctree_signals[EMPTY_POPUP_MENU] =
1374 g_signal_new ("empty_popup_menu",
1375 G_TYPE_FROM_CLASS (klass),
1377 G_STRUCT_OFFSET (GtkSCTreeClass, empty_popup_menu),
1379 claws_marshal_VOID__POINTER,
1382 sctree_signals[OPEN_ROW] =
1383 g_signal_new ("open_row",
1384 G_TYPE_FROM_CLASS (klass),
1386 G_STRUCT_OFFSET (GtkSCTreeClass, open_row),
1388 g_cclosure_marshal_VOID__VOID,
1390 sctree_signals[START_DRAG] =
1391 g_signal_new ("start_drag",
1392 G_TYPE_FROM_CLASS (klass),
1394 G_STRUCT_OFFSET (GtkSCTreeClass, start_drag),
1396 claws_marshal_VOID__INT_POINTER,
1401 /* gtk_object_class_add_signals (object_class, sctree_signals, LAST_SIGNAL); */
1403 clist_class->clear = gtk_sctree_clear;
1404 clist_class->draw_row = gtk_sctree_draw_row;
1405 clist_class->unselect_all = gtk_sctree_real_unselect_all;
1406 ctree_class->tree_collapse = gtk_sctree_collapse;
1407 ctree_class->tree_expand = gtk_sctree_real_tree_expand;
1408 ctree_class->tree_move = sreal_tree_move;
1409 ctree_class->change_focus_row_expansion = gtk_sctree_change_focus_row_expansion;
1411 widget_class->button_press_event = gtk_sctree_button_press;
1412 widget_class->button_release_event = gtk_sctree_button_release;
1413 widget_class->motion_notify_event = gtk_sctree_motion;
1414 widget_class->drag_begin = gtk_sctree_drag_begin;
1415 widget_class->drag_end = gtk_sctree_drag_end;
1416 widget_class->drag_data_get = gtk_sctree_drag_data_get;
1417 widget_class->drag_leave = gtk_sctree_drag_leave;
1418 widget_class->drag_motion = gtk_sctree_drag_motion;
1419 widget_class->drag_drop = gtk_sctree_drag_drop;
1420 widget_class->drag_data_received = gtk_sctree_drag_data_received;
1422 gobject_class->finalize = gtk_sctree_finalize;
1425 /* Standard object initialization function */
1427 gtk_sctree_init (GtkSCTree *sctree)
1429 sctree->anchor_row = NULL;
1431 /* GtkCMCTree does not specify pointer motion by default */
1432 gtk_widget_add_events (GTK_WIDGET (sctree), GDK_POINTER_MOTION_MASK);
1433 gtk_widget_add_events (GTK_WIDGET (sctree), GDK_POINTER_MOTION_MASK);
1436 /* Get information the specified row is selected. */
1439 row_is_selected(GtkSCTree *sctree, gint row)
1441 GtkCMCListRow *clist_row;
1442 clist_row = g_list_nth (GTK_CMCLIST(sctree)->row_list, row)->data;
1443 return clist_row ? clist_row->state == GTK_STATE_SELECTED : FALSE;
1446 /* Selects the rows between the anchor to the specified row, inclusive. */
1448 select_range (GtkSCTree *sctree, gint row)
1454 if (sctree->anchor_row == NULL) {
1456 sctree->anchor_row = gtk_cmctree_node_nth(GTK_CMCTREE(sctree), row);
1458 prev_row = g_list_position(GTK_CMCLIST(sctree)->row_list,
1459 (GList *)sctree->anchor_row);
1461 if (row < prev_row) {
1464 GTK_CMCLIST(sctree)->focus_row = max;
1469 sctree->selecting_range++;
1478 gtk_cmclist_freeze(GTK_CMCLIST(sctree));
1480 node = g_list_nth((GTK_CMCLIST(sctree))->row_list, min);
1481 for (i = min; i < max; i++) {
1482 if (node && GTK_CMCTREE_ROW (node)->row.selectable) {
1483 g_signal_emit_by_name(G_OBJECT(sctree), "tree_select_row",
1489 gtk_cmclist_thaw(GTK_CMCLIST(sctree));
1492 sctree->selecting_range--;
1493 gtk_cmclist_select_row (GTK_CMCLIST (sctree), max, -1);
1496 /* Handles row selection according to the specified modifier state */
1497 /* in certain cases, we arrive here from a function knowing the GtkCMCTreeNode, and having
1498 * already slowly found row using g_list_position. In which case, _node will be non-NULL
1499 * to avoid this function having to slowly find it with g_list_nth. */
1501 select_row (GtkSCTree *sctree, gint row, gint col, guint state, GtkCMCTreeNode *_node)
1503 gboolean range, additive;
1504 g_return_if_fail (sctree != NULL);
1505 g_return_if_fail (GTK_IS_SCTREE (sctree));
1507 range = ((state & GDK_SHIFT_MASK) != 0) &&
1508 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_SINGLE) &&
1509 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_BROWSE);
1510 additive = ((state & GDK_CONTROL_MASK) != 0) &&
1511 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_SINGLE) &&
1512 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_BROWSE);
1514 if (!range && !additive && sctree->force_additive_sel)
1517 GTK_CMCLIST(sctree)->focus_row = row;
1520 gtk_cmclist_unselect_all (GTK_CMCLIST (sctree));
1524 GtkCMCTreeNode *node;
1526 node = _node ? _node : gtk_cmctree_node_nth (GTK_CMCTREE(sctree), row);
1528 /*No need to manage overlapped list*/
1530 if (row_is_selected(sctree, row))
1531 gtk_cmclist_unselect_row (GTK_CMCLIST (sctree), row, col);
1533 g_signal_emit_by_name
1535 "tree_select_row", node, col);
1537 g_signal_emit_by_name
1539 "tree_select_row", node, col);
1541 sctree->anchor_row = node;
1543 select_range (sctree, row);
1547 sctree_is_hot_spot (GtkSCTree *sctree,
1548 GtkCMCTreeNode *node,
1553 GtkCMCTreeRow *tree_row;
1556 GtkCMCellPixText *cell;
1560 g_return_val_if_fail (GTK_IS_SCTREE (sctree), FALSE);
1561 g_return_val_if_fail (node != NULL, FALSE);
1563 clist = GTK_CMCLIST (sctree);
1564 ctree = GTK_CMCTREE (sctree);
1566 if (!clist->column[ctree->tree_column].visible ||
1567 ctree->expander_style == GTK_CMCTREE_EXPANDER_NONE)
1570 tree_row = GTK_CMCTREE_ROW (node);
1572 cell = GTK_CMCELL_PIXTEXT (tree_row->row.cell[ctree->tree_column]);
1574 if (!GTK_CMCLIST_ROW_HEIGHT_SET(GTK_CMCLIST(clist)))
1575 yu = (ROW_TOP_YPIXEL (clist, row) + (clist->row_height - PM_SIZE) / 2 -
1576 (clist->row_height - 1) % 2);
1578 yu = (ROW_TOP_YPIXEL (clist, row) + (clist->row_height/2 - PM_SIZE) / 2 -
1579 (clist->row_height/2 - 1) % 2);
1581 #ifndef GENERIC_UMPC
1582 if (clist->column[ctree->tree_column].justification == GTK_JUSTIFY_RIGHT)
1583 xl = (clist->column[ctree->tree_column].area.x +
1584 clist->column[ctree->tree_column].area.width - 1 + clist->hoffset -
1585 (tree_row->level - 1) * ctree->tree_indent - PM_SIZE -
1586 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1588 xl = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1589 (tree_row->level - 1) * ctree->tree_indent +
1590 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1592 xmax = xl + PM_SIZE;
1594 if (clist->column[ctree->tree_column].justification == GTK_JUSTIFY_RIGHT) {
1595 xl = (clist->column[ctree->tree_column].area.x +
1596 clist->column[ctree->tree_column].area.width - 1 + clist->hoffset -
1597 (tree_row->level - 1) * ctree->tree_indent - PM_SIZE -
1598 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1599 xmax = xl + PM_SIZE;
1600 } else if (ctree->tree_column == 0) {
1601 xl = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1602 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1603 xmax = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1604 (tree_row->level - 1) * ctree->tree_indent +
1605 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3) +
1608 xl = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1609 (tree_row->level - 1) * ctree->tree_indent +
1610 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1611 xmax = xl + PM_SIZE;
1614 return (x >= xl && x <= xmax && y >= yu && y <= yu + PM_SIZE);
1618 gtk_sctree_is_hot_spot (GtkSCTree *ctree,
1622 GtkCMCTreeNode *node;
1626 g_return_val_if_fail (GTK_IS_SCTREE (ctree), FALSE);
1628 if (gtk_cmclist_get_selection_info (GTK_CMCLIST (ctree), x, y, &row, &column))
1629 if ((node = GTK_CMCTREE_NODE(g_list_nth (GTK_CMCLIST (ctree)->row_list, row))))
1630 return sctree_is_hot_spot (ctree, node, row, x, y);
1635 /* Our handler for button_press events. We override all of GtkCMCList's broken
1639 gtk_sctree_button_press (GtkWidget *widget, GdkEventButton *event)
1648 g_return_val_if_fail (widget != NULL, FALSE);
1649 g_return_val_if_fail (GTK_IS_SCTREE (widget), FALSE);
1650 g_return_val_if_fail (event != NULL, FALSE);
1652 sctree = GTK_SCTREE (widget);
1653 clist = GTK_CMCLIST (widget);
1656 if (event->window != clist->clist_window)
1657 return (* GTK_WIDGET_CLASS (parent_class)->button_press_event) (widget, event);
1659 on_row = gtk_cmclist_get_selection_info (clist, event->x, event->y, &row, &col);
1661 if (on_row && !GTK_WIDGET_HAS_FOCUS(widget))
1662 gtk_widget_grab_focus (widget);
1664 if (gtk_sctree_is_hot_spot (GTK_SCTREE(sctree), event->x, event->y)) {
1665 GtkCMCTreeNode *node = gtk_cmctree_node_nth(GTK_CMCTREE(sctree), row);
1666 if (GTK_CMCTREE_ROW (node)->expanded)
1667 gtk_cmctree_collapse(GTK_CMCTREE(sctree), node);
1668 else if (GTK_SCTREE(sctree)->always_expand_recursively)
1669 gtk_cmctree_expand_recursive (GTK_CMCTREE(sctree), node);
1671 gtk_cmctree_expand(GTK_CMCTREE(sctree), node);
1675 switch (event->type) {
1676 case GDK_BUTTON_PRESS:
1677 if (event->button == 1 || event->button == 2) {
1678 if (event->button == 2)
1679 event->state &= ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK);
1681 /* Save the mouse info for DnD */
1682 sctree->dnd_press_button = event->button;
1683 sctree->dnd_press_x = event->x;
1684 sctree->dnd_press_y = event->y;
1686 /* Handle selection */
1687 if ((row_is_selected (sctree, row)
1688 && !(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)))
1689 || ((event->state & GDK_CONTROL_MASK)
1690 && !(event->state & GDK_SHIFT_MASK))) {
1691 sctree->dnd_select_pending = TRUE;
1692 sctree->dnd_select_pending_state = event->state;
1693 sctree->dnd_select_pending_row = row;
1695 select_row (sctree, row, col, event->state, NULL);
1698 gtk_cmclist_unselect_all (clist);
1702 } else if (event->button == 3) {
1703 /* Emit *_popup_menu signal*/
1705 if (!row_is_selected(sctree,row))
1706 select_row (sctree, row, col, 0, NULL);
1707 g_signal_emit (G_OBJECT (sctree),
1708 sctree_signals[ROW_POPUP_MENU],
1711 gtk_cmclist_unselect_all(clist);
1712 g_signal_emit (G_OBJECT (sctree),
1713 sctree_signals[EMPTY_POPUP_MENU],
1721 case GDK_2BUTTON_PRESS:
1722 if (event->button != 1)
1725 sctree->dnd_select_pending = FALSE;
1726 sctree->dnd_select_pending_state = 0;
1729 g_signal_emit (G_OBJECT (sctree),
1730 sctree_signals[OPEN_ROW], 0);
1742 /* Our handler for button_release events. We override all of GtkCMCList's broken
1746 gtk_sctree_button_release (GtkWidget *widget, GdkEventButton *event)
1754 g_return_val_if_fail (widget != NULL, FALSE);
1755 g_return_val_if_fail (GTK_IS_SCTREE (widget), FALSE);
1756 g_return_val_if_fail (event != NULL, FALSE);
1758 sctree = GTK_SCTREE (widget);
1759 clist = GTK_CMCLIST (widget);
1762 if (event->window != clist->clist_window)
1763 return (* GTK_WIDGET_CLASS (parent_class)->button_release_event) (widget, event);
1765 on_row = gtk_cmclist_get_selection_info (clist, event->x, event->y, &row, &col);
1767 if (!(event->button == 1 || event->button == 2))
1770 sctree->dnd_press_button = 0;
1771 sctree->dnd_press_x = 0;
1772 sctree->dnd_press_y = 0;
1775 if (sctree->dnd_select_pending) {
1776 select_row (sctree, row, col, sctree->dnd_select_pending_state, NULL);
1777 sctree->dnd_select_pending = FALSE;
1778 sctree->dnd_select_pending_state = 0;
1787 /* Our handler for motion_notify events. We override all of GtkCMCList's broken
1791 gtk_sctree_motion (GtkWidget *widget, GdkEventMotion *event)
1796 g_return_val_if_fail (widget != NULL, FALSE);
1797 g_return_val_if_fail (GTK_IS_SCTREE (widget), FALSE);
1798 g_return_val_if_fail (event != NULL, FALSE);
1800 sctree = GTK_SCTREE (widget);
1801 clist = GTK_CMCLIST (widget);
1803 if (event->window != clist->clist_window)
1804 return (* GTK_WIDGET_CLASS (parent_class)->motion_notify_event) (widget, event);
1806 if (!((sctree->dnd_press_button == 1 && (event->state & GDK_BUTTON1_MASK))
1807 || (sctree->dnd_press_button == 2 && (event->state & GDK_BUTTON2_MASK))))
1810 /* This is the same threshold value that is used in gtkdnd.c */
1812 #ifndef GENERIC_UMPC
1817 if (MAX (ABS (sctree->dnd_press_x - event->x),
1818 ABS (sctree->dnd_press_y - event->y)) <= THRESHOLD)
1821 /* Handle any pending selections */
1823 if (sctree->dnd_select_pending) {
1824 if (!row_is_selected(sctree,sctree->dnd_select_pending_row))
1826 sctree->dnd_select_pending_row,
1828 sctree->dnd_select_pending_state,
1831 sctree->dnd_select_pending = FALSE;
1832 sctree->dnd_select_pending_state = 0;
1835 g_signal_emit (G_OBJECT (sctree),
1836 sctree_signals[START_DRAG],
1838 sctree->dnd_press_button,
1843 /* We override the drag_begin signal to do nothing */
1845 gtk_sctree_drag_begin (GtkWidget *widget, GdkDragContext *context)
1850 /* We override the drag_end signal to do nothing */
1852 gtk_sctree_drag_end (GtkWidget *widget, GdkDragContext *context)
1857 /* We override the drag_data_get signal to do nothing */
1859 gtk_sctree_drag_data_get (GtkWidget *widget, GdkDragContext *context,
1860 GtkSelectionData *data, guint info, guint time)
1865 /* We override the drag_leave signal to do nothing */
1867 gtk_sctree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time)
1872 /* We override the drag_motion signal to do nothing */
1874 gtk_sctree_drag_motion (GtkWidget *widget, GdkDragContext *context,
1875 gint x, gint y, guint time)
1880 /* We override the drag_drop signal to do nothing */
1882 gtk_sctree_drag_drop (GtkWidget *widget, GdkDragContext *context,
1883 gint x, gint y, guint time)
1888 /* We override the drag_data_received signal to do nothing */
1890 gtk_sctree_drag_data_received (GtkWidget *widget, GdkDragContext *context,
1891 gint x, gint y, GtkSelectionData *data,
1892 guint info, guint time)
1897 /* Our handler for the clear signal of the clist. We have to reset the anchor
1901 gtk_sctree_clear (GtkCMCList *clist)
1905 g_return_if_fail (clist != NULL);
1906 g_return_if_fail (GTK_IS_SCTREE (clist));
1908 sctree = GTK_SCTREE (clist);
1909 sctree->anchor_row = NULL;
1911 if (((GtkCMCListClass *)parent_class)->clear)
1912 (* ((GtkCMCListClass *)parent_class)->clear) (clist);
1916 gtk_sctree_real_unselect_all (GtkCMCList *clist)
1919 gboolean should_freeze = FALSE;
1921 g_return_if_fail (clist != NULL);
1922 g_return_if_fail (GTK_IS_SCTREE (clist));
1924 sctree = GTK_SCTREE (clist);
1926 if (sc_g_list_bigger(GTK_CMCLIST(sctree)->selection, 10)) {
1927 should_freeze = TRUE;
1928 sctree->selecting_range++;
1929 gtk_cmclist_freeze (GTK_CMCLIST (sctree));
1932 if (((GtkCMCListClass *)parent_class)->unselect_all)
1933 (* ((GtkCMCListClass *)parent_class)->unselect_all) (clist);
1935 if (should_freeze) {
1936 gtk_cmclist_thaw (GTK_CMCLIST (sctree));
1937 sctree->selecting_range--;
1941 /* Our handler for the change_focus_row_expansion signal of the ctree.
1942 We have to set the anchor to parent visible node.
1945 gtk_sctree_collapse (GtkCMCTree *ctree, GtkCMCTreeNode *node)
1947 g_return_if_fail (ctree != NULL);
1948 g_return_if_fail (GTK_IS_SCTREE (ctree));
1950 (* parent_class->tree_collapse) (ctree, node);
1951 GTK_SCTREE(ctree)->anchor_row =
1952 gtk_cmctree_node_nth(ctree, GTK_CMCLIST(ctree)->focus_row);
1955 GtkWidget *gtk_sctree_new_with_titles (gint columns, gint tree_column,
1960 g_return_val_if_fail (columns > 0, NULL);
1961 g_return_val_if_fail (tree_column >= 0, NULL);
1963 widget = gtk_widget_new (TYPE_GTK_SCTREE,
1964 "n_columns", columns,
1965 "tree_column", tree_column,
1968 GtkCMCList *clist = GTK_CMCLIST (widget);
1971 for (i = 0; i < columns; i++)
1972 gtk_cmclist_set_column_title (clist, i, titles[i]);
1973 gtk_cmclist_column_titles_show (clist);
1976 GTK_SCTREE(widget)->show_stripes = TRUE;
1977 GTK_SCTREE(widget)->always_expand_recursively = TRUE;
1978 GTK_SCTREE(widget)->force_additive_sel = FALSE;
1980 GTK_SCTREE(widget)->use_markup = g_new0(gboolean, columns);
1985 void gtk_sctree_set_use_markup (GtkSCTree *sctree,
1990 GValue value = { 0 };
1992 g_return_if_fail(GTK_IS_SCTREE(sctree));
1994 g_value_init (&value, G_TYPE_INT);
1995 g_object_get_property (G_OBJECT (sctree), "n-columns", &value);
1996 columns = g_value_get_int (&value);
1997 g_value_unset (&value);
1999 g_return_if_fail(column < columns);
2001 sctree->use_markup[column] = markup;
2004 void gtk_sctree_select (GtkSCTree *sctree, GtkCMCTreeNode *node)
2007 g_list_position(GTK_CMCLIST(sctree)->row_list, (GList *)node),
2011 void gtk_sctree_select_with_state (GtkSCTree *sctree, GtkCMCTreeNode *node, int state)
2014 g_list_position(GTK_CMCLIST(sctree)->row_list, (GList *)node),
2018 void gtk_sctree_unselect_all (GtkSCTree *sctree)
2020 gtk_cmclist_unselect_all(GTK_CMCLIST(sctree));
2021 sctree->anchor_row = NULL;
2024 void gtk_sctree_set_anchor_row (GtkSCTree *sctree, GtkCMCTreeNode *node)
2026 sctree->anchor_row = node;
2029 void gtk_sctree_remove_node (GtkSCTree *sctree, GtkCMCTreeNode *node)
2031 if (sctree->anchor_row == node)
2032 sctree->anchor_row = NULL;
2033 gtk_cmctree_remove_node(GTK_CMCTREE(sctree), node);
2036 void gtk_sctree_set_stripes(GtkSCTree *sctree, gboolean show_stripes)
2038 sctree->show_stripes = show_stripes;
2041 void gtk_sctree_set_recursive_expand(GtkSCTree *sctree, gboolean rec_exp)
2043 sctree->always_expand_recursively = rec_exp;
2046 /***********************************************************
2047 * Tree sorting functions *
2048 ***********************************************************/
2050 static void sink(GtkCMCList *clist, GPtrArray *numbers, gint root, gint bottom)
2053 GtkCMCTreeNode *temp;
2058 /* find the maximum element of numbers[root],
2059 numbers[2*root] and numbers[2*root+1] */
2061 if (clist->compare( clist, GTK_CMCTREE_ROW (g_ptr_array_index(numbers, root)),
2062 GTK_CMCTREE_ROW(g_ptr_array_index( numbers, j))) >= 0)
2065 if (clist->compare( clist, GTK_CMCTREE_ROW (g_ptr_array_index(numbers, k)),
2066 GTK_CMCTREE_ROW (g_ptr_array_index( numbers, j))) > 0)
2068 /* if numbers[root] wasn't the maximum element then
2071 temp = g_ptr_array_index( numbers,root);
2072 g_ptr_array_index( numbers, root) = g_ptr_array_index( numbers, j);
2073 g_ptr_array_index( numbers, j) = temp;
2074 sink( clist, numbers, j, bottom);
2079 static void heap_sort(GtkCMCList *clist, GPtrArray *numbers, gint array_size)
2082 GtkCMCTreeNode *temp;
2084 /* build the Heap */
2085 for (i = (array_size / 2); i >= 1; i--)
2086 sink( clist, numbers, i, array_size);
2087 /* output the Heap */
2088 for (i = array_size; i >= 2; i--) {
2089 temp = g_ptr_array_index( numbers, 1);
2090 g_ptr_array_index( numbers, 1) = g_ptr_array_index( numbers, i);
2091 g_ptr_array_index( numbers, i) = temp;
2092 sink( clist, numbers, 1, i-1);
2097 stree_sort (GtkCMCTree *ctree,
2098 GtkCMCTreeNode *node,
2101 GtkCMCTreeNode *list_start, *work, *next;
2102 GPtrArray *row_array, *viewable_array;
2106 clist = GTK_CMCLIST (ctree);
2109 work = GTK_CMCTREE_ROW (node)->children;
2111 work = GTK_CMCTREE_NODE (clist->row_list);
2113 row_array = g_ptr_array_new();
2114 viewable_array = g_ptr_array_new();
2117 g_ptr_array_add( row_array, NULL);
2119 /* add all rows to row_array */
2120 g_ptr_array_add( row_array, work);
2121 if (GTK_CMCTREE_ROW (work)->parent && gtk_cmctree_is_viewable( ctree, work))
2122 g_ptr_array_add( viewable_array, GTK_CMCTREE_ROW (work)->parent);
2123 next = GTK_CMCTREE_ROW (work)->sibling;
2124 gtk_sctree_unlink( ctree, work, FALSE);
2128 heap_sort( clist, row_array, (row_array->len)-1);
2131 list_start = GTK_CMCTREE_ROW (node)->children;
2133 list_start = GTK_CMCTREE_NODE (clist->row_list);
2135 if (clist->sort_type == GTK_SORT_ASCENDING) {
2136 for (i=(row_array->len)-1; i>=1; i--) {
2137 work = g_ptr_array_index( row_array, i);
2138 gtk_sctree_link( ctree, work, node, list_start, FALSE);
2140 /* insert work at the beginning of the list */
2143 for (i=1; i<row_array->len; i++) {
2144 work = g_ptr_array_index( row_array, i);
2145 gtk_sctree_link( ctree, work, node, list_start, FALSE);
2147 /* insert work at the beginning of the list */
2151 for (i=0; i<viewable_array->len; i++) {
2152 gtk_cmctree_expand( ctree, g_ptr_array_index( viewable_array, i));
2156 g_ptr_array_free( row_array, TRUE);
2157 g_ptr_array_free( viewable_array, TRUE);
2161 gtk_sctree_sort_recursive (GtkCMCTree *ctree,
2162 GtkCMCTreeNode *node)
2165 GtkCMCTreeNode *focus_node = NULL;
2167 g_return_if_fail (ctree != NULL);
2168 g_return_if_fail (GTK_IS_CMCTREE (ctree));
2170 clist = GTK_CMCLIST (ctree);
2172 gtk_cmclist_freeze (clist);
2174 if (clist->selection_mode == GTK_SELECTION_EXTENDED) {
2175 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2177 g_list_free (clist->undo_selection);
2178 g_list_free (clist->undo_unselection);
2179 clist->undo_selection = NULL;
2180 clist->undo_unselection = NULL;
2183 if (!node || (node && gtk_cmctree_is_viewable (ctree, node)))
2184 focus_node = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
2186 GTK_SCTREE(ctree)->sorting = TRUE;
2188 gtk_cmctree_post_recursive (ctree, node, GTK_CMCTREE_FUNC (stree_sort), NULL);
2191 stree_sort (ctree, NULL, NULL);
2193 GTK_SCTREE(ctree)->sorting = FALSE;
2196 clist->focus_row = g_list_position (clist->row_list,(GList *)focus_node);
2197 clist->undo_anchor = clist->focus_row;
2200 gtk_cmclist_thaw (clist);
2204 gtk_sctree_sort_node (GtkCMCTree *ctree,
2205 GtkCMCTreeNode *node)
2208 GtkCMCTreeNode *focus_node = NULL;
2210 g_return_if_fail (ctree != NULL);
2211 g_return_if_fail (GTK_IS_CMCTREE (ctree));
2213 clist = GTK_CMCLIST (ctree);
2215 gtk_cmclist_freeze (clist);
2217 if (clist->selection_mode == GTK_SELECTION_EXTENDED) {
2218 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2220 g_list_free (clist->undo_selection);
2221 g_list_free (clist->undo_unselection);
2222 clist->undo_selection = NULL;
2223 clist->undo_unselection = NULL;
2226 if (!node || (node && gtk_cmctree_is_viewable (ctree, node)))
2227 focus_node = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
2229 GTK_SCTREE(ctree)->sorting = TRUE;
2231 stree_sort (ctree, node, NULL);
2233 GTK_SCTREE(ctree)->sorting = FALSE;
2236 clist->focus_row = g_list_position (clist->row_list,(GList *)focus_node);
2237 clist->undo_anchor = clist->focus_row;
2240 gtk_cmclist_thaw (clist);
2243 /************************************************************************/
2246 gtk_sctree_unlink (GtkCMCTree *ctree,
2247 GtkCMCTreeNode *node,
2248 gboolean update_focus_row)
2254 GtkCMCTreeNode *work;
2255 GtkCMCTreeNode *parent;
2258 g_return_if_fail (ctree != NULL);
2259 g_return_if_fail (GTK_IS_CMCTREE (ctree));
2260 g_return_if_fail (node != NULL);
2262 clist = GTK_CMCLIST (ctree);
2264 if (update_focus_row && clist->selection_mode == GTK_SELECTION_EXTENDED) {
2265 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2267 g_list_free (clist->undo_selection);
2268 g_list_free (clist->undo_unselection);
2269 clist->undo_selection = NULL;
2270 clist->undo_unselection = NULL;
2273 visible = gtk_cmctree_is_viewable (ctree, node);
2275 /* clist->row_list_end unlinked ? */
2276 if (visible && (GTK_CMCTREE_NODE_NEXT (node) == NULL ||
2277 (GTK_CMCTREE_ROW (node)->children && gtk_cmctree_is_ancestor (ctree, node,
2278 GTK_CMCTREE_NODE (clist->row_list_end)))))
2279 clist->row_list_end = (GList *) (GTK_CMCTREE_NODE_PREV (node));
2283 level = GTK_CMCTREE_ROW (node)->level;
2284 work = GTK_CMCTREE_NODE_NEXT (node);
2285 while (work && GTK_CMCTREE_ROW (work)->level > level) {
2286 work = GTK_CMCTREE_NODE_NEXT (work);
2291 clist->rows -= (rows + 1);
2293 if (update_focus_row) {
2295 pos = g_list_position (clist->row_list, (GList *)node);
2296 if (pos + rows < clist->focus_row)
2297 clist->focus_row -= (rows + 1);
2298 else if (pos <= clist->focus_row) {
2299 if (!GTK_CMCTREE_ROW (node)->sibling)
2300 clist->focus_row = MAX (pos - 1, 0);
2302 clist->focus_row = pos;
2304 clist->focus_row = MIN (clist->focus_row, clist->rows - 1);
2306 clist->undo_anchor = clist->focus_row;
2311 list = (GList *)GTK_CMCTREE_NODE_PREV (work);
2313 list = (GList *)work;
2314 list->prev = (GList *)GTK_CMCTREE_NODE_PREV (node);
2317 if (GTK_CMCTREE_NODE_PREV (node) &&
2318 GTK_CMCTREE_NODE_NEXT (GTK_CMCTREE_NODE_PREV (node)) == node) {
2319 list = (GList *)GTK_CMCTREE_NODE_PREV (node);
2320 list->next = (GList *)work;
2324 parent = GTK_CMCTREE_ROW (node)->parent;
2326 if (GTK_CMCTREE_ROW (parent)->children == node) {
2327 GTK_CMCTREE_ROW (parent)->children = GTK_CMCTREE_ROW (node)->sibling;
2330 GtkCMCTreeNode *sibling;
2332 sibling = GTK_CMCTREE_ROW (parent)->children;
2333 while (GTK_CMCTREE_ROW (sibling)->sibling != node)
2334 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
2335 GTK_CMCTREE_ROW (sibling)->sibling = GTK_CMCTREE_ROW (node)->sibling;
2339 if (clist->row_list == (GList *)node)
2340 clist->row_list = (GList *) (GTK_CMCTREE_ROW (node)->sibling);
2342 GtkCMCTreeNode *sibling;
2344 sibling = GTK_CMCTREE_NODE (clist->row_list);
2345 while (GTK_CMCTREE_ROW (sibling)->sibling != node)
2346 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
2347 GTK_CMCTREE_ROW (sibling)->sibling = GTK_CMCTREE_ROW (node)->sibling;
2353 gtk_sctree_link (GtkCMCTree *ctree,
2354 GtkCMCTreeNode *node,
2355 GtkCMCTreeNode *parent,
2356 GtkCMCTreeNode *sibling,
2357 gboolean update_focus_row)
2363 gboolean visible = FALSE;
2367 g_return_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent);
2368 g_return_if_fail (node != NULL);
2369 g_return_if_fail (node != sibling);
2370 g_return_if_fail (node != parent);
2372 clist = GTK_CMCLIST (ctree);
2374 if (update_focus_row && clist->selection_mode == GTK_SELECTION_EXTENDED) {
2375 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2377 g_list_free (clist->undo_selection);
2378 g_list_free (clist->undo_unselection);
2379 clist->undo_selection = NULL;
2380 clist->undo_unselection = NULL;
2383 for (rows = 1, list_end = (GList *)node; list_end->next;
2384 list_end = list_end->next)
2387 GTK_CMCTREE_ROW (node)->parent = parent;
2388 GTK_CMCTREE_ROW (node)->sibling = sibling;
2390 if (!parent || (parent && (gtk_cmctree_is_viewable (ctree, parent) &&
2391 GTK_CMCTREE_ROW (parent)->expanded))) {
2393 clist->rows += rows;
2397 work = (GList *)(GTK_CMCTREE_ROW (parent)->children);
2399 work = clist->row_list;
2402 if (work != (GList *)sibling) {
2403 while (GTK_CMCTREE_ROW (work)->sibling != sibling)
2404 work = (GList *)(GTK_CMCTREE_ROW (work)->sibling);
2405 GTK_CMCTREE_ROW (work)->sibling = node;
2408 if (sibling == GTK_CMCTREE_NODE (clist->row_list))
2409 clist->row_list = (GList *) node;
2410 if (GTK_CMCTREE_NODE_PREV (sibling) &&
2411 GTK_CMCTREE_NODE_NEXT (GTK_CMCTREE_NODE_PREV (sibling)) == sibling) {
2412 list = (GList *)GTK_CMCTREE_NODE_PREV (sibling);
2413 list->next = (GList *)node;
2416 list = (GList *)node;
2417 list->prev = (GList *)GTK_CMCTREE_NODE_PREV (sibling);
2418 list_end->next = (GList *)sibling;
2419 list = (GList *)sibling;
2420 list->prev = list_end;
2421 if (parent && GTK_CMCTREE_ROW (parent)->children == sibling)
2422 GTK_CMCTREE_ROW (parent)->children = node;
2427 while (GTK_CMCTREE_ROW (work)->sibling)
2428 work = (GList *)(GTK_CMCTREE_ROW (work)->sibling);
2429 GTK_CMCTREE_ROW (work)->sibling = node;
2431 /* find last visible child of sibling */
2432 work = (GList *) gtk_sctree_last_visible (ctree,
2433 GTK_CMCTREE_NODE (work));
2435 list_end->next = work->next;
2437 list = work->next->prev = list_end;
2438 work->next = (GList *)node;
2439 list = (GList *)node;
2444 GTK_CMCTREE_ROW (parent)->children = node;
2445 list = (GList *)node;
2446 list->prev = (GList *)parent;
2447 if (GTK_CMCTREE_ROW (parent)->expanded) {
2448 list_end->next = (GList *)GTK_CMCTREE_NODE_NEXT (parent);
2449 if (GTK_CMCTREE_NODE_NEXT(parent)) {
2450 list = (GList *)GTK_CMCTREE_NODE_NEXT (parent);
2451 list->prev = list_end;
2453 list = (GList *)parent;
2454 list->next = (GList *)node;
2457 list_end->next = NULL;
2460 clist->row_list = (GList *)node;
2461 list = (GList *)node;
2463 list_end->next = NULL;
2468 gtk_cmctree_pre_recursive (ctree, node, stree_update_level, NULL);
2470 if (clist->row_list_end == NULL ||
2471 clist->row_list_end->next == (GList *)node)
2472 clist->row_list_end = list_end;
2474 if (visible && update_focus_row) {
2476 pos = g_list_position (clist->row_list, (GList *)node);
2478 if (pos <= clist->focus_row) {
2479 clist->focus_row += rows;
2480 clist->undo_anchor = clist->focus_row;
2486 stree_update_level (GtkCMCTree *ctree,
2487 GtkCMCTreeNode *node,
2493 if (GTK_CMCTREE_ROW (node)->parent)
2494 GTK_CMCTREE_ROW (node)->level =
2495 GTK_CMCTREE_ROW (GTK_CMCTREE_ROW (node)->parent)->level + 1;
2497 GTK_CMCTREE_ROW (node)->level = 1;
2500 static GtkCMCTreeNode *
2501 gtk_sctree_last_visible (GtkCMCTree *ctree,
2502 GtkCMCTreeNode *node)
2504 GtkCMCTreeNode *work;
2509 work = GTK_CMCTREE_ROW (node)->children;
2511 if (!work || !GTK_CMCTREE_ROW (node)->expanded)
2514 while (GTK_CMCTREE_ROW (work)->sibling)
2515 work = GTK_CMCTREE_ROW (work)->sibling;
2517 return gtk_sctree_last_visible (ctree, work);
2520 /* this wrapper simply replaces NULL pixmaps
2521 * with a transparent, 1x1 pixmap. This works
2522 * around a memory problem deep inside gtk,
2523 * revealed by valgrind.
2525 /*GtkCMCTreeNode* gtk_sctree_insert_node (GtkCMCTree *ctree,
2526 GtkCMCTreeNode *parent,
2527 GtkCMCTreeNode *sibling,
2530 GdkPixmap *pixmap_closed,
2531 GdkBitmap *mask_closed,
2532 GdkPixmap *pixmap_opened,
2533 GdkBitmap *mask_opened,
2538 stock_pixmap_gdk(GTK_WIDGET(ctree), STOCK_PIXMAP_EMPTY,
2539 &emptyxpm, &emptyxpmmask);
2541 if (!pixmap_closed) {
2542 pixmap_closed = emptyxpm;
2543 mask_closed = emptyxpmmask;
2545 if (!pixmap_opened) {
2546 pixmap_opened = emptyxpm;
2547 mask_opened = emptyxpmmask;
2549 return gtk_cmctree_insert_node(ctree, parent, sibling, text,spacing,
2550 pixmap_closed, mask_closed, pixmap_opened, mask_opened,
2555 sset_node_info (GtkCMCTree *ctree,
2556 GtkCMCTreeNode *node,
2559 GdkPixmap *pixmap_closed,
2560 GdkBitmap *mask_closed,
2561 GdkPixmap *pixmap_opened,
2562 GdkBitmap *mask_opened,
2566 if (GTK_CMCTREE_ROW (node)->pixmap_opened)
2568 g_object_unref (GTK_CMCTREE_ROW (node)->pixmap_opened);
2569 if (GTK_CMCTREE_ROW (node)->mask_opened)
2570 g_object_unref (GTK_CMCTREE_ROW (node)->mask_opened);
2572 if (GTK_CMCTREE_ROW (node)->pixmap_closed)
2574 g_object_unref (GTK_CMCTREE_ROW (node)->pixmap_closed);
2575 if (GTK_CMCTREE_ROW (node)->mask_closed)
2576 g_object_unref (GTK_CMCTREE_ROW (node)->mask_closed);
2579 GTK_CMCTREE_ROW (node)->pixmap_opened = NULL;
2580 GTK_CMCTREE_ROW (node)->mask_opened = NULL;
2581 GTK_CMCTREE_ROW (node)->pixmap_closed = NULL;
2582 GTK_CMCTREE_ROW (node)->mask_closed = NULL;
2586 GTK_CMCTREE_ROW (node)->pixmap_closed = g_object_ref (pixmap_closed);
2588 GTK_CMCTREE_ROW (node)->mask_closed = g_object_ref (mask_closed);
2592 GTK_CMCTREE_ROW (node)->pixmap_opened = g_object_ref (pixmap_opened);
2594 GTK_CMCTREE_ROW (node)->mask_opened = g_object_ref (mask_opened);
2597 GTK_CMCTREE_ROW (node)->is_leaf = is_leaf;
2598 GTK_CMCTREE_ROW (node)->expanded = (is_leaf) ? FALSE : expanded;
2600 if (GTK_CMCTREE_ROW (node)->expanded)
2601 gtk_cmctree_node_set_pixtext (ctree, node, ctree->tree_column,
2602 text, spacing, pixmap_opened, mask_opened);
2604 gtk_cmctree_node_set_pixtext (ctree, node, ctree->tree_column,
2605 text, spacing, pixmap_closed, mask_closed);
2609 stree_draw_node (GtkCMCTree *ctree,
2610 GtkCMCTreeNode *node)
2614 clist = GTK_CMCLIST (ctree);
2616 if (CLIST_UNFROZEN (clist) && gtk_cmctree_is_viewable (ctree, node))
2618 GtkCMCTreeNode *work;
2621 work = GTK_CMCTREE_NODE (clist->row_list);
2622 while (work && work != node)
2624 work = GTK_CMCTREE_NODE_NEXT (work);
2627 if (work && gtk_cmclist_row_is_visible (clist, num) != GTK_VISIBILITY_NONE)
2628 GTK_CMCLIST_GET_CLASS (clist)->draw_row
2629 (clist, NULL, num, GTK_CMCLIST_ROW ((GList *) node));
2633 /* this wrapper simply replaces NULL pixmaps
2634 * with a transparent, 1x1 pixmap. This works
2635 * around a memory problem deep inside gtk,
2636 * revealed by valgrind.
2638 void gtk_sctree_set_node_info (GtkCMCTree *ctree,
2639 GtkCMCTreeNode *node,
2642 GdkPixmap *pixmap_closed,
2643 GdkBitmap *mask_closed,
2644 GdkPixmap *pixmap_opened,
2645 GdkBitmap *mask_opened,
2650 gboolean old_expanded;
2651 GtkCMCTreeNode *work;
2654 stock_pixmap_gdk(GTK_WIDGET(ctree), STOCK_PIXMAP_EMPTY,
2655 &emptyxpm, &emptyxpmmask);
2657 if (!pixmap_closed) {
2658 pixmap_closed = emptyxpm;
2659 mask_closed = emptyxpmmask;
2661 if (!pixmap_opened) {
2662 pixmap_opened = emptyxpm;
2663 mask_opened = emptyxpmmask;
2666 if (!GTK_IS_CMCTREE (ctree) || !node) return;
2668 old_leaf = GTK_CMCTREE_ROW (node)->is_leaf;
2669 old_expanded = GTK_CMCTREE_ROW (node)->expanded;
2671 if (is_leaf && (work = GTK_CMCTREE_ROW (node)->children) != NULL)
2673 GtkCMCTreeNode *ptr;
2678 work = GTK_CMCTREE_ROW (work)->sibling;
2679 gtk_cmctree_remove_node (ctree, ptr);
2683 sset_node_info (ctree, node, text, spacing, pixmap_closed, mask_closed,
2684 pixmap_opened, mask_opened, is_leaf, expanded);
2686 if (!is_leaf && !old_leaf)
2688 GTK_CMCTREE_ROW (node)->expanded = old_expanded;
2689 if (expanded && !old_expanded)
2690 gtk_cmctree_expand (ctree, node);
2691 else if (!expanded && old_expanded)
2692 gtk_cmctree_collapse (ctree, node);
2695 GTK_CMCTREE_ROW (node)->expanded = (is_leaf) ? FALSE : expanded;
2697 stree_draw_node (ctree, node);
2700 static GtkCMCTreeRow *
2701 srow_new (GtkCMCTree *ctree)
2704 GtkCMCTreeRow *ctree_row;
2707 clist = GTK_CMCLIST (ctree);
2708 #if GLIB_CHECK_VERSION(2,10,0)
2709 ctree_row = g_slice_new (GtkCMCTreeRow);
2710 ctree_row->row.cell = g_slice_alloc (sizeof (GtkCMCell) * clist->columns);
2712 ctree_row = g_chunk_new (GtkCMCTreeRow, (GMemChunk *)clist->row_mem_chunk);
2713 ctree_row->row.cell = g_chunk_new (GtkCMCell, (GMemChunk *)clist->cell_mem_chunk);
2715 for (i = 0; i < clist->columns; i++)
2717 ctree_row->row.cell[i].type = GTK_CMCELL_EMPTY;
2718 ctree_row->row.cell[i].vertical = 0;
2719 ctree_row->row.cell[i].horizontal = 0;
2720 ctree_row->row.cell[i].style = NULL;
2723 GTK_CMCELL_PIXTEXT (ctree_row->row.cell[ctree->tree_column])->text = NULL;
2725 ctree_row->row.fg_set = FALSE;
2726 ctree_row->row.bg_set = FALSE;
2727 ctree_row->row.style = NULL;
2728 ctree_row->row.selectable = TRUE;
2729 ctree_row->row.state = GTK_STATE_NORMAL;
2730 ctree_row->row.data = NULL;
2731 ctree_row->row.destroy = NULL;
2733 ctree_row->level = 0;
2734 ctree_row->expanded = FALSE;
2735 ctree_row->parent = NULL;
2736 ctree_row->sibling = NULL;
2737 ctree_row->children = NULL;
2738 ctree_row->pixmap_closed = NULL;
2739 ctree_row->mask_closed = NULL;
2740 ctree_row->pixmap_opened = NULL;
2741 ctree_row->mask_opened = NULL;
2747 srow_delete (GtkCMCTree *ctree,
2748 GtkCMCTreeRow *ctree_row)
2753 clist = GTK_CMCLIST (ctree);
2755 for (i = 0; i < clist->columns; i++)
2757 GTK_CMCLIST_GET_CLASS (clist)->set_cell_contents
2758 (clist, &(ctree_row->row), i, GTK_CMCELL_EMPTY, NULL, 0, NULL, NULL);
2759 if (ctree_row->row.cell[i].style)
2761 if (GTK_WIDGET_REALIZED (ctree))
2762 gtk_style_detach (ctree_row->row.cell[i].style);
2763 g_object_unref (ctree_row->row.cell[i].style);
2767 if (ctree_row->row.style)
2769 if (GTK_WIDGET_REALIZED (ctree))
2770 gtk_style_detach (ctree_row->row.style);
2771 g_object_unref (ctree_row->row.style);
2774 if (ctree_row->pixmap_closed)
2776 g_object_unref (ctree_row->pixmap_closed);
2777 if (ctree_row->mask_closed)
2778 g_object_unref (ctree_row->mask_closed);
2781 if (ctree_row->pixmap_opened)
2783 g_object_unref (ctree_row->pixmap_opened);
2784 if (ctree_row->mask_opened)
2785 g_object_unref (ctree_row->mask_opened);
2788 if (ctree_row->row.destroy)
2790 GDestroyNotify dnotify = ctree_row->row.destroy;
2791 gpointer ddata = ctree_row->row.data;
2793 ctree_row->row.destroy = NULL;
2794 ctree_row->row.data = NULL;
2799 #if GLIB_CHECK_VERSION(2,10,0)
2800 g_slice_free1 (sizeof (GtkCMCell) * clist->columns, ctree_row->row.cell);
2801 g_slice_free (GtkCMCTreeRow, ctree_row);
2803 g_mem_chunk_free ((GMemChunk *)clist->cell_mem_chunk, ctree_row->row.cell);
2804 g_mem_chunk_free ((GMemChunk *)clist->row_mem_chunk, ctree_row);
2809 stree_delete_row (GtkCMCTree *ctree,
2810 GtkCMCTreeNode *node,
2813 srow_delete (ctree, GTK_CMCTREE_ROW (node));
2814 g_list_free_1 ((GList *)node);
2818 gtk_sctree_column_auto_resize (GtkCMCList *clist,
2819 GtkCMCListRow *clist_row,
2823 /* resize column if needed for auto_resize */
2824 GtkRequisition requisition;
2826 if (!clist->column[column].auto_resize ||
2827 GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2831 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request (clist, clist_row,
2832 column, &requisition);
2834 requisition.width = 0;
2836 if (requisition.width > clist->column[column].width)
2837 gtk_cmclist_set_column_width (clist, column, requisition.width);
2838 else if (requisition.width < old_width &&
2839 old_width == clist->column[column].width)
2844 /* run a "gtk_cmclist_optimal_column_width" but break, if
2845 * the column doesn't shrink */
2846 if (GTK_CMCLIST_SHOW_TITLES (clist) && clist->column[column].button)
2847 new_width = (clist->column[column].button->requisition.width -
2848 (CELL_SPACING + (2 * COLUMN_INSET)));
2852 for (list = clist->row_list; list; list = list->next)
2854 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2855 (clist, GTK_CMCLIST_ROW (list), column, &requisition);
2856 new_width = MAX (new_width, requisition.width);
2857 if (new_width == clist->column[column].width)
2860 if (new_width < clist->column[column].width)
2861 gtk_cmclist_set_column_width (clist, column, new_width);
2867 gtk_sctree_real_tree_expand (GtkCMCTree *ctree,
2868 GtkCMCTreeNode *node)
2871 GtkCMCTreeNode *work;
2872 GtkRequisition requisition;
2876 g_return_if_fail (GTK_IS_CMCTREE (ctree));
2878 if (!node || GTK_CMCTREE_ROW (node)->expanded || GTK_CMCTREE_ROW (node)->is_leaf)
2881 clist = GTK_CMCLIST (ctree);
2883 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2885 GTK_CMCTREE_ROW (node)->expanded = TRUE;
2886 level = GTK_CMCTREE_ROW (node)->level;
2888 visible = gtk_cmctree_is_viewable (ctree, node);
2889 /* get cell width if tree_column is auto resized */
2890 if (visible && clist->column[ctree->tree_column].auto_resize &&
2891 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2892 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2893 (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column, &requisition);
2895 /* unref/unset closed pixmap */
2896 if (GTK_CMCELL_PIXTEXT
2897 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixmap)
2901 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixmap);
2904 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixmap = NULL;
2906 if (GTK_CMCELL_PIXTEXT
2907 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->mask)
2911 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->mask);
2913 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->mask = NULL;
2917 /* set/ref opened pixmap */
2918 if (GTK_CMCTREE_ROW (node)->pixmap_opened)
2921 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixmap =
2922 g_object_ref (GTK_CMCTREE_ROW (node)->pixmap_opened);
2924 if (GTK_CMCTREE_ROW (node)->mask_opened)
2926 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->mask =
2927 g_object_ref (GTK_CMCTREE_ROW (node)->mask_opened);
2931 work = GTK_CMCTREE_ROW (node)->children;
2934 GList *list = (GList *)work;
2935 gint *cell_width = NULL;
2940 if (visible && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2942 cell_width = g_new0 (gint, clist->columns);
2943 if (clist->column[ctree->tree_column].auto_resize)
2944 cell_width[ctree->tree_column] = requisition.width;
2948 /* search maximum cell widths of auto_resize columns */
2949 for (i = 0; i < clist->columns; i++)
2950 if (clist->column[i].auto_resize)
2952 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2953 (clist, >K_CMCTREE_ROW (work)->row, i, &requisition);
2954 cell_width[i] = MAX (requisition.width, cell_width[i]);
2957 list = (GList *)work;
2958 work = GTK_CMCTREE_NODE_NEXT (work);
2965 list = (GList *)work;
2966 work = GTK_CMCTREE_NODE_NEXT (work);
2970 list->next = (GList *)GTK_CMCTREE_NODE_NEXT (node);
2972 if (GTK_CMCTREE_NODE_NEXT (node))
2976 if (clist->row_list_end == list)
2977 clist->row_list_end = g_list_last(list);
2979 tmp_list = (GList *)GTK_CMCTREE_NODE_NEXT (node);
2980 tmp_list->prev = list;
2983 clist->row_list_end = list;
2985 list = (GList *)node;
2986 list->next = (GList *)(GTK_CMCTREE_ROW (node)->children);
2990 /* resize auto_resize columns if needed */
2991 for (i = 0; i < clist->columns; i++)
2992 if (clist->column[i].auto_resize &&
2993 cell_width[i] > clist->column[i].width)
2994 gtk_cmclist_set_column_width (clist, i, cell_width[i]);
2995 g_free (cell_width);
2997 if (!GTK_SCTREE(ctree)->sorting) {
2998 /* update focus_row position */
2999 row = g_list_position (clist->row_list, (GList *)node);
3000 if (row < clist->focus_row)
3001 clist->focus_row += tmp;
3004 CLIST_REFRESH (clist);
3007 else if (visible && clist->column[ctree->tree_column].auto_resize)
3008 /* resize tree_column if needed */
3009 gtk_sctree_column_auto_resize (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column,
3015 gtk_sctree_insert_node (GtkCMCTree *ctree,
3016 GtkCMCTreeNode *parent,
3017 GtkCMCTreeNode *sibling,
3020 GdkPixmap *pixmap_closed,
3021 GdkBitmap *mask_closed,
3022 GdkPixmap *pixmap_opened,
3023 GdkBitmap *mask_opened,
3028 GtkCMCTreeRow *new_row;
3029 GtkCMCTreeNode *node;
3034 stock_pixmap_gdk(GTK_WIDGET(ctree), STOCK_PIXMAP_EMPTY,
3035 &emptyxpm, &emptyxpmmask);
3037 if (!pixmap_closed) {
3038 pixmap_closed = emptyxpm;
3039 mask_closed = emptyxpmmask;
3041 if (!pixmap_opened) {
3042 pixmap_opened = emptyxpm;
3043 mask_opened = emptyxpmmask;
3045 g_return_val_if_fail (GTK_IS_CMCTREE (ctree), NULL);
3047 g_return_val_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent, NULL);
3049 if (parent && GTK_CMCTREE_ROW (parent)->is_leaf)
3052 clist = GTK_CMCLIST (ctree);
3054 /* create the row */
3055 new_row = srow_new (ctree);
3056 list = g_list_alloc ();
3057 list->data = new_row;
3058 node = GTK_CMCTREE_NODE (list);
3061 for (i = 0; i < clist->columns; i++)
3062 if (text[i] && i != ctree->tree_column)
3063 GTK_CMCLIST_GET_CLASS (clist)->set_cell_contents
3064 (clist, &(new_row->row), i, GTK_CMCELL_TEXT, text[i], 0, NULL, NULL);
3066 sset_node_info (ctree, node, text ?
3067 text[ctree->tree_column] : NULL, spacing, pixmap_closed,
3068 mask_closed, pixmap_opened, mask_opened, is_leaf, expanded);
3070 /* sorted insertion */
3071 if (GTK_CMCLIST_AUTO_SORT (clist))
3074 sibling = GTK_CMCTREE_ROW (parent)->children;
3076 sibling = GTK_CMCTREE_NODE (clist->row_list);
3078 while (sibling && clist->compare
3079 (clist, GTK_CMCTREE_ROW (node), GTK_CMCTREE_ROW (sibling)) > 0)
3080 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
3083 gtk_sctree_link (ctree, node, parent, sibling, FALSE);
3085 if (text && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist) &&
3086 gtk_cmctree_is_viewable (ctree, node))
3088 for (i = 0; i < clist->columns; i++)
3089 if (clist->column[i].auto_resize)
3090 gtk_sctree_column_auto_resize (clist, &(new_row->row), i, 0);
3093 if (clist->rows == 1)
3095 clist->focus_row = 0;
3096 if (clist->selection_mode == GTK_SELECTION_BROWSE)
3097 gtk_sctree_select (GTK_SCTREE(ctree), node);
3101 CLIST_REFRESH (clist);
3107 gtk_sctree_insert_gnode (GtkCMCTree *ctree,
3108 GtkCMCTreeNode *parent,
3109 GtkCMCTreeNode *sibling,
3111 GtkCMCTreeGNodeFunc func,
3115 GtkCMCTreeNode *cnode = NULL;
3116 GtkCMCTreeNode *child = NULL;
3117 GtkCMCTreeNode *new_child;
3122 g_return_val_if_fail (GTK_IS_CMCTREE (ctree), NULL);
3123 g_return_val_if_fail (gnode != NULL, NULL);
3124 g_return_val_if_fail (func != NULL, NULL);
3126 g_return_val_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent, NULL);
3128 clist = GTK_CMCLIST (ctree);
3131 depth = GTK_CMCTREE_ROW (parent)->level + 1;
3133 list = g_list_alloc ();
3134 list->data = srow_new (ctree);
3135 cnode = GTK_CMCTREE_NODE (list);
3137 gtk_cmclist_freeze (clist);
3139 sset_node_info (ctree, cnode, "", 0, NULL, NULL, NULL, NULL, TRUE, FALSE);
3141 if (!func (ctree, depth, gnode, cnode, data))
3143 stree_delete_row (ctree, cnode, NULL);
3144 gtk_cmclist_thaw (clist);
3148 if (GTK_CMCLIST_AUTO_SORT (clist))
3151 sibling = GTK_CMCTREE_ROW (parent)->children;
3153 sibling = GTK_CMCTREE_NODE (clist->row_list);
3155 while (sibling && clist->compare
3156 (clist, GTK_CMCTREE_ROW (cnode), GTK_CMCTREE_ROW (sibling)) > 0)
3157 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
3160 gtk_sctree_link (ctree, cnode, parent, sibling, FALSE);
3162 for (work = g_node_last_child (gnode); work; work = work->prev)
3164 new_child = gtk_sctree_insert_gnode (ctree, cnode, child,
3170 gtk_cmclist_thaw (clist);
3176 sreal_tree_move (GtkCMCTree *ctree,
3177 GtkCMCTreeNode *node,
3178 GtkCMCTreeNode *new_parent,
3179 GtkCMCTreeNode *new_sibling)
3182 GtkCMCTreeNode *work;
3183 gboolean visible = FALSE;
3185 g_return_if_fail (ctree != NULL);
3186 g_return_if_fail (node != NULL);
3187 g_return_if_fail (!new_sibling ||
3188 GTK_CMCTREE_ROW (new_sibling)->parent == new_parent);
3190 if (new_parent && GTK_CMCTREE_ROW (new_parent)->is_leaf)
3193 /* new_parent != child of child */
3194 for (work = new_parent; work; work = GTK_CMCTREE_ROW (work)->parent)
3198 clist = GTK_CMCLIST (ctree);
3200 visible = gtk_cmctree_is_viewable (ctree, node);
3202 if (clist->selection_mode == GTK_SELECTION_MULTIPLE)
3204 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
3206 g_list_free (clist->undo_selection);
3207 g_list_free (clist->undo_unselection);
3208 clist->undo_selection = NULL;
3209 clist->undo_unselection = NULL;
3212 if (GTK_CMCLIST_AUTO_SORT (clist))
3214 if (new_parent == GTK_CMCTREE_ROW (node)->parent)
3218 new_sibling = GTK_CMCTREE_ROW (new_parent)->children;
3220 new_sibling = GTK_CMCTREE_NODE (clist->row_list);
3222 while (new_sibling && clist->compare
3223 (clist, GTK_CMCTREE_ROW (node), GTK_CMCTREE_ROW (new_sibling)) > 0)
3224 new_sibling = GTK_CMCTREE_ROW (new_sibling)->sibling;
3227 if (new_parent == GTK_CMCTREE_ROW (node)->parent &&
3228 new_sibling == GTK_CMCTREE_ROW (node)->sibling)
3231 gtk_cmclist_freeze (clist);
3235 if (!GTK_SCTREE(ctree)->sorting && gtk_cmctree_is_viewable (ctree, node))
3236 work = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
3238 gtk_sctree_unlink (ctree, node, FALSE);
3239 gtk_sctree_link (ctree, node, new_parent, new_sibling, FALSE);
3241 if (!GTK_SCTREE(ctree)->sorting && work)
3243 while (work && !gtk_cmctree_is_viewable (ctree, work))
3244 work = GTK_CMCTREE_ROW (work)->parent;
3245 clist->focus_row = g_list_position (clist->row_list, (GList *)work);
3246 clist->undo_anchor = clist->focus_row;
3249 if (clist->column[ctree->tree_column].auto_resize &&
3250 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist) &&
3251 (visible || gtk_cmctree_is_viewable (ctree, node)))
3252 gtk_cmclist_set_column_width
3253 (clist, ctree->tree_column,
3254 gtk_cmclist_optimal_column_width (clist, ctree->tree_column));
3256 gtk_cmclist_thaw (clist);
3259 void gtk_sctree_set_column_tooltip (GtkSCTree *sctree,
3263 #if !(GTK_CHECK_VERSION(2,12,0))
3265 if (!sctree->tooltips)
3266 sctree->tooltips = gtk_tooltips_new();
3267 tips = sctree->tooltips;
3270 CLAWS_SET_TIP(GTK_CMCLIST(sctree)->column[column].button,