4 * Copyright (C) 2008 The Geeqie Team
8 * This software is released under the GNU General Public License (GNU GPL).
9 * Please read the included file COPYING for more information.
10 * This software comes with no warranty of any kind, use at your own risk!
19 #include "ui_fileops.h"
22 GtkTargetEntry dnd_file_drag_types[] = {
23 { "text/uri-list", 0, TARGET_URI_LIST },
24 { "text/plain", 0, TARGET_TEXT_PLAIN }
26 gint dnd_file_drag_types_count = 2;
28 GtkTargetEntry dnd_file_drop_types[] = {
29 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER },
30 { "text/uri-list", 0, TARGET_URI_LIST }
32 gint dnd_file_drop_types_count = 2;
35 #define DND_ICON_SIZE (options->dnd_icon_size)
38 static void pixbuf_draw_border(GdkPixbuf *pixbuf, gint w, gint h)
46 alpha = gdk_pixbuf_get_has_alpha(pixbuf);
47 rs = gdk_pixbuf_get_rowstride(pixbuf);
48 pix = gdk_pixbuf_get_pixels(pixbuf);
51 for (i = 0; i < w; i++)
53 *p = 0; p++; *p = 0; p++; *p = 0; p++;
54 if (alpha) { *p= 255; p++; }
56 for (i = 1; i < h - 1; i++)
59 *p = 0; p++; *p = 0; p++; *p = 0; p++;
62 p = pix + rs * i + (w - 1) * ((alpha == TRUE) ? 4 : 3);
63 *p = 0; p++; *p = 0; p++; *p = 0; p++;
66 p = pix + rs * (h - 1);
67 for (i = 0; i < w; i++)
69 *p = 0; p++; *p = 0; p++; *p = 0; p++;
70 if (alpha) { *p= 255; p++; }
74 static void pixbuf_draw_rect(GdkPixbuf *pixbuf, gint x, gint y, gint w, gint h, guint8 val)
82 alpha = gdk_pixbuf_get_has_alpha(pixbuf);
83 rs = gdk_pixbuf_get_rowstride(pixbuf);
84 pix = gdk_pixbuf_get_pixels(pixbuf);
86 for (j = 0; j < h; j++)
88 p = pix + (rs * (y + j)) + (x * ((alpha) ? 4 : 3));
89 for (i = 0; i < w; i++)
91 *p = (*p * (256-val)) >> 8; p++;
92 *p = (*p * (256-val)) >> 8; p++;
93 *p = (*p * (256-val)) >> 8; p++;
94 if (alpha) { *p = 255; p++; }
99 void dnd_set_drag_icon(GtkWidget *widget, GdkDragContext *context, GdkPixbuf *pixbuf, gint items)
106 PangoLayout *layout = NULL;
111 sw = gdk_pixbuf_get_width(pixbuf);
112 sh = gdk_pixbuf_get_height(pixbuf);
114 if (sw <= DND_ICON_SIZE && sh <= DND_ICON_SIZE)
121 w = sw * DND_ICON_SIZE / sh;
127 h = sh * DND_ICON_SIZE / sw;
130 dest = gdk_pixbuf_scale_simple(pixbuf, w, h, GDK_INTERP_BILINEAR);
131 pixbuf_draw_border(dest, w, h);
138 layout = gtk_widget_create_pango_layout(widget, NULL);
139 buf = g_strdup_printf("<small> %d </small>", items);
140 pango_layout_set_markup(layout, buf, -1);
143 pango_layout_get_pixel_size(layout, &lw, &lh);
147 lw = CLAMP(lw, 0, w - x - 1);
148 lh = CLAMP(lh, 0, h - y - 1);
150 pixbuf_draw_rect(dest, x, y, lw, lh, 128);
153 gdk_pixbuf_render_pixmap_and_mask(dest, &pixmap, &mask, 128);
154 g_object_unref(dest);
158 gdk_draw_layout(pixmap, widget->style->black_gc, x+1, y+1, layout);
159 gdk_draw_layout(pixmap, widget->style->white_gc, x, y, layout);
161 g_object_unref(G_OBJECT(layout));
164 gtk_drag_set_icon_pixmap(context, gtk_widget_get_colormap(widget), pixmap, mask, -8, -6);
166 g_object_unref(pixmap);
167 if (mask) g_object_unref(mask);