2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
4 * Copyright (C) 1999-2009 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 /* We know this file uses some deprecated stuff. */
32 #undef G_DISABLE_DEPRECATED
33 #undef GTK_DISABLE_DEPRECATED
34 #undef GDK_DISABLE_DEPRECATED
36 #include "gtksctree.h"
37 #include "claws-marshal.h"
38 #include "prefs_common.h"
42 #define CLIST_UNFROZEN(clist) (((GtkCMCList*) (clist))->freeze_count == 0)
43 #define CLIST_REFRESH(clist) G_STMT_START { \
44 if (CLIST_UNFROZEN (clist)) \
45 GTK_CMCLIST_GET_CLASS (clist)->refresh ((GtkCMCList*) (clist)); \
47 #define CELL_SPACING 1
48 #define CLIST_OPTIMUM_SIZE 64
49 #define COLUMN_INSET 3
51 #define TAB_SIZE (PM_SIZE + 6)
52 #define ROW_TOP_YPIXEL(clist, row) (((clist)->row_height * (row)) + \
53 (((row) + 1) * CELL_SPACING) + \
55 #define ROW_FROM_YPIXEL(clist, y) (((y) - (clist)->voffset) / \
56 ((clist)->row_height + CELL_SPACING))
57 #define COLUMN_LEFT_XPIXEL(clist, col) ((clist)->column[(col)].area.x \
59 #define COLUMN_LEFT(clist, column) ((clist)->column[(column)].area.x)
69 static void gtk_sctree_class_init (GtkSCTreeClass *class);
70 static void gtk_sctree_init (GtkSCTree *sctree);
72 static gint gtk_sctree_button_press (GtkWidget *widget, GdkEventButton *event);
73 static gint gtk_sctree_button_release (GtkWidget *widget, GdkEventButton *event);
74 static gint gtk_sctree_motion (GtkWidget *widget, GdkEventMotion *event);
75 static void gtk_sctree_drag_begin (GtkWidget *widget, GdkDragContext *context);
76 static void gtk_sctree_drag_end (GtkWidget *widget, GdkDragContext *context);
77 static void gtk_sctree_drag_data_get (GtkWidget *widget, GdkDragContext *context,
78 GtkSelectionData *data, guint info, guint time);
79 static void gtk_sctree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time);
80 static gboolean gtk_sctree_drag_motion (GtkWidget *widget, GdkDragContext *context,
81 gint x, gint y, guint time);
82 static gboolean gtk_sctree_drag_drop (GtkWidget *widget, GdkDragContext *context,
83 gint x, gint y, guint time);
84 static void gtk_sctree_drag_data_received (GtkWidget *widget, GdkDragContext *context,
85 gint x, gint y, GtkSelectionData *data,
86 guint info, guint time);
88 static void gtk_sctree_clear (GtkCMCList *clist);
89 static void gtk_sctree_real_unselect_all (GtkCMCList *clist);
91 static void stree_sort (GtkCMCTree *ctree, GtkCMCTreeNode *node, gpointer data);
92 void gtk_sctree_sort_node (GtkCMCTree *ctree, GtkCMCTreeNode *node);
93 void gtk_sctree_sort_recursive (GtkCMCTree *ctree, GtkCMCTreeNode *node);
95 static void gtk_sctree_link (GtkCMCTree *ctree,
97 GtkCMCTreeNode *parent,
98 GtkCMCTreeNode *sibling,
99 gboolean update_focus_row);
101 static void gtk_sctree_unlink (GtkCMCTree *ctree,
102 GtkCMCTreeNode *node,
103 gboolean update_focus_row);
105 static void stree_update_level (GtkCMCTree *ctree,
106 GtkCMCTreeNode *node,
109 static GtkCMCTreeNode * gtk_sctree_last_visible (GtkCMCTree *ctree,
110 GtkCMCTreeNode *node);
111 static void gtk_sctree_real_tree_expand (GtkCMCTree *ctree,
112 GtkCMCTreeNode *node);
113 static void gtk_sctree_real_tree_collapse (GtkCMCTree *ctree,
114 GtkCMCTreeNode *node);
116 sreal_tree_move (GtkCMCTree *ctree,
117 GtkCMCTreeNode *node,
118 GtkCMCTreeNode *new_parent,
119 GtkCMCTreeNode *new_sibling);
121 static GtkCMCTreeClass *parent_class;
123 static guint sctree_signals[LAST_SIGNAL];
126 * gtk_sctree_get_type:
129 * Creates the GtkSCTree class and its type information
131 * Return value: The type ID for GtkSCTreeClass
134 gtk_sctree_get_type (void)
136 static GType sctree_type = 0;
139 GTypeInfo sctree_info = {
140 sizeof (GtkSCTreeClass),
142 (GBaseInitFunc) NULL,
143 (GBaseFinalizeFunc) NULL,
145 (GClassInitFunc) gtk_sctree_class_init,
146 (GClassFinalizeFunc) NULL,
147 NULL, /* class_data */
151 (GInstanceInitFunc) gtk_sctree_init,
154 sctree_type = g_type_register_static (GTK_TYPE_CMCTREE, "GtkSCTree", &sctree_info, (GTypeFlags)0);
161 gtk_sctree_draw_cell_pixbuf (GdkWindow *window,
162 GdkRectangle *clip_rectangle,
173 gdk_gc_set_clip_origin (fg_gc, x, y);
174 if (x < clip_rectangle->x)
176 xsrc = clip_rectangle->x - x;
178 x = clip_rectangle->x;
180 if (x + width > clip_rectangle->x + clip_rectangle->width)
181 width = clip_rectangle->x + clip_rectangle->width - x;
183 if (y < clip_rectangle->y)
185 ysrc = clip_rectangle->y - y;
187 y = clip_rectangle->y;
189 if (y + height > clip_rectangle->y + clip_rectangle->height)
190 height = clip_rectangle->y + clip_rectangle->height - y;
192 if (width > 0 && height > 0)
193 gdk_draw_pixbuf (window, fg_gc, pixbuf, xsrc, ysrc, x, y, width, height, GDK_RGB_DITHER_NONE, 0, 0);
195 gdk_gc_set_clip_origin (fg_gc, 0, 0);
197 return x + MAX (width, 0);
201 gtk_sctree_get_cell_style (GtkCMCList *clist,
202 GtkCMCListRow *clist_row,
212 if ((state == GTK_STATE_NORMAL) &&
213 (GTK_WIDGET (clist)->state == GTK_STATE_INSENSITIVE))
214 fg_state = GTK_STATE_INSENSITIVE;
218 if (clist_row->cell[column].style)
221 *style = clist_row->cell[column].style;
223 *fg_gc = clist_row->cell[column].style->fg_gc[fg_state];
225 if (state == GTK_STATE_SELECTED)
226 *bg_gc = clist_row->cell[column].style->bg_gc[state];
229 else if (clist_row->style)
232 *style = clist_row->style;
234 *fg_gc = clist_row->style->fg_gc[fg_state];
236 if (state == GTK_STATE_SELECTED)
237 *bg_gc = clist_row->style->bg_gc[state];
239 *bg_gc = clist_row->bg_set ?
240 clist->bg_gc : clist_row->style->base_gc[state];
246 *style = GTK_WIDGET (clist)->style;
248 *fg_gc = GTK_WIDGET (clist)->style->fg_gc[fg_state];
250 if (state == GTK_STATE_SELECTED)
251 *bg_gc = GTK_WIDGET (clist)->style->bg_gc[state];
253 *bg_gc = GTK_WIDGET (clist)->style->base_gc[state];
256 if (state != GTK_STATE_SELECTED)
258 if (fg_gc && clist_row->fg_set)
259 *fg_gc = clist->fg_gc;
260 if (bg_gc && clist_row->bg_set)
261 *bg_gc = clist->bg_gc;
267 gtk_sctree_draw_expander (GtkCMCTree *ctree,
268 GtkCMCTreeRow *ctree_row,
270 GdkRectangle *clip_rectangle,
275 gint justification_factor;
278 if (ctree->expander_style == GTK_CMCTREE_EXPANDER_NONE)
281 clist = GTK_CMCLIST (ctree);
282 if (clist->column[ctree->tree_column].justification == GTK_JUSTIFY_RIGHT)
283 justification_factor = -1;
285 justification_factor = 1;
286 if (!GTK_CMCLIST_ROW_HEIGHT_SET(GTK_CMCLIST(clist)))
287 y = (clip_rectangle->y + (clip_rectangle->height - PM_SIZE) / 2 -
288 (clip_rectangle->height + 1) % 2);
290 y = (clip_rectangle->y + (clip_rectangle->height/2 - PM_SIZE) / 2 -
291 (clip_rectangle->height/2 + 1) % 2);
293 if (!ctree_row->children)
295 switch (ctree->expander_style)
297 case GTK_CMCTREE_EXPANDER_NONE:
299 case GTK_CMCTREE_EXPANDER_TRIANGLE:
300 return x + justification_factor * (PM_SIZE + 3);
301 case GTK_CMCTREE_EXPANDER_SQUARE:
302 case GTK_CMCTREE_EXPANDER_CIRCULAR:
303 return x + justification_factor * (PM_SIZE + 1);
307 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], clip_rectangle);
308 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], clip_rectangle);
310 switch (ctree->expander_style)
312 case GTK_CMCTREE_EXPANDER_NONE:
314 case GTK_CMCTREE_EXPANDER_TRIANGLE:
315 if (ctree_row->expanded)
318 points[0].y = y + (PM_SIZE + 2) / 6;
319 points[1].x = points[0].x + justification_factor * (PM_SIZE + 2);
320 points[1].y = points[0].y;
321 points[2].x = (points[0].x +
322 justification_factor * (PM_SIZE + 2) / 2);
323 points[2].y = y + 2 * (PM_SIZE + 2) / 3;
327 points[0].x = x + justification_factor * ((PM_SIZE + 2) / 6 + 2);
329 points[1].x = points[0].x;
330 points[1].y = points[0].y + (PM_SIZE + 2);
331 points[2].x = (points[0].x +
332 justification_factor * (2 * (PM_SIZE + 2) / 3 - 1));
333 points[2].y = points[0].y + (PM_SIZE + 2) / 2;
336 gdk_draw_polygon (clist->clist_window, style->base_gc[GTK_STATE_NORMAL],
338 gdk_draw_polygon (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
341 x += justification_factor * (PM_SIZE + 3);
343 case GTK_CMCTREE_EXPANDER_SQUARE:
344 case GTK_CMCTREE_EXPANDER_CIRCULAR:
345 if (justification_factor == -1)
346 x += justification_factor * (PM_SIZE + 1);
348 if (ctree->expander_style == GTK_CMCTREE_EXPANDER_CIRCULAR)
350 gdk_draw_arc (clist->clist_window, style->base_gc[GTK_STATE_NORMAL],
351 TRUE, x, y, PM_SIZE, PM_SIZE, 0, 360 * 64);
352 gdk_draw_arc (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
353 FALSE, x, y, PM_SIZE, PM_SIZE, 0, 360 * 64);
357 gdk_draw_rectangle (clist->clist_window,
358 style->base_gc[GTK_STATE_NORMAL], TRUE,
359 x, y, PM_SIZE, PM_SIZE);
360 gdk_draw_rectangle (clist->clist_window,
361 style->fg_gc[GTK_STATE_NORMAL], FALSE,
362 x, y, PM_SIZE, PM_SIZE);
365 gdk_draw_line (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
366 x + 2, y + PM_SIZE / 2, x + PM_SIZE - 2, y + PM_SIZE / 2);
368 if (!ctree_row->expanded)
369 gdk_draw_line (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
370 x + PM_SIZE / 2, y + 2,
371 x + PM_SIZE / 2, y + PM_SIZE - 2);
373 if (justification_factor == 1)
374 x += justification_factor * (PM_SIZE + 1);
378 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
379 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
385 gtk_sctree_draw_lines (GtkCMCTree *ctree,
386 GtkCMCTreeRow *ctree_row,
390 GdkRectangle *clip_rectangle,
391 GdkRectangle *cell_rectangle,
397 GtkCMCTreeNode *node;
398 GtkCMCTreeNode *parent;
399 GdkRectangle tree_rectangle;
400 GdkRectangle tc_rectangle;
411 gint justification_factor;
413 clist = GTK_CMCLIST (ctree);
414 ycenter = clip_rectangle->y + (clip_rectangle->height / 2);
415 justify_right = (clist->column[column].justification == GTK_JUSTIFY_RIGHT);
419 offset = (clip_rectangle->x + clip_rectangle->width - 1 -
420 ctree->tree_indent * (ctree_row->level - 1));
421 justification_factor = -1;
425 offset = clip_rectangle->x + ctree->tree_indent * (ctree_row->level - 1);
426 justification_factor = 1;
429 switch (ctree->line_style)
431 case GTK_CMCTREE_LINES_NONE:
433 case GTK_CMCTREE_LINES_TABBED:
434 xcenter = offset + justification_factor * TAB_SIZE;
436 column_right = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) +
437 clist->column[ctree->tree_column].area.width +
439 column_left = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) -
440 COLUMN_INSET - CELL_SPACING);
444 tree_rectangle.y = crect->y;
445 tree_rectangle.height = crect->height;
449 tree_rectangle.x = xcenter;
450 tree_rectangle.width = column_right - xcenter;
454 tree_rectangle.x = column_left;
455 tree_rectangle.width = xcenter - column_left;
458 if (!gdk_rectangle_intersect (area, &tree_rectangle, &tc_rectangle))
460 offset += justification_factor * 3;
465 gdk_gc_set_clip_rectangle (ctree->lines_gc, crect);
467 next_level = ctree_row->level;
469 if (!ctree_row->sibling || (ctree_row->children && ctree_row->expanded))
471 node = gtk_cmctree_find_node_ptr (ctree, ctree_row);
472 if (GTK_CMCTREE_NODE_NEXT (node))
473 next_level = GTK_CMCTREE_ROW (GTK_CMCTREE_NODE_NEXT (node))->level;
478 if (ctree->tree_indent > 0)
480 node = ctree_row->parent;
483 xcenter -= (justification_factor * ctree->tree_indent);
485 if ((justify_right && xcenter < column_left) ||
486 (!justify_right && xcenter > column_right))
488 node = GTK_CMCTREE_ROW (node)->parent;
492 tree_rectangle.y = cell_rectangle->y;
493 tree_rectangle.height = cell_rectangle->height;
496 tree_rectangle.x = MAX (xcenter - ctree->tree_indent + 1,
498 tree_rectangle.width = MIN (xcenter - column_left,
503 tree_rectangle.x = xcenter;
504 tree_rectangle.width = MIN (column_right - xcenter,
508 if (!area || gdk_rectangle_intersect (area, &tree_rectangle,
511 gtk_sctree_get_cell_style (clist, >K_CMCTREE_ROW (node)->row,
512 state, row, column, NULL, NULL, &bg_gc);
514 if (bg_gc == clist->bg_gc)
515 gdk_gc_set_foreground
516 (clist->bg_gc, >K_CMCTREE_ROW (node)->row.background);
519 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
522 tree_rectangle.width,
523 tree_rectangle.height);
525 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
529 tc_rectangle.height);
531 if (next_level > GTK_CMCTREE_ROW (node)->level)
532 gdk_draw_line (clist->clist_window, ctree->lines_gc,
534 xcenter, crect->y + crect->height);
539 offset_x = MIN (ctree->tree_indent, 2 * TAB_SIZE);
540 width = offset_x / 2 + offset_x % 2;
542 parent = GTK_CMCTREE_ROW (node)->parent;
544 tree_rectangle.y = ycenter;
545 tree_rectangle.height = (cell_rectangle->y - ycenter +
546 cell_rectangle->height);
550 tree_rectangle.x = MAX(xcenter + 1 - width, column_left);
551 tree_rectangle.width = MIN (xcenter + 1 - column_left,
556 tree_rectangle.x = xcenter;
557 tree_rectangle.width = MIN (column_right - xcenter,
562 gdk_rectangle_intersect (area, &tree_rectangle,
567 gtk_sctree_get_cell_style (clist, >K_CMCTREE_ROW (parent)->row,
568 state, row, column, NULL, NULL, &bg_gc);
569 if (bg_gc == clist->bg_gc)
570 gdk_gc_set_foreground
572 >K_CMCTREE_ROW (parent)->row.background);
574 else if (state == GTK_STATE_SELECTED)
575 bg_gc = style->base_gc[state];
577 bg_gc = GTK_WIDGET (clist)->style->base_gc[state];
580 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
583 tree_rectangle.width,
584 tree_rectangle.height);
586 gdk_draw_rectangle (clist->clist_window,
591 tc_rectangle.height);
594 gtk_sctree_get_cell_style (clist, >K_CMCTREE_ROW (node)->row,
595 state, row, column, NULL, NULL, &bg_gc);
596 if (bg_gc == clist->bg_gc)
597 gdk_gc_set_foreground
598 (clist->bg_gc, >K_CMCTREE_ROW (node)->row.background);
600 gdk_gc_set_clip_rectangle (bg_gc, crect);
601 gdk_draw_arc (clist->clist_window, bg_gc, TRUE,
602 xcenter - (justify_right * offset_x),
604 offset_x, clist->row_height,
605 (180 + (justify_right * 90)) * 64, 90 * 64);
606 gdk_gc_set_clip_rectangle (bg_gc, NULL);
608 gdk_draw_line (clist->clist_window, ctree->lines_gc,
609 xcenter, cell_rectangle->y, xcenter, ycenter);
612 gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
613 xcenter - offset_x, cell_rectangle->y,
614 offset_x, clist->row_height,
617 gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
618 xcenter, cell_rectangle->y,
619 offset_x, clist->row_height,
622 node = GTK_CMCTREE_ROW (node)->parent;
626 if (state != GTK_STATE_SELECTED)
628 tree_rectangle.y = clip_rectangle->y;
629 tree_rectangle.height = clip_rectangle->height;
630 tree_rectangle.width = COLUMN_INSET + CELL_SPACING +
631 MIN (clist->column[ctree->tree_column].area.width + COLUMN_INSET,
635 tree_rectangle.x = MAX (xcenter + 1, column_left);
637 tree_rectangle.x = column_left;
640 gdk_draw_rectangle (clist->clist_window,
642 (ctree)->style->base_gc[GTK_STATE_NORMAL],
646 tree_rectangle.width,
647 tree_rectangle.height);
648 else if (gdk_rectangle_intersect (area, &tree_rectangle,
650 gdk_draw_rectangle (clist->clist_window,
652 (ctree)->style->base_gc[GTK_STATE_NORMAL],
657 tc_rectangle.height);
660 xcenter = offset + (justification_factor * ctree->tree_indent / 2);
662 gtk_sctree_get_cell_style (clist, &ctree_row->row, state, row, column, NULL, NULL,
664 if (bg_gc == clist->bg_gc)
665 gdk_gc_set_foreground (clist->bg_gc, &ctree_row->row.background);
667 gdk_gc_set_clip_rectangle (bg_gc, crect);
668 if (ctree_row->is_leaf)
672 points[0].x = offset + justification_factor * TAB_SIZE;
673 points[0].y = cell_rectangle->y;
675 points[1].x = points[0].x - justification_factor * 4;
676 points[1].y = points[0].y;
678 points[2].x = points[1].x - justification_factor * 2;
679 points[2].y = points[1].y + 3;
681 points[3].x = points[2].x;
682 points[3].y = points[2].y + clist->row_height - 5;
684 points[4].x = points[3].x + justification_factor * 2;
685 points[4].y = points[3].y + 3;
687 points[5].x = points[4].x + justification_factor * 4;
688 points[5].y = points[4].y;
690 gdk_draw_polygon (clist->clist_window, bg_gc, TRUE, points, 6);
691 gdk_draw_lines (clist->clist_window, ctree->lines_gc, points, 6);
695 gdk_draw_arc (clist->clist_window, bg_gc, TRUE,
696 offset - (justify_right * 2 * TAB_SIZE),
698 2 * TAB_SIZE, clist->row_height,
699 (90 + (180 * justify_right)) * 64, 180 * 64);
700 gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
701 offset - (justify_right * 2 * TAB_SIZE),
703 2 * TAB_SIZE, clist->row_height,
704 (90 + (180 * justify_right)) * 64, 180 * 64);
706 gdk_gc_set_clip_rectangle (bg_gc, NULL);
707 gdk_gc_set_clip_rectangle (ctree->lines_gc, NULL);
709 offset += justification_factor * 3;
712 xcenter = offset + justification_factor * PM_SIZE / 2;
716 tree_rectangle.y = crect->y;
717 tree_rectangle.height = crect->height;
721 tree_rectangle.x = xcenter - PM_SIZE / 2 - 2;
722 tree_rectangle.width = (clip_rectangle->x +
723 clip_rectangle->width -tree_rectangle.x);
727 tree_rectangle.x = clip_rectangle->x + PM_SIZE / 2;
728 tree_rectangle.width = (xcenter + PM_SIZE / 2 + 2 -
732 if (!gdk_rectangle_intersect (area, &tree_rectangle, &tc_rectangle))
738 if (ctree->line_style == GTK_CMCTREE_LINES_DOTTED)
740 offset_x += abs((clip_rectangle->x + clist->hoffset) % 2);
741 offset_y = abs((cell_rectangle->y + clist->voffset) % 2);
745 clip_rectangle->height++;
746 gdk_gc_set_clip_rectangle (ctree->lines_gc, clip_rectangle);
747 gdk_draw_line (clist->clist_window, ctree->lines_gc,
749 (ctree->show_stub || clist->row_list->data != ctree_row) ?
750 cell_rectangle->y + offset_y : ycenter,
752 (ctree_row->sibling) ? crect->y +crect->height : ycenter);
754 gdk_draw_line (clist->clist_window, ctree->lines_gc,
755 xcenter + (justification_factor * offset_x), ycenter,
756 xcenter + (justification_factor * (PM_SIZE / 2 + 2)),
759 node = ctree_row->parent;
762 xcenter -= (justification_factor * ctree->tree_indent);
764 if (GTK_CMCTREE_ROW (node)->sibling)
765 gdk_draw_line (clist->clist_window, ctree->lines_gc,
766 xcenter, cell_rectangle->y + offset_y,
767 xcenter, crect->y + crect->height);
768 node = GTK_CMCTREE_ROW (node)->parent;
770 gdk_gc_set_clip_rectangle (ctree->lines_gc, NULL);
772 clip_rectangle->height--;
778 static gboolean filter_fg (PangoAttribute *attribute, gpointer data)
780 const PangoAttrClass *klass = attribute->klass;
781 if (klass->type == PANGO_ATTR_FOREGROUND)
788 sc_gtk_cmclist_create_cell_layout (GtkCMCList *clist,
789 GtkCMCListRow *clist_row,
797 gtk_sctree_get_cell_style (clist, clist_row, GTK_STATE_NORMAL, 0, column, &style,
801 cell = &clist_row->cell[column];
804 case GTK_CMCELL_TEXT:
805 case GTK_CMCELL_PIXTEXT:
806 text = ((cell->type == GTK_CMCELL_PIXTEXT) ?
807 GTK_CMCELL_PIXTEXT (*cell)->text :
808 GTK_CMCELL_TEXT (*cell)->text);
813 if (!GTK_SCTREE(clist)->use_markup[column]) {
814 layout = gtk_widget_create_pango_layout (GTK_WIDGET (clist),
815 ((cell->type == GTK_CMCELL_PIXTEXT) ?
816 GTK_CMCELL_PIXTEXT (*cell)->text :
817 GTK_CMCELL_TEXT (*cell)->text));
818 pango_layout_set_font_description (layout, style->font_desc);
820 PangoContext *context = gtk_widget_get_pango_context (GTK_WIDGET(clist));
821 layout = pango_layout_new (context);
822 pango_layout_set_markup (layout, text, -1);
823 pango_layout_set_font_description (layout, style->font_desc);
824 if (clist_row->state == GTK_STATE_SELECTED) {
825 /* for selected row, we should remove any forced foreground color
826 * or it looks like shit */
827 PangoAttrList *list = pango_layout_get_attributes(layout);
828 PangoAttrList *rem = pango_attr_list_filter(list, filter_fg, NULL);
830 pango_attr_list_unref(rem);
842 gtk_sctree_draw_row (GtkCMCList *clist,
845 GtkCMCListRow *clist_row)
851 GdkRectangle row_rectangle;
852 GdkRectangle cell_rectangle;
853 GdkRectangle clip_rectangle;
854 GdkRectangle intersect_rectangle;
856 gint column_left = 0;
857 gint column_right = 0;
861 static GdkColor greybg={0, 0, 0, 0};
862 static gboolean color_change = TRUE;
864 if (greybg.pixel == 0 &&
868 GdkColor normalbg = {0, 0xffff, 0xffff, 0xffff};
869 if (GTK_WIDGET (clist)->style) {
870 normalbg = GTK_WIDGET (clist)->style->base[GTK_STATE_NORMAL];
872 if (normalbg.red > 0x8888 && normalbg.green > 0x8888 && normalbg.blue > 0x8888) {
873 greybg.pixel = normalbg.pixel;
874 greybg.red = normalbg.red - prefs_common.stripes_color_offset;
875 greybg.green = normalbg.green - prefs_common.stripes_color_offset;
876 greybg.blue = normalbg.blue - prefs_common.stripes_color_offset;
877 } else if (normalbg.red < 0x8888 && normalbg.green < 0x8888 && normalbg.blue < 0x8888) {
878 greybg.pixel = normalbg.pixel;
879 greybg.red = normalbg.red + prefs_common.stripes_color_offset;
880 greybg.green = normalbg.green + prefs_common.stripes_color_offset;
881 greybg.blue = normalbg.blue + prefs_common.stripes_color_offset;
883 color_change = FALSE;
887 cm_return_if_fail (clist != NULL);
889 /* bail now if we arn't drawable yet */
890 if (!gtkut_widget_is_drawable (GTK_WIDGET(clist)) || row < 0 || row >= clist->rows)
893 widget = GTK_WIDGET (clist);
894 ctree = GTK_CMCTREE (clist);
896 /* if the function is passed the pointer to the row instead of null,
897 * it avoids this expensive lookup */
899 clist_row = (g_list_nth (clist->row_list, row))->data;
901 /* rectangle of the entire row */
903 row_rectangle.y = ROW_TOP_YPIXEL (clist, row);
904 row_rectangle.width = clist->clist_window_width;
905 row_rectangle.height = clist->row_height;
907 /* rectangle of the cell spacing above the row */
908 cell_rectangle.x = 0;
909 cell_rectangle.y = row_rectangle.y - CELL_SPACING;
910 cell_rectangle.width = row_rectangle.width;
911 cell_rectangle.height = CELL_SPACING;
913 /* rectangle used to clip drawing operations, its y and height
914 * positions only need to be set once, so we set them once here.
915 * the x and width are set withing the drawing loop below once per
917 clip_rectangle.y = row_rectangle.y;
918 clip_rectangle.height = row_rectangle.height;
920 if (prefs_common.use_stripes_everywhere && GTK_SCTREE(ctree)->show_stripes
921 && color_change && row % 2) {
922 clist_row->background = greybg;
923 clist_row->bg_set = TRUE;
925 clist_row->bg_set = FALSE;
927 if (clist_row->state == GTK_STATE_NORMAL)
929 if (clist_row->fg_set)
930 gdk_gc_set_foreground (clist->fg_gc, &clist_row->foreground);
931 if (clist_row->bg_set)
932 gdk_gc_set_rgb_fg_color (clist->bg_gc, &clist_row->background);
935 state = clist_row->state;
937 gdk_gc_set_foreground (ctree->lines_gc,
938 &widget->style->fg[clist_row->state]);
940 /* draw the cell borders */
943 rect = &intersect_rectangle;
944 crect = &intersect_rectangle;
946 if (gdk_rectangle_intersect (area, &cell_rectangle, crect))
947 gdk_draw_rectangle (clist->clist_window,
948 widget->style->base_gc[GTK_STATE_NORMAL], TRUE,
949 crect->x, crect->y, crect->width, crect->height);
953 rect = &clip_rectangle;
954 crect = &cell_rectangle;
956 gdk_draw_rectangle (clist->clist_window,
957 widget->style->base_gc[GTK_STATE_NORMAL], TRUE,
958 crect->x, crect->y, crect->width, crect->height);
961 /* horizontal black lines */
962 if (ctree->line_style == GTK_CMCTREE_LINES_TABBED)
965 column_right = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) +
966 clist->column[ctree->tree_column].area.width +
968 column_left = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) -
969 COLUMN_INSET - (ctree->tree_column != 0) * CELL_SPACING);
971 switch (clist->column[ctree->tree_column].justification)
973 case GTK_JUSTIFY_CENTER:
974 case GTK_JUSTIFY_FILL:
975 case GTK_JUSTIFY_LEFT:
976 offset = (column_left + ctree->tree_indent *
977 (((GtkCMCTreeRow *)clist_row)->level - 1));
979 gdk_draw_line (clist->clist_window, ctree->lines_gc,
980 MIN (offset + TAB_SIZE, column_right),
982 clist->clist_window_width, cell_rectangle.y);
984 case GTK_JUSTIFY_RIGHT:
985 offset = (column_right - 1 - ctree->tree_indent *
986 (((GtkCMCTreeRow *)clist_row)->level - 1));
988 gdk_draw_line (clist->clist_window, ctree->lines_gc,
989 -1, cell_rectangle.y,
990 MAX (offset - TAB_SIZE, column_left),
996 /* the last row has to clear its bottom cell spacing too */
997 if (clist_row == clist->row_list_end->data)
999 cell_rectangle.y += clist->row_height + CELL_SPACING;
1001 if (!area || gdk_rectangle_intersect (area, &cell_rectangle, crect))
1003 gdk_draw_rectangle (clist->clist_window,
1004 widget->style->base_gc[GTK_STATE_NORMAL], TRUE,
1005 crect->x, crect->y, crect->width, crect->height);
1007 /* horizontal black lines */
1008 if (ctree->line_style == GTK_CMCTREE_LINES_TABBED)
1010 switch (clist->column[ctree->tree_column].justification)
1012 case GTK_JUSTIFY_CENTER:
1013 case GTK_JUSTIFY_FILL:
1014 case GTK_JUSTIFY_LEFT:
1015 gdk_draw_line (clist->clist_window, ctree->lines_gc,
1016 MIN (column_left + TAB_SIZE + COLUMN_INSET +
1017 (((GtkCMCTreeRow *)clist_row)->level > 1) *
1018 MIN (ctree->tree_indent / 2, TAB_SIZE),
1021 clist->clist_window_width, cell_rectangle.y);
1023 case GTK_JUSTIFY_RIGHT:
1024 gdk_draw_line (clist->clist_window, ctree->lines_gc,
1025 -1, cell_rectangle.y,
1026 MAX (column_right - TAB_SIZE - 1 -
1028 (((GtkCMCTreeRow *)clist_row)->level > 1) *
1029 MIN (ctree->tree_indent / 2, TAB_SIZE),
1030 column_left - 1), cell_rectangle.y);
1037 for (last_column = clist->columns - 1;
1038 last_column >= 0 && !clist->column[last_column].visible; last_column--)
1041 /* iterate and draw all the columns (row cells) and draw their contents */
1042 for (i = 0; i < clist->columns; i++)
1047 PangoLayout *layout = NULL;
1048 PangoRectangle logical_rect;
1056 if (!clist->column[i].visible)
1059 gtk_sctree_get_cell_style (clist, clist_row, state, row, i, &style, &fg_gc, &bg_gc);
1061 /* calculate clipping region */
1062 clip_rectangle.x = clist->column[i].area.x + clist->hoffset;
1063 clip_rectangle.width = clist->column[i].area.width;
1065 cell_rectangle.x = clip_rectangle.x - COLUMN_INSET - CELL_SPACING;
1066 cell_rectangle.width = (clip_rectangle.width + 2 * COLUMN_INSET +
1067 (1 + (i == last_column)) * CELL_SPACING);
1068 cell_rectangle.y = clip_rectangle.y;
1069 cell_rectangle.height = clip_rectangle.height;
1075 if (area && !gdk_rectangle_intersect (area, &cell_rectangle,
1076 &intersect_rectangle))
1078 if (i != ctree->tree_column)
1083 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
1084 crect->x, crect->y, crect->width, crect->height);
1087 layout = sc_gtk_cmclist_create_cell_layout (clist, clist_row, i);
1090 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1091 width = logical_rect.width;
1096 switch (clist_row->cell[i].type)
1098 case GTK_CMCELL_PIXBUF:
1099 pixbuf_width = gdk_pixbuf_get_width(GTK_CMCELL_PIXBUF (clist_row->cell[i])->pixbuf);
1100 height = gdk_pixbuf_get_height(GTK_CMCELL_PIXBUF (clist_row->cell[i])->pixbuf);
1101 width += pixbuf_width;
1103 case GTK_CMCELL_PIXTEXT:
1104 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf)
1106 pixbuf_width = gdk_pixbuf_get_width(GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf);
1107 height = gdk_pixbuf_get_height(GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf);
1108 width += pixbuf_width;
1111 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->text &&
1112 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf)
1113 width += GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1115 if (i == ctree->tree_column)
1116 width += (ctree->tree_indent *
1117 ((GtkCMCTreeRow *)clist_row)->level);
1123 switch (clist->column[i].justification)
1125 case GTK_JUSTIFY_LEFT:
1126 offset = clip_rectangle.x + clist_row->cell[i].horizontal;
1128 case GTK_JUSTIFY_RIGHT:
1129 offset = (clip_rectangle.x + clist_row->cell[i].horizontal +
1130 clip_rectangle.width - width);
1132 case GTK_JUSTIFY_CENTER:
1133 case GTK_JUSTIFY_FILL:
1134 offset = (clip_rectangle.x + clist_row->cell[i].horizontal +
1135 (clip_rectangle.width / 2) - (width / 2));
1139 if (i != ctree->tree_column)
1141 int start_y = (clip_rectangle.height - height) / 2;
1142 if (GTK_CMCLIST_ROW_HEIGHT_SET(GTK_CMCLIST(clist)))
1143 start_y = (clip_rectangle.height/2 - height) / 2;
1145 offset += clist_row->cell[i].horizontal;
1146 switch (clist_row->cell[i].type)
1148 case GTK_CMCELL_PIXBUF:
1149 gtk_sctree_draw_cell_pixbuf
1150 (clist->clist_window, &clip_rectangle, fg_gc,
1151 GTK_CMCELL_PIXBUF (clist_row->cell[i])->pixbuf,
1153 clip_rectangle.y + clist_row->cell[i].vertical +
1155 pixbuf_width, height);
1157 case GTK_CMCELL_PIXTEXT:
1158 offset = gtk_sctree_draw_cell_pixbuf
1159 (clist->clist_window, &clip_rectangle, fg_gc,
1160 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf,
1162 clip_rectangle.y + clist_row->cell[i].vertical +
1164 pixbuf_width, height);
1165 offset += GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1168 case GTK_CMCELL_TEXT:
1171 gint row_center_offset = (clist->row_height - logical_rect.height) / 2;
1173 gdk_gc_set_clip_rectangle (fg_gc, &clip_rectangle);
1174 gdk_draw_layout (clist->clist_window, fg_gc,
1176 row_rectangle.y + row_center_offset + clist_row->cell[i].vertical,
1178 gdk_gc_set_clip_rectangle (fg_gc, NULL);
1179 g_object_unref (G_OBJECT (layout));
1189 if (bg_gc == clist->bg_gc)
1190 gdk_gc_set_background (ctree->lines_gc, &clist_row->background);
1192 /* draw ctree->tree_column */
1193 cell_rectangle.y -= CELL_SPACING;
1194 cell_rectangle.height += CELL_SPACING;
1196 if (area && !gdk_rectangle_intersect (area, &cell_rectangle,
1197 &intersect_rectangle))
1200 g_object_unref (G_OBJECT (layout));
1205 offset = gtk_sctree_draw_lines (ctree, (GtkCMCTreeRow *)clist_row, row, i,
1206 state, &clip_rectangle, &cell_rectangle,
1207 crect, area, style);
1210 offset = gtk_sctree_draw_expander (ctree, (GtkCMCTreeRow *)clist_row,
1211 style, &clip_rectangle, offset);
1213 if (clist->column[i].justification == GTK_JUSTIFY_RIGHT)
1214 offset -= ctree->tree_spacing;
1216 offset += ctree->tree_spacing;
1218 if (clist->column[i].justification == GTK_JUSTIFY_RIGHT)
1219 offset -= (pixbuf_width + clist_row->cell[i].horizontal);
1221 offset += clist_row->cell[i].horizontal;
1223 old_offset = offset;
1224 offset = gtk_sctree_draw_cell_pixbuf (clist->clist_window, &clip_rectangle, fg_gc,
1225 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf,
1227 clip_rectangle.y + clist_row->cell[i].vertical
1228 + (clip_rectangle.height - height) / 2,
1229 pixbuf_width, height);
1233 gint row_center_offset = (clist->row_height - logical_rect.height) / 2;
1235 if (clist->column[i].justification == GTK_JUSTIFY_RIGHT)
1237 offset = (old_offset - string_width);
1238 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf)
1239 offset -= GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1243 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf)
1244 offset += GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1247 gdk_gc_set_clip_rectangle (fg_gc, &clip_rectangle);
1248 gdk_draw_layout (clist->clist_window, fg_gc,
1250 row_rectangle.y + row_center_offset + clist_row->cell[i].vertical,
1253 g_object_unref (G_OBJECT (layout));
1255 gdk_gc_set_clip_rectangle (fg_gc, NULL);
1258 /* draw focus rectangle */
1259 if (clist->focus_row == row &&
1260 gtkut_widget_get_can_focus (widget) && gtkut_widget_has_focus (widget))
1263 gdk_draw_rectangle (clist->clist_window, clist->xor_gc, FALSE,
1264 row_rectangle.x, row_rectangle.y,
1265 row_rectangle.width - 1, row_rectangle.height - 1);
1266 else if (gdk_rectangle_intersect (area, &row_rectangle,
1267 &intersect_rectangle))
1269 gdk_gc_set_clip_rectangle (clist->xor_gc, &intersect_rectangle);
1270 gdk_draw_rectangle (clist->clist_window, clist->xor_gc, FALSE,
1271 row_rectangle.x, row_rectangle.y,
1272 row_rectangle.width - 1,
1273 row_rectangle.height - 1);
1274 gdk_gc_set_clip_rectangle (clist->xor_gc, NULL);
1280 gtk_sctree_change_focus_row_expansion (GtkCMCTree *ctree,
1281 GtkCMCTreeExpansionType action)
1284 GtkCMCTreeNode *node;
1286 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
1288 clist = GTK_CMCLIST (ctree);
1290 if (gdk_display_pointer_is_grabbed (gtk_widget_get_display (GTK_WIDGET (ctree))) &&
1291 gtkut_widget_has_grab (GTK_WIDGET(ctree)))
1295 GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row))) ||
1296 GTK_CMCTREE_ROW (node)->is_leaf || !(GTK_CMCTREE_ROW (node)->children))
1301 case GTK_CMCTREE_EXPANSION_EXPAND:
1302 if (GTK_SCTREE(ctree)->always_expand_recursively)
1303 gtk_cmctree_expand_recursive (ctree, node);
1305 gtk_cmctree_expand (ctree, node);
1308 case GTK_CMCTREE_EXPANSION_EXPAND_RECURSIVE:
1309 gtk_cmctree_expand_recursive (ctree, node);
1311 case GTK_CMCTREE_EXPANSION_COLLAPSE:
1312 gtk_cmctree_collapse (ctree, node);
1314 case GTK_CMCTREE_EXPANSION_COLLAPSE_RECURSIVE:
1315 gtk_cmctree_collapse_recursive (ctree, node);
1317 case GTK_CMCTREE_EXPANSION_TOGGLE:
1318 if (GTK_SCTREE(ctree)->always_expand_recursively)
1319 gtk_cmctree_toggle_expansion_recursive (ctree, node);
1321 gtk_cmctree_toggle_expansion (ctree, node);
1323 case GTK_CMCTREE_EXPANSION_TOGGLE_RECURSIVE:
1324 gtk_cmctree_toggle_expansion_recursive (ctree, node);
1329 static void gtk_sctree_finalize(GObject *object)
1331 GtkSCTree *sctree = GTK_SCTREE(object);
1332 g_free(sctree->use_markup);
1333 sctree->use_markup = NULL;
1334 G_OBJECT_CLASS (parent_class)->finalize (object);
1337 /* Standard class initialization function */
1339 gtk_sctree_class_init (GtkSCTreeClass *klass)
1341 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1342 GtkObjectClass *object_class;
1343 GtkWidgetClass *widget_class;
1344 GtkCMCListClass *clist_class;
1345 GtkCMCTreeClass *ctree_class;
1347 object_class = (GtkObjectClass *) klass;
1348 widget_class = (GtkWidgetClass *) klass;
1349 clist_class = (GtkCMCListClass *) klass;
1350 ctree_class = (GtkCMCTreeClass *) klass;
1352 parent_class = g_type_class_peek (gtk_cmctree_get_type ());
1354 sctree_signals[ROW_POPUP_MENU] =
1355 g_signal_new ("row_popup_menu",
1356 G_TYPE_FROM_CLASS (klass),
1358 G_STRUCT_OFFSET (GtkSCTreeClass, row_popup_menu),
1360 claws_marshal_VOID__POINTER,
1363 sctree_signals[EMPTY_POPUP_MENU] =
1364 g_signal_new ("empty_popup_menu",
1365 G_TYPE_FROM_CLASS (klass),
1367 G_STRUCT_OFFSET (GtkSCTreeClass, empty_popup_menu),
1369 claws_marshal_VOID__POINTER,
1372 sctree_signals[OPEN_ROW] =
1373 g_signal_new ("open_row",
1374 G_TYPE_FROM_CLASS (klass),
1376 G_STRUCT_OFFSET (GtkSCTreeClass, open_row),
1378 g_cclosure_marshal_VOID__VOID,
1380 sctree_signals[START_DRAG] =
1381 g_signal_new ("start_drag",
1382 G_TYPE_FROM_CLASS (klass),
1384 G_STRUCT_OFFSET (GtkSCTreeClass, start_drag),
1386 claws_marshal_VOID__INT_POINTER,
1391 /* gtk_object_class_add_signals (object_class, sctree_signals, LAST_SIGNAL); */
1393 clist_class->clear = gtk_sctree_clear;
1394 clist_class->draw_row = gtk_sctree_draw_row;
1395 clist_class->unselect_all = gtk_sctree_real_unselect_all;
1396 ctree_class->tree_collapse = gtk_sctree_real_tree_collapse;
1397 ctree_class->tree_expand = gtk_sctree_real_tree_expand;
1398 ctree_class->tree_move = sreal_tree_move;
1399 ctree_class->change_focus_row_expansion = gtk_sctree_change_focus_row_expansion;
1401 widget_class->button_press_event = gtk_sctree_button_press;
1402 widget_class->button_release_event = gtk_sctree_button_release;
1403 widget_class->motion_notify_event = gtk_sctree_motion;
1404 widget_class->drag_begin = gtk_sctree_drag_begin;
1405 widget_class->drag_end = gtk_sctree_drag_end;
1406 widget_class->drag_data_get = gtk_sctree_drag_data_get;
1407 widget_class->drag_leave = gtk_sctree_drag_leave;
1408 widget_class->drag_motion = gtk_sctree_drag_motion;
1409 widget_class->drag_drop = gtk_sctree_drag_drop;
1410 widget_class->drag_data_received = gtk_sctree_drag_data_received;
1412 gobject_class->finalize = gtk_sctree_finalize;
1415 /* Standard object initialization function */
1417 gtk_sctree_init (GtkSCTree *sctree)
1419 sctree->anchor_row = NULL;
1421 /* GtkCMCTree does not specify pointer motion by default */
1422 gtk_widget_add_events (GTK_WIDGET (sctree), GDK_POINTER_MOTION_MASK);
1423 gtk_widget_add_events (GTK_WIDGET (sctree), GDK_POINTER_MOTION_MASK);
1426 /* Get information the specified row is selected. */
1429 row_is_selected(GtkSCTree *sctree, gint row)
1431 GtkCMCListRow *clist_row;
1432 clist_row = g_list_nth (GTK_CMCLIST(sctree)->row_list, row)->data;
1433 return clist_row ? clist_row->state == GTK_STATE_SELECTED : FALSE;
1436 /* Selects the rows between the anchor to the specified row, inclusive. */
1438 select_range (GtkSCTree *sctree, gint row)
1444 if (sctree->anchor_row == NULL) {
1446 sctree->anchor_row = gtk_cmctree_node_nth(GTK_CMCTREE(sctree), row);
1448 prev_row = g_list_position(GTK_CMCLIST(sctree)->row_list,
1449 (GList *)sctree->anchor_row);
1451 if (row < prev_row) {
1454 GTK_CMCLIST(sctree)->focus_row = max;
1459 sctree->selecting_range++;
1468 gtk_cmclist_freeze(GTK_CMCLIST(sctree));
1470 node = g_list_nth((GTK_CMCLIST(sctree))->row_list, min);
1471 for (i = min; i < max; i++) {
1472 if (node && GTK_CMCTREE_ROW (node)->row.selectable) {
1473 g_signal_emit_by_name(G_OBJECT(sctree), "tree_select_row",
1479 gtk_cmclist_thaw(GTK_CMCLIST(sctree));
1482 sctree->selecting_range--;
1483 gtk_cmclist_select_row (GTK_CMCLIST (sctree), max, -1);
1486 /* Handles row selection according to the specified modifier state */
1487 /* in certain cases, we arrive here from a function knowing the GtkCMCTreeNode, and having
1488 * already slowly found row using g_list_position. In which case, _node will be non-NULL
1489 * to avoid this function having to slowly find it with g_list_nth. */
1491 select_row (GtkSCTree *sctree, gint row, gint col, guint state, GtkCMCTreeNode *_node)
1493 gboolean range, additive;
1494 cm_return_if_fail (sctree != NULL);
1495 cm_return_if_fail (GTK_IS_SCTREE (sctree));
1497 range = ((state & GDK_SHIFT_MASK) != 0) &&
1498 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_SINGLE) &&
1499 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_BROWSE);
1500 additive = ((state & GDK_CONTROL_MASK) != 0) &&
1501 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_SINGLE) &&
1502 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_BROWSE);
1504 if (!range && !additive && sctree->force_additive_sel)
1507 GTK_CMCLIST(sctree)->focus_row = row;
1510 gtk_cmclist_unselect_all (GTK_CMCLIST (sctree));
1514 GtkCMCTreeNode *node;
1516 node = _node ? _node : gtk_cmctree_node_nth (GTK_CMCTREE(sctree), row);
1518 /*No need to manage overlapped list*/
1520 if (row_is_selected(sctree, row))
1521 gtk_cmclist_unselect_row (GTK_CMCLIST (sctree), row, col);
1523 g_signal_emit_by_name
1525 "tree_select_row", node, col);
1527 g_signal_emit_by_name
1529 "tree_select_row", node, col);
1531 sctree->anchor_row = node;
1533 select_range (sctree, row);
1537 sctree_is_hot_spot (GtkSCTree *sctree,
1538 GtkCMCTreeNode *node,
1543 GtkCMCTreeRow *tree_row;
1546 GtkCMCellPixText *cell;
1550 cm_return_val_if_fail (GTK_IS_SCTREE (sctree), FALSE);
1551 cm_return_val_if_fail (node != NULL, FALSE);
1553 clist = GTK_CMCLIST (sctree);
1554 ctree = GTK_CMCTREE (sctree);
1556 if (!clist->column[ctree->tree_column].visible ||
1557 ctree->expander_style == GTK_CMCTREE_EXPANDER_NONE)
1560 tree_row = GTK_CMCTREE_ROW (node);
1562 cell = GTK_CMCELL_PIXTEXT (tree_row->row.cell[ctree->tree_column]);
1564 if (!GTK_CMCLIST_ROW_HEIGHT_SET(GTK_CMCLIST(clist)))
1565 yu = (ROW_TOP_YPIXEL (clist, row) + (clist->row_height - PM_SIZE) / 2 -
1566 (clist->row_height - 1) % 2);
1568 yu = (ROW_TOP_YPIXEL (clist, row) + (clist->row_height/2 - PM_SIZE) / 2 -
1569 (clist->row_height/2 - 1) % 2);
1571 #ifndef GENERIC_UMPC
1572 if (clist->column[ctree->tree_column].justification == GTK_JUSTIFY_RIGHT)
1573 xl = (clist->column[ctree->tree_column].area.x +
1574 clist->column[ctree->tree_column].area.width - 1 + clist->hoffset -
1575 (tree_row->level - 1) * ctree->tree_indent - PM_SIZE -
1576 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1578 xl = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1579 (tree_row->level - 1) * ctree->tree_indent +
1580 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1582 xmax = xl + PM_SIZE;
1584 if (clist->column[ctree->tree_column].justification == GTK_JUSTIFY_RIGHT) {
1585 xl = (clist->column[ctree->tree_column].area.x +
1586 clist->column[ctree->tree_column].area.width - 1 + clist->hoffset -
1587 (tree_row->level - 1) * ctree->tree_indent - PM_SIZE -
1588 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1589 xmax = xl + PM_SIZE;
1590 } else if (ctree->tree_column == 0) {
1591 xl = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1592 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1593 xmax = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1594 (tree_row->level - 1) * ctree->tree_indent +
1595 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3) +
1598 xl = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1599 (tree_row->level - 1) * ctree->tree_indent +
1600 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1601 xmax = xl + PM_SIZE;
1604 return (x >= xl && x <= xmax && y >= yu && y <= yu + PM_SIZE);
1608 gtk_sctree_is_hot_spot (GtkSCTree *ctree,
1612 GtkCMCTreeNode *node;
1616 cm_return_val_if_fail (GTK_IS_SCTREE (ctree), FALSE);
1618 if (gtk_cmclist_get_selection_info (GTK_CMCLIST (ctree), x, y, &row, &column))
1619 if ((node = GTK_CMCTREE_NODE(g_list_nth (GTK_CMCLIST (ctree)->row_list, row))))
1620 return sctree_is_hot_spot (ctree, node, row, x, y);
1625 /* Our handler for button_press events. We override all of GtkCMCList's broken
1629 gtk_sctree_button_press (GtkWidget *widget, GdkEventButton *event)
1638 cm_return_val_if_fail (widget != NULL, FALSE);
1639 cm_return_val_if_fail (GTK_IS_SCTREE (widget), FALSE);
1640 cm_return_val_if_fail (event != NULL, FALSE);
1642 sctree = GTK_SCTREE (widget);
1643 clist = GTK_CMCLIST (widget);
1646 if (event->window != clist->clist_window)
1647 return (* GTK_WIDGET_CLASS (parent_class)->button_press_event) (widget, event);
1649 on_row = gtk_cmclist_get_selection_info (clist, event->x, event->y, &row, &col);
1651 if (on_row && !gtkut_widget_has_focus(widget))
1652 gtk_widget_grab_focus (widget);
1654 if (gtk_sctree_is_hot_spot (GTK_SCTREE(sctree), event->x, event->y)) {
1655 GtkCMCTreeNode *node = gtk_cmctree_node_nth(GTK_CMCTREE(sctree), row);
1656 if (GTK_CMCTREE_ROW (node)->expanded)
1657 gtk_cmctree_collapse(GTK_CMCTREE(sctree), node);
1658 else if (GTK_SCTREE(sctree)->always_expand_recursively)
1659 gtk_cmctree_expand_recursive (GTK_CMCTREE(sctree), node);
1661 gtk_cmctree_expand(GTK_CMCTREE(sctree), node);
1665 switch (event->type) {
1666 case GDK_BUTTON_PRESS:
1667 if (event->button == 1 || event->button == 2) {
1668 if (event->button == 2)
1669 event->state &= ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK);
1671 /* Save the mouse info for DnD */
1672 sctree->dnd_press_button = event->button;
1673 sctree->dnd_press_x = event->x;
1674 sctree->dnd_press_y = event->y;
1676 /* Handle selection */
1677 if ((row_is_selected (sctree, row)
1678 && !(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)))
1679 || ((event->state & GDK_CONTROL_MASK)
1680 && !(event->state & GDK_SHIFT_MASK))) {
1681 sctree->dnd_select_pending = TRUE;
1682 sctree->dnd_select_pending_state = event->state;
1683 sctree->dnd_select_pending_row = row;
1685 select_row (sctree, row, col, event->state, NULL);
1688 gtk_cmclist_unselect_all (clist);
1692 } else if (event->button == 3) {
1693 /* Emit *_popup_menu signal*/
1695 if (!row_is_selected(sctree,row))
1696 select_row (sctree, row, col, 0, NULL);
1697 g_signal_emit (G_OBJECT (sctree),
1698 sctree_signals[ROW_POPUP_MENU],
1701 gtk_cmclist_unselect_all(clist);
1702 g_signal_emit (G_OBJECT (sctree),
1703 sctree_signals[EMPTY_POPUP_MENU],
1711 case GDK_2BUTTON_PRESS:
1712 if (event->button != 1)
1715 sctree->dnd_select_pending = FALSE;
1716 sctree->dnd_select_pending_state = 0;
1719 g_signal_emit (G_OBJECT (sctree),
1720 sctree_signals[OPEN_ROW], 0);
1732 /* Our handler for button_release events. We override all of GtkCMCList's broken
1736 gtk_sctree_button_release (GtkWidget *widget, GdkEventButton *event)
1744 cm_return_val_if_fail (widget != NULL, FALSE);
1745 cm_return_val_if_fail (GTK_IS_SCTREE (widget), FALSE);
1746 cm_return_val_if_fail (event != NULL, FALSE);
1748 sctree = GTK_SCTREE (widget);
1749 clist = GTK_CMCLIST (widget);
1752 if (event->window != clist->clist_window)
1753 return (* GTK_WIDGET_CLASS (parent_class)->button_release_event) (widget, event);
1755 on_row = gtk_cmclist_get_selection_info (clist, event->x, event->y, &row, &col);
1757 if (!(event->button == 1 || event->button == 2))
1760 sctree->dnd_press_button = 0;
1761 sctree->dnd_press_x = 0;
1762 sctree->dnd_press_y = 0;
1765 if (sctree->dnd_select_pending) {
1766 select_row (sctree, row, col, sctree->dnd_select_pending_state, NULL);
1767 sctree->dnd_select_pending = FALSE;
1768 sctree->dnd_select_pending_state = 0;
1777 /* Our handler for motion_notify events. We override all of GtkCMCList's broken
1781 gtk_sctree_motion (GtkWidget *widget, GdkEventMotion *event)
1786 cm_return_val_if_fail (widget != NULL, FALSE);
1787 cm_return_val_if_fail (GTK_IS_SCTREE (widget), FALSE);
1788 cm_return_val_if_fail (event != NULL, FALSE);
1790 sctree = GTK_SCTREE (widget);
1791 clist = GTK_CMCLIST (widget);
1793 if (event->window != clist->clist_window)
1794 return (* GTK_WIDGET_CLASS (parent_class)->motion_notify_event) (widget, event);
1796 if (!((sctree->dnd_press_button == 1 && (event->state & GDK_BUTTON1_MASK))
1797 || (sctree->dnd_press_button == 2 && (event->state & GDK_BUTTON2_MASK))))
1800 /* This is the same threshold value that is used in gtkdnd.c */
1802 #ifndef GENERIC_UMPC
1807 if (MAX (ABS (sctree->dnd_press_x - event->x),
1808 ABS (sctree->dnd_press_y - event->y)) <= THRESHOLD)
1811 /* Handle any pending selections */
1813 if (sctree->dnd_select_pending) {
1814 if (!row_is_selected(sctree,sctree->dnd_select_pending_row))
1816 sctree->dnd_select_pending_row,
1818 sctree->dnd_select_pending_state,
1821 sctree->dnd_select_pending = FALSE;
1822 sctree->dnd_select_pending_state = 0;
1825 g_signal_emit (G_OBJECT (sctree),
1826 sctree_signals[START_DRAG],
1828 sctree->dnd_press_button,
1833 /* We override the drag_begin signal to do nothing */
1835 gtk_sctree_drag_begin (GtkWidget *widget, GdkDragContext *context)
1840 /* We override the drag_end signal to do nothing */
1842 gtk_sctree_drag_end (GtkWidget *widget, GdkDragContext *context)
1847 /* We override the drag_data_get signal to do nothing */
1849 gtk_sctree_drag_data_get (GtkWidget *widget, GdkDragContext *context,
1850 GtkSelectionData *data, guint info, guint time)
1855 /* We override the drag_leave signal to do nothing */
1857 gtk_sctree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time)
1862 /* We override the drag_motion signal to do nothing */
1864 gtk_sctree_drag_motion (GtkWidget *widget, GdkDragContext *context,
1865 gint x, gint y, guint time)
1870 /* We override the drag_drop signal to do nothing */
1872 gtk_sctree_drag_drop (GtkWidget *widget, GdkDragContext *context,
1873 gint x, gint y, guint time)
1878 /* We override the drag_data_received signal to do nothing */
1880 gtk_sctree_drag_data_received (GtkWidget *widget, GdkDragContext *context,
1881 gint x, gint y, GtkSelectionData *data,
1882 guint info, guint time)
1887 /* Our handler for the clear signal of the clist. We have to reset the anchor
1891 gtk_sctree_clear (GtkCMCList *clist)
1895 cm_return_if_fail (clist != NULL);
1896 cm_return_if_fail (GTK_IS_SCTREE (clist));
1898 sctree = GTK_SCTREE (clist);
1899 sctree->anchor_row = NULL;
1901 if (((GtkCMCListClass *)parent_class)->clear)
1902 (* ((GtkCMCListClass *)parent_class)->clear) (clist);
1906 gtk_sctree_real_unselect_all (GtkCMCList *clist)
1909 gboolean should_freeze = FALSE;
1911 cm_return_if_fail (clist != NULL);
1912 cm_return_if_fail (GTK_IS_SCTREE (clist));
1914 sctree = GTK_SCTREE (clist);
1916 if (sc_g_list_bigger(GTK_CMCLIST(sctree)->selection, 10)) {
1917 should_freeze = TRUE;
1918 sctree->selecting_range++;
1919 gtk_cmclist_freeze (GTK_CMCLIST (sctree));
1922 if (((GtkCMCListClass *)parent_class)->unselect_all)
1923 (* ((GtkCMCListClass *)parent_class)->unselect_all) (clist);
1925 if (should_freeze) {
1926 gtk_cmclist_thaw (GTK_CMCLIST (sctree));
1927 sctree->selecting_range--;
1932 gtk_sctree_column_auto_resize (GtkCMCList *clist,
1933 GtkCMCListRow *clist_row,
1937 /* resize column if needed for auto_resize */
1938 GtkRequisition requisition;
1940 if (!clist->column[column].auto_resize ||
1941 GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
1945 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request (clist, clist_row,
1946 column, &requisition);
1948 requisition.width = 0;
1950 if (requisition.width > clist->column[column].width)
1951 gtk_cmclist_set_column_width (clist, column, requisition.width);
1952 else if (requisition.width < old_width &&
1953 old_width == clist->column[column].width)
1958 /* run a "gtk_cmclist_optimal_column_width" but break, if
1959 * the column doesn't shrink */
1960 if (GTK_CMCLIST_SHOW_TITLES (clist) && clist->column[column].button)
1961 new_width = (clist->column[column].button->requisition.width -
1962 (CELL_SPACING + (2 * COLUMN_INSET)));
1966 for (list = clist->row_list; list; list = list->next)
1968 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
1969 (clist, GTK_CMCLIST_ROW (list), column, &requisition);
1970 new_width = MAX (new_width, requisition.width);
1971 if (new_width == clist->column[column].width)
1974 if (new_width < clist->column[column].width)
1975 gtk_cmclist_set_column_width (clist, column, new_width);
1980 gtk_sctree_auto_resize_columns (GtkCMCList *clist)
1984 if (GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
1987 for (i = 0; i < clist->columns; i++)
1988 gtk_sctree_column_auto_resize (clist, NULL, i, clist->column[i].width);
1992 gtk_sctree_real_tree_collapse (GtkCMCTree *ctree,
1993 GtkCMCTreeNode *node)
1996 GtkCMCTreeNode *work;
1997 GtkRequisition requisition;
2001 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2003 if (!node || !GTK_CMCTREE_ROW (node)->expanded ||
2004 GTK_CMCTREE_ROW (node)->is_leaf)
2007 clist = GTK_CMCLIST (ctree);
2009 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2011 GTK_CMCTREE_ROW (node)->expanded = FALSE;
2012 level = GTK_CMCTREE_ROW (node)->level;
2014 visible = gtk_cmctree_is_viewable (ctree, node);
2015 /* get cell width if tree_column is auto resized */
2016 if (visible && clist->column[ctree->tree_column].auto_resize &&
2017 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2018 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2019 (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column, &requisition);
2021 /* unref/unset opened pixbuf */
2022 if (GTK_CMCELL_PIXTEXT
2023 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf)
2027 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf);
2030 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf = NULL;
2033 /* set/ref closed pixbuf */
2034 if (GTK_CMCTREE_ROW (node)->pixbuf_closed)
2037 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf =
2038 g_object_ref (GTK_CMCTREE_ROW (node)->pixbuf_closed);
2041 work = GTK_CMCTREE_ROW (node)->children;
2048 while (work && GTK_CMCTREE_ROW (work)->level > level)
2050 work = GTK_CMCTREE_NODE_NEXT (work);
2056 list = (GList *)node;
2057 list->next = (GList *)work;
2058 list = (GList *)GTK_CMCTREE_NODE_PREV (work);
2060 list = (GList *)work;
2061 list->prev = (GList *)node;
2065 list = (GList *)node;
2067 clist->row_list_end = (GList *)node;
2072 /* resize auto_resize columns if needed */
2073 gtk_sctree_auto_resize_columns (clist);
2075 if (!GTK_SCTREE(clist)->sorting) {
2076 row = g_list_position (clist->row_list, (GList *)node);
2077 if (row < clist->focus_row)
2078 clist->focus_row -= tmp;
2081 CLIST_REFRESH (clist);
2084 else if (visible && clist->column[ctree->tree_column].auto_resize &&
2085 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2086 /* resize tree_column if needed */
2087 gtk_sctree_column_auto_resize (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column,
2093 GtkWidget *gtk_sctree_new_with_titles (gint columns, gint tree_column,
2098 cm_return_val_if_fail (columns > 0, NULL);
2099 cm_return_val_if_fail (tree_column >= 0, NULL);
2101 if (tree_column >= columns) {
2102 g_warning("Wrong tree column");
2107 widget = gtk_widget_new (TYPE_GTK_SCTREE,
2108 "n_columns", columns,
2109 "tree_column", tree_column,
2112 GtkCMCList *clist = GTK_CMCLIST (widget);
2115 for (i = 0; i < columns; i++)
2116 gtk_cmclist_set_column_title (clist, i, titles[i]);
2117 gtk_cmclist_column_titles_show (clist);
2120 GTK_SCTREE(widget)->show_stripes = TRUE;
2121 GTK_SCTREE(widget)->always_expand_recursively = TRUE;
2122 GTK_SCTREE(widget)->force_additive_sel = FALSE;
2124 GTK_SCTREE(widget)->use_markup = g_new0(gboolean, columns);
2129 void gtk_sctree_set_use_markup (GtkSCTree *sctree,
2134 GValue value = { 0 };
2136 cm_return_if_fail(GTK_IS_SCTREE(sctree));
2138 g_value_init (&value, G_TYPE_INT);
2139 g_object_get_property (G_OBJECT (sctree), "n-columns", &value);
2140 columns = g_value_get_int (&value);
2141 g_value_unset (&value);
2143 cm_return_if_fail(column < columns);
2145 sctree->use_markup[column] = markup;
2148 void gtk_sctree_select (GtkSCTree *sctree, GtkCMCTreeNode *node)
2151 g_list_position(GTK_CMCLIST(sctree)->row_list, (GList *)node),
2155 void gtk_sctree_select_with_state (GtkSCTree *sctree, GtkCMCTreeNode *node, int state)
2158 g_list_position(GTK_CMCLIST(sctree)->row_list, (GList *)node),
2162 void gtk_sctree_unselect_all (GtkSCTree *sctree)
2164 gtk_cmclist_unselect_all(GTK_CMCLIST(sctree));
2165 sctree->anchor_row = NULL;
2168 void gtk_sctree_set_anchor_row (GtkSCTree *sctree, GtkCMCTreeNode *node)
2170 sctree->anchor_row = node;
2173 void gtk_sctree_remove_node (GtkSCTree *sctree, GtkCMCTreeNode *node)
2175 if (sctree->anchor_row == node)
2176 sctree->anchor_row = NULL;
2177 gtk_cmctree_remove_node(GTK_CMCTREE(sctree), node);
2180 void gtk_sctree_set_stripes(GtkSCTree *sctree, gboolean show_stripes)
2182 sctree->show_stripes = show_stripes;
2185 void gtk_sctree_set_recursive_expand(GtkSCTree *sctree, gboolean rec_exp)
2187 sctree->always_expand_recursively = rec_exp;
2190 /***********************************************************
2191 * Tree sorting functions *
2192 ***********************************************************/
2194 static void sink(GtkCMCList *clist, GPtrArray *numbers, gint root, gint bottom)
2197 GtkCMCTreeNode *temp;
2202 /* find the maximum element of numbers[root],
2203 numbers[2*root] and numbers[2*root+1] */
2205 if (clist->compare( clist, GTK_CMCTREE_ROW (g_ptr_array_index(numbers, root)),
2206 GTK_CMCTREE_ROW(g_ptr_array_index( numbers, j))) >= 0)
2209 if (clist->compare( clist, GTK_CMCTREE_ROW (g_ptr_array_index(numbers, k)),
2210 GTK_CMCTREE_ROW (g_ptr_array_index( numbers, j))) > 0)
2212 /* if numbers[root] wasn't the maximum element then
2215 temp = g_ptr_array_index( numbers,root);
2216 g_ptr_array_index( numbers, root) = g_ptr_array_index( numbers, j);
2217 g_ptr_array_index( numbers, j) = temp;
2218 sink( clist, numbers, j, bottom);
2223 static void heap_sort(GtkCMCList *clist, GPtrArray *numbers, gint array_size)
2226 GtkCMCTreeNode *temp;
2228 /* build the Heap */
2229 for (i = (array_size / 2); i >= 1; i--)
2230 sink( clist, numbers, i, array_size);
2231 /* output the Heap */
2232 for (i = array_size; i >= 2; i--) {
2233 temp = g_ptr_array_index( numbers, 1);
2234 g_ptr_array_index( numbers, 1) = g_ptr_array_index( numbers, i);
2235 g_ptr_array_index( numbers, i) = temp;
2236 sink( clist, numbers, 1, i-1);
2241 stree_sort (GtkCMCTree *ctree,
2242 GtkCMCTreeNode *node,
2245 GtkCMCTreeNode *list_start, *work, *next;
2246 GPtrArray *row_array, *viewable_array;
2250 clist = GTK_CMCLIST (ctree);
2253 work = GTK_CMCTREE_ROW (node)->children;
2255 work = GTK_CMCTREE_NODE (clist->row_list);
2257 row_array = g_ptr_array_new();
2258 viewable_array = g_ptr_array_new();
2261 g_ptr_array_add( row_array, NULL);
2263 /* add all rows to row_array */
2264 g_ptr_array_add( row_array, work);
2265 if (GTK_CMCTREE_ROW (work)->parent && gtk_cmctree_is_viewable( ctree, work))
2266 g_ptr_array_add( viewable_array, GTK_CMCTREE_ROW (work)->parent);
2267 next = GTK_CMCTREE_ROW (work)->sibling;
2268 gtk_sctree_unlink( ctree, work, FALSE);
2272 heap_sort( clist, row_array, (row_array->len)-1);
2275 list_start = GTK_CMCTREE_ROW (node)->children;
2277 list_start = GTK_CMCTREE_NODE (clist->row_list);
2279 if (clist->sort_type == GTK_SORT_ASCENDING) {
2280 for (i=(row_array->len)-1; i>=1; i--) {
2281 work = g_ptr_array_index( row_array, i);
2282 gtk_sctree_link( ctree, work, node, list_start, FALSE);
2284 /* insert work at the beginning of the list */
2287 for (i=1; i<row_array->len; i++) {
2288 work = g_ptr_array_index( row_array, i);
2289 gtk_sctree_link( ctree, work, node, list_start, FALSE);
2291 /* insert work at the beginning of the list */
2295 for (i=0; i<viewable_array->len; i++) {
2296 gtk_cmctree_expand( ctree, g_ptr_array_index( viewable_array, i));
2300 g_ptr_array_free( row_array, TRUE);
2301 g_ptr_array_free( viewable_array, TRUE);
2305 gtk_sctree_sort_recursive (GtkCMCTree *ctree,
2306 GtkCMCTreeNode *node)
2309 GtkCMCTreeNode *focus_node = NULL;
2311 cm_return_if_fail (ctree != NULL);
2312 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2314 clist = GTK_CMCLIST (ctree);
2316 gtk_cmclist_freeze (clist);
2318 if (clist->selection_mode == GTK_SELECTION_EXTENDED) {
2319 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2321 g_list_free (clist->undo_selection);
2322 g_list_free (clist->undo_unselection);
2323 clist->undo_selection = NULL;
2324 clist->undo_unselection = NULL;
2327 if (!node || (node && gtk_cmctree_is_viewable (ctree, node)))
2328 focus_node = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
2330 GTK_SCTREE(ctree)->sorting = TRUE;
2332 gtk_cmctree_post_recursive (ctree, node, GTK_CMCTREE_FUNC (stree_sort), NULL);
2335 stree_sort (ctree, NULL, NULL);
2337 GTK_SCTREE(ctree)->sorting = FALSE;
2340 clist->focus_row = g_list_position (clist->row_list,(GList *)focus_node);
2341 clist->undo_anchor = clist->focus_row;
2344 gtk_cmclist_thaw (clist);
2348 gtk_sctree_sort_node (GtkCMCTree *ctree,
2349 GtkCMCTreeNode *node)
2352 GtkCMCTreeNode *focus_node = NULL;
2354 cm_return_if_fail (ctree != NULL);
2355 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2357 clist = GTK_CMCLIST (ctree);
2359 gtk_cmclist_freeze (clist);
2361 if (clist->selection_mode == GTK_SELECTION_EXTENDED) {
2362 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2364 g_list_free (clist->undo_selection);
2365 g_list_free (clist->undo_unselection);
2366 clist->undo_selection = NULL;
2367 clist->undo_unselection = NULL;
2370 if (!node || (node && gtk_cmctree_is_viewable (ctree, node)))
2371 focus_node = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
2373 GTK_SCTREE(ctree)->sorting = TRUE;
2375 stree_sort (ctree, node, NULL);
2377 GTK_SCTREE(ctree)->sorting = FALSE;
2380 clist->focus_row = g_list_position (clist->row_list,(GList *)focus_node);
2381 clist->undo_anchor = clist->focus_row;
2384 gtk_cmclist_thaw (clist);
2387 /************************************************************************/
2390 gtk_sctree_unlink (GtkCMCTree *ctree,
2391 GtkCMCTreeNode *node,
2392 gboolean update_focus_row)
2398 GtkCMCTreeNode *work;
2399 GtkCMCTreeNode *parent;
2402 cm_return_if_fail (ctree != NULL);
2403 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2404 cm_return_if_fail (node != NULL);
2406 clist = GTK_CMCLIST (ctree);
2408 if (update_focus_row && clist->selection_mode == GTK_SELECTION_EXTENDED) {
2409 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2411 g_list_free (clist->undo_selection);
2412 g_list_free (clist->undo_unselection);
2413 clist->undo_selection = NULL;
2414 clist->undo_unselection = NULL;
2417 visible = gtk_cmctree_is_viewable (ctree, node);
2419 /* clist->row_list_end unlinked ? */
2420 if (visible && (GTK_CMCTREE_NODE_NEXT (node) == NULL ||
2421 (GTK_CMCTREE_ROW (node)->children && gtk_cmctree_is_ancestor (ctree, node,
2422 GTK_CMCTREE_NODE (clist->row_list_end)))))
2423 clist->row_list_end = (GList *) (GTK_CMCTREE_NODE_PREV (node));
2427 level = GTK_CMCTREE_ROW (node)->level;
2428 work = GTK_CMCTREE_NODE_NEXT (node);
2429 while (work && GTK_CMCTREE_ROW (work)->level > level) {
2430 work = GTK_CMCTREE_NODE_NEXT (work);
2435 clist->rows -= (rows + 1);
2437 if (update_focus_row) {
2439 pos = g_list_position (clist->row_list, (GList *)node);
2440 if (pos + rows < clist->focus_row)
2441 clist->focus_row -= (rows + 1);
2442 else if (pos <= clist->focus_row) {
2443 if (!GTK_CMCTREE_ROW (node)->sibling)
2444 clist->focus_row = MAX (pos - 1, 0);
2446 clist->focus_row = pos;
2448 clist->focus_row = MIN (clist->focus_row, clist->rows - 1);
2450 clist->undo_anchor = clist->focus_row;
2455 list = (GList *)GTK_CMCTREE_NODE_PREV (work);
2457 list = (GList *)work;
2458 list->prev = (GList *)GTK_CMCTREE_NODE_PREV (node);
2461 if (GTK_CMCTREE_NODE_PREV (node) &&
2462 GTK_CMCTREE_NODE_NEXT (GTK_CMCTREE_NODE_PREV (node)) == node) {
2463 list = (GList *)GTK_CMCTREE_NODE_PREV (node);
2464 list->next = (GList *)work;
2468 parent = GTK_CMCTREE_ROW (node)->parent;
2470 if (GTK_CMCTREE_ROW (parent)->children == node) {
2471 GTK_CMCTREE_ROW (parent)->children = GTK_CMCTREE_ROW (node)->sibling;
2474 GtkCMCTreeNode *sibling;
2476 sibling = GTK_CMCTREE_ROW (parent)->children;
2477 while (GTK_CMCTREE_ROW (sibling)->sibling != node)
2478 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
2479 GTK_CMCTREE_ROW (sibling)->sibling = GTK_CMCTREE_ROW (node)->sibling;
2483 if (clist->row_list == (GList *)node)
2484 clist->row_list = (GList *) (GTK_CMCTREE_ROW (node)->sibling);
2486 GtkCMCTreeNode *sibling;
2488 sibling = GTK_CMCTREE_NODE (clist->row_list);
2489 while (GTK_CMCTREE_ROW (sibling)->sibling != node)
2490 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
2491 GTK_CMCTREE_ROW (sibling)->sibling = GTK_CMCTREE_ROW (node)->sibling;
2497 gtk_sctree_link (GtkCMCTree *ctree,
2498 GtkCMCTreeNode *node,
2499 GtkCMCTreeNode *parent,
2500 GtkCMCTreeNode *sibling,
2501 gboolean update_focus_row)
2507 gboolean visible = FALSE;
2511 cm_return_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent);
2512 cm_return_if_fail (node != NULL);
2513 cm_return_if_fail (node != sibling);
2514 cm_return_if_fail (node != parent);
2516 clist = GTK_CMCLIST (ctree);
2518 if (update_focus_row && clist->selection_mode == GTK_SELECTION_EXTENDED) {
2519 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2521 g_list_free (clist->undo_selection);
2522 g_list_free (clist->undo_unselection);
2523 clist->undo_selection = NULL;
2524 clist->undo_unselection = NULL;
2527 for (rows = 1, list_end = (GList *)node; list_end->next;
2528 list_end = list_end->next)
2531 GTK_CMCTREE_ROW (node)->parent = parent;
2532 GTK_CMCTREE_ROW (node)->sibling = sibling;
2534 if (!parent || (parent && (gtk_cmctree_is_viewable (ctree, parent) &&
2535 GTK_CMCTREE_ROW (parent)->expanded))) {
2537 clist->rows += rows;
2541 work = (GList *)(GTK_CMCTREE_ROW (parent)->children);
2543 work = clist->row_list;
2546 if (work != (GList *)sibling) {
2547 while (GTK_CMCTREE_ROW (work)->sibling != sibling)
2548 work = (GList *)(GTK_CMCTREE_ROW (work)->sibling);
2549 GTK_CMCTREE_ROW (work)->sibling = node;
2552 if (sibling == GTK_CMCTREE_NODE (clist->row_list))
2553 clist->row_list = (GList *) node;
2554 if (GTK_CMCTREE_NODE_PREV (sibling) &&
2555 GTK_CMCTREE_NODE_NEXT (GTK_CMCTREE_NODE_PREV (sibling)) == sibling) {
2556 list = (GList *)GTK_CMCTREE_NODE_PREV (sibling);
2557 list->next = (GList *)node;
2560 list = (GList *)node;
2561 list->prev = (GList *)GTK_CMCTREE_NODE_PREV (sibling);
2562 list_end->next = (GList *)sibling;
2563 list = (GList *)sibling;
2564 list->prev = list_end;
2565 if (parent && GTK_CMCTREE_ROW (parent)->children == sibling)
2566 GTK_CMCTREE_ROW (parent)->children = node;
2571 while (GTK_CMCTREE_ROW (work)->sibling)
2572 work = (GList *)(GTK_CMCTREE_ROW (work)->sibling);
2573 GTK_CMCTREE_ROW (work)->sibling = node;
2575 /* find last visible child of sibling */
2576 work = (GList *) gtk_sctree_last_visible (ctree,
2577 GTK_CMCTREE_NODE (work));
2579 list_end->next = work->next;
2581 list = work->next->prev = list_end;
2582 work->next = (GList *)node;
2583 list = (GList *)node;
2588 GTK_CMCTREE_ROW (parent)->children = node;
2589 list = (GList *)node;
2590 list->prev = (GList *)parent;
2591 if (GTK_CMCTREE_ROW (parent)->expanded) {
2592 list_end->next = (GList *)GTK_CMCTREE_NODE_NEXT (parent);
2593 if (GTK_CMCTREE_NODE_NEXT(parent)) {
2594 list = (GList *)GTK_CMCTREE_NODE_NEXT (parent);
2595 list->prev = list_end;
2597 list = (GList *)parent;
2598 list->next = (GList *)node;
2601 list_end->next = NULL;
2604 clist->row_list = (GList *)node;
2605 list = (GList *)node;
2607 list_end->next = NULL;
2612 gtk_cmctree_pre_recursive (ctree, node, stree_update_level, NULL);
2614 if (clist->row_list_end == NULL ||
2615 clist->row_list_end->next == (GList *)node)
2616 clist->row_list_end = list_end;
2618 if (visible && update_focus_row) {
2620 pos = g_list_position (clist->row_list, (GList *)node);
2622 if (pos <= clist->focus_row) {
2623 clist->focus_row += rows;
2624 clist->undo_anchor = clist->focus_row;
2630 stree_update_level (GtkCMCTree *ctree,
2631 GtkCMCTreeNode *node,
2637 if (GTK_CMCTREE_ROW (node)->parent)
2638 GTK_CMCTREE_ROW (node)->level =
2639 GTK_CMCTREE_ROW (GTK_CMCTREE_ROW (node)->parent)->level + 1;
2641 GTK_CMCTREE_ROW (node)->level = 1;
2644 static GtkCMCTreeNode *
2645 gtk_sctree_last_visible (GtkCMCTree *ctree,
2646 GtkCMCTreeNode *node)
2648 GtkCMCTreeNode *work;
2653 work = GTK_CMCTREE_ROW (node)->children;
2655 if (!work || !GTK_CMCTREE_ROW (node)->expanded)
2658 while (GTK_CMCTREE_ROW (work)->sibling)
2659 work = GTK_CMCTREE_ROW (work)->sibling;
2661 return gtk_sctree_last_visible (ctree, work);
2665 sset_node_info (GtkCMCTree *ctree,
2666 GtkCMCTreeNode *node,
2669 GdkPixbuf *pixbuf_closed,
2670 GdkPixbuf *pixbuf_opened,
2674 if (GTK_CMCTREE_ROW (node)->pixbuf_opened)
2676 g_object_unref (GTK_CMCTREE_ROW (node)->pixbuf_opened);
2678 if (GTK_CMCTREE_ROW (node)->pixbuf_closed)
2680 g_object_unref (GTK_CMCTREE_ROW (node)->pixbuf_closed);
2683 GTK_CMCTREE_ROW (node)->pixbuf_opened = NULL;
2684 GTK_CMCTREE_ROW (node)->pixbuf_closed = NULL;
2688 GTK_CMCTREE_ROW (node)->pixbuf_closed = g_object_ref (pixbuf_closed);
2692 GTK_CMCTREE_ROW (node)->pixbuf_opened = g_object_ref (pixbuf_opened);
2695 GTK_CMCTREE_ROW (node)->is_leaf = is_leaf;
2696 GTK_CMCTREE_ROW (node)->expanded = (is_leaf) ? FALSE : expanded;
2698 if (GTK_CMCTREE_ROW (node)->expanded)
2699 gtk_cmctree_node_set_pixtext (ctree, node, ctree->tree_column,
2700 text, spacing, pixbuf_opened);
2702 gtk_cmctree_node_set_pixtext (ctree, node, ctree->tree_column,
2703 text, spacing, pixbuf_closed);
2707 stree_draw_node (GtkCMCTree *ctree,
2708 GtkCMCTreeNode *node)
2712 clist = GTK_CMCLIST (ctree);
2714 if (CLIST_UNFROZEN (clist) && gtk_cmctree_is_viewable (ctree, node))
2716 GtkCMCTreeNode *work;
2719 work = GTK_CMCTREE_NODE (clist->row_list);
2720 while (work && work != node)
2722 work = GTK_CMCTREE_NODE_NEXT (work);
2725 if (work && gtk_cmclist_row_is_visible (clist, num) != GTK_VISIBILITY_NONE)
2726 GTK_CMCLIST_GET_CLASS (clist)->draw_row
2727 (clist, NULL, num, GTK_CMCLIST_ROW ((GList *) node));
2731 /* this wrapper simply replaces NULL pixbufs
2732 * with a transparent, 1x1 pixbuf. This works
2733 * around a memory problem deep inside gtk,
2734 * revealed by valgrind.
2736 void gtk_sctree_set_node_info (GtkCMCTree *ctree,
2737 GtkCMCTreeNode *node,
2740 GdkPixbuf *pixbuf_closed,
2741 GdkPixbuf *pixbuf_opened,
2746 gboolean old_expanded;
2747 GtkCMCTreeNode *work;
2749 if (!GTK_IS_CMCTREE (ctree) || !node) return;
2751 old_leaf = GTK_CMCTREE_ROW (node)->is_leaf;
2752 old_expanded = GTK_CMCTREE_ROW (node)->expanded;
2754 if (is_leaf && (work = GTK_CMCTREE_ROW (node)->children) != NULL)
2756 GtkCMCTreeNode *ptr;
2761 work = GTK_CMCTREE_ROW (work)->sibling;
2762 gtk_cmctree_remove_node (ctree, ptr);
2766 sset_node_info (ctree, node, text, spacing, pixbuf_closed,
2767 pixbuf_opened, is_leaf, expanded);
2769 if (!is_leaf && !old_leaf)
2771 GTK_CMCTREE_ROW (node)->expanded = old_expanded;
2772 if (expanded && !old_expanded)
2773 gtk_cmctree_expand (ctree, node);
2774 else if (!expanded && old_expanded)
2775 gtk_cmctree_collapse (ctree, node);
2778 GTK_CMCTREE_ROW (node)->expanded = (is_leaf) ? FALSE : expanded;
2780 stree_draw_node (ctree, node);
2783 static GtkCMCTreeRow *
2784 srow_new (GtkCMCTree *ctree)
2787 GtkCMCTreeRow *ctree_row;
2790 clist = GTK_CMCLIST (ctree);
2791 #if GLIB_CHECK_VERSION(2,10,0)
2792 ctree_row = g_slice_new (GtkCMCTreeRow);
2793 ctree_row->row.cell = g_slice_alloc (sizeof (GtkCMCell) * clist->columns);
2795 ctree_row = g_chunk_new (GtkCMCTreeRow, (GMemChunk *)clist->row_mem_chunk);
2796 ctree_row->row.cell = g_chunk_new (GtkCMCell, (GMemChunk *)clist->cell_mem_chunk);
2798 for (i = 0; i < clist->columns; i++)
2800 ctree_row->row.cell[i].type = GTK_CMCELL_EMPTY;
2801 ctree_row->row.cell[i].vertical = 0;
2802 ctree_row->row.cell[i].horizontal = 0;
2803 ctree_row->row.cell[i].style = NULL;
2806 GTK_CMCELL_PIXTEXT (ctree_row->row.cell[ctree->tree_column])->text = NULL;
2808 ctree_row->row.fg_set = FALSE;
2809 ctree_row->row.bg_set = FALSE;
2810 ctree_row->row.style = NULL;
2811 ctree_row->row.selectable = TRUE;
2812 ctree_row->row.state = GTK_STATE_NORMAL;
2813 ctree_row->row.data = NULL;
2814 ctree_row->row.destroy = NULL;
2816 ctree_row->level = 0;
2817 ctree_row->expanded = FALSE;
2818 ctree_row->parent = NULL;
2819 ctree_row->sibling = NULL;
2820 ctree_row->children = NULL;
2821 ctree_row->pixbuf_closed = NULL;
2822 ctree_row->pixbuf_opened = NULL;
2828 srow_delete (GtkCMCTree *ctree,
2829 GtkCMCTreeRow *ctree_row)
2834 clist = GTK_CMCLIST (ctree);
2836 for (i = 0; i < clist->columns; i++)
2838 GTK_CMCLIST_GET_CLASS (clist)->set_cell_contents
2839 (clist, &(ctree_row->row), i, GTK_CMCELL_EMPTY, NULL, 0, NULL);
2840 if (ctree_row->row.cell[i].style)
2842 if (gtkut_widget_get_realized (GTK_WIDGET(ctree)))
2843 gtk_style_detach (ctree_row->row.cell[i].style);
2844 g_object_unref (ctree_row->row.cell[i].style);
2848 if (ctree_row->row.style)
2850 if (gtkut_widget_get_realized (GTK_WIDGET(ctree)))
2851 gtk_style_detach (ctree_row->row.style);
2852 g_object_unref (ctree_row->row.style);
2855 if (ctree_row->pixbuf_closed)
2857 g_object_unref (ctree_row->pixbuf_closed);
2860 if (ctree_row->pixbuf_opened)
2862 g_object_unref (ctree_row->pixbuf_opened);
2865 if (ctree_row->row.destroy)
2867 GDestroyNotify dnotify = ctree_row->row.destroy;
2868 gpointer ddata = ctree_row->row.data;
2870 ctree_row->row.destroy = NULL;
2871 ctree_row->row.data = NULL;
2876 #if GLIB_CHECK_VERSION(2,10,0)
2877 g_slice_free1 (sizeof (GtkCMCell) * clist->columns, ctree_row->row.cell);
2878 g_slice_free (GtkCMCTreeRow, ctree_row);
2880 g_mem_chunk_free ((GMemChunk *)clist->cell_mem_chunk, ctree_row->row.cell);
2881 g_mem_chunk_free ((GMemChunk *)clist->row_mem_chunk, ctree_row);
2886 stree_delete_row (GtkCMCTree *ctree,
2887 GtkCMCTreeNode *node,
2890 srow_delete (ctree, GTK_CMCTREE_ROW (node));
2891 g_list_free_1 ((GList *)node);
2895 gtk_sctree_real_tree_expand (GtkCMCTree *ctree,
2896 GtkCMCTreeNode *node)
2899 GtkCMCTreeNode *work;
2900 GtkRequisition requisition;
2904 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2906 if (!node || GTK_CMCTREE_ROW (node)->expanded || GTK_CMCTREE_ROW (node)->is_leaf)
2909 clist = GTK_CMCLIST (ctree);
2911 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2913 GTK_CMCTREE_ROW (node)->expanded = TRUE;
2914 level = GTK_CMCTREE_ROW (node)->level;
2916 visible = gtk_cmctree_is_viewable (ctree, node);
2917 /* get cell width if tree_column is auto resized */
2918 if (visible && clist->column[ctree->tree_column].auto_resize &&
2919 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2920 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2921 (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column, &requisition);
2923 /* unref/unset closed pixbuf */
2924 if (GTK_CMCELL_PIXTEXT
2925 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf)
2929 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf);
2932 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf = NULL;
2935 /* set/ref opened pixbuf */
2936 if (GTK_CMCTREE_ROW (node)->pixbuf_opened)
2939 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf =
2940 g_object_ref (GTK_CMCTREE_ROW (node)->pixbuf_opened);
2944 work = GTK_CMCTREE_ROW (node)->children;
2947 GList *list = (GList *)work;
2948 gint *cell_width = NULL;
2953 if (visible && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2955 cell_width = g_new0 (gint, clist->columns);
2956 if (clist->column[ctree->tree_column].auto_resize)
2957 cell_width[ctree->tree_column] = requisition.width;
2961 /* search maximum cell widths of auto_resize columns */
2962 for (i = 0; i < clist->columns; i++)
2963 if (clist->column[i].auto_resize)
2965 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2966 (clist, >K_CMCTREE_ROW (work)->row, i, &requisition);
2967 cell_width[i] = MAX (requisition.width, cell_width[i]);
2970 list = (GList *)work;
2971 work = GTK_CMCTREE_NODE_NEXT (work);
2978 list = (GList *)work;
2979 work = GTK_CMCTREE_NODE_NEXT (work);
2983 list->next = (GList *)GTK_CMCTREE_NODE_NEXT (node);
2985 if (GTK_CMCTREE_NODE_NEXT (node))
2989 if (clist->row_list_end == list)
2990 clist->row_list_end = g_list_last(list);
2992 tmp_list = (GList *)GTK_CMCTREE_NODE_NEXT (node);
2993 tmp_list->prev = list;
2996 clist->row_list_end = list;
2998 list = (GList *)node;
2999 list->next = (GList *)(GTK_CMCTREE_ROW (node)->children);
3001 if (visible && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
3003 /* resize auto_resize columns if needed */
3004 for (i = 0; i < clist->columns; i++)
3005 if (clist->column[i].auto_resize &&
3006 cell_width[i] > clist->column[i].width)
3007 gtk_cmclist_set_column_width (clist, i, cell_width[i]);
3008 g_free (cell_width);
3010 if (!GTK_SCTREE(ctree)->sorting) {
3011 /* update focus_row position */
3012 row = g_list_position (clist->row_list, (GList *)node);
3013 if (row < clist->focus_row)
3014 clist->focus_row += tmp;
3017 CLIST_REFRESH (clist);
3020 else if (visible && clist->column[ctree->tree_column].auto_resize)
3021 /* resize tree_column if needed */
3022 gtk_sctree_column_auto_resize (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column,
3028 gtk_sctree_insert_node (GtkCMCTree *ctree,
3029 GtkCMCTreeNode *parent,
3030 GtkCMCTreeNode *sibling,
3033 GdkPixbuf *pixbuf_closed,
3034 GdkPixbuf *pixbuf_opened,
3039 GtkCMCTreeRow *new_row;
3040 GtkCMCTreeNode *node;
3044 cm_return_val_if_fail (GTK_IS_CMCTREE (ctree), NULL);
3046 cm_return_val_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent, NULL);
3048 if (parent && GTK_CMCTREE_ROW (parent)->is_leaf)
3051 clist = GTK_CMCLIST (ctree);
3053 /* create the row */
3054 new_row = srow_new (ctree);
3055 list = g_list_alloc ();
3056 list->data = new_row;
3057 node = GTK_CMCTREE_NODE (list);
3060 for (i = 0; i < clist->columns; i++)
3061 if (text[i] && i != ctree->tree_column)
3062 GTK_CMCLIST_GET_CLASS (clist)->set_cell_contents
3063 (clist, &(new_row->row), i, GTK_CMCELL_TEXT, text[i], 0, NULL);
3065 sset_node_info (ctree, node, text ?
3066 text[ctree->tree_column] : NULL, spacing, pixbuf_closed,
3067 pixbuf_opened, is_leaf, expanded);
3069 /* sorted insertion */
3070 if (GTK_CMCLIST_AUTO_SORT (clist))
3073 sibling = GTK_CMCTREE_ROW (parent)->children;
3075 sibling = GTK_CMCTREE_NODE (clist->row_list);
3077 while (sibling && clist->compare
3078 (clist, GTK_CMCTREE_ROW (node), GTK_CMCTREE_ROW (sibling)) > 0)
3079 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
3082 gtk_sctree_link (ctree, node, parent, sibling, FALSE);
3084 if (text && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist) &&
3085 gtk_cmctree_is_viewable (ctree, node))
3087 for (i = 0; i < clist->columns; i++)
3088 if (clist->column[i].auto_resize)
3089 gtk_sctree_column_auto_resize (clist, &(new_row->row), i, 0);
3092 if (clist->rows == 1)
3094 clist->focus_row = 0;
3095 if (clist->selection_mode == GTK_SELECTION_BROWSE)
3096 gtk_sctree_select (GTK_SCTREE(ctree), node);
3100 CLIST_REFRESH (clist);
3106 gtk_sctree_insert_gnode (GtkCMCTree *ctree,
3107 GtkCMCTreeNode *parent,
3108 GtkCMCTreeNode *sibling,
3110 GtkCMCTreeGNodeFunc func,
3114 GtkCMCTreeNode *cnode = NULL;
3115 GtkCMCTreeNode *child = NULL;
3116 GtkCMCTreeNode *new_child;
3121 cm_return_val_if_fail (GTK_IS_CMCTREE (ctree), NULL);
3122 cm_return_val_if_fail (gnode != NULL, NULL);
3123 cm_return_val_if_fail (func != NULL, NULL);
3125 cm_return_val_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent, NULL);
3127 clist = GTK_CMCLIST (ctree);
3130 depth = GTK_CMCTREE_ROW (parent)->level + 1;
3132 list = g_list_alloc ();
3133 list->data = srow_new (ctree);
3134 cnode = GTK_CMCTREE_NODE (list);
3136 gtk_cmclist_freeze (clist);
3138 sset_node_info (ctree, cnode, "", 0, NULL, NULL, TRUE, FALSE);
3140 if (!func (ctree, depth, gnode, cnode, data))
3142 stree_delete_row (ctree, cnode, NULL);
3143 gtk_cmclist_thaw (clist);
3147 if (GTK_CMCLIST_AUTO_SORT (clist))
3150 sibling = GTK_CMCTREE_ROW (parent)->children;
3152 sibling = GTK_CMCTREE_NODE (clist->row_list);
3154 while (sibling && clist->compare
3155 (clist, GTK_CMCTREE_ROW (cnode), GTK_CMCTREE_ROW (sibling)) > 0)
3156 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
3159 gtk_sctree_link (ctree, cnode, parent, sibling, FALSE);
3161 for (work = g_node_last_child (gnode); work; work = work->prev)
3163 new_child = gtk_sctree_insert_gnode (ctree, cnode, child,
3169 gtk_cmclist_thaw (clist);
3175 sreal_tree_move (GtkCMCTree *ctree,
3176 GtkCMCTreeNode *node,
3177 GtkCMCTreeNode *new_parent,
3178 GtkCMCTreeNode *new_sibling)
3181 GtkCMCTreeNode *work;
3182 gboolean visible = FALSE;
3184 cm_return_if_fail (ctree != NULL);
3185 cm_return_if_fail (node != NULL);
3186 cm_return_if_fail (!new_sibling ||
3187 GTK_CMCTREE_ROW (new_sibling)->parent == new_parent);
3189 if (new_parent && GTK_CMCTREE_ROW (new_parent)->is_leaf)
3192 /* new_parent != child of child */
3193 for (work = new_parent; work; work = GTK_CMCTREE_ROW (work)->parent)
3197 clist = GTK_CMCLIST (ctree);
3199 visible = gtk_cmctree_is_viewable (ctree, node);
3201 if (clist->selection_mode == GTK_SELECTION_MULTIPLE)
3203 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
3205 g_list_free (clist->undo_selection);
3206 g_list_free (clist->undo_unselection);
3207 clist->undo_selection = NULL;
3208 clist->undo_unselection = NULL;
3211 if (GTK_CMCLIST_AUTO_SORT (clist))
3213 if (new_parent == GTK_CMCTREE_ROW (node)->parent)
3217 new_sibling = GTK_CMCTREE_ROW (new_parent)->children;
3219 new_sibling = GTK_CMCTREE_NODE (clist->row_list);
3221 while (new_sibling && clist->compare
3222 (clist, GTK_CMCTREE_ROW (node), GTK_CMCTREE_ROW (new_sibling)) > 0)
3223 new_sibling = GTK_CMCTREE_ROW (new_sibling)->sibling;
3226 if (new_parent == GTK_CMCTREE_ROW (node)->parent &&
3227 new_sibling == GTK_CMCTREE_ROW (node)->sibling)
3230 gtk_cmclist_freeze (clist);
3234 if (!GTK_SCTREE(ctree)->sorting && gtk_cmctree_is_viewable (ctree, node))
3235 work = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
3237 gtk_sctree_unlink (ctree, node, FALSE);
3238 gtk_sctree_link (ctree, node, new_parent, new_sibling, FALSE);
3240 if (!GTK_SCTREE(ctree)->sorting && work)
3242 while (work && !gtk_cmctree_is_viewable (ctree, work))
3243 work = GTK_CMCTREE_ROW (work)->parent;
3244 clist->focus_row = g_list_position (clist->row_list, (GList *)work);
3245 clist->undo_anchor = clist->focus_row;
3248 if (clist->column[ctree->tree_column].auto_resize &&
3249 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist) &&
3250 (visible || gtk_cmctree_is_viewable (ctree, node)))
3251 gtk_cmclist_set_column_width
3252 (clist, ctree->tree_column,
3253 gtk_cmclist_optimal_column_width (clist, ctree->tree_column));
3255 gtk_cmclist_thaw (clist);
3258 void gtk_sctree_set_column_tooltip (GtkSCTree *sctree,
3262 #if !(GTK_CHECK_VERSION(2,12,0))
3264 if (!sctree->tooltips)
3265 sctree->tooltips = gtk_tooltips_new();
3266 tips = sctree->tooltips;
3269 CLAWS_SET_TIP(GTK_CMCLIST(sctree)->column[column].button,