2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
4 * Copyright (C) 1999-2011 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 "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 void gtk_sctree_class_init (GtkSCTreeClass *class);
65 static void gtk_sctree_init (GtkSCTree *sctree);
67 static gint gtk_sctree_button_press (GtkWidget *widget, GdkEventButton *event);
68 static gint gtk_sctree_button_release (GtkWidget *widget, GdkEventButton *event);
69 static gint gtk_sctree_motion (GtkWidget *widget, GdkEventMotion *event);
70 static void gtk_sctree_drag_begin (GtkWidget *widget, GdkDragContext *context);
71 static void gtk_sctree_drag_end (GtkWidget *widget, GdkDragContext *context);
72 static void gtk_sctree_drag_data_get (GtkWidget *widget, GdkDragContext *context,
73 GtkSelectionData *data, guint info, guint time);
74 static void gtk_sctree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time);
75 static gboolean gtk_sctree_drag_motion (GtkWidget *widget, GdkDragContext *context,
76 gint x, gint y, guint time);
77 static gboolean gtk_sctree_drag_drop (GtkWidget *widget, GdkDragContext *context,
78 gint x, gint y, guint time);
79 static void gtk_sctree_drag_data_received (GtkWidget *widget, GdkDragContext *context,
80 gint x, gint y, GtkSelectionData *data,
81 guint info, guint time);
83 static void gtk_sctree_clear (GtkCMCList *clist);
84 static void gtk_sctree_real_unselect_all (GtkCMCList *clist);
86 static void stree_sort (GtkCMCTree *ctree, GtkCMCTreeNode *node, gpointer data);
87 void gtk_sctree_sort_node (GtkCMCTree *ctree, GtkCMCTreeNode *node);
88 void gtk_sctree_sort_recursive (GtkCMCTree *ctree, GtkCMCTreeNode *node);
90 static void gtk_sctree_link (GtkCMCTree *ctree,
92 GtkCMCTreeNode *parent,
93 GtkCMCTreeNode *sibling,
94 gboolean update_focus_row);
96 static void gtk_sctree_unlink (GtkCMCTree *ctree,
98 gboolean update_focus_row);
100 static void stree_update_level (GtkCMCTree *ctree,
101 GtkCMCTreeNode *node,
104 static GtkCMCTreeNode * gtk_sctree_last_visible (GtkCMCTree *ctree,
105 GtkCMCTreeNode *node);
106 static void gtk_sctree_real_tree_expand (GtkCMCTree *ctree,
107 GtkCMCTreeNode *node);
108 static void gtk_sctree_real_tree_collapse (GtkCMCTree *ctree,
109 GtkCMCTreeNode *node);
111 sreal_tree_move (GtkCMCTree *ctree,
112 GtkCMCTreeNode *node,
113 GtkCMCTreeNode *new_parent,
114 GtkCMCTreeNode *new_sibling);
116 static GtkCMCTreeClass *parent_class;
118 static guint sctree_signals[LAST_SIGNAL];
121 * gtk_sctree_get_type:
124 * Creates the GtkSCTree class and its type information
126 * Return value: The type ID for GtkSCTreeClass
129 gtk_sctree_get_type (void)
131 static GType sctree_type = 0;
134 GTypeInfo sctree_info = {
135 sizeof (GtkSCTreeClass),
137 (GBaseInitFunc) NULL,
138 (GBaseFinalizeFunc) NULL,
140 (GClassInitFunc) gtk_sctree_class_init,
141 (GClassFinalizeFunc) NULL,
142 NULL, /* class_data */
146 (GInstanceInitFunc) gtk_sctree_init,
149 sctree_type = g_type_register_static (GTK_TYPE_CMCTREE, "GtkSCTree", &sctree_info, (GTypeFlags)0);
156 gtk_sctree_draw_cell_pixbuf (GdkWindow *window,
157 GdkRectangle *clip_rectangle,
168 gdk_gc_set_clip_origin (fg_gc, x, y);
169 if (x < clip_rectangle->x)
171 xsrc = clip_rectangle->x - x;
173 x = clip_rectangle->x;
175 if (x + width > clip_rectangle->x + clip_rectangle->width)
176 width = clip_rectangle->x + clip_rectangle->width - x;
178 if (y < clip_rectangle->y)
180 ysrc = clip_rectangle->y - y;
182 y = clip_rectangle->y;
184 if (y + height > clip_rectangle->y + clip_rectangle->height)
185 height = clip_rectangle->y + clip_rectangle->height - y;
187 if (width > 0 && height > 0)
188 gdk_draw_pixbuf (window, fg_gc, pixbuf, xsrc, ysrc, x, y, width, height, GDK_RGB_DITHER_NONE, 0, 0);
190 gdk_gc_set_clip_origin (fg_gc, 0, 0);
192 return x + MAX (width, 0);
196 gtk_sctree_get_cell_style (GtkCMCList *clist,
197 GtkCMCListRow *clist_row,
208 if ((state == GTK_STATE_NORMAL) &&
209 (gtk_widget_get_state (GTK_WIDGET (clist)) == GTK_STATE_INSENSITIVE))
210 fg_state = GTK_STATE_INSENSITIVE;
214 if (clist_row->cell[column].style)
217 *style = clist_row->cell[column].style;
219 *fg_gc = clist_row->cell[column].style->fg_gc[fg_state];
221 if (state == GTK_STATE_SELECTED)
222 *bg_gc = clist_row->cell[column].style->bg_gc[state];
225 else if (clist_row->style)
228 *style = clist_row->style;
230 *fg_gc = clist_row->style->fg_gc[fg_state];
232 if (state == GTK_STATE_SELECTED)
233 *bg_gc = clist_row->style->bg_gc[state];
235 *bg_gc = clist_row->bg_set ?
236 clist->bg_gc : clist_row->style->base_gc[state];
241 gtkstyle = gtk_widget_get_style (GTK_WIDGET (clist));
245 *fg_gc = gtkstyle->fg_gc[fg_state];
247 if (state == GTK_STATE_SELECTED)
248 *bg_gc = gtkstyle->bg_gc[state];
250 *bg_gc = gtkstyle->base_gc[state];
253 if (state != GTK_STATE_SELECTED)
255 if (fg_gc && clist_row->fg_set)
256 *fg_gc = clist->fg_gc;
257 if (bg_gc && clist_row->bg_set)
258 *bg_gc = clist->bg_gc;
264 gtk_sctree_draw_expander (GtkCMCTree *ctree,
265 GtkCMCTreeRow *ctree_row,
267 GdkRectangle *clip_rectangle,
272 gint justification_factor;
275 if (ctree->expander_style == GTK_CMCTREE_EXPANDER_NONE)
278 clist = GTK_CMCLIST (ctree);
279 if (clist->column[ctree->tree_column].justification == GTK_JUSTIFY_RIGHT)
280 justification_factor = -1;
282 justification_factor = 1;
283 if (!GTK_CMCLIST_ROW_HEIGHT_SET(GTK_CMCLIST(clist)))
284 y = (clip_rectangle->y + (clip_rectangle->height - PM_SIZE) / 2 -
285 (clip_rectangle->height + 1) % 2);
287 y = (clip_rectangle->y + (clip_rectangle->height/2 - PM_SIZE) / 2 -
288 (clip_rectangle->height/2 + 1) % 2);
290 if (!ctree_row->children)
292 switch (ctree->expander_style)
294 case GTK_CMCTREE_EXPANDER_NONE:
296 case GTK_CMCTREE_EXPANDER_TRIANGLE:
297 return x + justification_factor * (PM_SIZE + 3);
298 case GTK_CMCTREE_EXPANDER_SQUARE:
299 case GTK_CMCTREE_EXPANDER_CIRCULAR:
300 return x + justification_factor * (PM_SIZE + 1);
304 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], clip_rectangle);
305 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], clip_rectangle);
307 switch (ctree->expander_style)
309 case GTK_CMCTREE_EXPANDER_NONE:
311 case GTK_CMCTREE_EXPANDER_TRIANGLE:
312 if (ctree_row->expanded)
315 points[0].y = y + (PM_SIZE + 2) / 6;
316 points[1].x = points[0].x + justification_factor * (PM_SIZE + 2);
317 points[1].y = points[0].y;
318 points[2].x = (points[0].x +
319 justification_factor * (PM_SIZE + 2) / 2);
320 points[2].y = y + 2 * (PM_SIZE + 2) / 3;
324 points[0].x = x + justification_factor * ((PM_SIZE + 2) / 6 + 2);
326 points[1].x = points[0].x;
327 points[1].y = points[0].y + (PM_SIZE + 2);
328 points[2].x = (points[0].x +
329 justification_factor * (2 * (PM_SIZE + 2) / 3 - 1));
330 points[2].y = points[0].y + (PM_SIZE + 2) / 2;
333 gdk_draw_polygon (clist->clist_window, style->base_gc[GTK_STATE_NORMAL],
335 gdk_draw_polygon (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
338 x += justification_factor * (PM_SIZE + 3);
340 case GTK_CMCTREE_EXPANDER_SQUARE:
341 case GTK_CMCTREE_EXPANDER_CIRCULAR:
342 if (justification_factor == -1)
343 x += justification_factor * (PM_SIZE + 1);
345 if (ctree->expander_style == GTK_CMCTREE_EXPANDER_CIRCULAR)
347 gdk_draw_arc (clist->clist_window, style->base_gc[GTK_STATE_NORMAL],
348 TRUE, x, y, PM_SIZE, PM_SIZE, 0, 360 * 64);
349 gdk_draw_arc (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
350 FALSE, x, y, PM_SIZE, PM_SIZE, 0, 360 * 64);
354 gdk_draw_rectangle (clist->clist_window,
355 style->base_gc[GTK_STATE_NORMAL], TRUE,
356 x, y, PM_SIZE, PM_SIZE);
357 gdk_draw_rectangle (clist->clist_window,
358 style->fg_gc[GTK_STATE_NORMAL], FALSE,
359 x, y, PM_SIZE, PM_SIZE);
362 gdk_draw_line (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
363 x + 2, y + PM_SIZE / 2, x + PM_SIZE - 2, y + PM_SIZE / 2);
365 if (!ctree_row->expanded)
366 gdk_draw_line (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
367 x + PM_SIZE / 2, y + 2,
368 x + PM_SIZE / 2, y + PM_SIZE - 2);
370 if (justification_factor == 1)
371 x += justification_factor * (PM_SIZE + 1);
375 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
376 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
382 gtk_sctree_draw_lines (GtkCMCTree *ctree,
383 GtkCMCTreeRow *ctree_row,
387 GdkRectangle *clip_rectangle,
388 GdkRectangle *cell_rectangle,
394 GtkCMCTreeNode *node;
395 GtkCMCTreeNode *parent;
396 GdkRectangle tree_rectangle;
397 GdkRectangle tc_rectangle;
408 gint justification_factor;
410 clist = GTK_CMCLIST (ctree);
411 ycenter = clip_rectangle->y + (clip_rectangle->height / 2);
412 justify_right = (clist->column[column].justification == GTK_JUSTIFY_RIGHT);
416 offset = (clip_rectangle->x + clip_rectangle->width - 1 -
417 ctree->tree_indent * (ctree_row->level - 1));
418 justification_factor = -1;
422 offset = clip_rectangle->x + ctree->tree_indent * (ctree_row->level - 1);
423 justification_factor = 1;
426 switch (ctree->line_style)
428 case GTK_CMCTREE_LINES_NONE:
430 case GTK_CMCTREE_LINES_TABBED:
431 xcenter = offset + justification_factor * TAB_SIZE;
433 column_right = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) +
434 clist->column[ctree->tree_column].area.width +
436 column_left = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) -
437 COLUMN_INSET - CELL_SPACING);
441 tree_rectangle.y = crect->y;
442 tree_rectangle.height = crect->height;
446 tree_rectangle.x = xcenter;
447 tree_rectangle.width = column_right - xcenter;
451 tree_rectangle.x = column_left;
452 tree_rectangle.width = xcenter - column_left;
455 if (!gdk_rectangle_intersect (area, &tree_rectangle, &tc_rectangle))
457 offset += justification_factor * 3;
462 gdk_gc_set_clip_rectangle (ctree->lines_gc, crect);
464 next_level = ctree_row->level;
466 if (!ctree_row->sibling || (ctree_row->children && ctree_row->expanded))
468 node = gtk_cmctree_find_node_ptr (ctree, ctree_row);
469 if (GTK_CMCTREE_NODE_NEXT (node))
470 next_level = GTK_CMCTREE_ROW (GTK_CMCTREE_NODE_NEXT (node))->level;
475 if (ctree->tree_indent > 0)
477 node = ctree_row->parent;
480 xcenter -= (justification_factor * ctree->tree_indent);
482 if ((justify_right && xcenter < column_left) ||
483 (!justify_right && xcenter > column_right))
485 node = GTK_CMCTREE_ROW (node)->parent;
489 tree_rectangle.y = cell_rectangle->y;
490 tree_rectangle.height = cell_rectangle->height;
493 tree_rectangle.x = MAX (xcenter - ctree->tree_indent + 1,
495 tree_rectangle.width = MIN (xcenter - column_left,
500 tree_rectangle.x = xcenter;
501 tree_rectangle.width = MIN (column_right - xcenter,
505 if (!area || gdk_rectangle_intersect (area, &tree_rectangle,
508 gtk_sctree_get_cell_style (clist, >K_CMCTREE_ROW (node)->row,
509 state, row, column, NULL, NULL, &bg_gc);
511 if (bg_gc == clist->bg_gc)
512 gdk_gc_set_foreground
513 (clist->bg_gc, >K_CMCTREE_ROW (node)->row.background);
516 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
519 tree_rectangle.width,
520 tree_rectangle.height);
522 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
526 tc_rectangle.height);
528 if (next_level > GTK_CMCTREE_ROW (node)->level)
529 gdk_draw_line (clist->clist_window, ctree->lines_gc,
531 xcenter, crect->y + crect->height);
536 offset_x = MIN (ctree->tree_indent, 2 * TAB_SIZE);
537 width = offset_x / 2 + offset_x % 2;
539 parent = GTK_CMCTREE_ROW (node)->parent;
541 tree_rectangle.y = ycenter;
542 tree_rectangle.height = (cell_rectangle->y - ycenter +
543 cell_rectangle->height);
547 tree_rectangle.x = MAX(xcenter + 1 - width, column_left);
548 tree_rectangle.width = MIN (xcenter + 1 - column_left,
553 tree_rectangle.x = xcenter;
554 tree_rectangle.width = MIN (column_right - xcenter,
559 gdk_rectangle_intersect (area, &tree_rectangle,
564 gtk_sctree_get_cell_style (clist, >K_CMCTREE_ROW (parent)->row,
565 state, row, column, NULL, NULL, &bg_gc);
566 if (bg_gc == clist->bg_gc)
567 gdk_gc_set_foreground
569 >K_CMCTREE_ROW (parent)->row.background);
571 else if (state == GTK_STATE_SELECTED)
572 bg_gc = style->base_gc[state];
574 bg_gc = gtk_widget_get_style (GTK_WIDGET (clist))->base_gc[state];
577 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
580 tree_rectangle.width,
581 tree_rectangle.height);
583 gdk_draw_rectangle (clist->clist_window,
588 tc_rectangle.height);
591 gtk_sctree_get_cell_style (clist, >K_CMCTREE_ROW (node)->row,
592 state, row, column, NULL, NULL, &bg_gc);
593 if (bg_gc == clist->bg_gc)
594 gdk_gc_set_foreground
595 (clist->bg_gc, >K_CMCTREE_ROW (node)->row.background);
597 gdk_gc_set_clip_rectangle (bg_gc, crect);
598 gdk_draw_arc (clist->clist_window, bg_gc, TRUE,
599 xcenter - (justify_right * offset_x),
601 offset_x, clist->row_height,
602 (180 + (justify_right * 90)) * 64, 90 * 64);
603 gdk_gc_set_clip_rectangle (bg_gc, NULL);
605 gdk_draw_line (clist->clist_window, ctree->lines_gc,
606 xcenter, cell_rectangle->y, xcenter, ycenter);
609 gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
610 xcenter - offset_x, cell_rectangle->y,
611 offset_x, clist->row_height,
614 gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
615 xcenter, cell_rectangle->y,
616 offset_x, clist->row_height,
619 node = GTK_CMCTREE_ROW (node)->parent;
623 if (state != GTK_STATE_SELECTED)
625 tree_rectangle.y = clip_rectangle->y;
626 tree_rectangle.height = clip_rectangle->height;
627 tree_rectangle.width = COLUMN_INSET + CELL_SPACING +
628 MIN (clist->column[ctree->tree_column].area.width + COLUMN_INSET,
632 tree_rectangle.x = MAX (xcenter + 1, column_left);
634 tree_rectangle.x = column_left;
637 gdk_draw_rectangle (clist->clist_window,
638 gtk_widget_get_style (GTK_WIDGET
639 (ctree))->base_gc[GTK_STATE_NORMAL],
643 tree_rectangle.width,
644 tree_rectangle.height);
645 else if (gdk_rectangle_intersect (area, &tree_rectangle,
647 gdk_draw_rectangle (clist->clist_window,
648 gtk_widget_get_style (GTK_WIDGET
649 (ctree))->base_gc[GTK_STATE_NORMAL],
654 tc_rectangle.height);
657 xcenter = offset + (justification_factor * ctree->tree_indent / 2);
659 gtk_sctree_get_cell_style (clist, &ctree_row->row, state, row, column, NULL, NULL,
661 if (bg_gc == clist->bg_gc)
662 gdk_gc_set_foreground (clist->bg_gc, &ctree_row->row.background);
664 gdk_gc_set_clip_rectangle (bg_gc, crect);
665 if (ctree_row->is_leaf)
669 points[0].x = offset + justification_factor * TAB_SIZE;
670 points[0].y = cell_rectangle->y;
672 points[1].x = points[0].x - justification_factor * 4;
673 points[1].y = points[0].y;
675 points[2].x = points[1].x - justification_factor * 2;
676 points[2].y = points[1].y + 3;
678 points[3].x = points[2].x;
679 points[3].y = points[2].y + clist->row_height - 5;
681 points[4].x = points[3].x + justification_factor * 2;
682 points[4].y = points[3].y + 3;
684 points[5].x = points[4].x + justification_factor * 4;
685 points[5].y = points[4].y;
687 gdk_draw_polygon (clist->clist_window, bg_gc, TRUE, points, 6);
688 gdk_draw_lines (clist->clist_window, ctree->lines_gc, points, 6);
692 gdk_draw_arc (clist->clist_window, bg_gc, TRUE,
693 offset - (justify_right * 2 * TAB_SIZE),
695 2 * TAB_SIZE, clist->row_height,
696 (90 + (180 * justify_right)) * 64, 180 * 64);
697 gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
698 offset - (justify_right * 2 * TAB_SIZE),
700 2 * TAB_SIZE, clist->row_height,
701 (90 + (180 * justify_right)) * 64, 180 * 64);
703 gdk_gc_set_clip_rectangle (bg_gc, NULL);
704 gdk_gc_set_clip_rectangle (ctree->lines_gc, NULL);
706 offset += justification_factor * 3;
709 xcenter = offset + justification_factor * PM_SIZE / 2;
713 tree_rectangle.y = crect->y;
714 tree_rectangle.height = crect->height;
718 tree_rectangle.x = xcenter - PM_SIZE / 2 - 2;
719 tree_rectangle.width = (clip_rectangle->x +
720 clip_rectangle->width -tree_rectangle.x);
724 tree_rectangle.x = clip_rectangle->x + PM_SIZE / 2;
725 tree_rectangle.width = (xcenter + PM_SIZE / 2 + 2 -
729 if (!gdk_rectangle_intersect (area, &tree_rectangle, &tc_rectangle))
735 if (ctree->line_style == GTK_CMCTREE_LINES_DOTTED)
737 offset_x += abs((clip_rectangle->x + clist->hoffset) % 2);
738 offset_y = abs((cell_rectangle->y + clist->voffset) % 2);
742 clip_rectangle->height++;
743 gdk_gc_set_clip_rectangle (ctree->lines_gc, clip_rectangle);
744 gdk_draw_line (clist->clist_window, ctree->lines_gc,
746 (ctree->show_stub || clist->row_list->data != ctree_row) ?
747 cell_rectangle->y + offset_y : ycenter,
749 (ctree_row->sibling) ? crect->y +crect->height : ycenter);
751 gdk_draw_line (clist->clist_window, ctree->lines_gc,
752 xcenter + (justification_factor * offset_x), ycenter,
753 xcenter + (justification_factor * (PM_SIZE / 2 + 2)),
756 node = ctree_row->parent;
759 xcenter -= (justification_factor * ctree->tree_indent);
761 if (GTK_CMCTREE_ROW (node)->sibling)
762 gdk_draw_line (clist->clist_window, ctree->lines_gc,
763 xcenter, cell_rectangle->y + offset_y,
764 xcenter, crect->y + crect->height);
765 node = GTK_CMCTREE_ROW (node)->parent;
767 gdk_gc_set_clip_rectangle (ctree->lines_gc, NULL);
769 clip_rectangle->height--;
775 static gboolean filter_fg (PangoAttribute *attribute, gpointer data)
777 const PangoAttrClass *klass = attribute->klass;
778 if (klass->type == PANGO_ATTR_FOREGROUND)
785 sc_gtk_cmclist_create_cell_layout (GtkCMCList *clist,
786 GtkCMCListRow *clist_row,
794 gtk_sctree_get_cell_style (clist, clist_row, GTK_STATE_NORMAL, 0, column, &style,
798 cell = &clist_row->cell[column];
801 case GTK_CMCELL_TEXT:
802 case GTK_CMCELL_PIXTEXT:
803 text = ((cell->type == GTK_CMCELL_PIXTEXT) ?
804 GTK_CMCELL_PIXTEXT (*cell)->text :
805 GTK_CMCELL_TEXT (*cell)->text);
810 if (!GTK_SCTREE(clist)->use_markup[column]) {
811 layout = gtk_widget_create_pango_layout (GTK_WIDGET (clist),
812 ((cell->type == GTK_CMCELL_PIXTEXT) ?
813 GTK_CMCELL_PIXTEXT (*cell)->text :
814 GTK_CMCELL_TEXT (*cell)->text));
815 pango_layout_set_font_description (layout, style->font_desc);
817 PangoContext *context = gtk_widget_get_pango_context (GTK_WIDGET(clist));
818 layout = pango_layout_new (context);
819 pango_layout_set_markup (layout, text, -1);
820 pango_layout_set_font_description (layout, style->font_desc);
821 if (clist_row->state == GTK_STATE_SELECTED) {
822 /* for selected row, we should remove any forced foreground color
823 * or it looks like shit */
824 PangoAttrList *list = pango_layout_get_attributes(layout);
825 PangoAttrList *rem = pango_attr_list_filter(list, filter_fg, NULL);
827 pango_attr_list_unref(rem);
839 gtk_sctree_draw_row (GtkCMCList *clist,
842 GtkCMCListRow *clist_row)
849 GdkRectangle row_rectangle;
850 GdkRectangle cell_rectangle;
851 GdkRectangle clip_rectangle;
852 GdkRectangle intersect_rectangle;
854 gint column_left = 0;
855 gint column_right = 0;
859 static GdkColor greybg={0, 0, 0, 0};
860 static gboolean color_change = TRUE;
862 cm_return_if_fail (clist != NULL);
863 widget = GTK_WIDGET (clist);
864 style = gtk_widget_get_style (widget);
866 if (greybg.pixel == 0 &&
870 GdkColor normalbg = {0, 0xffff, 0xffff, 0xffff};
872 normalbg = style->base[GTK_STATE_NORMAL];
874 if (normalbg.red > 0x8888 && normalbg.green > 0x8888 && normalbg.blue > 0x8888) {
875 greybg.pixel = normalbg.pixel;
876 greybg.red = normalbg.red - prefs_common.stripes_color_offset;
877 greybg.green = normalbg.green - prefs_common.stripes_color_offset;
878 greybg.blue = normalbg.blue - prefs_common.stripes_color_offset;
879 } else if (normalbg.red < 0x8888 && normalbg.green < 0x8888 && normalbg.blue < 0x8888) {
880 greybg.pixel = normalbg.pixel;
881 greybg.red = normalbg.red + prefs_common.stripes_color_offset;
882 greybg.green = normalbg.green + prefs_common.stripes_color_offset;
883 greybg.blue = normalbg.blue + prefs_common.stripes_color_offset;
885 color_change = FALSE;
889 /* bail now if we arn't drawable yet */
890 if (!gtkut_widget_is_drawable (GTK_WIDGET(clist)) || row < 0 || row >= clist->rows)
893 ctree = GTK_CMCTREE (clist);
895 /* if the function is passed the pointer to the row instead of null,
896 * it avoids this expensive lookup */
898 clist_row = (g_list_nth (clist->row_list, row))->data;
900 /* rectangle of the entire row */
902 row_rectangle.y = ROW_TOP_YPIXEL (clist, row);
903 row_rectangle.width = clist->clist_window_width;
904 row_rectangle.height = clist->row_height;
906 /* rectangle of the cell spacing above the row */
907 cell_rectangle.x = 0;
908 cell_rectangle.y = row_rectangle.y - CELL_SPACING;
909 cell_rectangle.width = row_rectangle.width;
910 cell_rectangle.height = CELL_SPACING;
912 /* rectangle used to clip drawing operations, its y and height
913 * positions only need to be set once, so we set them once here.
914 * the x and width are set withing the drawing loop below once per
916 clip_rectangle.y = row_rectangle.y;
917 clip_rectangle.height = row_rectangle.height;
919 if (prefs_common.use_stripes_everywhere && GTK_SCTREE(ctree)->show_stripes
920 && color_change && row % 2) {
921 clist_row->background = greybg;
922 clist_row->bg_set = TRUE;
924 clist_row->bg_set = FALSE;
926 if (clist_row->state == GTK_STATE_NORMAL)
928 if (clist_row->fg_set)
929 gdk_gc_set_foreground (clist->fg_gc, &clist_row->foreground);
930 if (clist_row->bg_set)
931 gdk_gc_set_rgb_fg_color (clist->bg_gc, &clist_row->background);
934 state = clist_row->state;
936 gdk_gc_set_foreground (ctree->lines_gc,
937 &style->fg[clist_row->state]);
939 /* draw the cell borders */
942 rect = &intersect_rectangle;
943 crect = &intersect_rectangle;
945 if (gdk_rectangle_intersect (area, &cell_rectangle, crect))
946 gdk_draw_rectangle (clist->clist_window,
947 style->base_gc[GTK_STATE_NORMAL], TRUE,
948 crect->x, crect->y, crect->width, crect->height);
952 rect = &clip_rectangle;
953 crect = &cell_rectangle;
955 gdk_draw_rectangle (clist->clist_window,
956 style->base_gc[GTK_STATE_NORMAL], TRUE,
957 crect->x, crect->y, crect->width, crect->height);
960 /* horizontal black lines */
961 if (ctree->line_style == GTK_CMCTREE_LINES_TABBED)
964 column_right = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) +
965 clist->column[ctree->tree_column].area.width +
967 column_left = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) -
968 COLUMN_INSET - (ctree->tree_column != 0) * CELL_SPACING);
970 switch (clist->column[ctree->tree_column].justification)
972 case GTK_JUSTIFY_CENTER:
973 case GTK_JUSTIFY_FILL:
974 case GTK_JUSTIFY_LEFT:
975 offset = (column_left + ctree->tree_indent *
976 (((GtkCMCTreeRow *)clist_row)->level - 1));
978 gdk_draw_line (clist->clist_window, ctree->lines_gc,
979 MIN (offset + TAB_SIZE, column_right),
981 clist->clist_window_width, cell_rectangle.y);
983 case GTK_JUSTIFY_RIGHT:
984 offset = (column_right - 1 - ctree->tree_indent *
985 (((GtkCMCTreeRow *)clist_row)->level - 1));
987 gdk_draw_line (clist->clist_window, ctree->lines_gc,
988 -1, cell_rectangle.y,
989 MAX (offset - TAB_SIZE, column_left),
995 /* the last row has to clear its bottom cell spacing too */
996 if (clist_row == clist->row_list_end->data)
998 cell_rectangle.y += clist->row_height + CELL_SPACING;
1000 if (!area || gdk_rectangle_intersect (area, &cell_rectangle, crect))
1002 gdk_draw_rectangle (clist->clist_window,
1003 style->base_gc[GTK_STATE_NORMAL], TRUE,
1004 crect->x, crect->y, crect->width, crect->height);
1006 /* horizontal black lines */
1007 if (ctree->line_style == GTK_CMCTREE_LINES_TABBED)
1009 switch (clist->column[ctree->tree_column].justification)
1011 case GTK_JUSTIFY_CENTER:
1012 case GTK_JUSTIFY_FILL:
1013 case GTK_JUSTIFY_LEFT:
1014 gdk_draw_line (clist->clist_window, ctree->lines_gc,
1015 MIN (column_left + TAB_SIZE + COLUMN_INSET +
1016 (((GtkCMCTreeRow *)clist_row)->level > 1) *
1017 MIN (ctree->tree_indent / 2, TAB_SIZE),
1020 clist->clist_window_width, cell_rectangle.y);
1022 case GTK_JUSTIFY_RIGHT:
1023 gdk_draw_line (clist->clist_window, ctree->lines_gc,
1024 -1, cell_rectangle.y,
1025 MAX (column_right - TAB_SIZE - 1 -
1027 (((GtkCMCTreeRow *)clist_row)->level > 1) *
1028 MIN (ctree->tree_indent / 2, TAB_SIZE),
1029 column_left - 1), cell_rectangle.y);
1036 for (last_column = clist->columns - 1;
1037 last_column >= 0 && !clist->column[last_column].visible; last_column--)
1040 /* iterate and draw all the columns (row cells) and draw their contents */
1041 for (i = 0; i < clist->columns; i++)
1046 PangoLayout *layout = NULL;
1047 PangoRectangle logical_rect;
1055 if (!clist->column[i].visible)
1058 gtk_sctree_get_cell_style (clist, clist_row, state, row, i, &style, &fg_gc, &bg_gc);
1060 /* calculate clipping region */
1061 clip_rectangle.x = clist->column[i].area.x + clist->hoffset;
1062 clip_rectangle.width = clist->column[i].area.width;
1064 cell_rectangle.x = clip_rectangle.x - COLUMN_INSET - CELL_SPACING;
1065 cell_rectangle.width = (clip_rectangle.width + 2 * COLUMN_INSET +
1066 (1 + (i == last_column)) * CELL_SPACING);
1067 cell_rectangle.y = clip_rectangle.y;
1068 cell_rectangle.height = clip_rectangle.height;
1074 if (area && !gdk_rectangle_intersect (area, &cell_rectangle,
1075 &intersect_rectangle))
1077 if (i != ctree->tree_column)
1082 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
1083 crect->x, crect->y, crect->width, crect->height);
1086 layout = sc_gtk_cmclist_create_cell_layout (clist, clist_row, i);
1089 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1090 width = logical_rect.width;
1095 switch (clist_row->cell[i].type)
1097 case GTK_CMCELL_PIXBUF:
1098 pixbuf_width = gdk_pixbuf_get_width(GTK_CMCELL_PIXBUF (clist_row->cell[i])->pixbuf);
1099 height = gdk_pixbuf_get_height(GTK_CMCELL_PIXBUF (clist_row->cell[i])->pixbuf);
1100 width += pixbuf_width;
1102 case GTK_CMCELL_PIXTEXT:
1103 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf)
1105 pixbuf_width = gdk_pixbuf_get_width(GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf);
1106 height = gdk_pixbuf_get_height(GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf);
1107 width += pixbuf_width;
1110 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->text &&
1111 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf)
1112 width += GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1114 if (i == ctree->tree_column)
1115 width += (ctree->tree_indent *
1116 ((GtkCMCTreeRow *)clist_row)->level);
1122 switch (clist->column[i].justification)
1124 case GTK_JUSTIFY_LEFT:
1125 offset = clip_rectangle.x + clist_row->cell[i].horizontal;
1127 case GTK_JUSTIFY_RIGHT:
1128 offset = (clip_rectangle.x + clist_row->cell[i].horizontal +
1129 clip_rectangle.width - width);
1131 case GTK_JUSTIFY_CENTER:
1132 case GTK_JUSTIFY_FILL:
1133 offset = (clip_rectangle.x + clist_row->cell[i].horizontal +
1134 (clip_rectangle.width / 2) - (width / 2));
1138 if (i != ctree->tree_column)
1140 int start_y = (clip_rectangle.height - height) / 2;
1141 if (GTK_CMCLIST_ROW_HEIGHT_SET(GTK_CMCLIST(clist)))
1142 start_y = (clip_rectangle.height/2 - height) / 2;
1144 offset += clist_row->cell[i].horizontal;
1145 switch (clist_row->cell[i].type)
1147 case GTK_CMCELL_PIXBUF:
1148 gtk_sctree_draw_cell_pixbuf
1149 (clist->clist_window, &clip_rectangle, fg_gc,
1150 GTK_CMCELL_PIXBUF (clist_row->cell[i])->pixbuf,
1152 clip_rectangle.y + clist_row->cell[i].vertical +
1154 pixbuf_width, height);
1156 case GTK_CMCELL_PIXTEXT:
1157 offset = gtk_sctree_draw_cell_pixbuf
1158 (clist->clist_window, &clip_rectangle, fg_gc,
1159 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf,
1161 clip_rectangle.y + clist_row->cell[i].vertical +
1163 pixbuf_width, height);
1164 offset += GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1167 case GTK_CMCELL_TEXT:
1170 gint row_center_offset = (clist->row_height - logical_rect.height) / 2;
1172 gdk_gc_set_clip_rectangle (fg_gc, &clip_rectangle);
1173 gdk_draw_layout (clist->clist_window, fg_gc,
1175 row_rectangle.y + row_center_offset + clist_row->cell[i].vertical,
1177 gdk_gc_set_clip_rectangle (fg_gc, NULL);
1178 g_object_unref (G_OBJECT (layout));
1188 if (bg_gc == clist->bg_gc)
1189 gdk_gc_set_background (ctree->lines_gc, &clist_row->background);
1191 /* draw ctree->tree_column */
1192 cell_rectangle.y -= CELL_SPACING;
1193 cell_rectangle.height += CELL_SPACING;
1195 if (area && !gdk_rectangle_intersect (area, &cell_rectangle,
1196 &intersect_rectangle))
1199 g_object_unref (G_OBJECT (layout));
1204 offset = gtk_sctree_draw_lines (ctree, (GtkCMCTreeRow *)clist_row, row, i,
1205 state, &clip_rectangle, &cell_rectangle,
1206 crect, area, style);
1209 offset = gtk_sctree_draw_expander (ctree, (GtkCMCTreeRow *)clist_row,
1210 style, &clip_rectangle, offset);
1212 if (clist->column[i].justification == GTK_JUSTIFY_RIGHT)
1213 offset -= ctree->tree_spacing;
1215 offset += ctree->tree_spacing;
1217 if (clist->column[i].justification == GTK_JUSTIFY_RIGHT)
1218 offset -= (pixbuf_width + clist_row->cell[i].horizontal);
1220 offset += clist_row->cell[i].horizontal;
1222 old_offset = offset;
1223 offset = gtk_sctree_draw_cell_pixbuf (clist->clist_window, &clip_rectangle, fg_gc,
1224 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf,
1226 clip_rectangle.y + clist_row->cell[i].vertical
1227 + (clip_rectangle.height - height) / 2,
1228 pixbuf_width, height);
1232 gint row_center_offset = (clist->row_height - logical_rect.height) / 2;
1234 if (clist->column[i].justification == GTK_JUSTIFY_RIGHT)
1236 offset = (old_offset - string_width);
1237 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf)
1238 offset -= GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1242 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf)
1243 offset += GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1246 gdk_gc_set_clip_rectangle (fg_gc, &clip_rectangle);
1247 gdk_draw_layout (clist->clist_window, fg_gc,
1249 row_rectangle.y + row_center_offset + clist_row->cell[i].vertical,
1252 g_object_unref (G_OBJECT (layout));
1254 gdk_gc_set_clip_rectangle (fg_gc, NULL);
1257 /* draw focus rectangle */
1258 if (clist->focus_row == row &&
1259 gtkut_widget_get_can_focus (widget) && gtkut_widget_has_focus (widget))
1262 gdk_draw_rectangle (clist->clist_window, clist->xor_gc, FALSE,
1263 row_rectangle.x, row_rectangle.y,
1264 row_rectangle.width - 1, row_rectangle.height - 1);
1265 else if (gdk_rectangle_intersect (area, &row_rectangle,
1266 &intersect_rectangle))
1268 gdk_gc_set_clip_rectangle (clist->xor_gc, &intersect_rectangle);
1269 gdk_draw_rectangle (clist->clist_window, clist->xor_gc, FALSE,
1270 row_rectangle.x, row_rectangle.y,
1271 row_rectangle.width - 1,
1272 row_rectangle.height - 1);
1273 gdk_gc_set_clip_rectangle (clist->xor_gc, NULL);
1279 gtk_sctree_change_focus_row_expansion (GtkCMCTree *ctree,
1280 GtkCMCTreeExpansionType action)
1283 GtkCMCTreeNode *node;
1285 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
1287 clist = GTK_CMCLIST (ctree);
1289 if (gdk_display_pointer_is_grabbed (gtk_widget_get_display (GTK_WIDGET (ctree))) &&
1290 gtkut_widget_has_grab (GTK_WIDGET(ctree)))
1294 GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row))) ||
1295 GTK_CMCTREE_ROW (node)->is_leaf || !(GTK_CMCTREE_ROW (node)->children))
1300 case GTK_CMCTREE_EXPANSION_EXPAND:
1301 if (GTK_SCTREE(ctree)->always_expand_recursively)
1302 gtk_cmctree_expand_recursive (ctree, node);
1304 gtk_cmctree_expand (ctree, node);
1307 case GTK_CMCTREE_EXPANSION_EXPAND_RECURSIVE:
1308 gtk_cmctree_expand_recursive (ctree, node);
1310 case GTK_CMCTREE_EXPANSION_COLLAPSE:
1311 gtk_cmctree_collapse (ctree, node);
1313 case GTK_CMCTREE_EXPANSION_COLLAPSE_RECURSIVE:
1314 gtk_cmctree_collapse_recursive (ctree, node);
1316 case GTK_CMCTREE_EXPANSION_TOGGLE:
1317 if (GTK_SCTREE(ctree)->always_expand_recursively)
1318 gtk_cmctree_toggle_expansion_recursive (ctree, node);
1320 gtk_cmctree_toggle_expansion (ctree, node);
1322 case GTK_CMCTREE_EXPANSION_TOGGLE_RECURSIVE:
1323 gtk_cmctree_toggle_expansion_recursive (ctree, node);
1328 static void gtk_sctree_finalize(GObject *object)
1330 GtkSCTree *sctree = GTK_SCTREE(object);
1331 g_free(sctree->use_markup);
1332 sctree->use_markup = NULL;
1333 G_OBJECT_CLASS (parent_class)->finalize (object);
1336 /* Standard class initialization function */
1338 gtk_sctree_class_init (GtkSCTreeClass *klass)
1340 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1341 GtkObjectClass *object_class;
1342 GtkWidgetClass *widget_class;
1343 GtkCMCListClass *clist_class;
1344 GtkCMCTreeClass *ctree_class;
1346 object_class = (GtkObjectClass *) klass;
1347 widget_class = (GtkWidgetClass *) klass;
1348 clist_class = (GtkCMCListClass *) klass;
1349 ctree_class = (GtkCMCTreeClass *) klass;
1351 parent_class = g_type_class_peek (gtk_cmctree_get_type ());
1353 sctree_signals[ROW_POPUP_MENU] =
1354 g_signal_new ("row_popup_menu",
1355 G_TYPE_FROM_CLASS (klass),
1357 G_STRUCT_OFFSET (GtkSCTreeClass, row_popup_menu),
1359 claws_marshal_VOID__POINTER,
1362 sctree_signals[EMPTY_POPUP_MENU] =
1363 g_signal_new ("empty_popup_menu",
1364 G_TYPE_FROM_CLASS (klass),
1366 G_STRUCT_OFFSET (GtkSCTreeClass, empty_popup_menu),
1368 claws_marshal_VOID__POINTER,
1371 sctree_signals[OPEN_ROW] =
1372 g_signal_new ("open_row",
1373 G_TYPE_FROM_CLASS (klass),
1375 G_STRUCT_OFFSET (GtkSCTreeClass, open_row),
1377 g_cclosure_marshal_VOID__VOID,
1379 sctree_signals[START_DRAG] =
1380 g_signal_new ("start_drag",
1381 G_TYPE_FROM_CLASS (klass),
1383 G_STRUCT_OFFSET (GtkSCTreeClass, start_drag),
1385 claws_marshal_VOID__INT_POINTER,
1390 /* gtk_object_class_add_signals (object_class, sctree_signals, LAST_SIGNAL); */
1392 clist_class->clear = gtk_sctree_clear;
1393 clist_class->draw_row = gtk_sctree_draw_row;
1394 clist_class->unselect_all = gtk_sctree_real_unselect_all;
1395 ctree_class->tree_collapse = gtk_sctree_real_tree_collapse;
1396 ctree_class->tree_expand = gtk_sctree_real_tree_expand;
1397 ctree_class->tree_move = sreal_tree_move;
1398 ctree_class->change_focus_row_expansion = gtk_sctree_change_focus_row_expansion;
1400 widget_class->button_press_event = gtk_sctree_button_press;
1401 widget_class->button_release_event = gtk_sctree_button_release;
1402 widget_class->motion_notify_event = gtk_sctree_motion;
1403 widget_class->drag_begin = gtk_sctree_drag_begin;
1404 widget_class->drag_end = gtk_sctree_drag_end;
1405 widget_class->drag_data_get = gtk_sctree_drag_data_get;
1406 widget_class->drag_leave = gtk_sctree_drag_leave;
1407 widget_class->drag_motion = gtk_sctree_drag_motion;
1408 widget_class->drag_drop = gtk_sctree_drag_drop;
1409 widget_class->drag_data_received = gtk_sctree_drag_data_received;
1411 gobject_class->finalize = gtk_sctree_finalize;
1414 /* Standard object initialization function */
1416 gtk_sctree_init (GtkSCTree *sctree)
1418 sctree->anchor_row = NULL;
1420 /* GtkCMCTree does not specify pointer motion by default */
1421 gtk_widget_add_events (GTK_WIDGET (sctree), GDK_POINTER_MOTION_MASK);
1422 gtk_widget_add_events (GTK_WIDGET (sctree), GDK_POINTER_MOTION_MASK);
1425 /* Get information the specified row is selected. */
1428 row_is_selected(GtkSCTree *sctree, gint row)
1430 GtkCMCListRow *clist_row;
1431 clist_row = g_list_nth (GTK_CMCLIST(sctree)->row_list, row)->data;
1432 return clist_row ? clist_row->state == GTK_STATE_SELECTED : FALSE;
1435 /* Selects the rows between the anchor to the specified row, inclusive. */
1437 select_range (GtkSCTree *sctree, gint row)
1443 if (sctree->anchor_row == NULL) {
1445 sctree->anchor_row = gtk_cmctree_node_nth(GTK_CMCTREE(sctree), row);
1447 prev_row = g_list_position(GTK_CMCLIST(sctree)->row_list,
1448 (GList *)sctree->anchor_row);
1450 if (row < prev_row) {
1453 GTK_CMCLIST(sctree)->focus_row = max;
1458 sctree->selecting_range++;
1467 gtk_cmclist_freeze(GTK_CMCLIST(sctree));
1469 node = g_list_nth((GTK_CMCLIST(sctree))->row_list, min);
1470 for (i = min; i < max; i++) {
1471 if (node && GTK_CMCTREE_ROW (node)->row.selectable) {
1472 g_signal_emit_by_name(G_OBJECT(sctree), "tree_select_row",
1478 gtk_cmclist_thaw(GTK_CMCLIST(sctree));
1481 sctree->selecting_range--;
1482 gtk_cmclist_select_row (GTK_CMCLIST (sctree), max, -1);
1485 /* Handles row selection according to the specified modifier state */
1486 /* in certain cases, we arrive here from a function knowing the GtkCMCTreeNode, and having
1487 * already slowly found row using g_list_position. In which case, _node will be non-NULL
1488 * to avoid this function having to slowly find it with g_list_nth. */
1490 select_row (GtkSCTree *sctree, gint row, gint col, guint state, GtkCMCTreeNode *_node)
1492 gboolean range, additive;
1493 cm_return_if_fail (sctree != NULL);
1494 cm_return_if_fail (GTK_IS_SCTREE (sctree));
1496 range = ((state & GDK_SHIFT_MASK) != 0) &&
1497 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_SINGLE) &&
1498 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_BROWSE);
1499 additive = ((state & GDK_CONTROL_MASK) != 0) &&
1500 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_SINGLE) &&
1501 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_BROWSE);
1503 if (!range && !additive && sctree->force_additive_sel)
1506 GTK_CMCLIST(sctree)->focus_row = row;
1509 gtk_cmclist_unselect_all (GTK_CMCLIST (sctree));
1513 GtkCMCTreeNode *node;
1515 node = _node ? _node : gtk_cmctree_node_nth (GTK_CMCTREE(sctree), row);
1517 /*No need to manage overlapped list*/
1519 if (row_is_selected(sctree, row))
1520 gtk_cmclist_unselect_row (GTK_CMCLIST (sctree), row, col);
1522 g_signal_emit_by_name
1524 "tree_select_row", node, col);
1526 g_signal_emit_by_name
1528 "tree_select_row", node, col);
1530 sctree->anchor_row = node;
1532 select_range (sctree, row);
1536 sctree_is_hot_spot (GtkSCTree *sctree,
1537 GtkCMCTreeNode *node,
1542 GtkCMCTreeRow *tree_row;
1545 GtkCMCellPixText *cell;
1549 cm_return_val_if_fail (GTK_IS_SCTREE (sctree), FALSE);
1550 cm_return_val_if_fail (node != NULL, FALSE);
1552 clist = GTK_CMCLIST (sctree);
1553 ctree = GTK_CMCTREE (sctree);
1555 if (!clist->column[ctree->tree_column].visible ||
1556 ctree->expander_style == GTK_CMCTREE_EXPANDER_NONE)
1559 tree_row = GTK_CMCTREE_ROW (node);
1561 cell = GTK_CMCELL_PIXTEXT (tree_row->row.cell[ctree->tree_column]);
1563 if (!GTK_CMCLIST_ROW_HEIGHT_SET(GTK_CMCLIST(clist)))
1564 yu = (ROW_TOP_YPIXEL (clist, row) + (clist->row_height - PM_SIZE) / 2 -
1565 (clist->row_height - 1) % 2);
1567 yu = (ROW_TOP_YPIXEL (clist, row) + (clist->row_height/2 - PM_SIZE) / 2 -
1568 (clist->row_height/2 - 1) % 2);
1570 #ifndef GENERIC_UMPC
1571 if (clist->column[ctree->tree_column].justification == GTK_JUSTIFY_RIGHT)
1572 xl = (clist->column[ctree->tree_column].area.x +
1573 clist->column[ctree->tree_column].area.width - 1 + clist->hoffset -
1574 (tree_row->level - 1) * ctree->tree_indent - PM_SIZE -
1575 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1577 xl = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1578 (tree_row->level - 1) * ctree->tree_indent +
1579 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1581 xmax = xl + PM_SIZE;
1583 if (clist->column[ctree->tree_column].justification == GTK_JUSTIFY_RIGHT) {
1584 xl = (clist->column[ctree->tree_column].area.x +
1585 clist->column[ctree->tree_column].area.width - 1 + clist->hoffset -
1586 (tree_row->level - 1) * ctree->tree_indent - PM_SIZE -
1587 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1588 xmax = xl + PM_SIZE;
1589 } else if (ctree->tree_column == 0) {
1590 xl = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1591 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1592 xmax = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1593 (tree_row->level - 1) * ctree->tree_indent +
1594 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3) +
1597 xl = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1598 (tree_row->level - 1) * ctree->tree_indent +
1599 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1600 xmax = xl + PM_SIZE;
1603 return (x >= xl && x <= xmax && y >= yu && y <= yu + PM_SIZE);
1607 gtk_sctree_is_hot_spot (GtkSCTree *ctree,
1611 GtkCMCTreeNode *node;
1615 cm_return_val_if_fail (GTK_IS_SCTREE (ctree), FALSE);
1617 if (gtk_cmclist_get_selection_info (GTK_CMCLIST (ctree), x, y, &row, &column))
1618 if ((node = GTK_CMCTREE_NODE(g_list_nth (GTK_CMCLIST (ctree)->row_list, row))))
1619 return sctree_is_hot_spot (ctree, node, row, x, y);
1624 /* Our handler for button_press events. We override all of GtkCMCList's broken
1628 gtk_sctree_button_press (GtkWidget *widget, GdkEventButton *event)
1637 cm_return_val_if_fail (widget != NULL, FALSE);
1638 cm_return_val_if_fail (GTK_IS_SCTREE (widget), FALSE);
1639 cm_return_val_if_fail (event != NULL, FALSE);
1641 sctree = GTK_SCTREE (widget);
1642 clist = GTK_CMCLIST (widget);
1645 if (event->window != clist->clist_window)
1646 return (* GTK_WIDGET_CLASS (parent_class)->button_press_event) (widget, event);
1648 on_row = gtk_cmclist_get_selection_info (clist, event->x, event->y, &row, &col);
1650 if (on_row && !gtkut_widget_has_focus(widget))
1651 gtk_widget_grab_focus (widget);
1653 if (gtk_sctree_is_hot_spot (GTK_SCTREE(sctree), event->x, event->y)) {
1654 GtkCMCTreeNode *node = gtk_cmctree_node_nth(GTK_CMCTREE(sctree), row);
1655 if (GTK_CMCTREE_ROW (node)->expanded)
1656 gtk_cmctree_collapse(GTK_CMCTREE(sctree), node);
1657 else if (GTK_SCTREE(sctree)->always_expand_recursively)
1658 gtk_cmctree_expand_recursive (GTK_CMCTREE(sctree), node);
1660 gtk_cmctree_expand(GTK_CMCTREE(sctree), node);
1664 switch (event->type) {
1665 case GDK_BUTTON_PRESS:
1666 if (event->button == 1 || event->button == 2) {
1667 if (event->button == 2)
1668 event->state &= ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK);
1670 /* Save the mouse info for DnD */
1671 sctree->dnd_press_button = event->button;
1672 sctree->dnd_press_x = event->x;
1673 sctree->dnd_press_y = event->y;
1675 /* Handle selection */
1676 if ((row_is_selected (sctree, row)
1677 && !(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)))
1678 || ((event->state & GDK_CONTROL_MASK)
1679 && !(event->state & GDK_SHIFT_MASK))) {
1680 sctree->dnd_select_pending = TRUE;
1681 sctree->dnd_select_pending_state = event->state;
1682 sctree->dnd_select_pending_row = row;
1684 select_row (sctree, row, col, event->state, NULL);
1687 gtk_cmclist_unselect_all (clist);
1691 } else if (event->button == 3) {
1692 /* Emit *_popup_menu signal*/
1694 if (!row_is_selected(sctree,row))
1695 select_row (sctree, row, col, 0, NULL);
1696 g_signal_emit (G_OBJECT (sctree),
1697 sctree_signals[ROW_POPUP_MENU],
1700 gtk_cmclist_unselect_all(clist);
1701 g_signal_emit (G_OBJECT (sctree),
1702 sctree_signals[EMPTY_POPUP_MENU],
1710 case GDK_2BUTTON_PRESS:
1711 if (event->button != 1)
1714 sctree->dnd_select_pending = FALSE;
1715 sctree->dnd_select_pending_state = 0;
1718 g_signal_emit (G_OBJECT (sctree),
1719 sctree_signals[OPEN_ROW], 0);
1731 /* Our handler for button_release events. We override all of GtkCMCList's broken
1735 gtk_sctree_button_release (GtkWidget *widget, GdkEventButton *event)
1743 cm_return_val_if_fail (widget != NULL, FALSE);
1744 cm_return_val_if_fail (GTK_IS_SCTREE (widget), FALSE);
1745 cm_return_val_if_fail (event != NULL, FALSE);
1747 sctree = GTK_SCTREE (widget);
1748 clist = GTK_CMCLIST (widget);
1751 if (event->window != clist->clist_window)
1752 return (* GTK_WIDGET_CLASS (parent_class)->button_release_event) (widget, event);
1754 on_row = gtk_cmclist_get_selection_info (clist, event->x, event->y, &row, &col);
1756 if (!(event->button == 1 || event->button == 2))
1759 sctree->dnd_press_button = 0;
1760 sctree->dnd_press_x = 0;
1761 sctree->dnd_press_y = 0;
1764 if (sctree->dnd_select_pending) {
1765 select_row (sctree, row, col, sctree->dnd_select_pending_state, NULL);
1766 sctree->dnd_select_pending = FALSE;
1767 sctree->dnd_select_pending_state = 0;
1776 /* Our handler for motion_notify events. We override all of GtkCMCList's broken
1780 gtk_sctree_motion (GtkWidget *widget, GdkEventMotion *event)
1785 cm_return_val_if_fail (widget != NULL, FALSE);
1786 cm_return_val_if_fail (GTK_IS_SCTREE (widget), FALSE);
1787 cm_return_val_if_fail (event != NULL, FALSE);
1789 sctree = GTK_SCTREE (widget);
1790 clist = GTK_CMCLIST (widget);
1792 if (event->window != clist->clist_window)
1793 return (* GTK_WIDGET_CLASS (parent_class)->motion_notify_event) (widget, event);
1795 if (!((sctree->dnd_press_button == 1 && (event->state & GDK_BUTTON1_MASK))
1796 || (sctree->dnd_press_button == 2 && (event->state & GDK_BUTTON2_MASK))))
1799 /* This is the same threshold value that is used in gtkdnd.c */
1801 #ifndef GENERIC_UMPC
1806 if (MAX (ABS (sctree->dnd_press_x - event->x),
1807 ABS (sctree->dnd_press_y - event->y)) <= THRESHOLD)
1810 /* Handle any pending selections */
1812 if (sctree->dnd_select_pending) {
1813 if (!row_is_selected(sctree,sctree->dnd_select_pending_row))
1815 sctree->dnd_select_pending_row,
1817 sctree->dnd_select_pending_state,
1820 sctree->dnd_select_pending = FALSE;
1821 sctree->dnd_select_pending_state = 0;
1824 g_signal_emit (G_OBJECT (sctree),
1825 sctree_signals[START_DRAG],
1827 sctree->dnd_press_button,
1832 /* We override the drag_begin signal to do nothing */
1834 gtk_sctree_drag_begin (GtkWidget *widget, GdkDragContext *context)
1839 /* We override the drag_end signal to do nothing */
1841 gtk_sctree_drag_end (GtkWidget *widget, GdkDragContext *context)
1846 /* We override the drag_data_get signal to do nothing */
1848 gtk_sctree_drag_data_get (GtkWidget *widget, GdkDragContext *context,
1849 GtkSelectionData *data, guint info, guint time)
1854 /* We override the drag_leave signal to do nothing */
1856 gtk_sctree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time)
1861 /* We override the drag_motion signal to do nothing */
1863 gtk_sctree_drag_motion (GtkWidget *widget, GdkDragContext *context,
1864 gint x, gint y, guint time)
1869 /* We override the drag_drop signal to do nothing */
1871 gtk_sctree_drag_drop (GtkWidget *widget, GdkDragContext *context,
1872 gint x, gint y, guint time)
1877 /* We override the drag_data_received signal to do nothing */
1879 gtk_sctree_drag_data_received (GtkWidget *widget, GdkDragContext *context,
1880 gint x, gint y, GtkSelectionData *data,
1881 guint info, guint time)
1886 /* Our handler for the clear signal of the clist. We have to reset the anchor
1890 gtk_sctree_clear (GtkCMCList *clist)
1894 cm_return_if_fail (clist != NULL);
1895 cm_return_if_fail (GTK_IS_SCTREE (clist));
1897 sctree = GTK_SCTREE (clist);
1898 sctree->anchor_row = NULL;
1900 if (((GtkCMCListClass *)parent_class)->clear)
1901 (* ((GtkCMCListClass *)parent_class)->clear) (clist);
1905 gtk_sctree_real_unselect_all (GtkCMCList *clist)
1908 gboolean should_freeze = FALSE;
1910 cm_return_if_fail (clist != NULL);
1911 cm_return_if_fail (GTK_IS_SCTREE (clist));
1913 sctree = GTK_SCTREE (clist);
1915 if (sc_g_list_bigger(GTK_CMCLIST(sctree)->selection, 10)) {
1916 should_freeze = TRUE;
1917 sctree->selecting_range++;
1918 gtk_cmclist_freeze (GTK_CMCLIST (sctree));
1921 if (((GtkCMCListClass *)parent_class)->unselect_all)
1922 (* ((GtkCMCListClass *)parent_class)->unselect_all) (clist);
1924 if (should_freeze) {
1925 gtk_cmclist_thaw (GTK_CMCLIST (sctree));
1926 sctree->selecting_range--;
1931 gtk_sctree_column_auto_resize (GtkCMCList *clist,
1932 GtkCMCListRow *clist_row,
1936 /* resize column if needed for auto_resize */
1937 GtkRequisition requisition;
1939 if (!clist->column[column].auto_resize ||
1940 GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
1944 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request (clist, clist_row,
1945 column, &requisition);
1947 requisition.width = 0;
1949 if (requisition.width > clist->column[column].width)
1950 gtk_cmclist_set_column_width (clist, column, requisition.width);
1951 else if (requisition.width < old_width &&
1952 old_width == clist->column[column].width)
1955 GtkRequisition button_req;
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)
1962 gtk_widget_get_requisition (clist->column[column].button, &button_req);
1963 new_width = (button_req.width -
1964 (CELL_SPACING + (2 * COLUMN_INSET)));
1969 for (list = clist->row_list; list; list = list->next)
1971 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
1972 (clist, GTK_CMCLIST_ROW (list), column, &requisition);
1973 new_width = MAX (new_width, requisition.width);
1974 if (new_width == clist->column[column].width)
1977 if (new_width < clist->column[column].width)
1978 gtk_cmclist_set_column_width (clist, column, new_width);
1983 gtk_sctree_auto_resize_columns (GtkCMCList *clist)
1987 if (GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
1990 for (i = 0; i < clist->columns; i++)
1991 gtk_sctree_column_auto_resize (clist, NULL, i, clist->column[i].width);
1995 gtk_sctree_real_tree_collapse (GtkCMCTree *ctree,
1996 GtkCMCTreeNode *node)
1999 GtkCMCTreeNode *work;
2000 GtkRequisition requisition;
2004 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2006 if (!node || !GTK_CMCTREE_ROW (node)->expanded ||
2007 GTK_CMCTREE_ROW (node)->is_leaf)
2010 clist = GTK_CMCLIST (ctree);
2012 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2014 GTK_CMCTREE_ROW (node)->expanded = FALSE;
2015 level = GTK_CMCTREE_ROW (node)->level;
2017 visible = gtk_cmctree_is_viewable (ctree, node);
2018 /* get cell width if tree_column is auto resized */
2019 if (visible && clist->column[ctree->tree_column].auto_resize &&
2020 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2021 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2022 (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column, &requisition);
2024 /* unref/unset opened pixbuf */
2025 if (GTK_CMCELL_PIXTEXT
2026 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf)
2030 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf);
2033 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf = NULL;
2036 /* set/ref closed pixbuf */
2037 if (GTK_CMCTREE_ROW (node)->pixbuf_closed)
2040 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf =
2041 g_object_ref (GTK_CMCTREE_ROW (node)->pixbuf_closed);
2044 work = GTK_CMCTREE_ROW (node)->children;
2051 while (work && GTK_CMCTREE_ROW (work)->level > level)
2053 work = GTK_CMCTREE_NODE_NEXT (work);
2059 list = (GList *)node;
2060 list->next = (GList *)work;
2061 list = (GList *)GTK_CMCTREE_NODE_PREV (work);
2063 list = (GList *)work;
2064 list->prev = (GList *)node;
2068 list = (GList *)node;
2070 clist->row_list_end = (GList *)node;
2075 /* resize auto_resize columns if needed */
2076 gtk_sctree_auto_resize_columns (clist);
2078 if (!GTK_SCTREE(clist)->sorting) {
2079 row = g_list_position (clist->row_list, (GList *)node);
2080 if (row < clist->focus_row)
2081 clist->focus_row -= tmp;
2084 CLIST_REFRESH (clist);
2087 else if (visible && clist->column[ctree->tree_column].auto_resize &&
2088 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2089 /* resize tree_column if needed */
2090 gtk_sctree_column_auto_resize (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column,
2096 GtkWidget *gtk_sctree_new_with_titles (gint columns, gint tree_column,
2101 cm_return_val_if_fail (columns > 0, NULL);
2102 cm_return_val_if_fail (tree_column >= 0, NULL);
2104 if (tree_column >= columns) {
2105 g_warning("Wrong tree column");
2110 widget = gtk_widget_new (TYPE_GTK_SCTREE,
2111 "n_columns", columns,
2112 "tree_column", tree_column,
2115 GtkCMCList *clist = GTK_CMCLIST (widget);
2118 for (i = 0; i < columns; i++)
2119 gtk_cmclist_set_column_title (clist, i, titles[i]);
2120 gtk_cmclist_column_titles_show (clist);
2123 GTK_SCTREE(widget)->show_stripes = TRUE;
2124 GTK_SCTREE(widget)->always_expand_recursively = TRUE;
2125 GTK_SCTREE(widget)->force_additive_sel = FALSE;
2127 GTK_SCTREE(widget)->use_markup = g_new0(gboolean, columns);
2132 void gtk_sctree_set_use_markup (GtkSCTree *sctree,
2137 GValue value = { 0 };
2139 cm_return_if_fail(GTK_IS_SCTREE(sctree));
2141 g_value_init (&value, G_TYPE_INT);
2142 g_object_get_property (G_OBJECT (sctree), "n-columns", &value);
2143 columns = g_value_get_int (&value);
2144 g_value_unset (&value);
2146 cm_return_if_fail(column < columns);
2148 sctree->use_markup[column] = markup;
2151 void gtk_sctree_select (GtkSCTree *sctree, GtkCMCTreeNode *node)
2154 g_list_position(GTK_CMCLIST(sctree)->row_list, (GList *)node),
2158 void gtk_sctree_select_with_state (GtkSCTree *sctree, GtkCMCTreeNode *node, int state)
2161 g_list_position(GTK_CMCLIST(sctree)->row_list, (GList *)node),
2165 void gtk_sctree_unselect_all (GtkSCTree *sctree)
2167 gtk_cmclist_unselect_all(GTK_CMCLIST(sctree));
2168 sctree->anchor_row = NULL;
2171 void gtk_sctree_set_anchor_row (GtkSCTree *sctree, GtkCMCTreeNode *node)
2173 sctree->anchor_row = node;
2176 void gtk_sctree_remove_node (GtkSCTree *sctree, GtkCMCTreeNode *node)
2178 if (sctree->anchor_row == node)
2179 sctree->anchor_row = NULL;
2180 gtk_cmctree_remove_node(GTK_CMCTREE(sctree), node);
2183 void gtk_sctree_set_stripes(GtkSCTree *sctree, gboolean show_stripes)
2185 sctree->show_stripes = show_stripes;
2188 void gtk_sctree_set_recursive_expand(GtkSCTree *sctree, gboolean rec_exp)
2190 sctree->always_expand_recursively = rec_exp;
2193 /***********************************************************
2194 * Tree sorting functions *
2195 ***********************************************************/
2197 static void sink(GtkCMCList *clist, GPtrArray *numbers, gint root, gint bottom)
2200 GtkCMCTreeNode *temp;
2205 /* find the maximum element of numbers[root],
2206 numbers[2*root] and numbers[2*root+1] */
2208 if (clist->compare( clist, GTK_CMCTREE_ROW (g_ptr_array_index(numbers, root)),
2209 GTK_CMCTREE_ROW(g_ptr_array_index( numbers, j))) >= 0)
2212 if (clist->compare( clist, GTK_CMCTREE_ROW (g_ptr_array_index(numbers, k)),
2213 GTK_CMCTREE_ROW (g_ptr_array_index( numbers, j))) > 0)
2215 /* if numbers[root] wasn't the maximum element then
2218 temp = g_ptr_array_index( numbers,root);
2219 g_ptr_array_index( numbers, root) = g_ptr_array_index( numbers, j);
2220 g_ptr_array_index( numbers, j) = temp;
2221 sink( clist, numbers, j, bottom);
2226 static void heap_sort(GtkCMCList *clist, GPtrArray *numbers, gint array_size)
2229 GtkCMCTreeNode *temp;
2231 /* build the Heap */
2232 for (i = (array_size / 2); i >= 1; i--)
2233 sink( clist, numbers, i, array_size);
2234 /* output the Heap */
2235 for (i = array_size; i >= 2; i--) {
2236 temp = g_ptr_array_index( numbers, 1);
2237 g_ptr_array_index( numbers, 1) = g_ptr_array_index( numbers, i);
2238 g_ptr_array_index( numbers, i) = temp;
2239 sink( clist, numbers, 1, i-1);
2244 stree_sort (GtkCMCTree *ctree,
2245 GtkCMCTreeNode *node,
2248 GtkCMCTreeNode *list_start, *work, *next;
2249 GPtrArray *row_array, *viewable_array;
2253 clist = GTK_CMCLIST (ctree);
2256 work = GTK_CMCTREE_ROW (node)->children;
2258 work = GTK_CMCTREE_NODE (clist->row_list);
2260 row_array = g_ptr_array_new();
2261 viewable_array = g_ptr_array_new();
2264 g_ptr_array_add( row_array, NULL);
2266 /* add all rows to row_array */
2267 g_ptr_array_add( row_array, work);
2268 if (GTK_CMCTREE_ROW (work)->parent && gtk_cmctree_is_viewable( ctree, work))
2269 g_ptr_array_add( viewable_array, GTK_CMCTREE_ROW (work)->parent);
2270 next = GTK_CMCTREE_ROW (work)->sibling;
2271 gtk_sctree_unlink( ctree, work, FALSE);
2275 heap_sort( clist, row_array, (row_array->len)-1);
2278 list_start = GTK_CMCTREE_ROW (node)->children;
2280 list_start = GTK_CMCTREE_NODE (clist->row_list);
2282 if (clist->sort_type == GTK_SORT_ASCENDING) {
2283 for (i=(row_array->len)-1; i>=1; i--) {
2284 work = g_ptr_array_index( row_array, i);
2285 gtk_sctree_link( ctree, work, node, list_start, FALSE);
2287 /* insert work at the beginning of the list */
2290 for (i=1; i<row_array->len; i++) {
2291 work = g_ptr_array_index( row_array, i);
2292 gtk_sctree_link( ctree, work, node, list_start, FALSE);
2294 /* insert work at the beginning of the list */
2298 for (i=0; i<viewable_array->len; i++) {
2299 gtk_cmctree_expand( ctree, g_ptr_array_index( viewable_array, i));
2303 g_ptr_array_free( row_array, TRUE);
2304 g_ptr_array_free( viewable_array, TRUE);
2308 gtk_sctree_sort_recursive (GtkCMCTree *ctree,
2309 GtkCMCTreeNode *node)
2312 GtkCMCTreeNode *focus_node = NULL;
2314 cm_return_if_fail (ctree != NULL);
2315 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2317 clist = GTK_CMCLIST (ctree);
2319 gtk_cmclist_freeze (clist);
2321 if (clist->selection_mode == GTK_SELECTION_EXTENDED) {
2322 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2324 g_list_free (clist->undo_selection);
2325 g_list_free (clist->undo_unselection);
2326 clist->undo_selection = NULL;
2327 clist->undo_unselection = NULL;
2330 if (!node || (node && gtk_cmctree_is_viewable (ctree, node)))
2331 focus_node = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
2333 GTK_SCTREE(ctree)->sorting = TRUE;
2335 gtk_cmctree_post_recursive (ctree, node, GTK_CMCTREE_FUNC (stree_sort), NULL);
2338 stree_sort (ctree, NULL, NULL);
2340 GTK_SCTREE(ctree)->sorting = FALSE;
2343 clist->focus_row = g_list_position (clist->row_list,(GList *)focus_node);
2344 clist->undo_anchor = clist->focus_row;
2347 gtk_cmclist_thaw (clist);
2351 gtk_sctree_sort_node (GtkCMCTree *ctree,
2352 GtkCMCTreeNode *node)
2355 GtkCMCTreeNode *focus_node = NULL;
2357 cm_return_if_fail (ctree != NULL);
2358 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2360 clist = GTK_CMCLIST (ctree);
2362 gtk_cmclist_freeze (clist);
2364 if (clist->selection_mode == GTK_SELECTION_EXTENDED) {
2365 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2367 g_list_free (clist->undo_selection);
2368 g_list_free (clist->undo_unselection);
2369 clist->undo_selection = NULL;
2370 clist->undo_unselection = NULL;
2373 if (!node || (node && gtk_cmctree_is_viewable (ctree, node)))
2374 focus_node = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
2376 GTK_SCTREE(ctree)->sorting = TRUE;
2378 stree_sort (ctree, node, NULL);
2380 GTK_SCTREE(ctree)->sorting = FALSE;
2383 clist->focus_row = g_list_position (clist->row_list,(GList *)focus_node);
2384 clist->undo_anchor = clist->focus_row;
2387 gtk_cmclist_thaw (clist);
2390 /************************************************************************/
2393 gtk_sctree_unlink (GtkCMCTree *ctree,
2394 GtkCMCTreeNode *node,
2395 gboolean update_focus_row)
2401 GtkCMCTreeNode *work;
2402 GtkCMCTreeNode *parent;
2405 cm_return_if_fail (ctree != NULL);
2406 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2407 cm_return_if_fail (node != NULL);
2409 clist = GTK_CMCLIST (ctree);
2411 if (update_focus_row && clist->selection_mode == GTK_SELECTION_EXTENDED) {
2412 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2414 g_list_free (clist->undo_selection);
2415 g_list_free (clist->undo_unselection);
2416 clist->undo_selection = NULL;
2417 clist->undo_unselection = NULL;
2420 visible = gtk_cmctree_is_viewable (ctree, node);
2422 /* clist->row_list_end unlinked ? */
2423 if (visible && (GTK_CMCTREE_NODE_NEXT (node) == NULL ||
2424 (GTK_CMCTREE_ROW (node)->children && gtk_cmctree_is_ancestor (ctree, node,
2425 GTK_CMCTREE_NODE (clist->row_list_end)))))
2426 clist->row_list_end = (GList *) (GTK_CMCTREE_NODE_PREV (node));
2430 level = GTK_CMCTREE_ROW (node)->level;
2431 work = GTK_CMCTREE_NODE_NEXT (node);
2432 while (work && GTK_CMCTREE_ROW (work)->level > level) {
2433 work = GTK_CMCTREE_NODE_NEXT (work);
2438 clist->rows -= (rows + 1);
2440 if (update_focus_row) {
2442 pos = g_list_position (clist->row_list, (GList *)node);
2443 if (pos + rows < clist->focus_row)
2444 clist->focus_row -= (rows + 1);
2445 else if (pos <= clist->focus_row) {
2446 if (!GTK_CMCTREE_ROW (node)->sibling)
2447 clist->focus_row = MAX (pos - 1, 0);
2449 clist->focus_row = pos;
2451 clist->focus_row = MIN (clist->focus_row, clist->rows - 1);
2453 clist->undo_anchor = clist->focus_row;
2458 list = (GList *)GTK_CMCTREE_NODE_PREV (work);
2460 list = (GList *)work;
2461 list->prev = (GList *)GTK_CMCTREE_NODE_PREV (node);
2464 if (GTK_CMCTREE_NODE_PREV (node) &&
2465 GTK_CMCTREE_NODE_NEXT (GTK_CMCTREE_NODE_PREV (node)) == node) {
2466 list = (GList *)GTK_CMCTREE_NODE_PREV (node);
2467 list->next = (GList *)work;
2471 parent = GTK_CMCTREE_ROW (node)->parent;
2473 if (GTK_CMCTREE_ROW (parent)->children == node) {
2474 GTK_CMCTREE_ROW (parent)->children = GTK_CMCTREE_ROW (node)->sibling;
2477 GtkCMCTreeNode *sibling;
2479 sibling = GTK_CMCTREE_ROW (parent)->children;
2480 while (GTK_CMCTREE_ROW (sibling)->sibling != node)
2481 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
2482 GTK_CMCTREE_ROW (sibling)->sibling = GTK_CMCTREE_ROW (node)->sibling;
2486 if (clist->row_list == (GList *)node)
2487 clist->row_list = (GList *) (GTK_CMCTREE_ROW (node)->sibling);
2489 GtkCMCTreeNode *sibling;
2491 sibling = GTK_CMCTREE_NODE (clist->row_list);
2492 while (GTK_CMCTREE_ROW (sibling)->sibling != node)
2493 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
2494 GTK_CMCTREE_ROW (sibling)->sibling = GTK_CMCTREE_ROW (node)->sibling;
2500 gtk_sctree_link (GtkCMCTree *ctree,
2501 GtkCMCTreeNode *node,
2502 GtkCMCTreeNode *parent,
2503 GtkCMCTreeNode *sibling,
2504 gboolean update_focus_row)
2510 gboolean visible = FALSE;
2514 cm_return_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent);
2515 cm_return_if_fail (node != NULL);
2516 cm_return_if_fail (node != sibling);
2517 cm_return_if_fail (node != parent);
2519 clist = GTK_CMCLIST (ctree);
2521 if (update_focus_row && clist->selection_mode == GTK_SELECTION_EXTENDED) {
2522 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2524 g_list_free (clist->undo_selection);
2525 g_list_free (clist->undo_unselection);
2526 clist->undo_selection = NULL;
2527 clist->undo_unselection = NULL;
2530 for (rows = 1, list_end = (GList *)node; list_end->next;
2531 list_end = list_end->next)
2534 GTK_CMCTREE_ROW (node)->parent = parent;
2535 GTK_CMCTREE_ROW (node)->sibling = sibling;
2537 if (!parent || (parent && (gtk_cmctree_is_viewable (ctree, parent) &&
2538 GTK_CMCTREE_ROW (parent)->expanded))) {
2540 clist->rows += rows;
2544 work = (GList *)(GTK_CMCTREE_ROW (parent)->children);
2546 work = clist->row_list;
2549 if (work != (GList *)sibling) {
2550 while (GTK_CMCTREE_ROW (work)->sibling != sibling)
2551 work = (GList *)(GTK_CMCTREE_ROW (work)->sibling);
2552 GTK_CMCTREE_ROW (work)->sibling = node;
2555 if (sibling == GTK_CMCTREE_NODE (clist->row_list))
2556 clist->row_list = (GList *) node;
2557 if (GTK_CMCTREE_NODE_PREV (sibling) &&
2558 GTK_CMCTREE_NODE_NEXT (GTK_CMCTREE_NODE_PREV (sibling)) == sibling) {
2559 list = (GList *)GTK_CMCTREE_NODE_PREV (sibling);
2560 list->next = (GList *)node;
2563 list = (GList *)node;
2564 list->prev = (GList *)GTK_CMCTREE_NODE_PREV (sibling);
2565 list_end->next = (GList *)sibling;
2566 list = (GList *)sibling;
2567 list->prev = list_end;
2568 if (parent && GTK_CMCTREE_ROW (parent)->children == sibling)
2569 GTK_CMCTREE_ROW (parent)->children = node;
2574 while (GTK_CMCTREE_ROW (work)->sibling)
2575 work = (GList *)(GTK_CMCTREE_ROW (work)->sibling);
2576 GTK_CMCTREE_ROW (work)->sibling = node;
2578 /* find last visible child of sibling */
2579 work = (GList *) gtk_sctree_last_visible (ctree,
2580 GTK_CMCTREE_NODE (work));
2582 list_end->next = work->next;
2584 list = work->next->prev = list_end;
2585 work->next = (GList *)node;
2586 list = (GList *)node;
2591 GTK_CMCTREE_ROW (parent)->children = node;
2592 list = (GList *)node;
2593 list->prev = (GList *)parent;
2594 if (GTK_CMCTREE_ROW (parent)->expanded) {
2595 list_end->next = (GList *)GTK_CMCTREE_NODE_NEXT (parent);
2596 if (GTK_CMCTREE_NODE_NEXT(parent)) {
2597 list = (GList *)GTK_CMCTREE_NODE_NEXT (parent);
2598 list->prev = list_end;
2600 list = (GList *)parent;
2601 list->next = (GList *)node;
2604 list_end->next = NULL;
2607 clist->row_list = (GList *)node;
2608 list = (GList *)node;
2610 list_end->next = NULL;
2615 gtk_cmctree_pre_recursive (ctree, node, stree_update_level, NULL);
2617 if (clist->row_list_end == NULL ||
2618 clist->row_list_end->next == (GList *)node)
2619 clist->row_list_end = list_end;
2621 if (visible && update_focus_row) {
2623 pos = g_list_position (clist->row_list, (GList *)node);
2625 if (pos <= clist->focus_row) {
2626 clist->focus_row += rows;
2627 clist->undo_anchor = clist->focus_row;
2633 stree_update_level (GtkCMCTree *ctree,
2634 GtkCMCTreeNode *node,
2640 if (GTK_CMCTREE_ROW (node)->parent)
2641 GTK_CMCTREE_ROW (node)->level =
2642 GTK_CMCTREE_ROW (GTK_CMCTREE_ROW (node)->parent)->level + 1;
2644 GTK_CMCTREE_ROW (node)->level = 1;
2647 static GtkCMCTreeNode *
2648 gtk_sctree_last_visible (GtkCMCTree *ctree,
2649 GtkCMCTreeNode *node)
2651 GtkCMCTreeNode *work;
2656 work = GTK_CMCTREE_ROW (node)->children;
2658 if (!work || !GTK_CMCTREE_ROW (node)->expanded)
2661 while (GTK_CMCTREE_ROW (work)->sibling)
2662 work = GTK_CMCTREE_ROW (work)->sibling;
2664 return gtk_sctree_last_visible (ctree, work);
2668 sset_node_info (GtkCMCTree *ctree,
2669 GtkCMCTreeNode *node,
2672 GdkPixbuf *pixbuf_closed,
2673 GdkPixbuf *pixbuf_opened,
2677 if (GTK_CMCTREE_ROW (node)->pixbuf_opened)
2679 g_object_unref (GTK_CMCTREE_ROW (node)->pixbuf_opened);
2681 if (GTK_CMCTREE_ROW (node)->pixbuf_closed)
2683 g_object_unref (GTK_CMCTREE_ROW (node)->pixbuf_closed);
2686 GTK_CMCTREE_ROW (node)->pixbuf_opened = NULL;
2687 GTK_CMCTREE_ROW (node)->pixbuf_closed = NULL;
2691 GTK_CMCTREE_ROW (node)->pixbuf_closed = g_object_ref (pixbuf_closed);
2695 GTK_CMCTREE_ROW (node)->pixbuf_opened = g_object_ref (pixbuf_opened);
2698 GTK_CMCTREE_ROW (node)->is_leaf = is_leaf;
2699 GTK_CMCTREE_ROW (node)->expanded = (is_leaf) ? FALSE : expanded;
2701 if (GTK_CMCTREE_ROW (node)->expanded)
2702 gtk_cmctree_node_set_pixtext (ctree, node, ctree->tree_column,
2703 text, spacing, pixbuf_opened);
2705 gtk_cmctree_node_set_pixtext (ctree, node, ctree->tree_column,
2706 text, spacing, pixbuf_closed);
2710 stree_draw_node (GtkCMCTree *ctree,
2711 GtkCMCTreeNode *node)
2715 clist = GTK_CMCLIST (ctree);
2717 if (CLIST_UNFROZEN (clist) && gtk_cmctree_is_viewable (ctree, node))
2719 GtkCMCTreeNode *work;
2722 work = GTK_CMCTREE_NODE (clist->row_list);
2723 while (work && work != node)
2725 work = GTK_CMCTREE_NODE_NEXT (work);
2728 if (work && gtk_cmclist_row_is_visible (clist, num) != GTK_VISIBILITY_NONE)
2729 GTK_CMCLIST_GET_CLASS (clist)->draw_row
2730 (clist, NULL, num, GTK_CMCLIST_ROW ((GList *) node));
2734 /* this wrapper simply replaces NULL pixbufs
2735 * with a transparent, 1x1 pixbuf. This works
2736 * around a memory problem deep inside gtk,
2737 * revealed by valgrind.
2739 void gtk_sctree_set_node_info (GtkCMCTree *ctree,
2740 GtkCMCTreeNode *node,
2743 GdkPixbuf *pixbuf_closed,
2744 GdkPixbuf *pixbuf_opened,
2749 gboolean old_expanded;
2750 GtkCMCTreeNode *work;
2752 if (!GTK_IS_CMCTREE (ctree) || !node) return;
2754 old_leaf = GTK_CMCTREE_ROW (node)->is_leaf;
2755 old_expanded = GTK_CMCTREE_ROW (node)->expanded;
2757 if (is_leaf && (work = GTK_CMCTREE_ROW (node)->children) != NULL)
2759 GtkCMCTreeNode *ptr;
2764 work = GTK_CMCTREE_ROW (work)->sibling;
2765 gtk_cmctree_remove_node (ctree, ptr);
2769 sset_node_info (ctree, node, text, spacing, pixbuf_closed,
2770 pixbuf_opened, is_leaf, expanded);
2772 if (!is_leaf && !old_leaf)
2774 GTK_CMCTREE_ROW (node)->expanded = old_expanded;
2775 if (expanded && !old_expanded)
2776 gtk_cmctree_expand (ctree, node);
2777 else if (!expanded && old_expanded)
2778 gtk_cmctree_collapse (ctree, node);
2781 GTK_CMCTREE_ROW (node)->expanded = (is_leaf) ? FALSE : expanded;
2783 stree_draw_node (ctree, node);
2786 static GtkCMCTreeRow *
2787 srow_new (GtkCMCTree *ctree)
2790 GtkCMCTreeRow *ctree_row;
2793 clist = GTK_CMCLIST (ctree);
2794 #if GLIB_CHECK_VERSION(2,10,0)
2795 ctree_row = g_slice_new (GtkCMCTreeRow);
2796 ctree_row->row.cell = g_slice_alloc (sizeof (GtkCMCell) * clist->columns);
2798 ctree_row = g_chunk_new (GtkCMCTreeRow, (GMemChunk *)clist->row_mem_chunk);
2799 ctree_row->row.cell = g_chunk_new (GtkCMCell, (GMemChunk *)clist->cell_mem_chunk);
2801 for (i = 0; i < clist->columns; i++)
2803 ctree_row->row.cell[i].type = GTK_CMCELL_EMPTY;
2804 ctree_row->row.cell[i].vertical = 0;
2805 ctree_row->row.cell[i].horizontal = 0;
2806 ctree_row->row.cell[i].style = NULL;
2809 GTK_CMCELL_PIXTEXT (ctree_row->row.cell[ctree->tree_column])->text = NULL;
2811 ctree_row->row.fg_set = FALSE;
2812 ctree_row->row.bg_set = FALSE;
2813 ctree_row->row.style = NULL;
2814 ctree_row->row.selectable = TRUE;
2815 ctree_row->row.state = GTK_STATE_NORMAL;
2816 ctree_row->row.data = NULL;
2817 ctree_row->row.destroy = NULL;
2819 ctree_row->level = 0;
2820 ctree_row->expanded = FALSE;
2821 ctree_row->parent = NULL;
2822 ctree_row->sibling = NULL;
2823 ctree_row->children = NULL;
2824 ctree_row->pixbuf_closed = NULL;
2825 ctree_row->pixbuf_opened = NULL;
2831 srow_delete (GtkCMCTree *ctree,
2832 GtkCMCTreeRow *ctree_row)
2837 clist = GTK_CMCLIST (ctree);
2839 for (i = 0; i < clist->columns; i++)
2841 GTK_CMCLIST_GET_CLASS (clist)->set_cell_contents
2842 (clist, &(ctree_row->row), i, GTK_CMCELL_EMPTY, NULL, 0, NULL);
2843 if (ctree_row->row.cell[i].style)
2845 if (gtkut_widget_get_realized (GTK_WIDGET(ctree)))
2846 gtk_style_detach (ctree_row->row.cell[i].style);
2847 g_object_unref (ctree_row->row.cell[i].style);
2851 if (ctree_row->row.style)
2853 if (gtkut_widget_get_realized (GTK_WIDGET(ctree)))
2854 gtk_style_detach (ctree_row->row.style);
2855 g_object_unref (ctree_row->row.style);
2858 if (ctree_row->pixbuf_closed)
2860 g_object_unref (ctree_row->pixbuf_closed);
2863 if (ctree_row->pixbuf_opened)
2865 g_object_unref (ctree_row->pixbuf_opened);
2868 if (ctree_row->row.destroy)
2870 GDestroyNotify dnotify = ctree_row->row.destroy;
2871 gpointer ddata = ctree_row->row.data;
2873 ctree_row->row.destroy = NULL;
2874 ctree_row->row.data = NULL;
2879 #if GLIB_CHECK_VERSION(2,10,0)
2880 g_slice_free1 (sizeof (GtkCMCell) * clist->columns, ctree_row->row.cell);
2881 g_slice_free (GtkCMCTreeRow, ctree_row);
2883 g_mem_chunk_free ((GMemChunk *)clist->cell_mem_chunk, ctree_row->row.cell);
2884 g_mem_chunk_free ((GMemChunk *)clist->row_mem_chunk, ctree_row);
2889 stree_delete_row (GtkCMCTree *ctree,
2890 GtkCMCTreeNode *node,
2893 srow_delete (ctree, GTK_CMCTREE_ROW (node));
2894 g_list_free_1 ((GList *)node);
2898 gtk_sctree_real_tree_expand (GtkCMCTree *ctree,
2899 GtkCMCTreeNode *node)
2902 GtkCMCTreeNode *work;
2903 GtkRequisition requisition;
2907 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2909 if (!node || GTK_CMCTREE_ROW (node)->expanded || GTK_CMCTREE_ROW (node)->is_leaf)
2912 clist = GTK_CMCLIST (ctree);
2914 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2916 GTK_CMCTREE_ROW (node)->expanded = TRUE;
2917 level = GTK_CMCTREE_ROW (node)->level;
2919 visible = gtk_cmctree_is_viewable (ctree, node);
2920 /* get cell width if tree_column is auto resized */
2921 if (visible && clist->column[ctree->tree_column].auto_resize &&
2922 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2923 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2924 (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column, &requisition);
2926 /* unref/unset closed pixbuf */
2927 if (GTK_CMCELL_PIXTEXT
2928 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf)
2932 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf);
2935 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf = NULL;
2938 /* set/ref opened pixbuf */
2939 if (GTK_CMCTREE_ROW (node)->pixbuf_opened)
2942 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf =
2943 g_object_ref (GTK_CMCTREE_ROW (node)->pixbuf_opened);
2947 work = GTK_CMCTREE_ROW (node)->children;
2950 GList *list = (GList *)work;
2951 gint *cell_width = NULL;
2956 if (visible && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2958 cell_width = g_new0 (gint, clist->columns);
2959 if (clist->column[ctree->tree_column].auto_resize)
2960 cell_width[ctree->tree_column] = requisition.width;
2964 /* search maximum cell widths of auto_resize columns */
2965 for (i = 0; i < clist->columns; i++)
2966 if (clist->column[i].auto_resize)
2968 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2969 (clist, >K_CMCTREE_ROW (work)->row, i, &requisition);
2970 cell_width[i] = MAX (requisition.width, cell_width[i]);
2973 list = (GList *)work;
2974 work = GTK_CMCTREE_NODE_NEXT (work);
2981 list = (GList *)work;
2982 work = GTK_CMCTREE_NODE_NEXT (work);
2986 list->next = (GList *)GTK_CMCTREE_NODE_NEXT (node);
2988 if (GTK_CMCTREE_NODE_NEXT (node))
2992 if (clist->row_list_end == list)
2993 clist->row_list_end = g_list_last(list);
2995 tmp_list = (GList *)GTK_CMCTREE_NODE_NEXT (node);
2996 tmp_list->prev = list;
2999 clist->row_list_end = list;
3001 list = (GList *)node;
3002 list->next = (GList *)(GTK_CMCTREE_ROW (node)->children);
3004 if (visible && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
3006 /* resize auto_resize columns if needed */
3007 for (i = 0; i < clist->columns; i++)
3008 if (clist->column[i].auto_resize &&
3009 cell_width[i] > clist->column[i].width)
3010 gtk_cmclist_set_column_width (clist, i, cell_width[i]);
3011 g_free (cell_width);
3013 if (!GTK_SCTREE(ctree)->sorting) {
3014 /* update focus_row position */
3015 row = g_list_position (clist->row_list, (GList *)node);
3016 if (row < clist->focus_row)
3017 clist->focus_row += tmp;
3020 CLIST_REFRESH (clist);
3023 else if (visible && clist->column[ctree->tree_column].auto_resize)
3024 /* resize tree_column if needed */
3025 gtk_sctree_column_auto_resize (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column,
3031 gtk_sctree_insert_node (GtkCMCTree *ctree,
3032 GtkCMCTreeNode *parent,
3033 GtkCMCTreeNode *sibling,
3036 GdkPixbuf *pixbuf_closed,
3037 GdkPixbuf *pixbuf_opened,
3042 GtkCMCTreeRow *new_row;
3043 GtkCMCTreeNode *node;
3047 cm_return_val_if_fail (GTK_IS_CMCTREE (ctree), NULL);
3049 cm_return_val_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent, NULL);
3051 if (parent && GTK_CMCTREE_ROW (parent)->is_leaf)
3054 clist = GTK_CMCLIST (ctree);
3056 /* create the row */
3057 new_row = srow_new (ctree);
3058 list = g_list_alloc ();
3059 list->data = new_row;
3060 node = GTK_CMCTREE_NODE (list);
3063 for (i = 0; i < clist->columns; i++)
3064 if (text[i] && i != ctree->tree_column)
3065 GTK_CMCLIST_GET_CLASS (clist)->set_cell_contents
3066 (clist, &(new_row->row), i, GTK_CMCELL_TEXT, text[i], 0, NULL);
3068 sset_node_info (ctree, node, text ?
3069 text[ctree->tree_column] : NULL, spacing, pixbuf_closed,
3070 pixbuf_opened, is_leaf, expanded);
3072 /* sorted insertion */
3073 if (GTK_CMCLIST_AUTO_SORT (clist))
3076 sibling = GTK_CMCTREE_ROW (parent)->children;
3078 sibling = GTK_CMCTREE_NODE (clist->row_list);
3080 while (sibling && clist->compare
3081 (clist, GTK_CMCTREE_ROW (node), GTK_CMCTREE_ROW (sibling)) > 0)
3082 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
3085 gtk_sctree_link (ctree, node, parent, sibling, FALSE);
3087 if (text && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist) &&
3088 gtk_cmctree_is_viewable (ctree, node))
3090 for (i = 0; i < clist->columns; i++)
3091 if (clist->column[i].auto_resize)
3092 gtk_sctree_column_auto_resize (clist, &(new_row->row), i, 0);
3095 if (clist->rows == 1)
3097 clist->focus_row = 0;
3098 if (clist->selection_mode == GTK_SELECTION_BROWSE)
3099 gtk_sctree_select (GTK_SCTREE(ctree), node);
3103 CLIST_REFRESH (clist);
3109 gtk_sctree_insert_gnode (GtkCMCTree *ctree,
3110 GtkCMCTreeNode *parent,
3111 GtkCMCTreeNode *sibling,
3113 GtkCMCTreeGNodeFunc func,
3117 GtkCMCTreeNode *cnode = NULL;
3118 GtkCMCTreeNode *child = NULL;
3119 GtkCMCTreeNode *new_child;
3124 cm_return_val_if_fail (GTK_IS_CMCTREE (ctree), NULL);
3125 cm_return_val_if_fail (gnode != NULL, NULL);
3126 cm_return_val_if_fail (func != NULL, NULL);
3128 cm_return_val_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent, NULL);
3130 clist = GTK_CMCLIST (ctree);
3133 depth = GTK_CMCTREE_ROW (parent)->level + 1;
3135 list = g_list_alloc ();
3136 list->data = srow_new (ctree);
3137 cnode = GTK_CMCTREE_NODE (list);
3139 gtk_cmclist_freeze (clist);
3141 sset_node_info (ctree, cnode, "", 0, NULL, NULL, TRUE, FALSE);
3143 if (!func (ctree, depth, gnode, cnode, data))
3145 stree_delete_row (ctree, cnode, NULL);
3146 gtk_cmclist_thaw (clist);
3150 if (GTK_CMCLIST_AUTO_SORT (clist))
3153 sibling = GTK_CMCTREE_ROW (parent)->children;
3155 sibling = GTK_CMCTREE_NODE (clist->row_list);
3157 while (sibling && clist->compare
3158 (clist, GTK_CMCTREE_ROW (cnode), GTK_CMCTREE_ROW (sibling)) > 0)
3159 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
3162 gtk_sctree_link (ctree, cnode, parent, sibling, FALSE);
3164 for (work = g_node_last_child (gnode); work; work = work->prev)
3166 new_child = gtk_sctree_insert_gnode (ctree, cnode, child,
3172 gtk_cmclist_thaw (clist);
3178 sreal_tree_move (GtkCMCTree *ctree,
3179 GtkCMCTreeNode *node,
3180 GtkCMCTreeNode *new_parent,
3181 GtkCMCTreeNode *new_sibling)
3184 GtkCMCTreeNode *work;
3185 gboolean visible = FALSE;
3187 cm_return_if_fail (ctree != NULL);
3188 cm_return_if_fail (node != NULL);
3189 cm_return_if_fail (!new_sibling ||
3190 GTK_CMCTREE_ROW (new_sibling)->parent == new_parent);
3192 if (new_parent && GTK_CMCTREE_ROW (new_parent)->is_leaf)
3195 /* new_parent != child of child */
3196 for (work = new_parent; work; work = GTK_CMCTREE_ROW (work)->parent)
3200 clist = GTK_CMCLIST (ctree);
3202 visible = gtk_cmctree_is_viewable (ctree, node);
3204 if (clist->selection_mode == GTK_SELECTION_MULTIPLE)
3206 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
3208 g_list_free (clist->undo_selection);
3209 g_list_free (clist->undo_unselection);
3210 clist->undo_selection = NULL;
3211 clist->undo_unselection = NULL;
3214 if (GTK_CMCLIST_AUTO_SORT (clist))
3216 if (new_parent == GTK_CMCTREE_ROW (node)->parent)
3220 new_sibling = GTK_CMCTREE_ROW (new_parent)->children;
3222 new_sibling = GTK_CMCTREE_NODE (clist->row_list);
3224 while (new_sibling && clist->compare
3225 (clist, GTK_CMCTREE_ROW (node), GTK_CMCTREE_ROW (new_sibling)) > 0)
3226 new_sibling = GTK_CMCTREE_ROW (new_sibling)->sibling;
3229 if (new_parent == GTK_CMCTREE_ROW (node)->parent &&
3230 new_sibling == GTK_CMCTREE_ROW (node)->sibling)
3233 gtk_cmclist_freeze (clist);
3237 if (!GTK_SCTREE(ctree)->sorting && gtk_cmctree_is_viewable (ctree, node))
3238 work = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
3240 gtk_sctree_unlink (ctree, node, FALSE);
3241 gtk_sctree_link (ctree, node, new_parent, new_sibling, FALSE);
3243 if (!GTK_SCTREE(ctree)->sorting && work)
3245 while (work && !gtk_cmctree_is_viewable (ctree, work))
3246 work = GTK_CMCTREE_ROW (work)->parent;
3247 clist->focus_row = g_list_position (clist->row_list, (GList *)work);
3248 clist->undo_anchor = clist->focus_row;
3251 if (clist->column[ctree->tree_column].auto_resize &&
3252 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist) &&
3253 (visible || gtk_cmctree_is_viewable (ctree, node)))
3254 gtk_cmclist_set_column_width
3255 (clist, ctree->tree_column,
3256 gtk_cmclist_optimal_column_width (clist, ctree->tree_column));
3258 gtk_cmclist_thaw (clist);
3261 void gtk_sctree_set_column_tooltip (GtkSCTree *sctree,
3265 #if !(GTK_CHECK_VERSION(2,12,0))
3267 if (!sctree->tooltips)
3268 sctree->tooltips = gtk_tooltips_new();
3269 tips = sctree->tooltips;
3272 CLAWS_SET_TIP(GTK_CMCLIST(sctree)->column[column].button,