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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
|
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1999 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team.
*/
/*
* GTK+ DirectFB backend
* Copyright (C) 2001-2002 convergence integrated media GmbH
* Copyright (C) 2002-2004 convergence GmbH
* Written by Denis Oliver Kropp <dok@convergence.de> and
* Sven Neumann <sven@convergence.de>
*/
#include "config.h"
#include "gdk.h"
#include "gdkdirectfb.h"
#include "gdkprivate-directfb.h"
#include "gdkdnd.h"
#include "gdkproperty.h"
typedef struct _GdkDragContextPrivate GdkDragContextPrivate;
typedef enum
{
GDK_DRAG_STATUS_DRAG,
GDK_DRAG_STATUS_MOTION_WAIT,
GDK_DRAG_STATUS_ACTION_WAIT,
GDK_DRAG_STATUS_DROP
} GtkDragStatus;
/* Structure that holds information about a drag in progress.
* this is used on both source and destination sides.
*/
struct _GdkDragContextPrivate
{
GdkAtom local_selection;
guint16 last_x; /* Coordinates from last event */
guint16 last_y;
guint drag_status : 4; /* current status of drag */
};
/* Drag Contexts */
static GList *contexts = NULL;
static GdkDragContext *current_dest_drag = NULL;
#define GDK_DRAG_CONTEXT_PRIVATE_DATA(ctx) ((GdkDragContextPrivate *) GDK_DRAG_CONTEXT (ctx)->windowing_data)
static void gdk_drag_context_finalize (GObject *object);
G_DEFINE_TYPE (GdkDragContext, gdk_drag_context, G_TYPE_OBJECT)
static void
gdk_drag_context_init (GdkDragContext *dragcontext)
{
GdkDragContextPrivate *private;
private = G_TYPE_INSTANCE_GET_PRIVATE (dragcontext,
GDK_TYPE_DRAG_CONTEXT,
GdkDragContextPrivate);
dragcontext->windowing_data = private;
contexts = g_list_prepend (contexts, dragcontext);
}
static void
gdk_drag_context_class_init (GdkDragContextClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gdk_drag_context_finalize;
g_type_class_add_private (object_class, sizeof (GdkDragContextPrivate));
}
static void
gdk_drag_context_finalize (GObject *object)
{
GdkDragContext *context = GDK_DRAG_CONTEXT (object);
g_list_free (context->targets);
if (context->source_window)
g_object_unref (context->source_window);
if (context->dest_window)
g_object_unref (context->dest_window);
contexts = g_list_remove (contexts, context);
G_OBJECT_CLASS (gdk_drag_context_parent_class)->finalize (object);
}
GdkDragContext *
gdk_drag_context_new (void)
{
return g_object_new (gdk_drag_context_get_type (), NULL);
}
static GdkDragContext *
gdk_drag_context_find (gboolean is_source,
GdkWindow *source,
GdkWindow *dest)
{
GdkDragContext *context;
GdkDragContextPrivate *private;
GList *list;
for (list = contexts; list; list = list->next)
{
context = (GdkDragContext *) list->data;
private = GDK_DRAG_CONTEXT_PRIVATE_DATA (context);
if ((!context->is_source == !is_source) &&
((source == NULL) ||
(context->source_window && (context->source_window == source))) &&
((dest == NULL) ||
(context->dest_window && (context->dest_window == dest))))
return context;
}
return NULL;
}
/************************** Public API ***********************/
void
_gdk_dnd_init (void)
{
}
/* Source side */
static void
local_send_leave (GdkDragContext *context,
guint32 time)
{
GdkEvent event;
if ((current_dest_drag != NULL) &&
(current_dest_drag->protocol == GDK_DRAG_PROTO_LOCAL) &&
(current_dest_drag->source_window == context->source_window))
{
event.dnd.type = GDK_DRAG_LEAVE;
event.dnd.window = context->dest_window;
/* Pass ownership of context to the event */
event.dnd.context = current_dest_drag;
event.dnd.send_event = FALSE;
event.dnd.time = time;
current_dest_drag = NULL;
gdk_event_put (&event);
}
}
static void
local_send_enter (GdkDragContext *context,
guint32 time)
{
GdkDragContextPrivate *private;
GdkDragContext *new_context;
GdkEvent event;
private = GDK_DRAG_CONTEXT_PRIVATE_DATA (context);
if (!private->local_selection)
private->local_selection = gdk_atom_intern ("LocalDndSelection", FALSE);
if (current_dest_drag != NULL)
{
g_object_unref (current_dest_drag);
current_dest_drag = NULL;
}
new_context = gdk_drag_context_new ();
new_context->protocol = GDK_DRAG_PROTO_LOCAL;
new_context->is_source = FALSE;
new_context->source_window = g_object_ref (context->source_window);
new_context->dest_window = g_object_ref (context->dest_window);
new_context->targets = g_list_copy (context->targets);
gdk_window_set_events (new_context->source_window,
gdk_window_get_events (new_context->source_window) |
GDK_PROPERTY_CHANGE_MASK);
new_context->actions = context->actions;
event.dnd.type = GDK_DRAG_ENTER;
event.dnd.window = context->dest_window;
event.dnd.send_event = FALSE;
event.dnd.context = new_context;
event.dnd.time = time;
current_dest_drag = new_context;
(GDK_DRAG_CONTEXT_PRIVATE_DATA (new_context))->local_selection =
private->local_selection;
gdk_event_put (&event);
}
static void
local_send_motion (GdkDragContext *context,
gint x_root,
gint y_root,
GdkDragAction action,
guint32 time)
{
GdkEvent event;
if ((current_dest_drag != NULL) &&
(current_dest_drag->protocol == GDK_DRAG_PROTO_LOCAL) &&
(current_dest_drag->source_window == context->source_window))
{
event.dnd.type = GDK_DRAG_MOTION;
event.dnd.window = current_dest_drag->dest_window;
event.dnd.send_event = FALSE;
event.dnd.context = current_dest_drag;
event.dnd.time = time;
event.dnd.x_root = x_root;
event.dnd.y_root = y_root;
current_dest_drag->suggested_action = action;
current_dest_drag->actions = action;
(GDK_DRAG_CONTEXT_PRIVATE_DATA (current_dest_drag))->last_x = x_root;
(GDK_DRAG_CONTEXT_PRIVATE_DATA (current_dest_drag))->last_y = y_root;
GDK_DRAG_CONTEXT_PRIVATE_DATA (context)->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
gdk_event_put (&event);
}
}
static void
local_send_drop (GdkDragContext *context,
guint32 time)
{
GdkEvent event;
if ((current_dest_drag != NULL) &&
(current_dest_drag->protocol == GDK_DRAG_PROTO_LOCAL) &&
(current_dest_drag->source_window == context->source_window))
{
GdkDragContextPrivate *private;
private = GDK_DRAG_CONTEXT_PRIVATE_DATA (current_dest_drag);
event.dnd.type = GDK_DROP_START;
event.dnd.window = current_dest_drag->dest_window;
event.dnd.send_event = FALSE;
event.dnd.context = current_dest_drag;
event.dnd.time = time;
event.dnd.x_root = private->last_x;
event.dnd.y_root = private->last_y;
gdk_event_put (&event);
}
}
static void
gdk_drag_do_leave (GdkDragContext *context,
guint32 time)
{
if (context->dest_window)
{
switch (context->protocol)
{
case GDK_DRAG_PROTO_LOCAL:
local_send_leave (context, time);
break;
default:
break;
}
g_object_unref (context->dest_window);
context->dest_window = NULL;
}
}
GdkDragContext *
gdk_drag_begin (GdkWindow *window,
GList *targets)
{
GList *list;
GdkDragContext *new_context;
g_return_val_if_fail (window != NULL, NULL);
g_object_ref (window);
new_context = gdk_drag_context_new ();
new_context->is_source = TRUE;
new_context->source_window = window;
new_context->targets = NULL;
new_context->actions = 0;
for (list = targets; list; list = list->next)
new_context->targets = g_list_append (new_context->targets, list->data);
return new_context;
}
guint32
gdk_drag_get_protocol_for_display(GdkDisplay *display, guint32 xid,
GdkDragProtocol *protocol)
{
GdkWindow *window;
window = gdk_window_lookup ((GdkNativeWindow) xid);
if (window &&
g_object_get_data (G_OBJECT (window), "gdk-dnd-registered") != NULL)
{
*protocol = GDK_DRAG_PROTO_LOCAL;
return xid;
}
*protocol = GDK_DRAG_PROTO_NONE;
return 0;
}
void
gdk_drag_find_window_for_screen (GdkDragContext *context,
GdkWindow *drag_window,
GdkScreen *screen,
gint x_root,
gint y_root,
GdkWindow **dest_window,
GdkDragProtocol *protocol)
{
GdkWindow *dest;
g_return_if_fail (context != NULL);
dest = gdk_window_get_pointer (NULL, &x_root, &y_root, NULL);
if (context->dest_window != dest)
{
guint32 recipient;
/* Check if new destination accepts drags, and which protocol */
if ((recipient = gdk_drag_get_protocol (GDK_WINDOW_DFB_ID (dest),
protocol)))
{
*dest_window = gdk_window_lookup ((GdkNativeWindow) recipient);
if (dest_window)
g_object_ref (*dest_window);
}
else
*dest_window = NULL;
}
else
{
*dest_window = context->dest_window;
if (*dest_window)
g_object_ref (*dest_window);
*protocol = context->protocol;
}
}
gboolean
gdk_drag_motion (GdkDragContext *context,
GdkWindow *dest_window,
GdkDragProtocol protocol,
gint x_root,
gint y_root,
GdkDragAction suggested_action,
GdkDragAction possible_actions,
guint32 time)
{
GdkDragContextPrivate *private;
g_return_val_if_fail (context != NULL, FALSE);
private = GDK_DRAG_CONTEXT_PRIVATE_DATA (context);
if (context->dest_window != dest_window)
{
GdkEvent event;
/* Send a leave to the last destination */
gdk_drag_do_leave (context, time);
private->drag_status = GDK_DRAG_STATUS_DRAG;
/* Check if new destination accepts drags, and which protocol */
if (dest_window)
{
context->dest_window = g_object_ref (dest_window);
context->protocol = protocol;
switch (protocol)
{
case GDK_DRAG_PROTO_LOCAL:
local_send_enter (context, time);
break;
default:
break;
}
context->suggested_action = suggested_action;
}
else
{
context->dest_window = NULL;
context->action = 0;
}
/* Push a status event, to let the client know that
* the drag changed
*/
event.dnd.type = GDK_DRAG_STATUS;
event.dnd.window = context->source_window;
/* We use this to signal a synthetic status. Perhaps
* we should use an extra field...
*/
event.dnd.send_event = TRUE;
event.dnd.context = context;
event.dnd.time = time;
gdk_event_put (&event);
}
else
{
context->suggested_action = suggested_action;
}
/* Send a drag-motion event */
private->last_x = x_root;
private->last_y = y_root;
if (context->dest_window)
{
if (private->drag_status == GDK_DRAG_STATUS_DRAG)
{
switch (context->protocol)
{
case GDK_DRAG_PROTO_LOCAL:
local_send_motion (context,
x_root, y_root, suggested_action, time);
break;
case GDK_DRAG_PROTO_NONE:
g_warning ("GDK_DRAG_PROTO_NONE is not valid in gdk_drag_motion()");
break;
default:
break;
}
}
else
return TRUE;
}
return FALSE;
}
void
gdk_drag_drop (GdkDragContext *context,
guint32 time)
{
g_return_if_fail (context != NULL);
if (context->dest_window)
{
switch (context->protocol)
{
case GDK_DRAG_PROTO_LOCAL:
local_send_drop (context, time);
break;
case GDK_DRAG_PROTO_NONE:
g_warning ("GDK_DRAG_PROTO_NONE is not valid in gdk_drag_drop()");
break;
default:
break;
}
}
}
void
gdk_drag_abort (GdkDragContext *context,
guint32 time)
{
g_return_if_fail (context != NULL);
gdk_drag_do_leave (context, time);
}
/* Destination side */
void
gdk_drag_status (GdkDragContext *context,
GdkDragAction action,
guint32 time)
{
GdkDragContextPrivate *private;
GdkDragContext *src_context;
GdkEvent event;
g_return_if_fail (context != NULL);
private = GDK_DRAG_CONTEXT_PRIVATE_DATA (context);
src_context = gdk_drag_context_find (TRUE,
context->source_window,
context->dest_window);
if (src_context)
{
GdkDragContextPrivate *private;
private = GDK_DRAG_CONTEXT_PRIVATE_DATA (src_context);
if (private->drag_status == GDK_DRAG_STATUS_MOTION_WAIT)
private->drag_status = GDK_DRAG_STATUS_DRAG;
event.dnd.type = GDK_DRAG_STATUS;
event.dnd.window = src_context->source_window;
event.dnd.send_event = FALSE;
event.dnd.context = src_context;
event.dnd.time = time;
src_context->action = action;
gdk_event_put (&event);
}
}
void
gdk_drop_reply (GdkDragContext *context,
gboolean ok,
guint32 time)
{
g_return_if_fail (context != NULL);
}
void
gdk_drop_finish (GdkDragContext *context,
gboolean success,
guint32 time)
{
GdkDragContextPrivate *private;
GdkDragContext *src_context;
GdkEvent event;
g_return_if_fail (context != NULL);
private = GDK_DRAG_CONTEXT_PRIVATE_DATA (context);
src_context = gdk_drag_context_find (TRUE,
context->source_window,
context->dest_window);
if (src_context)
{
g_object_ref (src_context);
event.dnd.type = GDK_DROP_FINISHED;
event.dnd.window = src_context->source_window;
event.dnd.send_event = FALSE;
event.dnd.context = src_context;
gdk_event_put (&event);
}
}
gboolean
gdk_drag_drop_succeeded (GdkDragContext *context)
{
g_warning("gdk_drag_drop_succeeded unimplemented \n");
return TRUE;
}
void
gdk_window_register_dnd (GdkWindow *window)
{
g_return_if_fail (window != NULL);
if (g_object_get_data (G_OBJECT (window), "gdk-dnd-registered") != NULL)
return;
g_object_set_data (G_OBJECT (window),
"gdk-dnd-registered",
GINT_TO_POINTER (TRUE));
}
/*************************************************************
* gdk_drag_get_selection:
* Returns the selection atom for the current source window
* arguments:
*
* results:
*************************************************************/
GdkAtom
gdk_drag_get_selection (GdkDragContext *context)
{
g_return_val_if_fail (context != NULL, GDK_NONE);
if (context->protocol == GDK_DRAG_PROTO_LOCAL)
return (GDK_DRAG_CONTEXT_PRIVATE_DATA (context))->local_selection;
else
return GDK_NONE;
}
|