use cairo for drawing
[geeqie.git] / src / ui_tree_edit.c
1 /*
2  * (SLIK) SimpLIstic sKin functions
3  * (C) 2004 John Ellis
4  * Copyright (C) 2008 - 2012 The Geeqie Team
5  *
6  * Author: John Ellis
7  *
8  * This software is released under the GNU General Public License (GNU GPL).
9  * Please read the included file COPYING for more information.
10  * This software comes with no warranty of any kind, use at your own risk!
11  */
12
13 #ifdef HAVE_CONFIG_H
14 #  include "config.h"
15 #endif
16 #include "intl.h"
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21
22 #include <gtk/gtk.h>
23 #include <gdk/gdkkeysyms.h>
24
25 #include "ui_tree_edit.h"
26
27 /*
28  *-------------------------------------------------------------------
29  * cell popup editor
30  *-------------------------------------------------------------------
31  */
32
33 static void tree_edit_close(TreeEditData *ted)
34 {
35         gtk_grab_remove(ted->window);
36         gdk_keyboard_ungrab(GDK_CURRENT_TIME);
37         gdk_pointer_ungrab(GDK_CURRENT_TIME);
38
39         gtk_widget_destroy(ted->window);
40
41         g_free(ted->old_name);
42         g_free(ted->new_name);
43         gtk_tree_path_free(ted->path);
44
45         g_free(ted);
46 }
47
48 static void tree_edit_do(TreeEditData *ted)
49 {
50         ted->new_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(ted->entry)));
51
52         if (strcmp(ted->new_name, ted->old_name) != 0)
53                 {
54                 if (ted->edit_func)
55                         {
56                         if (ted->edit_func(ted, ted->old_name, ted->new_name, ted->edit_data))
57                                 {
58                                 /* hmm, should the caller be required to set text instead ? */
59                                 }
60                         }
61                 }
62 }
63
64 static gboolean tree_edit_click_end_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
65 {
66         TreeEditData *ted = data;
67
68         tree_edit_do(ted);
69         tree_edit_close(ted);
70
71         return TRUE;
72 }
73
74 static gboolean tree_edit_click_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
75 {
76         TreeEditData *ted = data;
77         GdkWindow *window = gtk_widget_get_window(ted->window);
78
79         gint x, y;
80         gint w, h;
81
82         gint xr, yr;
83
84         xr = (gint)event->x_root;
85         yr = (gint)event->y_root;
86
87         gdk_window_get_origin(window, &x, &y);
88         w = gdk_window_get_width(window);
89         h = gdk_window_get_height(window);
90
91         if (xr < x || yr < y || xr > x + w || yr > y + h)
92                 {
93                 /* gobble the release event, so it does not propgate to an underlying widget */
94                 g_signal_connect(G_OBJECT(ted->window), "button_release_event",
95                                  G_CALLBACK(tree_edit_click_end_cb), ted);
96                 return TRUE;
97                 }
98         return FALSE;
99 }
100
101 static gboolean tree_edit_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
102 {
103         TreeEditData *ted = data;
104
105         switch (event->keyval)
106                 {
107                 case GDK_Return:
108                 case GDK_KP_Enter:
109                 case GDK_Tab:           /* ok, we are going to intercept the focus change
110                                            from keyboard and act like return was hit */
111                 case GDK_ISO_Left_Tab:
112                 case GDK_Up:
113                 case GDK_Down:
114                 case GDK_KP_Up:
115                 case GDK_KP_Down:
116                 case GDK_KP_Left:
117                 case GDK_KP_Right:
118                         tree_edit_do(ted);
119                         tree_edit_close(ted);
120                         break;
121                 case GDK_Escape:
122                         tree_edit_close(ted);
123                         break;
124                 default:
125                         break;
126                 }
127
128         return FALSE;
129 }
130
131 static gboolean tree_edit_by_path_idle_cb(gpointer data)
132 {
133         TreeEditData *ted = data;
134         GdkRectangle rect;
135         gint x, y, w, h;        /* geometry of cell within tree */
136         gint wx, wy;            /* geometry of tree from root window */
137         gint sx, sw;
138
139         gtk_tree_view_get_cell_area(ted->tree, ted->path, ted->column, &rect);
140
141         x = rect.x;
142         y = rect.y;
143         w = rect.width + 4;
144         h = rect.height + 4;
145
146         if (gtk_tree_view_column_cell_get_position(ted->column, ted->cell, &sx, &sw))
147                 {
148                 x += sx;
149                 w = MAX(w - sx, sw);
150                 }
151
152         gdk_window_get_origin(gtk_tree_view_get_bin_window(ted->tree), &wx, &wy);
153
154         x += wx - 2; /* the -val is to 'fix' alignment of entry position */
155         y += wy - 2;
156
157         /* now show it */
158         gtk_widget_set_size_request(ted->window, w, h);
159         gtk_widget_realize(ted->window);
160         gtk_window_move(GTK_WINDOW(ted->window), x, y);
161         gtk_window_resize(GTK_WINDOW(ted->window), w, h);
162         gtk_widget_show(ted->window);
163
164         /* grab it */
165         gtk_widget_grab_focus(ted->entry);
166         /* explicitely set the focus flag for the entry, for some reason on popup windows this
167          * is not set, and causes no edit cursor to appear ( popups not allowed focus? )
168          */
169         gtk_widget_grab_focus(ted->entry);
170         gtk_grab_add(ted->window);
171         gdk_pointer_grab(gtk_widget_get_window(ted->window), TRUE,
172                          GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK,
173                          NULL, NULL, GDK_CURRENT_TIME);
174         gdk_keyboard_grab(gtk_widget_get_window(ted->window), TRUE, GDK_CURRENT_TIME);
175
176         return FALSE;
177 }
178
179 gboolean tree_edit_by_path(GtkTreeView *tree, GtkTreePath *tpath, gint column, const gchar *text,
180                            gboolean (*edit_func)(TreeEditData *, const gchar *, const gchar *, gpointer), gpointer data)
181 {
182         TreeEditData *ted;
183         GtkTreeViewColumn *tcolumn;
184         GtkCellRenderer *cell = NULL;
185         GList *list;
186         GList *work;
187
188         if (!edit_func) return FALSE;
189 #if GTK_CHECK_VERSION(2,20,0)
190         if (!gtk_widget_get_visible(GTK_WIDGET(tree))) return FALSE;
191 #else
192         if (!GTK_WIDGET_VISIBLE(tree)) return FALSE;
193 #endif
194
195         tcolumn = gtk_tree_view_get_column(tree, column);
196         if (!tcolumn) return FALSE;
197
198 #if GTK_CHECK_VERSION(2,18,0)
199         list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(tcolumn));
200 #else
201         list = gtk_tree_view_column_get_cell_renderers(tcolumn);
202 #endif
203         work = list;
204         while (work && !cell)
205                 {
206                 cell = work->data;
207                 if (!GTK_IS_CELL_RENDERER_TEXT(cell))
208                         {
209                         cell = NULL;
210                         }
211                 work = work->next;
212                 }
213
214         g_list_free(list);
215         if (!cell) return FALSE;
216
217         if (!text) text = "";
218
219         ted = g_new0(TreeEditData, 1);
220
221         ted->old_name = g_strdup(text);
222
223         ted->edit_func = edit_func;
224         ted->edit_data = data;
225
226         ted->tree = tree;
227         ted->path = gtk_tree_path_copy(tpath);
228         ted->column = tcolumn;
229         ted->cell = cell;
230
231         gtk_tree_view_scroll_to_cell(ted->tree, ted->path, ted->column, FALSE, 0.0, 0.0);
232
233         /* create the window */
234
235         ted->window = gtk_window_new(GTK_WINDOW_POPUP);
236         gtk_window_set_resizable(GTK_WINDOW(ted->window), FALSE);
237         g_signal_connect(G_OBJECT(ted->window), "button_press_event",
238                          G_CALLBACK(tree_edit_click_cb), ted);
239         g_signal_connect(G_OBJECT(ted->window), "key_press_event",
240                          G_CALLBACK(tree_edit_key_press_cb), ted);
241
242         ted->entry = gtk_entry_new();
243         gtk_entry_set_text(GTK_ENTRY(ted->entry), ted->old_name);
244         gtk_editable_select_region(GTK_EDITABLE(ted->entry), 0, strlen(ted->old_name));
245         gtk_container_add(GTK_CONTAINER(ted->window), ted->entry);
246         gtk_widget_show(ted->entry);
247
248         /* due to the fact that gtktreeview scrolls in an idle loop, we cannot
249          * reliably get the cell position until those scroll priority signals are processed
250          */
251         g_idle_add_full(G_PRIORITY_DEFAULT_IDLE - 2, tree_edit_by_path_idle_cb, ted, NULL);
252
253         return TRUE;
254 }
255
256 /*
257  *-------------------------------------------------------------------
258  * tree cell position retrieval
259  *-------------------------------------------------------------------
260  */
261
262 gboolean tree_view_get_cell_origin(GtkTreeView *widget, GtkTreePath *tpath, gint column, gboolean text_cell_only,
263                                    gint *x, gint *y, gint *width, gint *height)
264 {
265         gint x_origin, y_origin;
266         gint x_offset, y_offset;
267         gint header_size;
268         GtkTreeViewColumn *tv_column;
269         GdkRectangle rect;
270
271         tv_column = gtk_tree_view_get_column(widget, column);
272         if (!tv_column || !tpath) return FALSE;
273
274         /* hmm, appears the rect will not account for X scroll, but does for Y scroll
275          * use x_offset instead for X scroll (sigh)
276          */
277         gtk_tree_view_get_cell_area(widget, tpath, tv_column, &rect);
278 #if GTK_CHECK_VERSION(2,12,0)
279         gtk_tree_view_convert_tree_to_widget_coords(widget, 0, 0, &x_offset, &y_offset);
280 #else
281         gtk_tree_view_tree_to_widget_coords(widget, 0, 0, &x_offset, &y_offset);
282 #endif
283         gdk_window_get_origin(gtk_widget_get_window(GTK_WIDGET(widget)), &x_origin, &y_origin);
284
285         if (gtk_tree_view_get_headers_visible(widget))
286                 {
287                 GtkAllocation allocation;
288 #if GTK_CHECK_VERSION(3,0,0)
289                 gtk_widget_get_allocation(gtk_tree_view_column_get_button(tv_column), &allocation);
290 #else
291                 gtk_widget_get_allocation(tv_column->button, &allocation);
292 #endif
293                 header_size = allocation.height;
294                 }
295         else
296                 {
297                 header_size = 0;
298                 }
299
300         if (text_cell_only)
301                 {
302                 GtkCellRenderer *cell = NULL;
303                 GList *renderers;
304                 GList *work;
305                 gint cell_x;
306                 gint cell_width;
307
308 #if GTK_CHECK_VERSION(2,18,0)
309                 renderers = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(tv_column));
310 #else
311                 renderers = gtk_tree_view_column_get_cell_renderers(tv_column);
312 #endif
313                 work = renderers;
314                 while (work && !cell)
315                         {
316                         cell = work->data;
317                         work = work->next;
318                         if (!GTK_IS_CELL_RENDERER_TEXT(cell)) cell = NULL;
319                         }
320                 g_list_free(renderers);
321
322                 if (!cell) return FALSE;
323
324                 if (!gtk_tree_view_column_cell_get_position(tv_column, cell, &cell_x, &cell_width))
325                         {
326                         cell_x = 0;
327                         cell_width = rect.width;
328                         }
329                 *x = x_origin + x_offset + rect.x + cell_x;
330                 *width = cell_width;
331                 }
332         else
333                 {
334                 *x = x_origin + x_offset + rect.x;
335                 *width = rect.width;
336                 }
337         *y = y_origin + rect.y + header_size;
338         *height = rect.height;
339         return TRUE;
340 }
341
342 void tree_view_get_cell_clamped(GtkTreeView *widget, GtkTreePath *tpath, gint column, gboolean text_cell_only,
343                                 gint *x, gint *y, gint *width, gint *height)
344 {
345         gint wx, wy, ww, wh;
346         GdkWindow *window;
347
348         window = gtk_widget_get_window(GTK_WIDGET(widget));
349         gdk_window_get_origin(window, &wx, &wy);
350
351         ww = gdk_window_get_width(window);
352         wh = gdk_window_get_height(window);
353
354         if (!tree_view_get_cell_origin(widget, tpath, column, text_cell_only, x,  y, width, height))
355                 {
356                 *x = wx;
357                 *y = wy;
358                 *width = ww;
359                 *height = wh;
360                 return;
361                 }
362
363         *width = MIN(*width, ww);
364         *x = CLAMP(*x, wx, wx + ww - (*width));
365         *y = CLAMP(*y, wy, wy + wh);
366         *height = MIN(*height, wy + wh - (*y));
367 }
368
369 #if GTK_CHECK_VERSION(2,8,0)
370 /* an implementation that uses gtk_tree_view_get_visible_range */
371 gint tree_view_row_get_visibility(GtkTreeView *widget, GtkTreeIter *iter, gboolean fully_visible)
372 {
373         GtkTreeModel *store;
374         GtkTreePath *tpath, *start_path, *end_path;
375         gint ret = 0;
376
377         if (!gtk_tree_view_get_visible_range(widget, &start_path, &end_path)) return -1; /* we will most probably scroll down, needed for tree_view_row_make_visible */
378
379         store = gtk_tree_view_get_model(widget);
380         tpath = gtk_tree_model_get_path(store, iter);
381
382         if (fully_visible)
383                 {
384                 if (gtk_tree_path_compare(tpath, start_path) <= 0)
385                         {
386                         ret = -1;
387                         }
388                 else if (gtk_tree_path_compare(tpath, end_path) >= 0)
389                         {
390                         ret = 1;
391                         }
392                 }
393         else
394                 {
395                 if (gtk_tree_path_compare(tpath, start_path) < 0)
396                         {
397                         ret = -1;
398                         }
399                 else if (gtk_tree_path_compare(tpath, end_path) > 0)
400                         {
401                         ret = 1;
402                         }
403                 }
404
405         gtk_tree_path_free(tpath);
406         gtk_tree_path_free(start_path);
407         gtk_tree_path_free(end_path);
408         return ret;
409 }
410
411 #else 
412 /* an implementation that uses gtk_tree_view_get_visible_rect, it seems to be more error prone than the variant above */
413
414 gint tree_view_row_get_visibility(GtkTreeView *widget, GtkTreeIter *iter, gboolean fully_visible)
415 {
416         GtkTreeModel *store;
417         GtkTreePath *tpath;
418         gint cx, cy;
419
420         GdkRectangle vrect;
421         GdkRectangle crect;
422
423         if (!GTK_WIDGET_REALIZED(GTK_WIDGET(widget))) return -1; /* we will most probably scroll down, needed for tree_view_row_make_visible */
424
425         store = gtk_tree_view_get_model(widget);
426         tpath = gtk_tree_model_get_path(store, iter);
427
428         gtk_tree_view_get_visible_rect(widget, &vrect);
429         gtk_tree_view_get_cell_area(widget, tpath, NULL, &crect);
430         gtk_tree_path_free(tpath);
431
432
433 #if GTK_CHECK_VERSION(2,12,0)
434         gtk_tree_view_convert_widget_to_tree_coords(widget, crect.x, crect.y, &cx, &cy);
435 #else
436         gtk_tree_view_widget_to_tree_coords(widget, crect.x, crect.y, &cx, &cy);
437 #endif
438
439         if (fully_visible)
440                 {
441                 if (cy < vrect.y) return -1;
442                 if (cy + crect.height > vrect.y + vrect.height) return 1;
443                 return 0;
444                 }
445
446         if (cy + crect.height < vrect.y) return -1;
447         if (cy > vrect.y + vrect.height) return 1;
448         return 0;
449 }
450 #endif
451
452 gint tree_view_row_make_visible(GtkTreeView *widget, GtkTreeIter *iter, gboolean center)
453 {
454         GtkTreePath *tpath;
455         gint vis;
456
457         vis = tree_view_row_get_visibility(widget, iter, TRUE);
458
459         tpath = gtk_tree_model_get_path(gtk_tree_view_get_model(widget), iter);
460         if (center && vis != 0)
461                 {
462                 gtk_tree_view_scroll_to_cell(widget, tpath, NULL, TRUE, 0.5, 0.0);
463                 }
464         else if (vis < 0)
465                 {
466                 gtk_tree_view_scroll_to_cell(widget, tpath, NULL, TRUE, 0.0, 0.0);
467                 }
468         else if (vis > 0)
469                 {
470                 gtk_tree_view_scroll_to_cell(widget, tpath, NULL, TRUE, 1.0, 0.0);
471                 }
472         gtk_tree_path_free(tpath);
473
474         return vis;
475 }
476
477 gboolean tree_view_move_cursor_away(GtkTreeView *widget, GtkTreeIter *iter, gboolean only_selected)
478 {
479         GtkTreeModel *store;
480         GtkTreePath *tpath;
481         GtkTreePath *fpath;
482         gboolean move = FALSE;
483
484         if (!iter) return FALSE;
485
486         store = gtk_tree_view_get_model(widget);
487         tpath = gtk_tree_model_get_path(store, iter);
488         gtk_tree_view_get_cursor(widget, &fpath, NULL);
489
490         if (fpath && gtk_tree_path_compare(tpath, fpath) == 0)
491                 {
492                 GtkTreeSelection *selection;
493
494                 selection = gtk_tree_view_get_selection(widget);
495
496                 if (!only_selected ||
497                     gtk_tree_selection_path_is_selected(selection, tpath))
498                         {
499                         GtkTreeIter current;
500
501                         current = *iter;
502                         if (gtk_tree_model_iter_next(store, &current))
503                                 {
504                                 gtk_tree_path_next(tpath);
505                                 move = TRUE;
506                                 }
507                         else if (gtk_tree_path_prev(tpath) &&
508                                  gtk_tree_model_get_iter(store, &current, tpath))
509                                 {
510                                 move = TRUE;
511                                 }
512
513                         if (move)
514                                 {
515                                 gtk_tree_view_set_cursor(widget, tpath, NULL, FALSE);
516                                 }
517                         }
518                 }
519
520         gtk_tree_path_free(tpath);
521         if (fpath) gtk_tree_path_free(fpath);
522
523         return move;
524 }
525
526 gint tree_path_to_row(GtkTreePath *tpath)
527 {
528         gint *indices;
529
530         indices = gtk_tree_path_get_indices(tpath);
531         if (indices) return indices[0];
532
533         return -1;
534 }
535
536
537 /*
538  *-------------------------------------------------------------------
539  * color utilities
540  *-------------------------------------------------------------------
541  */
542
543 void shift_color(GdkColor *src, gshort val, gint direction)
544 {
545         gshort cs;
546
547         if (val == -1)
548                 {
549                 val = STYLE_SHIFT_STANDARD;
550                 }
551         else
552                 {
553                 val = CLAMP(val, 1, 100);
554                 }
555         cs = 0xffff / 100 * val;
556
557         /* up or down ? */
558         if (direction < 0 ||
559             (direction == 0 &&((gint)src->red + (gint)src->green + (gint)src->blue) / 3 > 0xffff / 2))
560                 {
561                 src->red = MAX(0 , src->red - cs);
562                 src->green = MAX(0 , src->green - cs);
563                 src->blue = MAX(0 , src->blue - cs);
564                 }
565         else
566                 {
567                 src->red = MIN(0xffff, src->red + cs);
568                 src->green = MIN(0xffff, src->green + cs);
569                 src->blue = MIN(0xffff, src->blue + cs);
570                 }
571 }
572
573 /* darkens or lightens a style's color for given state
574  * esp. useful for alternating dark/light in (c)lists
575  */
576 void style_shift_color(GtkStyle *style, GtkStateType type, gshort shift_value, gint direction)
577 {
578         if (!style) return;
579
580         shift_color(&style->base[type], shift_value, direction);
581         shift_color(&style->bg[type], shift_value, direction);
582 }
583
584 /*
585  *-------------------------------------------------------------------
586  * auto scroll by mouse position
587  *-------------------------------------------------------------------
588  */
589
590 #define AUTO_SCROLL_DEFAULT_SPEED 100
591 #define AUTO_SCROLL_DEFAULT_REGION 20
592
593 typedef struct _AutoScrollData AutoScrollData;
594 struct _AutoScrollData
595 {
596         guint timer_id; /* event source id */
597         gint region_size;
598         GtkWidget *widget;
599         GtkAdjustment *adj;
600         gint max_step;
601
602         gint (*notify_func)(GtkWidget *, gint, gint, gpointer);
603         gpointer notify_data;
604 };
605
606 void widget_auto_scroll_stop(GtkWidget *widget)
607 {
608         AutoScrollData *sd;
609
610         sd = g_object_get_data(G_OBJECT(widget), "autoscroll");
611         if (!sd) return;
612         g_object_set_data(G_OBJECT(widget), "autoscroll", NULL);
613
614         if (sd->timer_id) g_source_remove(sd->timer_id);
615         g_free(sd);
616 }
617
618 static gboolean widget_auto_scroll_cb(gpointer data)
619 {
620         AutoScrollData *sd = data;
621         GdkWindow *window;
622         gint x, y;
623         gint w, h;
624         gint amt = 0;
625
626         if (sd->max_step < sd->region_size)
627                 {
628                 sd->max_step = MIN(sd->region_size, sd->max_step + 2);
629                 }
630
631         window = gtk_widget_get_window(sd->widget);
632         gdk_window_get_pointer(window, &x, &y, NULL);
633         w = gdk_window_get_width(window);
634         h = gdk_window_get_height(window);
635
636         if (x < 0 || x >= w || y < 0 || y >= h)
637                 {
638                 sd->timer_id = 0;
639                 widget_auto_scroll_stop(sd->widget);
640                 return FALSE;
641                 }
642
643         if (h < sd->region_size * 3)
644                 {
645                 /* height is cramped, nicely divide into three equal regions */
646                 if (y < h / 3 || y > h / 3 * 2)
647                         {
648                         amt = (y < h / 2) ? 0 - ((h / 2) - y) : y - (h / 2);
649                         }
650                 }
651         else if (y < sd->region_size)
652                 {
653                 amt = 0 - (sd->region_size - y);
654                 }
655         else if (y >= h - sd->region_size)
656                 {
657                 amt = y - (h - sd->region_size);
658                 }
659
660         if (amt != 0)
661                 {
662                 amt = CLAMP(amt, 0 - sd->max_step, sd->max_step);
663
664                 if (gtk_adjustment_get_value(sd->adj) != CLAMP(gtk_adjustment_get_value(sd->adj) + amt, gtk_adjustment_get_lower(sd->adj), gtk_adjustment_get_upper(sd->adj) - gtk_adjustment_get_page_size(sd->adj)))
665                         {
666                         /* only notify when scrolling is needed */
667                         if (sd->notify_func && !sd->notify_func(sd->widget, x, y, sd->notify_data))
668                                 {
669                                 sd->timer_id = 0;
670                                 widget_auto_scroll_stop(sd->widget);
671                                 return FALSE;
672                                 }
673
674                         gtk_adjustment_set_value(sd->adj,
675                                 CLAMP(gtk_adjustment_get_value(sd->adj) + amt, gtk_adjustment_get_lower(sd->adj), gtk_adjustment_get_upper(sd->adj) - gtk_adjustment_get_page_size(sd->adj)));
676                         }
677                 }
678
679         return TRUE;
680 }
681
682 gint widget_auto_scroll_start(GtkWidget *widget, GtkAdjustment *v_adj, gint scroll_speed, gint region_size,
683                               gint (*notify_func)(GtkWidget *widget, gint x, gint y, gpointer data), gpointer notify_data)
684 {
685         AutoScrollData *sd;
686
687         if (!widget || !v_adj) return 0;
688         if (g_object_get_data(G_OBJECT(widget), "autoscroll")) return 0;
689         if (scroll_speed < 1) scroll_speed = AUTO_SCROLL_DEFAULT_SPEED;
690         if (region_size < 1) region_size = AUTO_SCROLL_DEFAULT_REGION;
691
692         sd = g_new0(AutoScrollData, 1);
693         sd->widget = widget;
694         sd->adj = v_adj;
695         sd->region_size = region_size;
696         sd->max_step = 1;
697         sd->timer_id = g_timeout_add(scroll_speed, widget_auto_scroll_cb, sd);
698
699         sd->notify_func = notify_func;
700         sd->notify_data = notify_data;
701
702         g_object_set_data(G_OBJECT(widget), "autoscroll", sd);
703
704         return scroll_speed;
705 }
706
707
708 /*
709  *-------------------------------------------------------------------
710  * GList utils
711  *-------------------------------------------------------------------
712  */
713
714 GList *uig_list_insert_link(GList *list, GList *link, gpointer data)
715 {
716         GList *new_list;
717
718         if (!list || link == list) return g_list_prepend(list, data);
719         if (!link) return g_list_append(list, data);
720
721         new_list = g_list_alloc();
722         new_list->data = data;
723
724         if (link->prev)
725                 {
726                 link->prev->next = new_list;
727                 new_list->prev = link->prev;
728                 }
729         else
730                 {
731                 list = new_list;
732                 }
733         link->prev = new_list;
734         new_list->next = link;
735
736         return list;
737 }
738
739 GList *uig_list_insert_list(GList *parent, GList *insert_link, GList *list)
740 {
741         GList *end;
742
743         if (!insert_link) return g_list_concat(parent, list);
744         if (insert_link == parent) return g_list_concat(list, parent);
745         if (!parent) return list;
746         if (!list) return parent;
747
748         end  = g_list_last(list);
749
750         if (insert_link->prev) insert_link->prev->next = list;
751         list->prev = insert_link->prev;
752         insert_link->prev = end;
753         end->next = insert_link;
754
755         return parent;
756 }
757 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */