Remove commented out code.
[geeqie.git] / src / collect-table.c
index 8c69d0c..160c1b6 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Geeqie
  * (C) 2004 John Ellis
- * Copyright (C) 2008 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
  *
  * Author: John Ellis
  *
 #include "editors.h"
 #include "filedata.h"
 #include "img-view.h"
-#include "info.h"
 #include "layout.h"
 #include "layout_image.h"
 #include "menu.h"
 #include "print.h"
 #include "utilops.h"
-#include "ui_bookmark.h"
 #include "ui_fileops.h"
 #include "ui_menu.h"
 #include "ui_tree_edit.h"
+#include "uri_utils.h"
 
 #include "icons/marker.xpm"
 #define MARKER_WIDTH 26
@@ -66,7 +65,7 @@ typedef enum {
 #define INFO_SELECTED(x) (x->flag_mask & SELECTION_SELECTED)
 
 
-static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gint force);
+static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gboolean force);
 
 
 /*
@@ -75,7 +74,7 @@ static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint
  *-------------------------------------------------------------------
  */
 
-static gint collection_table_find_position(CollectTable *ct, CollectInfo *info, gint *row, gint *col)
+static gboolean collection_table_find_position(CollectTable *ct, CollectInfo *info, gint *row, gint *col)
 {
        gint n;
 
@@ -89,7 +88,7 @@ static gint collection_table_find_position(CollectTable *ct, CollectInfo *info,
        return TRUE;
 }
 
-static gint collection_table_find_iter(CollectTable *ct, CollectInfo *info, GtkTreeIter *iter, gint *column)
+static gboolean collection_table_find_iter(CollectTable *ct, CollectInfo *info, GtkTreeIter *iter, gint *column)
 {
        GtkTreeModel *store;
        gint row, col;
@@ -150,30 +149,85 @@ static CollectInfo *collection_table_find_data_by_coord(CollectTable *ct, gint x
        return g_list_nth_data(list, n);
 }
 
+static guint collection_table_list_count(CollectTable *ct, gint64 *bytes)
+{
+       if (bytes)
+               {
+               gint64 b = 0;
+               GList *work;
+
+               work = ct->cd->list;
+               while (work)
+                       {
+                       CollectInfo *ci = work->data;
+                       work = work->next;
+                       b += ci->fd->size;
+                       }
+
+               *bytes = b;
+               }
+
+       return g_list_length(ct->cd->list);
+}
+
+static guint collection_table_selection_count(CollectTable *ct, gint64 *bytes)
+{
+       if (bytes)
+               {
+               gint64 b = 0;
+               GList *work;
+
+               work = ct->selection;
+               while (work)
+                       {
+                       CollectInfo *ci = work->data;
+                       work = work->next;
+                       b += ci->fd->size;
+                       }
+
+               *bytes = b;
+               }
+
+       return g_list_length(ct->selection);
+}
+
 static void collection_table_update_status(CollectTable *ct)
 {
        gchar *buf;
+       guint n;
+       gint64 n_bytes = 0;
+       guint s;
+       gint64 s_bytes = 0;
 
        if (!ct->status_label) return;
 
-       if (!ct->cd->list)
+       n = collection_table_list_count(ct, &n_bytes);
+       s = collection_table_selection_count(ct, &s_bytes);
+
+       if (s > 0)
                {
-               buf = g_strdup(_("Empty"));
+               gchar *b = text_from_size_abrev(n_bytes);
+               gchar *sb = text_from_size_abrev(s_bytes);
+               buf = g_strdup_printf(_("%s, %d images (%s, %d)"), b, n, sb, s);
+               g_free(b);
+               g_free(sb);
                }
-       else if (ct->selection)
+       else if (n > 0)
                {
-               buf = g_strdup_printf(_("%d images (%d)"), g_list_length(ct->cd->list), g_list_length(ct->selection));
+               gchar *b = text_from_size_abrev(n_bytes);
+               buf = g_strdup_printf(_("%s, %d images"), b, n);
+               g_free(b);
                }
        else
                {
-               buf = g_strdup_printf(_("%d images"), g_list_length(ct->cd->list));
+               buf = g_strdup(_("Empty"));
                }
 
        gtk_label_set_text(GTK_LABEL(ct->status_label), buf);
        g_free(buf);
 }
 
-static void collection_table_update_extras(CollectTable *ct, gint loading, gdouble value)
+static void collection_table_update_extras(CollectTable *ct, gboolean loading, gdouble value)
 {
        gchar *text;
 
@@ -190,10 +244,12 @@ static void collection_table_update_extras(CollectTable *ct, gint loading, gdoub
 
 static void collection_table_toggle_filenames(CollectTable *ct)
 {
+       GtkAllocation allocation;
        ct->show_text = !ct->show_text;
        options->show_icon_names = ct->show_text;
 
-       collection_table_populate_at_new_size(ct, ct->listview->allocation.width, ct->listview->allocation.height, TRUE);
+       gtk_widget_get_allocation(ct->listview, &allocation);
+       collection_table_populate_at_new_size(ct, allocation.width, allocation.height, TRUE);
 }
 
 static gint collection_table_get_icon_width(CollectTable *ct)
@@ -313,6 +369,37 @@ void collection_table_unselect_all(CollectTable *ct)
        collection_table_update_status(ct);
 }
 
+/* Invert the current collection's selection */
+static void collection_table_select_invert_all(CollectTable *ct)
+{
+       GList *work;
+       GList *new_selection = NULL;
+
+       work = ct->cd->list;
+       while (work)
+               {
+               CollectInfo *info = work->data;
+
+               if (INFO_SELECTED(info))
+                       {
+                       collection_table_selection_remove(ct, info, SELECTION_SELECTED, NULL);
+                       }
+               else
+                       {
+                       new_selection = g_list_append(new_selection, info);
+                       collection_table_selection_add(ct, info, SELECTION_SELECTED, NULL);
+
+                       }
+
+               work = work->next;
+               }
+
+       g_list_free(ct->selection);
+       ct->selection = new_selection;
+
+       collection_table_update_status(ct);
+}
+
 static void collection_table_select(CollectTable *ct, CollectInfo *info)
 {
        ct->prev_selection = info;
@@ -337,7 +424,7 @@ static void collection_table_unselect(CollectTable *ct, CollectInfo *info)
        collection_table_update_status(ct);
 }
 
-static void collection_table_select_util(CollectTable *ct, CollectInfo *info, gint select)
+static void collection_table_select_util(CollectTable *ct, CollectInfo *info, gboolean select)
 {
        if (select)
                {
@@ -349,7 +436,7 @@ static void collection_table_select_util(CollectTable *ct, CollectInfo *info, gi
                }
 }
 
-static void collection_table_select_region_util(CollectTable *ct, CollectInfo *start, CollectInfo *end, gint select)
+static void collection_table_select_region_util(CollectTable *ct, CollectInfo *start, CollectInfo *end, gboolean select)
 {
        gint row1, col1;
        gint row2, col2;
@@ -435,7 +522,7 @@ static void tip_show(CollectTable *ct)
 
        if (ct->tip_window) return;
 
-       gdk_window_get_pointer(ct->listview->window, &x, &y, NULL);
+       gdk_window_get_pointer(gtk_widget_get_window(ct->listview), &x, &y, NULL);
 
        ct->tip_info = collection_table_find_data_by_coord(ct, x, y, NULL);
        if (!ct->tip_info) return;
@@ -452,7 +539,7 @@ static void tip_show(CollectTable *ct)
 
        gdk_window_get_pointer(NULL, &x, &y, NULL);
 
-       if (!GTK_WIDGET_REALIZED(ct->tip_window)) gtk_widget_realize(ct->tip_window);
+       if (!gtk_widget_get_realized(ct->tip_window)) gtk_widget_realize(ct->tip_window);
        gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
        gtk_widget_show(ct->tip_window);
 }
@@ -463,15 +550,15 @@ static void tip_hide(CollectTable *ct)
        ct->tip_window = NULL;
 }
 
-static gint tip_schedule_cb(gpointer data)
+static gboolean tip_schedule_cb(gpointer data)
 {
        CollectTable *ct = data;
 
-       if (ct->tip_delay_id == -1) return FALSE;
+       if (!ct->tip_delay_id) return FALSE;
 
        tip_show(ct);
 
-       ct->tip_delay_id = -1;
+       ct->tip_delay_id = 0;
        return FALSE;
 }
 
@@ -479,10 +566,10 @@ static void tip_schedule(CollectTable *ct)
 {
        tip_hide(ct);
 
-       if (ct->tip_delay_id != -1)
+       if (ct->tip_delay_id)
                {
                g_source_remove(ct->tip_delay_id);
-               ct->tip_delay_id = -1;
+               ct->tip_delay_id = 0;
                }
 
        ct->tip_delay_id = g_timeout_add(ct->show_text ? COLLECT_TABLE_TIP_DELAY_PATH : COLLECT_TABLE_TIP_DELAY, tip_schedule_cb, ct);
@@ -492,8 +579,11 @@ static void tip_unschedule(CollectTable *ct)
 {
        tip_hide(ct);
 
-       if (ct->tip_delay_id != -1) g_source_remove(ct->tip_delay_id);
-       ct->tip_delay_id = -1;
+       if (ct->tip_delay_id)
+               {
+               g_source_remove(ct->tip_delay_id);
+               ct->tip_delay_id = 0;
+               }
 }
 
 static void tip_update(CollectTable *ct, CollectInfo *info)
@@ -568,27 +658,13 @@ static GList *collection_table_popup_file_list(CollectTable *ct)
 static void collection_table_popup_edit_cb(GtkWidget *widget, gpointer data)
 {
        CollectTable *ct;
-       gint n;
-       GList *list;
+       const gchar *key = data;
 
        ct = submenu_item_get_data(widget);
 
        if (!ct) return;
-       n = GPOINTER_TO_INT(data);
-
-       list = collection_table_popup_file_list(ct);
-       if (list)
-               {
-               file_util_start_editor_from_filelist(n, list, ct->listview);
-               filelist_free(list);
-               }
-}
-
-static void collection_table_popup_info_cb(GtkWidget *widget, gpointer data)
-{
-       CollectTable *ct = data;
 
-       info_window_new(NULL, collection_table_popup_file_list(ct), NULL);
+       file_util_start_editor_from_filelist(key, collection_table_popup_file_list(ct), NULL, ct->listview);
 }
 
 static void collection_table_popup_copy_cb(GtkWidget *widget, gpointer data)
@@ -640,6 +716,17 @@ static void collection_table_popup_sort_cb(GtkWidget *widget, gpointer data)
        collection_set_sort_method(ct->cd, type);
 }
 
+static void collection_table_popup_randomize_cb(GtkWidget *widget, gpointer data)
+{
+       CollectTable *ct;
+
+       ct = submenu_item_get_data(widget);
+
+       if (!ct) return;
+
+       collection_randomize(ct->cd);
+}
+
 static void collection_table_popup_view_new_cb(GtkWidget *widget, gpointer data)
 {
        CollectTable *ct = data;
@@ -676,6 +763,14 @@ static void collection_table_popup_unselectall_cb(GtkWidget *widget, gpointer da
        ct->prev_selection= ct->click_info;
 }
 
+static void collection_table_popup_select_invert_cb(GtkWidget *widget, gpointer data)
+{
+       CollectTable *ct = data;
+
+       collection_table_select_invert_all(ct);
+       ct->prev_selection= ct->click_info;
+}
+
 static void collection_table_popup_remove_cb(GtkWidget *widget, gpointer data)
 {
        CollectTable *ct = data;
@@ -754,12 +849,16 @@ static void collection_table_popup_destroy_cb(GtkWidget *widget, gpointer data)
        filelist_free(ct->drop_list);
        ct->drop_list = NULL;
        ct->drop_info = NULL;
+
+       filelist_free(ct->editmenu_fd_list);
+       ct->editmenu_fd_list = NULL;
 }
 
-static GtkWidget *collection_table_popup_menu(CollectTable *ct, gint over_icon)
+static GtkWidget *collection_table_popup_menu(CollectTable *ct, gboolean over_icon)
 {
        GtkWidget *menu;
        GtkWidget *item;
+       GtkWidget *submenu;
 
        menu = popup_menu_short_lived();
 
@@ -779,18 +878,24 @@ static GtkWidget *collection_table_popup_menu(CollectTable *ct, gint over_icon)
        menu_item_add_stock(menu, _("Append from collection..."), GTK_STOCK_OPEN,
                        G_CALLBACK(collection_table_popup_add_collection_cb), ct);
        menu_item_add_divider(menu);
-       menu_item_add(menu, _("Select all"),
+
+       item = menu_item_add(menu, _("_Selection"), NULL, NULL);
+       submenu = gtk_menu_new();
+       menu_item_add(submenu, _("Select all"),
                        G_CALLBACK(collection_table_popup_selectall_cb), ct);
-       menu_item_add(menu, _("Select none"),
+       menu_item_add(submenu, _("Select none"),
                        G_CALLBACK(collection_table_popup_unselectall_cb), ct);
+       menu_item_add(submenu, _("Invert selection"),
+                       G_CALLBACK(collection_table_popup_select_invert_cb), ct);
+       gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
        menu_item_add_divider(menu);
 
+       
+       ct->editmenu_fd_list = collection_table_selection_get_list(ct);
        submenu_add_edit(menu, &item,
-                       G_CALLBACK(collection_table_popup_edit_cb), ct);
+                       G_CALLBACK(collection_table_popup_edit_cb), ct, ct->editmenu_fd_list);
        gtk_widget_set_sensitive(item, over_icon);
 
-       menu_item_add_sensitive(menu, _("_Properties"), over_icon,
-                       G_CALLBACK(collection_table_popup_info_cb), ct);
        menu_item_add_divider(menu);
        menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, over_icon,
                        G_CALLBACK(collection_table_popup_copy_cb), ct);
@@ -800,12 +905,17 @@ static GtkWidget *collection_table_popup_menu(CollectTable *ct, gint over_icon)
                        G_CALLBACK(collection_table_popup_rename_cb), ct);
        menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, over_icon,
                        G_CALLBACK(collection_table_popup_delete_cb), ct);
-       if (options->show_copy_path)
-               menu_item_add_sensitive(menu, _("_Copy path"), over_icon,
-                                       G_CALLBACK(collection_table_popup_copy_path_cb), ct);
+       menu_item_add_sensitive(menu, _("_Copy path"), over_icon,
+                               G_CALLBACK(collection_table_popup_copy_path_cb), ct);
        menu_item_add_divider(menu);
 
-       submenu_add_sort(menu, G_CALLBACK(collection_table_popup_sort_cb), ct, FALSE, TRUE, FALSE, 0);
+       submenu = submenu_add_sort(NULL, G_CALLBACK(collection_table_popup_sort_cb), ct, FALSE, TRUE, FALSE, 0);
+       menu_item_add_divider(submenu);
+       menu_item_add(submenu, _("Randomize"),
+                       G_CALLBACK(collection_table_popup_randomize_cb), ct);
+       item = menu_item_add(menu, _("_Sort"), NULL, NULL);
+       gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
+
        menu_item_add_check(menu, _("Show filename _text"), ct->show_text,
                        G_CALLBACK(collection_table_popup_show_names_cb), ct);
        menu_item_add_divider(menu);
@@ -874,7 +984,7 @@ static void collection_table_set_focus(CollectTable *ct, CollectInfo *info)
                }
 }
 
-static void collection_table_move_focus(CollectTable *ct, gint row, gint col, gint relative)
+static void collection_table_move_focus(CollectTable *ct, gint row, gint col, gboolean relative)
 {
        gint new_row;
        gint new_col;
@@ -991,7 +1101,7 @@ static gint page_height(CollectTable *ct)
        gint ret;
 
        adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
-       page_size = (gint)adj->page_increment;
+       page_size = (gint)gtk_adjustment_get_page_increment(adj);
 
        row_height = options->thumbnails.max_height + THUMB_BORDER_PADDING * 2;
        if (ct->show_text) row_height += options->thumbnails.max_height / 3;
@@ -1020,44 +1130,43 @@ static void collection_table_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboole
        popup_menu_position_clamp(menu, x, y, 0);
 }
 
-static gint collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
+static gboolean collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
 {
        CollectTable *ct = data;
        gint focus_row = 0;
        gint focus_col = 0;
        CollectInfo *info;
-       gint stop_signal;
+       gboolean stop_signal = TRUE;
 
-       stop_signal = TRUE;
        switch (event->keyval)
                {
-               case GDK_Left: case GDK_KP_Left:
+               case GDK_KEY_Left: case GDK_KEY_KP_Left:
                        focus_col = -1;
                        break;
-               case GDK_Right: case GDK_KP_Right:
+               case GDK_KEY_Right: case GDK_KEY_KP_Right:
                        focus_col = 1;
                        break;
-               case GDK_Up: case GDK_KP_Up:
+               case GDK_KEY_Up: case GDK_KEY_KP_Up:
                        focus_row = -1;
                        break;
-               case GDK_Down: case GDK_KP_Down:
+               case GDK_KEY_Down: case GDK_KEY_KP_Down:
                        focus_row = 1;
                        break;
-               case GDK_Page_Up: case GDK_KP_Page_Up:
+               case GDK_KEY_Page_Up: case GDK_KEY_KP_Page_Up:
                        focus_row = -page_height(ct);
                        break;
-               case GDK_Page_Down: case GDK_KP_Page_Down:
+               case GDK_KEY_Page_Down: case GDK_KEY_KP_Page_Down:
                        focus_row = page_height(ct);
                        break;
-               case GDK_Home: case GDK_KP_Home:
+               case GDK_KEY_Home: case GDK_KEY_KP_Home:
                        focus_row = -ct->focus_row;
                        focus_col = -ct->focus_column;
                        break;
-               case GDK_End: case GDK_KP_End:
+               case GDK_KEY_End: case GDK_KEY_KP_End:
                        focus_row = ct->rows - 1 - ct->focus_row;
                        focus_col = ct->columns - 1 - ct->focus_column;
                        break;
-               case GDK_space:
+               case GDK_KEY_space:
                        info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
                        if (info)
                                {
@@ -1076,8 +1185,8 @@ static gint collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event,
                case 'T': case 't':
                        if (event->state & GDK_CONTROL_MASK) collection_table_toggle_filenames(ct);
                        break;
-               case GDK_Menu:
-               case GDK_F10:
+               case GDK_KEY_Menu:
+               case GDK_KEY_F10:
                        info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
                        ct->click_info = info;
 
@@ -1130,9 +1239,6 @@ static gint collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event,
 
        if (stop_signal)
                {
-#if 0
-               g_signal_stop_emission_by_name(GTK_OBJECT(widget), "key_press_event");
-#endif
                tip_unschedule(ct);
                }
 
@@ -1145,8 +1251,8 @@ static gint collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event,
  *-------------------------------------------------------------------
  */
 
-static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *source, gint *after, GdkRectangle *cell,
-                                                gint use_coord, gint x, gint y)
+static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *source, gboolean *after, GdkRectangle *cell,
+                                                gboolean use_coord, gint x, gint y)
 {
        CollectInfo *info = NULL;
        GtkTreeModel *store;
@@ -1156,7 +1262,7 @@ static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *
 
        store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
 
-       if (!use_coord) gdk_window_get_pointer(ct->listview->window, &x, &y, NULL);
+       if (!use_coord) gdk_window_get_pointer(gtk_widget_get_window(ct->listview), &x, &y, NULL);
 
        if (source)
                {
@@ -1169,7 +1275,7 @@ static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *
                        gtk_tree_path_free(tpath);
 
                        info = source;
-                       *after = (x > cell->x + (cell->width / 2));
+                       *after = !!(x > cell->x + (cell->width / 2));
                        }
                return info;
                }
@@ -1189,7 +1295,7 @@ static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *
                if (info)
                        {
                        gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
-                       *after = (x > cell->x + (cell->width / 2));
+                       *after = !!(x > cell->x + (cell->width / 2));
                        }
 
                gtk_tree_path_free(tpath);
@@ -1224,7 +1330,7 @@ static CollectInfo *collection_table_insert_point(CollectTable *ct, gint x, gint
 {
        CollectInfo *info;
        GdkRectangle cell;
-       gint after = FALSE;
+       gboolean after = FALSE;
 
        info = collection_table_insert_find(ct, NULL, &after, &cell, TRUE, x, y);
 
@@ -1246,10 +1352,9 @@ static CollectInfo *collection_table_insert_point(CollectTable *ct, gint x, gint
        return info;
 }
 
-static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info, gint enable)
+static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info, gboolean enable)
 {
-       gint row, col;
-       gint after = FALSE;
+       gboolean after = FALSE;
        GdkRectangle cell;
 
        if (!enable)
@@ -1265,26 +1370,14 @@ static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info,
        /* this setting does not take into account (after), but since it is not really used... */
        ct->marker_info = info;
 
-       row = -1;
-       col = -1;
-
        if (!ct->marker_window)
                {
-               GdkWindow *parent;
+               GdkWindow *parent = gtk_tree_view_get_bin_window(GTK_TREE_VIEW(ct->listview));
                GdkWindowAttr attributes;
                gint attributes_mask;
-               GdkPixmap *pixmap;
-               GdkBitmap *mask;
-               GdkPixbuf *pb;
-               gint w, h;
-
-               parent = gtk_tree_view_get_bin_window(GTK_TREE_VIEW(ct->listview));
-
-               pb = gdk_pixbuf_new_from_xpm_data((const char **)marker_xpm);
-               gdk_pixbuf_render_pixmap_and_mask(pb, &pixmap, &mask, 128);
-               gdk_pixbuf_unref(pb);
-
-               gdk_drawable_get_size(pixmap, &w, &h);
+               GdkPixbuf *pb = gdk_pixbuf_new_from_xpm_data((const gchar **)marker_xpm);
+               gint w = gdk_pixbuf_get_width(pb);
+               gint h = gdk_pixbuf_get_height(pb);
 
                attributes.window_type = GDK_WINDOW_CHILD;
                attributes.wclass = GDK_INPUT_OUTPUT;
@@ -1294,11 +1387,34 @@ static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info,
                attributes_mask = 0;
 
                ct->marker_window = gdk_window_new(parent, &attributes, attributes_mask);
+
+#if GTK_CHECK_VERSION(3,0,0)
+               cairo_region_t *mask;
+               cairo_pattern_t *pattern;
+               cairo_surface_t *img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
+               cairo_t *cr = cairo_create(img);
+               gdk_cairo_set_source_pixbuf(cr, pb, 0, 0);
+               cairo_paint(cr);
+               pattern = cairo_pattern_create_for_surface(img);
+               mask = gdk_cairo_region_create_from_surface(img);
+               gdk_window_shape_combine_region(ct->marker_window, mask, 0, 0);
+               gdk_window_set_background_pattern(ct->marker_window, pattern);
+               cairo_region_destroy(mask);
+               cairo_pattern_destroy(pattern);
+               cairo_destroy(cr);
+               cairo_surface_destroy(img);
+#else
+               GdkPixmap *pixmap;
+               GdkBitmap *mask;
+               gdk_pixbuf_render_pixmap_and_mask(pb, &pixmap, &mask, 128);
+
                gdk_window_set_back_pixmap(ct->marker_window, pixmap, FALSE);
                gdk_window_shape_combine_mask(ct->marker_window, mask, 0, 0);
 
                g_object_unref(pixmap);
                if (mask) g_object_unref(mask);
+#endif
+               g_object_unref(pb);
                }
 
        if (info)
@@ -1306,7 +1422,8 @@ static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info,
                gint x, y;
                gint w, h;
 
-               gdk_drawable_get_size(ct->marker_window, &w, &h);
+               w = gdk_window_get_width(ct->marker_window);
+               h = gdk_window_get_height(ct->marker_window);
 
                if (!after)
                        {
@@ -1320,7 +1437,9 @@ static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info,
                y = cell.y + (cell.height / 2) - (h / 2);
 
                gdk_window_move(ct->marker_window, x, y);
+#if !GTK_CHECK_VERSION(3,0,0)
                gdk_window_clear(ct->marker_window);
+#endif
                if (!gdk_window_is_visible(ct->marker_window)) gdk_window_show(ct->marker_window);
                }
        else
@@ -1335,7 +1454,7 @@ static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info,
  *-------------------------------------------------------------------
  */
 
-static void collection_table_motion_update(CollectTable *ct, gint x, gint y, gint drop_event)
+static void collection_table_motion_update(CollectTable *ct, gint x, gint y, gboolean drop_event)
 {
        CollectInfo *info;
 
@@ -1352,44 +1471,48 @@ static void collection_table_motion_update(CollectTable *ct, gint x, gint y, gin
                }
 }
 
-static gint collection_table_auto_scroll_idle_cb(gpointer data)
+static gboolean collection_table_auto_scroll_idle_cb(gpointer data)
 {
        CollectTable *ct = data;
        GdkWindow *window;
        gint x, y;
        gint w, h;
 
-       if (ct->drop_idle_id == -1) return FALSE;
+       if (!ct->drop_idle_id) return FALSE;
 
-       window = ct->listview->window;
+       window = gtk_widget_get_window(ct->listview);
        gdk_window_get_pointer(window, &x, &y, NULL);
-       gdk_drawable_get_size(window, &w, &h);
+       w = gdk_window_get_width(window);
+       h = gdk_window_get_height(window);
        if (x >= 0 && x < w && y >= 0 && y < h)
                {
                collection_table_motion_update(ct, x, y, TRUE);
                }
 
-       ct->drop_idle_id = -1;
+       ct->drop_idle_id = 0;
        return FALSE;
 }
 
-static gint collection_table_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data)
+static gboolean collection_table_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data)
 {
        CollectTable *ct = data;
 
-       if (ct->drop_idle_id == -1) ct->drop_idle_id = g_idle_add(collection_table_auto_scroll_idle_cb, ct);
+       if (!ct->drop_idle_id)
+               {
+               ct->drop_idle_id = g_idle_add(collection_table_auto_scroll_idle_cb, ct);
+               }
 
        return TRUE;
 }
 
-static void collection_table_scroll(CollectTable *ct, gint scroll)
+static void collection_table_scroll(CollectTable *ct, gboolean scroll)
 {
        if (!scroll)
                {
-               if (ct->drop_idle_id != -1)
+               if (ct->drop_idle_id)
                        {
                        g_source_remove(ct->drop_idle_id);
-                       ct->drop_idle_id = -1;
+                       ct->drop_idle_id = 0;
                        }
                widget_auto_scroll_stop(ct->listview);
                collection_table_insert_marker(ct, NULL, FALSE);
@@ -1408,7 +1531,7 @@ static void collection_table_scroll(CollectTable *ct, gint scroll)
  *-------------------------------------------------------------------
  */
 
-static gint collection_table_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
+static gboolean collection_table_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
 {
        CollectTable *ct = data;
 
@@ -1417,7 +1540,7 @@ static gint collection_table_motion_cb(GtkWidget *widget, GdkEventButton *bevent
        return FALSE;
 }
 
-static gint collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
+static gboolean collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
 {
        CollectTable *ct = data;
        GtkTreeIter iter;
@@ -1440,7 +1563,7 @@ static gint collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent,
                                        layout_image_set_collection(NULL, ct->cd, info);
                                        }
                                }
-                       else if (!GTK_WIDGET_HAS_FOCUS(ct->listview))
+                       else if (!gtk_widget_has_focus(ct->listview))
                                {
                                gtk_widget_grab_focus(ct->listview);
                                }
@@ -1456,7 +1579,7 @@ static gint collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent,
        return TRUE;
 }
 
-static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
+static gboolean collection_table_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
 {
        CollectTable *ct = data;
        GtkTreeIter iter;
@@ -1464,7 +1587,7 @@ static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *beven
 
        tip_schedule(ct);
 
-       if ((gint)bevent->x != 0 || (gint) bevent->y != 0)
+       if ((gint)bevent->x != 0 || (gint)bevent->y != 0)
                {
                info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter);
                }
@@ -1481,9 +1604,8 @@ static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *beven
 
                if (bevent->state & GDK_CONTROL_MASK)
                        {
-                       gint select;
+                       gboolean select = !INFO_SELECTED(info);
 
-                       select = !INFO_SELECTED(info);
                        if ((bevent->state & GDK_SHIFT_MASK) && ct->prev_selection)
                                {
                                collection_table_select_region_util(ct, ct->prev_selection, info, select);
@@ -1517,7 +1639,7 @@ static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *beven
        return TRUE;
 }
 
-static gint collection_table_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data)
+static gboolean collection_table_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data)
 {
        CollectTable *ct = data;
 
@@ -1566,7 +1688,7 @@ static GList *collection_table_add_row(CollectTable *ct, GtkTreeIter *iter)
        return list;
 }
 
-static void collection_table_populate(CollectTable *ct, gint resize)
+static void collection_table_populate(CollectTable *ct, gboolean resize)
 {
        gint row;
        GList *work;
@@ -1592,7 +1714,7 @@ static void collection_table_populate(CollectTable *ct, gint resize)
                        gtk_tree_view_column_set_visible(column, (i < ct->columns));
                        gtk_tree_view_column_set_fixed_width(column, thumb_width + (THUMB_BORDER_PADDING * 6));
 
-                       list = gtk_tree_view_column_get_cell_renderers(column);
+                       list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column));
                        cell = (list) ? list->data : NULL;
                        g_list_free(list);
 
@@ -1603,7 +1725,7 @@ static void collection_table_populate(CollectTable *ct, gint resize)
                                                             "show_text", ct->show_text, NULL);
                                }
                        }
-               if (GTK_WIDGET_REALIZED(ct->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(ct->listview));
+               if (gtk_widget_get_realized(ct->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(ct->listview));
                }
 
        row = -1;
@@ -1630,7 +1752,7 @@ static void collection_table_populate(CollectTable *ct, gint resize)
        collection_table_update_status(ct);
 }
 
-static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gint force)
+static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gboolean force)
 {
        gint new_cols;
        gint thumb_width;
@@ -1714,12 +1836,13 @@ static void collection_table_sync(CollectTable *ct)
        collection_table_update_status(ct);
 }
 
-static gint collection_table_sync_idle_cb(gpointer data)
+static gboolean collection_table_sync_idle_cb(gpointer data)
 {
        CollectTable *ct = data;
 
-       if (ct->sync_idle_id == -1) return FALSE;
-       ct->sync_idle_id = -1;
+       if (!ct->sync_idle_id) return FALSE;
+       g_source_remove(ct->sync_idle_id);
+       ct->sync_idle_id = 0;
 
        collection_table_sync(ct);
        return FALSE;
@@ -1727,7 +1850,7 @@ static gint collection_table_sync_idle_cb(gpointer data)
 
 static void collection_table_sync_idle(CollectTable *ct)
 {
-       if (ct->sync_idle_id == -1)
+       if (!ct->sync_idle_id)
                {
                /* high priority, the view needs to be resynced before a redraw
                 * may contain invalid pointers at this time
@@ -1898,7 +2021,7 @@ void collection_table_refresh(CollectTable *ct)
  *-------------------------------------------------------------------
  */
 
-static void collection_table_add_dir_recursive(CollectTable *ct, FileData *dir_fd, gint recursive)
+static void collection_table_add_dir_recursive(CollectTable *ct, FileData *dir_fd, gboolean recursive)
 {
        GList *d;
        GList *f;
@@ -1926,7 +2049,7 @@ static void collection_table_add_dir_recursive(CollectTable *ct, FileData *dir_f
        filelist_free(d);
 }
 
-static void confirm_dir_list_do(CollectTable *ct, GList *list, gint recursive)
+static void confirm_dir_list_do(CollectTable *ct, GList *list, gboolean recursive)
 {
        GList *work = list;
        while (work)
@@ -2007,7 +2130,7 @@ static void collection_table_dnd_get(GtkWidget *widget, GdkDragContext *context,
                                     guint time, gpointer data)
 {
        CollectTable *ct = data;
-       gint selected;
+       gboolean selected;
        GList *list = NULL;
        gchar *uri_text = NULL;
        gint total;
@@ -2029,6 +2152,9 @@ static void collection_table_dnd_get(GtkWidget *widget, GdkDragContext *context,
                                uri_text = collection_info_list_to_dnd_data(ct->cd, list, &total);
                                g_list_free(list);
                                }
+                       gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data),
+                                               8, (guchar *)uri_text, total);
+                       g_free(uri_text);
                        break;
                case TARGET_URI_LIST:
                case TARGET_TEXT_PLAIN:
@@ -2043,14 +2169,10 @@ static void collection_table_dnd_get(GtkWidget *widget, GdkDragContext *context,
                                }
                        if (!list) return;
 
-                       uri_text = uri_text_from_filelist(list, &total, (info == TARGET_TEXT_PLAIN));
+                       uri_selection_data_set_uris_from_filelist(selection_data, list);
                        filelist_free(list);
                        break;
                }
-
-       gtk_selection_data_set(selection_data, selection_data->target,
-                              8, (guchar *)uri_text, total);
-       g_free(uri_text);
 }
 
 
@@ -2066,7 +2188,7 @@ static void collection_table_dnd_receive(GtkWidget *widget, GdkDragContext *cont
        CollectInfo *drop_info;
        GList *work;
 
-       DEBUG_1("%s", selection_data->data);
+       DEBUG_1("%s", gtk_selection_data_get_data(selection_data));
 
        collection_table_scroll(ct, FALSE);
        collection_table_insert_marker(ct, NULL, FALSE);
@@ -2076,7 +2198,7 @@ static void collection_table_dnd_receive(GtkWidget *widget, GdkDragContext *cont
        switch (info)
                {
                case TARGET_APP_COLLECTION_MEMBER:
-                       source = collection_from_dnd_data((gchar *)selection_data->data, &list, &info_list);
+                       source = collection_from_dnd_data((gchar *)gtk_selection_data_get_data(selection_data), &list, &info_list);
                        if (source)
                                {
                                if (source == ct->cd)
@@ -2100,7 +2222,7 @@ static void collection_table_dnd_receive(GtkWidget *widget, GdkDragContext *cont
                                else
                                        {
                                        /* it is a move/copy across collections */
-                                       if (context->action == GDK_ACTION_MOVE)
+                                       if (gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE)
                                                {
                                                collection_remove_by_info_list(source, info_list);
                                                }
@@ -2109,7 +2231,7 @@ static void collection_table_dnd_receive(GtkWidget *widget, GdkDragContext *cont
                                }
                        break;
                case TARGET_URI_LIST:
-                       list = uri_filelist_from_text((gchar *)selection_data->data, TRUE);
+                       list = uri_filelist_from_gtk_selection_data(selection_data);
                        work = list;
                        while (work)
                                {
@@ -2250,9 +2372,6 @@ static void collection_table_cell_data_cb(GtkTreeViewColumn *tree_column, GtkCel
 
        if (info && (info->flag_mask & SELECTION_PRELIGHT))
                {
-#if 0
-               shift_color(&color_fg, -1, 0);
-#endif
                shift_color(&color_bg, -1, 0);
                }
 
@@ -2319,12 +2438,12 @@ static void collection_table_destroy(GtkWidget *widget, gpointer data)
 
        if (ct->popup)
                {
-               g_signal_handlers_disconnect_matched(GTK_OBJECT(ct->popup), G_SIGNAL_MATCH_DATA,
+               g_signal_handlers_disconnect_matched(G_OBJECT(ct->popup), G_SIGNAL_MATCH_DATA,
                                                     0, 0, 0, NULL, ct);
                gtk_widget_destroy(ct->popup);
                }
 
-       if (ct->sync_idle_id != -1) g_source_remove(ct->sync_idle_id);
+       if (ct->sync_idle_id) g_source_remove(ct->sync_idle_id);
 
        tip_unschedule(ct);
        collection_table_scroll(ct, FALSE);
@@ -2347,35 +2466,10 @@ CollectTable *collection_table_new(CollectionData *cd)
        gint i;
 
        ct = g_new0(CollectTable, 1);
+       
        ct->cd = cd;
-       ct->columns = 0;
-       ct->rows = 0;
-
-       ct->selection = NULL;
-       ct->prev_selection = NULL;
-
-       ct->tip_window = NULL;
-       ct->tip_delay_id = -1;
-
-       ct->marker_window = NULL;
-       ct->marker_info = NULL;
-
-       ct->status_label = NULL;
-       ct->extra_label = NULL;
-
-       ct->focus_row = 0;
-       ct->focus_column = 0;
-       ct->focus_info = NULL;
-
        ct->show_text = options->show_icon_names;
 
-       ct->sync_idle_id = -1;
-       ct->drop_idle_id = -1;
-
-       ct->popup = NULL;
-       ct->drop_info = NULL;
-       ct->drop_list = NULL;
-
        ct->scrolled = gtk_scrolled_window_new(NULL, NULL);
        gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(ct->scrolled), GTK_SHADOW_IN);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ct->scrolled),
@@ -2439,3 +2533,5 @@ CollectInfo *collection_table_get_focus_info(CollectTable *ct)
 {
        return collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
 }
+
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */