4 * Copyright (C) 2008 - 2012 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 },
31 { "text/plain", 0, TARGET_TEXT_PLAIN },
33 gint dnd_file_drop_types_count = 3;
36 #define DND_ICON_SIZE (options->dnd_icon_size)
39 static void pixbuf_draw_border(GdkPixbuf *pixbuf, gint w, gint h)
47 alpha = gdk_pixbuf_get_has_alpha(pixbuf);
48 rs = gdk_pixbuf_get_rowstride(pixbuf);
49 pix = gdk_pixbuf_get_pixels(pixbuf);
52 for (i = 0; i < w; i++)
54 *p = 0; p++; *p = 0; p++; *p = 0; p++;
55 if (alpha) { *p= 255; p++; }
57 for (i = 1; i < h - 1; i++)
60 *p = 0; p++; *p = 0; p++; *p = 0; p++;
63 p = pix + rs * i + (w - 1) * ((alpha == TRUE) ? 4 : 3);
64 *p = 0; p++; *p = 0; p++; *p = 0; p++;
67 p = pix + rs * (h - 1);
68 for (i = 0; i < w; i++)
70 *p = 0; p++; *p = 0; p++; *p = 0; p++;
71 if (alpha) { *p= 255; p++; }
75 static void pixbuf_draw_rect(GdkPixbuf *pixbuf, gint x, gint y, gint w, gint h, guint8 val)
83 alpha = gdk_pixbuf_get_has_alpha(pixbuf);
84 rs = gdk_pixbuf_get_rowstride(pixbuf);
85 pix = gdk_pixbuf_get_pixels(pixbuf);
87 for (j = 0; j < h; j++)
89 p = pix + (rs * (y + j)) + (x * ((alpha) ? 4 : 3));
90 for (i = 0; i < w; i++)
92 *p = (*p * (256-val)) >> 8; p++;
93 *p = (*p * (256-val)) >> 8; p++;
94 *p = (*p * (256-val)) >> 8; p++;
95 if (alpha) { *p = 255; p++; }
100 void dnd_set_drag_icon(GtkWidget *widget, GdkDragContext *context, GdkPixbuf *pixbuf, gint items)
107 PangoLayout *layout = NULL;
112 sw = gdk_pixbuf_get_width(pixbuf);
113 sh = gdk_pixbuf_get_height(pixbuf);
115 if (sw <= DND_ICON_SIZE && sh <= DND_ICON_SIZE)
122 w = sw * DND_ICON_SIZE / sh;
128 h = sh * DND_ICON_SIZE / sw;
131 dest = gdk_pixbuf_scale_simple(pixbuf, w, h, GDK_INTERP_BILINEAR);
132 pixbuf_draw_border(dest, w, h);
139 layout = gtk_widget_create_pango_layout(widget, NULL);
140 buf = g_strdup_printf("<small> %d </small>", items);
141 pango_layout_set_markup(layout, buf, -1);
144 pango_layout_get_pixel_size(layout, &lw, &lh);
148 lw = CLAMP(lw, 0, w - x - 1);
149 lh = CLAMP(lh, 0, h - y - 1);
151 pixbuf_draw_rect(dest, x, y, lw, lh, 128);
154 gdk_pixbuf_render_pixmap_and_mask(dest, &pixmap, &mask, 128);
155 g_object_unref(dest);
159 gdk_draw_layout(pixmap, widget->style->black_gc, x+1, y+1, layout);
160 gdk_draw_layout(pixmap, widget->style->white_gc, x, y, layout);
162 g_object_unref(G_OBJECT(layout));
165 gtk_drag_set_icon_pixmap(context, gtk_widget_get_colormap(widget), pixmap, mask, -8, -6);
167 g_object_unref(pixmap);
168 if (mask) g_object_unref(mask);
171 static void dnd_set_drag_label_end_cb(GtkWidget *widget, GdkDragContext *context, gpointer data)
173 GtkWidget *window = data;
174 g_signal_handlers_disconnect_by_func(widget, dnd_set_drag_label_end_cb, data);
175 gtk_widget_destroy(window);
178 void dnd_set_drag_label(GtkWidget *widget, GdkDragContext *context, const gchar *text)
183 window = gtk_window_new(GTK_WINDOW_POPUP);
184 gtk_widget_realize (window);
186 label = gtk_label_new(text);
187 gtk_container_add(GTK_CONTAINER (window), label);
188 gtk_widget_show(label);
189 gtk_drag_set_icon_widget(context, window, -15, 10);
190 g_signal_connect(G_OBJECT(widget), "drag_end",
191 G_CALLBACK(dnd_set_drag_label_end_cb), window);
195 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */