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 widget = gtk_widget_new (TYPE_GTK_SCTREE,
2096 "n_columns", columns,
2097 "tree_column", tree_column,
2100 GtkCMCList *clist = GTK_CMCLIST (widget);
2103 for (i = 0; i < columns; i++)
2104 gtk_cmclist_set_column_title (clist, i, titles[i]);
2105 gtk_cmclist_column_titles_show (clist);
2108 GTK_SCTREE(widget)->show_stripes = TRUE;
2109 GTK_SCTREE(widget)->always_expand_recursively = TRUE;
2110 GTK_SCTREE(widget)->force_additive_sel = FALSE;
2112 GTK_SCTREE(widget)->use_markup = g_new0(gboolean, columns);
2117 void gtk_sctree_set_use_markup (GtkSCTree *sctree,
2122 GValue value = { 0 };
2124 cm_return_if_fail(GTK_IS_SCTREE(sctree));
2126 g_value_init (&value, G_TYPE_INT);
2127 g_object_get_property (G_OBJECT (sctree), "n-columns", &value);
2128 columns = g_value_get_int (&value);
2129 g_value_unset (&value);
2131 cm_return_if_fail(column < columns);
2133 sctree->use_markup[column] = markup;
2136 void gtk_sctree_select (GtkSCTree *sctree, GtkCMCTreeNode *node)
2139 g_list_position(GTK_CMCLIST(sctree)->row_list, (GList *)node),
2143 void gtk_sctree_select_with_state (GtkSCTree *sctree, GtkCMCTreeNode *node, int state)
2146 g_list_position(GTK_CMCLIST(sctree)->row_list, (GList *)node),
2150 void gtk_sctree_unselect_all (GtkSCTree *sctree)
2152 gtk_cmclist_unselect_all(GTK_CMCLIST(sctree));
2153 sctree->anchor_row = NULL;
2156 void gtk_sctree_set_anchor_row (GtkSCTree *sctree, GtkCMCTreeNode *node)
2158 sctree->anchor_row = node;
2161 void gtk_sctree_remove_node (GtkSCTree *sctree, GtkCMCTreeNode *node)
2163 if (sctree->anchor_row == node)
2164 sctree->anchor_row = NULL;
2165 gtk_cmctree_remove_node(GTK_CMCTREE(sctree), node);
2168 void gtk_sctree_set_stripes(GtkSCTree *sctree, gboolean show_stripes)
2170 sctree->show_stripes = show_stripes;
2173 void gtk_sctree_set_recursive_expand(GtkSCTree *sctree, gboolean rec_exp)
2175 sctree->always_expand_recursively = rec_exp;
2178 /***********************************************************
2179 * Tree sorting functions *
2180 ***********************************************************/
2182 static void sink(GtkCMCList *clist, GPtrArray *numbers, gint root, gint bottom)
2185 GtkCMCTreeNode *temp;
2190 /* find the maximum element of numbers[root],
2191 numbers[2*root] and numbers[2*root+1] */
2193 if (clist->compare( clist, GTK_CMCTREE_ROW (g_ptr_array_index(numbers, root)),
2194 GTK_CMCTREE_ROW(g_ptr_array_index( numbers, j))) >= 0)
2197 if (clist->compare( clist, GTK_CMCTREE_ROW (g_ptr_array_index(numbers, k)),
2198 GTK_CMCTREE_ROW (g_ptr_array_index( numbers, j))) > 0)
2200 /* if numbers[root] wasn't the maximum element then
2203 temp = g_ptr_array_index( numbers,root);
2204 g_ptr_array_index( numbers, root) = g_ptr_array_index( numbers, j);
2205 g_ptr_array_index( numbers, j) = temp;
2206 sink( clist, numbers, j, bottom);
2211 static void heap_sort(GtkCMCList *clist, GPtrArray *numbers, gint array_size)
2214 GtkCMCTreeNode *temp;
2216 /* build the Heap */
2217 for (i = (array_size / 2); i >= 1; i--)
2218 sink( clist, numbers, i, array_size);
2219 /* output the Heap */
2220 for (i = array_size; i >= 2; i--) {
2221 temp = g_ptr_array_index( numbers, 1);
2222 g_ptr_array_index( numbers, 1) = g_ptr_array_index( numbers, i);
2223 g_ptr_array_index( numbers, i) = temp;
2224 sink( clist, numbers, 1, i-1);
2229 stree_sort (GtkCMCTree *ctree,
2230 GtkCMCTreeNode *node,
2233 GtkCMCTreeNode *list_start, *work, *next;
2234 GPtrArray *row_array, *viewable_array;
2238 clist = GTK_CMCLIST (ctree);
2241 work = GTK_CMCTREE_ROW (node)->children;
2243 work = GTK_CMCTREE_NODE (clist->row_list);
2245 row_array = g_ptr_array_new();
2246 viewable_array = g_ptr_array_new();
2249 g_ptr_array_add( row_array, NULL);
2251 /* add all rows to row_array */
2252 g_ptr_array_add( row_array, work);
2253 if (GTK_CMCTREE_ROW (work)->parent && gtk_cmctree_is_viewable( ctree, work))
2254 g_ptr_array_add( viewable_array, GTK_CMCTREE_ROW (work)->parent);
2255 next = GTK_CMCTREE_ROW (work)->sibling;
2256 gtk_sctree_unlink( ctree, work, FALSE);
2260 heap_sort( clist, row_array, (row_array->len)-1);
2263 list_start = GTK_CMCTREE_ROW (node)->children;
2265 list_start = GTK_CMCTREE_NODE (clist->row_list);
2267 if (clist->sort_type == GTK_SORT_ASCENDING) {
2268 for (i=(row_array->len)-1; i>=1; i--) {
2269 work = g_ptr_array_index( row_array, i);
2270 gtk_sctree_link( ctree, work, node, list_start, FALSE);
2272 /* insert work at the beginning of the list */
2275 for (i=1; i<row_array->len; 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 */
2283 for (i=0; i<viewable_array->len; i++) {
2284 gtk_cmctree_expand( ctree, g_ptr_array_index( viewable_array, i));
2288 g_ptr_array_free( row_array, TRUE);
2289 g_ptr_array_free( viewable_array, TRUE);
2293 gtk_sctree_sort_recursive (GtkCMCTree *ctree,
2294 GtkCMCTreeNode *node)
2297 GtkCMCTreeNode *focus_node = NULL;
2299 cm_return_if_fail (ctree != NULL);
2300 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2302 clist = GTK_CMCLIST (ctree);
2304 gtk_cmclist_freeze (clist);
2306 if (clist->selection_mode == GTK_SELECTION_EXTENDED) {
2307 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2309 g_list_free (clist->undo_selection);
2310 g_list_free (clist->undo_unselection);
2311 clist->undo_selection = NULL;
2312 clist->undo_unselection = NULL;
2315 if (!node || (node && gtk_cmctree_is_viewable (ctree, node)))
2316 focus_node = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
2318 GTK_SCTREE(ctree)->sorting = TRUE;
2320 gtk_cmctree_post_recursive (ctree, node, GTK_CMCTREE_FUNC (stree_sort), NULL);
2323 stree_sort (ctree, NULL, NULL);
2325 GTK_SCTREE(ctree)->sorting = FALSE;
2328 clist->focus_row = g_list_position (clist->row_list,(GList *)focus_node);
2329 clist->undo_anchor = clist->focus_row;
2332 gtk_cmclist_thaw (clist);
2336 gtk_sctree_sort_node (GtkCMCTree *ctree,
2337 GtkCMCTreeNode *node)
2340 GtkCMCTreeNode *focus_node = NULL;
2342 cm_return_if_fail (ctree != NULL);
2343 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2345 clist = GTK_CMCLIST (ctree);
2347 gtk_cmclist_freeze (clist);
2349 if (clist->selection_mode == GTK_SELECTION_EXTENDED) {
2350 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2352 g_list_free (clist->undo_selection);
2353 g_list_free (clist->undo_unselection);
2354 clist->undo_selection = NULL;
2355 clist->undo_unselection = NULL;
2358 if (!node || (node && gtk_cmctree_is_viewable (ctree, node)))
2359 focus_node = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
2361 GTK_SCTREE(ctree)->sorting = TRUE;
2363 stree_sort (ctree, node, NULL);
2365 GTK_SCTREE(ctree)->sorting = FALSE;
2368 clist->focus_row = g_list_position (clist->row_list,(GList *)focus_node);
2369 clist->undo_anchor = clist->focus_row;
2372 gtk_cmclist_thaw (clist);
2375 /************************************************************************/
2378 gtk_sctree_unlink (GtkCMCTree *ctree,
2379 GtkCMCTreeNode *node,
2380 gboolean update_focus_row)
2386 GtkCMCTreeNode *work;
2387 GtkCMCTreeNode *parent;
2390 cm_return_if_fail (ctree != NULL);
2391 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2392 cm_return_if_fail (node != NULL);
2394 clist = GTK_CMCLIST (ctree);
2396 if (update_focus_row && clist->selection_mode == GTK_SELECTION_EXTENDED) {
2397 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2399 g_list_free (clist->undo_selection);
2400 g_list_free (clist->undo_unselection);
2401 clist->undo_selection = NULL;
2402 clist->undo_unselection = NULL;
2405 visible = gtk_cmctree_is_viewable (ctree, node);
2407 /* clist->row_list_end unlinked ? */
2408 if (visible && (GTK_CMCTREE_NODE_NEXT (node) == NULL ||
2409 (GTK_CMCTREE_ROW (node)->children && gtk_cmctree_is_ancestor (ctree, node,
2410 GTK_CMCTREE_NODE (clist->row_list_end)))))
2411 clist->row_list_end = (GList *) (GTK_CMCTREE_NODE_PREV (node));
2415 level = GTK_CMCTREE_ROW (node)->level;
2416 work = GTK_CMCTREE_NODE_NEXT (node);
2417 while (work && GTK_CMCTREE_ROW (work)->level > level) {
2418 work = GTK_CMCTREE_NODE_NEXT (work);
2423 clist->rows -= (rows + 1);
2425 if (update_focus_row) {
2427 pos = g_list_position (clist->row_list, (GList *)node);
2428 if (pos + rows < clist->focus_row)
2429 clist->focus_row -= (rows + 1);
2430 else if (pos <= clist->focus_row) {
2431 if (!GTK_CMCTREE_ROW (node)->sibling)
2432 clist->focus_row = MAX (pos - 1, 0);
2434 clist->focus_row = pos;
2436 clist->focus_row = MIN (clist->focus_row, clist->rows - 1);
2438 clist->undo_anchor = clist->focus_row;
2443 list = (GList *)GTK_CMCTREE_NODE_PREV (work);
2445 list = (GList *)work;
2446 list->prev = (GList *)GTK_CMCTREE_NODE_PREV (node);
2449 if (GTK_CMCTREE_NODE_PREV (node) &&
2450 GTK_CMCTREE_NODE_NEXT (GTK_CMCTREE_NODE_PREV (node)) == node) {
2451 list = (GList *)GTK_CMCTREE_NODE_PREV (node);
2452 list->next = (GList *)work;
2456 parent = GTK_CMCTREE_ROW (node)->parent;
2458 if (GTK_CMCTREE_ROW (parent)->children == node) {
2459 GTK_CMCTREE_ROW (parent)->children = GTK_CMCTREE_ROW (node)->sibling;
2462 GtkCMCTreeNode *sibling;
2464 sibling = GTK_CMCTREE_ROW (parent)->children;
2465 while (GTK_CMCTREE_ROW (sibling)->sibling != node)
2466 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
2467 GTK_CMCTREE_ROW (sibling)->sibling = GTK_CMCTREE_ROW (node)->sibling;
2471 if (clist->row_list == (GList *)node)
2472 clist->row_list = (GList *) (GTK_CMCTREE_ROW (node)->sibling);
2474 GtkCMCTreeNode *sibling;
2476 sibling = GTK_CMCTREE_NODE (clist->row_list);
2477 while (GTK_CMCTREE_ROW (sibling)->sibling != node)
2478 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
2479 GTK_CMCTREE_ROW (sibling)->sibling = GTK_CMCTREE_ROW (node)->sibling;
2485 gtk_sctree_link (GtkCMCTree *ctree,
2486 GtkCMCTreeNode *node,
2487 GtkCMCTreeNode *parent,
2488 GtkCMCTreeNode *sibling,
2489 gboolean update_focus_row)
2495 gboolean visible = FALSE;
2499 cm_return_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent);
2500 cm_return_if_fail (node != NULL);
2501 cm_return_if_fail (node != sibling);
2502 cm_return_if_fail (node != parent);
2504 clist = GTK_CMCLIST (ctree);
2506 if (update_focus_row && clist->selection_mode == GTK_SELECTION_EXTENDED) {
2507 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2509 g_list_free (clist->undo_selection);
2510 g_list_free (clist->undo_unselection);
2511 clist->undo_selection = NULL;
2512 clist->undo_unselection = NULL;
2515 for (rows = 1, list_end = (GList *)node; list_end->next;
2516 list_end = list_end->next)
2519 GTK_CMCTREE_ROW (node)->parent = parent;
2520 GTK_CMCTREE_ROW (node)->sibling = sibling;
2522 if (!parent || (parent && (gtk_cmctree_is_viewable (ctree, parent) &&
2523 GTK_CMCTREE_ROW (parent)->expanded))) {
2525 clist->rows += rows;
2529 work = (GList *)(GTK_CMCTREE_ROW (parent)->children);
2531 work = clist->row_list;
2534 if (work != (GList *)sibling) {
2535 while (GTK_CMCTREE_ROW (work)->sibling != sibling)
2536 work = (GList *)(GTK_CMCTREE_ROW (work)->sibling);
2537 GTK_CMCTREE_ROW (work)->sibling = node;
2540 if (sibling == GTK_CMCTREE_NODE (clist->row_list))
2541 clist->row_list = (GList *) node;
2542 if (GTK_CMCTREE_NODE_PREV (sibling) &&
2543 GTK_CMCTREE_NODE_NEXT (GTK_CMCTREE_NODE_PREV (sibling)) == sibling) {
2544 list = (GList *)GTK_CMCTREE_NODE_PREV (sibling);
2545 list->next = (GList *)node;
2548 list = (GList *)node;
2549 list->prev = (GList *)GTK_CMCTREE_NODE_PREV (sibling);
2550 list_end->next = (GList *)sibling;
2551 list = (GList *)sibling;
2552 list->prev = list_end;
2553 if (parent && GTK_CMCTREE_ROW (parent)->children == sibling)
2554 GTK_CMCTREE_ROW (parent)->children = node;
2559 while (GTK_CMCTREE_ROW (work)->sibling)
2560 work = (GList *)(GTK_CMCTREE_ROW (work)->sibling);
2561 GTK_CMCTREE_ROW (work)->sibling = node;
2563 /* find last visible child of sibling */
2564 work = (GList *) gtk_sctree_last_visible (ctree,
2565 GTK_CMCTREE_NODE (work));
2567 list_end->next = work->next;
2569 list = work->next->prev = list_end;
2570 work->next = (GList *)node;
2571 list = (GList *)node;
2576 GTK_CMCTREE_ROW (parent)->children = node;
2577 list = (GList *)node;
2578 list->prev = (GList *)parent;
2579 if (GTK_CMCTREE_ROW (parent)->expanded) {
2580 list_end->next = (GList *)GTK_CMCTREE_NODE_NEXT (parent);
2581 if (GTK_CMCTREE_NODE_NEXT(parent)) {
2582 list = (GList *)GTK_CMCTREE_NODE_NEXT (parent);
2583 list->prev = list_end;
2585 list = (GList *)parent;
2586 list->next = (GList *)node;
2589 list_end->next = NULL;
2592 clist->row_list = (GList *)node;
2593 list = (GList *)node;
2595 list_end->next = NULL;
2600 gtk_cmctree_pre_recursive (ctree, node, stree_update_level, NULL);
2602 if (clist->row_list_end == NULL ||
2603 clist->row_list_end->next == (GList *)node)
2604 clist->row_list_end = list_end;
2606 if (visible && update_focus_row) {
2608 pos = g_list_position (clist->row_list, (GList *)node);
2610 if (pos <= clist->focus_row) {
2611 clist->focus_row += rows;
2612 clist->undo_anchor = clist->focus_row;
2618 stree_update_level (GtkCMCTree *ctree,
2619 GtkCMCTreeNode *node,
2625 if (GTK_CMCTREE_ROW (node)->parent)
2626 GTK_CMCTREE_ROW (node)->level =
2627 GTK_CMCTREE_ROW (GTK_CMCTREE_ROW (node)->parent)->level + 1;
2629 GTK_CMCTREE_ROW (node)->level = 1;
2632 static GtkCMCTreeNode *
2633 gtk_sctree_last_visible (GtkCMCTree *ctree,
2634 GtkCMCTreeNode *node)
2636 GtkCMCTreeNode *work;
2641 work = GTK_CMCTREE_ROW (node)->children;
2643 if (!work || !GTK_CMCTREE_ROW (node)->expanded)
2646 while (GTK_CMCTREE_ROW (work)->sibling)
2647 work = GTK_CMCTREE_ROW (work)->sibling;
2649 return gtk_sctree_last_visible (ctree, work);
2653 sset_node_info (GtkCMCTree *ctree,
2654 GtkCMCTreeNode *node,
2657 GdkPixbuf *pixbuf_closed,
2658 GdkPixbuf *pixbuf_opened,
2662 if (GTK_CMCTREE_ROW (node)->pixbuf_opened)
2664 g_object_unref (GTK_CMCTREE_ROW (node)->pixbuf_opened);
2666 if (GTK_CMCTREE_ROW (node)->pixbuf_closed)
2668 g_object_unref (GTK_CMCTREE_ROW (node)->pixbuf_closed);
2671 GTK_CMCTREE_ROW (node)->pixbuf_opened = NULL;
2672 GTK_CMCTREE_ROW (node)->pixbuf_closed = NULL;
2676 GTK_CMCTREE_ROW (node)->pixbuf_closed = g_object_ref (pixbuf_closed);
2680 GTK_CMCTREE_ROW (node)->pixbuf_opened = g_object_ref (pixbuf_opened);
2683 GTK_CMCTREE_ROW (node)->is_leaf = is_leaf;
2684 GTK_CMCTREE_ROW (node)->expanded = (is_leaf) ? FALSE : expanded;
2686 if (GTK_CMCTREE_ROW (node)->expanded)
2687 gtk_cmctree_node_set_pixtext (ctree, node, ctree->tree_column,
2688 text, spacing, pixbuf_opened);
2690 gtk_cmctree_node_set_pixtext (ctree, node, ctree->tree_column,
2691 text, spacing, pixbuf_closed);
2695 stree_draw_node (GtkCMCTree *ctree,
2696 GtkCMCTreeNode *node)
2700 clist = GTK_CMCLIST (ctree);
2702 if (CLIST_UNFROZEN (clist) && gtk_cmctree_is_viewable (ctree, node))
2704 GtkCMCTreeNode *work;
2707 work = GTK_CMCTREE_NODE (clist->row_list);
2708 while (work && work != node)
2710 work = GTK_CMCTREE_NODE_NEXT (work);
2713 if (work && gtk_cmclist_row_is_visible (clist, num) != GTK_VISIBILITY_NONE)
2714 GTK_CMCLIST_GET_CLASS (clist)->draw_row
2715 (clist, NULL, num, GTK_CMCLIST_ROW ((GList *) node));
2719 /* this wrapper simply replaces NULL pixbufs
2720 * with a transparent, 1x1 pixbuf. This works
2721 * around a memory problem deep inside gtk,
2722 * revealed by valgrind.
2724 void gtk_sctree_set_node_info (GtkCMCTree *ctree,
2725 GtkCMCTreeNode *node,
2728 GdkPixbuf *pixbuf_closed,
2729 GdkPixbuf *pixbuf_opened,
2734 gboolean old_expanded;
2735 GtkCMCTreeNode *work;
2737 if (!GTK_IS_CMCTREE (ctree) || !node) return;
2739 old_leaf = GTK_CMCTREE_ROW (node)->is_leaf;
2740 old_expanded = GTK_CMCTREE_ROW (node)->expanded;
2742 if (is_leaf && (work = GTK_CMCTREE_ROW (node)->children) != NULL)
2744 GtkCMCTreeNode *ptr;
2749 work = GTK_CMCTREE_ROW (work)->sibling;
2750 gtk_cmctree_remove_node (ctree, ptr);
2754 sset_node_info (ctree, node, text, spacing, pixbuf_closed,
2755 pixbuf_opened, is_leaf, expanded);
2757 if (!is_leaf && !old_leaf)
2759 GTK_CMCTREE_ROW (node)->expanded = old_expanded;
2760 if (expanded && !old_expanded)
2761 gtk_cmctree_expand (ctree, node);
2762 else if (!expanded && old_expanded)
2763 gtk_cmctree_collapse (ctree, node);
2766 GTK_CMCTREE_ROW (node)->expanded = (is_leaf) ? FALSE : expanded;
2768 stree_draw_node (ctree, node);
2771 static GtkCMCTreeRow *
2772 srow_new (GtkCMCTree *ctree)
2775 GtkCMCTreeRow *ctree_row;
2778 clist = GTK_CMCLIST (ctree);
2779 #if GLIB_CHECK_VERSION(2,10,0)
2780 ctree_row = g_slice_new (GtkCMCTreeRow);
2781 ctree_row->row.cell = g_slice_alloc (sizeof (GtkCMCell) * clist->columns);
2783 ctree_row = g_chunk_new (GtkCMCTreeRow, (GMemChunk *)clist->row_mem_chunk);
2784 ctree_row->row.cell = g_chunk_new (GtkCMCell, (GMemChunk *)clist->cell_mem_chunk);
2786 for (i = 0; i < clist->columns; i++)
2788 ctree_row->row.cell[i].type = GTK_CMCELL_EMPTY;
2789 ctree_row->row.cell[i].vertical = 0;
2790 ctree_row->row.cell[i].horizontal = 0;
2791 ctree_row->row.cell[i].style = NULL;
2794 GTK_CMCELL_PIXTEXT (ctree_row->row.cell[ctree->tree_column])->text = NULL;
2796 ctree_row->row.fg_set = FALSE;
2797 ctree_row->row.bg_set = FALSE;
2798 ctree_row->row.style = NULL;
2799 ctree_row->row.selectable = TRUE;
2800 ctree_row->row.state = GTK_STATE_NORMAL;
2801 ctree_row->row.data = NULL;
2802 ctree_row->row.destroy = NULL;
2804 ctree_row->level = 0;
2805 ctree_row->expanded = FALSE;
2806 ctree_row->parent = NULL;
2807 ctree_row->sibling = NULL;
2808 ctree_row->children = NULL;
2809 ctree_row->pixbuf_closed = NULL;
2810 ctree_row->pixbuf_opened = NULL;
2816 srow_delete (GtkCMCTree *ctree,
2817 GtkCMCTreeRow *ctree_row)
2822 clist = GTK_CMCLIST (ctree);
2824 for (i = 0; i < clist->columns; i++)
2826 GTK_CMCLIST_GET_CLASS (clist)->set_cell_contents
2827 (clist, &(ctree_row->row), i, GTK_CMCELL_EMPTY, NULL, 0, NULL);
2828 if (ctree_row->row.cell[i].style)
2830 if (GTK_WIDGET_REALIZED (ctree))
2831 gtk_style_detach (ctree_row->row.cell[i].style);
2832 g_object_unref (ctree_row->row.cell[i].style);
2836 if (ctree_row->row.style)
2838 if (GTK_WIDGET_REALIZED (ctree))
2839 gtk_style_detach (ctree_row->row.style);
2840 g_object_unref (ctree_row->row.style);
2843 if (ctree_row->pixbuf_closed)
2845 g_object_unref (ctree_row->pixbuf_closed);
2848 if (ctree_row->pixbuf_opened)
2850 g_object_unref (ctree_row->pixbuf_opened);
2853 if (ctree_row->row.destroy)
2855 GDestroyNotify dnotify = ctree_row->row.destroy;
2856 gpointer ddata = ctree_row->row.data;
2858 ctree_row->row.destroy = NULL;
2859 ctree_row->row.data = NULL;
2864 #if GLIB_CHECK_VERSION(2,10,0)
2865 g_slice_free1 (sizeof (GtkCMCell) * clist->columns, ctree_row->row.cell);
2866 g_slice_free (GtkCMCTreeRow, ctree_row);
2868 g_mem_chunk_free ((GMemChunk *)clist->cell_mem_chunk, ctree_row->row.cell);
2869 g_mem_chunk_free ((GMemChunk *)clist->row_mem_chunk, ctree_row);
2874 stree_delete_row (GtkCMCTree *ctree,
2875 GtkCMCTreeNode *node,
2878 srow_delete (ctree, GTK_CMCTREE_ROW (node));
2879 g_list_free_1 ((GList *)node);
2883 gtk_sctree_real_tree_expand (GtkCMCTree *ctree,
2884 GtkCMCTreeNode *node)
2887 GtkCMCTreeNode *work;
2888 GtkRequisition requisition;
2892 cm_return_if_fail (GTK_IS_CMCTREE (ctree));
2894 if (!node || GTK_CMCTREE_ROW (node)->expanded || GTK_CMCTREE_ROW (node)->is_leaf)
2897 clist = GTK_CMCLIST (ctree);
2899 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
2901 GTK_CMCTREE_ROW (node)->expanded = TRUE;
2902 level = GTK_CMCTREE_ROW (node)->level;
2904 visible = gtk_cmctree_is_viewable (ctree, node);
2905 /* get cell width if tree_column is auto resized */
2906 if (visible && clist->column[ctree->tree_column].auto_resize &&
2907 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2908 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2909 (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column, &requisition);
2911 /* unref/unset closed pixbuf */
2912 if (GTK_CMCELL_PIXTEXT
2913 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf)
2917 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf);
2920 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf = NULL;
2923 /* set/ref opened pixbuf */
2924 if (GTK_CMCTREE_ROW (node)->pixbuf_opened)
2927 (GTK_CMCTREE_ROW (node)->row.cell[ctree->tree_column])->pixbuf =
2928 g_object_ref (GTK_CMCTREE_ROW (node)->pixbuf_opened);
2932 work = GTK_CMCTREE_ROW (node)->children;
2935 GList *list = (GList *)work;
2936 gint *cell_width = NULL;
2941 if (visible && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2943 cell_width = g_new0 (gint, clist->columns);
2944 if (clist->column[ctree->tree_column].auto_resize)
2945 cell_width[ctree->tree_column] = requisition.width;
2949 /* search maximum cell widths of auto_resize columns */
2950 for (i = 0; i < clist->columns; i++)
2951 if (clist->column[i].auto_resize)
2953 GTK_CMCLIST_GET_CLASS (clist)->cell_size_request
2954 (clist, >K_CMCTREE_ROW (work)->row, i, &requisition);
2955 cell_width[i] = MAX (requisition.width, cell_width[i]);
2958 list = (GList *)work;
2959 work = GTK_CMCTREE_NODE_NEXT (work);
2966 list = (GList *)work;
2967 work = GTK_CMCTREE_NODE_NEXT (work);
2971 list->next = (GList *)GTK_CMCTREE_NODE_NEXT (node);
2973 if (GTK_CMCTREE_NODE_NEXT (node))
2977 if (clist->row_list_end == list)
2978 clist->row_list_end = g_list_last(list);
2980 tmp_list = (GList *)GTK_CMCTREE_NODE_NEXT (node);
2981 tmp_list->prev = list;
2984 clist->row_list_end = list;
2986 list = (GList *)node;
2987 list->next = (GList *)(GTK_CMCTREE_ROW (node)->children);
2989 if (visible && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist))
2991 /* resize auto_resize columns if needed */
2992 for (i = 0; i < clist->columns; i++)
2993 if (clist->column[i].auto_resize &&
2994 cell_width[i] > clist->column[i].width)
2995 gtk_cmclist_set_column_width (clist, i, cell_width[i]);
2996 g_free (cell_width);
2998 if (!GTK_SCTREE(ctree)->sorting) {
2999 /* update focus_row position */
3000 row = g_list_position (clist->row_list, (GList *)node);
3001 if (row < clist->focus_row)
3002 clist->focus_row += tmp;
3005 CLIST_REFRESH (clist);
3008 else if (visible && clist->column[ctree->tree_column].auto_resize)
3009 /* resize tree_column if needed */
3010 gtk_sctree_column_auto_resize (clist, >K_CMCTREE_ROW (node)->row, ctree->tree_column,
3016 gtk_sctree_insert_node (GtkCMCTree *ctree,
3017 GtkCMCTreeNode *parent,
3018 GtkCMCTreeNode *sibling,
3021 GdkPixbuf *pixbuf_closed,
3022 GdkPixbuf *pixbuf_opened,
3027 GtkCMCTreeRow *new_row;
3028 GtkCMCTreeNode *node;
3032 cm_return_val_if_fail (GTK_IS_CMCTREE (ctree), NULL);
3034 cm_return_val_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent, NULL);
3036 if (parent && GTK_CMCTREE_ROW (parent)->is_leaf)
3039 clist = GTK_CMCLIST (ctree);
3041 /* create the row */
3042 new_row = srow_new (ctree);
3043 list = g_list_alloc ();
3044 list->data = new_row;
3045 node = GTK_CMCTREE_NODE (list);
3048 for (i = 0; i < clist->columns; i++)
3049 if (text[i] && i != ctree->tree_column)
3050 GTK_CMCLIST_GET_CLASS (clist)->set_cell_contents
3051 (clist, &(new_row->row), i, GTK_CMCELL_TEXT, text[i], 0, NULL);
3053 sset_node_info (ctree, node, text ?
3054 text[ctree->tree_column] : NULL, spacing, pixbuf_closed,
3055 pixbuf_opened, is_leaf, expanded);
3057 /* sorted insertion */
3058 if (GTK_CMCLIST_AUTO_SORT (clist))
3061 sibling = GTK_CMCTREE_ROW (parent)->children;
3063 sibling = GTK_CMCTREE_NODE (clist->row_list);
3065 while (sibling && clist->compare
3066 (clist, GTK_CMCTREE_ROW (node), GTK_CMCTREE_ROW (sibling)) > 0)
3067 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
3070 gtk_sctree_link (ctree, node, parent, sibling, FALSE);
3072 if (text && !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist) &&
3073 gtk_cmctree_is_viewable (ctree, node))
3075 for (i = 0; i < clist->columns; i++)
3076 if (clist->column[i].auto_resize)
3077 gtk_sctree_column_auto_resize (clist, &(new_row->row), i, 0);
3080 if (clist->rows == 1)
3082 clist->focus_row = 0;
3083 if (clist->selection_mode == GTK_SELECTION_BROWSE)
3084 gtk_sctree_select (GTK_SCTREE(ctree), node);
3088 CLIST_REFRESH (clist);
3094 gtk_sctree_insert_gnode (GtkCMCTree *ctree,
3095 GtkCMCTreeNode *parent,
3096 GtkCMCTreeNode *sibling,
3098 GtkCMCTreeGNodeFunc func,
3102 GtkCMCTreeNode *cnode = NULL;
3103 GtkCMCTreeNode *child = NULL;
3104 GtkCMCTreeNode *new_child;
3109 cm_return_val_if_fail (GTK_IS_CMCTREE (ctree), NULL);
3110 cm_return_val_if_fail (gnode != NULL, NULL);
3111 cm_return_val_if_fail (func != NULL, NULL);
3113 cm_return_val_if_fail (GTK_CMCTREE_ROW (sibling)->parent == parent, NULL);
3115 clist = GTK_CMCLIST (ctree);
3118 depth = GTK_CMCTREE_ROW (parent)->level + 1;
3120 list = g_list_alloc ();
3121 list->data = srow_new (ctree);
3122 cnode = GTK_CMCTREE_NODE (list);
3124 gtk_cmclist_freeze (clist);
3126 sset_node_info (ctree, cnode, "", 0, NULL, NULL, TRUE, FALSE);
3128 if (!func (ctree, depth, gnode, cnode, data))
3130 stree_delete_row (ctree, cnode, NULL);
3131 gtk_cmclist_thaw (clist);
3135 if (GTK_CMCLIST_AUTO_SORT (clist))
3138 sibling = GTK_CMCTREE_ROW (parent)->children;
3140 sibling = GTK_CMCTREE_NODE (clist->row_list);
3142 while (sibling && clist->compare
3143 (clist, GTK_CMCTREE_ROW (cnode), GTK_CMCTREE_ROW (sibling)) > 0)
3144 sibling = GTK_CMCTREE_ROW (sibling)->sibling;
3147 gtk_sctree_link (ctree, cnode, parent, sibling, FALSE);
3149 for (work = g_node_last_child (gnode); work; work = work->prev)
3151 new_child = gtk_sctree_insert_gnode (ctree, cnode, child,
3157 gtk_cmclist_thaw (clist);
3163 sreal_tree_move (GtkCMCTree *ctree,
3164 GtkCMCTreeNode *node,
3165 GtkCMCTreeNode *new_parent,
3166 GtkCMCTreeNode *new_sibling)
3169 GtkCMCTreeNode *work;
3170 gboolean visible = FALSE;
3172 cm_return_if_fail (ctree != NULL);
3173 cm_return_if_fail (node != NULL);
3174 cm_return_if_fail (!new_sibling ||
3175 GTK_CMCTREE_ROW (new_sibling)->parent == new_parent);
3177 if (new_parent && GTK_CMCTREE_ROW (new_parent)->is_leaf)
3180 /* new_parent != child of child */
3181 for (work = new_parent; work; work = GTK_CMCTREE_ROW (work)->parent)
3185 clist = GTK_CMCLIST (ctree);
3187 visible = gtk_cmctree_is_viewable (ctree, node);
3189 if (clist->selection_mode == GTK_SELECTION_MULTIPLE)
3191 GTK_CMCLIST_GET_CLASS (clist)->resync_selection (clist, NULL);
3193 g_list_free (clist->undo_selection);
3194 g_list_free (clist->undo_unselection);
3195 clist->undo_selection = NULL;
3196 clist->undo_unselection = NULL;
3199 if (GTK_CMCLIST_AUTO_SORT (clist))
3201 if (new_parent == GTK_CMCTREE_ROW (node)->parent)
3205 new_sibling = GTK_CMCTREE_ROW (new_parent)->children;
3207 new_sibling = GTK_CMCTREE_NODE (clist->row_list);
3209 while (new_sibling && clist->compare
3210 (clist, GTK_CMCTREE_ROW (node), GTK_CMCTREE_ROW (new_sibling)) > 0)
3211 new_sibling = GTK_CMCTREE_ROW (new_sibling)->sibling;
3214 if (new_parent == GTK_CMCTREE_ROW (node)->parent &&
3215 new_sibling == GTK_CMCTREE_ROW (node)->sibling)
3218 gtk_cmclist_freeze (clist);
3222 if (!GTK_SCTREE(ctree)->sorting && gtk_cmctree_is_viewable (ctree, node))
3223 work = GTK_CMCTREE_NODE (g_list_nth (clist->row_list, clist->focus_row));
3225 gtk_sctree_unlink (ctree, node, FALSE);
3226 gtk_sctree_link (ctree, node, new_parent, new_sibling, FALSE);
3228 if (!GTK_SCTREE(ctree)->sorting && work)
3230 while (work && !gtk_cmctree_is_viewable (ctree, work))
3231 work = GTK_CMCTREE_ROW (work)->parent;
3232 clist->focus_row = g_list_position (clist->row_list, (GList *)work);
3233 clist->undo_anchor = clist->focus_row;
3236 if (clist->column[ctree->tree_column].auto_resize &&
3237 !GTK_CMCLIST_AUTO_RESIZE_BLOCKED (clist) &&
3238 (visible || gtk_cmctree_is_viewable (ctree, node)))
3239 gtk_cmclist_set_column_width
3240 (clist, ctree->tree_column,
3241 gtk_cmclist_optimal_column_width (clist, ctree->tree_column));
3243 gtk_cmclist_thaw (clist);
3246 void gtk_sctree_set_column_tooltip (GtkSCTree *sctree,
3250 #if !(GTK_CHECK_VERSION(2,12,0))
3252 if (!sctree->tooltips)
3253 sctree->tooltips = gtk_tooltips_new();
3254 tips = sctree->tooltips;
3257 CLAWS_SET_TIP(GTK_CMCLIST(sctree)->column[column].button,