annotate src/dnd.c @ 229:c44b98370dba

Use more generic names for some cache manager callback functions.
author zas_
date Thu, 03 Apr 2008 18:20:39 +0000
parents f6e307c7bad6
children 9995c5fb202a
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
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
4 *
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
5 * Author: John Ellis
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
6 *
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
7 * 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
8 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
9 * This software comes with no warranty of any kind, use at your own risk!
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
10 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
11
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
12
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
13 #include "gqview.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
14 #include "dnd.h"
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
15
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
16 #include "collect.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
17 #include "image.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
18 #include "ui_bookmark.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[] = {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
29 { "application/x-gqview-collection-member", 0, TARGET_APP_COLLECTION_MEMBER },
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
30 { "text/uri-list", 0, TARGET_URI_LIST }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
31 };
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
32 gint dnd_file_drop_types_count = 2;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
33
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
34
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
35 #define DND_ICON_SIZE 48
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
36
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
37
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
38 static void pixbuf_draw_border(GdkPixbuf *pixbuf, gint w, gint h)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
39 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
40 gint alpha;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
41 gint rs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
42 guchar *pix;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
43 guchar *p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
44 gint i;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
45
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
46 alpha = gdk_pixbuf_get_has_alpha(pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
47 rs = gdk_pixbuf_get_rowstride(pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
48 pix = gdk_pixbuf_get_pixels(pixbuf);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
49
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
50 p = pix;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
51 for (i = 0; i < w; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
52 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
53 *p = 0; p++; *p = 0; p++; *p = 0; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
54 if (alpha) { *p= 255; p++; }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
55 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
56 for (i = 1; i < h - 1; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
57 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
58 p = pix + rs * i;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
59 *p = 0; p++; *p = 0; p++; *p = 0; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
60 if (alpha) *p= 255;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
61
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
62 p = pix + rs * i + (w - 1) * ((alpha == TRUE) ? 4 : 3);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
63 *p = 0; p++; *p = 0; p++; *p = 0; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
64 if (alpha) *p= 255;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
65 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
66 p = pix + rs * (h - 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
67 for (i = 0; i < w; i++)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
68 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
69 *p = 0; p++; *p = 0; p++; *p = 0; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
70 if (alpha) { *p= 255; p++; }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
71 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
72 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
73
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
74 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
75 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
76 gint alpha;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
77 gint rs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
78 guchar *pix;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
79 guchar *p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
80 gint i, j;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
81
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
82 alpha = gdk_pixbuf_get_has_alpha(pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
83 rs = gdk_pixbuf_get_rowstride(pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
84 pix = gdk_pixbuf_get_pixels(pixbuf);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
85
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
86 for (j = 0; j < h; j++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
87 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
88 p = pix + (rs * (y + j)) + (x * ((alpha) ? 4 : 3));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
89 for (i = 0; i < w; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
90 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
91 *p = (*p * (256-val)) >> 8; p++;
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 if (alpha) { *p = 255; p++; }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
95 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
96 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
97 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
98
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
99 void dnd_set_drag_icon(GtkWidget *widget, GdkDragContext *context, GdkPixbuf *pixbuf, gint items)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
100 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
101 GdkPixmap *pixmap;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
102 GdkBitmap *mask;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
103 GdkPixbuf *dest;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
104 gint w, h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
105 gint sw, sh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
106 PangoLayout *layout = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
107 gint x, y;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
108
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
109 x = y = 0;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
110
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
111 sw = gdk_pixbuf_get_width(pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
112 sh = gdk_pixbuf_get_height(pixbuf);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
113
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
114 if (sw <= DND_ICON_SIZE && sh <= DND_ICON_SIZE)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
115 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
116 w = sw;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
117 h = sh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
118 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
119 else if (sw < sh)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
120 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
121 w = sw * DND_ICON_SIZE / sh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
122 h = DND_ICON_SIZE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
123 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
124 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
125 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
126 w = DND_ICON_SIZE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
127 h = sh * DND_ICON_SIZE / sw;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
128 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
129
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
130 dest = gdk_pixbuf_scale_simple(pixbuf, w, h, GDK_INTERP_BILINEAR);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
131 pixbuf_draw_border(dest, w, h);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
132
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
133 if (items > 1)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
134 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
135 gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
136 gint lw,lh;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
137
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
138 layout = gtk_widget_create_pango_layout(widget, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
139 buf = g_strdup_printf("<small> %d </small>", items);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
140 pango_layout_set_markup(layout, buf, -1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
141 g_free(buf);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
142
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
143 pango_layout_get_pixel_size(layout, &lw, &lh);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
144
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
145 x = MAX(0, w - lw);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
146 y = MAX(0, h - lh);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
147 lw = CLAMP(lw, 0, w - x - 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
148 lh = CLAMP(lh, 0, h - y - 1);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
149
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
150 pixbuf_draw_rect(dest, x, y, lw, lh, 128);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
151 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
152
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
153 gdk_pixbuf_render_pixmap_and_mask(dest, &pixmap, &mask, 128);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
154 g_object_unref(dest);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
155
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
156 if (layout)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
157 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
158 gdk_draw_layout(pixmap, widget->style->black_gc, x+1, y+1, layout);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
159 gdk_draw_layout(pixmap, widget->style->white_gc, x, y, layout);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
160
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
161 g_object_unref(G_OBJECT(layout));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
162 }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
163
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
164 gtk_drag_set_icon_pixmap(context, gtk_widget_get_colormap(widget), pixmap, mask, -8, -6);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
165
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
166 g_object_unref(pixmap);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
167 if (mask) g_object_unref(mask);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
168 }