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 #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,
207 if ((state == GTK_STATE_NORMAL) &&
208 (GTK_WIDGET (clist)->state == GTK_STATE_INSENSITIVE))
209 fg_state = GTK_STATE_INSENSITIVE;
213 if (clist_row->cell[column].style)
216 *style = clist_row->cell[column].style;
218 *fg_gc = clist_row->cell[column].style->fg_gc[fg_state];
220 if (state == GTK_STATE_SELECTED)
221 *bg_gc = clist_row->cell[column].style->bg_gc[state];
224 else if (clist_row->style)
227 *style = clist_row->style;
229 *fg_gc = clist_row->style->fg_gc[fg_state];
231 if (state == GTK_STATE_SELECTED)
232 *bg_gc = clist_row->style->bg_gc[state];
234 *bg_gc = clist_row->bg_set ?
235 clist->bg_gc : clist_row->style->base_gc[state];
241 *style = GTK_WIDGET (clist)->style;
243 *fg_gc = GTK_WIDGET (clist)->style->fg_gc[fg_state];
245 if (state == GTK_STATE_SELECTED)
246 *bg_gc = GTK_WIDGET (clist)->style->bg_gc[state];
248 *bg_gc = GTK_WIDGET (clist)->style->base_gc[state];
251 if (state != GTK_STATE_SELECTED)
253 if (fg_gc && clist_row->fg_set)
254 *fg_gc = clist->fg_gc;
255 if (bg_gc && clist_row->bg_set)
256 *bg_gc = clist->bg_gc;
262 gtk_sctree_draw_expander (GtkCMCTree *ctree,
263 GtkCMCTreeRow *ctree_row,
265 GdkRectangle *clip_rectangle,
270 gint justification_factor;
273 if (ctree->expander_style == GTK_CMCTREE_EXPANDER_NONE)
276 clist = GTK_CMCLIST (ctree);
277 if (clist->column[ctree->tree_column].justification == GTK_JUSTIFY_RIGHT)
278 justification_factor = -1;
280 justification_factor = 1;
281 if (!GTK_CMCLIST_ROW_HEIGHT_SET(GTK_CMCLIST(clist)))
282 y = (clip_rectangle->y + (clip_rectangle->height - PM_SIZE) / 2 -
283 (clip_rectangle->height + 1) % 2);
285 y = (clip_rectangle->y + (clip_rectangle->height/2 - PM_SIZE) / 2 -
286 (clip_rectangle->height/2 + 1) % 2);
288 if (!ctree_row->children)
290 switch (ctree->expander_style)
292 case GTK_CMCTREE_EXPANDER_NONE:
294 case GTK_CMCTREE_EXPANDER_TRIANGLE:
295 return x + justification_factor * (PM_SIZE + 3);
296 case GTK_CMCTREE_EXPANDER_SQUARE:
297 case GTK_CMCTREE_EXPANDER_CIRCULAR:
298 return x + justification_factor * (PM_SIZE + 1);
302 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], clip_rectangle);
303 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], clip_rectangle);
305 switch (ctree->expander_style)
307 case GTK_CMCTREE_EXPANDER_NONE:
309 case GTK_CMCTREE_EXPANDER_TRIANGLE:
310 if (ctree_row->expanded)
313 points[0].y = y + (PM_SIZE + 2) / 6;
314 points[1].x = points[0].x + justification_factor * (PM_SIZE + 2);
315 points[1].y = points[0].y;
316 points[2].x = (points[0].x +
317 justification_factor * (PM_SIZE + 2) / 2);
318 points[2].y = y + 2 * (PM_SIZE + 2) / 3;
322 points[0].x = x + justification_factor * ((PM_SIZE + 2) / 6 + 2);
324 points[1].x = points[0].x;
325 points[1].y = points[0].y + (PM_SIZE + 2);
326 points[2].x = (points[0].x +
327 justification_factor * (2 * (PM_SIZE + 2) / 3 - 1));
328 points[2].y = points[0].y + (PM_SIZE + 2) / 2;
331 gdk_draw_polygon (clist->clist_window, style->base_gc[GTK_STATE_NORMAL],
333 gdk_draw_polygon (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
336 x += justification_factor * (PM_SIZE + 3);
338 case GTK_CMCTREE_EXPANDER_SQUARE:
339 case GTK_CMCTREE_EXPANDER_CIRCULAR:
340 if (justification_factor == -1)
341 x += justification_factor * (PM_SIZE + 1);
343 if (ctree->expander_style == GTK_CMCTREE_EXPANDER_CIRCULAR)
345 gdk_draw_arc (clist->clist_window, style->base_gc[GTK_STATE_NORMAL],
346 TRUE, x, y, PM_SIZE, PM_SIZE, 0, 360 * 64);
347 gdk_draw_arc (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
348 FALSE, x, y, PM_SIZE, PM_SIZE, 0, 360 * 64);
352 gdk_draw_rectangle (clist->clist_window,
353 style->base_gc[GTK_STATE_NORMAL], TRUE,
354 x, y, PM_SIZE, PM_SIZE);
355 gdk_draw_rectangle (clist->clist_window,
356 style->fg_gc[GTK_STATE_NORMAL], FALSE,
357 x, y, PM_SIZE, PM_SIZE);
360 gdk_draw_line (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
361 x + 2, y + PM_SIZE / 2, x + PM_SIZE - 2, y + PM_SIZE / 2);
363 if (!ctree_row->expanded)
364 gdk_draw_line (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
365 x + PM_SIZE / 2, y + 2,
366 x + PM_SIZE / 2, y + PM_SIZE - 2);
368 if (justification_factor == 1)
369 x += justification_factor * (PM_SIZE + 1);
373 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
374 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
380 gtk_sctree_draw_lines (GtkCMCTree *ctree,
381 GtkCMCTreeRow *ctree_row,
385 GdkRectangle *clip_rectangle,
386 GdkRectangle *cell_rectangle,
392 GtkCMCTreeNode *node;
393 GtkCMCTreeNode *parent;
394 GdkRectangle tree_rectangle;
395 GdkRectangle tc_rectangle;
406 gint justification_factor;
408 clist = GTK_CMCLIST (ctree);
409 ycenter = clip_rectangle->y + (clip_rectangle->height / 2);
410 justify_right = (clist->column[column].justification == GTK_JUSTIFY_RIGHT);
414 offset = (clip_rectangle->x + clip_rectangle->width - 1 -
415 ctree->tree_indent * (ctree_row->level - 1));
416 justification_factor = -1;
420 offset = clip_rectangle->x + ctree->tree_indent * (ctree_row->level - 1);
421 justification_factor = 1;
424 switch (ctree->line_style)
426 case GTK_CMCTREE_LINES_NONE:
428 case GTK_CMCTREE_LINES_TABBED:
429 xcenter = offset + justification_factor * TAB_SIZE;
431 column_right = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) +
432 clist->column[ctree->tree_column].area.width +
434 column_left = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) -
435 COLUMN_INSET - CELL_SPACING);
439 tree_rectangle.y = crect->y;
440 tree_rectangle.height = crect->height;
444 tree_rectangle.x = xcenter;
445 tree_rectangle.width = column_right - xcenter;
449 tree_rectangle.x = column_left;
450 tree_rectangle.width = xcenter - column_left;
453 if (!gdk_rectangle_intersect (area, &tree_rectangle, &tc_rectangle))
455 offset += justification_factor * 3;
460 gdk_gc_set_clip_rectangle (ctree->lines_gc, crect);
462 next_level = ctree_row->level;
464 if (!ctree_row->sibling || (ctree_row->children && ctree_row->expanded))
466 node = gtk_cmctree_find_node_ptr (ctree, ctree_row);
467 if (GTK_CMCTREE_NODE_NEXT (node))
468 next_level = GTK_CMCTREE_ROW (GTK_CMCTREE_NODE_NEXT (node))->level;
473 if (ctree->tree_indent > 0)
475 node = ctree_row->parent;
478 xcenter -= (justification_factor * ctree->tree_indent);
480 if ((justify_right && xcenter < column_left) ||
481 (!justify_right && xcenter > column_right))
483 node = GTK_CMCTREE_ROW (node)->parent;
487 tree_rectangle.y = cell_rectangle->y;
488 tree_rectangle.height = cell_rectangle->height;
491 tree_rectangle.x = MAX (xcenter - ctree->tree_indent + 1,
493 tree_rectangle.width = MIN (xcenter - column_left,
498 tree_rectangle.x = xcenter;
499 tree_rectangle.width = MIN (column_right - xcenter,
503 if (!area || gdk_rectangle_intersect (area, &tree_rectangle,
506 gtk_sctree_get_cell_style (clist, >K_CMCTREE_ROW (node)->row,
507 state, row, column, NULL, NULL, &bg_gc);
509 if (bg_gc == clist->bg_gc)
510 gdk_gc_set_foreground
511 (clist->bg_gc, >K_CMCTREE_ROW (node)->row.background);
514 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
517 tree_rectangle.width,
518 tree_rectangle.height);
520 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
524 tc_rectangle.height);
526 if (next_level > GTK_CMCTREE_ROW (node)->level)
527 gdk_draw_line (clist->clist_window, ctree->lines_gc,
529 xcenter, crect->y + crect->height);
534 offset_x = MIN (ctree->tree_indent, 2 * TAB_SIZE);
535 width = offset_x / 2 + offset_x % 2;
537 parent = GTK_CMCTREE_ROW (node)->parent;
539 tree_rectangle.y = ycenter;
540 tree_rectangle.height = (cell_rectangle->y - ycenter +
541 cell_rectangle->height);
545 tree_rectangle.x = MAX(xcenter + 1 - width, column_left);
546 tree_rectangle.width = MIN (xcenter + 1 - column_left,
551 tree_rectangle.x = xcenter;
552 tree_rectangle.width = MIN (column_right - xcenter,
557 gdk_rectangle_intersect (area, &tree_rectangle,
562 gtk_sctree_get_cell_style (clist, >K_CMCTREE_ROW (parent)->row,
563 state, row, column, NULL, NULL, &bg_gc);
564 if (bg_gc == clist->bg_gc)
565 gdk_gc_set_foreground
567 >K_CMCTREE_ROW (parent)->row.background);
569 else if (state == GTK_STATE_SELECTED)
570 bg_gc = style->base_gc[state];
572 bg_gc = GTK_WIDGET (clist)->style->base_gc[state];
575 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
578 tree_rectangle.width,
579 tree_rectangle.height);
581 gdk_draw_rectangle (clist->clist_window,
586 tc_rectangle.height);
589 gtk_sctree_get_cell_style (clist, >K_CMCTREE_ROW (node)->row,
590 state, row, column, NULL, NULL, &bg_gc);
591 if (bg_gc == clist->bg_gc)
592 gdk_gc_set_foreground
593 (clist->bg_gc, >K_CMCTREE_ROW (node)->row.background);
595 gdk_gc_set_clip_rectangle (bg_gc, crect);
596 gdk_draw_arc (clist->clist_window, bg_gc, TRUE,
597 xcenter - (justify_right * offset_x),
599 offset_x, clist->row_height,
600 (180 + (justify_right * 90)) * 64, 90 * 64);
601 gdk_gc_set_clip_rectangle (bg_gc, NULL);
603 gdk_draw_line (clist->clist_window, ctree->lines_gc,
604 xcenter, cell_rectangle->y, xcenter, ycenter);
607 gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
608 xcenter - offset_x, cell_rectangle->y,
609 offset_x, clist->row_height,
612 gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
613 xcenter, cell_rectangle->y,
614 offset_x, clist->row_height,
617 node = GTK_CMCTREE_ROW (node)->parent;
621 if (state != GTK_STATE_SELECTED)
623 tree_rectangle.y = clip_rectangle->y;
624 tree_rectangle.height = clip_rectangle->height;
625 tree_rectangle.width = COLUMN_INSET + CELL_SPACING +
626 MIN (clist->column[ctree->tree_column].area.width + COLUMN_INSET,
630 tree_rectangle.x = MAX (xcenter + 1, column_left);
632 tree_rectangle.x = column_left;
635 gdk_draw_rectangle (clist->clist_window,
637 (ctree)->style->base_gc[GTK_STATE_NORMAL],
641 tree_rectangle.width,
642 tree_rectangle.height);
643 else if (gdk_rectangle_intersect (area, &tree_rectangle,
645 gdk_draw_rectangle (clist->clist_window,
647 (ctree)->style->base_gc[GTK_STATE_NORMAL],
652 tc_rectangle.height);
655 xcenter = offset + (justification_factor * ctree->tree_indent / 2);
657 gtk_sctree_get_cell_style (clist, &ctree_row->row, state, row, column, NULL, NULL,
659 if (bg_gc == clist->bg_gc)
660 gdk_gc_set_foreground (clist->bg_gc, &ctree_row->row.background);
662 gdk_gc_set_clip_rectangle (bg_gc, crect);
663 if (ctree_row->is_leaf)
667 points[0].x = offset + justification_factor * TAB_SIZE;
668 points[0].y = cell_rectangle->y;
670 points[1].x = points[0].x - justification_factor * 4;
671 points[1].y = points[0].y;
673 points[2].x = points[1].x - justification_factor * 2;
674 points[2].y = points[1].y + 3;
676 points[3].x = points[2].x;
677 points[3].y = points[2].y + clist->row_height - 5;
679 points[4].x = points[3].x + justification_factor * 2;
680 points[4].y = points[3].y + 3;
682 points[5].x = points[4].x + justification_factor * 4;
683 points[5].y = points[4].y;
685 gdk_draw_polygon (clist->clist_window, bg_gc, TRUE, points, 6);
686 gdk_draw_lines (clist->clist_window, ctree->lines_gc, points, 6);
690 gdk_draw_arc (clist->clist_window, bg_gc, TRUE,
691 offset - (justify_right * 2 * TAB_SIZE),
693 2 * TAB_SIZE, clist->row_height,
694 (90 + (180 * justify_right)) * 64, 180 * 64);
695 gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
696 offset - (justify_right * 2 * TAB_SIZE),
698 2 * TAB_SIZE, clist->row_height,
699 (90 + (180 * justify_right)) * 64, 180 * 64);
701 gdk_gc_set_clip_rectangle (bg_gc, NULL);
702 gdk_gc_set_clip_rectangle (ctree->lines_gc, NULL);
704 offset += justification_factor * 3;
707 xcenter = offset + justification_factor * PM_SIZE / 2;
711 tree_rectangle.y = crect->y;
712 tree_rectangle.height = crect->height;
716 tree_rectangle.x = xcenter - PM_SIZE / 2 - 2;
717 tree_rectangle.width = (clip_rectangle->x +
718 clip_rectangle->width -tree_rectangle.x);
722 tree_rectangle.x = clip_rectangle->x + PM_SIZE / 2;
723 tree_rectangle.width = (xcenter + PM_SIZE / 2 + 2 -
727 if (!gdk_rectangle_intersect (area, &tree_rectangle, &tc_rectangle))
733 if (ctree->line_style == GTK_CMCTREE_LINES_DOTTED)
735 offset_x += abs((clip_rectangle->x + clist->hoffset) % 2);
736 offset_y = abs((cell_rectangle->y + clist->voffset) % 2);
740 clip_rectangle->height++;
741 gdk_gc_set_clip_rectangle (ctree->lines_gc, clip_rectangle);
742 gdk_draw_line (clist->clist_window, ctree->lines_gc,
744 (ctree->show_stub || clist->row_list->data != ctree_row) ?
745 cell_rectangle->y + offset_y : ycenter,
747 (ctree_row->sibling) ? crect->y +crect->height : ycenter);
749 gdk_draw_line (clist->clist_window, ctree->lines_gc,
750 xcenter + (justification_factor * offset_x), ycenter,
751 xcenter + (justification_factor * (PM_SIZE / 2 + 2)),
754 node = ctree_row->parent;
757 xcenter -= (justification_factor * ctree->tree_indent);
759 if (GTK_CMCTREE_ROW (node)->sibling)
760 gdk_draw_line (clist->clist_window, ctree->lines_gc,
761 xcenter, cell_rectangle->y + offset_y,
762 xcenter, crect->y + crect->height);
763 node = GTK_CMCTREE_ROW (node)->parent;
765 gdk_gc_set_clip_rectangle (ctree->lines_gc, NULL);
767 clip_rectangle->height--;
773 static gboolean filter_fg (PangoAttribute *attribute, gpointer data)
775 const PangoAttrClass *klass = attribute->klass;
776 if (klass->type == PANGO_ATTR_FOREGROUND)
783 sc_gtk_cmclist_create_cell_layout (GtkCMCList *clist,
784 GtkCMCListRow *clist_row,
792 gtk_sctree_get_cell_style (clist, clist_row, GTK_STATE_NORMAL, 0, column, &style,
796 cell = &clist_row->cell[column];
799 case GTK_CMCELL_TEXT:
800 case GTK_CMCELL_PIXTEXT:
801 text = ((cell->type == GTK_CMCELL_PIXTEXT) ?
802 GTK_CMCELL_PIXTEXT (*cell)->text :
803 GTK_CMCELL_TEXT (*cell)->text);
808 if (!GTK_SCTREE(clist)->use_markup[column]) {
809 layout = gtk_widget_create_pango_layout (GTK_WIDGET (clist),
810 ((cell->type == GTK_CMCELL_PIXTEXT) ?
811 GTK_CMCELL_PIXTEXT (*cell)->text :
812 GTK_CMCELL_TEXT (*cell)->text));
813 pango_layout_set_font_description (layout, style->font_desc);
815 PangoContext *context = gtk_widget_get_pango_context (GTK_WIDGET(clist));
816 layout = pango_layout_new (context);
817 pango_layout_set_markup (layout, text, -1);
818 pango_layout_set_font_description (layout, style->font_desc);
819 if (clist_row->state == GTK_STATE_SELECTED) {
820 /* for selected row, we should remove any forced foreground color
821 * or it looks like shit */
822 PangoAttrList *list = pango_layout_get_attributes(layout);
823 PangoAttrList *rem = pango_attr_list_filter(list, filter_fg, NULL);
825 pango_attr_list_unref(rem);
837 gtk_sctree_draw_row (GtkCMCList *clist,
840 GtkCMCListRow *clist_row)
846 GdkRectangle row_rectangle;
847 GdkRectangle cell_rectangle;
848 GdkRectangle clip_rectangle;
849 GdkRectangle intersect_rectangle;
851 gint column_left = 0;
852 gint column_right = 0;
856 static GdkColor greybg={0, 0, 0, 0};
857 static gboolean color_change = TRUE;
859 if (greybg.pixel == 0 &&
863 GdkColor normalbg = {0, 0xffff, 0xffff, 0xffff};
864 if (GTK_WIDGET (clist)->style) {
865 normalbg = GTK_WIDGET (clist)->style->base[GTK_STATE_NORMAL];
867 if (normalbg.red > 0x8888 && normalbg.green > 0x8888 && normalbg.blue > 0x8888) {
868 greybg.pixel = normalbg.pixel;
869 greybg.red = normalbg.red - prefs_common.stripes_color_offset;
870 greybg.green = normalbg.green - prefs_common.stripes_color_offset;
871 greybg.blue = normalbg.blue - prefs_common.stripes_color_offset;
872 } else 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;
878 color_change = FALSE;
882 cm_return_if_fail (clist != NULL);
884 /* bail now if we arn't drawable yet */
885 if (!gtkut_widget_is_drawable (GTK_WIDGET(clist)) || row < 0 || row >= clist->rows)
888 widget = GTK_WIDGET (clist);
889 ctree = GTK_CMCTREE (clist);
891 /* if the function is passed the pointer to the row instead of null,
892 * it avoids this expensive lookup */
894 clist_row = (g_list_nth (clist->row_list, row))->data;
896 /* rectangle of the entire row */
898 row_rectangle.y = ROW_TOP_YPIXEL (clist, row);
899 row_rectangle.width = clist->clist_window_width;
900 row_rectangle.height = clist->row_height;
902 /* rectangle of the cell spacing above the row */
903 cell_rectangle.x = 0;
904 cell_rectangle.y = row_rectangle.y - CELL_SPACING;
905 cell_rectangle.width = row_rectangle.width;
906 cell_rectangle.height = CELL_SPACING;
908 /* rectangle used to clip drawing operations, its y and height
909 * positions only need to be set once, so we set them once here.
910 * the x and width are set withing the drawing loop below once per
912 clip_rectangle.y = row_rectangle.y;
913 clip_rectangle.height = row_rectangle.height;
915 if (prefs_common.use_stripes_everywhere && GTK_SCTREE(ctree)->show_stripes
916 && color_change && row % 2) {
917 clist_row->background = greybg;
918 clist_row->bg_set = TRUE;
920 clist_row->bg_set = FALSE;
922 if (clist_row->state == GTK_STATE_NORMAL)
924 if (clist_row->fg_set)
925 gdk_gc_set_foreground (clist->fg_gc, &clist_row->foreground);
926 if (clist_row->bg_set)
927 gdk_gc_set_rgb_fg_color (clist->bg_gc, &clist_row->background);
930 state = clist_row->state;
932 gdk_gc_set_foreground (ctree->lines_gc,
933 &widget->style->fg[clist_row->state]);
935 /* draw the cell borders */
938 rect = &intersect_rectangle;
939 crect = &intersect_rectangle;
941 if (gdk_rectangle_intersect (area, &cell_rectangle, crect))
942 gdk_draw_rectangle (clist->clist_window,
943 widget->style->base_gc[GTK_STATE_NORMAL], TRUE,
944 crect->x, crect->y, crect->width, crect->height);
948 rect = &clip_rectangle;
949 crect = &cell_rectangle;
951 gdk_draw_rectangle (clist->clist_window,
952 widget->style->base_gc[GTK_STATE_NORMAL], TRUE,
953 crect->x, crect->y, crect->width, crect->height);
956 /* horizontal black lines */
957 if (ctree->line_style == GTK_CMCTREE_LINES_TABBED)
960 column_right = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) +
961 clist->column[ctree->tree_column].area.width +
963 column_left = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) -
964 COLUMN_INSET - (ctree->tree_column != 0) * CELL_SPACING);
966 switch (clist->column[ctree->tree_column].justification)
968 case GTK_JUSTIFY_CENTER:
969 case GTK_JUSTIFY_FILL:
970 case GTK_JUSTIFY_LEFT:
971 offset = (column_left + ctree->tree_indent *
972 (((GtkCMCTreeRow *)clist_row)->level - 1));
974 gdk_draw_line (clist->clist_window, ctree->lines_gc,
975 MIN (offset + TAB_SIZE, column_right),
977 clist->clist_window_width, cell_rectangle.y);
979 case GTK_JUSTIFY_RIGHT:
980 offset = (column_right - 1 - ctree->tree_indent *
981 (((GtkCMCTreeRow *)clist_row)->level - 1));
983 gdk_draw_line (clist->clist_window, ctree->lines_gc,
984 -1, cell_rectangle.y,
985 MAX (offset - TAB_SIZE, column_left),
991 /* the last row has to clear its bottom cell spacing too */
992 if (clist_row == clist->row_list_end->data)
994 cell_rectangle.y += clist->row_height + CELL_SPACING;
996 if (!area || gdk_rectangle_intersect (area, &cell_rectangle, crect))
998 gdk_draw_rectangle (clist->clist_window,
999 widget->style->base_gc[GTK_STATE_NORMAL], TRUE,
1000 crect->x, crect->y, crect->width, crect->height);
1002 /* horizontal black lines */
1003 if (ctree->line_style == GTK_CMCTREE_LINES_TABBED)
1005 switch (clist->column[ctree->tree_column].justification)
1007 case GTK_JUSTIFY_CENTER:
1008 case GTK_JUSTIFY_FILL:
1009 case GTK_JUSTIFY_LEFT:
1010 gdk_draw_line (clist->clist_window, ctree->lines_gc,
1011 MIN (column_left + TAB_SIZE + COLUMN_INSET +
1012 (((GtkCMCTreeRow *)clist_row)->level > 1) *
1013 MIN (ctree->tree_indent / 2, TAB_SIZE),
1016 clist->clist_window_width, cell_rectangle.y);
1018 case GTK_JUSTIFY_RIGHT:
1019 gdk_draw_line (clist->clist_window, ctree->lines_gc,
1020 -1, cell_rectangle.y,
1021 MAX (column_right - TAB_SIZE - 1 -
1023 (((GtkCMCTreeRow *)clist_row)->level > 1) *
1024 MIN (ctree->tree_indent / 2, TAB_SIZE),
1025 column_left - 1), cell_rectangle.y);
1032 for (last_column = clist->columns - 1;
1033 last_column >= 0 && !clist->column[last_column].visible; last_column--)
1036 /* iterate and draw all the columns (row cells) and draw their contents */
1037 for (i = 0; i < clist->columns; i++)
1042 PangoLayout *layout = NULL;
1043 PangoRectangle logical_rect;
1051 if (!clist->column[i].visible)
1054 gtk_sctree_get_cell_style (clist, clist_row, state, row, i, &style, &fg_gc, &bg_gc);
1056 /* calculate clipping region */
1057 clip_rectangle.x = clist->column[i].area.x + clist->hoffset;
1058 clip_rectangle.width = clist->column[i].area.width;
1060 cell_rectangle.x = clip_rectangle.x - COLUMN_INSET - CELL_SPACING;
1061 cell_rectangle.width = (clip_rectangle.width + 2 * COLUMN_INSET +
1062 (1 + (i == last_column)) * CELL_SPACING);
1063 cell_rectangle.y = clip_rectangle.y;
1064 cell_rectangle.height = clip_rectangle.height;
1070 if (area && !gdk_rectangle_intersect (area, &cell_rectangle,
1071 &intersect_rectangle))
1073 if (i != ctree->tree_column)
1078 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
1079 crect->x, crect->y, crect->width, crect->height);
1082 layout = sc_gtk_cmclist_create_cell_layout (clist, clist_row, i);
1085 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1086 width = logical_rect.width;
1091 switch (clist_row->cell[i].type)
1093 case GTK_CMCELL_PIXBUF:
1094 pixbuf_width = gdk_pixbuf_get_width(GTK_CMCELL_PIXBUF (clist_row->cell[i])->pixbuf);
1095 height = gdk_pixbuf_get_height(GTK_CMCELL_PIXBUF (clist_row->cell[i])->pixbuf);
1096 width += pixbuf_width;
1098 case GTK_CMCELL_PIXTEXT:
1099 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf)
1101 pixbuf_width = gdk_pixbuf_get_width(GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf);
1102 height = gdk_pixbuf_get_height(GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf);
1103 width += pixbuf_width;
1106 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->text &&
1107 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf)
1108 width += GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1110 if (i == ctree->tree_column)
1111 width += (ctree->tree_indent *
1112 ((GtkCMCTreeRow *)clist_row)->level);
1118 switch (clist->column[i].justification)
1120 case GTK_JUSTIFY_LEFT:
1121 offset = clip_rectangle.x + clist_row->cell[i].horizontal;
1123 case GTK_JUSTIFY_RIGHT:
1124 offset = (clip_rectangle.x + clist_row->cell[i].horizontal +
1125 clip_rectangle.width - width);
1127 case GTK_JUSTIFY_CENTER:
1128 case GTK_JUSTIFY_FILL:
1129 offset = (clip_rectangle.x + clist_row->cell[i].horizontal +
1130 (clip_rectangle.width / 2) - (width / 2));
1134 if (i != ctree->tree_column)
1136 int start_y = (clip_rectangle.height - height) / 2;
1137 if (GTK_CMCLIST_ROW_HEIGHT_SET(GTK_CMCLIST(clist)))
1138 start_y = (clip_rectangle.height/2 - height) / 2;
1140 offset += clist_row->cell[i].horizontal;
1141 switch (clist_row->cell[i].type)
1143 case GTK_CMCELL_PIXBUF:
1144 gtk_sctree_draw_cell_pixbuf
1145 (clist->clist_window, &clip_rectangle, fg_gc,
1146 GTK_CMCELL_PIXBUF (clist_row->cell[i])->pixbuf,
1148 clip_rectangle.y + clist_row->cell[i].vertical +
1150 pixbuf_width, height);
1152 case GTK_CMCELL_PIXTEXT:
1153 offset = gtk_sctree_draw_cell_pixbuf
1154 (clist->clist_window, &clip_rectangle, fg_gc,
1155 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf,
1157 clip_rectangle.y + clist_row->cell[i].vertical +
1159 pixbuf_width, height);
1160 offset += GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1163 case GTK_CMCELL_TEXT:
1166 gint row_center_offset = (clist->row_height - logical_rect.height) / 2;
1168 gdk_gc_set_clip_rectangle (fg_gc, &clip_rectangle);
1169 gdk_draw_layout (clist->clist_window, fg_gc,
1171 row_rectangle.y + row_center_offset + clist_row->cell[i].vertical,
1173 gdk_gc_set_clip_rectangle (fg_gc, NULL);
1174 g_object_unref (G_OBJECT (layout));
1184 if (bg_gc == clist->bg_gc)
1185 gdk_gc_set_background (ctree->lines_gc, &clist_row->background);
1187 /* draw ctree->tree_column */
1188 cell_rectangle.y -= CELL_SPACING;
1189 cell_rectangle.height += CELL_SPACING;
1191 if (area && !gdk_rectangle_intersect (area, &cell_rectangle,
1192 &intersect_rectangle))
1195 g_object_unref (G_OBJECT (layout));
1200 offset = gtk_sctree_draw_lines (ctree, (GtkCMCTreeRow *)clist_row, row, i,
1201 state, &clip_rectangle, &cell_rectangle,
1202 crect, area, style);
1205 offset = gtk_sctree_draw_expander (ctree, (GtkCMCTreeRow *)clist_row,
1206 style, &clip_rectangle, offset);
1208 if (clist->column[i].justification == GTK_JUSTIFY_RIGHT)
1209 offset -= ctree->tree_spacing;
1211 offset += ctree->tree_spacing;
1213 if (clist->column[i].justification == GTK_JUSTIFY_RIGHT)
1214 offset -= (pixbuf_width + clist_row->cell[i].horizontal);
1216 offset += clist_row->cell[i].horizontal;
1218 old_offset = offset;
1219 offset = gtk_sctree_draw_cell_pixbuf (clist->clist_window, &clip_rectangle, fg_gc,
1220 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf,
1222 clip_rectangle.y + clist_row->cell[i].vertical
1223 + (clip_rectangle.height - height) / 2,
1224 pixbuf_width, height);
1228 gint row_center_offset = (clist->row_height - logical_rect.height) / 2;
1230 if (clist->column[i].justification == GTK_JUSTIFY_RIGHT)
1232 offset = (old_offset - string_width);
1233 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf)
1234 offset -= GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1238 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf)
1239 offset += GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1242 gdk_gc_set_clip_rectangle (fg_gc, &clip_rectangle);
1243 gdk_draw_layout (clist->clist_window, fg_gc,
1245 row_rectangle.y + row_center_offset + clist_row->cell[i].vertical,
1248 g_object_unref (G_OBJECT (layout));
1250 gdk_gc_set_clip_rectangle (fg_gc, NULL);
1253 /* draw focus rectangle */
1254 if (clist->focus_row == row &&
1255 gtkut_widget_get_can_focus (widget) && gtkut_widget_has_focus (widget))
1258 gdk_draw_rectangle (clist->clist_window, clist->xor_gc, FALSE,
1259 row_rectangle.x, row_rectangle.y,
1260 row_rectangle.width - 1, row_rectangle.height - 1);
1261 else if (gdk_rectangle_intersect (area, &row_rectangle,
1262 &intersect_rectangle))
1264 gdk_gc_set_clip_rectangle (clist->xor_gc, &intersect_rectangle);
1265 gdk_draw_rectangle (clist->clist_window, clist->xor_gc, FALSE,
1266 row_rectangle.x, row_rectangle.y,
1267 row_rectangle.width - 1,
1268 row_rectangle.height - 1);
1269 gdk_gc_set_clip_rectangle (clist->xor_gc, NULL);
1275 gtk_sctree_change_focus_row_expansion (GtkCMCTree *ctree,
1276 GtkCMCTreeExpansionType action)
1279 GtkCMCTreeNode *node;
1281 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
1283 clist = GTK_CMCLIST (ctree);
1285 if (gdk_display_pointer_is_grabbed (gtk_widget_get_display (GTK_WIDGET (ctree))) &&
1286 gtkut_widget_has_grab (GTK_WIDGET(ctree)))
1290 GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row))) ||
1291 GTK_CMCTREE_ROW (node)->is_leaf || !(GTK_CMCTREE_ROW (node)->children))
1296 case GTK_CMCTREE_EXPANSION_EXPAND:
1297 if (GTK_SCTREE(ctree)->always_expand_recursively)
1298 gtk_cmctree_expand_recursive (ctree, node);
1300 gtk_cmctree_expand (ctree, node);
1303 case GTK_CMCTREE_EXPANSION_EXPAND_RECURSIVE:
1304 gtk_cmctree_expand_recursive (ctree, node);
1306 case GTK_CMCTREE_EXPANSION_COLLAPSE:
1307 gtk_cmctree_collapse (ctree, node);
1309 case GTK_CMCTREE_EXPANSION_COLLAPSE_RECURSIVE:
1310 gtk_cmctree_collapse_recursive (ctree, node);
1312 case GTK_CMCTREE_EXPANSION_TOGGLE:
1313 if (GTK_SCTREE(ctree)->always_expand_recursively)
1314 gtk_cmctree_toggle_expansion_recursive (ctree, node);
1316 gtk_cmctree_toggle_expansion (ctree, node);
1318 case GTK_CMCTREE_EXPANSION_TOGGLE_RECURSIVE:
1319 gtk_cmctree_toggle_expansion_recursive (ctree, node);
1324 static void gtk_sctree_finalize(GObject *object)
1326 GtkSCTree *sctree = GTK_SCTREE(object);
1327 g_free(sctree->use_markup);
1328 sctree->use_markup = NULL;
1329 G_OBJECT_CLASS (parent_class)->finalize (object);
1332 /* Standard class initialization function */
1334 gtk_sctree_class_init (GtkSCTreeClass *klass)
1336 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1337 GtkObjectClass *object_class;
1338 GtkWidgetClass *widget_class;
1339 GtkCMCListClass *clist_class;
1340 GtkCMCTreeClass *ctree_class;
1342 object_class = (GtkObjectClass *) klass;
1343 widget_class = (GtkWidgetClass *) klass;
1344 clist_class = (GtkCMCListClass *) klass;
1345 ctree_class = (GtkCMCTreeClass *) klass;
1347 parent_class = g_type_class_peek (gtk_cmctree_get_type ());
1349 sctree_signals[ROW_POPUP_MENU] =
1350 g_signal_new ("row_popup_menu",
1351 G_TYPE_FROM_CLASS (klass),
1353 G_STRUCT_OFFSET (GtkSCTreeClass, row_popup_menu),
1355 claws_marshal_VOID__POINTER,
1358 sctree_signals[EMPTY_POPUP_MENU] =
1359 g_signal_new ("empty_popup_menu",
1360 G_TYPE_FROM_CLASS (klass),
1362 G_STRUCT_OFFSET (GtkSCTreeClass, empty_popup_menu),
1364 claws_marshal_VOID__POINTER,
1367 sctree_signals[OPEN_ROW] =
1368 g_signal_new ("open_row",
1369 G_TYPE_FROM_CLASS (klass),
1371 G_STRUCT_OFFSET (GtkSCTreeClass, open_row),
1373 g_cclosure_marshal_VOID__VOID,
1375 sctree_signals[START_DRAG] =
1376 g_signal_new ("start_drag",
1377 G_TYPE_FROM_CLASS (klass),
1379 G_STRUCT_OFFSET (GtkSCTreeClass, start_drag),
1381 claws_marshal_VOID__INT_POINTER,
1386 /* gtk_object_class_add_signals (object_class, sctree_signals, LAST_SIGNAL); */
1388 clist_class->clear = gtk_sctree_clear;
1389 clist_class->draw_row = gtk_sctree_draw_row;
1390 clist_class->unselect_all = gtk_sctree_real_unselect_all;
1391 ctree_class->tree_collapse = gtk_sctree_real_tree_collapse;
1392 ctree_class->tree_expand = gtk_sctree_real_tree_expand;
1393 ctree_class->tree_move = sreal_tree_move;
1394 ctree_class->change_focus_row_expansion = gtk_sctree_change_focus_row_expansion;
1396 widget_class->button_press_event = gtk_sctree_button_press;
1397 widget_class->button_release_event = gtk_sctree_button_release;
1398 widget_class->motion_notify_event = gtk_sctree_motion;
1399 widget_class->drag_begin = gtk_sctree_drag_begin;
1400 widget_class->drag_end = gtk_sctree_drag_end;
1401 widget_class->drag_data_get = gtk_sctree_drag_data_get;
1402 widget_class->drag_leave = gtk_sctree_drag_leave;
1403 widget_class->drag_motion = gtk_sctree_drag_motion;
1404 widget_class->drag_drop = gtk_sctree_drag_drop;
1405 widget_class->drag_data_received = gtk_sctree_drag_data_received;
1407 gobject_class->finalize = gtk_sctree_finalize;
1410 /* Standard object initialization function */
1412 gtk_sctree_init (GtkSCTree *sctree)
1414 sctree->anchor_row = NULL;
1416 /* GtkCMCTree does not specify pointer motion by default */
1417 gtk_widget_add_events (GTK_WIDGET (sctree), GDK_POINTER_MOTION_MASK);
1418 gtk_widget_add_events (GTK_WIDGET (sctree), GDK_POINTER_MOTION_MASK);
1421 /* Get information the specified row is selected. */
1424 row_is_selected(GtkSCTree *sctree, gint row)
1426 GtkCMCListRow *clist_row;
1427 clist_row = g_list_nth (GTK_CMCLIST(sctree)->row_list, row)->data;
1428 return clist_row ? clist_row->state == GTK_STATE_SELECTED : FALSE;
1431 /* Selects the rows between the anchor to the specified row, inclusive. */
1433 select_range (GtkSCTree *sctree, gint row)
1439 if (sctree->anchor_row == NULL) {
1441 sctree->anchor_row = gtk_cmctree_node_nth(GTK_CMCTREE(sctree), row);
1443 prev_row = g_list_position(GTK_CMCLIST(sctree)->row_list,
1444 (GList *)sctree->anchor_row);
1446 if (row < prev_row) {
1449 GTK_CMCLIST(sctree)->focus_row = max;
1454 sctree->selecting_range++;
1463 gtk_cmclist_freeze(GTK_CMCLIST(sctree));
1465 node = g_list_nth((GTK_CMCLIST(sctree))->row_list, min);
1466 for (i = min; i < max; i++) {
1467 if (node && GTK_CMCTREE_ROW (node)->row.selectable) {
1468 g_signal_emit_by_name(G_OBJECT(sctree), "tree_select_row",
1474 gtk_cmclist_thaw(GTK_CMCLIST(sctree));
1477 sctree->selecting_range--;
1478 gtk_cmclist_select_row (GTK_CMCLIST (sctree), max, -1);
1481 /* Handles row selection according to the specified modifier state */
1482 /* in certain cases, we arrive here from a function knowing the GtkCMCTreeNode, and having
1483 * already slowly found row using g_list_position. In which case, _node will be non-NULL
1484 * to avoid this function having to slowly find it with g_list_nth. */
1486 select_row (GtkSCTree *sctree, gint row, gint col, guint state, GtkCMCTreeNode *_node)
1488 gboolean range, additive;
1489 cm_return_if_fail (sctree != NULL);
1490 cm_return_if_fail (GTK_IS_SCTREE (sctree));
1492 range = ((state & GDK_SHIFT_MASK) != 0) &&
1493 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_SINGLE) &&
1494 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_BROWSE);
1495 additive = ((state & GDK_CONTROL_MASK) != 0) &&
1496 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_SINGLE) &&
1497 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_BROWSE);
1499 if (!range && !additive && sctree->force_additive_sel)
1502 GTK_CMCLIST(sctree)->focus_row = row;
1505 gtk_cmclist_unselect_all (GTK_CMCLIST (sctree));
1509 GtkCMCTreeNode *node;
1511 node = _node ? _node : gtk_cmctree_node_nth (GTK_CMCTREE(sctree), row);
1513 /*No need to manage overlapped list*/
1515 if (row_is_selected(sctree, row))
1516 gtk_cmclist_unselect_row (GTK_CMCLIST (sctree), row, col);
1518 g_signal_emit_by_name
1520 "tree_select_row", node, col);
1522 g_signal_emit_by_name
1524 "tree_select_row", node, col);
1526 sctree->anchor_row = node;
1528 select_range (sctree, row);
1532 sctree_is_hot_spot (GtkSCTree *sctree,
1533 GtkCMCTreeNode *node,
1538 GtkCMCTreeRow *tree_row;
1541 GtkCMCellPixText *cell;
1545 cm_return_val_if_fail (GTK_IS_SCTREE (sctree), FALSE);
1546 cm_return_val_if_fail (node != NULL, FALSE);
1548 clist = GTK_CMCLIST (sctree);
1549 ctree = GTK_CMCTREE (sctree);
1551 if (!clist->column[ctree->tree_column].visible ||
1552 ctree->expander_style == GTK_CMCTREE_EXPANDER_NONE)
1555 tree_row = GTK_CMCTREE_ROW (node);
1557 cell = GTK_CMCELL_PIXTEXT (tree_row->row.cell[ctree->tree_column]);
1559 if (!GTK_CMCLIST_ROW_HEIGHT_SET(GTK_CMCLIST(clist)))
1560 yu = (ROW_TOP_YPIXEL (clist, row) + (clist->row_height - PM_SIZE) / 2 -
1561 (clist->row_height - 1) % 2);
1563 yu = (ROW_TOP_YPIXEL (clist, row) + (clist->row_height/2 - PM_SIZE) / 2 -
1564 (clist->row_height/2 - 1) % 2);
1566 #ifndef GENERIC_UMPC
1567 if (clist->column[ctree->tree_column].justification == GTK_JUSTIFY_RIGHT)
1568 xl = (clist->column[ctree->tree_column].area.x +
1569 clist->column[ctree->tree_column].area.width - 1 + clist->hoffset -
1570 (tree_row->level - 1) * ctree->tree_indent - PM_SIZE -
1571 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1573 xl = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1574 (tree_row->level - 1) * ctree->tree_indent +
1575 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1577 xmax = xl + PM_SIZE;
1579 if (clist->column[ctree->tree_column].justification == GTK_JUSTIFY_RIGHT) {
1580 xl = (clist->column[ctree->tree_column].area.x +
1581 clist->column[ctree->tree_column].area.width - 1 + clist->hoffset -
1582 (tree_row->level - 1) * ctree->tree_indent - PM_SIZE -
1583 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1584 xmax = xl + PM_SIZE;
1585 } else if (ctree->tree_column == 0) {
1586 xl = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1587 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1588 xmax = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1589 (tree_row->level - 1) * ctree->tree_indent +
1590 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3) +
1593 xl = (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);
1596 xmax = xl + PM_SIZE;
1599 return (x >= xl && x <= xmax && y >= yu && y <= yu + PM_SIZE);
1603 gtk_sctree_is_hot_spot (GtkSCTree *ctree,
1607 GtkCMCTreeNode *node;
1611 cm_return_val_if_fail (GTK_IS_SCTREE (ctree), FALSE);
1613 if (gtk_cmclist_get_selection_info (GTK_CMCLIST (ctree), x, y, &row, &column))
1614 if ((node = GTK_CMCTREE_NODE(g_list_nth (GTK_CMCLIST (ctree)->row_list, row))))
1615 return sctree_is_hot_spot (ctree, node, row, x, y);
1620 /* Our handler for button_press events. We override all of GtkCMCList's broken
1624 gtk_sctree_button_press (GtkWidget *widget, GdkEventButton *event)
1633 cm_return_val_if_fail (widget != NULL, FALSE);
1634 cm_return_val_if_fail (GTK_IS_SCTREE (widget), FALSE);
1635 cm_return_val_if_fail (event != NULL, FALSE);
1637 sctree = GTK_SCTREE (widget);
1638 clist = GTK_CMCLIST (widget);
1641 if (event->window != clist->clist_window)
1642 return (* GTK_WIDGET_CLASS (parent_class)->button_press_event) (widget, event);
1644 on_row = gtk_cmclist_get_selection_info (clist, event->x, event->y, &row, &col);
1646 if (on_row && !gtkut_widget_has_focus(widget))
1647 gtk_widget_grab_focus (widget);
1649 if (gtk_sctree_is_hot_spot (GTK_SCTREE(sctree), event->x, event->y)) {
1650 GtkCMCTreeNode *node = gtk_cmctree_node_nth(GTK_CMCTREE(sctree), row);
1651 if (GTK_CMCTREE_ROW (node)->expanded)
1652 gtk_cmctree_collapse(GTK_CMCTREE(sctree), node);
1653 else if (GTK_SCTREE(sctree)->always_expand_recursively)
1654 gtk_cmctree_expand_recursive (GTK_CMCTREE(sctree), node);
1656 gtk_cmctree_expand(GTK_CMCTREE(sctree), node);
1660 switch (event->type) {
1661 case GDK_BUTTON_PRESS:
1662 if (event->button == 1 || event->button == 2) {
1663 if (event->button == 2)
1664 event->state &= ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK);
1666 /* Save the mouse info for DnD */
1667 sctree->dnd_press_button = event->button;
1668 sctree->dnd_press_x = event->x;
1669 sctree->dnd_press_y = event->y;
1671 /* Handle selection */
1672 if ((row_is_selected (sctree, row)
1673 && !(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)))
1674 || ((event->state & GDK_CONTROL_MASK)
1675 && !(event->state & GDK_SHIFT_MASK))) {
1676 sctree->dnd_select_pending = TRUE;
1677 sctree->dnd_select_pending_state = event->state;
1678 sctree->dnd_select_pending_row = row;
1680 select_row (sctree, row, col, event->state, NULL);
1683 gtk_cmclist_unselect_all (clist);
1687 } else if (event->button == 3) {
1688 /* Emit *_popup_menu signal*/
1690 if (!row_is_selected(sctree,row))
1691 select_row (sctree, row, col, 0, NULL);
1692 g_signal_emit (G_OBJECT (sctree),
1693 sctree_signals[ROW_POPUP_MENU],
1696 gtk_cmclist_unselect_all(clist);
1697 g_signal_emit (G_OBJECT (sctree),
1698 sctree_signals[EMPTY_POPUP_MENU],
1706 case GDK_2BUTTON_PRESS:
1707 if (event->button != 1)
1710 sctree->dnd_select_pending = FALSE;
1711 sctree->dnd_select_pending_state = 0;
1714 g_signal_emit (G_OBJECT (sctree),
1715 sctree_signals[OPEN_ROW], 0);
1727 /* Our handler for button_release events. We override all of GtkCMCList's broken
1731 gtk_sctree_button_release (GtkWidget *widget, GdkEventButton *event)
1739 cm_return_val_if_fail (widget != NULL, FALSE);
1740 cm_return_val_if_fail (GTK_IS_SCTREE (widget), FALSE);
1741 cm_return_val_if_fail (event != NULL, FALSE);
1743 sctree = GTK_SCTREE (widget);
1744 clist = GTK_CMCLIST (widget);
1747 if (event->window != clist->clist_window)
1748 return (* GTK_WIDGET_CLASS (parent_class)->button_release_event) (widget, event);
1750 on_row = gtk_cmclist_get_selection_info (clist, event->x, event->y, &row, &col);
1752 if (!(event->button == 1 || event->button == 2))
1755 sctree->dnd_press_button = 0;
1756 sctree->dnd_press_x = 0;
1757 sctree->dnd_press_y = 0;
1760 if (sctree->dnd_select_pending) {
1761 select_row (sctree, row, col, sctree->dnd_select_pending_state, NULL);
1762 sctree->dnd_select_pending = FALSE;
1763 sctree->dnd_select_pending_state = 0;
1772 /* Our handler for motion_notify events. We override all of GtkCMCList's broken
1776 gtk_sctree_motion (GtkWidget *widget, GdkEventMotion *event)
1781 cm_return_val_if_fail (widget != NULL, FALSE);
1782 cm_return_val_if_fail (GTK_IS_SCTREE (widget), FALSE);
1783 cm_return_val_if_fail (event != NULL, FALSE);
1785 sctree = GTK_SCTREE (widget);
1786 clist = GTK_CMCLIST (widget);
1788 if (event->window != clist->clist_window)
1789 return (* GTK_WIDGET_CLASS (parent_class)->motion_notify_event) (widget, event);
1791 if (!((sctree->dnd_press_button == 1 && (event->state & GDK_BUTTON1_MASK))
1792 || (sctree->dnd_press_button == 2 && (event->state & GDK_BUTTON2_MASK))))
1795 /* This is the same threshold value that is used in gtkdnd.c */
1797 #ifndef GENERIC_UMPC
1802 if (MAX (ABS (sctree->dnd_press_x - event->x),
1803 ABS (sctree->dnd_press_y - event->y)) <= THRESHOLD)
1806 /* Handle any pending selections */
1808 if (sctree->dnd_select_pending) {
1809 if (!row_is_selected(sctree,sctree->dnd_select_pending_row))
1811 sctree->dnd_select_pending_row,
1813 sctree->dnd_select_pending_state,
1816 sctree->dnd_select_pending = FALSE;
1817 sctree->dnd_select_pending_state = 0;
1820 g_signal_emit (G_OBJECT (sctree),
1821 sctree_signals[START_DRAG],
1823 sctree->dnd_press_button,
1828 /* We override the drag_begin signal to do nothing */
1830 gtk_sctree_drag_begin (GtkWidget *widget, GdkDragContext *context)
1835 /* We override the drag_end signal to do nothing */
1837 gtk_sctree_drag_end (GtkWidget *widget, GdkDragContext *context)
1842 /* We override the drag_data_get signal to do nothing */
1844 gtk_sctree_drag_data_get (GtkWidget *widget, GdkDragContext *context,
1845 GtkSelectionData *data, guint info, guint time)
1850 /* We override the drag_leave signal to do nothing */
1852 gtk_sctree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time)
1857 /* We override the drag_motion signal to do nothing */
1859 gtk_sctree_drag_motion (GtkWidget *widget, GdkDragContext *context,
1860 gint x, gint y, guint time)
1865 /* We override the drag_drop signal to do nothing */
1867 gtk_sctree_drag_drop (GtkWidget *widget, GdkDragContext *context,
1868 gint x, gint y, guint time)
1873 /* We override the drag_data_received signal to do nothing */
1875 gtk_sctree_drag_data_received (GtkWidget *widget, GdkDragContext *context,
1876 gint x, gint y, GtkSelectionData *data,
1877 guint info, guint time)
1882 /* Our handler for the clear signal of the clist. We have to reset the anchor
1886 gtk_sctree_clear (GtkCMCList *clist)
1890 cm_return_if_fail (clist != NULL);
1891 cm_return_if_fail (GTK_IS_SCTREE (clist));
1893 sctree = GTK_SCTREE (clist);
1894 sctree->anchor_row = NULL;
1896 if (((GtkCMCListClass *)parent_class)->clear)
1897 (* ((GtkCMCListClass *)parent_class)->clear) (clist);
1901 gtk_sctree_real_unselect_all (GtkCMCList *clist)
1904 gboolean should_freeze = FALSE;
1906 cm_return_if_fail (clist != NULL);
1907 cm_return_if_fail (GTK_IS_SCTREE (clist));
1909 sctree = GTK_SCTREE (clist);
1911 if (sc_g_list_bigger(GTK_CMCLIST(sctree)->selection, 10)) {
1912 should_freeze = TRUE;
1913 sctree->selecting_range++;
1914 gtk_cmclist_freeze (GTK_CMCLIST (sctree));
1917 if (((GtkCMCListClass *)parent_class)->unselect_all)
1918 (* ((GtkCMCListClass *)parent_class)->unselect_all) (clist);
1920 if (should_freeze) {
1921 gtk_cmclist_thaw (GTK_CMCLIST (sctree));
1922 sctree->selecting_range--;
1927 gtk_sctree_column_auto_resize (GtkCMCList *clist,
1928 GtkCMCListRow *clist_row,
1932 /* resize column if needed for auto_resize */
1933 GtkRequisition requisition;
1935 if (!clist->column[column].auto_resize ||
1936 GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
1940 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request (clist, clist_row,
1941 column, &requisition);
1943 requisition.width = 0;
1945 if (requisition.width > clist->column[column].width)
1946 gtk_cmclist_set_column_width (clist, column, requisition.width);
1947 else if (requisition.width < old_width &&
1948 old_width == clist->column[column].width)
1953 /* run a "gtk_cmclist_optimal_column_width" but break, if
1954 * the column doesn't shrink */
1955 if (GTK_CMCLIST_SHOW_TITLES (clist) && clist->column[column].button)
1956 new_width = (clist->column[column].button->requisition.width -
1957 (CELL_SPACING + (2 * COLUMN_INSET)));
1961 for (list = clist->row_list; list; list = list->next)
1963 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
1964 (clist, GTK_CMCLIST_ROW (list), column, &requisition);
1965 new_width = MAX (new_width, requisition.width);
1966 if (new_width == clist->column[column].width)
1969 if (new_width < clist->column[column].width)
1970 gtk_cmclist_set_column_width (clist, column, new_width);
1975 gtk_sctree_auto_resize_columns (GtkCMCList *clist)
1979 if (GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
1982 for (i = 0; i < clist->columns; i++)
1983 gtk_sctree_column_auto_resize (clist, NULL, i, clist->column[i].width);
1987 gtk_sctree_real_tree_collapse (GtkCMCTree *ctree,
1988 GtkCMCTreeNode *node)
1991 GtkCMCTreeNode *work;
1992 GtkRequisition requisition;
1996 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
1998 if (!node || !GTK_CMCTREE_ROW (node)->expanded ||
1999 GTK_CMCTREE_ROW (node)->is_leaf)
2002 clist = GTK_CMCLIST (ctree);
2004 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2006 GTK_CMCTREE_ROW (node)->expanded = FALSE;
2007 level = GTK_CMCTREE_ROW (node)->level;
2009 visible = gtk_cmctree_is_viewable (ctree, node);
2010 /* get cell width if tree_column is auto resized */
2011 if (visible && clist->column[ctree->tree_column].auto_resize &&
2012 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2013 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2014 (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column, &requisition);
2016 /* unref/unset opened pixbuf */
2017 if (GTK_CMCELL_PIXTEXT
2018 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf)
2022 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf);
2025 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf = NULL;
2028 /* set/ref closed pixbuf */
2029 if (GTK_CMCTREE_ROW (node)->pixbuf_closed)
2032 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf =
2033 g_object_ref (GTK_CMCTREE_ROW (node)->pixbuf_closed);
2036 work = GTK_CMCTREE_ROW (node)->children;
2043 while (work && GTK_CMCTREE_ROW (work)->level > level)
2045 work = GTK_CMCTREE_NODE_NEXT (work);
2051 list = (GList *)node;
2052 list->next = (GList *)work;
2053 list = (GList *)GTK_CMCTREE_NODE_PREV (work);
2055 list = (GList *)work;
2056 list->prev = (GList *)node;
2060 list = (GList *)node;
2062 clist->row_list_end = (GList *)node;
2067 /* resize auto_resize columns if needed */
2068 gtk_sctree_auto_resize_columns (clist);
2070 if (!GTK_SCTREE(clist)->sorting) {
2071 row = g_list_position (clist->row_list, (GList *)node);
2072 if (row < clist->focus_row)
2073 clist->focus_row -= tmp;
2076 CLIST_REFRESH (clist);
2079 else if (visible && clist->column[ctree->tree_column].auto_resize &&
2080 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2081 /* resize tree_column if needed */
2082 gtk_sctree_column_auto_resize (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column,
2088 GtkWidget *gtk_sctree_new_with_titles (gint columns, gint tree_column,
2093 cm_return_val_if_fail (columns > 0, NULL);
2094 cm_return_val_if_fail (tree_column >= 0, NULL);
2096 if (tree_column >= columns) {
2097 g_warning("Wrong tree column");
2102 widget = gtk_widget_new (TYPE_GTK_SCTREE,
2103 "n_columns", columns,
2104 "tree_column", tree_column,
2107 GtkCMCList *clist = GTK_CMCLIST (widget);
2110 for (i = 0; i < columns; i++)
2111 gtk_cmclist_set_column_title (clist, i, titles[i]);
2112 gtk_cmclist_column_titles_show (clist);
2115 GTK_SCTREE(widget)->show_stripes = TRUE;
2116 GTK_SCTREE(widget)->always_expand_recursively = TRUE;
2117 GTK_SCTREE(widget)->force_additive_sel = FALSE;
2119 GTK_SCTREE(widget)->use_markup = g_new0(gboolean, columns);
2124 void gtk_sctree_set_use_markup (GtkSCTree *sctree,
2129 GValue value = { 0 };
2131 cm_return_if_fail(GTK_IS_SCTREE(sctree));
2133 g_value_init (&value, G_TYPE_INT);
2134 g_object_get_property (G_OBJECT (sctree), "n-columns", &value);
2135 columns = g_value_get_int (&value);
2136 g_value_unset (&value);
2138 cm_return_if_fail(column < columns);
2140 sctree->use_markup[column] = markup;
2143 void gtk_sctree_select (GtkSCTree *sctree, GtkCMCTreeNode *node)
2146 g_list_position(GTK_CMCLIST(sctree)->row_list, (GList *)node),
2150 void gtk_sctree_select_with_state (GtkSCTree *sctree, GtkCMCTreeNode *node, int state)
2153 g_list_position(GTK_CMCLIST(sctree)->row_list, (GList *)node),
2157 void gtk_sctree_unselect_all (GtkSCTree *sctree)
2159 gtk_cmclist_unselect_all(GTK_CMCLIST(sctree));
2160 sctree->anchor_row = NULL;
2163 void gtk_sctree_set_anchor_row (GtkSCTree *sctree, GtkCMCTreeNode *node)
2165 sctree->anchor_row = node;
2168 void gtk_sctree_remove_node (GtkSCTree *sctree, GtkCMCTreeNode *node)
2170 if (sctree->anchor_row == node)
2171 sctree->anchor_row = NULL;
2172 gtk_cmctree_remove_node(GTK_CMCTREE(sctree), node);
2175 void gtk_sctree_set_stripes(GtkSCTree *sctree, gboolean show_stripes)
2177 sctree->show_stripes = show_stripes;
2180 void gtk_sctree_set_recursive_expand(GtkSCTree *sctree, gboolean rec_exp)
2182 sctree->always_expand_recursively = rec_exp;
2185 /***********************************************************
2186 * Tree sorting functions *
2187 ***********************************************************/
2189 static void sink(GtkCMCList *clist, GPtrArray *numbers, gint root, gint bottom)
2192 GtkCMCTreeNode *temp;
2197 /* find the maximum element of numbers[root],
2198 numbers[2*root] and numbers[2*root+1] */
2200 if (clist->compare( clist, GTK_CMCTREE_ROW (g_ptr_array_index(numbers, root)),
2201 GTK_CMCTREE_ROW(g_ptr_array_index( numbers, j))) >= 0)
2204 if (clist->compare( clist, GTK_CMCTREE_ROW (g_ptr_array_index(numbers, k)),
2205 GTK_CMCTREE_ROW (g_ptr_array_index( numbers, j))) > 0)
2207 /* if numbers[root] wasn't the maximum element then
2210 temp = g_ptr_array_index( numbers,root);
2211 g_ptr_array_index( numbers, root) = g_ptr_array_index( numbers, j);
2212 g_ptr_array_index( numbers, j) = temp;
2213 sink( clist, numbers, j, bottom);
2218 static void heap_sort(GtkCMCList *clist, GPtrArray *numbers, gint array_size)
2221 GtkCMCTreeNode *temp;
2223 /* build the Heap */
2224 for (i = (array_size / 2); i >= 1; i--)
2225 sink( clist, numbers, i, array_size);
2226 /* output the Heap */
2227 for (i = array_size; i >= 2; i--) {
2228 temp = g_ptr_array_index( numbers, 1);
2229 g_ptr_array_index( numbers, 1) = g_ptr_array_index( numbers, i);
2230 g_ptr_array_index( numbers, i) = temp;
2231 sink( clist, numbers, 1, i-1);
2236 stree_sort (GtkCMCTree *ctree,
2237 GtkCMCTreeNode *node,
2240 GtkCMCTreeNode *list_start, *work, *next;
2241 GPtrArray *row_array, *viewable_array;
2245 clist = GTK_CMCLIST (ctree);
2248 work = GTK_CMCTREE_ROW (node)->children;
2250 work = GTK_CMCTREE_NODE (clist->row_list);
2252 row_array = g_ptr_array_new();
2253 viewable_array = g_ptr_array_new();
2256 g_ptr_array_add( row_array, NULL);
2258 /* add all rows to row_array */
2259 g_ptr_array_add( row_array, work);
2260 if (GTK_CMCTREE_ROW (work)->parent && gtk_cmctree_is_viewable( ctree, work))
2261 g_ptr_array_add( viewable_array, GTK_CMCTREE_ROW (work)->parent);
2262 next = GTK_CMCTREE_ROW (work)->sibling;
2263 gtk_sctree_unlink( ctree, work, FALSE);
2267 heap_sort( clist, row_array, (row_array->len)-1);
2270 list_start = GTK_CMCTREE_ROW (node)->children;
2272 list_start = GTK_CMCTREE_NODE (clist->row_list);
2274 if (clist->sort_type == GTK_SORT_ASCENDING) {
2275 for (i=(row_array->len)-1; i>=1; i--) {
2276 work = g_ptr_array_index( row_array, i);
2277 gtk_sctree_link( ctree, work, node, list_start, FALSE);
2279 /* insert work at the beginning of the list */
2282 for (i=1; i<row_array->len; i++) {
2283 work = g_ptr_array_index( row_array, i);
2284 gtk_sctree_link( ctree, work, node, list_start, FALSE);
2286 /* insert work at the beginning of the list */
2290 for (i=0; i<viewable_array->len; i++) {
2291 gtk_cmctree_expand( ctree, g_ptr_array_index( viewable_array, i));
2295 g_ptr_array_free( row_array, TRUE);
2296 g_ptr_array_free( viewable_array, TRUE);
2300 gtk_sctree_sort_recursive (GtkCMCTree *ctree,
2301 GtkCMCTreeNode *node)
2304 GtkCMCTreeNode *focus_node = NULL;
2306 cm_return_if_fail (ctree != NULL);
2307 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2309 clist = GTK_CMCLIST (ctree);
2311 gtk_cmclist_freeze (clist);
2313 if (clist->selection_mode == GTK_SELECTION_EXTENDED) {
2314 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2316 g_list_free (clist->undo_selection);
2317 g_list_free (clist->undo_unselection);
2318 clist->undo_selection = NULL;
2319 clist->undo_unselection = NULL;
2322 if (!node || (node && gtk_cmctree_is_viewable (ctree, node)))
2323 focus_node = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
2325 GTK_SCTREE(ctree)->sorting = TRUE;
2327 gtk_cmctree_post_recursive (ctree, node, GTK_CMCTREE_FUNC (stree_sort), NULL);
2330 stree_sort (ctree, NULL, NULL);
2332 GTK_SCTREE(ctree)->sorting = FALSE;
2335 clist->focus_row = g_list_position (clist->row_list,(GList *)focus_node);
2336 clist->undo_anchor = clist->focus_row;
2339 gtk_cmclist_thaw (clist);
2343 gtk_sctree_sort_node (GtkCMCTree *ctree,
2344 GtkCMCTreeNode *node)
2347 GtkCMCTreeNode *focus_node = NULL;
2349 cm_return_if_fail (ctree != NULL);
2350 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2352 clist = GTK_CMCLIST (ctree);
2354 gtk_cmclist_freeze (clist);
2356 if (clist->selection_mode == GTK_SELECTION_EXTENDED) {
2357 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2359 g_list_free (clist->undo_selection);
2360 g_list_free (clist->undo_unselection);
2361 clist->undo_selection = NULL;
2362 clist->undo_unselection = NULL;
2365 if (!node || (node && gtk_cmctree_is_viewable (ctree, node)))
2366 focus_node = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
2368 GTK_SCTREE(ctree)->sorting = TRUE;
2370 stree_sort (ctree, node, NULL);
2372 GTK_SCTREE(ctree)->sorting = FALSE;
2375 clist->focus_row = g_list_position (clist->row_list,(GList *)focus_node);
2376 clist->undo_anchor = clist->focus_row;
2379 gtk_cmclist_thaw (clist);
2382 /************************************************************************/
2385 gtk_sctree_unlink (GtkCMCTree *ctree,
2386 GtkCMCTreeNode *node,
2387 gboolean update_focus_row)
2393 GtkCMCTreeNode *work;
2394 GtkCMCTreeNode *parent;
2397 cm_return_if_fail (ctree != NULL);
2398 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2399 cm_return_if_fail (node != NULL);
2401 clist = GTK_CMCLIST (ctree);
2403 if (update_focus_row && clist->selection_mode == GTK_SELECTION_EXTENDED) {
2404 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2406 g_list_free (clist->undo_selection);
2407 g_list_free (clist->undo_unselection);
2408 clist->undo_selection = NULL;
2409 clist->undo_unselection = NULL;
2412 visible = gtk_cmctree_is_viewable (ctree, node);
2414 /* clist->row_list_end unlinked ? */
2415 if (visible && (GTK_CMCTREE_NODE_NEXT (node) == NULL ||
2416 (GTK_CMCTREE_ROW (node)->children && gtk_cmctree_is_ancestor (ctree, node,
2417 GTK_CMCTREE_NODE (clist->row_list_end)))))
2418 clist->row_list_end = (GList *) (GTK_CMCTREE_NODE_PREV (node));
2422 level = GTK_CMCTREE_ROW (node)->level;
2423 work = GTK_CMCTREE_NODE_NEXT (node);
2424 while (work && GTK_CMCTREE_ROW (work)->level > level) {
2425 work = GTK_CMCTREE_NODE_NEXT (work);
2430 clist->rows -= (rows + 1);
2432 if (update_focus_row) {
2434 pos = g_list_position (clist->row_list, (GList *)node);
2435 if (pos + rows < clist->focus_row)
2436 clist->focus_row -= (rows + 1);
2437 else if (pos <= clist->focus_row) {
2438 if (!GTK_CMCTREE_ROW (node)->sibling)
2439 clist->focus_row = MAX (pos - 1, 0);
2441 clist->focus_row = pos;
2443 clist->focus_row = MIN (clist->focus_row, clist->rows - 1);
2445 clist->undo_anchor = clist->focus_row;
2450 list = (GList *)GTK_CMCTREE_NODE_PREV (work);
2452 list = (GList *)work;
2453 list->prev = (GList *)GTK_CMCTREE_NODE_PREV (node);
2456 if (GTK_CMCTREE_NODE_PREV (node) &&
2457 GTK_CMCTREE_NODE_NEXT (GTK_CMCTREE_NODE_PREV (node)) == node) {
2458 list = (GList *)GTK_CMCTREE_NODE_PREV (node);
2459 list->next = (GList *)work;
2463 parent = GTK_CMCTREE_ROW (node)->parent;
2465 if (GTK_CMCTREE_ROW (parent)->children == node) {
2466 GTK_CMCTREE_ROW (parent)->children = GTK_CMCTREE_ROW (node)->sibling;
2469 GtkCMCTreeNode *sibling;
2471 sibling = GTK_CMCTREE_ROW (parent)->children;
2472 while (GTK_CMCTREE_ROW (sibling)->sibling != node)
2473 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
2474 GTK_CMCTREE_ROW (sibling)->sibling = GTK_CMCTREE_ROW (node)->sibling;
2478 if (clist->row_list == (GList *)node)
2479 clist->row_list = (GList *) (GTK_CMCTREE_ROW (node)->sibling);
2481 GtkCMCTreeNode *sibling;
2483 sibling = GTK_CMCTREE_NODE (clist->row_list);
2484 while (GTK_CMCTREE_ROW (sibling)->sibling != node)
2485 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
2486 GTK_CMCTREE_ROW (sibling)->sibling = GTK_CMCTREE_ROW (node)->sibling;
2492 gtk_sctree_link (GtkCMCTree *ctree,
2493 GtkCMCTreeNode *node,
2494 GtkCMCTreeNode *parent,
2495 GtkCMCTreeNode *sibling,
2496 gboolean update_focus_row)
2502 gboolean visible = FALSE;
2506 cm_return_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent);
2507 cm_return_if_fail (node != NULL);
2508 cm_return_if_fail (node != sibling);
2509 cm_return_if_fail (node != parent);
2511 clist = GTK_CMCLIST (ctree);
2513 if (update_focus_row && clist->selection_mode == GTK_SELECTION_EXTENDED) {
2514 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2516 g_list_free (clist->undo_selection);
2517 g_list_free (clist->undo_unselection);
2518 clist->undo_selection = NULL;
2519 clist->undo_unselection = NULL;
2522 for (rows = 1, list_end = (GList *)node; list_end->next;
2523 list_end = list_end->next)
2526 GTK_CMCTREE_ROW (node)->parent = parent;
2527 GTK_CMCTREE_ROW (node)->sibling = sibling;
2529 if (!parent || (parent && (gtk_cmctree_is_viewable (ctree, parent) &&
2530 GTK_CMCTREE_ROW (parent)->expanded))) {
2532 clist->rows += rows;
2536 work = (GList *)(GTK_CMCTREE_ROW (parent)->children);
2538 work = clist->row_list;
2541 if (work != (GList *)sibling) {
2542 while (GTK_CMCTREE_ROW (work)->sibling != sibling)
2543 work = (GList *)(GTK_CMCTREE_ROW (work)->sibling);
2544 GTK_CMCTREE_ROW (work)->sibling = node;
2547 if (sibling == GTK_CMCTREE_NODE (clist->row_list))
2548 clist->row_list = (GList *) node;
2549 if (GTK_CMCTREE_NODE_PREV (sibling) &&
2550 GTK_CMCTREE_NODE_NEXT (GTK_CMCTREE_NODE_PREV (sibling)) == sibling) {
2551 list = (GList *)GTK_CMCTREE_NODE_PREV (sibling);
2552 list->next = (GList *)node;
2555 list = (GList *)node;
2556 list->prev = (GList *)GTK_CMCTREE_NODE_PREV (sibling);
2557 list_end->next = (GList *)sibling;
2558 list = (GList *)sibling;
2559 list->prev = list_end;
2560 if (parent && GTK_CMCTREE_ROW (parent)->children == sibling)
2561 GTK_CMCTREE_ROW (parent)->children = node;
2566 while (GTK_CMCTREE_ROW (work)->sibling)
2567 work = (GList *)(GTK_CMCTREE_ROW (work)->sibling);
2568 GTK_CMCTREE_ROW (work)->sibling = node;
2570 /* find last visible child of sibling */
2571 work = (GList *) gtk_sctree_last_visible (ctree,
2572 GTK_CMCTREE_NODE (work));
2574 list_end->next = work->next;
2576 list = work->next->prev = list_end;
2577 work->next = (GList *)node;
2578 list = (GList *)node;
2583 GTK_CMCTREE_ROW (parent)->children = node;
2584 list = (GList *)node;
2585 list->prev = (GList *)parent;
2586 if (GTK_CMCTREE_ROW (parent)->expanded) {
2587 list_end->next = (GList *)GTK_CMCTREE_NODE_NEXT (parent);
2588 if (GTK_CMCTREE_NODE_NEXT(parent)) {
2589 list = (GList *)GTK_CMCTREE_NODE_NEXT (parent);
2590 list->prev = list_end;
2592 list = (GList *)parent;
2593 list->next = (GList *)node;
2596 list_end->next = NULL;
2599 clist->row_list = (GList *)node;
2600 list = (GList *)node;
2602 list_end->next = NULL;
2607 gtk_cmctree_pre_recursive (ctree, node, stree_update_level, NULL);
2609 if (clist->row_list_end == NULL ||
2610 clist->row_list_end->next == (GList *)node)
2611 clist->row_list_end = list_end;
2613 if (visible && update_focus_row) {
2615 pos = g_list_position (clist->row_list, (GList *)node);
2617 if (pos <= clist->focus_row) {
2618 clist->focus_row += rows;
2619 clist->undo_anchor = clist->focus_row;
2625 stree_update_level (GtkCMCTree *ctree,
2626 GtkCMCTreeNode *node,
2632 if (GTK_CMCTREE_ROW (node)->parent)
2633 GTK_CMCTREE_ROW (node)->level =
2634 GTK_CMCTREE_ROW (GTK_CMCTREE_ROW (node)->parent)->level + 1;
2636 GTK_CMCTREE_ROW (node)->level = 1;
2639 static GtkCMCTreeNode *
2640 gtk_sctree_last_visible (GtkCMCTree *ctree,
2641 GtkCMCTreeNode *node)
2643 GtkCMCTreeNode *work;
2648 work = GTK_CMCTREE_ROW (node)->children;
2650 if (!work || !GTK_CMCTREE_ROW (node)->expanded)
2653 while (GTK_CMCTREE_ROW (work)->sibling)
2654 work = GTK_CMCTREE_ROW (work)->sibling;
2656 return gtk_sctree_last_visible (ctree, work);
2660 sset_node_info (GtkCMCTree *ctree,
2661 GtkCMCTreeNode *node,
2664 GdkPixbuf *pixbuf_closed,
2665 GdkPixbuf *pixbuf_opened,
2669 if (GTK_CMCTREE_ROW (node)->pixbuf_opened)
2671 g_object_unref (GTK_CMCTREE_ROW (node)->pixbuf_opened);
2673 if (GTK_CMCTREE_ROW (node)->pixbuf_closed)
2675 g_object_unref (GTK_CMCTREE_ROW (node)->pixbuf_closed);
2678 GTK_CMCTREE_ROW (node)->pixbuf_opened = NULL;
2679 GTK_CMCTREE_ROW (node)->pixbuf_closed = NULL;
2683 GTK_CMCTREE_ROW (node)->pixbuf_closed = g_object_ref (pixbuf_closed);
2687 GTK_CMCTREE_ROW (node)->pixbuf_opened = g_object_ref (pixbuf_opened);
2690 GTK_CMCTREE_ROW (node)->is_leaf = is_leaf;
2691 GTK_CMCTREE_ROW (node)->expanded = (is_leaf) ? FALSE : expanded;
2693 if (GTK_CMCTREE_ROW (node)->expanded)
2694 gtk_cmctree_node_set_pixtext (ctree, node, ctree->tree_column,
2695 text, spacing, pixbuf_opened);
2697 gtk_cmctree_node_set_pixtext (ctree, node, ctree->tree_column,
2698 text, spacing, pixbuf_closed);
2702 stree_draw_node (GtkCMCTree *ctree,
2703 GtkCMCTreeNode *node)
2707 clist = GTK_CMCLIST (ctree);
2709 if (CLIST_UNFROZEN (clist) && gtk_cmctree_is_viewable (ctree, node))
2711 GtkCMCTreeNode *work;
2714 work = GTK_CMCTREE_NODE (clist->row_list);
2715 while (work && work != node)
2717 work = GTK_CMCTREE_NODE_NEXT (work);
2720 if (work && gtk_cmclist_row_is_visible (clist, num) != GTK_VISIBILITY_NONE)
2721 GTK_CMCLIST_GET_CLASS (clist)->draw_row
2722 (clist, NULL, num, GTK_CMCLIST_ROW ((GList *) node));
2726 /* this wrapper simply replaces NULL pixbufs
2727 * with a transparent, 1x1 pixbuf. This works
2728 * around a memory problem deep inside gtk,
2729 * revealed by valgrind.
2731 void gtk_sctree_set_node_info (GtkCMCTree *ctree,
2732 GtkCMCTreeNode *node,
2735 GdkPixbuf *pixbuf_closed,
2736 GdkPixbuf *pixbuf_opened,
2741 gboolean old_expanded;
2742 GtkCMCTreeNode *work;
2744 if (!GTK_IS_CMCTREE (ctree) || !node) return;
2746 old_leaf = GTK_CMCTREE_ROW (node)->is_leaf;
2747 old_expanded = GTK_CMCTREE_ROW (node)->expanded;
2749 if (is_leaf && (work = GTK_CMCTREE_ROW (node)->children) != NULL)
2751 GtkCMCTreeNode *ptr;
2756 work = GTK_CMCTREE_ROW (work)->sibling;
2757 gtk_cmctree_remove_node (ctree, ptr);
2761 sset_node_info (ctree, node, text, spacing, pixbuf_closed,
2762 pixbuf_opened, is_leaf, expanded);
2764 if (!is_leaf && !old_leaf)
2766 GTK_CMCTREE_ROW (node)->expanded = old_expanded;
2767 if (expanded && !old_expanded)
2768 gtk_cmctree_expand (ctree, node);
2769 else if (!expanded && old_expanded)
2770 gtk_cmctree_collapse (ctree, node);
2773 GTK_CMCTREE_ROW (node)->expanded = (is_leaf) ? FALSE : expanded;
2775 stree_draw_node (ctree, node);
2778 static GtkCMCTreeRow *
2779 srow_new (GtkCMCTree *ctree)
2782 GtkCMCTreeRow *ctree_row;
2785 clist = GTK_CMCLIST (ctree);
2786 #if GLIB_CHECK_VERSION(2,10,0)
2787 ctree_row = g_slice_new (GtkCMCTreeRow);
2788 ctree_row->row.cell = g_slice_alloc (sizeof (GtkCMCell) * clist->columns);
2790 ctree_row = g_chunk_new (GtkCMCTreeRow, (GMemChunk *)clist->row_mem_chunk);
2791 ctree_row->row.cell = g_chunk_new (GtkCMCell, (GMemChunk *)clist->cell_mem_chunk);
2793 for (i = 0; i < clist->columns; i++)
2795 ctree_row->row.cell[i].type = GTK_CMCELL_EMPTY;
2796 ctree_row->row.cell[i].vertical = 0;
2797 ctree_row->row.cell[i].horizontal = 0;
2798 ctree_row->row.cell[i].style = NULL;
2801 GTK_CMCELL_PIXTEXT (ctree_row->row.cell[ctree->tree_column])->text = NULL;
2803 ctree_row->row.fg_set = FALSE;
2804 ctree_row->row.bg_set = FALSE;
2805 ctree_row->row.style = NULL;
2806 ctree_row->row.selectable = TRUE;
2807 ctree_row->row.state = GTK_STATE_NORMAL;
2808 ctree_row->row.data = NULL;
2809 ctree_row->row.destroy = NULL;
2811 ctree_row->level = 0;
2812 ctree_row->expanded = FALSE;
2813 ctree_row->parent = NULL;
2814 ctree_row->sibling = NULL;
2815 ctree_row->children = NULL;
2816 ctree_row->pixbuf_closed = NULL;
2817 ctree_row->pixbuf_opened = NULL;
2823 srow_delete (GtkCMCTree *ctree,
2824 GtkCMCTreeRow *ctree_row)
2829 clist = GTK_CMCLIST (ctree);
2831 for (i = 0; i < clist->columns; i++)
2833 GTK_CMCLIST_GET_CLASS (clist)->set_cell_contents
2834 (clist, &(ctree_row->row), i, GTK_CMCELL_EMPTY, NULL, 0, NULL);
2835 if (ctree_row->row.cell[i].style)
2837 if (gtkut_widget_get_realized (GTK_WIDGET(ctree)))
2838 gtk_style_detach (ctree_row->row.cell[i].style);
2839 g_object_unref (ctree_row->row.cell[i].style);
2843 if (ctree_row->row.style)
2845 if (gtkut_widget_get_realized (GTK_WIDGET(ctree)))
2846 gtk_style_detach (ctree_row->row.style);
2847 g_object_unref (ctree_row->row.style);
2850 if (ctree_row->pixbuf_closed)
2852 g_object_unref (ctree_row->pixbuf_closed);
2855 if (ctree_row->pixbuf_opened)
2857 g_object_unref (ctree_row->pixbuf_opened);
2860 if (ctree_row->row.destroy)
2862 GDestroyNotify dnotify = ctree_row->row.destroy;
2863 gpointer ddata = ctree_row->row.data;
2865 ctree_row->row.destroy = NULL;
2866 ctree_row->row.data = NULL;
2871 #if GLIB_CHECK_VERSION(2,10,0)
2872 g_slice_free1 (sizeof (GtkCMCell) * clist->columns, ctree_row->row.cell);
2873 g_slice_free (GtkCMCTreeRow, ctree_row);
2875 g_mem_chunk_free ((GMemChunk *)clist->cell_mem_chunk, ctree_row->row.cell);
2876 g_mem_chunk_free ((GMemChunk *)clist->row_mem_chunk, ctree_row);
2881 stree_delete_row (GtkCMCTree *ctree,
2882 GtkCMCTreeNode *node,
2885 srow_delete (ctree, GTK_CMCTREE_ROW (node));
2886 g_list_free_1 ((GList *)node);
2890 gtk_sctree_real_tree_expand (GtkCMCTree *ctree,
2891 GtkCMCTreeNode *node)
2894 GtkCMCTreeNode *work;
2895 GtkRequisition requisition;
2899 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2901 if (!node || GTK_CMCTREE_ROW (node)->expanded || GTK_CMCTREE_ROW (node)->is_leaf)
2904 clist = GTK_CMCLIST (ctree);
2906 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2908 GTK_CMCTREE_ROW (node)->expanded = TRUE;
2909 level = GTK_CMCTREE_ROW (node)->level;
2911 visible = gtk_cmctree_is_viewable (ctree, node);
2912 /* get cell width if tree_column is auto resized */
2913 if (visible && clist->column[ctree->tree_column].auto_resize &&
2914 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2915 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2916 (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column, &requisition);
2918 /* unref/unset closed pixbuf */
2919 if (GTK_CMCELL_PIXTEXT
2920 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf)
2924 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf);
2927 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf = NULL;
2930 /* set/ref opened pixbuf */
2931 if (GTK_CMCTREE_ROW (node)->pixbuf_opened)
2934 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf =
2935 g_object_ref (GTK_CMCTREE_ROW (node)->pixbuf_opened);
2939 work = GTK_CMCTREE_ROW (node)->children;
2942 GList *list = (GList *)work;
2943 gint *cell_width = NULL;
2948 if (visible && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2950 cell_width = g_new0 (gint, clist->columns);
2951 if (clist->column[ctree->tree_column].auto_resize)
2952 cell_width[ctree->tree_column] = requisition.width;
2956 /* search maximum cell widths of auto_resize columns */
2957 for (i = 0; i < clist->columns; i++)
2958 if (clist->column[i].auto_resize)
2960 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2961 (clist, >K_CMCTREE_ROW (work)->row, i, &requisition);
2962 cell_width[i] = MAX (requisition.width, cell_width[i]);
2965 list = (GList *)work;
2966 work = GTK_CMCTREE_NODE_NEXT (work);
2973 list = (GList *)work;
2974 work = GTK_CMCTREE_NODE_NEXT (work);
2978 list->next = (GList *)GTK_CMCTREE_NODE_NEXT (node);
2980 if (GTK_CMCTREE_NODE_NEXT (node))
2984 if (clist->row_list_end == list)
2985 clist->row_list_end = g_list_last(list);
2987 tmp_list = (GList *)GTK_CMCTREE_NODE_NEXT (node);
2988 tmp_list->prev = list;
2991 clist->row_list_end = list;
2993 list = (GList *)node;
2994 list->next = (GList *)(GTK_CMCTREE_ROW (node)->children);
2996 if (visible && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2998 /* resize auto_resize columns if needed */
2999 for (i = 0; i < clist->columns; i++)
3000 if (clist->column[i].auto_resize &&
3001 cell_width[i] > clist->column[i].width)
3002 gtk_cmclist_set_column_width (clist, i, cell_width[i]);
3003 g_free (cell_width);
3005 if (!GTK_SCTREE(ctree)->sorting) {
3006 /* update focus_row position */
3007 row = g_list_position (clist->row_list, (GList *)node);
3008 if (row < clist->focus_row)
3009 clist->focus_row += tmp;
3012 CLIST_REFRESH (clist);
3015 else if (visible && clist->column[ctree->tree_column].auto_resize)
3016 /* resize tree_column if needed */
3017 gtk_sctree_column_auto_resize (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column,
3023 gtk_sctree_insert_node (GtkCMCTree *ctree,
3024 GtkCMCTreeNode *parent,
3025 GtkCMCTreeNode *sibling,
3028 GdkPixbuf *pixbuf_closed,
3029 GdkPixbuf *pixbuf_opened,
3034 GtkCMCTreeRow *new_row;
3035 GtkCMCTreeNode *node;
3039 cm_return_val_if_fail (GTK_IS_CMCTREE (ctree), NULL);
3041 cm_return_val_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent, NULL);
3043 if (parent && GTK_CMCTREE_ROW (parent)->is_leaf)
3046 clist = GTK_CMCLIST (ctree);
3048 /* create the row */
3049 new_row = srow_new (ctree);
3050 list = g_list_alloc ();
3051 list->data = new_row;
3052 node = GTK_CMCTREE_NODE (list);
3055 for (i = 0; i < clist->columns; i++)
3056 if (text[i] && i != ctree->tree_column)
3057 GTK_CMCLIST_GET_CLASS (clist)->set_cell_contents
3058 (clist, &(new_row->row), i, GTK_CMCELL_TEXT, text[i], 0, NULL);
3060 sset_node_info (ctree, node, text ?
3061 text[ctree->tree_column] : NULL, spacing, pixbuf_closed,
3062 pixbuf_opened, is_leaf, expanded);
3064 /* sorted insertion */
3065 if (GTK_CMCLIST_AUTO_SORT (clist))
3068 sibling = GTK_CMCTREE_ROW (parent)->children;
3070 sibling = GTK_CMCTREE_NODE (clist->row_list);
3072 while (sibling && clist->compare
3073 (clist, GTK_CMCTREE_ROW (node), GTK_CMCTREE_ROW (sibling)) > 0)
3074 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
3077 gtk_sctree_link (ctree, node, parent, sibling, FALSE);
3079 if (text && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist) &&
3080 gtk_cmctree_is_viewable (ctree, node))
3082 for (i = 0; i < clist->columns; i++)
3083 if (clist->column[i].auto_resize)
3084 gtk_sctree_column_auto_resize (clist, &(new_row->row), i, 0);
3087 if (clist->rows == 1)
3089 clist->focus_row = 0;
3090 if (clist->selection_mode == GTK_SELECTION_BROWSE)
3091 gtk_sctree_select (GTK_SCTREE(ctree), node);
3095 CLIST_REFRESH (clist);
3101 gtk_sctree_insert_gnode (GtkCMCTree *ctree,
3102 GtkCMCTreeNode *parent,
3103 GtkCMCTreeNode *sibling,
3105 GtkCMCTreeGNodeFunc func,
3109 GtkCMCTreeNode *cnode = NULL;
3110 GtkCMCTreeNode *child = NULL;
3111 GtkCMCTreeNode *new_child;
3116 cm_return_val_if_fail (GTK_IS_CMCTREE (ctree), NULL);
3117 cm_return_val_if_fail (gnode != NULL, NULL);
3118 cm_return_val_if_fail (func != NULL, NULL);
3120 cm_return_val_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent, NULL);
3122 clist = GTK_CMCLIST (ctree);
3125 depth = GTK_CMCTREE_ROW (parent)->level + 1;
3127 list = g_list_alloc ();
3128 list->data = srow_new (ctree);
3129 cnode = GTK_CMCTREE_NODE (list);
3131 gtk_cmclist_freeze (clist);
3133 sset_node_info (ctree, cnode, "", 0, NULL, NULL, TRUE, FALSE);
3135 if (!func (ctree, depth, gnode, cnode, data))
3137 stree_delete_row (ctree, cnode, NULL);
3138 gtk_cmclist_thaw (clist);
3142 if (GTK_CMCLIST_AUTO_SORT (clist))
3145 sibling = GTK_CMCTREE_ROW (parent)->children;
3147 sibling = GTK_CMCTREE_NODE (clist->row_list);
3149 while (sibling && clist->compare
3150 (clist, GTK_CMCTREE_ROW (cnode), GTK_CMCTREE_ROW (sibling)) > 0)
3151 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
3154 gtk_sctree_link (ctree, cnode, parent, sibling, FALSE);
3156 for (work = g_node_last_child (gnode); work; work = work->prev)
3158 new_child = gtk_sctree_insert_gnode (ctree, cnode, child,
3164 gtk_cmclist_thaw (clist);
3170 sreal_tree_move (GtkCMCTree *ctree,
3171 GtkCMCTreeNode *node,
3172 GtkCMCTreeNode *new_parent,
3173 GtkCMCTreeNode *new_sibling)
3176 GtkCMCTreeNode *work;
3177 gboolean visible = FALSE;
3179 cm_return_if_fail (ctree != NULL);
3180 cm_return_if_fail (node != NULL);
3181 cm_return_if_fail (!new_sibling ||
3182 GTK_CMCTREE_ROW (new_sibling)->parent == new_parent);
3184 if (new_parent && GTK_CMCTREE_ROW (new_parent)->is_leaf)
3187 /* new_parent != child of child */
3188 for (work = new_parent; work; work = GTK_CMCTREE_ROW (work)->parent)
3192 clist = GTK_CMCLIST (ctree);
3194 visible = gtk_cmctree_is_viewable (ctree, node);
3196 if (clist->selection_mode == GTK_SELECTION_MULTIPLE)
3198 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
3200 g_list_free (clist->undo_selection);
3201 g_list_free (clist->undo_unselection);
3202 clist->undo_selection = NULL;
3203 clist->undo_unselection = NULL;
3206 if (GTK_CMCLIST_AUTO_SORT (clist))
3208 if (new_parent == GTK_CMCTREE_ROW (node)->parent)
3212 new_sibling = GTK_CMCTREE_ROW (new_parent)->children;
3214 new_sibling = GTK_CMCTREE_NODE (clist->row_list);
3216 while (new_sibling && clist->compare
3217 (clist, GTK_CMCTREE_ROW (node), GTK_CMCTREE_ROW (new_sibling)) > 0)
3218 new_sibling = GTK_CMCTREE_ROW (new_sibling)->sibling;
3221 if (new_parent == GTK_CMCTREE_ROW (node)->parent &&
3222 new_sibling == GTK_CMCTREE_ROW (node)->sibling)
3225 gtk_cmclist_freeze (clist);
3229 if (!GTK_SCTREE(ctree)->sorting && gtk_cmctree_is_viewable (ctree, node))
3230 work = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
3232 gtk_sctree_unlink (ctree, node, FALSE);
3233 gtk_sctree_link (ctree, node, new_parent, new_sibling, FALSE);
3235 if (!GTK_SCTREE(ctree)->sorting && work)
3237 while (work && !gtk_cmctree_is_viewable (ctree, work))
3238 work = GTK_CMCTREE_ROW (work)->parent;
3239 clist->focus_row = g_list_position (clist->row_list, (GList *)work);
3240 clist->undo_anchor = clist->focus_row;
3243 if (clist->column[ctree->tree_column].auto_resize &&
3244 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist) &&
3245 (visible || gtk_cmctree_is_viewable (ctree, node)))
3246 gtk_cmclist_set_column_width
3247 (clist, ctree->tree_column,
3248 gtk_cmclist_optimal_column_width (clist, ctree->tree_column));
3250 gtk_cmclist_thaw (clist);
3253 void gtk_sctree_set_column_tooltip (GtkSCTree *sctree,
3257 #if !(GTK_CHECK_VERSION(2,12,0))
3259 if (!sctree->tooltips)
3260 sctree->tooltips = gtk_tooltips_new();
3261 tips = sctree->tooltips;
3264 CLAWS_SET_TIP(GTK_CMCLIST(sctree)->column[column].button,