annotate src/dnd.c @ 1442:e37cde2857c1

fixed XMP and IPTC entry names in exif pane
author nadvornik
date Sun, 15 Mar 2009 12:41:39 +0000
parents 3a9fb1b52559
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1 /*
196
f6e307c7bad6 rename GQview -> Geeqie over the code
nadvornik
parents: 9
diff changeset
2 * Geeqie
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
3 * (C) 2004 John Ellis
1284
8b89e3ff286b Add year 2009 to copyright info everywhere.
zas_
parents: 1202
diff changeset
4 * Copyright (C) 2008 - 2009 The Geeqie Team
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
5 *
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
6 * Author: John Ellis
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
7 *
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
9 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
10 * This software comes with no warranty of any kind, use at your own risk!
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
11 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
12
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
13
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 196
diff changeset
14 #include "main.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
15 #include "dnd.h"
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
16
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
17 #include "collect.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
18 #include "image.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
19 #include "ui_fileops.h"
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
20
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
21
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
22 GtkTargetEntry dnd_file_drag_types[] = {
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
23 { "text/uri-list", 0, TARGET_URI_LIST },
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
24 { "text/plain", 0, TARGET_TEXT_PLAIN }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
25 };
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
26 gint dnd_file_drag_types_count = 2;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
27
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
28 GtkTargetEntry dnd_file_drop_types[] = {
316
2ebd0d9145cf Define drag and drop target string in dnd.h.
zas_
parents: 281
diff changeset
29 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER },
1202
8bf3fff49ddd Allow to drag keywords on files in list or icon view. Dragged text is appended to keywords list of the destination file.
zas_
parents: 1055
diff changeset
30 { "text/uri-list", 0, TARGET_URI_LIST },
8bf3fff49ddd Allow to drag keywords on files in list or icon view. Dragged text is appended to keywords list of the destination file.
zas_
parents: 1055
diff changeset
31 { "text/plain", 0, TARGET_TEXT_PLAIN },
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
32 };
1202
8bf3fff49ddd Allow to drag keywords on files in list or icon view. Dragged text is appended to keywords list of the destination file.
zas_
parents: 1055
diff changeset
33 gint dnd_file_drop_types_count = 3;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
34
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
35
458
7a69309b91c8 Allow the user to set the drag'n drop icon size through
zas_
parents: 316
diff changeset
36 #define DND_ICON_SIZE (options->dnd_icon_size)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
37
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
38
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
39 static void pixbuf_draw_border(GdkPixbuf *pixbuf, gint w, gint h)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
40 {
1420
3a9fb1b52559 Use gboolean where applicable, for the sake of consistency.
zas_
parents: 1393
diff changeset
41 gboolean alpha;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
42 gint rs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
43 guchar *pix;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
44 guchar *p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
45 gint i;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
46
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
47 alpha = gdk_pixbuf_get_has_alpha(pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
48 rs = gdk_pixbuf_get_rowstride(pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
49 pix = gdk_pixbuf_get_pixels(pixbuf);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
50
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
51 p = pix;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
52 for (i = 0; i < w; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
53 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
54 *p = 0; p++; *p = 0; p++; *p = 0; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
55 if (alpha) { *p= 255; p++; }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
56 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
57 for (i = 1; i < h - 1; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
58 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
59 p = pix + rs * i;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
60 *p = 0; p++; *p = 0; p++; *p = 0; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
61 if (alpha) *p= 255;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
62
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
63 p = pix + rs * i + (w - 1) * ((alpha == TRUE) ? 4 : 3);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
64 *p = 0; p++; *p = 0; p++; *p = 0; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
65 if (alpha) *p= 255;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
66 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
67 p = pix + rs * (h - 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
68 for (i = 0; i < w; i++)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
69 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
70 *p = 0; p++; *p = 0; p++; *p = 0; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
71 if (alpha) { *p= 255; p++; }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
72 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
73 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
74
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
75 static void pixbuf_draw_rect(GdkPixbuf *pixbuf, gint x, gint y, gint w, gint h, guint8 val)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
76 {
1420
3a9fb1b52559 Use gboolean where applicable, for the sake of consistency.
zas_
parents: 1393
diff changeset
77 gboolean alpha;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
78 gint rs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
79 guchar *pix;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
80 guchar *p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
81 gint i, j;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
82
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
83 alpha = gdk_pixbuf_get_has_alpha(pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
84 rs = gdk_pixbuf_get_rowstride(pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
85 pix = gdk_pixbuf_get_pixels(pixbuf);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
86
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
87 for (j = 0; j < h; j++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
88 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
89 p = pix + (rs * (y + j)) + (x * ((alpha) ? 4 : 3));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
90 for (i = 0; i < w; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
91 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
92 *p = (*p * (256-val)) >> 8; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
93 *p = (*p * (256-val)) >> 8; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
94 *p = (*p * (256-val)) >> 8; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
95 if (alpha) { *p = 255; p++; }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
96 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
97 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
98 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
99
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
100 void dnd_set_drag_icon(GtkWidget *widget, GdkDragContext *context, GdkPixbuf *pixbuf, gint items)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
101 {
977
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
102 GdkPixmap *pixmap;
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
103 GdkBitmap *mask;
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
104 GdkPixbuf *dest;
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
105 gint w, h;
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
106 gint sw, sh;
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
107 PangoLayout *layout = NULL;
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
108 gint x, y;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
109
977
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
110 x = y = 0;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
111
977
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
112 sw = gdk_pixbuf_get_width(pixbuf);
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
113 sh = gdk_pixbuf_get_height(pixbuf);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
114
977
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
115 if (sw <= DND_ICON_SIZE && sh <= DND_ICON_SIZE)
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
116 {
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
117 w = sw;
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
118 h = sh;
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
119 }
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
120 else if (sw < sh)
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
121 {
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
122 w = sw * DND_ICON_SIZE / sh;
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
123 h = DND_ICON_SIZE;
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
124 }
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
125 else
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
126 {
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
127 w = DND_ICON_SIZE;
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
128 h = sh * DND_ICON_SIZE / sw;
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
129 }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
130
977
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
131 dest = gdk_pixbuf_scale_simple(pixbuf, w, h, GDK_INTERP_BILINEAR);
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
132 pixbuf_draw_border(dest, w, h);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
133
977
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
134 if (items > 1)
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
135 {
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
136 gchar *buf;
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
137 gint lw,lh;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
138
977
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
139 layout = gtk_widget_create_pango_layout(widget, NULL);
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
140 buf = g_strdup_printf("<small> %d </small>", items);
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
141 pango_layout_set_markup(layout, buf, -1);
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
142 g_free(buf);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
143
977
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
144 pango_layout_get_pixel_size(layout, &lw, &lh);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
145
977
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
146 x = MAX(0, w - lw);
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
147 y = MAX(0, h - lh);
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
148 lw = CLAMP(lw, 0, w - x - 1);
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
149 lh = CLAMP(lh, 0, h - y - 1);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
150
977
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
151 pixbuf_draw_rect(dest, x, y, lw, lh, 128);
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
152 }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
153
977
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
154 gdk_pixbuf_render_pixmap_and_mask(dest, &pixmap, &mask, 128);
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
155 g_object_unref(dest);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
156
977
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
157 if (layout)
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
158 {
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
159 gdk_draw_layout(pixmap, widget->style->black_gc, x+1, y+1, layout);
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
160 gdk_draw_layout(pixmap, widget->style->white_gc, x, y, layout);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
161
977
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
162 g_object_unref(G_OBJECT(layout));
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
163 }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
164
977
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
165 gtk_drag_set_icon_pixmap(context, gtk_widget_get_colormap(widget), pixmap, mask, -8, -6);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
166
977
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
167 g_object_unref(pixmap);
1f634178a14f Indentation fix.
zas_
parents: 902
diff changeset
168 if (mask) g_object_unref(mask);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
169 }
1393
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
170
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
171 static void dnd_set_drag_label_end_cb(GtkWidget *widget, GdkDragContext *context, gpointer data)
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
172 {
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
173 GtkWidget *window = data;
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
174 g_signal_handlers_disconnect_by_func(widget, dnd_set_drag_label_end_cb, data);
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
175 gtk_widget_destroy(window);
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
176 }
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
177
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
178 void dnd_set_drag_label(GtkWidget *widget, GdkDragContext *context, const gchar *text)
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
179 {
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
180 GtkWidget *window;
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
181 GtkWidget *label;
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
182
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
183 window = gtk_window_new(GTK_WINDOW_POPUP);
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
184 gtk_widget_realize (window);
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
185
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
186 label = gtk_label_new(text);
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
187 gtk_container_add(GTK_CONTAINER (window), label);
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
188 gtk_widget_show(label);
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
189 gtk_drag_set_icon_widget(context, window, -15, 10);
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
190 g_signal_connect(G_OBJECT(widget), "drag_end",
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
191 G_CALLBACK(dnd_set_drag_label_end_cb), window);
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
192 }
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
193
79b32088ecc4 show a label instead of the default drag icon
nadvornik
parents: 1284
diff changeset
194
1055
1646720364cf Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents: 977
diff changeset
195 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */