Mercurial > geeqie.yaz
annotate src/collect-table.c @ 196:f6e307c7bad6
rename GQview -> Geeqie over the code
author | nadvornik |
---|---|
date | Sun, 23 Mar 2008 20:38:54 +0000 |
parents | 71e1ebee420e |
children | 2710d14f6a28 |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
4 * | |
5 * Author: John Ellis | |
6 * | |
7 * This software is released under the GNU General Public License (GNU GPL). | |
8 * Please read the included file COPYING for more information. | |
9 * This software comes with no warranty of any kind, use at your own risk! | |
10 */ | |
11 | |
12 | |
13 #include "gqview.h" | |
14 #include "collect-table.h" | |
15 | |
16 #include "cellrenderericon.h" | |
17 #include "collect-dlg.h" | |
18 #include "collect-io.h" | |
19 #include "dnd.h" | |
20 #include "dupe.h" | |
21 #include "editors.h" | |
22 #include "filelist.h" | |
23 #include "img-view.h" | |
24 #include "info.h" | |
25 #include "layout.h" | |
26 #include "layout_image.h" | |
27 #include "menu.h" | |
28 #include "print.h" | |
29 #include "utilops.h" | |
30 #include "ui_bookmark.h" | |
31 #include "ui_fileops.h" | |
32 #include "ui_menu.h" | |
33 #include "ui_tree_edit.h" | |
34 | |
35 #include "icons/marker.xpm" | |
36 #define MARKER_WIDTH 26 | |
37 #define MARKER_HEIGHT 32 | |
38 | |
39 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
40 | |
41 /* between these, the icon width is increased by thumb_max_width / 2 */ | |
42 #define THUMB_MIN_ICON_WIDTH 128 | |
43 #define THUMB_MAX_ICON_WIDTH 150 | |
44 | |
45 #define COLLECT_TABLE_MAX_COLUMNS 32 | |
46 #define THUMB_BORDER_PADDING 2 | |
47 | |
48 #define COLLECT_TABLE_TIP_DELAY 500 | |
49 | |
50 | |
51 enum { | |
52 CTABLE_COLUMN_POINTER = 0, | |
53 CTABLE_COLUMN_COUNT | |
54 }; | |
55 | |
56 typedef enum { | |
57 SELECTION_NONE = 0, | |
58 SELECTION_SELECTED = 1 << 0, | |
59 SELECTION_PRELIGHT = 1 << 1, | |
60 SELECTION_FOCUS = 1 << 2 | |
61 } SelectionType; | |
62 | |
63 | |
64 #define INFO_SELECTED(x) (x->flag_mask & SELECTION_SELECTED) | |
65 | |
66 | |
67 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gint force); | |
68 | |
69 | |
70 /* | |
71 *------------------------------------------------------------------- | |
72 * more misc | |
73 *------------------------------------------------------------------- | |
74 */ | |
75 | |
76 static gint collection_table_find_position(CollectTable *ct, CollectInfo *info, gint *row, gint *col) | |
77 { | |
78 gint n; | |
79 | |
80 n = g_list_index(ct->cd->list, info); | |
81 | |
82 if (n < 0) return FALSE; | |
83 | |
84 *row = n / ct->columns; | |
85 *col = n - (*row * ct->columns); | |
86 | |
87 return TRUE; | |
88 } | |
89 | |
90 static gint collection_table_find_iter(CollectTable *ct, CollectInfo *info, GtkTreeIter *iter, gint *column) | |
91 { | |
92 GtkTreeModel *store; | |
93 gint row, col; | |
94 | |
95 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)); | |
96 if (!collection_table_find_position(ct, info, &row, &col)) return FALSE; | |
97 if (!gtk_tree_model_iter_nth_child(store, iter, NULL, row)) return FALSE; | |
98 if (column) *column = col; | |
99 | |
100 return TRUE; | |
101 } | |
102 | |
103 static CollectInfo *collection_table_find_data(CollectTable *ct, gint row, gint col, GtkTreeIter *iter) | |
104 { | |
105 GtkTreeModel *store; | |
106 GtkTreeIter p; | |
107 | |
108 if (row < 0 || col < 0) return NULL; | |
109 | |
110 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)); | |
111 if (gtk_tree_model_iter_nth_child(store, &p, NULL, row)) | |
112 { | |
113 GList *list; | |
114 | |
115 gtk_tree_model_get(store, &p, CTABLE_COLUMN_POINTER, &list, -1); | |
116 if (!list) return NULL; | |
117 | |
118 if (iter) *iter = p; | |
119 | |
120 return g_list_nth_data(list, col); | |
121 } | |
122 | |
123 return NULL; | |
124 } | |
125 | |
126 static CollectInfo *collection_table_find_data_by_coord(CollectTable *ct, gint x, gint y, GtkTreeIter *iter) | |
127 { | |
128 GtkTreePath *tpath; | |
129 GtkTreeViewColumn *column; | |
130 | |
131 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y, | |
132 &tpath, &column, NULL, NULL)) | |
133 { | |
134 GtkTreeModel *store; | |
135 GtkTreeIter row; | |
136 GList *list; | |
137 gint n; | |
138 | |
139 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)); | |
140 gtk_tree_model_get_iter(store, &row, tpath); | |
141 gtk_tree_path_free(tpath); | |
142 | |
143 gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1); | |
144 | |
145 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number")); | |
146 if (list) | |
147 { | |
148 if (iter) *iter = row; | |
149 return g_list_nth_data(list, n); | |
150 } | |
151 } | |
152 | |
153 return NULL; | |
154 } | |
155 | |
156 static void collection_table_update_status(CollectTable *ct) | |
157 { | |
158 if (ct->status_label) | |
159 { | |
160 gchar *buf; | |
161 | |
162 if (!ct->cd->list) | |
163 { | |
164 buf = g_strdup(_("Empty")); | |
165 } | |
166 else if (ct->selection) | |
167 { | |
168 buf = g_strdup_printf(_("%d images (%d)"), g_list_length(ct->cd->list), g_list_length(ct->selection)); | |
169 } | |
170 else | |
171 { | |
172 buf = g_strdup_printf(_("%d images"), g_list_length(ct->cd->list)); | |
173 } | |
174 | |
175 gtk_label_set_text(GTK_LABEL(ct->status_label), buf); | |
176 g_free(buf); | |
177 } | |
178 } | |
179 | |
180 static void collection_table_update_extras(CollectTable *ct, gint loading, gdouble value) | |
181 { | |
182 if (ct->extra_label) | |
183 { | |
184 gchar *text; | |
185 if (loading) | |
186 text = _("Loading thumbs..."); | |
187 else | |
188 text = " "; | |
189 | |
190 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ct->extra_label), value); | |
191 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ct->extra_label), text); | |
192 } | |
193 } | |
194 | |
195 static void collection_table_toggle_filenames(CollectTable *ct) | |
196 { | |
197 ct->show_text = !ct->show_text; | |
198 show_icon_names = ct->show_text; | |
199 | |
200 collection_table_populate_at_new_size(ct, ct->listview->allocation.width, ct->listview->allocation.height, TRUE); | |
201 } | |
202 | |
203 static gint collection_table_get_icon_width(CollectTable *ct) | |
204 { | |
205 gint width; | |
206 | |
207 if (!ct->show_text) return thumb_max_width; | |
208 | |
209 width = thumb_max_width + thumb_max_width / 2; | |
210 if (width < THUMB_MIN_ICON_WIDTH) width = THUMB_MIN_ICON_WIDTH; | |
211 if (width > THUMB_MAX_ICON_WIDTH) width = thumb_max_width; | |
212 | |
213 return width; | |
214 } | |
215 | |
216 /* | |
217 *------------------------------------------------------------------- | |
218 * cell updates | |
219 *------------------------------------------------------------------- | |
220 */ | |
221 | |
222 static void collection_table_selection_set(CollectTable *ct, CollectInfo *info, SelectionType value, GtkTreeIter *iter) | |
223 { | |
224 GtkTreeModel *store; | |
225 GList *list; | |
226 | |
227 if (!info) return; | |
228 | |
229 if (info->flag_mask == value) return; | |
230 info->flag_mask = value; | |
231 | |
232 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)); | |
233 if (iter) | |
234 { | |
235 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1); | |
236 if (list) gtk_list_store_set(GTK_LIST_STORE(store), iter, CTABLE_COLUMN_POINTER, list, -1); | |
237 } | |
238 else | |
239 { | |
240 GtkTreeIter row; | |
241 | |
242 if (collection_table_find_iter(ct, info, &row, NULL)) | |
243 { | |
244 gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1); | |
245 if (list) gtk_list_store_set(GTK_LIST_STORE(store), &row, CTABLE_COLUMN_POINTER, list, -1); | |
246 } | |
247 } | |
248 } | |
249 | |
250 static void collection_table_selection_add(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter) | |
251 { | |
252 if (!info) return; | |
253 | |
254 collection_table_selection_set(ct, info, info->flag_mask | mask, iter); | |
255 } | |
256 | |
257 static void collection_table_selection_remove(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter) | |
258 { | |
259 if (!info) return; | |
260 | |
261 collection_table_selection_set(ct, info, info->flag_mask & ~mask, iter); | |
262 } | |
263 /* | |
264 *------------------------------------------------------------------- | |
265 * selections | |
266 *------------------------------------------------------------------- | |
267 */ | |
268 | |
269 static void collection_table_verify_selections(CollectTable *ct) | |
270 { | |
271 GList *work; | |
272 | |
273 work = ct->selection; | |
274 while (work) | |
275 { | |
276 CollectInfo *info = work->data; | |
277 work = work->next; | |
278 if (!g_list_find(ct->cd->list, info)) | |
279 { | |
280 ct->selection = g_list_remove(ct->selection, info); | |
281 } | |
282 } | |
283 } | |
284 | |
285 void collection_table_select_all(CollectTable *ct) | |
286 { | |
287 GList *work; | |
288 | |
289 g_list_free(ct->selection); | |
290 ct->selection = NULL; | |
291 | |
292 work = ct->cd->list; | |
293 while(work) | |
294 { | |
295 ct->selection = g_list_append(ct->selection, work->data); | |
296 collection_table_selection_add(ct, work->data, SELECTION_SELECTED, NULL); | |
297 work = work->next; | |
298 } | |
299 | |
300 collection_table_update_status(ct); | |
301 } | |
302 | |
303 void collection_table_unselect_all(CollectTable *ct) | |
304 { | |
305 GList *work; | |
306 | |
307 work = ct->selection; | |
308 while (work) | |
309 { | |
310 collection_table_selection_remove(ct, work->data, SELECTION_SELECTED, NULL); | |
311 work = work->next; | |
312 } | |
313 | |
314 g_list_free(ct->selection); | |
315 ct->selection = NULL; | |
316 | |
317 collection_table_update_status(ct); | |
318 } | |
319 | |
320 static void collection_table_select(CollectTable *ct, CollectInfo *info) | |
321 { | |
322 ct->prev_selection = info; | |
323 | |
324 if (!info || INFO_SELECTED(info)) return; | |
325 | |
326 ct->selection = g_list_append(ct->selection, info); | |
327 collection_table_selection_add(ct, info, SELECTION_SELECTED, NULL); | |
328 | |
329 collection_table_update_status(ct); | |
330 } | |
331 | |
332 static void collection_table_unselect(CollectTable *ct, CollectInfo *info) | |
333 { | |
334 ct->prev_selection = info; | |
335 | |
336 if (!info || !INFO_SELECTED(info) ) return; | |
337 | |
338 ct->selection = g_list_remove(ct->selection, info); | |
339 collection_table_selection_remove(ct, info, SELECTION_SELECTED, NULL); | |
340 | |
341 collection_table_update_status(ct); | |
342 } | |
343 | |
344 static void collection_table_select_util(CollectTable *ct, CollectInfo *info, gint select) | |
345 { | |
346 if (select) | |
347 { | |
348 collection_table_select(ct, info); | |
349 } | |
350 else | |
351 { | |
352 collection_table_unselect(ct, info); | |
353 } | |
354 } | |
355 | |
356 static void collection_table_select_region_util(CollectTable *ct, CollectInfo *start, CollectInfo *end, gint select) | |
357 { | |
358 gint row1, col1; | |
359 gint row2, col2; | |
360 gint t; | |
361 gint i, j; | |
362 | |
363 if (!collection_table_find_position(ct, start, &row1, &col1) || | |
364 !collection_table_find_position(ct, end, &row2, &col2) ) return; | |
365 | |
366 ct->prev_selection = end; | |
367 | |
368 if (!collection_rectangular_selection) | |
369 { | |
370 GList *work; | |
371 CollectInfo *info; | |
372 | |
373 if (g_list_index(ct->cd->list, start) > g_list_index(ct->cd->list, end)) | |
374 { | |
375 info = start; | |
376 start = end; | |
377 end = info; | |
378 } | |
379 | |
380 work = g_list_find(ct->cd->list, start); | |
381 while (work) | |
382 { | |
383 info = work->data; | |
384 collection_table_select_util(ct, info, select); | |
385 | |
386 if (work->data != end) | |
387 work = work->next; | |
388 else | |
389 work = NULL; | |
390 } | |
391 return; | |
392 } | |
393 | |
394 if (row2 < row1) | |
395 { | |
396 t = row1; | |
397 row1 = row2; | |
398 row2 = t; | |
399 } | |
400 if (col2 < col1) | |
401 { | |
402 t = col1; | |
403 col1 = col2; | |
404 col2 = t; | |
405 } | |
406 | |
407 if (debug) printf("table: %d x %d to %d x %d\n", row1, col1, row2, col2); | |
408 | |
409 for (i = row1; i <= row2; i++) | |
410 { | |
411 for (j = col1; j <= col2; j++) | |
412 { | |
413 CollectInfo *info = collection_table_find_data(ct, i, j, NULL); | |
414 if (info) collection_table_select_util(ct, info, select); | |
415 } | |
416 } | |
417 } | |
418 | |
419 GList *collection_table_selection_get_list(CollectTable *ct) | |
420 { | |
138 | 421 return collection_list_to_filelist(ct->selection); |
9 | 422 } |
423 | |
424 static GList *collection_table_get_list(CollectTable *ct) | |
425 { | |
138 | 426 return collection_list_to_filelist(ct->cd->list); |
9 | 427 } |
428 | |
429 /* | |
430 *------------------------------------------------------------------- | |
431 * tooltip type window | |
432 *------------------------------------------------------------------- | |
433 */ | |
434 | |
435 static void tip_show(CollectTable *ct) | |
436 { | |
437 GtkWidget *label; | |
438 gint x, y; | |
439 | |
440 if (ct->tip_window) return; | |
441 | |
442 gdk_window_get_pointer(ct->listview->window, &x, &y, NULL); | |
443 | |
444 ct->tip_info = collection_table_find_data_by_coord(ct, x, y, NULL); | |
445 if (!ct->tip_info) return; | |
446 | |
447 ct->tip_window = gtk_window_new(GTK_WINDOW_POPUP); | |
448 gtk_window_set_resizable(GTK_WINDOW(ct->tip_window), FALSE); | |
449 gtk_container_set_border_width(GTK_CONTAINER(ct->tip_window), 2); | |
450 | |
138 | 451 label = gtk_label_new(ct->tip_info->fd->name); |
9 | 452 |
453 g_object_set_data(G_OBJECT(ct->tip_window), "tip_label", label); | |
454 gtk_container_add(GTK_CONTAINER(ct->tip_window), label); | |
455 gtk_widget_show(label); | |
456 | |
457 gdk_window_get_pointer(NULL, &x, &y, NULL); | |
458 | |
459 if (!GTK_WIDGET_REALIZED(ct->tip_window)) gtk_widget_realize(ct->tip_window); | |
460 gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16); | |
461 gtk_widget_show(ct->tip_window); | |
462 } | |
463 | |
464 static void tip_hide(CollectTable *ct) | |
465 { | |
466 if (ct->tip_window) gtk_widget_destroy(ct->tip_window); | |
467 ct->tip_window = NULL; | |
468 } | |
469 | |
470 static gint tip_schedule_cb(gpointer data) | |
471 { | |
472 CollectTable *ct = data; | |
473 | |
474 if (ct->tip_delay_id == -1) return FALSE; | |
475 | |
476 tip_show(ct); | |
477 | |
478 ct->tip_delay_id = -1; | |
479 return FALSE; | |
480 } | |
481 | |
482 static void tip_schedule(CollectTable *ct) | |
483 { | |
484 tip_hide(ct); | |
485 | |
486 if (ct->tip_delay_id != -1) | |
487 { | |
488 g_source_remove(ct->tip_delay_id); | |
489 ct->tip_delay_id = -1; | |
490 } | |
491 | |
492 if (!ct->show_text) | |
493 { | |
494 ct->tip_delay_id = g_timeout_add(COLLECT_TABLE_TIP_DELAY, tip_schedule_cb, ct); | |
495 } | |
496 } | |
497 | |
498 static void tip_unschedule(CollectTable *ct) | |
499 { | |
500 tip_hide(ct); | |
501 | |
502 if (ct->tip_delay_id != -1) g_source_remove(ct->tip_delay_id); | |
503 ct->tip_delay_id = -1; | |
504 } | |
505 | |
506 static void tip_update(CollectTable *ct, CollectInfo *info) | |
507 { | |
508 if (ct->tip_window) | |
509 { | |
510 gint x, y; | |
511 | |
512 gdk_window_get_pointer(NULL, &x, &y, NULL); | |
513 gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16); | |
514 | |
515 if (info != ct->tip_info) | |
516 { | |
517 GtkWidget *label; | |
518 | |
519 ct->tip_info = info; | |
520 | |
521 if (!ct->tip_info) | |
522 { | |
523 tip_hide(ct); | |
524 tip_schedule(ct); | |
525 return; | |
526 } | |
527 | |
528 label = g_object_get_data(G_OBJECT(ct->tip_window), "tip_label"); | |
138 | 529 gtk_label_set_text(GTK_LABEL(label), ct->tip_info->fd->name); |
9 | 530 } |
531 } | |
532 else | |
533 { | |
534 tip_schedule(ct); | |
535 } | |
536 } | |
537 | |
538 /* | |
539 *------------------------------------------------------------------- | |
540 * popup menus | |
541 *------------------------------------------------------------------- | |
542 */ | |
543 | |
544 static void collection_table_popup_save_as_cb(GtkWidget *widget, gpointer data) | |
545 { | |
546 CollectTable *ct = data; | |
547 | |
548 collection_dialog_save_as(NULL, ct->cd); | |
549 } | |
550 | |
551 static void collection_table_popup_save_cb(GtkWidget *widget, gpointer data) | |
552 { | |
553 CollectTable *ct = data; | |
554 | |
555 if (!ct->cd->path) | |
556 { | |
557 collection_table_popup_save_as_cb(widget, data); | |
558 return; | |
559 } | |
560 | |
561 if (!collection_save(ct->cd, ct->cd->path)) | |
562 { | |
563 printf("failed saving to collection path: %s\n", ct->cd->path); | |
564 } | |
565 } | |
566 | |
567 static GList *collection_table_popup_file_list(CollectTable *ct) | |
568 { | |
569 if (!ct->click_info) return NULL; | |
570 | |
571 if (INFO_SELECTED(ct->click_info)) | |
572 { | |
573 return collection_table_selection_get_list(ct); | |
574 } | |
575 | |
138 | 576 return g_list_append(NULL, g_strdup(ct->click_info->fd->path)); |
9 | 577 } |
578 | |
579 static void collection_table_popup_edit_cb(GtkWidget *widget, gpointer data) | |
580 { | |
581 CollectTable *ct; | |
582 gint n; | |
583 GList *list; | |
584 | |
585 ct = submenu_item_get_data(widget); | |
586 | |
587 if (!ct) return; | |
588 n = GPOINTER_TO_INT(data); | |
589 | |
590 list = collection_table_popup_file_list(ct); | |
591 if (list) | |
592 { | |
138 | 593 start_editor_from_filelist(n, list); |
594 filelist_free(list); | |
9 | 595 } |
596 } | |
597 | |
598 static void collection_table_popup_info_cb(GtkWidget *widget, gpointer data) | |
599 { | |
600 CollectTable *ct = data; | |
601 | |
602 info_window_new(NULL, collection_table_popup_file_list(ct)); | |
603 } | |
604 | |
605 static void collection_table_popup_copy_cb(GtkWidget *widget, gpointer data) | |
606 { | |
607 CollectTable *ct = data; | |
608 | |
609 file_util_copy(NULL, collection_table_popup_file_list(ct), NULL, ct->listview); | |
610 } | |
611 | |
612 static void collection_table_popup_move_cb(GtkWidget *widget, gpointer data) | |
613 { | |
614 CollectTable *ct = data; | |
615 | |
616 file_util_move(NULL, collection_table_popup_file_list(ct), NULL, ct->listview); | |
617 } | |
618 | |
619 static void collection_table_popup_rename_cb(GtkWidget *widget, gpointer data) | |
620 { | |
621 CollectTable *ct = data; | |
622 | |
623 file_util_rename(NULL, collection_table_popup_file_list(ct), ct->listview); | |
624 } | |
625 | |
626 static void collection_table_popup_delete_cb(GtkWidget *widget, gpointer data) | |
627 { | |
628 CollectTable *ct = data; | |
629 | |
630 file_util_delete(NULL, collection_table_popup_file_list(ct), ct->listview); | |
631 } | |
632 | |
633 static void collection_table_popup_sort_cb(GtkWidget *widget, gpointer data) | |
634 { | |
635 CollectTable *ct; | |
636 SortType type; | |
637 | |
638 ct = submenu_item_get_data(widget); | |
639 | |
640 if (!ct) return; | |
641 | |
642 type = (SortType)GPOINTER_TO_INT(data); | |
643 | |
644 collection_set_sort_method(ct->cd, type); | |
645 } | |
646 | |
647 static void collection_table_popup_view_new_cb(GtkWidget *widget, gpointer data) | |
648 { | |
649 CollectTable *ct = data; | |
650 | |
651 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info)) | |
652 { | |
653 view_window_new_from_collection(ct->cd, ct->click_info); | |
654 } | |
655 } | |
656 | |
657 static void collection_table_popup_view_cb(GtkWidget *widget, gpointer data) | |
658 { | |
659 CollectTable *ct = data; | |
660 | |
661 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info)) | |
662 { | |
663 layout_image_set_collection(NULL, ct->cd, ct->click_info); | |
664 } | |
665 } | |
666 | |
667 static void collection_table_popup_selectall_cb(GtkWidget *widget, gpointer data) | |
668 { | |
669 CollectTable *ct = data; | |
670 | |
671 collection_table_select_all(ct); | |
672 ct->prev_selection= ct->click_info; | |
673 } | |
674 | |
675 static void collection_table_popup_unselectall_cb(GtkWidget *widget, gpointer data) | |
676 { | |
677 CollectTable *ct = data; | |
678 | |
679 collection_table_unselect_all(ct); | |
680 ct->prev_selection= ct->click_info; | |
681 } | |
682 | |
683 static void collection_table_popup_remove_cb(GtkWidget *widget, gpointer data) | |
684 { | |
685 CollectTable *ct = data; | |
686 GList *list; | |
687 | |
688 if (!ct->click_info) return; | |
689 | |
690 if (INFO_SELECTED(ct->click_info)) | |
691 { | |
692 list = g_list_copy(ct->selection); | |
693 } | |
694 else | |
695 { | |
696 list = g_list_append(NULL, ct->click_info); | |
697 } | |
698 | |
699 collection_remove_by_info_list(ct->cd, list); | |
700 g_list_free(list); | |
701 } | |
702 | |
703 static void collection_table_popup_add_filelist_cb(GtkWidget *widget, gpointer data) | |
704 { | |
705 CollectTable *ct = data; | |
706 GList *list; | |
707 | |
708 list = layout_list(NULL); | |
709 | |
710 if (list) | |
711 { | |
138 | 712 collection_table_add_filelist(ct, list); |
713 filelist_free(list); | |
9 | 714 } |
715 } | |
716 | |
717 static void collection_table_popup_add_collection_cb(GtkWidget *widget, gpointer data) | |
718 { | |
719 CollectTable *ct = data; | |
720 | |
721 collection_dialog_append(NULL, ct->cd); | |
722 } | |
723 | |
724 static void collection_table_popup_find_dupes_cb(GtkWidget *widget, gpointer data) | |
725 { | |
726 CollectTable *ct = data; | |
727 DupeWindow *dw; | |
728 | |
729 dw = dupe_window_new(DUPE_MATCH_NAME); | |
730 dupe_window_add_collection(dw, ct->cd); | |
731 } | |
732 | |
733 static void collection_table_popup_print_cb(GtkWidget *widget, gpointer data) | |
734 { | |
735 CollectTable *ct = data; | |
138 | 736 FileData *fd; |
737 | |
738 fd = (ct->click_info) ? ct->click_info->fd : NULL; | |
739 | |
740 print_window_new(fd, collection_table_selection_get_list(ct), collection_table_get_list(ct), ct->listview); | |
9 | 741 } |
742 | |
743 static void collection_table_popup_show_names_cb(GtkWidget *widget, gpointer data) | |
744 { | |
745 CollectTable *ct = data; | |
746 | |
747 collection_table_toggle_filenames(ct); | |
748 } | |
749 | |
750 static void collection_table_popup_destroy_cb(GtkWidget *widget, gpointer data) | |
751 { | |
752 CollectTable *ct = data; | |
753 | |
754 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL); | |
755 ct->click_info = NULL; | |
756 ct->popup = NULL; | |
757 | |
758 path_list_free(ct->drop_list); | |
759 ct->drop_list = NULL; | |
760 ct->drop_info = NULL; | |
761 } | |
762 | |
763 static GtkWidget *collection_table_popup_menu(CollectTable *ct, gint over_icon) | |
764 { | |
765 GtkWidget *menu; | |
766 GtkWidget *item; | |
767 | |
768 menu = popup_menu_short_lived(); | |
769 | |
770 g_signal_connect(G_OBJECT(menu), "destroy", | |
771 G_CALLBACK(collection_table_popup_destroy_cb), ct); | |
772 | |
773 menu_item_add_sensitive(menu, _("_View"), over_icon, | |
774 G_CALLBACK(collection_table_popup_view_cb), ct); | |
775 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, over_icon, | |
776 G_CALLBACK(collection_table_popup_view_new_cb), ct); | |
777 menu_item_add_divider(menu); | |
778 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, over_icon, | |
779 G_CALLBACK(collection_table_popup_remove_cb), ct); | |
780 | |
781 menu_item_add_stock(menu, _("Append from file list"), GTK_STOCK_ADD, | |
782 G_CALLBACK(collection_table_popup_add_filelist_cb), ct); | |
783 menu_item_add_stock(menu, _("Append from collection..."), GTK_STOCK_OPEN, | |
784 G_CALLBACK(collection_table_popup_add_collection_cb), ct); | |
785 menu_item_add_divider(menu); | |
786 menu_item_add(menu, _("Select all"), | |
787 G_CALLBACK(collection_table_popup_selectall_cb), ct); | |
788 menu_item_add(menu, _("Select none"), | |
789 G_CALLBACK(collection_table_popup_unselectall_cb), ct); | |
790 menu_item_add_divider(menu); | |
791 | |
792 submenu_add_edit(menu, &item, | |
793 G_CALLBACK(collection_table_popup_edit_cb), ct); | |
794 gtk_widget_set_sensitive(item, over_icon); | |
795 | |
796 menu_item_add_sensitive(menu, _("_Properties"), over_icon, | |
797 G_CALLBACK(collection_table_popup_info_cb), ct); | |
798 menu_item_add_divider(menu); | |
799 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, over_icon, | |
800 G_CALLBACK(collection_table_popup_copy_cb), ct); | |
801 menu_item_add_sensitive(menu, _("_Move..."), over_icon, | |
802 G_CALLBACK(collection_table_popup_move_cb), ct); | |
803 menu_item_add_sensitive(menu, _("_Rename..."), over_icon, | |
804 G_CALLBACK(collection_table_popup_rename_cb), ct); | |
805 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, over_icon, | |
806 G_CALLBACK(collection_table_popup_delete_cb), ct); | |
807 menu_item_add_divider(menu); | |
808 | |
809 submenu_add_sort(menu, G_CALLBACK(collection_table_popup_sort_cb), ct, FALSE, TRUE, FALSE, 0); | |
810 menu_item_add_check(menu, _("Show filename _text"), ct->show_text, | |
811 G_CALLBACK(collection_table_popup_show_names_cb), ct); | |
812 menu_item_add_divider(menu); | |
813 menu_item_add_stock(menu, _("_Save collection"), GTK_STOCK_SAVE, | |
814 G_CALLBACK(collection_table_popup_save_cb), ct); | |
815 menu_item_add_stock(menu, _("Save collection _as..."), GTK_STOCK_SAVE_AS, | |
816 G_CALLBACK(collection_table_popup_save_as_cb), ct); | |
817 menu_item_add_divider(menu); | |
818 menu_item_add_stock(menu, _("_Find duplicates..."), GTK_STOCK_FIND, | |
819 G_CALLBACK(collection_table_popup_find_dupes_cb), ct); | |
820 menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, over_icon, | |
821 G_CALLBACK(collection_table_popup_print_cb), ct); | |
822 | |
823 return menu; | |
824 } | |
825 /* | |
826 *------------------------------------------------------------------- | |
827 * keyboard callbacks | |
828 *------------------------------------------------------------------- | |
829 */ | |
830 | |
831 static void collection_table_set_focus(CollectTable *ct, CollectInfo *info) | |
832 { | |
833 GtkTreeIter iter; | |
834 gint row, col; | |
835 | |
836 if (g_list_find(ct->cd->list, ct->focus_info)) | |
837 { | |
838 if (info == ct->focus_info) | |
839 { | |
840 /* ensure focus row col are correct */ | |
841 collection_table_find_position(ct, ct->focus_info, | |
842 &ct->focus_row, &ct->focus_column); | |
843 return; | |
844 } | |
845 collection_table_selection_remove(ct, ct->focus_info, SELECTION_FOCUS, NULL); | |
846 } | |
847 | |
848 if (!collection_table_find_position(ct, info, &row, &col)) | |
849 { | |
850 ct->focus_info = NULL; | |
851 ct->focus_row = -1; | |
852 ct->focus_column = -1; | |
853 return; | |
854 } | |
855 | |
856 ct->focus_info = info; | |
857 ct->focus_row = row; | |
858 ct->focus_column = col; | |
859 collection_table_selection_add(ct, ct->focus_info, SELECTION_FOCUS, NULL); | |
860 | |
861 if (collection_table_find_iter(ct, ct->focus_info, &iter, NULL)) | |
862 { | |
863 GtkTreePath *tpath; | |
864 GtkTreeViewColumn *column; | |
865 GtkTreeModel *store; | |
866 | |
867 tree_view_row_make_visible(GTK_TREE_VIEW(ct->listview), &iter, FALSE); | |
868 | |
869 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)); | |
870 tpath = gtk_tree_model_get_path(store, &iter); | |
871 /* focus is set to an extra column with 0 width to hide focus, we draw it ourself */ | |
872 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), COLLECT_TABLE_MAX_COLUMNS); | |
873 gtk_tree_view_set_cursor(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE); | |
874 gtk_tree_path_free(tpath); | |
875 } | |
876 } | |
877 | |
878 static void collection_table_move_focus(CollectTable *ct, gint row, gint col, gint relative) | |
879 { | |
880 gint new_row; | |
881 gint new_col; | |
882 | |
883 if (relative) | |
884 { | |
885 new_row = ct->focus_row; | |
886 new_col = ct->focus_column; | |
887 | |
888 new_row += row; | |
889 if (new_row < 0) new_row = 0; | |
890 if (new_row >= ct->rows) new_row = ct->rows - 1; | |
891 | |
892 while(col != 0) | |
893 { | |
894 if (col < 0) | |
895 { | |
896 new_col--; | |
897 col++; | |
898 } | |
899 else | |
900 { | |
901 new_col++; | |
902 col--; | |
903 } | |
904 | |
905 if (new_col < 0) | |
906 { | |
907 if (new_row > 0) | |
908 { | |
909 new_row--; | |
910 new_col = ct->columns - 1; | |
911 } | |
912 else | |
913 { | |
914 new_col = 0; | |
915 } | |
916 } | |
917 if (new_col >= ct->columns) | |
918 { | |
919 if (new_row < ct->rows - 1) | |
920 { | |
921 new_row++; | |
922 new_col = 0; | |
923 } | |
924 else | |
925 { | |
926 new_col = ct->columns - 1; | |
927 } | |
928 } | |
929 } | |
930 } | |
931 else | |
932 { | |
933 new_row = row; | |
934 new_col = col; | |
935 | |
936 if (new_row >= ct->rows) | |
937 { | |
938 if (ct->rows > 0) | |
939 new_row = ct->rows - 1; | |
940 else | |
941 new_row = 0; | |
942 new_col = ct->columns - 1; | |
943 } | |
944 if (new_col >= ct->columns) new_col = ct->columns - 1; | |
945 } | |
946 | |
947 if (new_row == ct->rows - 1) | |
948 { | |
949 gint l; | |
950 | |
951 /* if we moved beyond the last image, go to the last image */ | |
952 | |
953 l = g_list_length(ct->cd->list); | |
954 if (ct->rows > 1) l -= (ct->rows - 1) * ct->columns; | |
955 if (new_col >= l) new_col = l - 1; | |
956 } | |
957 | |
958 if (new_row == -1 || new_col == -1) | |
959 { | |
960 if (!ct->cd->list) return; | |
961 new_row = new_col = 0; | |
962 } | |
963 | |
964 collection_table_set_focus(ct, collection_table_find_data(ct, new_row, new_col, NULL)); | |
965 } | |
966 | |
967 static void collection_table_update_focus(CollectTable *ct) | |
968 { | |
969 gint new_row = 0; | |
970 gint new_col = 0; | |
971 | |
972 if (ct->focus_info && collection_table_find_position(ct, ct->focus_info, &new_row, &new_col)) | |
973 { | |
974 /* first find the old focus, if it exists and is valid */ | |
975 } | |
976 else | |
977 { | |
978 /* (try to) stay where we were */ | |
979 new_row = ct->focus_row; | |
980 new_col = ct->focus_column; | |
981 } | |
982 | |
983 collection_table_move_focus(ct, new_row, new_col, FALSE); | |
984 } | |
985 | |
986 /* used to figure the page up/down distances */ | |
987 static gint page_height(CollectTable *ct) | |
988 { | |
989 GtkAdjustment *adj; | |
990 gint page_size; | |
991 gint row_height; | |
992 gint ret; | |
993 | |
994 adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview)); | |
995 page_size = (gint)adj->page_increment; | |
996 | |
997 row_height = thumb_max_height + THUMB_BORDER_PADDING * 2; | |
998 if (ct->show_text) row_height += thumb_max_height / 3; | |
999 | |
1000 ret = page_size / row_height; | |
1001 if (ret < 1) ret = 1; | |
1002 | |
1003 return ret; | |
1004 } | |
1005 | |
1006 static void collection_table_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) | |
1007 { | |
1008 CollectTable *ct = data; | |
1009 GtkTreeModel *store; | |
1010 GtkTreeIter iter; | |
1011 gint column; | |
1012 GtkTreePath *tpath; | |
1013 gint cw, ch; | |
1014 | |
1015 if (!collection_table_find_iter(ct, ct->click_info, &iter, &column)) return; | |
1016 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)); | |
1017 tpath = gtk_tree_model_get_path(store, &iter); | |
1018 tree_view_get_cell_clamped(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE, x, y, &cw, &ch); | |
1019 gtk_tree_path_free(tpath); | |
1020 *y += ch; | |
1021 popup_menu_position_clamp(menu, x, y, 0); | |
1022 } | |
1023 | |
1024 static gint collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
1025 { | |
1026 CollectTable *ct = data; | |
1027 gint focus_row = 0; | |
1028 gint focus_col = 0; | |
1029 CollectInfo *info; | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1030 gint stop_signal; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1031 |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1032 stop_signal = TRUE; |
9 | 1033 switch (event->keyval) |
1034 { | |
1035 case GDK_Left: case GDK_KP_Left: | |
1036 focus_col = -1; | |
1037 break; | |
1038 case GDK_Right: case GDK_KP_Right: | |
1039 focus_col = 1; | |
1040 break; | |
1041 case GDK_Up: case GDK_KP_Up: | |
1042 focus_row = -1; | |
1043 break; | |
1044 case GDK_Down: case GDK_KP_Down: | |
1045 focus_row = 1; | |
1046 break; | |
1047 case GDK_Page_Up: case GDK_KP_Page_Up: | |
1048 focus_row = -page_height(ct); | |
1049 break; | |
1050 case GDK_Page_Down: case GDK_KP_Page_Down: | |
1051 focus_row = page_height(ct); | |
1052 break; | |
1053 case GDK_Home: case GDK_KP_Home: | |
1054 focus_row = -ct->focus_row; | |
1055 focus_col = -ct->focus_column; | |
1056 break; | |
1057 case GDK_End: case GDK_KP_End: | |
1058 focus_row = ct->rows - 1 - ct->focus_row; | |
1059 focus_col = ct->columns - 1 - ct->focus_column; | |
1060 break; | |
1061 case GDK_space: | |
1062 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL); | |
1063 if (info) | |
1064 { | |
1065 ct->click_info = info; | |
1066 if (event->state & GDK_CONTROL_MASK) | |
1067 { | |
1068 collection_table_select_util(ct, info, !INFO_SELECTED(info)); | |
1069 } | |
1070 else | |
1071 { | |
1072 collection_table_unselect_all(ct); | |
1073 collection_table_select(ct, info); | |
1074 } | |
1075 } | |
1076 break; | |
1077 case 'T': case 't': | |
1078 if (event->state & GDK_CONTROL_MASK) collection_table_toggle_filenames(ct); | |
1079 break; | |
1080 case GDK_Menu: | |
1081 case GDK_F10: | |
1082 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL); | |
1083 ct->click_info = info; | |
1084 | |
1085 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, NULL); | |
1086 tip_unschedule(ct); | |
1087 | |
1088 ct->popup = collection_table_popup_menu(ct, (info != NULL)); | |
1089 gtk_menu_popup(GTK_MENU(ct->popup), NULL, NULL, collection_table_menu_pos_cb, ct, 0, GDK_CURRENT_TIME); | |
1090 break; | |
1091 default: | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1092 stop_signal = FALSE; |
9 | 1093 break; |
1094 } | |
1095 | |
1096 if (focus_row != 0 || focus_col != 0) | |
1097 { | |
1098 CollectInfo *new_info; | |
1099 CollectInfo *old_info; | |
1100 | |
1101 old_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL); | |
1102 collection_table_move_focus(ct, focus_row, focus_col, TRUE); | |
1103 new_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL); | |
1104 | |
1105 if (new_info != old_info) | |
1106 { | |
1107 if (event->state & GDK_SHIFT_MASK) | |
1108 { | |
1109 if (!collection_rectangular_selection) | |
1110 { | |
1111 collection_table_select_region_util(ct, old_info, new_info, FALSE); | |
1112 } | |
1113 else | |
1114 { | |
1115 collection_table_select_region_util(ct, ct->click_info, old_info, FALSE); | |
1116 } | |
1117 collection_table_select_region_util(ct, ct->click_info, new_info, TRUE); | |
1118 } | |
1119 else if (event->state & GDK_CONTROL_MASK) | |
1120 { | |
1121 ct->click_info = new_info; | |
1122 } | |
1123 else | |
1124 { | |
1125 ct->click_info = new_info; | |
1126 collection_table_unselect_all(ct); | |
1127 collection_table_select(ct, new_info); | |
1128 } | |
1129 } | |
1130 } | |
1131 | |
1132 if (stop_signal) | |
1133 { | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1134 #if 0 |
9 | 1135 g_signal_stop_emission_by_name(GTK_OBJECT(widget), "key_press_event"); |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1136 #endif |
9 | 1137 tip_unschedule(ct); |
1138 } | |
1139 | |
1140 return stop_signal; | |
1141 } | |
1142 | |
1143 /* | |
1144 *------------------------------------------------------------------- | |
1145 * insert marker | |
1146 *------------------------------------------------------------------- | |
1147 */ | |
1148 | |
1149 static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *source, gint *after, GdkRectangle *cell, | |
1150 gint use_coord, gint x, gint y) | |
1151 { | |
1152 CollectInfo *info = NULL; | |
1153 GtkTreeModel *store; | |
1154 GtkTreeIter iter; | |
1155 GtkTreePath *tpath; | |
1156 GtkTreeViewColumn *column; | |
1157 | |
1158 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)); | |
1159 | |
1160 if (!use_coord) gdk_window_get_pointer(ct->listview->window, &x, &y, NULL); | |
1161 | |
1162 if (source) | |
1163 { | |
1164 gint col; | |
1165 if (collection_table_find_iter(ct, source, &iter, &col)) | |
1166 { | |
1167 tpath = gtk_tree_model_get_path(store, &iter); | |
1168 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col); | |
1169 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell); | |
1170 gtk_tree_path_free(tpath); | |
1171 | |
1172 info = source; | |
1173 *after = (x > cell->x + (cell->width / 2)); | |
1174 } | |
1175 return info; | |
1176 } | |
1177 | |
1178 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y, | |
1179 &tpath, &column, NULL, NULL)) | |
1180 { | |
1181 GList *list; | |
1182 gint n; | |
1183 | |
1184 gtk_tree_model_get_iter(store, &iter, tpath); | |
1185 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1); | |
1186 | |
1187 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number")); | |
1188 info = g_list_nth_data(list, n); | |
1189 | |
1190 if (info) | |
1191 { | |
1192 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell); | |
1193 *after = (x > cell->x + (cell->width / 2)); | |
1194 } | |
1195 | |
1196 gtk_tree_path_free(tpath); | |
1197 } | |
1198 | |
1199 if (info == NULL) | |
1200 { | |
1201 GList *work; | |
1202 | |
1203 work = g_list_last(ct->cd->list); | |
1204 if (work) | |
1205 { | |
1206 gint col; | |
1207 | |
1208 info = work->data; | |
1209 *after = TRUE; | |
1210 | |
1211 if (collection_table_find_iter(ct, info, &iter, &col)) | |
1212 { | |
1213 tpath = gtk_tree_model_get_path(store, &iter); | |
1214 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col); | |
1215 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell); | |
1216 gtk_tree_path_free(tpath); | |
1217 } | |
1218 } | |
1219 } | |
1220 | |
1221 return info; | |
1222 } | |
1223 | |
1224 static CollectInfo *collection_table_insert_point(CollectTable *ct, gint x, gint y) | |
1225 { | |
1226 CollectInfo *info; | |
1227 GdkRectangle cell; | |
1228 gint after = FALSE; | |
1229 | |
1230 info = collection_table_insert_find(ct, NULL, &after, &cell, TRUE, x, y); | |
1231 | |
1232 if (info && after) | |
1233 { | |
1234 GList *work; | |
1235 | |
1236 work = g_list_find(ct->cd->list, info); | |
1237 if (work && work->next) | |
1238 { | |
1239 info = work->next->data; | |
1240 } | |
1241 else | |
1242 { | |
1243 info = NULL; | |
1244 } | |
1245 } | |
1246 | |
1247 return info; | |
1248 } | |
1249 | |
1250 static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info, gint enable) | |
1251 { | |
1252 gint row, col; | |
1253 gint after = FALSE; | |
1254 GdkRectangle cell; | |
1255 | |
1256 if (!enable) | |
1257 { | |
1258 if (ct->marker_window) gdk_window_destroy(ct->marker_window); | |
1259 ct->marker_window = NULL; | |
1260 | |
1261 return; | |
1262 } | |
1263 | |
1264 info = collection_table_insert_find(ct, info, &after, &cell, FALSE, 0, 0); | |
1265 | |
1266 /* this setting does not take into account (after), but since it is not really used... */ | |
1267 ct->marker_info = info; | |
1268 | |
1269 row = -1; | |
1270 col = -1; | |
1271 | |
1272 if (!ct->marker_window) | |
1273 { | |
1274 GdkWindow *parent; | |
1275 GdkWindowAttr attributes; | |
1276 gint attributes_mask; | |
1277 GdkPixmap *pixmap; | |
1278 GdkBitmap *mask; | |
1279 GdkPixbuf *pb; | |
1280 gint w, h; | |
1281 | |
1282 parent = gtk_tree_view_get_bin_window(GTK_TREE_VIEW(ct->listview)); | |
1283 | |
1284 pb = gdk_pixbuf_new_from_xpm_data((const char **)marker_xpm); | |
1285 gdk_pixbuf_render_pixmap_and_mask(pb, &pixmap, &mask, 128); | |
1286 gdk_pixbuf_unref(pb); | |
1287 | |
1288 gdk_drawable_get_size(pixmap, &w, &h); | |
1289 | |
1290 attributes.window_type = GDK_WINDOW_CHILD; | |
1291 attributes.wclass = GDK_INPUT_OUTPUT; | |
1292 attributes.width = w; | |
1293 attributes.height = h; | |
1294 attributes.event_mask = gtk_widget_get_events(ct->listview); | |
1295 attributes_mask = 0; | |
1296 | |
1297 ct->marker_window = gdk_window_new(parent, &attributes, attributes_mask); | |
1298 gdk_window_set_back_pixmap(ct->marker_window, pixmap, FALSE); | |
1299 gdk_window_shape_combine_mask(ct->marker_window, mask, 0, 0); | |
1300 | |
1301 g_object_unref(pixmap); | |
1302 if (mask) g_object_unref(mask); | |
1303 } | |
1304 | |
1305 if (info) | |
1306 { | |
1307 gint x, y; | |
1308 gint w, h; | |
1309 | |
1310 gdk_drawable_get_size(ct->marker_window, &w, &h); | |
1311 | |
1312 if (!after) | |
1313 { | |
1314 x = cell.x; | |
1315 } | |
1316 else | |
1317 { | |
1318 x = cell.x + cell.width; | |
1319 } | |
1320 x -= (w / 2); | |
1321 y = cell.y + (cell.height / 2) - (h / 2); | |
1322 | |
1323 gdk_window_move(ct->marker_window, x, y); | |
1324 gdk_window_clear(ct->marker_window); | |
1325 if (!gdk_window_is_visible(ct->marker_window)) gdk_window_show(ct->marker_window); | |
1326 } | |
1327 else | |
1328 { | |
1329 if (gdk_window_is_visible(ct->marker_window)) gdk_window_hide(ct->marker_window); | |
1330 } | |
1331 } | |
1332 | |
1333 /* | |
1334 *------------------------------------------------------------------- | |
1335 * mouse drag auto-scroll | |
1336 *------------------------------------------------------------------- | |
1337 */ | |
1338 | |
1339 static void collection_table_motion_update(CollectTable *ct, gint x, gint y, gint drop_event) | |
1340 { | |
1341 CollectInfo *info; | |
1342 | |
1343 info = collection_table_find_data_by_coord(ct, x, y, NULL); | |
1344 | |
1345 if (drop_event) | |
1346 { | |
1347 tip_unschedule(ct); | |
1348 collection_table_insert_marker(ct, info, TRUE); | |
1349 } | |
1350 else | |
1351 { | |
1352 tip_update(ct, info); | |
1353 } | |
1354 } | |
1355 | |
1356 static gint collection_table_auto_scroll_idle_cb(gpointer data) | |
1357 { | |
1358 CollectTable *ct = data; | |
1359 GdkWindow *window; | |
1360 gint x, y; | |
1361 gint w, h; | |
1362 | |
1363 if (ct->drop_idle_id == -1) return FALSE; | |
1364 | |
1365 window = ct->listview->window; | |
1366 gdk_window_get_pointer(window, &x, &y, NULL); | |
1367 gdk_drawable_get_size(window, &w, &h); | |
1368 if (x >= 0 && x < w && y >= 0 && y < h) | |
1369 { | |
1370 collection_table_motion_update(ct, x, y, TRUE); | |
1371 } | |
1372 | |
1373 ct->drop_idle_id = -1; | |
1374 return FALSE; | |
1375 } | |
1376 | |
1377 static gint collection_table_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data) | |
1378 { | |
1379 CollectTable *ct = data; | |
1380 | |
1381 if (ct->drop_idle_id == -1) ct->drop_idle_id = g_idle_add(collection_table_auto_scroll_idle_cb, ct); | |
1382 | |
1383 return TRUE; | |
1384 } | |
1385 | |
1386 static void collection_table_scroll(CollectTable *ct, gint scroll) | |
1387 { | |
1388 if (!scroll) | |
1389 { | |
1390 if (ct->drop_idle_id != -1) | |
1391 { | |
1392 g_source_remove(ct->drop_idle_id); | |
1393 ct->drop_idle_id = -1; | |
1394 } | |
1395 widget_auto_scroll_stop(ct->listview); | |
1396 collection_table_insert_marker(ct, NULL, FALSE); | |
1397 } | |
1398 else | |
1399 { | |
1400 GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview)); | |
1401 widget_auto_scroll_start(ct->listview, adj, -1, thumb_max_height / 2, | |
1402 collection_table_auto_scroll_notify_cb, ct); | |
1403 } | |
1404 } | |
1405 | |
1406 /* | |
1407 *------------------------------------------------------------------- | |
1408 * mouse callbacks | |
1409 *------------------------------------------------------------------- | |
1410 */ | |
1411 | |
1412 static gint collection_table_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1413 { | |
1414 CollectTable *ct = data; | |
1415 | |
1416 collection_table_motion_update(ct, (gint)bevent->x, (gint)bevent->y, FALSE); | |
1417 | |
1418 return FALSE; | |
1419 } | |
1420 | |
1421 static gint collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1422 { | |
1423 CollectTable *ct = data; | |
1424 GtkTreeIter iter; | |
1425 CollectInfo *info; | |
1426 | |
1427 tip_unschedule(ct); | |
1428 | |
1429 info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter); | |
1430 | |
1431 ct->click_info = info; | |
1432 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, &iter); | |
1433 | |
1434 switch (bevent->button) | |
1435 { | |
1436 case 1: | |
1437 if (bevent->type == GDK_2BUTTON_PRESS) | |
1438 { | |
1439 if (info) | |
1440 { | |
1441 layout_image_set_collection(NULL, ct->cd, info); | |
1442 } | |
1443 } | |
1444 else if (!GTK_WIDGET_HAS_FOCUS(ct->listview)) | |
1445 { | |
1446 gtk_widget_grab_focus(ct->listview); | |
1447 } | |
1448 break; | |
1449 case 3: | |
1450 ct->popup = collection_table_popup_menu(ct, (info != NULL)); | |
1451 gtk_menu_popup(GTK_MENU(ct->popup), NULL, NULL, NULL, NULL, bevent->button, bevent->time); | |
1452 break; | |
1453 default: | |
1454 break; | |
1455 } | |
1456 | |
1457 return TRUE; | |
1458 } | |
1459 | |
1460 static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1461 { | |
1462 CollectTable *ct = data; | |
1463 GtkTreeIter iter; | |
1464 CollectInfo *info = NULL; | |
1465 | |
1466 tip_schedule(ct); | |
1467 | |
1468 if ((gint)bevent->x != 0 || (gint) bevent->y != 0) | |
1469 { | |
1470 info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter); | |
1471 } | |
1472 | |
1473 if (ct->click_info) | |
1474 { | |
1475 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL); | |
1476 } | |
1477 | |
1478 if (bevent->button == 1 && | |
1479 info && ct->click_info == info) | |
1480 { | |
1481 collection_table_set_focus(ct, info); | |
1482 | |
1483 if (bevent->state & GDK_CONTROL_MASK) | |
1484 { | |
1485 gint select; | |
1486 | |
1487 select = !INFO_SELECTED(info); | |
1488 if ((bevent->state & GDK_SHIFT_MASK) && ct->prev_selection) | |
1489 { | |
1490 collection_table_select_region_util(ct, ct->prev_selection, info, select); | |
1491 } | |
1492 else | |
1493 { | |
1494 collection_table_select_util(ct, info, select); | |
1495 } | |
1496 } | |
1497 else | |
1498 { | |
1499 collection_table_unselect_all(ct); | |
1500 | |
1501 if ((bevent->state & GDK_SHIFT_MASK) && | |
1502 ct->prev_selection) | |
1503 { | |
1504 collection_table_select_region_util(ct, ct->prev_selection, info, TRUE); | |
1505 } | |
1506 else | |
1507 { | |
1508 collection_table_select_util(ct, info, TRUE); | |
1509 } | |
1510 } | |
1511 } | |
1512 else if (bevent->button == 2 && | |
1513 info && ct->click_info == info) | |
1514 { | |
1515 collection_table_select_util(ct, info, !INFO_SELECTED(info)); | |
1516 } | |
1517 | |
1518 return TRUE; | |
1519 } | |
1520 | |
1521 static gint collection_table_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data) | |
1522 { | |
1523 CollectTable *ct = data; | |
1524 | |
1525 tip_unschedule(ct); | |
1526 return FALSE; | |
1527 } | |
1528 | |
1529 /* | |
1530 *------------------------------------------------------------------- | |
1531 * populate, add, insert, etc. | |
1532 *------------------------------------------------------------------- | |
1533 */ | |
1534 | |
1535 static gboolean collection_table_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data) | |
1536 { | |
1537 GList *list; | |
1538 | |
1539 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1); | |
1540 g_list_free(list); | |
1541 | |
1542 return FALSE; | |
1543 } | |
1544 | |
1545 static void collection_table_clear_store(CollectTable *ct) | |
1546 { | |
1547 GtkTreeModel *store; | |
1548 | |
1549 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)); | |
1550 gtk_tree_model_foreach(store, collection_table_destroy_node_cb, NULL); | |
1551 | |
1552 gtk_list_store_clear(GTK_LIST_STORE(store)); | |
1553 } | |
1554 | |
1555 static GList *collection_table_add_row(CollectTable *ct, GtkTreeIter *iter) | |
1556 { | |
1557 GtkListStore *store; | |
1558 GList *list = NULL; | |
1559 gint i; | |
1560 | |
1561 for (i = 0; i < ct->columns; i++) list = g_list_prepend(list, NULL); | |
1562 | |
1563 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview))); | |
1564 gtk_list_store_append(store, iter); | |
1565 gtk_list_store_set(store, iter, CTABLE_COLUMN_POINTER, list, -1); | |
1566 | |
1567 return list; | |
1568 } | |
1569 | |
1570 static void collection_table_populate(CollectTable *ct, gint resize) | |
1571 { | |
1572 gint row; | |
1573 GList *work; | |
1574 | |
1575 collection_table_verify_selections(ct); | |
1576 | |
1577 collection_table_clear_store(ct); | |
1578 | |
1579 if (resize) | |
1580 { | |
1581 gint i; | |
1582 gint thumb_width; | |
1583 | |
1584 thumb_width = collection_table_get_icon_width(ct); | |
1585 | |
1586 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++) | |
1587 { | |
1588 GtkTreeViewColumn *column; | |
1589 GtkCellRenderer *cell; | |
1590 GList *list; | |
1591 | |
1592 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), i); | |
1593 gtk_tree_view_column_set_visible(column, (i < ct->columns)); | |
1594 gtk_tree_view_column_set_fixed_width(column, thumb_width + (THUMB_BORDER_PADDING * 6)); | |
1595 | |
1596 list = gtk_tree_view_column_get_cell_renderers(column); | |
1597 cell = (list) ? list->data : NULL; | |
1598 g_list_free(list); | |
1599 | |
1600 if (cell && GQV_IS_CELL_RENDERER_ICON(cell)) | |
1601 { | |
1602 g_object_set(G_OBJECT(cell), "fixed_width", thumb_width, | |
1603 "fixed_height", thumb_max_height, | |
1604 "show_text", ct->show_text, NULL); | |
1605 } | |
1606 } | |
1607 if (GTK_WIDGET_REALIZED(ct->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(ct->listview)); | |
1608 } | |
1609 | |
1610 row = -1; | |
1611 work = ct->cd->list; | |
1612 while (work) | |
1613 { | |
1614 GList *list; | |
1615 GtkTreeIter iter; | |
1616 | |
1617 row++; | |
1618 | |
1619 list = collection_table_add_row(ct, &iter); | |
1620 while (work && list) | |
1621 { | |
1622 list->data = work->data; | |
1623 list = list->next; | |
1624 work = work->next; | |
1625 } | |
1626 } | |
1627 | |
1628 ct->rows = row + 1; | |
1629 | |
1630 collection_table_update_focus(ct); | |
1631 collection_table_update_status(ct); | |
1632 } | |
1633 | |
1634 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gint force) | |
1635 { | |
1636 gint new_cols; | |
1637 gint thumb_width; | |
1638 | |
1639 thumb_width = collection_table_get_icon_width(ct); | |
1640 | |
1641 new_cols = w / (thumb_width + (THUMB_BORDER_PADDING * 6)); | |
1642 if (new_cols < 1) new_cols = 1; | |
1643 | |
1644 if (!force && new_cols == ct->columns) return; | |
1645 | |
1646 ct->columns = new_cols; | |
1647 | |
1648 collection_table_populate(ct, TRUE); | |
1649 | |
1650 if (debug) printf("col tab pop cols=%d rows=%d\n", ct->columns, ct->rows); | |
1651 } | |
1652 | |
1653 static void collection_table_sync(CollectTable *ct) | |
1654 { | |
1655 GtkTreeModel *store; | |
1656 GtkTreeIter iter; | |
1657 GList *work; | |
1658 gint r, c; | |
1659 | |
1660 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)); | |
1661 | |
1662 r = -1; | |
1663 c = 0; | |
1664 | |
1665 work = ct->cd->list; | |
1666 while (work) | |
1667 { | |
1668 GList *list; | |
1669 r++; | |
1670 c = 0; | |
1671 if (gtk_tree_model_iter_nth_child(store, &iter, NULL, r)) | |
1672 { | |
1673 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1); | |
1674 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1); | |
1675 } | |
1676 else | |
1677 { | |
1678 list = collection_table_add_row(ct, &iter); | |
1679 } | |
1680 | |
1681 while (list) | |
1682 { | |
1683 CollectInfo *info; | |
1684 if (work) | |
1685 { | |
1686 info = work->data; | |
1687 work = work->next; | |
1688 c++; | |
1689 } | |
1690 else | |
1691 { | |
1692 info = NULL; | |
1693 } | |
1694 if (list) | |
1695 { | |
1696 list->data = info; | |
1697 list = list->next; | |
1698 } | |
1699 } | |
1700 } | |
1701 | |
1702 r++; | |
1703 while (gtk_tree_model_iter_nth_child(store, &iter, NULL, r)) | |
1704 { | |
1705 GList *list; | |
1706 | |
1707 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1); | |
1708 gtk_list_store_remove(GTK_LIST_STORE(store), &iter); | |
1709 g_list_free(list); | |
1710 } | |
1711 | |
1712 ct->rows = r; | |
1713 | |
1714 collection_table_update_focus(ct); | |
1715 collection_table_update_status(ct); | |
1716 } | |
1717 | |
1718 static gint collection_table_sync_idle_cb(gpointer data) | |
1719 { | |
1720 CollectTable *ct = data; | |
1721 | |
1722 if (ct->sync_idle_id == -1) return FALSE; | |
1723 ct->sync_idle_id = -1; | |
1724 | |
1725 collection_table_sync(ct); | |
1726 return FALSE; | |
1727 } | |
1728 | |
1729 static void collection_table_sync_idle(CollectTable *ct) | |
1730 { | |
1731 if (ct->sync_idle_id == -1) | |
1732 { | |
1733 /* high priority, the view needs to be resynced before a redraw | |
1734 * may contain invalid pointers at this time | |
1735 */ | |
1736 ct->sync_idle_id = g_idle_add_full(G_PRIORITY_HIGH, collection_table_sync_idle_cb, ct, NULL); | |
1737 } | |
1738 } | |
1739 | |
138 | 1740 void collection_table_add_filelist(CollectTable *ct, GList *list) |
9 | 1741 { |
1742 GList *work; | |
1743 | |
1744 if (!list) return; | |
1745 | |
1746 work = list; | |
1747 while (work) | |
1748 { | |
138 | 1749 collection_add(ct->cd, (FileData *)work->data, FALSE); |
9 | 1750 work = work->next; |
1751 } | |
1752 } | |
1753 | |
138 | 1754 static void collection_table_insert_filelist(CollectTable *ct, GList *list, CollectInfo *insert_info) |
9 | 1755 { |
1756 GList *work; | |
1757 | |
1758 if (!list) return; | |
1759 | |
1760 work = list; | |
1761 while (work) | |
1762 { | |
138 | 1763 collection_insert(ct->cd, (FileData *)work->data, insert_info, FALSE); |
9 | 1764 work = work->next; |
1765 } | |
1766 | |
1767 collection_table_sync_idle(ct); | |
1768 } | |
1769 | |
1770 static void collection_table_move_by_info_list(CollectTable *ct, GList *info_list, gint row, gint col) | |
1771 { | |
1772 GList *work; | |
1773 GList *insert_pos = NULL; | |
1774 GList *temp; | |
1775 CollectInfo *info; | |
1776 | |
1777 if (!info_list) return; | |
1778 | |
1779 info = collection_table_find_data(ct, row, col, NULL); | |
1780 | |
1781 if (!info_list->next && info_list->data == info) return; | |
1782 | |
1783 if (info) insert_pos = g_list_find(ct->cd->list, info); | |
1784 | |
1785 /* FIXME: this may get slow for large lists */ | |
1786 work = info_list; | |
1787 while (insert_pos && work) | |
1788 { | |
1789 if (insert_pos->data == work->data) | |
1790 { | |
1791 insert_pos = insert_pos->next; | |
1792 work = info_list; | |
1793 } | |
1794 else | |
1795 { | |
1796 work = work->next; | |
1797 } | |
1798 } | |
1799 | |
1800 work = info_list; | |
1801 while (work) | |
1802 { | |
1803 ct->cd->list = g_list_remove(ct->cd->list, work->data); | |
1804 work = work->next; | |
1805 } | |
1806 | |
1807 /* place them back in */ | |
1808 temp = g_list_copy(info_list); | |
1809 | |
1810 if (insert_pos) | |
1811 { | |
1812 ct->cd->list = uig_list_insert_list(ct->cd->list, insert_pos, temp); | |
1813 } | |
1814 else if (info) | |
1815 { | |
1816 ct->cd->list = g_list_concat(temp, ct->cd->list); | |
1817 } | |
1818 else | |
1819 { | |
1820 ct->cd->list = g_list_concat(ct->cd->list, temp); | |
1821 } | |
1822 | |
1823 ct->cd->changed = TRUE; | |
1824 | |
1825 collection_table_sync_idle(ct); | |
1826 } | |
1827 | |
1828 | |
1829 /* | |
1830 *------------------------------------------------------------------- | |
1831 * updating | |
1832 *------------------------------------------------------------------- | |
1833 */ | |
1834 | |
1835 void collection_table_file_update(CollectTable *ct, CollectInfo *info) | |
1836 { | |
1837 GtkTreeIter iter; | |
1838 gint row, col; | |
1839 gdouble value; | |
1840 | |
1841 if (!info) | |
1842 { | |
1843 collection_table_update_extras(ct, FALSE, 0.0); | |
1844 return; | |
1845 } | |
1846 | |
1847 if (!collection_table_find_position(ct, info, &row, &col)) return; | |
1848 | |
1849 if (ct->columns != 0 && ct->rows != 0) | |
1850 { | |
1851 value = (gdouble)(row * ct->columns + col) / (ct->columns * ct->rows); | |
1852 } | |
1853 else | |
1854 { | |
1855 value = 0.0; | |
1856 } | |
1857 | |
1858 collection_table_update_extras(ct, TRUE, value); | |
1859 | |
1860 if (collection_table_find_iter(ct, info, &iter, NULL)) | |
1861 { | |
1862 GtkTreeModel *store; | |
1863 GList *list; | |
1864 | |
1865 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)); | |
1866 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1); | |
1867 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1); | |
1868 } | |
1869 } | |
1870 | |
1871 void collection_table_file_add(CollectTable *ct, CollectInfo *info) | |
1872 { | |
1873 collection_table_sync_idle(ct); | |
1874 } | |
1875 | |
1876 void collection_table_file_insert(CollectTable *ct, CollectInfo *ci) | |
1877 { | |
1878 collection_table_sync_idle(ct); | |
1879 } | |
1880 | |
1881 void collection_table_file_remove(CollectTable *ct, CollectInfo *ci) | |
1882 { | |
1883 if (ci && INFO_SELECTED(ci)) | |
1884 { | |
1885 ct->selection = g_list_remove(ct->selection, ci); | |
1886 } | |
1887 | |
1888 collection_table_sync_idle(ct); | |
1889 } | |
1890 | |
1891 void collection_table_refresh(CollectTable *ct) | |
1892 { | |
1893 collection_table_populate(ct, FALSE); | |
1894 } | |
1895 | |
1896 /* | |
1897 *------------------------------------------------------------------- | |
1898 * dnd | |
1899 *------------------------------------------------------------------- | |
1900 */ | |
1901 | |
1902 static void collection_table_add_dir_recursive(CollectTable *ct, gchar *path, gint recursive) | |
1903 { | |
1904 GList *d = NULL; | |
1905 GList *f = NULL; | |
1906 | |
138 | 1907 if (filelist_read(path, &f, recursive ? &d : NULL)) |
9 | 1908 { |
1909 GList *work; | |
1910 | |
138 | 1911 f = filelist_filter(f, FALSE); |
1912 d = filelist_filter(d, TRUE); | |
1913 | |
1914 f = filelist_sort_path(f); | |
1915 d = filelist_sort_path(d); | |
1916 | |
1917 collection_table_insert_filelist(ct, f, ct->marker_info); | |
9 | 1918 |
1919 work = g_list_last(d); | |
1920 while (work) | |
1921 { | |
138 | 1922 collection_table_add_dir_recursive(ct, ((FileData *)work->data)->path, TRUE); |
9 | 1923 work = work->prev; |
1924 } | |
138 | 1925 filelist_free(f); |
1926 filelist_free(d); | |
9 | 1927 } |
1928 } | |
1929 | |
1930 static void confirm_dir_list_do(CollectTable *ct, GList *list, gint recursive) | |
1931 { | |
1932 GList *work = list; | |
1933 while (work) | |
1934 { | |
138 | 1935 FileData *fd = work->data; |
9 | 1936 work = work->next; |
138 | 1937 if (isdir(fd->path)) collection_table_add_dir_recursive(ct, fd->path, recursive); |
9 | 1938 } |
138 | 1939 collection_table_insert_filelist(ct, list, ct->marker_info); |
9 | 1940 } |
1941 | |
1942 | |
1943 static void confirm_dir_list_add(GtkWidget *widget, gpointer data) | |
1944 { | |
1945 CollectTable *ct = data; | |
1946 | |
1947 confirm_dir_list_do(ct, ct->drop_list, FALSE); | |
1948 } | |
1949 | |
1950 static void confirm_dir_list_recurse(GtkWidget *widget, gpointer data) | |
1951 { | |
1952 CollectTable *ct = data; | |
1953 | |
1954 confirm_dir_list_do(ct, ct->drop_list, TRUE); | |
1955 } | |
1956 | |
1957 static void confirm_dir_list_skip(GtkWidget *widget, gpointer data) | |
1958 { | |
1959 CollectTable *ct = data; | |
1960 | |
138 | 1961 collection_table_insert_filelist(ct, ct->drop_list, ct->marker_info); |
9 | 1962 } |
1963 | |
1964 static GtkWidget *collection_table_drop_menu(CollectTable *ct) | |
1965 { | |
1966 GtkWidget *menu; | |
1967 | |
1968 menu = popup_menu_short_lived(); | |
1969 g_signal_connect(G_OBJECT(menu), "destroy", | |
1970 G_CALLBACK(collection_table_popup_destroy_cb), ct); | |
1971 | |
1972 menu_item_add_stock(menu, _("Dropped list includes folders."), GTK_STOCK_DND_MULTIPLE, NULL, NULL); | |
1973 menu_item_add_divider(menu); | |
1974 menu_item_add_stock(menu, _("_Add contents"), GTK_STOCK_OK, | |
1975 G_CALLBACK(confirm_dir_list_add), ct); | |
1976 menu_item_add_stock(menu, _("Add contents _recursive"), GTK_STOCK_ADD, | |
1977 G_CALLBACK(confirm_dir_list_recurse), ct); | |
1978 menu_item_add_stock(menu, _("_Skip folders"), GTK_STOCK_REMOVE, | |
1979 G_CALLBACK(confirm_dir_list_skip), ct); | |
1980 menu_item_add_divider(menu); | |
1981 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, ct); | |
1982 | |
1983 return menu; | |
1984 } | |
1985 | |
1986 /* | |
1987 *------------------------------------------------------------------- | |
1988 * dnd | |
1989 *------------------------------------------------------------------- | |
1990 */ | |
1991 | |
1992 static GtkTargetEntry collection_drag_types[] = { | |
1993 { "application/x-gqview-collection-member", 0, TARGET_APP_COLLECTION_MEMBER }, | |
1994 { "text/uri-list", 0, TARGET_URI_LIST }, | |
1995 { "text/plain", 0, TARGET_TEXT_PLAIN } | |
1996 }; | |
1997 static gint n_collection_drag_types = 3; | |
1998 | |
1999 static GtkTargetEntry collection_drop_types[] = { | |
2000 { "application/x-gqview-collection-member", 0, TARGET_APP_COLLECTION_MEMBER }, | |
2001 { "text/uri-list", 0, TARGET_URI_LIST } | |
2002 }; | |
2003 static gint n_collection_drop_types = 2; | |
2004 | |
2005 | |
2006 static void collection_table_dnd_get(GtkWidget *widget, GdkDragContext *context, | |
2007 GtkSelectionData *selection_data, guint info, | |
2008 guint time, gpointer data) | |
2009 { | |
2010 CollectTable *ct = data; | |
2011 gint selected; | |
2012 GList *list = NULL; | |
2013 gchar *uri_text = NULL; | |
2014 gint total; | |
2015 | |
2016 if (!ct->click_info) return; | |
2017 | |
2018 selected = INFO_SELECTED(ct->click_info); | |
2019 | |
2020 switch (info) | |
2021 { | |
2022 case TARGET_APP_COLLECTION_MEMBER: | |
2023 if (selected) | |
2024 { | |
2025 uri_text = collection_info_list_to_dnd_data(ct->cd, ct->selection, &total); | |
2026 } | |
2027 else | |
2028 { | |
2029 list = g_list_append(NULL, ct->click_info); | |
2030 uri_text = collection_info_list_to_dnd_data(ct->cd, list, &total); | |
2031 g_list_free(list); | |
2032 } | |
2033 break; | |
2034 case TARGET_URI_LIST: | |
2035 case TARGET_TEXT_PLAIN: | |
2036 default: | |
2037 if (selected) | |
2038 { | |
2039 list = collection_table_selection_get_list(ct); | |
2040 } | |
2041 else | |
2042 { | |
138 | 2043 list = g_list_append(NULL, file_data_ref(ct->click_info->fd)); |
9 | 2044 } |
2045 if (!list) return; | |
2046 | |
138 | 2047 uri_text = uri_text_from_filelist(list, &total, (info == TARGET_TEXT_PLAIN)); |
2048 filelist_free(list); | |
9 | 2049 break; |
2050 } | |
2051 | |
2052 gtk_selection_data_set(selection_data, selection_data->target, | |
64
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
2053 8, (guchar *)uri_text, total); |
9 | 2054 g_free(uri_text); |
2055 } | |
2056 | |
2057 | |
2058 static void collection_table_dnd_receive(GtkWidget *widget, GdkDragContext *context, | |
2059 gint x, gint y, | |
2060 GtkSelectionData *selection_data, guint info, | |
2061 guint time, gpointer data) | |
2062 { | |
2063 CollectTable *ct = data; | |
2064 GList *list = NULL; | |
2065 GList *info_list = NULL; | |
2066 CollectionData *source; | |
2067 CollectInfo *drop_info; | |
2068 GList *work; | |
2069 | |
64
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
2070 if (debug) printf("%s\n", selection_data->data); |
9 | 2071 |
2072 collection_table_scroll(ct, FALSE); | |
2073 collection_table_insert_marker(ct, NULL, FALSE); | |
2074 | |
2075 drop_info = collection_table_insert_point(ct, x, y); | |
2076 | |
2077 switch (info) | |
2078 { | |
2079 case TARGET_APP_COLLECTION_MEMBER: | |
2080 source = collection_from_dnd_data((gchar *)selection_data->data, &list, &info_list); | |
2081 if (source) | |
2082 { | |
2083 if (source == ct->cd) | |
2084 { | |
2085 gint row = -1; | |
2086 gint col = -1; | |
2087 | |
2088 /* it is a move within a collection */ | |
138 | 2089 filelist_free(list); |
9 | 2090 list = NULL; |
2091 | |
2092 if (!drop_info) | |
2093 { | |
2094 collection_table_move_by_info_list(ct, info_list, -1, -1); | |
2095 } | |
2096 else if (collection_table_find_position(ct, drop_info, &row, &col)) | |
2097 { | |
2098 collection_table_move_by_info_list(ct, info_list, row, col); | |
2099 } | |
2100 } | |
2101 else | |
2102 { | |
2103 /* it is a move/copy across collections */ | |
2104 if (context->action == GDK_ACTION_MOVE) | |
2105 { | |
2106 collection_remove_by_info_list(source, info_list); | |
2107 } | |
2108 } | |
2109 g_list_free(info_list); | |
2110 } | |
2111 break; | |
2112 case TARGET_URI_LIST: | |
138 | 2113 list = uri_filelist_from_text((gchar *)selection_data->data, TRUE); |
9 | 2114 work = list; |
2115 while (work) | |
2116 { | |
138 | 2117 FileData *fd = work->data; |
2118 if (isdir(fd->path)) | |
9 | 2119 { |
2120 GtkWidget *menu; | |
2121 | |
2122 ct->drop_list = list; | |
2123 ct->drop_info = drop_info; | |
2124 menu = collection_table_drop_menu(ct); | |
2125 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, time); | |
2126 return; | |
2127 } | |
2128 work = work->next; | |
2129 } | |
2130 break; | |
2131 default: | |
2132 list = NULL; | |
2133 break; | |
2134 } | |
2135 | |
2136 if (list) | |
2137 { | |
138 | 2138 collection_table_insert_filelist(ct, list, drop_info); |
2139 filelist_free(list); | |
9 | 2140 } |
2141 } | |
2142 | |
2143 static void collection_table_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
2144 { | |
2145 CollectTable *ct = data; | |
2146 | |
2147 if (ct->click_info && ct->click_info->pixbuf) | |
2148 { | |
2149 gint items; | |
2150 | |
2151 if (INFO_SELECTED(ct->click_info)) | |
2152 items = g_list_length(ct->selection); | |
2153 else | |
2154 items = 1; | |
2155 dnd_set_drag_icon(widget, context, ct->click_info->pixbuf, items); | |
2156 } | |
2157 } | |
2158 | |
2159 static void collection_table_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
2160 { | |
2161 CollectTable *ct = data; | |
2162 | |
2163 /* apparently a leave event is not generated on a drop */ | |
2164 tip_unschedule(ct); | |
2165 | |
2166 collection_table_scroll(ct, FALSE); | |
2167 } | |
2168 | |
2169 static gint collection_table_dnd_motion(GtkWidget *widget, GdkDragContext *context, | |
2170 gint x, gint y, guint time, gpointer data) | |
2171 { | |
2172 CollectTable *ct = data; | |
2173 | |
2174 collection_table_motion_update(ct, x, y, TRUE); | |
2175 collection_table_scroll(ct, TRUE); | |
2176 | |
2177 return FALSE; | |
2178 } | |
2179 | |
2180 static void collection_table_dnd_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer data) | |
2181 { | |
2182 CollectTable *ct = data; | |
2183 | |
2184 collection_table_scroll(ct, FALSE); | |
2185 } | |
2186 | |
2187 static void collection_table_dnd_init(CollectTable *ct) | |
2188 { | |
2189 gtk_drag_source_set(ct->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, | |
2190 collection_drag_types, n_collection_drag_types, | |
2191 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
2192 g_signal_connect(G_OBJECT(ct->listview), "drag_data_get", | |
2193 G_CALLBACK(collection_table_dnd_get), ct); | |
2194 g_signal_connect(G_OBJECT(ct->listview), "drag_begin", | |
2195 G_CALLBACK(collection_table_dnd_begin), ct); | |
2196 g_signal_connect(G_OBJECT(ct->listview), "drag_end", | |
2197 G_CALLBACK(collection_table_dnd_end), ct); | |
2198 | |
2199 gtk_drag_dest_set(ct->listview, | |
2200 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP, | |
2201 collection_drop_types, n_collection_drop_types, | |
2202 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK); | |
2203 g_signal_connect(G_OBJECT(ct->listview), "drag_motion", | |
2204 G_CALLBACK(collection_table_dnd_motion), ct); | |
2205 g_signal_connect(G_OBJECT(ct->listview), "drag_leave", | |
2206 G_CALLBACK(collection_table_dnd_leave), ct); | |
2207 g_signal_connect(G_OBJECT(ct->listview), "drag_data_received", | |
2208 G_CALLBACK(collection_table_dnd_receive), ct); | |
2209 } | |
2210 | |
2211 /* | |
2212 *----------------------------------------------------------------------------- | |
2213 * draw, etc. | |
2214 *----------------------------------------------------------------------------- | |
2215 */ | |
2216 | |
2217 typedef struct _ColumnData ColumnData; | |
2218 struct _ColumnData | |
2219 { | |
2220 CollectTable *ct; | |
2221 gint number; | |
2222 }; | |
2223 | |
2224 static void collection_table_cell_data_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, | |
2225 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) | |
2226 { | |
2227 ColumnData *cd = data; | |
2228 CollectTable *ct; | |
2229 GtkStyle *style; | |
2230 GList *list; | |
2231 CollectInfo *info; | |
2232 GdkColor color_fg; | |
2233 GdkColor color_bg; | |
2234 | |
2235 ct = cd->ct; | |
2236 | |
2237 gtk_tree_model_get(tree_model, iter, CTABLE_COLUMN_POINTER, &list, -1); | |
2238 info = g_list_nth_data(list, cd->number); | |
2239 | |
2240 style = gtk_widget_get_style(ct->listview); | |
2241 if (info && (info->flag_mask & SELECTION_SELECTED) ) | |
2242 { | |
2243 memcpy(&color_fg, &style->text[GTK_STATE_SELECTED], sizeof(color_fg)); | |
2244 memcpy(&color_bg, &style->base[GTK_STATE_SELECTED], sizeof(color_bg)); | |
2245 } | |
2246 else | |
2247 { | |
2248 memcpy(&color_fg, &style->text[GTK_STATE_NORMAL], sizeof(color_fg)); | |
2249 memcpy(&color_bg, &style->base[GTK_STATE_NORMAL], sizeof(color_bg)); | |
2250 } | |
2251 | |
2252 if (info && (info->flag_mask & SELECTION_PRELIGHT)) | |
2253 { | |
2254 #if 0 | |
2255 shift_color(&color_fg, -1, 0); | |
2256 #endif | |
2257 shift_color(&color_bg, -1, 0); | |
2258 } | |
2259 | |
2260 if (GQV_IS_CELL_RENDERER_ICON(cell)) | |
2261 { | |
2262 if (info) | |
2263 { | |
2264 g_object_set(cell, "pixbuf", info->pixbuf, | |
138 | 2265 "text", info->fd->name, |
9 | 2266 "cell-background-gdk", &color_bg, |
2267 "cell-background-set", TRUE, | |
2268 "foreground-gdk", &color_fg, | |
2269 "foreground-set", TRUE, | |
2270 "has-focus", (ct->focus_info == info), NULL); | |
2271 } | |
2272 else | |
2273 { | |
2274 g_object_set(cell, "pixbuf", NULL, | |
2275 "text", NULL, | |
2276 "cell-background-set", FALSE, | |
2277 "foreground-set", FALSE, | |
2278 "has-focus", FALSE, NULL); | |
2279 } | |
2280 } | |
2281 } | |
2282 | |
2283 static void collection_table_append_column(CollectTable *ct, gint n) | |
2284 { | |
2285 ColumnData *cd; | |
2286 GtkTreeViewColumn *column; | |
2287 GtkCellRenderer *renderer; | |
2288 | |
2289 column = gtk_tree_view_column_new(); | |
2290 gtk_tree_view_column_set_min_width(column, 0); | |
2291 | |
2292 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); | |
2293 gtk_tree_view_column_set_alignment(column, 0.5); | |
2294 | |
2295 renderer = gqv_cell_renderer_icon_new(); | |
2296 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
2297 g_object_set(G_OBJECT(renderer), "xpad", THUMB_BORDER_PADDING * 2, | |
2298 "ypad", THUMB_BORDER_PADDING, | |
2299 "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL); | |
2300 | |
2301 g_object_set_data(G_OBJECT(column), "column_number", GINT_TO_POINTER(n)); | |
2302 | |
2303 cd = g_new0(ColumnData, 1); | |
2304 cd->ct = ct; | |
2305 cd->number = n; | |
2306 gtk_tree_view_column_set_cell_data_func(column, renderer, collection_table_cell_data_cb, cd, g_free); | |
2307 | |
2308 gtk_tree_view_append_column(GTK_TREE_VIEW(ct->listview), column); | |
2309 } | |
2310 | |
2311 /* | |
2312 *------------------------------------------------------------------- | |
2313 * init, destruction | |
2314 *------------------------------------------------------------------- | |
2315 */ | |
2316 | |
2317 static void collection_table_destroy(GtkWidget *widget, gpointer data) | |
2318 { | |
2319 CollectTable *ct = data; | |
2320 | |
2321 if (ct->popup) | |
2322 { | |
2323 g_signal_handlers_disconnect_matched(GTK_OBJECT(ct->popup), G_SIGNAL_MATCH_DATA, | |
2324 0, 0, 0, NULL, ct); | |
2325 gtk_widget_destroy(ct->popup); | |
2326 } | |
2327 | |
2328 if (ct->sync_idle_id != -1) g_source_remove(ct->sync_idle_id); | |
2329 | |
2330 tip_unschedule(ct); | |
2331 collection_table_scroll(ct, FALSE); | |
2332 | |
2333 g_free(ct); | |
2334 } | |
2335 | |
2336 static void collection_table_sized(GtkWidget *widget, GtkAllocation *allocation, gpointer data) | |
2337 { | |
2338 CollectTable *ct = data; | |
2339 | |
2340 collection_table_populate_at_new_size(ct, allocation->width, allocation->height, FALSE); | |
2341 } | |
2342 | |
2343 CollectTable *collection_table_new(CollectionData *cd) | |
2344 { | |
2345 CollectTable *ct; | |
2346 GtkListStore *store; | |
2347 GtkTreeSelection *selection; | |
2348 gint i; | |
2349 | |
2350 ct = g_new0(CollectTable, 1); | |
2351 ct->cd = cd; | |
2352 ct->columns = 0; | |
2353 ct->rows = 0; | |
2354 | |
2355 ct->selection = NULL; | |
2356 ct->prev_selection = NULL; | |
2357 | |
2358 ct->tip_window = NULL; | |
2359 ct->tip_delay_id = -1; | |
2360 | |
2361 ct->marker_window = NULL; | |
2362 ct->marker_info = NULL; | |
2363 | |
2364 ct->status_label = NULL; | |
2365 ct->extra_label = NULL; | |
2366 | |
2367 ct->focus_row = 0; | |
2368 ct->focus_column = 0; | |
2369 ct->focus_info = NULL; | |
2370 | |
2371 ct->show_text = show_icon_names; | |
2372 | |
2373 ct->sync_idle_id = -1; | |
2374 ct->drop_idle_id = -1; | |
2375 | |
2376 ct->popup = NULL; | |
2377 ct->drop_info = NULL; | |
2378 ct->drop_list = NULL; | |
2379 | |
2380 ct->scrolled = gtk_scrolled_window_new(NULL, NULL); | |
2381 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(ct->scrolled), GTK_SHADOW_IN); | |
2382 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (ct->scrolled), | |
2383 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
2384 | |
2385 store = gtk_list_store_new(1, G_TYPE_POINTER); | |
2386 ct->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
2387 g_object_unref(store); | |
2388 | |
2389 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ct->listview)); | |
2390 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_NONE); | |
2391 | |
2392 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(ct->listview), FALSE); | |
2393 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ct->listview), FALSE); | |
2394 | |
2395 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++) | |
2396 { | |
2397 collection_table_append_column(ct, i); | |
2398 } | |
2399 | |
2400 /* zero width column to hide tree view focus, we draw it ourselves */ | |
2401 collection_table_append_column(ct, i); | |
2402 /* end column to fill white space */ | |
2403 collection_table_append_column(ct, i); | |
2404 | |
2405 g_signal_connect(G_OBJECT(ct->listview), "destroy", | |
2406 G_CALLBACK(collection_table_destroy), ct); | |
2407 g_signal_connect(G_OBJECT(ct->listview), "size_allocate", | |
2408 G_CALLBACK(collection_table_sized), ct); | |
2409 g_signal_connect(G_OBJECT(ct->listview), "key_press_event", | |
2410 G_CALLBACK(collection_table_press_key_cb), ct); | |
2411 | |
2412 gtk_container_add(GTK_CONTAINER(ct->scrolled), ct->listview); | |
2413 gtk_widget_show(ct->listview); | |
2414 | |
2415 collection_table_dnd_init(ct); | |
2416 | |
2417 gtk_widget_set_events(ct->listview, GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK | | |
2418 GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK); | |
2419 g_signal_connect(G_OBJECT(ct->listview),"button_press_event", | |
2420 G_CALLBACK(collection_table_press_cb), ct); | |
2421 g_signal_connect(G_OBJECT(ct->listview),"button_release_event", | |
2422 G_CALLBACK(collection_table_release_cb), ct); | |
2423 g_signal_connect(G_OBJECT(ct->listview),"motion_notify_event", | |
2424 G_CALLBACK(collection_table_motion_cb), ct); | |
2425 g_signal_connect(G_OBJECT(ct->listview), "leave_notify_event", | |
2426 G_CALLBACK(collection_table_leave_cb), ct); | |
2427 | |
2428 return ct; | |
2429 } | |
2430 | |
2431 void collection_table_set_labels(CollectTable *ct, GtkWidget *status, GtkWidget *extra) | |
2432 { | |
2433 ct->status_label = status; | |
2434 ct->extra_label = extra; | |
2435 collection_table_update_status(ct); | |
2436 collection_table_update_extras(ct, FALSE, 0.0); | |
2437 } | |
2438 | |
2439 CollectInfo *collection_table_get_focus_info(CollectTable *ct) | |
2440 { | |
2441 return collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL); | |
2442 } | |
2443 |