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"
36 #define CLIST_UNFROZEN(clist) (((GtkCMCList*) (clist))->freeze_count == 0)
37 #define CLIST_REFRESH(clist) G_STMT_START { \
38 if (CLIST_UNFROZEN (clist)) \
39 GTK_CMCLIST_GET_CLASS (clist)->refresh ((GtkCMCList*) (clist)); \
41 #define CELL_SPACING 1
42 #define CLIST_OPTIMUM_SIZE 64
43 #define COLUMN_INSET 3
45 #define TAB_SIZE (PM_SIZE + 6)
46 #define ROW_TOP_YPIXEL(clist, row) (((clist)->row_height * (row)) + \
47 (((row) + 1) * CELL_SPACING) + \
49 #define ROW_FROM_YPIXEL(clist, y) (((y) - (clist)->voffset) / \
50 ((clist)->row_height + CELL_SPACING))
51 #define COLUMN_LEFT_XPIXEL(clist, col) ((clist)->column[(col)].area.x \
53 #define COLUMN_LEFT(clist, column) ((clist)->column[(column)].area.x)
63 static void gtk_sctree_class_init (GtkSCTreeClass *class);
64 static void gtk_sctree_init (GtkSCTree *sctree);
66 static gint gtk_sctree_button_press (GtkWidget *widget, GdkEventButton *event);
67 static gint gtk_sctree_button_release (GtkWidget *widget, GdkEventButton *event);
68 static gint gtk_sctree_motion (GtkWidget *widget, GdkEventMotion *event);
69 static void gtk_sctree_drag_begin (GtkWidget *widget, GdkDragContext *context);
70 static void gtk_sctree_drag_end (GtkWidget *widget, GdkDragContext *context);
71 static void gtk_sctree_drag_data_get (GtkWidget *widget, GdkDragContext *context,
72 GtkSelectionData *data, guint info, guint time);
73 static void gtk_sctree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time);
74 static gboolean gtk_sctree_drag_motion (GtkWidget *widget, GdkDragContext *context,
75 gint x, gint y, guint time);
76 static gboolean gtk_sctree_drag_drop (GtkWidget *widget, GdkDragContext *context,
77 gint x, gint y, guint time);
78 static void gtk_sctree_drag_data_received (GtkWidget *widget, GdkDragContext *context,
79 gint x, gint y, GtkSelectionData *data,
80 guint info, guint time);
82 static void gtk_sctree_clear (GtkCMCList *clist);
83 static void gtk_sctree_real_unselect_all (GtkCMCList *clist);
85 static void stree_sort (GtkCMCTree *ctree, GtkCMCTreeNode *node, gpointer data);
86 void gtk_sctree_sort_node (GtkCMCTree *ctree, GtkCMCTreeNode *node);
87 void gtk_sctree_sort_recursive (GtkCMCTree *ctree, GtkCMCTreeNode *node);
89 static void gtk_sctree_link (GtkCMCTree *ctree,
91 GtkCMCTreeNode *parent,
92 GtkCMCTreeNode *sibling,
93 gboolean update_focus_row);
95 static void gtk_sctree_unlink (GtkCMCTree *ctree,
97 gboolean update_focus_row);
99 static void stree_update_level (GtkCMCTree *ctree,
100 GtkCMCTreeNode *node,
103 static GtkCMCTreeNode * gtk_sctree_last_visible (GtkCMCTree *ctree,
104 GtkCMCTreeNode *node);
105 static void gtk_sctree_real_tree_expand (GtkCMCTree *ctree,
106 GtkCMCTreeNode *node);
107 static void gtk_sctree_real_tree_collapse (GtkCMCTree *ctree,
108 GtkCMCTreeNode *node);
110 sreal_tree_move (GtkCMCTree *ctree,
111 GtkCMCTreeNode *node,
112 GtkCMCTreeNode *new_parent,
113 GtkCMCTreeNode *new_sibling);
115 static GtkCMCTreeClass *parent_class;
117 static guint sctree_signals[LAST_SIGNAL];
120 * gtk_sctree_get_type:
123 * Creates the GtkSCTree class and its type information
125 * Return value: The type ID for GtkSCTreeClass
128 gtk_sctree_get_type (void)
130 static GType sctree_type = 0;
133 GTypeInfo sctree_info = {
134 sizeof (GtkSCTreeClass),
136 (GBaseInitFunc) NULL,
137 (GBaseFinalizeFunc) NULL,
139 (GClassInitFunc) gtk_sctree_class_init,
140 (GClassFinalizeFunc) NULL,
141 NULL, /* class_data */
145 (GInstanceInitFunc) gtk_sctree_init,
148 sctree_type = g_type_register_static (GTK_TYPE_CMCTREE, "GtkSCTree", &sctree_info, (GTypeFlags)0);
155 gtk_sctree_draw_cell_pixbuf (GdkWindow *window,
156 GdkRectangle *clip_rectangle,
167 gdk_gc_set_clip_origin (fg_gc, x, y);
168 if (x < clip_rectangle->x)
170 xsrc = clip_rectangle->x - x;
172 x = clip_rectangle->x;
174 if (x + width > clip_rectangle->x + clip_rectangle->width)
175 width = clip_rectangle->x + clip_rectangle->width - x;
177 if (y < clip_rectangle->y)
179 ysrc = clip_rectangle->y - y;
181 y = clip_rectangle->y;
183 if (y + height > clip_rectangle->y + clip_rectangle->height)
184 height = clip_rectangle->y + clip_rectangle->height - y;
186 if (width > 0 && height > 0)
187 gdk_draw_pixbuf (window, fg_gc, pixbuf, xsrc, ysrc, x, y, width, height, GDK_RGB_DITHER_NONE, 0, 0);
189 gdk_gc_set_clip_origin (fg_gc, 0, 0);
191 return x + MAX (width, 0);
195 gtk_sctree_get_cell_style (GtkCMCList *clist,
196 GtkCMCListRow *clist_row,
206 if ((state == GTK_STATE_NORMAL) &&
207 (GTK_WIDGET (clist)->state == GTK_STATE_INSENSITIVE))
208 fg_state = GTK_STATE_INSENSITIVE;
212 if (clist_row->cell[column].style)
215 *style = clist_row->cell[column].style;
217 *fg_gc = clist_row->cell[column].style->fg_gc[fg_state];
219 if (state == GTK_STATE_SELECTED)
220 *bg_gc = clist_row->cell[column].style->bg_gc[state];
223 else if (clist_row->style)
226 *style = clist_row->style;
228 *fg_gc = clist_row->style->fg_gc[fg_state];
230 if (state == GTK_STATE_SELECTED)
231 *bg_gc = clist_row->style->bg_gc[state];
233 *bg_gc = clist_row->bg_set ?
234 clist->bg_gc : clist_row->style->base_gc[state];
240 *style = GTK_WIDGET (clist)->style;
242 *fg_gc = GTK_WIDGET (clist)->style->fg_gc[fg_state];
244 if (state == GTK_STATE_SELECTED)
245 *bg_gc = GTK_WIDGET (clist)->style->bg_gc[state];
247 *bg_gc = GTK_WIDGET (clist)->style->base_gc[state];
250 if (state != GTK_STATE_SELECTED)
252 if (fg_gc && clist_row->fg_set)
253 *fg_gc = clist->fg_gc;
254 if (bg_gc && clist_row->bg_set)
255 *bg_gc = clist->bg_gc;
261 gtk_sctree_draw_expander (GtkCMCTree *ctree,
262 GtkCMCTreeRow *ctree_row,
264 GdkRectangle *clip_rectangle,
269 gint justification_factor;
272 if (ctree->expander_style == GTK_CMCTREE_EXPANDER_NONE)
275 clist = GTK_CMCLIST (ctree);
276 if (clist->column[ctree->tree_column].justification == GTK_JUSTIFY_RIGHT)
277 justification_factor = -1;
279 justification_factor = 1;
280 if (!GTK_CMCLIST_ROW_HEIGHT_SET(GTK_CMCLIST(clist)))
281 y = (clip_rectangle->y + (clip_rectangle->height - PM_SIZE) / 2 -
282 (clip_rectangle->height + 1) % 2);
284 y = (clip_rectangle->y + (clip_rectangle->height/2 - PM_SIZE) / 2 -
285 (clip_rectangle->height/2 + 1) % 2);
287 if (!ctree_row->children)
289 switch (ctree->expander_style)
291 case GTK_CMCTREE_EXPANDER_NONE:
293 case GTK_CMCTREE_EXPANDER_TRIANGLE:
294 return x + justification_factor * (PM_SIZE + 3);
295 case GTK_CMCTREE_EXPANDER_SQUARE:
296 case GTK_CMCTREE_EXPANDER_CIRCULAR:
297 return x + justification_factor * (PM_SIZE + 1);
301 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], clip_rectangle);
302 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], clip_rectangle);
304 switch (ctree->expander_style)
306 case GTK_CMCTREE_EXPANDER_NONE:
308 case GTK_CMCTREE_EXPANDER_TRIANGLE:
309 if (ctree_row->expanded)
312 points[0].y = y + (PM_SIZE + 2) / 6;
313 points[1].x = points[0].x + justification_factor * (PM_SIZE + 2);
314 points[1].y = points[0].y;
315 points[2].x = (points[0].x +
316 justification_factor * (PM_SIZE + 2) / 2);
317 points[2].y = y + 2 * (PM_SIZE + 2) / 3;
321 points[0].x = x + justification_factor * ((PM_SIZE + 2) / 6 + 2);
323 points[1].x = points[0].x;
324 points[1].y = points[0].y + (PM_SIZE + 2);
325 points[2].x = (points[0].x +
326 justification_factor * (2 * (PM_SIZE + 2) / 3 - 1));
327 points[2].y = points[0].y + (PM_SIZE + 2) / 2;
330 gdk_draw_polygon (clist->clist_window, style->base_gc[GTK_STATE_NORMAL],
332 gdk_draw_polygon (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
335 x += justification_factor * (PM_SIZE + 3);
337 case GTK_CMCTREE_EXPANDER_SQUARE:
338 case GTK_CMCTREE_EXPANDER_CIRCULAR:
339 if (justification_factor == -1)
340 x += justification_factor * (PM_SIZE + 1);
342 if (ctree->expander_style == GTK_CMCTREE_EXPANDER_CIRCULAR)
344 gdk_draw_arc (clist->clist_window, style->base_gc[GTK_STATE_NORMAL],
345 TRUE, x, y, PM_SIZE, PM_SIZE, 0, 360 * 64);
346 gdk_draw_arc (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
347 FALSE, x, y, PM_SIZE, PM_SIZE, 0, 360 * 64);
351 gdk_draw_rectangle (clist->clist_window,
352 style->base_gc[GTK_STATE_NORMAL], TRUE,
353 x, y, PM_SIZE, PM_SIZE);
354 gdk_draw_rectangle (clist->clist_window,
355 style->fg_gc[GTK_STATE_NORMAL], FALSE,
356 x, y, PM_SIZE, PM_SIZE);
359 gdk_draw_line (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
360 x + 2, y + PM_SIZE / 2, x + PM_SIZE - 2, y + PM_SIZE / 2);
362 if (!ctree_row->expanded)
363 gdk_draw_line (clist->clist_window, style->fg_gc[GTK_STATE_NORMAL],
364 x + PM_SIZE / 2, y + 2,
365 x + PM_SIZE / 2, y + PM_SIZE - 2);
367 if (justification_factor == 1)
368 x += justification_factor * (PM_SIZE + 1);
372 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
373 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
379 gtk_sctree_draw_lines (GtkCMCTree *ctree,
380 GtkCMCTreeRow *ctree_row,
384 GdkRectangle *clip_rectangle,
385 GdkRectangle *cell_rectangle,
391 GtkCMCTreeNode *node;
392 GtkCMCTreeNode *parent;
393 GdkRectangle tree_rectangle;
394 GdkRectangle tc_rectangle;
405 gint justification_factor;
407 clist = GTK_CMCLIST (ctree);
408 ycenter = clip_rectangle->y + (clip_rectangle->height / 2);
409 justify_right = (clist->column[column].justification == GTK_JUSTIFY_RIGHT);
413 offset = (clip_rectangle->x + clip_rectangle->width - 1 -
414 ctree->tree_indent * (ctree_row->level - 1));
415 justification_factor = -1;
419 offset = clip_rectangle->x + ctree->tree_indent * (ctree_row->level - 1);
420 justification_factor = 1;
423 switch (ctree->line_style)
425 case GTK_CMCTREE_LINES_NONE:
427 case GTK_CMCTREE_LINES_TABBED:
428 xcenter = offset + justification_factor * TAB_SIZE;
430 column_right = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) +
431 clist->column[ctree->tree_column].area.width +
433 column_left = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) -
434 COLUMN_INSET - CELL_SPACING);
438 tree_rectangle.y = crect->y;
439 tree_rectangle.height = crect->height;
443 tree_rectangle.x = xcenter;
444 tree_rectangle.width = column_right - xcenter;
448 tree_rectangle.x = column_left;
449 tree_rectangle.width = xcenter - column_left;
452 if (!gdk_rectangle_intersect (area, &tree_rectangle, &tc_rectangle))
454 offset += justification_factor * 3;
459 gdk_gc_set_clip_rectangle (ctree->lines_gc, crect);
461 next_level = ctree_row->level;
463 if (!ctree_row->sibling || (ctree_row->children && ctree_row->expanded))
465 node = gtk_cmctree_find_node_ptr (ctree, ctree_row);
466 if (GTK_CMCTREE_NODE_NEXT (node))
467 next_level = GTK_CMCTREE_ROW (GTK_CMCTREE_NODE_NEXT (node))->level;
472 if (ctree->tree_indent > 0)
474 node = ctree_row->parent;
477 xcenter -= (justification_factor * ctree->tree_indent);
479 if ((justify_right && xcenter < column_left) ||
480 (!justify_right && xcenter > column_right))
482 node = GTK_CMCTREE_ROW (node)->parent;
486 tree_rectangle.y = cell_rectangle->y;
487 tree_rectangle.height = cell_rectangle->height;
490 tree_rectangle.x = MAX (xcenter - ctree->tree_indent + 1,
492 tree_rectangle.width = MIN (xcenter - column_left,
497 tree_rectangle.x = xcenter;
498 tree_rectangle.width = MIN (column_right - xcenter,
502 if (!area || gdk_rectangle_intersect (area, &tree_rectangle,
505 gtk_sctree_get_cell_style (clist, >K_CMCTREE_ROW (node)->row,
506 state, row, column, NULL, NULL, &bg_gc);
508 if (bg_gc == clist->bg_gc)
509 gdk_gc_set_foreground
510 (clist->bg_gc, >K_CMCTREE_ROW (node)->row.background);
513 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
516 tree_rectangle.width,
517 tree_rectangle.height);
519 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
523 tc_rectangle.height);
525 if (next_level > GTK_CMCTREE_ROW (node)->level)
526 gdk_draw_line (clist->clist_window, ctree->lines_gc,
528 xcenter, crect->y + crect->height);
533 offset_x = MIN (ctree->tree_indent, 2 * TAB_SIZE);
534 width = offset_x / 2 + offset_x % 2;
536 parent = GTK_CMCTREE_ROW (node)->parent;
538 tree_rectangle.y = ycenter;
539 tree_rectangle.height = (cell_rectangle->y - ycenter +
540 cell_rectangle->height);
544 tree_rectangle.x = MAX(xcenter + 1 - width, column_left);
545 tree_rectangle.width = MIN (xcenter + 1 - column_left,
550 tree_rectangle.x = xcenter;
551 tree_rectangle.width = MIN (column_right - xcenter,
556 gdk_rectangle_intersect (area, &tree_rectangle,
561 gtk_sctree_get_cell_style (clist, >K_CMCTREE_ROW (parent)->row,
562 state, row, column, NULL, NULL, &bg_gc);
563 if (bg_gc == clist->bg_gc)
564 gdk_gc_set_foreground
566 >K_CMCTREE_ROW (parent)->row.background);
568 else if (state == GTK_STATE_SELECTED)
569 bg_gc = style->base_gc[state];
571 bg_gc = GTK_WIDGET (clist)->style->base_gc[state];
574 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
577 tree_rectangle.width,
578 tree_rectangle.height);
580 gdk_draw_rectangle (clist->clist_window,
585 tc_rectangle.height);
588 gtk_sctree_get_cell_style (clist, >K_CMCTREE_ROW (node)->row,
589 state, row, column, NULL, NULL, &bg_gc);
590 if (bg_gc == clist->bg_gc)
591 gdk_gc_set_foreground
592 (clist->bg_gc, >K_CMCTREE_ROW (node)->row.background);
594 gdk_gc_set_clip_rectangle (bg_gc, crect);
595 gdk_draw_arc (clist->clist_window, bg_gc, TRUE,
596 xcenter - (justify_right * offset_x),
598 offset_x, clist->row_height,
599 (180 + (justify_right * 90)) * 64, 90 * 64);
600 gdk_gc_set_clip_rectangle (bg_gc, NULL);
602 gdk_draw_line (clist->clist_window, ctree->lines_gc,
603 xcenter, cell_rectangle->y, xcenter, ycenter);
606 gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
607 xcenter - offset_x, cell_rectangle->y,
608 offset_x, clist->row_height,
611 gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
612 xcenter, cell_rectangle->y,
613 offset_x, clist->row_height,
616 node = GTK_CMCTREE_ROW (node)->parent;
620 if (state != GTK_STATE_SELECTED)
622 tree_rectangle.y = clip_rectangle->y;
623 tree_rectangle.height = clip_rectangle->height;
624 tree_rectangle.width = COLUMN_INSET + CELL_SPACING +
625 MIN (clist->column[ctree->tree_column].area.width + COLUMN_INSET,
629 tree_rectangle.x = MAX (xcenter + 1, column_left);
631 tree_rectangle.x = column_left;
634 gdk_draw_rectangle (clist->clist_window,
636 (ctree)->style->base_gc[GTK_STATE_NORMAL],
640 tree_rectangle.width,
641 tree_rectangle.height);
642 else if (gdk_rectangle_intersect (area, &tree_rectangle,
644 gdk_draw_rectangle (clist->clist_window,
646 (ctree)->style->base_gc[GTK_STATE_NORMAL],
651 tc_rectangle.height);
654 xcenter = offset + (justification_factor * ctree->tree_indent / 2);
656 gtk_sctree_get_cell_style (clist, &ctree_row->row, state, row, column, NULL, NULL,
658 if (bg_gc == clist->bg_gc)
659 gdk_gc_set_foreground (clist->bg_gc, &ctree_row->row.background);
661 gdk_gc_set_clip_rectangle (bg_gc, crect);
662 if (ctree_row->is_leaf)
666 points[0].x = offset + justification_factor * TAB_SIZE;
667 points[0].y = cell_rectangle->y;
669 points[1].x = points[0].x - justification_factor * 4;
670 points[1].y = points[0].y;
672 points[2].x = points[1].x - justification_factor * 2;
673 points[2].y = points[1].y + 3;
675 points[3].x = points[2].x;
676 points[3].y = points[2].y + clist->row_height - 5;
678 points[4].x = points[3].x + justification_factor * 2;
679 points[4].y = points[3].y + 3;
681 points[5].x = points[4].x + justification_factor * 4;
682 points[5].y = points[4].y;
684 gdk_draw_polygon (clist->clist_window, bg_gc, TRUE, points, 6);
685 gdk_draw_lines (clist->clist_window, ctree->lines_gc, points, 6);
689 gdk_draw_arc (clist->clist_window, bg_gc, TRUE,
690 offset - (justify_right * 2 * TAB_SIZE),
692 2 * TAB_SIZE, clist->row_height,
693 (90 + (180 * justify_right)) * 64, 180 * 64);
694 gdk_draw_arc (clist->clist_window, ctree->lines_gc, FALSE,
695 offset - (justify_right * 2 * TAB_SIZE),
697 2 * TAB_SIZE, clist->row_height,
698 (90 + (180 * justify_right)) * 64, 180 * 64);
700 gdk_gc_set_clip_rectangle (bg_gc, NULL);
701 gdk_gc_set_clip_rectangle (ctree->lines_gc, NULL);
703 offset += justification_factor * 3;
706 xcenter = offset + justification_factor * PM_SIZE / 2;
710 tree_rectangle.y = crect->y;
711 tree_rectangle.height = crect->height;
715 tree_rectangle.x = xcenter - PM_SIZE / 2 - 2;
716 tree_rectangle.width = (clip_rectangle->x +
717 clip_rectangle->width -tree_rectangle.x);
721 tree_rectangle.x = clip_rectangle->x + PM_SIZE / 2;
722 tree_rectangle.width = (xcenter + PM_SIZE / 2 + 2 -
726 if (!gdk_rectangle_intersect (area, &tree_rectangle, &tc_rectangle))
732 if (ctree->line_style == GTK_CMCTREE_LINES_DOTTED)
734 offset_x += abs((clip_rectangle->x + clist->hoffset) % 2);
735 offset_y = abs((cell_rectangle->y + clist->voffset) % 2);
739 clip_rectangle->height++;
740 gdk_gc_set_clip_rectangle (ctree->lines_gc, clip_rectangle);
741 gdk_draw_line (clist->clist_window, ctree->lines_gc,
743 (ctree->show_stub || clist->row_list->data != ctree_row) ?
744 cell_rectangle->y + offset_y : ycenter,
746 (ctree_row->sibling) ? crect->y +crect->height : ycenter);
748 gdk_draw_line (clist->clist_window, ctree->lines_gc,
749 xcenter + (justification_factor * offset_x), ycenter,
750 xcenter + (justification_factor * (PM_SIZE / 2 + 2)),
753 node = ctree_row->parent;
756 xcenter -= (justification_factor * ctree->tree_indent);
758 if (GTK_CMCTREE_ROW (node)->sibling)
759 gdk_draw_line (clist->clist_window, ctree->lines_gc,
760 xcenter, cell_rectangle->y + offset_y,
761 xcenter, crect->y + crect->height);
762 node = GTK_CMCTREE_ROW (node)->parent;
764 gdk_gc_set_clip_rectangle (ctree->lines_gc, NULL);
766 clip_rectangle->height--;
772 static gboolean filter_fg (PangoAttribute *attribute, gpointer data)
774 const PangoAttrClass *klass = attribute->klass;
775 if (klass->type == PANGO_ATTR_FOREGROUND)
782 sc_gtk_cmclist_create_cell_layout (GtkCMCList *clist,
783 GtkCMCListRow *clist_row,
791 gtk_sctree_get_cell_style (clist, clist_row, GTK_STATE_NORMAL, 0, column, &style,
795 cell = &clist_row->cell[column];
798 case GTK_CMCELL_TEXT:
799 case GTK_CMCELL_PIXTEXT:
800 text = ((cell->type == GTK_CMCELL_PIXTEXT) ?
801 GTK_CMCELL_PIXTEXT (*cell)->text :
802 GTK_CMCELL_TEXT (*cell)->text);
807 if (!GTK_SCTREE(clist)->use_markup[column]) {
808 layout = gtk_widget_create_pango_layout (GTK_WIDGET (clist),
809 ((cell->type == GTK_CMCELL_PIXTEXT) ?
810 GTK_CMCELL_PIXTEXT (*cell)->text :
811 GTK_CMCELL_TEXT (*cell)->text));
812 pango_layout_set_font_description (layout, style->font_desc);
814 PangoContext *context = gtk_widget_get_pango_context (GTK_WIDGET(clist));
815 layout = pango_layout_new (context);
816 pango_layout_set_markup (layout, text, -1);
817 pango_layout_set_font_description (layout, style->font_desc);
818 if (clist_row->state == GTK_STATE_SELECTED) {
819 /* for selected row, we should remove any forced foreground color
820 * or it looks like shit */
821 PangoAttrList *list = pango_layout_get_attributes(layout);
822 PangoAttrList *rem = pango_attr_list_filter(list, filter_fg, NULL);
824 pango_attr_list_unref(rem);
836 gtk_sctree_draw_row (GtkCMCList *clist,
839 GtkCMCListRow *clist_row)
845 GdkRectangle row_rectangle;
846 GdkRectangle cell_rectangle;
847 GdkRectangle clip_rectangle;
848 GdkRectangle intersect_rectangle;
850 gint column_left = 0;
851 gint column_right = 0;
855 static GdkColor greybg={0, 0, 0, 0};
856 static gboolean color_change = TRUE;
858 if (greybg.pixel == 0 &&
862 GdkColor normalbg = {0, 0xffff, 0xffff, 0xffff};
863 if (GTK_WIDGET (clist)->style) {
864 normalbg = GTK_WIDGET (clist)->style->base[GTK_STATE_NORMAL];
866 if (normalbg.red > 0x8888 && normalbg.green > 0x8888 && normalbg.blue > 0x8888) {
867 greybg.pixel = normalbg.pixel;
868 greybg.red = normalbg.red - prefs_common.stripes_color_offset;
869 greybg.green = normalbg.green - prefs_common.stripes_color_offset;
870 greybg.blue = normalbg.blue - prefs_common.stripes_color_offset;
871 } else if (normalbg.red < 0x8888 && normalbg.green < 0x8888 && normalbg.blue < 0x8888) {
872 greybg.pixel = normalbg.pixel;
873 greybg.red = normalbg.red + prefs_common.stripes_color_offset;
874 greybg.green = normalbg.green + prefs_common.stripes_color_offset;
875 greybg.blue = normalbg.blue + prefs_common.stripes_color_offset;
877 color_change = FALSE;
881 cm_return_if_fail (clist != NULL);
883 /* bail now if we arn't drawable yet */
884 if (!GTK_WIDGET_DRAWABLE (clist) || row < 0 || row >= clist->rows)
887 widget = GTK_WIDGET (clist);
888 ctree = GTK_CMCTREE (clist);
890 /* if the function is passed the pointer to the row instead of null,
891 * it avoids this expensive lookup */
893 clist_row = (g_list_nth (clist->row_list, row))->data;
895 /* rectangle of the entire row */
897 row_rectangle.y = ROW_TOP_YPIXEL (clist, row);
898 row_rectangle.width = clist->clist_window_width;
899 row_rectangle.height = clist->row_height;
901 /* rectangle of the cell spacing above the row */
902 cell_rectangle.x = 0;
903 cell_rectangle.y = row_rectangle.y - CELL_SPACING;
904 cell_rectangle.width = row_rectangle.width;
905 cell_rectangle.height = CELL_SPACING;
907 /* rectangle used to clip drawing operations, its y and height
908 * positions only need to be set once, so we set them once here.
909 * the x and width are set withing the drawing loop below once per
911 clip_rectangle.y = row_rectangle.y;
912 clip_rectangle.height = row_rectangle.height;
914 if (prefs_common.use_stripes_everywhere && GTK_SCTREE(ctree)->show_stripes
915 && color_change && row % 2) {
916 clist_row->background = greybg;
917 clist_row->bg_set = TRUE;
919 clist_row->bg_set = FALSE;
921 if (clist_row->state == GTK_STATE_NORMAL)
923 if (clist_row->fg_set)
924 gdk_gc_set_foreground (clist->fg_gc, &clist_row->foreground);
925 if (clist_row->bg_set)
926 gdk_gc_set_rgb_fg_color (clist->bg_gc, &clist_row->background);
929 state = clist_row->state;
931 gdk_gc_set_foreground (ctree->lines_gc,
932 &widget->style->fg[clist_row->state]);
934 /* draw the cell borders */
937 rect = &intersect_rectangle;
938 crect = &intersect_rectangle;
940 if (gdk_rectangle_intersect (area, &cell_rectangle, crect))
941 gdk_draw_rectangle (clist->clist_window,
942 widget->style->base_gc[GTK_STATE_NORMAL], TRUE,
943 crect->x, crect->y, crect->width, crect->height);
947 rect = &clip_rectangle;
948 crect = &cell_rectangle;
950 gdk_draw_rectangle (clist->clist_window,
951 widget->style->base_gc[GTK_STATE_NORMAL], TRUE,
952 crect->x, crect->y, crect->width, crect->height);
955 /* horizontal black lines */
956 if (ctree->line_style == GTK_CMCTREE_LINES_TABBED)
959 column_right = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) +
960 clist->column[ctree->tree_column].area.width +
962 column_left = (COLUMN_LEFT_XPIXEL (clist, ctree->tree_column) -
963 COLUMN_INSET - (ctree->tree_column != 0) * CELL_SPACING);
965 switch (clist->column[ctree->tree_column].justification)
967 case GTK_JUSTIFY_CENTER:
968 case GTK_JUSTIFY_FILL:
969 case GTK_JUSTIFY_LEFT:
970 offset = (column_left + ctree->tree_indent *
971 (((GtkCMCTreeRow *)clist_row)->level - 1));
973 gdk_draw_line (clist->clist_window, ctree->lines_gc,
974 MIN (offset + TAB_SIZE, column_right),
976 clist->clist_window_width, cell_rectangle.y);
978 case GTK_JUSTIFY_RIGHT:
979 offset = (column_right - 1 - ctree->tree_indent *
980 (((GtkCMCTreeRow *)clist_row)->level - 1));
982 gdk_draw_line (clist->clist_window, ctree->lines_gc,
983 -1, cell_rectangle.y,
984 MAX (offset - TAB_SIZE, column_left),
990 /* the last row has to clear its bottom cell spacing too */
991 if (clist_row == clist->row_list_end->data)
993 cell_rectangle.y += clist->row_height + CELL_SPACING;
995 if (!area || gdk_rectangle_intersect (area, &cell_rectangle, crect))
997 gdk_draw_rectangle (clist->clist_window,
998 widget->style->base_gc[GTK_STATE_NORMAL], TRUE,
999 crect->x, crect->y, crect->width, crect->height);
1001 /* horizontal black lines */
1002 if (ctree->line_style == GTK_CMCTREE_LINES_TABBED)
1004 switch (clist->column[ctree->tree_column].justification)
1006 case GTK_JUSTIFY_CENTER:
1007 case GTK_JUSTIFY_FILL:
1008 case GTK_JUSTIFY_LEFT:
1009 gdk_draw_line (clist->clist_window, ctree->lines_gc,
1010 MIN (column_left + TAB_SIZE + COLUMN_INSET +
1011 (((GtkCMCTreeRow *)clist_row)->level > 1) *
1012 MIN (ctree->tree_indent / 2, TAB_SIZE),
1015 clist->clist_window_width, cell_rectangle.y);
1017 case GTK_JUSTIFY_RIGHT:
1018 gdk_draw_line (clist->clist_window, ctree->lines_gc,
1019 -1, cell_rectangle.y,
1020 MAX (column_right - TAB_SIZE - 1 -
1022 (((GtkCMCTreeRow *)clist_row)->level > 1) *
1023 MIN (ctree->tree_indent / 2, TAB_SIZE),
1024 column_left - 1), cell_rectangle.y);
1031 for (last_column = clist->columns - 1;
1032 last_column >= 0 && !clist->column[last_column].visible; last_column--)
1035 /* iterate and draw all the columns (row cells) and draw their contents */
1036 for (i = 0; i < clist->columns; i++)
1041 PangoLayout *layout = NULL;
1042 PangoRectangle logical_rect;
1050 if (!clist->column[i].visible)
1053 gtk_sctree_get_cell_style (clist, clist_row, state, row, i, &style, &fg_gc, &bg_gc);
1055 /* calculate clipping region */
1056 clip_rectangle.x = clist->column[i].area.x + clist->hoffset;
1057 clip_rectangle.width = clist->column[i].area.width;
1059 cell_rectangle.x = clip_rectangle.x - COLUMN_INSET - CELL_SPACING;
1060 cell_rectangle.width = (clip_rectangle.width + 2 * COLUMN_INSET +
1061 (1 + (i == last_column)) * CELL_SPACING);
1062 cell_rectangle.y = clip_rectangle.y;
1063 cell_rectangle.height = clip_rectangle.height;
1069 if (area && !gdk_rectangle_intersect (area, &cell_rectangle,
1070 &intersect_rectangle))
1072 if (i != ctree->tree_column)
1077 gdk_draw_rectangle (clist->clist_window, bg_gc, TRUE,
1078 crect->x, crect->y, crect->width, crect->height);
1081 layout = sc_gtk_cmclist_create_cell_layout (clist, clist_row, i);
1084 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1085 width = logical_rect.width;
1090 switch (clist_row->cell[i].type)
1092 case GTK_CMCELL_PIXBUF:
1093 pixbuf_width = gdk_pixbuf_get_width(GTK_CMCELL_PIXBUF (clist_row->cell[i])->pixbuf);
1094 height = gdk_pixbuf_get_height(GTK_CMCELL_PIXBUF (clist_row->cell[i])->pixbuf);
1095 width += pixbuf_width;
1097 case GTK_CMCELL_PIXTEXT:
1098 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf)
1100 pixbuf_width = gdk_pixbuf_get_width(GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf);
1101 height = gdk_pixbuf_get_height(GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf);
1102 width += pixbuf_width;
1105 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->text &&
1106 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf)
1107 width += GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1109 if (i == ctree->tree_column)
1110 width += (ctree->tree_indent *
1111 ((GtkCMCTreeRow *)clist_row)->level);
1117 switch (clist->column[i].justification)
1119 case GTK_JUSTIFY_LEFT:
1120 offset = clip_rectangle.x + clist_row->cell[i].horizontal;
1122 case GTK_JUSTIFY_RIGHT:
1123 offset = (clip_rectangle.x + clist_row->cell[i].horizontal +
1124 clip_rectangle.width - width);
1126 case GTK_JUSTIFY_CENTER:
1127 case GTK_JUSTIFY_FILL:
1128 offset = (clip_rectangle.x + clist_row->cell[i].horizontal +
1129 (clip_rectangle.width / 2) - (width / 2));
1133 if (i != ctree->tree_column)
1135 int start_y = (clip_rectangle.height - height) / 2;
1136 if (GTK_CMCLIST_ROW_HEIGHT_SET(GTK_CMCLIST(clist)))
1137 start_y = (clip_rectangle.height/2 - height) / 2;
1139 offset += clist_row->cell[i].horizontal;
1140 switch (clist_row->cell[i].type)
1142 case GTK_CMCELL_PIXBUF:
1143 gtk_sctree_draw_cell_pixbuf
1144 (clist->clist_window, &clip_rectangle, fg_gc,
1145 GTK_CMCELL_PIXBUF (clist_row->cell[i])->pixbuf,
1147 clip_rectangle.y + clist_row->cell[i].vertical +
1149 pixbuf_width, height);
1151 case GTK_CMCELL_PIXTEXT:
1152 offset = gtk_sctree_draw_cell_pixbuf
1153 (clist->clist_window, &clip_rectangle, fg_gc,
1154 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf,
1156 clip_rectangle.y + clist_row->cell[i].vertical +
1158 pixbuf_width, height);
1159 offset += GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1162 case GTK_CMCELL_TEXT:
1165 gint row_center_offset = (clist->row_height - logical_rect.height) / 2;
1167 gdk_gc_set_clip_rectangle (fg_gc, &clip_rectangle);
1168 gdk_draw_layout (clist->clist_window, fg_gc,
1170 row_rectangle.y + row_center_offset + clist_row->cell[i].vertical,
1172 gdk_gc_set_clip_rectangle (fg_gc, NULL);
1173 g_object_unref (G_OBJECT (layout));
1183 if (bg_gc == clist->bg_gc)
1184 gdk_gc_set_background (ctree->lines_gc, &clist_row->background);
1186 /* draw ctree->tree_column */
1187 cell_rectangle.y -= CELL_SPACING;
1188 cell_rectangle.height += CELL_SPACING;
1190 if (area && !gdk_rectangle_intersect (area, &cell_rectangle,
1191 &intersect_rectangle))
1194 g_object_unref (G_OBJECT (layout));
1199 offset = gtk_sctree_draw_lines (ctree, (GtkCMCTreeRow *)clist_row, row, i,
1200 state, &clip_rectangle, &cell_rectangle,
1201 crect, area, style);
1204 offset = gtk_sctree_draw_expander (ctree, (GtkCMCTreeRow *)clist_row,
1205 style, &clip_rectangle, offset);
1207 if (clist->column[i].justification == GTK_JUSTIFY_RIGHT)
1208 offset -= ctree->tree_spacing;
1210 offset += ctree->tree_spacing;
1212 if (clist->column[i].justification == GTK_JUSTIFY_RIGHT)
1213 offset -= (pixbuf_width + clist_row->cell[i].horizontal);
1215 offset += clist_row->cell[i].horizontal;
1217 old_offset = offset;
1218 offset = gtk_sctree_draw_cell_pixbuf (clist->clist_window, &clip_rectangle, fg_gc,
1219 GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf,
1221 clip_rectangle.y + clist_row->cell[i].vertical
1222 + (clip_rectangle.height - height) / 2,
1223 pixbuf_width, height);
1227 gint row_center_offset = (clist->row_height - logical_rect.height) / 2;
1229 if (clist->column[i].justification == GTK_JUSTIFY_RIGHT)
1231 offset = (old_offset - string_width);
1232 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf)
1233 offset -= GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1237 if (GTK_CMCELL_PIXTEXT (clist_row->cell[i])->pixbuf)
1238 offset += GTK_CMCELL_PIXTEXT (clist_row->cell[i])->spacing;
1241 gdk_gc_set_clip_rectangle (fg_gc, &clip_rectangle);
1242 gdk_draw_layout (clist->clist_window, fg_gc,
1244 row_rectangle.y + row_center_offset + clist_row->cell[i].vertical,
1247 g_object_unref (G_OBJECT (layout));
1249 gdk_gc_set_clip_rectangle (fg_gc, NULL);
1252 /* draw focus rectangle */
1253 if (clist->focus_row == row &&
1254 GTK_WIDGET_CAN_FOCUS (widget) && GTK_WIDGET_HAS_FOCUS (widget))
1257 gdk_draw_rectangle (clist->clist_window, clist->xor_gc, FALSE,
1258 row_rectangle.x, row_rectangle.y,
1259 row_rectangle.width - 1, row_rectangle.height - 1);
1260 else if (gdk_rectangle_intersect (area, &row_rectangle,
1261 &intersect_rectangle))
1263 gdk_gc_set_clip_rectangle (clist->xor_gc, &intersect_rectangle);
1264 gdk_draw_rectangle (clist->clist_window, clist->xor_gc, FALSE,
1265 row_rectangle.x, row_rectangle.y,
1266 row_rectangle.width - 1,
1267 row_rectangle.height - 1);
1268 gdk_gc_set_clip_rectangle (clist->xor_gc, NULL);
1274 gtk_sctree_change_focus_row_expansion (GtkCMCTree *ctree,
1275 GtkCMCTreeExpansionType action)
1278 GtkCMCTreeNode *node;
1280 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
1282 clist = GTK_CMCLIST (ctree);
1284 if (gdk_display_pointer_is_grabbed (gtk_widget_get_display (GTK_WIDGET (ctree))) &&
1285 GTK_WIDGET_HAS_GRAB (ctree))
1289 GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row))) ||
1290 GTK_CMCTREE_ROW (node)->is_leaf || !(GTK_CMCTREE_ROW (node)->children))
1295 case GTK_CMCTREE_EXPANSION_EXPAND:
1296 if (GTK_SCTREE(ctree)->always_expand_recursively)
1297 gtk_cmctree_expand_recursive (ctree, node);
1299 gtk_cmctree_expand (ctree, node);
1302 case GTK_CMCTREE_EXPANSION_EXPAND_RECURSIVE:
1303 gtk_cmctree_expand_recursive (ctree, node);
1305 case GTK_CMCTREE_EXPANSION_COLLAPSE:
1306 gtk_cmctree_collapse (ctree, node);
1308 case GTK_CMCTREE_EXPANSION_COLLAPSE_RECURSIVE:
1309 gtk_cmctree_collapse_recursive (ctree, node);
1311 case GTK_CMCTREE_EXPANSION_TOGGLE:
1312 if (GTK_SCTREE(ctree)->always_expand_recursively)
1313 gtk_cmctree_toggle_expansion_recursive (ctree, node);
1315 gtk_cmctree_toggle_expansion (ctree, node);
1317 case GTK_CMCTREE_EXPANSION_TOGGLE_RECURSIVE:
1318 gtk_cmctree_toggle_expansion_recursive (ctree, node);
1323 static void gtk_sctree_finalize(GObject *object)
1325 GtkSCTree *sctree = GTK_SCTREE(object);
1326 g_free(sctree->use_markup);
1327 sctree->use_markup = NULL;
1328 G_OBJECT_CLASS (parent_class)->finalize (object);
1331 /* Standard class initialization function */
1333 gtk_sctree_class_init (GtkSCTreeClass *klass)
1335 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1336 GtkObjectClass *object_class;
1337 GtkWidgetClass *widget_class;
1338 GtkCMCListClass *clist_class;
1339 GtkCMCTreeClass *ctree_class;
1341 object_class = (GtkObjectClass *) klass;
1342 widget_class = (GtkWidgetClass *) klass;
1343 clist_class = (GtkCMCListClass *) klass;
1344 ctree_class = (GtkCMCTreeClass *) klass;
1346 parent_class = g_type_class_peek (gtk_cmctree_get_type ());
1348 sctree_signals[ROW_POPUP_MENU] =
1349 g_signal_new ("row_popup_menu",
1350 G_TYPE_FROM_CLASS (klass),
1352 G_STRUCT_OFFSET (GtkSCTreeClass, row_popup_menu),
1354 claws_marshal_VOID__POINTER,
1357 sctree_signals[EMPTY_POPUP_MENU] =
1358 g_signal_new ("empty_popup_menu",
1359 G_TYPE_FROM_CLASS (klass),
1361 G_STRUCT_OFFSET (GtkSCTreeClass, empty_popup_menu),
1363 claws_marshal_VOID__POINTER,
1366 sctree_signals[OPEN_ROW] =
1367 g_signal_new ("open_row",
1368 G_TYPE_FROM_CLASS (klass),
1370 G_STRUCT_OFFSET (GtkSCTreeClass, open_row),
1372 g_cclosure_marshal_VOID__VOID,
1374 sctree_signals[START_DRAG] =
1375 g_signal_new ("start_drag",
1376 G_TYPE_FROM_CLASS (klass),
1378 G_STRUCT_OFFSET (GtkSCTreeClass, start_drag),
1380 claws_marshal_VOID__INT_POINTER,
1385 /* gtk_object_class_add_signals (object_class, sctree_signals, LAST_SIGNAL); */
1387 clist_class->clear = gtk_sctree_clear;
1388 clist_class->draw_row = gtk_sctree_draw_row;
1389 clist_class->unselect_all = gtk_sctree_real_unselect_all;
1390 ctree_class->tree_collapse = gtk_sctree_real_tree_collapse;
1391 ctree_class->tree_expand = gtk_sctree_real_tree_expand;
1392 ctree_class->tree_move = sreal_tree_move;
1393 ctree_class->change_focus_row_expansion = gtk_sctree_change_focus_row_expansion;
1395 widget_class->button_press_event = gtk_sctree_button_press;
1396 widget_class->button_release_event = gtk_sctree_button_release;
1397 widget_class->motion_notify_event = gtk_sctree_motion;
1398 widget_class->drag_begin = gtk_sctree_drag_begin;
1399 widget_class->drag_end = gtk_sctree_drag_end;
1400 widget_class->drag_data_get = gtk_sctree_drag_data_get;
1401 widget_class->drag_leave = gtk_sctree_drag_leave;
1402 widget_class->drag_motion = gtk_sctree_drag_motion;
1403 widget_class->drag_drop = gtk_sctree_drag_drop;
1404 widget_class->drag_data_received = gtk_sctree_drag_data_received;
1406 gobject_class->finalize = gtk_sctree_finalize;
1409 /* Standard object initialization function */
1411 gtk_sctree_init (GtkSCTree *sctree)
1413 sctree->anchor_row = NULL;
1415 /* GtkCMCTree does not specify pointer motion by default */
1416 gtk_widget_add_events (GTK_WIDGET (sctree), GDK_POINTER_MOTION_MASK);
1417 gtk_widget_add_events (GTK_WIDGET (sctree), GDK_POINTER_MOTION_MASK);
1420 /* Get information the specified row is selected. */
1423 row_is_selected(GtkSCTree *sctree, gint row)
1425 GtkCMCListRow *clist_row;
1426 clist_row = g_list_nth (GTK_CMCLIST(sctree)->row_list, row)->data;
1427 return clist_row ? clist_row->state == GTK_STATE_SELECTED : FALSE;
1430 /* Selects the rows between the anchor to the specified row, inclusive. */
1432 select_range (GtkSCTree *sctree, gint row)
1438 if (sctree->anchor_row == NULL) {
1440 sctree->anchor_row = gtk_cmctree_node_nth(GTK_CMCTREE(sctree), row);
1442 prev_row = g_list_position(GTK_CMCLIST(sctree)->row_list,
1443 (GList *)sctree->anchor_row);
1445 if (row < prev_row) {
1448 GTK_CMCLIST(sctree)->focus_row = max;
1453 sctree->selecting_range++;
1462 gtk_cmclist_freeze(GTK_CMCLIST(sctree));
1464 node = g_list_nth((GTK_CMCLIST(sctree))->row_list, min);
1465 for (i = min; i < max; i++) {
1466 if (node && GTK_CMCTREE_ROW (node)->row.selectable) {
1467 g_signal_emit_by_name(G_OBJECT(sctree), "tree_select_row",
1473 gtk_cmclist_thaw(GTK_CMCLIST(sctree));
1476 sctree->selecting_range--;
1477 gtk_cmclist_select_row (GTK_CMCLIST (sctree), max, -1);
1480 /* Handles row selection according to the specified modifier state */
1481 /* in certain cases, we arrive here from a function knowing the GtkCMCTreeNode, and having
1482 * already slowly found row using g_list_position. In which case, _node will be non-NULL
1483 * to avoid this function having to slowly find it with g_list_nth. */
1485 select_row (GtkSCTree *sctree, gint row, gint col, guint state, GtkCMCTreeNode *_node)
1487 gboolean range, additive;
1488 cm_return_if_fail (sctree != NULL);
1489 cm_return_if_fail (GTK_IS_SCTREE (sctree));
1491 range = ((state & GDK_SHIFT_MASK) != 0) &&
1492 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_SINGLE) &&
1493 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_BROWSE);
1494 additive = ((state & GDK_CONTROL_MASK) != 0) &&
1495 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_SINGLE) &&
1496 (GTK_CMCLIST(sctree)->selection_mode != GTK_SELECTION_BROWSE);
1498 if (!range && !additive && sctree->force_additive_sel)
1501 GTK_CMCLIST(sctree)->focus_row = row;
1504 gtk_cmclist_unselect_all (GTK_CMCLIST (sctree));
1508 GtkCMCTreeNode *node;
1510 node = _node ? _node : gtk_cmctree_node_nth (GTK_CMCTREE(sctree), row);
1512 /*No need to manage overlapped list*/
1514 if (row_is_selected(sctree, row))
1515 gtk_cmclist_unselect_row (GTK_CMCLIST (sctree), row, col);
1517 g_signal_emit_by_name
1519 "tree_select_row", node, col);
1521 g_signal_emit_by_name
1523 "tree_select_row", node, col);
1525 sctree->anchor_row = node;
1527 select_range (sctree, row);
1531 sctree_is_hot_spot (GtkSCTree *sctree,
1532 GtkCMCTreeNode *node,
1537 GtkCMCTreeRow *tree_row;
1540 GtkCMCellPixText *cell;
1544 cm_return_val_if_fail (GTK_IS_SCTREE (sctree), FALSE);
1545 cm_return_val_if_fail (node != NULL, FALSE);
1547 clist = GTK_CMCLIST (sctree);
1548 ctree = GTK_CMCTREE (sctree);
1550 if (!clist->column[ctree->tree_column].visible ||
1551 ctree->expander_style == GTK_CMCTREE_EXPANDER_NONE)
1554 tree_row = GTK_CMCTREE_ROW (node);
1556 cell = GTK_CMCELL_PIXTEXT (tree_row->row.cell[ctree->tree_column]);
1558 if (!GTK_CMCLIST_ROW_HEIGHT_SET(GTK_CMCLIST(clist)))
1559 yu = (ROW_TOP_YPIXEL (clist, row) + (clist->row_height - PM_SIZE) / 2 -
1560 (clist->row_height - 1) % 2);
1562 yu = (ROW_TOP_YPIXEL (clist, row) + (clist->row_height/2 - PM_SIZE) / 2 -
1563 (clist->row_height/2 - 1) % 2);
1565 #ifndef GENERIC_UMPC
1566 if (clist->column[ctree->tree_column].justification == GTK_JUSTIFY_RIGHT)
1567 xl = (clist->column[ctree->tree_column].area.x +
1568 clist->column[ctree->tree_column].area.width - 1 + clist->hoffset -
1569 (tree_row->level - 1) * ctree->tree_indent - PM_SIZE -
1570 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1572 xl = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1573 (tree_row->level - 1) * ctree->tree_indent +
1574 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1576 xmax = xl + PM_SIZE;
1578 if (clist->column[ctree->tree_column].justification == GTK_JUSTIFY_RIGHT) {
1579 xl = (clist->column[ctree->tree_column].area.x +
1580 clist->column[ctree->tree_column].area.width - 1 + clist->hoffset -
1581 (tree_row->level - 1) * ctree->tree_indent - PM_SIZE -
1582 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1583 xmax = xl + PM_SIZE;
1584 } else if (ctree->tree_column == 0) {
1585 xl = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1586 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3);
1587 xmax = (clist->column[ctree->tree_column].area.x + clist->hoffset +
1588 (tree_row->level - 1) * ctree->tree_indent +
1589 (ctree->line_style == GTK_CMCTREE_LINES_TABBED) * 3) +
1592 xl = (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);
1595 xmax = xl + PM_SIZE;
1598 return (x >= xl && x <= xmax && y >= yu && y <= yu + PM_SIZE);
1602 gtk_sctree_is_hot_spot (GtkSCTree *ctree,
1606 GtkCMCTreeNode *node;
1610 cm_return_val_if_fail (GTK_IS_SCTREE (ctree), FALSE);
1612 if (gtk_cmclist_get_selection_info (GTK_CMCLIST (ctree), x, y, &row, &column))
1613 if ((node = GTK_CMCTREE_NODE(g_list_nth (GTK_CMCLIST (ctree)->row_list, row))))
1614 return sctree_is_hot_spot (ctree, node, row, x, y);
1619 /* Our handler for button_press events. We override all of GtkCMCList's broken
1623 gtk_sctree_button_press (GtkWidget *widget, GdkEventButton *event)
1632 cm_return_val_if_fail (widget != NULL, FALSE);
1633 cm_return_val_if_fail (GTK_IS_SCTREE (widget), FALSE);
1634 cm_return_val_if_fail (event != NULL, FALSE);
1636 sctree = GTK_SCTREE (widget);
1637 clist = GTK_CMCLIST (widget);
1640 if (event->window != clist->clist_window)
1641 return (* GTK_WIDGET_CLASS (parent_class)->button_press_event) (widget, event);
1643 on_row = gtk_cmclist_get_selection_info (clist, event->x, event->y, &row, &col);
1645 if (on_row && !GTK_WIDGET_HAS_FOCUS(widget))
1646 gtk_widget_grab_focus (widget);
1648 if (gtk_sctree_is_hot_spot (GTK_SCTREE(sctree), event->x, event->y)) {
1649 GtkCMCTreeNode *node = gtk_cmctree_node_nth(GTK_CMCTREE(sctree), row);
1650 if (GTK_CMCTREE_ROW (node)->expanded)
1651 gtk_cmctree_collapse(GTK_CMCTREE(sctree), node);
1652 else if (GTK_SCTREE(sctree)->always_expand_recursively)
1653 gtk_cmctree_expand_recursive (GTK_CMCTREE(sctree), node);
1655 gtk_cmctree_expand(GTK_CMCTREE(sctree), node);
1659 switch (event->type) {
1660 case GDK_BUTTON_PRESS:
1661 if (event->button == 1 || event->button == 2) {
1662 if (event->button == 2)
1663 event->state &= ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK);
1665 /* Save the mouse info for DnD */
1666 sctree->dnd_press_button = event->button;
1667 sctree->dnd_press_x = event->x;
1668 sctree->dnd_press_y = event->y;
1670 /* Handle selection */
1671 if ((row_is_selected (sctree, row)
1672 && !(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)))
1673 || ((event->state & GDK_CONTROL_MASK)
1674 && !(event->state & GDK_SHIFT_MASK))) {
1675 sctree->dnd_select_pending = TRUE;
1676 sctree->dnd_select_pending_state = event->state;
1677 sctree->dnd_select_pending_row = row;
1679 select_row (sctree, row, col, event->state, NULL);
1682 gtk_cmclist_unselect_all (clist);
1686 } else if (event->button == 3) {
1687 /* Emit *_popup_menu signal*/
1689 if (!row_is_selected(sctree,row))
1690 select_row (sctree, row, col, 0, NULL);
1691 g_signal_emit (G_OBJECT (sctree),
1692 sctree_signals[ROW_POPUP_MENU],
1695 gtk_cmclist_unselect_all(clist);
1696 g_signal_emit (G_OBJECT (sctree),
1697 sctree_signals[EMPTY_POPUP_MENU],
1705 case GDK_2BUTTON_PRESS:
1706 if (event->button != 1)
1709 sctree->dnd_select_pending = FALSE;
1710 sctree->dnd_select_pending_state = 0;
1713 g_signal_emit (G_OBJECT (sctree),
1714 sctree_signals[OPEN_ROW], 0);
1726 /* Our handler for button_release events. We override all of GtkCMCList's broken
1730 gtk_sctree_button_release (GtkWidget *widget, GdkEventButton *event)
1738 cm_return_val_if_fail (widget != NULL, FALSE);
1739 cm_return_val_if_fail (GTK_IS_SCTREE (widget), FALSE);
1740 cm_return_val_if_fail (event != NULL, FALSE);
1742 sctree = GTK_SCTREE (widget);
1743 clist = GTK_CMCLIST (widget);
1746 if (event->window != clist->clist_window)
1747 return (* GTK_WIDGET_CLASS (parent_class)->button_release_event) (widget, event);
1749 on_row = gtk_cmclist_get_selection_info (clist, event->x, event->y, &row, &col);
1751 if (!(event->button == 1 || event->button == 2))
1754 sctree->dnd_press_button = 0;
1755 sctree->dnd_press_x = 0;
1756 sctree->dnd_press_y = 0;
1759 if (sctree->dnd_select_pending) {
1760 select_row (sctree, row, col, sctree->dnd_select_pending_state, NULL);
1761 sctree->dnd_select_pending = FALSE;
1762 sctree->dnd_select_pending_state = 0;
1771 /* Our handler for motion_notify events. We override all of GtkCMCList's broken
1775 gtk_sctree_motion (GtkWidget *widget, GdkEventMotion *event)
1780 cm_return_val_if_fail (widget != NULL, FALSE);
1781 cm_return_val_if_fail (GTK_IS_SCTREE (widget), FALSE);
1782 cm_return_val_if_fail (event != NULL, FALSE);
1784 sctree = GTK_SCTREE (widget);
1785 clist = GTK_CMCLIST (widget);
1787 if (event->window != clist->clist_window)
1788 return (* GTK_WIDGET_CLASS (parent_class)->motion_notify_event) (widget, event);
1790 if (!((sctree->dnd_press_button == 1 && (event->state & GDK_BUTTON1_MASK))
1791 || (sctree->dnd_press_button == 2 && (event->state & GDK_BUTTON2_MASK))))
1794 /* This is the same threshold value that is used in gtkdnd.c */
1796 #ifndef GENERIC_UMPC
1801 if (MAX (ABS (sctree->dnd_press_x - event->x),
1802 ABS (sctree->dnd_press_y - event->y)) <= THRESHOLD)
1805 /* Handle any pending selections */
1807 if (sctree->dnd_select_pending) {
1808 if (!row_is_selected(sctree,sctree->dnd_select_pending_row))
1810 sctree->dnd_select_pending_row,
1812 sctree->dnd_select_pending_state,
1815 sctree->dnd_select_pending = FALSE;
1816 sctree->dnd_select_pending_state = 0;
1819 g_signal_emit (G_OBJECT (sctree),
1820 sctree_signals[START_DRAG],
1822 sctree->dnd_press_button,
1827 /* We override the drag_begin signal to do nothing */
1829 gtk_sctree_drag_begin (GtkWidget *widget, GdkDragContext *context)
1834 /* We override the drag_end signal to do nothing */
1836 gtk_sctree_drag_end (GtkWidget *widget, GdkDragContext *context)
1841 /* We override the drag_data_get signal to do nothing */
1843 gtk_sctree_drag_data_get (GtkWidget *widget, GdkDragContext *context,
1844 GtkSelectionData *data, guint info, guint time)
1849 /* We override the drag_leave signal to do nothing */
1851 gtk_sctree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time)
1856 /* We override the drag_motion signal to do nothing */
1858 gtk_sctree_drag_motion (GtkWidget *widget, GdkDragContext *context,
1859 gint x, gint y, guint time)
1864 /* We override the drag_drop signal to do nothing */
1866 gtk_sctree_drag_drop (GtkWidget *widget, GdkDragContext *context,
1867 gint x, gint y, guint time)
1872 /* We override the drag_data_received signal to do nothing */
1874 gtk_sctree_drag_data_received (GtkWidget *widget, GdkDragContext *context,
1875 gint x, gint y, GtkSelectionData *data,
1876 guint info, guint time)
1881 /* Our handler for the clear signal of the clist. We have to reset the anchor
1885 gtk_sctree_clear (GtkCMCList *clist)
1889 cm_return_if_fail (clist != NULL);
1890 cm_return_if_fail (GTK_IS_SCTREE (clist));
1892 sctree = GTK_SCTREE (clist);
1893 sctree->anchor_row = NULL;
1895 if (((GtkCMCListClass *)parent_class)->clear)
1896 (* ((GtkCMCListClass *)parent_class)->clear) (clist);
1900 gtk_sctree_real_unselect_all (GtkCMCList *clist)
1903 gboolean should_freeze = FALSE;
1905 cm_return_if_fail (clist != NULL);
1906 cm_return_if_fail (GTK_IS_SCTREE (clist));
1908 sctree = GTK_SCTREE (clist);
1910 if (sc_g_list_bigger(GTK_CMCLIST(sctree)->selection, 10)) {
1911 should_freeze = TRUE;
1912 sctree->selecting_range++;
1913 gtk_cmclist_freeze (GTK_CMCLIST (sctree));
1916 if (((GtkCMCListClass *)parent_class)->unselect_all)
1917 (* ((GtkCMCListClass *)parent_class)->unselect_all) (clist);
1919 if (should_freeze) {
1920 gtk_cmclist_thaw (GTK_CMCLIST (sctree));
1921 sctree->selecting_range--;
1926 gtk_sctree_column_auto_resize (GtkCMCList *clist,
1927 GtkCMCListRow *clist_row,
1931 /* resize column if needed for auto_resize */
1932 GtkRequisition requisition;
1934 if (!clist->column[column].auto_resize ||
1935 GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
1939 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request (clist, clist_row,
1940 column, &requisition);
1942 requisition.width = 0;
1944 if (requisition.width > clist->column[column].width)
1945 gtk_cmclist_set_column_width (clist, column, requisition.width);
1946 else if (requisition.width < old_width &&
1947 old_width == clist->column[column].width)
1952 /* run a "gtk_cmclist_optimal_column_width" but break, if
1953 * the column doesn't shrink */
1954 if (GTK_CMCLIST_SHOW_TITLES (clist) && clist->column[column].button)
1955 new_width = (clist->column[column].button->requisition.width -
1956 (CELL_SPACING + (2 * COLUMN_INSET)));
1960 for (list = clist->row_list; list; list = list->next)
1962 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
1963 (clist, GTK_CMCLIST_ROW (list), column, &requisition);
1964 new_width = MAX (new_width, requisition.width);
1965 if (new_width == clist->column[column].width)
1968 if (new_width < clist->column[column].width)
1969 gtk_cmclist_set_column_width (clist, column, new_width);
1974 gtk_sctree_auto_resize_columns (GtkCMCList *clist)
1978 if (GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
1981 for (i = 0; i < clist->columns; i++)
1982 gtk_sctree_column_auto_resize (clist, NULL, i, clist->column[i].width);
1986 gtk_sctree_real_tree_collapse (GtkCMCTree *ctree,
1987 GtkCMCTreeNode *node)
1990 GtkCMCTreeNode *work;
1991 GtkRequisition requisition;
1995 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
1997 if (!node || !GTK_CMCTREE_ROW (node)->expanded ||
1998 GTK_CMCTREE_ROW (node)->is_leaf)
2001 clist = GTK_CMCLIST (ctree);
2003 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2005 GTK_CMCTREE_ROW (node)->expanded = FALSE;
2006 level = GTK_CMCTREE_ROW (node)->level;
2008 visible = gtk_cmctree_is_viewable (ctree, node);
2009 /* get cell width if tree_column is auto resized */
2010 if (visible && clist->column[ctree->tree_column].auto_resize &&
2011 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2012 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2013 (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column, &requisition);
2015 /* unref/unset opened pixbuf */
2016 if (GTK_CMCELL_PIXTEXT
2017 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf)
2021 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf);
2024 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf = NULL;
2027 /* set/ref closed pixbuf */
2028 if (GTK_CMCTREE_ROW (node)->pixbuf_closed)
2031 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf =
2032 g_object_ref (GTK_CMCTREE_ROW (node)->pixbuf_closed);
2035 work = GTK_CMCTREE_ROW (node)->children;
2042 while (work && GTK_CMCTREE_ROW (work)->level > level)
2044 work = GTK_CMCTREE_NODE_NEXT (work);
2050 list = (GList *)node;
2051 list->next = (GList *)work;
2052 list = (GList *)GTK_CMCTREE_NODE_PREV (work);
2054 list = (GList *)work;
2055 list->prev = (GList *)node;
2059 list = (GList *)node;
2061 clist->row_list_end = (GList *)node;
2066 /* resize auto_resize columns if needed */
2067 gtk_sctree_auto_resize_columns (clist);
2069 if (!GTK_SCTREE(clist)->sorting) {
2070 row = g_list_position (clist->row_list, (GList *)node);
2071 if (row < clist->focus_row)
2072 clist->focus_row -= tmp;
2075 CLIST_REFRESH (clist);
2078 else if (visible && clist->column[ctree->tree_column].auto_resize &&
2079 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2080 /* resize tree_column if needed */
2081 gtk_sctree_column_auto_resize (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column,
2087 GtkWidget *gtk_sctree_new_with_titles (gint columns, gint tree_column,
2092 cm_return_val_if_fail (columns > 0, NULL);
2093 cm_return_val_if_fail (tree_column >= 0, NULL);
2095 if (tree_column >= columns) {
2096 g_warning("Wrong tree column");
2101 widget = gtk_widget_new (TYPE_GTK_SCTREE,
2102 "n_columns", columns,
2103 "tree_column", tree_column,
2106 GtkCMCList *clist = GTK_CMCLIST (widget);
2109 for (i = 0; i < columns; i++)
2110 gtk_cmclist_set_column_title (clist, i, titles[i]);
2111 gtk_cmclist_column_titles_show (clist);
2114 GTK_SCTREE(widget)->show_stripes = TRUE;
2115 GTK_SCTREE(widget)->always_expand_recursively = TRUE;
2116 GTK_SCTREE(widget)->force_additive_sel = FALSE;
2118 GTK_SCTREE(widget)->use_markup = g_new0(gboolean, columns);
2123 void gtk_sctree_set_use_markup (GtkSCTree *sctree,
2128 GValue value = { 0 };
2130 cm_return_if_fail(GTK_IS_SCTREE(sctree));
2132 g_value_init (&value, G_TYPE_INT);
2133 g_object_get_property (G_OBJECT (sctree), "n-columns", &value);
2134 columns = g_value_get_int (&value);
2135 g_value_unset (&value);
2137 cm_return_if_fail(column < columns);
2139 sctree->use_markup[column] = markup;
2142 void gtk_sctree_select (GtkSCTree *sctree, GtkCMCTreeNode *node)
2145 g_list_position(GTK_CMCLIST(sctree)->row_list, (GList *)node),
2149 void gtk_sctree_select_with_state (GtkSCTree *sctree, GtkCMCTreeNode *node, int state)
2152 g_list_position(GTK_CMCLIST(sctree)->row_list, (GList *)node),
2156 void gtk_sctree_unselect_all (GtkSCTree *sctree)
2158 gtk_cmclist_unselect_all(GTK_CMCLIST(sctree));
2159 sctree->anchor_row = NULL;
2162 void gtk_sctree_set_anchor_row (GtkSCTree *sctree, GtkCMCTreeNode *node)
2164 sctree->anchor_row = node;
2167 void gtk_sctree_remove_node (GtkSCTree *sctree, GtkCMCTreeNode *node)
2169 if (sctree->anchor_row == node)
2170 sctree->anchor_row = NULL;
2171 gtk_cmctree_remove_node(GTK_CMCTREE(sctree), node);
2174 void gtk_sctree_set_stripes(GtkSCTree *sctree, gboolean show_stripes)
2176 sctree->show_stripes = show_stripes;
2179 void gtk_sctree_set_recursive_expand(GtkSCTree *sctree, gboolean rec_exp)
2181 sctree->always_expand_recursively = rec_exp;
2184 /***********************************************************
2185 * Tree sorting functions *
2186 ***********************************************************/
2188 static void sink(GtkCMCList *clist, GPtrArray *numbers, gint root, gint bottom)
2191 GtkCMCTreeNode *temp;
2196 /* find the maximum element of numbers[root],
2197 numbers[2*root] and numbers[2*root+1] */
2199 if (clist->compare( clist, GTK_CMCTREE_ROW (g_ptr_array_index(numbers, root)),
2200 GTK_CMCTREE_ROW(g_ptr_array_index( numbers, j))) >= 0)
2203 if (clist->compare( clist, GTK_CMCTREE_ROW (g_ptr_array_index(numbers, k)),
2204 GTK_CMCTREE_ROW (g_ptr_array_index( numbers, j))) > 0)
2206 /* if numbers[root] wasn't the maximum element then
2209 temp = g_ptr_array_index( numbers,root);
2210 g_ptr_array_index( numbers, root) = g_ptr_array_index( numbers, j);
2211 g_ptr_array_index( numbers, j) = temp;
2212 sink( clist, numbers, j, bottom);
2217 static void heap_sort(GtkCMCList *clist, GPtrArray *numbers, gint array_size)
2220 GtkCMCTreeNode *temp;
2222 /* build the Heap */
2223 for (i = (array_size / 2); i >= 1; i--)
2224 sink( clist, numbers, i, array_size);
2225 /* output the Heap */
2226 for (i = array_size; i >= 2; i--) {
2227 temp = g_ptr_array_index( numbers, 1);
2228 g_ptr_array_index( numbers, 1) = g_ptr_array_index( numbers, i);
2229 g_ptr_array_index( numbers, i) = temp;
2230 sink( clist, numbers, 1, i-1);
2235 stree_sort (GtkCMCTree *ctree,
2236 GtkCMCTreeNode *node,
2239 GtkCMCTreeNode *list_start, *work, *next;
2240 GPtrArray *row_array, *viewable_array;
2244 clist = GTK_CMCLIST (ctree);
2247 work = GTK_CMCTREE_ROW (node)->children;
2249 work = GTK_CMCTREE_NODE (clist->row_list);
2251 row_array = g_ptr_array_new();
2252 viewable_array = g_ptr_array_new();
2255 g_ptr_array_add( row_array, NULL);
2257 /* add all rows to row_array */
2258 g_ptr_array_add( row_array, work);
2259 if (GTK_CMCTREE_ROW (work)->parent && gtk_cmctree_is_viewable( ctree, work))
2260 g_ptr_array_add( viewable_array, GTK_CMCTREE_ROW (work)->parent);
2261 next = GTK_CMCTREE_ROW (work)->sibling;
2262 gtk_sctree_unlink( ctree, work, FALSE);
2266 heap_sort( clist, row_array, (row_array->len)-1);
2269 list_start = GTK_CMCTREE_ROW (node)->children;
2271 list_start = GTK_CMCTREE_NODE (clist->row_list);
2273 if (clist->sort_type == GTK_SORT_ASCENDING) {
2274 for (i=(row_array->len)-1; i>=1; i--) {
2275 work = g_ptr_array_index( row_array, i);
2276 gtk_sctree_link( ctree, work, node, list_start, FALSE);
2278 /* insert work at the beginning of the list */
2281 for (i=1; i<row_array->len; i++) {
2282 work = g_ptr_array_index( row_array, i);
2283 gtk_sctree_link( ctree, work, node, list_start, FALSE);
2285 /* insert work at the beginning of the list */
2289 for (i=0; i<viewable_array->len; i++) {
2290 gtk_cmctree_expand( ctree, g_ptr_array_index( viewable_array, i));
2294 g_ptr_array_free( row_array, TRUE);
2295 g_ptr_array_free( viewable_array, TRUE);
2299 gtk_sctree_sort_recursive (GtkCMCTree *ctree,
2300 GtkCMCTreeNode *node)
2303 GtkCMCTreeNode *focus_node = NULL;
2305 cm_return_if_fail (ctree != NULL);
2306 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2308 clist = GTK_CMCLIST (ctree);
2310 gtk_cmclist_freeze (clist);
2312 if (clist->selection_mode == GTK_SELECTION_EXTENDED) {
2313 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2315 g_list_free (clist->undo_selection);
2316 g_list_free (clist->undo_unselection);
2317 clist->undo_selection = NULL;
2318 clist->undo_unselection = NULL;
2321 if (!node || (node && gtk_cmctree_is_viewable (ctree, node)))
2322 focus_node = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
2324 GTK_SCTREE(ctree)->sorting = TRUE;
2326 gtk_cmctree_post_recursive (ctree, node, GTK_CMCTREE_FUNC (stree_sort), NULL);
2329 stree_sort (ctree, NULL, NULL);
2331 GTK_SCTREE(ctree)->sorting = FALSE;
2334 clist->focus_row = g_list_position (clist->row_list,(GList *)focus_node);
2335 clist->undo_anchor = clist->focus_row;
2338 gtk_cmclist_thaw (clist);
2342 gtk_sctree_sort_node (GtkCMCTree *ctree,
2343 GtkCMCTreeNode *node)
2346 GtkCMCTreeNode *focus_node = NULL;
2348 cm_return_if_fail (ctree != NULL);
2349 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2351 clist = GTK_CMCLIST (ctree);
2353 gtk_cmclist_freeze (clist);
2355 if (clist->selection_mode == GTK_SELECTION_EXTENDED) {
2356 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2358 g_list_free (clist->undo_selection);
2359 g_list_free (clist->undo_unselection);
2360 clist->undo_selection = NULL;
2361 clist->undo_unselection = NULL;
2364 if (!node || (node && gtk_cmctree_is_viewable (ctree, node)))
2365 focus_node = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
2367 GTK_SCTREE(ctree)->sorting = TRUE;
2369 stree_sort (ctree, node, NULL);
2371 GTK_SCTREE(ctree)->sorting = FALSE;
2374 clist->focus_row = g_list_position (clist->row_list,(GList *)focus_node);
2375 clist->undo_anchor = clist->focus_row;
2378 gtk_cmclist_thaw (clist);
2381 /************************************************************************/
2384 gtk_sctree_unlink (GtkCMCTree *ctree,
2385 GtkCMCTreeNode *node,
2386 gboolean update_focus_row)
2392 GtkCMCTreeNode *work;
2393 GtkCMCTreeNode *parent;
2396 cm_return_if_fail (ctree != NULL);
2397 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2398 cm_return_if_fail (node != NULL);
2400 clist = GTK_CMCLIST (ctree);
2402 if (update_focus_row && clist->selection_mode == GTK_SELECTION_EXTENDED) {
2403 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2405 g_list_free (clist->undo_selection);
2406 g_list_free (clist->undo_unselection);
2407 clist->undo_selection = NULL;
2408 clist->undo_unselection = NULL;
2411 visible = gtk_cmctree_is_viewable (ctree, node);
2413 /* clist->row_list_end unlinked ? */
2414 if (visible && (GTK_CMCTREE_NODE_NEXT (node) == NULL ||
2415 (GTK_CMCTREE_ROW (node)->children && gtk_cmctree_is_ancestor (ctree, node,
2416 GTK_CMCTREE_NODE (clist->row_list_end)))))
2417 clist->row_list_end = (GList *) (GTK_CMCTREE_NODE_PREV (node));
2421 level = GTK_CMCTREE_ROW (node)->level;
2422 work = GTK_CMCTREE_NODE_NEXT (node);
2423 while (work && GTK_CMCTREE_ROW (work)->level > level) {
2424 work = GTK_CMCTREE_NODE_NEXT (work);
2429 clist->rows -= (rows + 1);
2431 if (update_focus_row) {
2433 pos = g_list_position (clist->row_list, (GList *)node);
2434 if (pos + rows < clist->focus_row)
2435 clist->focus_row -= (rows + 1);
2436 else if (pos <= clist->focus_row) {
2437 if (!GTK_CMCTREE_ROW (node)->sibling)
2438 clist->focus_row = MAX (pos - 1, 0);
2440 clist->focus_row = pos;
2442 clist->focus_row = MIN (clist->focus_row, clist->rows - 1);
2444 clist->undo_anchor = clist->focus_row;
2449 list = (GList *)GTK_CMCTREE_NODE_PREV (work);
2451 list = (GList *)work;
2452 list->prev = (GList *)GTK_CMCTREE_NODE_PREV (node);
2455 if (GTK_CMCTREE_NODE_PREV (node) &&
2456 GTK_CMCTREE_NODE_NEXT (GTK_CMCTREE_NODE_PREV (node)) == node) {
2457 list = (GList *)GTK_CMCTREE_NODE_PREV (node);
2458 list->next = (GList *)work;
2462 parent = GTK_CMCTREE_ROW (node)->parent;
2464 if (GTK_CMCTREE_ROW (parent)->children == node) {
2465 GTK_CMCTREE_ROW (parent)->children = GTK_CMCTREE_ROW (node)->sibling;
2468 GtkCMCTreeNode *sibling;
2470 sibling = GTK_CMCTREE_ROW (parent)->children;
2471 while (GTK_CMCTREE_ROW (sibling)->sibling != node)
2472 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
2473 GTK_CMCTREE_ROW (sibling)->sibling = GTK_CMCTREE_ROW (node)->sibling;
2477 if (clist->row_list == (GList *)node)
2478 clist->row_list = (GList *) (GTK_CMCTREE_ROW (node)->sibling);
2480 GtkCMCTreeNode *sibling;
2482 sibling = GTK_CMCTREE_NODE (clist->row_list);
2483 while (GTK_CMCTREE_ROW (sibling)->sibling != node)
2484 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
2485 GTK_CMCTREE_ROW (sibling)->sibling = GTK_CMCTREE_ROW (node)->sibling;
2491 gtk_sctree_link (GtkCMCTree *ctree,
2492 GtkCMCTreeNode *node,
2493 GtkCMCTreeNode *parent,
2494 GtkCMCTreeNode *sibling,
2495 gboolean update_focus_row)
2501 gboolean visible = FALSE;
2505 cm_return_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent);
2506 cm_return_if_fail (node != NULL);
2507 cm_return_if_fail (node != sibling);
2508 cm_return_if_fail (node != parent);
2510 clist = GTK_CMCLIST (ctree);
2512 if (update_focus_row && clist->selection_mode == GTK_SELECTION_EXTENDED) {
2513 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2515 g_list_free (clist->undo_selection);
2516 g_list_free (clist->undo_unselection);
2517 clist->undo_selection = NULL;
2518 clist->undo_unselection = NULL;
2521 for (rows = 1, list_end = (GList *)node; list_end->next;
2522 list_end = list_end->next)
2525 GTK_CMCTREE_ROW (node)->parent = parent;
2526 GTK_CMCTREE_ROW (node)->sibling = sibling;
2528 if (!parent || (parent && (gtk_cmctree_is_viewable (ctree, parent) &&
2529 GTK_CMCTREE_ROW (parent)->expanded))) {
2531 clist->rows += rows;
2535 work = (GList *)(GTK_CMCTREE_ROW (parent)->children);
2537 work = clist->row_list;
2540 if (work != (GList *)sibling) {
2541 while (GTK_CMCTREE_ROW (work)->sibling != sibling)
2542 work = (GList *)(GTK_CMCTREE_ROW (work)->sibling);
2543 GTK_CMCTREE_ROW (work)->sibling = node;
2546 if (sibling == GTK_CMCTREE_NODE (clist->row_list))
2547 clist->row_list = (GList *) node;
2548 if (GTK_CMCTREE_NODE_PREV (sibling) &&
2549 GTK_CMCTREE_NODE_NEXT (GTK_CMCTREE_NODE_PREV (sibling)) == sibling) {
2550 list = (GList *)GTK_CMCTREE_NODE_PREV (sibling);
2551 list->next = (GList *)node;
2554 list = (GList *)node;
2555 list->prev = (GList *)GTK_CMCTREE_NODE_PREV (sibling);
2556 list_end->next = (GList *)sibling;
2557 list = (GList *)sibling;
2558 list->prev = list_end;
2559 if (parent && GTK_CMCTREE_ROW (parent)->children == sibling)
2560 GTK_CMCTREE_ROW (parent)->children = node;
2565 while (GTK_CMCTREE_ROW (work)->sibling)
2566 work = (GList *)(GTK_CMCTREE_ROW (work)->sibling);
2567 GTK_CMCTREE_ROW (work)->sibling = node;
2569 /* find last visible child of sibling */
2570 work = (GList *) gtk_sctree_last_visible (ctree,
2571 GTK_CMCTREE_NODE (work));
2573 list_end->next = work->next;
2575 list = work->next->prev = list_end;
2576 work->next = (GList *)node;
2577 list = (GList *)node;
2582 GTK_CMCTREE_ROW (parent)->children = node;
2583 list = (GList *)node;
2584 list->prev = (GList *)parent;
2585 if (GTK_CMCTREE_ROW (parent)->expanded) {
2586 list_end->next = (GList *)GTK_CMCTREE_NODE_NEXT (parent);
2587 if (GTK_CMCTREE_NODE_NEXT(parent)) {
2588 list = (GList *)GTK_CMCTREE_NODE_NEXT (parent);
2589 list->prev = list_end;
2591 list = (GList *)parent;
2592 list->next = (GList *)node;
2595 list_end->next = NULL;
2598 clist->row_list = (GList *)node;
2599 list = (GList *)node;
2601 list_end->next = NULL;
2606 gtk_cmctree_pre_recursive (ctree, node, stree_update_level, NULL);
2608 if (clist->row_list_end == NULL ||
2609 clist->row_list_end->next == (GList *)node)
2610 clist->row_list_end = list_end;
2612 if (visible && update_focus_row) {
2614 pos = g_list_position (clist->row_list, (GList *)node);
2616 if (pos <= clist->focus_row) {
2617 clist->focus_row += rows;
2618 clist->undo_anchor = clist->focus_row;
2624 stree_update_level (GtkCMCTree *ctree,
2625 GtkCMCTreeNode *node,
2631 if (GTK_CMCTREE_ROW (node)->parent)
2632 GTK_CMCTREE_ROW (node)->level =
2633 GTK_CMCTREE_ROW (GTK_CMCTREE_ROW (node)->parent)->level + 1;
2635 GTK_CMCTREE_ROW (node)->level = 1;
2638 static GtkCMCTreeNode *
2639 gtk_sctree_last_visible (GtkCMCTree *ctree,
2640 GtkCMCTreeNode *node)
2642 GtkCMCTreeNode *work;
2647 work = GTK_CMCTREE_ROW (node)->children;
2649 if (!work || !GTK_CMCTREE_ROW (node)->expanded)
2652 while (GTK_CMCTREE_ROW (work)->sibling)
2653 work = GTK_CMCTREE_ROW (work)->sibling;
2655 return gtk_sctree_last_visible (ctree, work);
2659 sset_node_info (GtkCMCTree *ctree,
2660 GtkCMCTreeNode *node,
2663 GdkPixbuf *pixbuf_closed,
2664 GdkPixbuf *pixbuf_opened,
2668 if (GTK_CMCTREE_ROW (node)->pixbuf_opened)
2670 g_object_unref (GTK_CMCTREE_ROW (node)->pixbuf_opened);
2672 if (GTK_CMCTREE_ROW (node)->pixbuf_closed)
2674 g_object_unref (GTK_CMCTREE_ROW (node)->pixbuf_closed);
2677 GTK_CMCTREE_ROW (node)->pixbuf_opened = NULL;
2678 GTK_CMCTREE_ROW (node)->pixbuf_closed = NULL;
2682 GTK_CMCTREE_ROW (node)->pixbuf_closed = g_object_ref (pixbuf_closed);
2686 GTK_CMCTREE_ROW (node)->pixbuf_opened = g_object_ref (pixbuf_opened);
2689 GTK_CMCTREE_ROW (node)->is_leaf = is_leaf;
2690 GTK_CMCTREE_ROW (node)->expanded = (is_leaf) ? FALSE : expanded;
2692 if (GTK_CMCTREE_ROW (node)->expanded)
2693 gtk_cmctree_node_set_pixtext (ctree, node, ctree->tree_column,
2694 text, spacing, pixbuf_opened);
2696 gtk_cmctree_node_set_pixtext (ctree, node, ctree->tree_column,
2697 text, spacing, pixbuf_closed);
2701 stree_draw_node (GtkCMCTree *ctree,
2702 GtkCMCTreeNode *node)
2706 clist = GTK_CMCLIST (ctree);
2708 if (CLIST_UNFROZEN (clist) && gtk_cmctree_is_viewable (ctree, node))
2710 GtkCMCTreeNode *work;
2713 work = GTK_CMCTREE_NODE (clist->row_list);
2714 while (work && work != node)
2716 work = GTK_CMCTREE_NODE_NEXT (work);
2719 if (work && gtk_cmclist_row_is_visible (clist, num) != GTK_VISIBILITY_NONE)
2720 GTK_CMCLIST_GET_CLASS (clist)->draw_row
2721 (clist, NULL, num, GTK_CMCLIST_ROW ((GList *) node));
2725 /* this wrapper simply replaces NULL pixbufs
2726 * with a transparent, 1x1 pixbuf. This works
2727 * around a memory problem deep inside gtk,
2728 * revealed by valgrind.
2730 void gtk_sctree_set_node_info (GtkCMCTree *ctree,
2731 GtkCMCTreeNode *node,
2734 GdkPixbuf *pixbuf_closed,
2735 GdkPixbuf *pixbuf_opened,
2740 gboolean old_expanded;
2741 GtkCMCTreeNode *work;
2743 if (!GTK_IS_CMCTREE (ctree) || !node) return;
2745 old_leaf = GTK_CMCTREE_ROW (node)->is_leaf;
2746 old_expanded = GTK_CMCTREE_ROW (node)->expanded;
2748 if (is_leaf && (work = GTK_CMCTREE_ROW (node)->children) != NULL)
2750 GtkCMCTreeNode *ptr;
2755 work = GTK_CMCTREE_ROW (work)->sibling;
2756 gtk_cmctree_remove_node (ctree, ptr);
2760 sset_node_info (ctree, node, text, spacing, pixbuf_closed,
2761 pixbuf_opened, is_leaf, expanded);
2763 if (!is_leaf && !old_leaf)
2765 GTK_CMCTREE_ROW (node)->expanded = old_expanded;
2766 if (expanded && !old_expanded)
2767 gtk_cmctree_expand (ctree, node);
2768 else if (!expanded && old_expanded)
2769 gtk_cmctree_collapse (ctree, node);
2772 GTK_CMCTREE_ROW (node)->expanded = (is_leaf) ? FALSE : expanded;
2774 stree_draw_node (ctree, node);
2777 static GtkCMCTreeRow *
2778 srow_new (GtkCMCTree *ctree)
2781 GtkCMCTreeRow *ctree_row;
2784 clist = GTK_CMCLIST (ctree);
2785 #if GLIB_CHECK_VERSION(2,10,0)
2786 ctree_row = g_slice_new (GtkCMCTreeRow);
2787 ctree_row->row.cell = g_slice_alloc (sizeof (GtkCMCell) * clist->columns);
2789 ctree_row = g_chunk_new (GtkCMCTreeRow, (GMemChunk *)clist->row_mem_chunk);
2790 ctree_row->row.cell = g_chunk_new (GtkCMCell, (GMemChunk *)clist->cell_mem_chunk);
2792 for (i = 0; i < clist->columns; i++)
2794 ctree_row->row.cell[i].type = GTK_CMCELL_EMPTY;
2795 ctree_row->row.cell[i].vertical = 0;
2796 ctree_row->row.cell[i].horizontal = 0;
2797 ctree_row->row.cell[i].style = NULL;
2800 GTK_CMCELL_PIXTEXT (ctree_row->row.cell[ctree->tree_column])->text = NULL;
2802 ctree_row->row.fg_set = FALSE;
2803 ctree_row->row.bg_set = FALSE;
2804 ctree_row->row.style = NULL;
2805 ctree_row->row.selectable = TRUE;
2806 ctree_row->row.state = GTK_STATE_NORMAL;
2807 ctree_row->row.data = NULL;
2808 ctree_row->row.destroy = NULL;
2810 ctree_row->level = 0;
2811 ctree_row->expanded = FALSE;
2812 ctree_row->parent = NULL;
2813 ctree_row->sibling = NULL;
2814 ctree_row->children = NULL;
2815 ctree_row->pixbuf_closed = NULL;
2816 ctree_row->pixbuf_opened = NULL;
2822 srow_delete (GtkCMCTree *ctree,
2823 GtkCMCTreeRow *ctree_row)
2828 clist = GTK_CMCLIST (ctree);
2830 for (i = 0; i < clist->columns; i++)
2832 GTK_CMCLIST_GET_CLASS (clist)->set_cell_contents
2833 (clist, &(ctree_row->row), i, GTK_CMCELL_EMPTY, NULL, 0, NULL);
2834 if (ctree_row->row.cell[i].style)
2836 if (GTK_WIDGET_REALIZED (ctree))
2837 gtk_style_detach (ctree_row->row.cell[i].style);
2838 g_object_unref (ctree_row->row.cell[i].style);
2842 if (ctree_row->row.style)
2844 if (GTK_WIDGET_REALIZED (ctree))
2845 gtk_style_detach (ctree_row->row.style);
2846 g_object_unref (ctree_row->row.style);
2849 if (ctree_row->pixbuf_closed)
2851 g_object_unref (ctree_row->pixbuf_closed);
2854 if (ctree_row->pixbuf_opened)
2856 g_object_unref (ctree_row->pixbuf_opened);
2859 if (ctree_row->row.destroy)
2861 GDestroyNotify dnotify = ctree_row->row.destroy;
2862 gpointer ddata = ctree_row->row.data;
2864 ctree_row->row.destroy = NULL;
2865 ctree_row->row.data = NULL;
2870 #if GLIB_CHECK_VERSION(2,10,0)
2871 g_slice_free1 (sizeof (GtkCMCell) * clist->columns, ctree_row->row.cell);
2872 g_slice_free (GtkCMCTreeRow, ctree_row);
2874 g_mem_chunk_free ((GMemChunk *)clist->cell_mem_chunk, ctree_row->row.cell);
2875 g_mem_chunk_free ((GMemChunk *)clist->row_mem_chunk, ctree_row);
2880 stree_delete_row (GtkCMCTree *ctree,
2881 GtkCMCTreeNode *node,
2884 srow_delete (ctree, GTK_CMCTREE_ROW (node));
2885 g_list_free_1 ((GList *)node);
2889 gtk_sctree_real_tree_expand (GtkCMCTree *ctree,
2890 GtkCMCTreeNode *node)
2893 GtkCMCTreeNode *work;
2894 GtkRequisition requisition;
2898 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2900 if (!node || GTK_CMCTREE_ROW (node)->expanded || GTK_CMCTREE_ROW (node)->is_leaf)
2903 clist = GTK_CMCLIST (ctree);
2905 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2907 GTK_CMCTREE_ROW (node)->expanded = TRUE;
2908 level = GTK_CMCTREE_ROW (node)->level;
2910 visible = gtk_cmctree_is_viewable (ctree, node);
2911 /* get cell width if tree_column is auto resized */
2912 if (visible && clist->column[ctree->tree_column].auto_resize &&
2913 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2914 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2915 (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column, &requisition);
2917 /* unref/unset closed pixbuf */
2918 if (GTK_CMCELL_PIXTEXT
2919 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf)
2923 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf);
2926 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf = NULL;
2929 /* set/ref opened pixbuf */
2930 if (GTK_CMCTREE_ROW (node)->pixbuf_opened)
2933 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf =
2934 g_object_ref (GTK_CMCTREE_ROW (node)->pixbuf_opened);
2938 work = GTK_CMCTREE_ROW (node)->children;
2941 GList *list = (GList *)work;
2942 gint *cell_width = NULL;
2947 if (visible && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2949 cell_width = g_new0 (gint, clist->columns);
2950 if (clist->column[ctree->tree_column].auto_resize)
2951 cell_width[ctree->tree_column] = requisition.width;
2955 /* search maximum cell widths of auto_resize columns */
2956 for (i = 0; i < clist->columns; i++)
2957 if (clist->column[i].auto_resize)
2959 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2960 (clist, >K_CMCTREE_ROW (work)->row, i, &requisition);
2961 cell_width[i] = MAX (requisition.width, cell_width[i]);
2964 list = (GList *)work;
2965 work = GTK_CMCTREE_NODE_NEXT (work);
2972 list = (GList *)work;
2973 work = GTK_CMCTREE_NODE_NEXT (work);
2977 list->next = (GList *)GTK_CMCTREE_NODE_NEXT (node);
2979 if (GTK_CMCTREE_NODE_NEXT (node))
2983 if (clist->row_list_end == list)
2984 clist->row_list_end = g_list_last(list);
2986 tmp_list = (GList *)GTK_CMCTREE_NODE_NEXT (node);
2987 tmp_list->prev = list;
2990 clist->row_list_end = list;
2992 list = (GList *)node;
2993 list->next = (GList *)(GTK_CMCTREE_ROW (node)->children);
2995 if (visible && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2997 /* resize auto_resize columns if needed */
2998 for (i = 0; i < clist->columns; i++)
2999 if (clist->column[i].auto_resize &&
3000 cell_width[i] > clist->column[i].width)
3001 gtk_cmclist_set_column_width (clist, i, cell_width[i]);
3002 g_free (cell_width);
3004 if (!GTK_SCTREE(ctree)->sorting) {
3005 /* update focus_row position */
3006 row = g_list_position (clist->row_list, (GList *)node);
3007 if (row < clist->focus_row)
3008 clist->focus_row += tmp;
3011 CLIST_REFRESH (clist);
3014 else if (visible && clist->column[ctree->tree_column].auto_resize)
3015 /* resize tree_column if needed */
3016 gtk_sctree_column_auto_resize (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column,
3022 gtk_sctree_insert_node (GtkCMCTree *ctree,
3023 GtkCMCTreeNode *parent,
3024 GtkCMCTreeNode *sibling,
3027 GdkPixbuf *pixbuf_closed,
3028 GdkPixbuf *pixbuf_opened,
3033 GtkCMCTreeRow *new_row;
3034 GtkCMCTreeNode *node;
3038 cm_return_val_if_fail (GTK_IS_CMCTREE (ctree), NULL);
3040 cm_return_val_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent, NULL);
3042 if (parent && GTK_CMCTREE_ROW (parent)->is_leaf)
3045 clist = GTK_CMCLIST (ctree);
3047 /* create the row */
3048 new_row = srow_new (ctree);
3049 list = g_list_alloc ();
3050 list->data = new_row;
3051 node = GTK_CMCTREE_NODE (list);
3054 for (i = 0; i < clist->columns; i++)
3055 if (text[i] && i != ctree->tree_column)
3056 GTK_CMCLIST_GET_CLASS (clist)->set_cell_contents
3057 (clist, &(new_row->row), i, GTK_CMCELL_TEXT, text[i], 0, NULL);
3059 sset_node_info (ctree, node, text ?
3060 text[ctree->tree_column] : NULL, spacing, pixbuf_closed,
3061 pixbuf_opened, is_leaf, expanded);
3063 /* sorted insertion */
3064 if (GTK_CMCLIST_AUTO_SORT (clist))
3067 sibling = GTK_CMCTREE_ROW (parent)->children;
3069 sibling = GTK_CMCTREE_NODE (clist->row_list);
3071 while (sibling && clist->compare
3072 (clist, GTK_CMCTREE_ROW (node), GTK_CMCTREE_ROW (sibling)) > 0)
3073 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
3076 gtk_sctree_link (ctree, node, parent, sibling, FALSE);
3078 if (text && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist) &&
3079 gtk_cmctree_is_viewable (ctree, node))
3081 for (i = 0; i < clist->columns; i++)
3082 if (clist->column[i].auto_resize)
3083 gtk_sctree_column_auto_resize (clist, &(new_row->row), i, 0);
3086 if (clist->rows == 1)
3088 clist->focus_row = 0;
3089 if (clist->selection_mode == GTK_SELECTION_BROWSE)
3090 gtk_sctree_select (GTK_SCTREE(ctree), node);
3094 CLIST_REFRESH (clist);
3100 gtk_sctree_insert_gnode (GtkCMCTree *ctree,
3101 GtkCMCTreeNode *parent,
3102 GtkCMCTreeNode *sibling,
3104 GtkCMCTreeGNodeFunc func,
3108 GtkCMCTreeNode *cnode = NULL;
3109 GtkCMCTreeNode *child = NULL;
3110 GtkCMCTreeNode *new_child;
3115 cm_return_val_if_fail (GTK_IS_CMCTREE (ctree), NULL);
3116 cm_return_val_if_fail (gnode != NULL, NULL);
3117 cm_return_val_if_fail (func != NULL, NULL);
3119 cm_return_val_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent, NULL);
3121 clist = GTK_CMCLIST (ctree);
3124 depth = GTK_CMCTREE_ROW (parent)->level + 1;
3126 list = g_list_alloc ();
3127 list->data = srow_new (ctree);
3128 cnode = GTK_CMCTREE_NODE (list);
3130 gtk_cmclist_freeze (clist);
3132 sset_node_info (ctree, cnode, "", 0, NULL, NULL, TRUE, FALSE);
3134 if (!func (ctree, depth, gnode, cnode, data))
3136 stree_delete_row (ctree, cnode, NULL);
3137 gtk_cmclist_thaw (clist);
3141 if (GTK_CMCLIST_AUTO_SORT (clist))
3144 sibling = GTK_CMCTREE_ROW (parent)->children;
3146 sibling = GTK_CMCTREE_NODE (clist->row_list);
3148 while (sibling && clist->compare
3149 (clist, GTK_CMCTREE_ROW (cnode), GTK_CMCTREE_ROW (sibling)) > 0)
3150 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
3153 gtk_sctree_link (ctree, cnode, parent, sibling, FALSE);
3155 for (work = g_node_last_child (gnode); work; work = work->prev)
3157 new_child = gtk_sctree_insert_gnode (ctree, cnode, child,
3163 gtk_cmclist_thaw (clist);
3169 sreal_tree_move (GtkCMCTree *ctree,
3170 GtkCMCTreeNode *node,
3171 GtkCMCTreeNode *new_parent,
3172 GtkCMCTreeNode *new_sibling)
3175 GtkCMCTreeNode *work;
3176 gboolean visible = FALSE;
3178 cm_return_if_fail (ctree != NULL);
3179 cm_return_if_fail (node != NULL);
3180 cm_return_if_fail (!new_sibling ||
3181 GTK_CMCTREE_ROW (new_sibling)->parent == new_parent);
3183 if (new_parent && GTK_CMCTREE_ROW (new_parent)->is_leaf)
3186 /* new_parent != child of child */
3187 for (work = new_parent; work; work = GTK_CMCTREE_ROW (work)->parent)
3191 clist = GTK_CMCLIST (ctree);
3193 visible = gtk_cmctree_is_viewable (ctree, node);
3195 if (clist->selection_mode == GTK_SELECTION_MULTIPLE)
3197 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
3199 g_list_free (clist->undo_selection);
3200 g_list_free (clist->undo_unselection);
3201 clist->undo_selection = NULL;
3202 clist->undo_unselection = NULL;
3205 if (GTK_CMCLIST_AUTO_SORT (clist))
3207 if (new_parent == GTK_CMCTREE_ROW (node)->parent)
3211 new_sibling = GTK_CMCTREE_ROW (new_parent)->children;
3213 new_sibling = GTK_CMCTREE_NODE (clist->row_list);
3215 while (new_sibling && clist->compare
3216 (clist, GTK_CMCTREE_ROW (node), GTK_CMCTREE_ROW (new_sibling)) > 0)
3217 new_sibling = GTK_CMCTREE_ROW (new_sibling)->sibling;
3220 if (new_parent == GTK_CMCTREE_ROW (node)->parent &&
3221 new_sibling == GTK_CMCTREE_ROW (node)->sibling)
3224 gtk_cmclist_freeze (clist);
3228 if (!GTK_SCTREE(ctree)->sorting && gtk_cmctree_is_viewable (ctree, node))
3229 work = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
3231 gtk_sctree_unlink (ctree, node, FALSE);
3232 gtk_sctree_link (ctree, node, new_parent, new_sibling, FALSE);
3234 if (!GTK_SCTREE(ctree)->sorting && work)
3236 while (work && !gtk_cmctree_is_viewable (ctree, work))
3237 work = GTK_CMCTREE_ROW (work)->parent;
3238 clist->focus_row = g_list_position (clist->row_list, (GList *)work);
3239 clist->undo_anchor = clist->focus_row;
3242 if (clist->column[ctree->tree_column].auto_resize &&
3243 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist) &&
3244 (visible || gtk_cmctree_is_viewable (ctree, node)))
3245 gtk_cmclist_set_column_width
3246 (clist, ctree->tree_column,
3247 gtk_cmclist_optimal_column_width (clist, ctree->tree_column));
3249 gtk_cmclist_thaw (clist);
3252 void gtk_sctree_set_column_tooltip (GtkSCTree *sctree,
3256 #if !(GTK_CHECK_VERSION(2,12,0))
3258 if (!sctree->tooltips)
3259 sctree->tooltips = gtk_tooltips_new();
3260 tips = sctree->tooltips;
3263 CLAWS_SET_TIP(GTK_CMCLIST(sctree)->column[column].button,