Remove commented out code.
[geeqie.git] / src / dnd.c
1 /*
2  * Geeqie
3  * (C) 2004 John Ellis
4  * Copyright (C) 2008 - 2012 The Geeqie Team
5  *
6  * Author: John Ellis
7  *
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!
11  */
12
13
14 #include "main.h"
15 #include "dnd.h"
16
17 #include "collect.h"
18 #include "image.h"
19 #include "ui_fileops.h"
20 #include "pixbuf_util.h"
21
22
23 GtkTargetEntry dnd_file_drag_types[] = {
24         { "text/uri-list", 0, TARGET_URI_LIST },
25         { "text/plain", 0, TARGET_TEXT_PLAIN }
26 };
27 gint dnd_file_drag_types_count = 2;
28
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 },
33 };
34 gint dnd_file_drop_types_count = 3;
35
36
37 #define DND_ICON_SIZE (options->dnd_icon_size)
38
39
40 static void pixbuf_draw_border(GdkPixbuf *pixbuf, gint w, gint h)
41 {
42         gboolean alpha;
43         gint rs;
44         guchar *pix;
45         guchar *p;
46         gint i;
47
48         alpha = gdk_pixbuf_get_has_alpha(pixbuf);
49         rs = gdk_pixbuf_get_rowstride(pixbuf);
50         pix = gdk_pixbuf_get_pixels(pixbuf);
51
52         p = pix;
53         for (i = 0; i < w; i++)
54                 {
55                 *p = 0; p++; *p = 0; p++; *p = 0; p++;
56                 if (alpha) { *p= 255; p++; }
57                 }
58         for (i = 1; i < h - 1; i++)
59                 {
60                 p = pix + rs * i;
61                 *p = 0; p++; *p = 0; p++; *p = 0; p++;
62                 if (alpha) *p= 255;
63
64                 p = pix + rs * i + (w - 1) * ((alpha == TRUE) ? 4 : 3);
65                 *p = 0; p++; *p = 0; p++; *p = 0; p++;
66                 if (alpha) *p= 255;
67                 }
68         p = pix + rs * (h - 1);
69         for (i = 0; i < w; i++)
70                 {
71                 *p = 0; p++; *p = 0; p++; *p = 0; p++;
72                 if (alpha) { *p= 255; p++; }
73                 }
74 }
75
76 /*
77 static void pixbuf_draw_rect(GdkPixbuf *pixbuf, gint x, gint y, gint w, gint h, guint8 val)
78 {
79         gboolean alpha;
80         gint rs;
81         guchar *pix;
82         guchar *p;
83         gint i, j;
84
85         alpha = gdk_pixbuf_get_has_alpha(pixbuf);
86         rs = gdk_pixbuf_get_rowstride(pixbuf);
87         pix = gdk_pixbuf_get_pixels(pixbuf);
88
89         for (j = 0; j < h; j++)
90                 {
91                 p = pix + (rs * (y + j)) + (x * ((alpha) ? 4 : 3));
92                 for (i = 0; i < w; i++)
93                         {
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++; }
98                         }
99                 }
100 }
101 */
102 void dnd_set_drag_icon(GtkWidget *widget, GdkDragContext *context, GdkPixbuf *pixbuf, gint items)
103 {
104         GdkPixbuf *dest;
105         gint w, h;
106         gint sw, sh;
107         PangoLayout *layout = NULL;
108         gint x, y;
109
110         x = y = 0;
111
112         sw = gdk_pixbuf_get_width(pixbuf);
113         sh = gdk_pixbuf_get_height(pixbuf);
114
115         if (sw <= DND_ICON_SIZE && sh <= DND_ICON_SIZE)
116                 {
117                 w = sw;
118                 h = sh;
119                 }
120         else if (sw < sh)
121                 {
122                 w = sw * DND_ICON_SIZE / sh;
123                 h = DND_ICON_SIZE;
124                 }
125         else
126                 {
127                 w = DND_ICON_SIZE;
128                 h = sh * DND_ICON_SIZE / sw;
129                 }
130
131         dest = gdk_pixbuf_scale_simple(pixbuf, w, h, GDK_INTERP_BILINEAR);
132         pixbuf_draw_border(dest, w, h);
133
134         if (items > 1)
135                 {
136                 gchar *buf;
137                 gint lw,lh;
138
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);
142                 g_free(buf);
143
144                 pango_layout_get_pixel_size(layout, &lw, &lh);
145
146                 x = MAX(0, w - lw);
147                 y = MAX(0, h - lh);
148                 lw = CLAMP(lw, 0, w - x - 1);
149                 lh = CLAMP(lh, 0, h - y - 1);
150
151                 pixbuf_draw_rect_fill(dest, x, y, lw, lh, 128, 128, 128, 255);
152                 }
153
154         if (layout)
155                 {
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);
158
159                 g_object_unref(G_OBJECT(layout));
160                 }
161
162         gtk_drag_set_icon_pixbuf(context, dest, -8, -6);
163
164         g_object_unref(dest);
165 }
166
167 static void dnd_set_drag_label_end_cb(GtkWidget *widget, GdkDragContext *context, gpointer data)
168 {
169         GtkWidget *window = data;
170         g_signal_handlers_disconnect_by_func(widget, dnd_set_drag_label_end_cb, data);
171         gtk_widget_destroy(window);
172 }
173
174 void dnd_set_drag_label(GtkWidget *widget, GdkDragContext *context, const gchar *text)
175 {
176         GtkWidget *window;
177         GtkWidget *label;
178
179         window = gtk_window_new(GTK_WINDOW_POPUP);
180         gtk_widget_realize (window);
181
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);
188 }
189
190
191 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */