| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#include "config.h" |
| 28 |
#include <string.h> |
| 29 |
|
| 30 |
#include <io.h> |
| 31 |
#include <fcntl.h> |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) |
| 36 |
#define INITGUID |
| 37 |
#endif |
| 38 |
|
| 39 |
#include "gdkdropprivate.h" |
| 40 |
|
| 41 |
#include "gdkdrag.h" |
| 42 |
#include "gdkprivate-win32.h" |
| 43 |
#include "gdkwin32.h" |
| 44 |
#include "gdkwin32dnd.h" |
| 45 |
#include "gdkdisplayprivate.h" |
| 46 |
#include "gdkwin32dnd-private.h" |
| 47 |
#include "gdkdisplay-win32.h" |
| 48 |
#include "gdkdeviceprivate.h" |
| 49 |
#include "gdkhdataoutputstream-win32.h" |
| 50 |
|
| 51 |
#include <ole2.h> |
| 52 |
|
| 53 |
#include <shlobj.h> |
| 54 |
#include <shlguid.h> |
| 55 |
#include <objidl.h> |
| 56 |
#include <glib/gi18n-lib.h> |
| 57 |
|
| 58 |
#include <gdk/gdk.h> |
| 59 |
#include <glib/gstdio.h> |
| 60 |
|
| 61 |
#define GDK_TYPE_WIN32_DROP (gdk_win32_drop_get_type ()) |
| 62 |
#define GDK_WIN32_DROP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_WIN32_DROP, GdkWin32Drop)) |
| 63 |
#define GDK_WIN32_DROP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_WIN32_DROP, GdkWin32DropClass)) |
| 64 |
#define GDK_IS_WIN32_DROP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_WIN32_DROP)) |
| 65 |
#define GDK_IS_WIN32_DROP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_WIN32_DROP)) |
| 66 |
#define GDK_WIN32_DROP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_WIN32_DROP, GdkWin32DropClass)) |
| 67 |
|
| 68 |
typedef struct _GdkWin32Drop GdkWin32Drop; |
| 69 |
typedef struct _GdkWin32DropClass GdkWin32DropClass; |
| 70 |
|
| 71 |
struct _GdkWin32Drop |
| 72 |
{ |
| 73 |
GdkDrop drop; |
| 74 |
|
| 75 |
|
| 76 |
GdkDragProtocol protocol; |
| 77 |
|
| 78 |
|
| 79 |
GdkDragAction actions; |
| 80 |
|
| 81 |
guint scale; |
| 82 |
int last_x; |
| 83 |
int last_y; |
| 84 |
DWORD last_key_state; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
GArray *droptarget_w32format_contentformat_map; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
char *dropfiles_list; |
| 95 |
|
| 96 |
guint drop_finished : 1; |
| 97 |
guint drop_failed : 1; |
| 98 |
}; |
| 99 |
|
| 100 |
struct _GdkWin32DropClass |
| 101 |
{ |
| 102 |
GdkDropClass parent_class; |
| 103 |
}; |
| 104 |
|
| 105 |
GType gdk_win32_drop_get_type (void); |
| 106 |
|
| 107 |
G_DEFINE_TYPE (GdkWin32Drop, gdk_win32_drop, GDK_TYPE_DROP) |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
struct _drop_target_context |
| 114 |
{ |
| 115 |
IDropTarget idt; |
| 116 |
int ref_count; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
GdkDrop *drop; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
GdkSurface *surface; |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
IDataObject *data_object; |
| 137 |
}; |
| 138 |
|
| 139 |
static void |
| 140 |
gdk_win32_drop_init (GdkWin32Drop *drop) |
| 141 |
{ |
| 142 |
GDK_NOTE (DND, g_print ("gdk_win32_drop_init %p\n", drop)); |
| 143 |
} |
| 144 |
|
| 145 |
static void |
| 146 |
gdk_win32_drop_finalize (GObject *object) |
| 147 |
{ |
| 148 |
GdkDrop *drop; |
| 149 |
GdkWin32Drop *drop_win32; |
| 150 |
|
| 151 |
GDK_NOTE (DND, g_print ("gdk_win32_drop_finalize %p\n", object)); |
| 152 |
|
| 153 |
drop = GDK_DROP (object); |
| 154 |
|
| 155 |
drop_win32 = GDK_WIN32_DROP (drop); |
| 156 |
|
| 157 |
g_array_unref (drop_win32->droptarget_w32format_contentformat_map); |
| 158 |
|
| 159 |
G_OBJECT_CLASS (gdk_win32_drop_parent_class)->finalize (object); |
| 160 |
} |
| 161 |
|
| 162 |
static GdkDrop * |
| 163 |
gdk_drop_new (GdkDisplay *display, |
| 164 |
GdkDevice *device, |
| 165 |
GdkDrag *drag, |
| 166 |
GdkContentFormats *formats, |
| 167 |
GdkSurface *surface, |
| 168 |
GdkDragProtocol protocol) |
| 169 |
{ |
| 170 |
GdkWin32Drop *drop_win32; |
| 171 |
GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (display); |
| 172 |
|
| 173 |
drop_win32 = g_object_new (GDK_TYPE_WIN32_DROP, |
| 174 |
"device", device, |
| 175 |
"drag", drag, |
| 176 |
"formats", formats, |
| 177 |
"surface", surface, |
| 178 |
NULL); |
| 179 |
|
| 180 |
drop_win32->scale = gdk_win32_display_get_monitor_scale_factor (display_win32, NULL, NULL); |
| 181 |
drop_win32->protocol = protocol; |
| 182 |
|
| 183 |
return GDK_DROP (drop_win32); |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
#define PRINT_GUID(guid) \ |
| 188 |
g_print ("%.08lx-%.04x-%.04x-%.02x%.02x-%.02x%.02x%.02x%.02x%.02x%.02x", \ |
| 189 |
((gulong *) guid)[0], \ |
| 190 |
((gushort *) guid)[2], \ |
| 191 |
((gushort *) guid)[3], \ |
| 192 |
((guchar *) guid)[8], \ |
| 193 |
((guchar *) guid)[9], \ |
| 194 |
((guchar *) guid)[10], \ |
| 195 |
((guchar *) guid)[11], \ |
| 196 |
((guchar *) guid)[12], \ |
| 197 |
((guchar *) guid)[13], \ |
| 198 |
((guchar *) guid)[14], \ |
| 199 |
((guchar *) guid)[15]); |
| 200 |
|
| 201 |
static ULONG STDMETHODCALLTYPE |
| 202 |
idroptarget_addref (LPDROPTARGET This) |
| 203 |
{ |
| 204 |
drop_target_context *ctx = (drop_target_context *) This; |
| 205 |
|
| 206 |
int ref_count = ++ctx->ref_count; |
| 207 |
|
| 208 |
GDK_NOTE (DND, g_print ("idroptarget_addref %p %d\n", This, ref_count)); |
| 209 |
|
| 210 |
return ref_count; |
| 211 |
} |
| 212 |
|
| 213 |
static HRESULT STDMETHODCALLTYPE |
| 214 |
idroptarget_queryinterface (LPDROPTARGET This, |
| 215 |
REFIID riid, |
| 216 |
LPVOID *ppvObject) |
| 217 |
{ |
| 218 |
GDK_NOTE (DND, { |
| 219 |
g_print ("idroptarget_queryinterface %p ", This); |
| 220 |
PRINT_GUID (riid); |
| 221 |
}); |
| 222 |
|
| 223 |
*ppvObject = NULL; |
| 224 |
|
| 225 |
if (IsEqualGUID (riid, &IID_IUnknown)) |
| 226 |
{ |
| 227 |
GDK_NOTE (DND, g_print ("...IUnknown S_OK\n")); |
| 228 |
idroptarget_addref (This); |
| 229 |
*ppvObject = This; |
| 230 |
return S_OK; |
| 231 |
} |
| 232 |
else if (IsEqualGUID (riid, &IID_IDropTarget)) |
| 233 |
{ |
| 234 |
GDK_NOTE (DND, g_print ("...IDropTarget S_OK\n")); |
| 235 |
idroptarget_addref (This); |
| 236 |
*ppvObject = This; |
| 237 |
return S_OK; |
| 238 |
} |
| 239 |
else |
| 240 |
{ |
| 241 |
GDK_NOTE (DND, g_print ("...E_NOINTERFACE\n")); |
| 242 |
return E_NOINTERFACE; |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
static ULONG STDMETHODCALLTYPE |
| 247 |
idroptarget_release (LPDROPTARGET This) |
| 248 |
{ |
| 249 |
drop_target_context *ctx = (drop_target_context *) This; |
| 250 |
|
| 251 |
int ref_count = --ctx->ref_count; |
| 252 |
|
| 253 |
GDK_NOTE (DND, g_print ("idroptarget_release %p %d\n", This, ref_count)); |
| 254 |
|
| 255 |
if (ref_count == 0) |
| 256 |
{ |
| 257 |
g_clear_object (&ctx->drop); |
| 258 |
g_free (This); |
| 259 |
} |
| 260 |
|
| 261 |
return ref_count; |
| 262 |
} |
| 263 |
|
| 264 |
static GdkContentFormats * |
| 265 |
query_object_formats (GdkDisplay *display, |
| 266 |
LPDATAOBJECT pDataObj, |
| 267 |
GArray *w32format_contentformat_map) |
| 268 |
{ |
| 269 |
IEnumFORMATETC *pfmt = NULL; |
| 270 |
FORMATETC fmt; |
| 271 |
HRESULT hr; |
| 272 |
GdkContentFormatsBuilder *builder; |
| 273 |
GdkContentFormats *result_formats; |
| 274 |
|
| 275 |
hr = IDataObject_EnumFormatEtc (pDataObj, DATADIR_GET, &pfmt); |
| 276 |
if (FAILED (hr)) |
| 277 |
return gdk_content_formats_new (NULL, 0); |
| 278 |
|
| 279 |
builder = gdk_content_formats_builder_new (); |
| 280 |
hr = IEnumFORMATETC_Next (pfmt, 1, &fmt, NULL); |
| 281 |
|
| 282 |
while (SUCCEEDED (hr) && hr != S_FALSE) |
| 283 |
{ |
| 284 |
gboolean is_predef; |
| 285 |
char *registered_name = _gdk_win32_get_clipboard_format_name (fmt.cfFormat, &is_predef); |
| 286 |
|
| 287 |
if (registered_name && is_predef) |
| 288 |
GDK_NOTE (DND, g_print ("supported built-in source format 0x%x %s\n", fmt.cfFormat, registered_name)); |
| 289 |
else if (registered_name) |
| 290 |
GDK_NOTE (DND, g_print ("supported source format 0x%x %s\n", fmt.cfFormat, registered_name)); |
| 291 |
else |
| 292 |
GDK_NOTE (DND, g_print ("supported unnamed? source format 0x%x\n", fmt.cfFormat)); |
| 293 |
|
| 294 |
g_free (registered_name); |
| 295 |
gdk_win32_clipdrop_add_win32_format_to_pairs (gdk_win32_display_get_clipdrop (display), fmt.cfFormat, w32format_contentformat_map, builder); |
| 296 |
hr = IEnumFORMATETC_Next (pfmt, 1, &fmt, NULL); |
| 297 |
} |
| 298 |
|
| 299 |
gdk_win32_com_clear (&pfmt); |
| 300 |
|
| 301 |
result_formats = gdk_content_formats_builder_free_to_formats (builder); |
| 302 |
|
| 303 |
return result_formats; |
| 304 |
} |
| 305 |
|
| 306 |
static void |
| 307 |
set_data_object (LPDATAOBJECT *location, LPDATAOBJECT data_object) |
| 308 |
{ |
| 309 |
gdk_win32_com_clear (location); |
| 310 |
|
| 311 |
*location = data_object; |
| 312 |
|
| 313 |
if (*location != NULL) |
| 314 |
IDataObject_AddRef (*location); |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
static GdkDragAction |
| 321 |
get_user_action (DWORD grfKeyState) |
| 322 |
{ |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
if (((grfKeyState & (MK_CONTROL | MK_ALT)) == (MK_CONTROL | MK_ALT)) || |
| 333 |
((grfKeyState & (MK_ALT | MK_SHIFT)) == (MK_ALT | MK_SHIFT)) || |
| 334 |
((grfKeyState & (MK_CONTROL | MK_ALT | MK_SHIFT)) == (MK_CONTROL | MK_ALT | MK_SHIFT))) |
| 335 |
{ |
| 336 |
return 0; |
| 337 |
} |
| 338 |
else if ((grfKeyState & (MK_CONTROL | MK_SHIFT)) == (MK_CONTROL | MK_SHIFT)) |
| 339 |
return GDK_ACTION_LINK; |
| 340 |
else if (grfKeyState & MK_CONTROL) |
| 341 |
return GDK_ACTION_COPY; |
| 342 |
else if (grfKeyState & MK_ALT) |
| 343 |
return GDK_ACTION_MOVE; |
| 344 |
|
| 345 |
return 0; |
| 346 |
} |
| 347 |
|
| 348 |
static DWORD |
| 349 |
drop_effect_for_actions (GdkDragAction actions) |
| 350 |
{ |
| 351 |
DWORD effects = 0; |
| 352 |
int effect_count = 0; |
| 353 |
|
| 354 |
if (actions & GDK_ACTION_MOVE) |
| 355 |
{ |
| 356 |
effects |= DROPEFFECT_MOVE; |
| 357 |
effect_count++; |
| 358 |
} |
| 359 |
if (actions & GDK_ACTION_LINK) |
| 360 |
{ |
| 361 |
effects |= DROPEFFECT_LINK; |
| 362 |
effect_count++; |
| 363 |
} |
| 364 |
if (actions & GDK_ACTION_COPY) |
| 365 |
{ |
| 366 |
effects |= DROPEFFECT_COPY; |
| 367 |
effect_count++; |
| 368 |
} |
| 369 |
|
| 370 |
if (effect_count == 0) |
| 371 |
effects = DROPEFFECT_NONE; |
| 372 |
else if (effect_count > 1) |
| 373 |
|
| 374 |
effects = DROPEFFECT_COPY; |
| 375 |
|
| 376 |
return effects; |
| 377 |
} |
| 378 |
|
| 379 |
static GdkDragAction |
| 380 |
actions_for_drop_effects (DWORD effects) |
| 381 |
{ |
| 382 |
GdkDragAction actions = 0; |
| 383 |
|
| 384 |
if (effects & DROPEFFECT_MOVE) |
| 385 |
actions |= GDK_ACTION_MOVE; |
| 386 |
if (effects & DROPEFFECT_LINK) |
| 387 |
actions |= GDK_ACTION_LINK; |
| 388 |
if (effects & DROPEFFECT_COPY) |
| 389 |
actions |= GDK_ACTION_COPY; |
| 390 |
|
| 391 |
return actions; |
| 392 |
} |
| 393 |
|
| 394 |
static GdkDragAction |
| 395 |
filter_actions (GdkDragAction actions, |
| 396 |
GdkDragAction filter) |
| 397 |
{ |
| 398 |
return actions & filter; |
| 399 |
} |
| 400 |
|
| 401 |
static GdkDragAction |
| 402 |
set_source_actions_helper (GdkDrop *drop, |
| 403 |
GdkDragAction actions, |
| 404 |
DWORD grfKeyState) |
| 405 |
{ |
| 406 |
GdkDragAction user_action; |
| 407 |
GdkWin32Drop *drop_win32; |
| 408 |
|
| 409 |
user_action = get_user_action (grfKeyState); |
| 410 |
|
| 411 |
drop_win32 = GDK_WIN32_DROP (drop); |
| 412 |
drop_win32->actions = actions; |
| 413 |
|
| 414 |
if (user_action != 0) |
| 415 |
gdk_drop_set_actions (drop, user_action); |
| 416 |
else |
| 417 |
gdk_drop_set_actions (drop, actions); |
| 418 |
|
| 419 |
return actions; |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
static void |
| 427 |
unscaled_screen_to_client (GdkSurface* surface, |
| 428 |
double screen_x, |
| 429 |
double screen_y, |
| 430 |
double *client_x, |
| 431 |
double *client_y) |
| 432 |
{ |
| 433 |
POINT client_origin; |
| 434 |
|
| 435 |
client_origin.x = 0; |
| 436 |
client_origin.y = 0; |
| 437 |
ClientToScreen (GDK_SURFACE_HWND (surface), &client_origin); |
| 438 |
*client_x = screen_x - client_origin.x; |
| 439 |
*client_y = screen_y - client_origin.y; |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
static HRESULT STDMETHODCALLTYPE |
| 450 |
idroptarget_dragenter (LPDROPTARGET This, |
| 451 |
LPDATAOBJECT pDataObj, |
| 452 |
DWORD grfKeyState, |
| 453 |
POINTL pt, |
| 454 |
LPDWORD pdwEffect_and_dwOKEffects) |
| 455 |
{ |
| 456 |
drop_target_context *ctx = (drop_target_context *) This; |
| 457 |
GdkDrop *drop; |
| 458 |
GdkWin32Drop *drop_win32; |
| 459 |
GdkDisplay *display; |
| 460 |
int pt_x; |
| 461 |
int pt_y; |
| 462 |
double x = 0.0; |
| 463 |
double y = 0.0; |
| 464 |
GdkDrag *drag; |
| 465 |
GdkDragAction source_actions; |
| 466 |
GdkDragAction dest_actions; |
| 467 |
GdkContentFormats *formats; |
| 468 |
GArray *droptarget_w32format_contentformat_map; |
| 469 |
|
| 470 |
GDK_NOTE (DND, g_print ("idroptarget_dragenter %p @ %ld : %ld" |
| 471 |
" for dest surface 0x%p" |
| 472 |
". dwOKEffects = %lu\n", |
| 473 |
This, pt.x, pt.y, |
| 474 |
ctx->surface, |
| 475 |
*pdwEffect_and_dwOKEffects)); |
| 476 |
|
| 477 |
g_clear_object (&ctx->drop); |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
drag = NULL; |
| 483 |
|
| 484 |
if (ctx->surface) |
| 485 |
drag = gdk_win32_find_drag_for_dest_surface (ctx->surface); |
| 486 |
|
| 487 |
display = gdk_surface_get_display (ctx->surface); |
| 488 |
|
| 489 |
droptarget_w32format_contentformat_map = g_array_new (FALSE, FALSE, sizeof (GdkWin32ContentFormatPair)); |
| 490 |
formats = query_object_formats (display, pDataObj, droptarget_w32format_contentformat_map); |
| 491 |
drop = gdk_drop_new (display, |
| 492 |
gdk_seat_get_pointer (gdk_display_get_default_seat (display)), |
| 493 |
drag, |
| 494 |
formats, |
| 495 |
ctx->surface, |
| 496 |
GDK_DRAG_PROTO_OLE2); |
| 497 |
drop_win32 = GDK_WIN32_DROP (drop); |
| 498 |
drop_win32->droptarget_w32format_contentformat_map = droptarget_w32format_contentformat_map; |
| 499 |
gdk_content_formats_unref (formats); |
| 500 |
|
| 501 |
ctx->drop = drop; |
| 502 |
|
| 503 |
source_actions = set_source_actions_helper (drop, |
| 504 |
actions_for_drop_effects (*pdwEffect_and_dwOKEffects), |
| 505 |
grfKeyState); |
| 506 |
|
| 507 |
set_data_object (&ctx->data_object, pDataObj); |
| 508 |
pt_x = pt.x / drop_win32->scale; |
| 509 |
pt_y = pt.y / drop_win32->scale; |
| 510 |
|
| 511 |
unscaled_screen_to_client (ctx->surface, pt.x, pt.y, &x, &y); |
| 512 |
x /= drop_win32->scale; |
| 513 |
y /= drop_win32->scale; |
| 514 |
|
| 515 |
gdk_drop_emit_enter_event (drop, TRUE, x, y, GDK_CURRENT_TIME); |
| 516 |
drop_win32->last_key_state = grfKeyState; |
| 517 |
drop_win32->last_x = pt_x; |
| 518 |
drop_win32->last_y = pt_y; |
| 519 |
dest_actions = filter_actions (gdk_drop_get_actions (drop), source_actions); |
| 520 |
*pdwEffect_and_dwOKEffects = drop_effect_for_actions (dest_actions); |
| 521 |
|
| 522 |
GDK_NOTE (DND, g_print ("idroptarget_dragenter returns S_OK with actions %s" |
| 523 |
" and drop effect %lu\n", |
| 524 |
_gdk_win32_drag_action_to_string (dest_actions), |
| 525 |
*pdwEffect_and_dwOKEffects)); |
| 526 |
|
| 527 |
return S_OK; |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
static HRESULT STDMETHODCALLTYPE |
| 541 |
idroptarget_dragover (LPDROPTARGET This, |
| 542 |
DWORD grfKeyState, |
| 543 |
POINTL pt, |
| 544 |
LPDWORD pdwEffect_and_dwOKEffects) |
| 545 |
{ |
| 546 |
drop_target_context *ctx = (drop_target_context *) This; |
| 547 |
GdkWin32Drop *drop_win32 = GDK_WIN32_DROP (ctx->drop); |
| 548 |
int pt_x = pt.x / drop_win32->scale; |
| 549 |
int pt_y = pt.y / drop_win32->scale; |
| 550 |
GdkDragAction source_actions; |
| 551 |
GdkDragAction dest_actions; |
| 552 |
|
| 553 |
source_actions = actions_for_drop_effects (*pdwEffect_and_dwOKEffects); |
| 554 |
|
| 555 |
GDK_NOTE (DND, g_print ("idroptarget_dragover %p @ %d : %d" |
| 556 |
" (raw %ld : %ld)" |
| 557 |
", dwOKEffects = %lu" |
| 558 |
", suggests %d action\n", |
| 559 |
This, pt_x, pt_y, |
| 560 |
pt.x, pt.y, |
| 561 |
*pdwEffect_and_dwOKEffects, |
| 562 |
source_actions)); |
| 563 |
|
| 564 |
if (pt_x != drop_win32->last_x || |
| 565 |
pt_y != drop_win32->last_y || |
| 566 |
grfKeyState != drop_win32->last_key_state || |
| 567 |
source_actions != drop_win32->actions) |
| 568 |
{ |
| 569 |
double x = 0.0; |
| 570 |
double y = 0.0; |
| 571 |
|
| 572 |
unscaled_screen_to_client (ctx->surface, pt.x, pt.y, &x, &y); |
| 573 |
x /= drop_win32->scale; |
| 574 |
y /= drop_win32->scale; |
| 575 |
|
| 576 |
set_source_actions_helper (ctx->drop, source_actions, grfKeyState); |
| 577 |
|
| 578 |
gdk_drop_emit_motion_event (ctx->drop, TRUE, x, y, GDK_CURRENT_TIME); |
| 579 |
drop_win32->last_key_state = grfKeyState; |
| 580 |
drop_win32->last_x = pt_x; |
| 581 |
drop_win32->last_y = pt_y; |
| 582 |
} |
| 583 |
|
| 584 |
dest_actions = filter_actions (gdk_drop_get_actions (ctx->drop), source_actions); |
| 585 |
*pdwEffect_and_dwOKEffects = drop_effect_for_actions (dest_actions); |
| 586 |
|
| 587 |
GDK_NOTE (DND, g_print ("idroptarget_dragover returns S_OK with actions %s" |
| 588 |
" and effect %lu\n", |
| 589 |
_gdk_win32_drag_action_to_string (dest_actions), |
| 590 |
*pdwEffect_and_dwOKEffects)); |
| 591 |
|
| 592 |
return S_OK; |
| 593 |
} |
| 594 |
|
| 595 |
static HRESULT STDMETHODCALLTYPE |
| 596 |
idroptarget_dragleave (LPDROPTARGET This) |
| 597 |
{ |
| 598 |
drop_target_context *ctx = (drop_target_context *) This; |
| 599 |
|
| 600 |
GDK_NOTE (DND, g_print ("idroptarget_dragleave %p S_OK\n", This)); |
| 601 |
|
| 602 |
gdk_drop_emit_leave_event (GDK_DROP (ctx->drop), TRUE, GDK_CURRENT_TIME); |
| 603 |
|
| 604 |
g_clear_object (&ctx->drop); |
| 605 |
set_data_object (&ctx->data_object, NULL); |
| 606 |
|
| 607 |
return S_OK; |
| 608 |
} |
| 609 |
|
| 610 |
static HRESULT STDMETHODCALLTYPE |
| 611 |
idroptarget_drop (LPDROPTARGET This, |
| 612 |
LPDATAOBJECT pDataObj, |
| 613 |
DWORD grfKeyState, |
| 614 |
POINTL pt, |
| 615 |
LPDWORD pdwEffect_and_dwOKEffects) |
| 616 |
{ |
| 617 |
drop_target_context *ctx = (drop_target_context *) This; |
| 618 |
GdkWin32Drop *drop_win32 = GDK_WIN32_DROP (ctx->drop); |
| 619 |
double x = 0.0; |
| 620 |
double y = 0.0; |
| 621 |
GdkDragAction dest_action; |
| 622 |
|
| 623 |
GDK_NOTE (DND, g_print ("idroptarget_drop %p ", This)); |
| 624 |
|
| 625 |
if (pDataObj == NULL) |
| 626 |
{ |
| 627 |
GDK_NOTE (DND, g_print ("E_POINTER\n")); |
| 628 |
gdk_drop_emit_leave_event (ctx->drop, TRUE, GDK_CURRENT_TIME); |
| 629 |
g_clear_object (&ctx->drop); |
| 630 |
set_data_object (&ctx->data_object, NULL); |
| 631 |
|
| 632 |
return E_POINTER; |
| 633 |
} |
| 634 |
|
| 635 |
set_source_actions_helper (ctx->drop, |
| 636 |
actions_for_drop_effects (*pdwEffect_and_dwOKEffects), |
| 637 |
grfKeyState); |
| 638 |
|
| 639 |
drop_win32->drop_finished = FALSE; |
| 640 |
|
| 641 |
unscaled_screen_to_client (ctx->surface, pt.x, pt.y, &x, &y); |
| 642 |
x /= drop_win32->scale; |
| 643 |
y /= drop_win32->scale; |
| 644 |
|
| 645 |
gdk_drop_emit_motion_event (ctx->drop, TRUE, x, y, GDK_CURRENT_TIME); |
| 646 |
|
| 647 |
gdk_drop_emit_drop_event (ctx->drop, TRUE, x, y, GDK_CURRENT_TIME); |
| 648 |
|
| 649 |
gdk_drop_emit_leave_event (ctx->drop, TRUE, GDK_CURRENT_TIME); |
| 650 |
|
| 651 |
while (!drop_win32->drop_finished) |
| 652 |
g_main_context_iteration (NULL, FALSE); |
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
dest_action = drop_win32->actions; |
| 659 |
*pdwEffect_and_dwOKEffects = drop_effect_for_actions (dest_action); |
| 660 |
|
| 661 |
g_clear_object (&ctx->drop); |
| 662 |
set_data_object (&ctx->data_object, NULL); |
| 663 |
|
| 664 |
GDK_NOTE (DND, g_print ("drop S_OK with effect %lx\n", *pdwEffect_and_dwOKEffects)); |
| 665 |
|
| 666 |
return S_OK; |
| 667 |
} |
| 668 |
|
| 669 |
static IDropTargetVtbl idt_vtbl = { |
| 670 |
idroptarget_queryinterface, |
| 671 |
idroptarget_addref, |
| 672 |
idroptarget_release, |
| 673 |
idroptarget_dragenter, |
| 674 |
idroptarget_dragover, |
| 675 |
idroptarget_dragleave, |
| 676 |
idroptarget_drop |
| 677 |
}; |
| 678 |
|
| 679 |
static drop_target_context * |
| 680 |
target_context_new (GdkSurface *surface) |
| 681 |
{ |
| 682 |
drop_target_context *result; |
| 683 |
|
| 684 |
result = g_new0 (drop_target_context, 1); |
| 685 |
result->idt.lpVtbl = &idt_vtbl; |
| 686 |
result->ref_count = 0; |
| 687 |
|
| 688 |
result->surface = surface; |
| 689 |
|
| 690 |
idroptarget_addref (&result->idt); |
| 691 |
|
| 692 |
GDK_NOTE (DND, g_print ("target_context_new: %p (surface %p)\n", result, result->surface)); |
| 693 |
|
| 694 |
return result; |
| 695 |
} |
| 696 |
|
| 697 |
#if 0 |
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
static gboolean |
| 702 |
resolve_link (HWND hWnd, |
| 703 |
wchar_t *link, |
| 704 |
char **lpszPath) |
| 705 |
{ |
| 706 |
WIN32_FILE_ATTRIBUTE_DATA wfad; |
| 707 |
HRESULT hr; |
| 708 |
IShellLinkW *pslW = NULL; |
| 709 |
IPersistFile *ppf = NULL; |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
if (!GetFileAttributesExW (link, GetFileExInfoStandard, &wfad) || |
| 716 |
(wfad.nFileSizeHigh == 0 && wfad.nFileSizeLow == 0)) |
| 717 |
return FALSE; |
| 718 |
|
| 719 |
|
| 720 |
*lpszPath = 0; |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
hr = CoCreateInstance (&CLSID_ShellLink, |
| 728 |
NULL, |
| 729 |
CLSCTX_INPROC_SERVER, |
| 730 |
&IID_IShellLinkW, |
| 731 |
(LPVOID *)&pslW); |
| 732 |
|
| 733 |
if (SUCCEEDED (hr)) |
| 734 |
{ |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
hr = pslW->lpVtbl->QueryInterface (pslW, |
| 739 |
&IID_IPersistFile, |
| 740 |
(LPVOID *) &ppf); |
| 741 |
} |
| 742 |
|
| 743 |
if (SUCCEEDED (hr)) |
| 744 |
{ |
| 745 |
|
| 746 |
hr = ppf->lpVtbl->Load (ppf, link, STGM_READ); |
| 747 |
} |
| 748 |
|
| 749 |
if (SUCCEEDED (hr)) |
| 750 |
{ |
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
hr = pslW->lpVtbl->Resolve (pslW, hWnd, SLR_ANY_MATCH | SLR_NO_UI); |
| 755 |
} |
| 756 |
|
| 757 |
if (SUCCEEDED (hr)) |
| 758 |
{ |
| 759 |
wchar_t wtarget[MAX_PATH]; |
| 760 |
|
| 761 |
hr = pslW->lpVtbl->GetPath (pslW, wtarget, MAX_PATH, NULL, 0); |
| 762 |
if (SUCCEEDED (hr)) |
| 763 |
*lpszPath = g_utf16_to_utf8 (wtarget, -1, NULL, NULL, NULL); |
| 764 |
} |
| 765 |
|
| 766 |
if (ppf) |
| 767 |
ppf->lpVtbl->Release (ppf); |
| 768 |
|
| 769 |
if (pslW) |
| 770 |
pslW->lpVtbl->Release (pslW); |
| 771 |
|
| 772 |
return SUCCEEDED (hr); |
| 773 |
} |
| 774 |
|
| 775 |
|
| 776 |
static gboolean |
| 777 |
filename_looks_tempish (const char *filename) |
| 778 |
{ |
| 779 |
char *dirname; |
| 780 |
char *p; |
| 781 |
const char *q; |
| 782 |
gboolean retval = FALSE; |
| 783 |
|
| 784 |
dirname = g_path_get_dirname (filename); |
| 785 |
|
| 786 |
p = dirname; |
| 787 |
q = g_get_tmp_dir (); |
| 788 |
|
| 789 |
while (*p && *q && |
| 790 |
((G_IS_DIR_SEPARATOR (*p) && G_IS_DIR_SEPARATOR (*q)) || |
| 791 |
g_ascii_tolower (*p) == g_ascii_tolower (*q))) |
| 792 |
p++, q++; |
| 793 |
|
| 794 |
if (!*p && !*q) |
| 795 |
retval = TRUE; |
| 796 |
|
| 797 |
g_free (dirname); |
| 798 |
|
| 799 |
return retval; |
| 800 |
} |
| 801 |
|
| 802 |
static gboolean |
| 803 |
close_it (gpointer data) |
| 804 |
{ |
| 805 |
close (GPOINTER_TO_INT (data)); |
| 806 |
|
| 807 |
return FALSE; |
| 808 |
} |
| 809 |
|
| 810 |
#endif |
| 811 |
|
| 812 |
static void |
| 813 |
gdk_win32_drop_status (GdkDrop *drop, |
| 814 |
GdkDragAction actions, |
| 815 |
GdkDragAction preferred) |
| 816 |
{ |
| 817 |
GdkWin32Drop *drop_win32 = GDK_WIN32_DROP (drop); |
| 818 |
|
| 819 |
g_return_if_fail (drop != NULL); |
| 820 |
|
| 821 |
GDK_NOTE (DND, g_print ("gdk_win32_drop_status: %s\n" |
| 822 |
" context=%p:{source_actions=%s, preferred=%s}\n", |
| 823 |
_gdk_win32_drag_action_to_string (actions), |
| 824 |
drop, |
| 825 |
_gdk_win32_drag_action_to_string (gdk_drop_get_actions (drop)), |
| 826 |
_gdk_win32_drag_action_to_string (preferred))); |
| 827 |
|
| 828 |
if (preferred != 0) |
| 829 |
actions = preferred; |
| 830 |
|
| 831 |
gdk_drop_set_actions (drop, drop_win32->actions & actions); |
| 832 |
} |
| 833 |
|
| 834 |
static void |
| 835 |
gdk_win32_drop_finish (GdkDrop *drop, |
| 836 |
GdkDragAction action) |
| 837 |
{ |
| 838 |
GdkWin32Drop *drop_win32 = GDK_WIN32_DROP (drop); |
| 839 |
|
| 840 |
g_return_if_fail (drop != NULL); |
| 841 |
|
| 842 |
GDK_NOTE (DND, g_print ("gdk_win32_drop_finish with action %s\n", |
| 843 |
_gdk_win32_drag_action_to_string (action))); |
| 844 |
|
| 845 |
drop_win32->actions = action; |
| 846 |
drop_win32->drop_finished = TRUE; |
| 847 |
} |
| 848 |
|
| 849 |
#if 0 |
| 850 |
|
| 851 |
static GdkFilterReturn |
| 852 |
gdk_destroy_filter (GdkXEvent *xev, |
| 853 |
GdkEvent *event, |
| 854 |
gpointer data) |
| 855 |
{ |
| 856 |
MSG *msg = (MSG *) xev; |
| 857 |
|
| 858 |
if (msg->message == WM_DESTROY) |
| 859 |
{ |
| 860 |
IDropTarget *idtp = (IDropTarget *) data; |
| 861 |
|
| 862 |
GDK_NOTE (DND, g_print ("gdk_destroy_filter: WM_DESTROY: %p\n", msg->hwnd)); |
| 863 |
#if 0 |
| 864 |
idtp->lpVtbl->Release (idtp); |
| 865 |
#endif |
| 866 |
RevokeDragDrop (msg->hwnd); |
| 867 |
CoLockObjectExternal ((IUnknown*) idtp, FALSE, TRUE); |
| 868 |
} |
| 869 |
return GDK_FILTER_CONTINUE; |
| 870 |
} |
| 871 |
|
| 872 |
#endif |
| 873 |
|
| 874 |
void |
| 875 |
_gdk_win32_surface_register_dnd (GdkSurface *surface) |
| 876 |
{ |
| 877 |
drop_target_context *ctx; |
| 878 |
HRESULT hr; |
| 879 |
GdkWin32Surface *impl; |
| 880 |
|
| 881 |
g_return_if_fail (surface != NULL); |
| 882 |
|
| 883 |
if (g_object_get_data (G_OBJECT (surface), "gdk-dnd-registered") != NULL) |
| 884 |
return; |
| 885 |
else |
| 886 |
g_object_set_data (G_OBJECT (surface), "gdk-dnd-registered", GINT_TO_POINTER (TRUE)); |
| 887 |
|
| 888 |
GDK_NOTE (DND, g_print ("gdk_win32_surface_register_dnd: %p\n", GDK_SURFACE_HWND (surface))); |
| 889 |
|
| 890 |
impl = GDK_WIN32_SURFACE (surface); |
| 891 |
|
| 892 |
|
| 893 |
if (impl->drop_target != NULL) |
| 894 |
return; |
| 895 |
|
| 896 |
ctx = target_context_new (surface); |
| 897 |
|
| 898 |
hr = CoLockObjectExternal ((IUnknown *) &ctx->idt, TRUE, FALSE); |
| 899 |
if (!SUCCEEDED (hr)) |
| 900 |
OTHER_API_FAILED ("CoLockObjectExternal"); |
| 901 |
else |
| 902 |
{ |
| 903 |
hr = RegisterDragDrop (GDK_SURFACE_HWND (surface), &ctx->idt); |
| 904 |
if (hr == DRAGDROP_E_ALREADYREGISTERED) |
| 905 |
{ |
| 906 |
g_print ("DRAGDROP_E_ALREADYREGISTERED\n"); |
| 907 |
CoLockObjectExternal ((IUnknown *) &ctx->idt, FALSE, FALSE); |
| 908 |
} |
| 909 |
else if (!SUCCEEDED (hr)) |
| 910 |
OTHER_API_FAILED ("RegisterDragDrop"); |
| 911 |
else |
| 912 |
{ |
| 913 |
impl->drop_target = ctx; |
| 914 |
} |
| 915 |
} |
| 916 |
} |
| 917 |
|
| 918 |
void |
| 919 |
_gdk_win32_surface_unregister_dnd (GdkSurface *surface) |
| 920 |
{ |
| 921 |
GdkWin32Surface *impl = GDK_WIN32_SURFACE (surface); |
| 922 |
|
| 923 |
if (impl->drop_target) |
| 924 |
idroptarget_release (&impl->drop_target->idt); |
| 925 |
} |
| 926 |
|
| 927 |
static gpointer |
| 928 |
grab_data_from_hdata (GTask *task, |
| 929 |
HANDLE hdata, |
| 930 |
gsize *data_len) |
| 931 |
{ |
| 932 |
gpointer ptr; |
| 933 |
SIZE_T length; |
| 934 |
guchar *data; |
| 935 |
|
| 936 |
ptr = GlobalLock (hdata); |
| 937 |
if (ptr == NULL) |
| 938 |
{ |
| 939 |
DWORD error_code = GetLastError (); |
| 940 |
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, |
| 941 |
_("Cannot get DnD data. GlobalLock(0x%p) failed: 0x%lx."), hdata, error_code); |
| 942 |
return NULL; |
| 943 |
} |
| 944 |
|
| 945 |
length = GlobalSize (hdata); |
| 946 |
if (length == 0 && GetLastError () != NO_ERROR) |
| 947 |
{ |
| 948 |
DWORD error_code = GetLastError (); |
| 949 |
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, |
| 950 |
_("Cannot get DnD data. GlobalSize(0x%p) failed: 0x%lx."), hdata, error_code); |
| 951 |
GlobalUnlock (hdata); |
| 952 |
return NULL; |
| 953 |
} |
| 954 |
|
| 955 |
data = g_try_malloc (length); |
| 956 |
|
| 957 |
if (data == NULL) |
| 958 |
{ |
| 959 |
char *length_str = g_strdup_printf ("%" G_GSIZE_FORMAT, length); |
| 960 |
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, |
| 961 |
_("Cannot get DnD data. Failed to allocate %s bytes to store the data."), length_str); |
| 962 |
g_free (length_str); |
| 963 |
GlobalUnlock (hdata); |
| 964 |
return NULL; |
| 965 |
} |
| 966 |
|
| 967 |
memcpy (data, ptr, length); |
| 968 |
*data_len = length; |
| 969 |
|
| 970 |
GlobalUnlock (hdata); |
| 971 |
|
| 972 |
return data; |
| 973 |
} |
| 974 |
|
| 975 |
static void |
| 976 |
gdk_win32_drop_read_async (GdkDrop *drop, |
| 977 |
GdkContentFormats *formats, |
| 978 |
int io_priority, |
| 979 |
GCancellable *cancellable, |
| 980 |
GAsyncReadyCallback callback, |
| 981 |
gpointer user_data) |
| 982 |
{ |
| 983 |
GdkWin32Drop *drop_win32 = GDK_WIN32_DROP (drop); |
| 984 |
GTask *task; |
| 985 |
drop_target_context *tctx; |
| 986 |
const char * const *mime_types; |
| 987 |
gsize i, j, n_mime_types; |
| 988 |
GdkWin32ContentFormatPair *pair; |
| 989 |
FORMATETC fmt; |
| 990 |
HRESULT hr; |
| 991 |
STGMEDIUM storage; |
| 992 |
guchar *data; |
| 993 |
gsize data_len; |
| 994 |
GInputStream *stream; |
| 995 |
|
| 996 |
task = g_task_new (drop, cancellable, callback, user_data); |
| 997 |
g_task_set_priority (task, io_priority); |
| 998 |
g_task_set_source_tag (task, gdk_win32_drop_read_async); |
| 999 |
|
| 1000 |
mime_types = gdk_content_formats_get_mime_types (formats, &n_mime_types); |
| 1001 |
|
| 1002 |
if (drop_win32->protocol == GDK_DRAG_PROTO_WIN32_DROPFILES) |
| 1003 |
{ |
| 1004 |
for (i = 0; i < n_mime_types; i++) |
| 1005 |
if (g_strcmp0 (mime_types[i], "text/uri-list") == 0) |
| 1006 |
break; |
| 1007 |
if (i >= n_mime_types) |
| 1008 |
{ |
| 1009 |
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, |
| 1010 |
_("No compatible transfer format found")); |
| 1011 |
g_object_unref (task); |
| 1012 |
g_clear_pointer (&drop_win32->dropfiles_list, g_free); |
| 1013 |
|
| 1014 |
return; |
| 1015 |
} |
| 1016 |
|
| 1017 |
stream = g_memory_input_stream_new_from_data (drop_win32->dropfiles_list, strlen (drop_win32->dropfiles_list), g_free); |
| 1018 |
drop_win32->dropfiles_list = NULL; |
| 1019 |
g_object_set_data (G_OBJECT (stream), "gdk-dnd-stream-contenttype", (gpointer) "text/uri-list"); |
| 1020 |
g_task_return_pointer (task, stream, g_object_unref); |
| 1021 |
g_object_unref (task); |
| 1022 |
|
| 1023 |
return; |
| 1024 |
} |
| 1025 |
|
| 1026 |
tctx = GDK_WIN32_SURFACE (gdk_drop_get_surface (drop))->drop_target; |
| 1027 |
|
| 1028 |
if (tctx == NULL) |
| 1029 |
{ |
| 1030 |
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, |
| 1031 |
_("GDK surface 0x%p is not registered as a drop target"), gdk_drop_get_surface (drop)); |
| 1032 |
g_object_unref (task); |
| 1033 |
return; |
| 1034 |
} |
| 1035 |
|
| 1036 |
if (tctx->data_object == NULL) |
| 1037 |
{ |
| 1038 |
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, |
| 1039 |
_("Target context record 0x%p has no data object"), tctx); |
| 1040 |
g_object_unref (task); |
| 1041 |
return; |
| 1042 |
} |
| 1043 |
|
| 1044 |
for (pair = NULL, i = 0; i < n_mime_types; i++) |
| 1045 |
{ |
| 1046 |
for (j = 0; j < drop_win32->droptarget_w32format_contentformat_map->len; j++) |
| 1047 |
{ |
| 1048 |
pair = &g_array_index (drop_win32->droptarget_w32format_contentformat_map, GdkWin32ContentFormatPair, j); |
| 1049 |
if (pair->contentformat == mime_types[i]) |
| 1050 |
break; |
| 1051 |
|
| 1052 |
pair = NULL; |
| 1053 |
} |
| 1054 |
} |
| 1055 |
|
| 1056 |
if (pair == NULL) |
| 1057 |
{ |
| 1058 |
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, |
| 1059 |
_("No compatible transfer format found")); |
| 1060 |
g_object_unref (task); |
| 1061 |
return; |
| 1062 |
} |
| 1063 |
|
| 1064 |
fmt.cfFormat = pair->w32format; |
| 1065 |
if (_gdk_win32_format_uses_hdata (pair->w32format)) |
| 1066 |
fmt.tymed = TYMED_HGLOBAL; |
| 1067 |
else |
| 1068 |
g_assert_not_reached (); |
| 1069 |
|
| 1070 |
fmt.ptd = NULL; |
| 1071 |
fmt.dwAspect = DVASPECT_CONTENT; |
| 1072 |
fmt.lindex = -1; |
| 1073 |
|
| 1074 |
hr = IDataObject_GetData (tctx->data_object, &fmt, &storage); |
| 1075 |
|
| 1076 |
if (!SUCCEEDED (hr) || hr != S_OK) |
| 1077 |
{ |
| 1078 |
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, |
| 1079 |
_("IDataObject_GetData (0x%x) failed, returning 0x%lx"), fmt.cfFormat, hr); |
| 1080 |
g_object_unref (task); |
| 1081 |
return; |
| 1082 |
} |
| 1083 |
|
| 1084 |
if (!pair->transmute) |
| 1085 |
{ |
| 1086 |
if (_gdk_win32_format_uses_hdata (pair->w32format)) |
| 1087 |
{ |
| 1088 |
data = grab_data_from_hdata (task, storage.hGlobal, &data_len); |
| 1089 |
|
| 1090 |
if (data == NULL) |
| 1091 |
{ |
| 1092 |
ReleaseStgMedium (&storage); |
| 1093 |
g_object_unref (task); |
| 1094 |
|
| 1095 |
return; |
| 1096 |
} |
| 1097 |
} |
| 1098 |
else |
| 1099 |
{ |
| 1100 |
g_assert_not_reached (); |
| 1101 |
} |
| 1102 |
} |
| 1103 |
else |
| 1104 |
{ |
| 1105 |
GdkDisplay *display = gdk_drop_get_display (drop); |
| 1106 |
gdk_win32_clipdrop_transmute_windows_data (gdk_win32_display_get_clipdrop (display), |
| 1107 |
pair->w32format, pair->contentformat, |
| 1108 |
storage.hGlobal, |
| 1109 |
&data, |
| 1110 |
&data_len); |
| 1111 |
} |
| 1112 |
|
| 1113 |
ReleaseStgMedium (&storage); |
| 1114 |
|
| 1115 |
if (data == NULL) |
| 1116 |
{ |
| 1117 |
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, |
| 1118 |
_("Failed to transmute DnD data W32 format 0x%x to %p (%s)"), pair->w32format, pair->contentformat, pair->contentformat); |
| 1119 |
g_object_unref (task); |
| 1120 |
return; |
| 1121 |
} |
| 1122 |
|
| 1123 |
stream = g_memory_input_stream_new_from_data (data, data_len, g_free); |
| 1124 |
g_object_set_data (G_OBJECT (stream), "gdk-dnd-stream-contenttype", (gpointer) pair->contentformat); |
| 1125 |
g_task_return_pointer (task, stream, g_object_unref); |
| 1126 |
g_object_unref (task); |
| 1127 |
} |
| 1128 |
|
| 1129 |
static GInputStream * |
| 1130 |
gdk_win32_drop_read_finish (GdkDrop *drop, |
| 1131 |
GAsyncResult *result, |
| 1132 |
const char **out_mime_type, |
| 1133 |
GError **error) |
| 1134 |
{ |
| 1135 |
GTask *task; |
| 1136 |
GInputStream *stream; |
| 1137 |
|
| 1138 |
g_return_val_if_fail (g_task_is_valid (result, G_OBJECT (drop)), NULL); |
| 1139 |
task = G_TASK (result); |
| 1140 |
g_return_val_if_fail (g_task_get_source_tag (task) == gdk_win32_drop_read_async, NULL); |
| 1141 |
|
| 1142 |
stream = g_task_propagate_pointer (task, error); |
| 1143 |
|
| 1144 |
if (stream && out_mime_type) |
| 1145 |
*out_mime_type = g_object_get_data (G_OBJECT (stream), "gdk-dnd-stream-contenttype"); |
| 1146 |
|
| 1147 |
return stream; |
| 1148 |
} |
| 1149 |
|
| 1150 |
static void |
| 1151 |
gdk_win32_drop_class_init (GdkWin32DropClass *klass) |
| 1152 |
{ |
| 1153 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 1154 |
GdkDropClass *drop_class = GDK_DROP_CLASS (klass); |
| 1155 |
|
| 1156 |
object_class->finalize = gdk_win32_drop_finalize; |
| 1157 |
|
| 1158 |
drop_class->status = gdk_win32_drop_status; |
| 1159 |
drop_class->finish = gdk_win32_drop_finish; |
| 1160 |
drop_class->read_async = gdk_win32_drop_read_async; |
| 1161 |
drop_class->read_finish = gdk_win32_drop_read_finish; |
| 1162 |
} |