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