2 * Copyright (C) 2004 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "pixbuf-util.h"
28 GtkTargetEntry dnd_file_drag_types[] = {
29 { const_cast<gchar *>("text/uri-list"), 0, TARGET_URI_LIST },
30 { const_cast<gchar *>("text/plain"), 0, TARGET_TEXT_PLAIN }
32 gint dnd_file_drag_types_count = 2;
34 GtkTargetEntry dnd_file_drop_types[] = {
35 { const_cast<gchar *>(TARGET_APP_COLLECTION_MEMBER_STRING), 0, TARGET_APP_COLLECTION_MEMBER },
36 { const_cast<gchar *>("text/uri-list"), 0, TARGET_URI_LIST },
37 { const_cast<gchar *>("text/plain"), 0, TARGET_TEXT_PLAIN },
39 gint dnd_file_drop_types_count = 3;
42 #define DND_ICON_SIZE (options->dnd_icon_size)
45 static void pixbuf_draw_border(GdkPixbuf *pixbuf, gint w, gint h)
53 alpha = gdk_pixbuf_get_has_alpha(pixbuf);
54 rs = gdk_pixbuf_get_rowstride(pixbuf);
55 pix = gdk_pixbuf_get_pixels(pixbuf);
58 for (i = 0; i < w; i++)
60 *p = 0; p++; *p = 0; p++; *p = 0; p++;
61 if (alpha) { *p= 255; p++; }
63 for (i = 1; i < h - 1; i++)
66 *p = 0; p++; *p = 0; p++; *p = 0; p++;
69 p = pix + rs * i + (w - 1) * ((alpha == TRUE) ? 4 : 3);
70 *p = 0; p++; *p = 0; p++; *p = 0; p++;
73 p = pix + rs * (h - 1);
74 for (i = 0; i < w; i++)
76 *p = 0; p++; *p = 0; p++; *p = 0; p++;
77 if (alpha) { *p= 255; p++; }
82 static void pixbuf_draw_rect(GdkPixbuf *pixbuf, gint x, gint y, gint w, gint h, guint8 val)
90 alpha = gdk_pixbuf_get_has_alpha(pixbuf);
91 rs = gdk_pixbuf_get_rowstride(pixbuf);
92 pix = gdk_pixbuf_get_pixels(pixbuf);
94 for (j = 0; j < h; j++)
96 p = pix + (rs * (y + j)) + (x * ((alpha) ? 4 : 3));
97 for (i = 0; i < w; i++)
99 *p = (*p * (256-val)) >> 8; p++;
100 *p = (*p * (256-val)) >> 8; p++;
101 *p = (*p * (256-val)) >> 8; p++;
102 if (alpha) { *p = 255; p++; }
107 void dnd_set_drag_icon(GtkWidget *widget, GdkDragContext *context, GdkPixbuf *pixbuf, gint items)
112 PangoLayout *layout = NULL;
117 sw = gdk_pixbuf_get_width(pixbuf);
118 sh = gdk_pixbuf_get_height(pixbuf);
120 if (sw <= DND_ICON_SIZE && sh <= DND_ICON_SIZE)
127 w = sw * DND_ICON_SIZE / sh;
133 h = sh * DND_ICON_SIZE / sw;
136 dest = gdk_pixbuf_scale_simple(pixbuf, MAX(1, w), MAX(1, h), GDK_INTERP_BILINEAR);
137 pixbuf_draw_border(dest, MAX(1, w), MAX(1, h));
144 layout = gtk_widget_create_pango_layout(widget, NULL);
145 buf = g_strdup_printf("<small> %d </small>", items);
146 pango_layout_set_markup(layout, buf, -1);
149 pango_layout_get_pixel_size(layout, &lw, &lh);
153 lw = CLAMP(lw, 0, w - x - 1);
154 lh = CLAMP(lh, 0, h - y - 1);
156 pixbuf_draw_rect_fill(dest, x, y, lw, lh, 128, 128, 128, 255);
161 pixbuf_draw_layout(dest, layout, NULL, x+1, y+1, 0, 0, 0, 255);
162 pixbuf_draw_layout(dest, layout, NULL, x, y, 255, 255, 255, 255);
164 g_object_unref(G_OBJECT(layout));
167 gtk_drag_set_icon_pixbuf(context, dest, -8, -6);
169 g_object_unref(dest);
172 static void dnd_set_drag_label_end_cb(GtkWidget *widget, GdkDragContext *UNUSED(context), gpointer data)
174 GtkWidget *window = static_cast<GtkWidget *>(data);
175 g_signal_handlers_disconnect_by_func(widget, (gpointer)dnd_set_drag_label_end_cb, data);
176 gtk_widget_destroy(window);
179 void dnd_set_drag_label(GtkWidget *widget, GdkDragContext *context, const gchar *text)
184 window = gtk_window_new(GTK_WINDOW_POPUP);
185 gtk_widget_realize (window);
187 label = gtk_label_new(text);
188 gtk_container_add(GTK_CONTAINER (window), label);
189 gtk_widget_show(label);
190 gtk_drag_set_icon_widget(context, window, -15, 10);
191 g_signal_connect(G_OBJECT(widget), "drag_end",
192 G_CALLBACK(dnd_set_drag_label_end_cb), window);
196 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */