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