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"
20 #include "pixbuf_util.h"
23 GtkTargetEntry dnd_file_drag_types[] = {
24 { "text/uri-list", 0, TARGET_URI_LIST },
25 { "text/plain", 0, TARGET_TEXT_PLAIN }
27 gint dnd_file_drag_types_count = 2;
29 GtkTargetEntry dnd_file_drop_types[] = {
30 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER },
31 { "text/uri-list", 0, TARGET_URI_LIST },
32 { "text/plain", 0, TARGET_TEXT_PLAIN },
34 gint dnd_file_drop_types_count = 3;
37 #define DND_ICON_SIZE (options->dnd_icon_size)
40 static void pixbuf_draw_border(GdkPixbuf *pixbuf, gint w, gint h)
48 alpha = gdk_pixbuf_get_has_alpha(pixbuf);
49 rs = gdk_pixbuf_get_rowstride(pixbuf);
50 pix = gdk_pixbuf_get_pixels(pixbuf);
53 for (i = 0; i < w; i++)
55 *p = 0; p++; *p = 0; p++; *p = 0; p++;
56 if (alpha) { *p= 255; p++; }
58 for (i = 1; i < h - 1; i++)
61 *p = 0; p++; *p = 0; p++; *p = 0; p++;
64 p = pix + rs * i + (w - 1) * ((alpha == TRUE) ? 4 : 3);
65 *p = 0; p++; *p = 0; p++; *p = 0; p++;
68 p = pix + rs * (h - 1);
69 for (i = 0; i < w; i++)
71 *p = 0; p++; *p = 0; p++; *p = 0; p++;
72 if (alpha) { *p= 255; p++; }
77 static void pixbuf_draw_rect(GdkPixbuf *pixbuf, gint x, gint y, gint w, gint h, guint8 val)
85 alpha = gdk_pixbuf_get_has_alpha(pixbuf);
86 rs = gdk_pixbuf_get_rowstride(pixbuf);
87 pix = gdk_pixbuf_get_pixels(pixbuf);
89 for (j = 0; j < h; j++)
91 p = pix + (rs * (y + j)) + (x * ((alpha) ? 4 : 3));
92 for (i = 0; i < w; i++)
94 *p = (*p * (256-val)) >> 8; p++;
95 *p = (*p * (256-val)) >> 8; p++;
96 *p = (*p * (256-val)) >> 8; p++;
97 if (alpha) { *p = 255; p++; }
102 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_fill(dest, x, y, lw, lh, 128, 128, 128, 255);
156 pixbuf_draw_layout(dest, layout, NULL, x+1, y+1, 0, 0, 0, 255);
157 pixbuf_draw_layout(dest, layout, NULL, x, y, 255, 255, 255, 255);
159 g_object_unref(G_OBJECT(layout));
162 gtk_drag_set_icon_pixbuf(context, dest, -8, -6);
164 g_object_unref(dest);
167 static void dnd_set_drag_label_end_cb(GtkWidget *widget, GdkDragContext *context, gpointer data)
169 GtkWidget *window = data;
170 g_signal_handlers_disconnect_by_func(widget, dnd_set_drag_label_end_cb, data);
171 gtk_widget_destroy(window);
174 void dnd_set_drag_label(GtkWidget *widget, GdkDragContext *context, const gchar *text)
179 window = gtk_window_new(GTK_WINDOW_POPUP);
180 gtk_widget_realize (window);
182 label = gtk_label_new(text);
183 gtk_container_add(GTK_CONTAINER (window), label);
184 gtk_widget_show(label);
185 gtk_drag_set_icon_widget(context, window, -15, 10);
186 g_signal_connect(G_OBJECT(widget), "drag_end",
187 G_CALLBACK(dnd_set_drag_label_end_cb), window);
191 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */