aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/elementary/efl_ui_dnd.c
blob: c368beb0d10e59b3045edd2a409b18a42495bcf2 (plain) (blame)
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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED
#define ELM_INTERFACE_ATSPI_TEXT_PROTECTED
#define ELM_INTERFACE_ATSPI_TEXT_EDITABLE_PROTECTED
#define ELM_LAYOUT_PROTECTED

#define EFL_UI_SELECTION_MANAGER_BETA

#include <Elementary.h>
#include <Elementary_Cursor.h>
#include "elm_priv.h"

typedef struct _Efl_Ui_Dnd_Container_Data Efl_Ui_Dnd_Container_Data;
struct _Efl_Ui_Dnd_Container_Data
{
    unsigned int drag_delay_time;
};

extern int _wl_default_seat_id_get(Evas_Object *obj);
#ifdef HAVE_ELEMENTARY_WL2
Ecore_Wl2_Window *_wl_window_get(const Evas_Object *obj);
#endif

Eo*
_efl_ui_selection_manager_get(Eo *obj)
{
   if (!efl_isa(obj, EFL_UI_WIDGET_CLASS)) return NULL;
   Eo *app = efl_app_main_get(EFL_APP_CLASS);
   Eo *sel_man = efl_key_data_get(app, "__selection_manager");
   if (!sel_man)
     {
        sel_man = efl_add(EFL_UI_SELECTION_MANAGER_CLASS, app);
        efl_key_data_set(app, "__selection_manager", sel_man);
     }
   return sel_man;
}

void
_efl_ui_dnd_shutdown(void)
{
   Eo *app = efl_app_main_get(EFL_APP_CLASS);
   Eo *sel_man = efl_key_data_get(app, "__selection_manager");

   efl_del(sel_man);
}

EOLIAN static void
_efl_ui_dnd_drag_start(Eo *obj, void *pd EINA_UNUSED, Efl_Ui_Selection_Format format, Eina_Slice data,
                       Efl_Ui_Selection_Action action, void *icon_func_data, Efl_Dnd_Drag_Icon_Create icon_func, Eina_Free_Cb icon_func_free_cb,
                       unsigned int seat)
{
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   efl_ui_selection_manager_drag_start(sel_man, obj, format, data, action,
                                    icon_func_data, icon_func, icon_func_free_cb,
                                    seat);
}

EOLIAN static void
_efl_ui_dnd_drag_cancel(Eo *obj, void *pd EINA_UNUSED, unsigned int seat)
{
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   efl_ui_selection_manager_drag_cancel(sel_man, obj, seat);
}

EOLIAN static void
_efl_ui_dnd_drag_action_set(Eo *obj, void *pd EINA_UNUSED, Efl_Ui_Selection_Action action, unsigned int seat)
{
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   efl_ui_selection_manager_drag_action_set(sel_man, obj, action, seat);
}


EOLIAN static void
_efl_ui_dnd_drop_target_add(Eo *obj, void *pd EINA_UNUSED, Efl_Ui_Selection_Format format, unsigned int seat)
{
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   efl_ui_selection_manager_drop_target_add(sel_man, obj, format, seat);
}

EOLIAN static void
_efl_ui_dnd_drop_target_del(Eo *obj, void *pd EINA_UNUSED, Efl_Ui_Selection_Format format, unsigned int seat)
{
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   efl_ui_selection_manager_drop_target_del(sel_man, obj, format, seat);
}

EOLIAN static double
_efl_ui_dnd_container_drag_delay_time_get(const Eo *obj EINA_UNUSED, Efl_Ui_Dnd_Container_Data *pd)
{
    return pd->drag_delay_time;
}

EOLIAN static void
_efl_ui_dnd_container_drag_delay_time_set(Eo *obj EINA_UNUSED, Efl_Ui_Dnd_Container_Data *pd, double drag_delay_time)
{
    pd->drag_delay_time = drag_delay_time;
}

EOLIAN static void
_efl_ui_dnd_container_drag_item_add(Eo *obj, Efl_Ui_Dnd_Container_Data *pd,
                                    void *data_func_data, Efl_Dnd_Drag_Data_Get data_func, Eina_Free_Cb data_func_free_cb,
                                    void *item_func_data, Efl_Dnd_Item_Get item_func, Eina_Free_Cb item_func_free_cb,
                                    void *icon_func_data, Efl_Dnd_Drag_Icon_Create icon_func, Eina_Free_Cb icon_func_free_cb,
                                    void *icon_list_func_data, Efl_Dnd_Drag_Icon_List_Create icon_list_func, Eina_Free_Cb icon_list_func_free_cb,
                                    unsigned int seat)
{
   double drag_delay_time = pd->drag_delay_time;
   double anim_time = elm_config_drag_anim_duration_get();
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   efl_ui_selection_manager_container_drag_item_add(sel_man, obj, drag_delay_time, anim_time,
                                                 data_func_data, data_func, data_func_free_cb,
                                                 item_func_data, item_func, item_func_free_cb,
                                                 icon_func_data, icon_func, icon_func_free_cb,
                                                 icon_list_func_data, icon_list_func, icon_list_func_free_cb,
                                                 seat);
}

static void
_efl_ui_dnd_container_drag_item_del(Eo *obj, Efl_Ui_Dnd_Container_Data *pd EINA_UNUSED, unsigned int seat)
{
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   efl_ui_selection_manager_container_drag_item_del(sel_man, obj, seat);
}
EOLIAN static void
_efl_ui_dnd_container_drop_item_add(Eo *obj, Efl_Ui_Dnd_Container_Data *pd EINA_UNUSED,
                                    Efl_Ui_Selection_Format format,
                                    void *item_func_data, Efl_Dnd_Item_Get item_func, Eina_Free_Cb item_func_free_cb,
                                    unsigned int seat)
{
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   efl_ui_selection_manager_container_drop_item_add(sel_man, obj, format, item_func_data, item_func, item_func_free_cb, seat);
}

EOLIAN static void
_efl_ui_dnd_container_drop_item_del(Eo *obj, Efl_Ui_Dnd_Container_Data *pd EINA_UNUSED, unsigned int seat)
{
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   efl_ui_selection_manager_container_drop_item_del(sel_man, obj, seat);
}


///////////
typedef struct _Dnd_Icon_Create Dnd_Icon_Create;
typedef struct _Dnd_Drag_Pos Dnd_Drag_Pos;
typedef struct _Dnd_Drag_Accept Dnd_Drag_Accept;
typedef struct _Dnd_Drag_Done Dnd_Drag_Done;
typedef struct _Dnd_Drag_State Dnd_Drag_State;
typedef struct _Dnd_Drop Dnd_Drop;
typedef struct _Dnd_Cont_Drag_Pos Dnd_Cont_Drag_Pos;
typedef struct _Dnd_Cont_Drop Dnd_Cont_Drop;
typedef struct _Item_Container_Drag_Info Item_Container_Drag_Info;

struct _Dnd_Icon_Create
{
   void *icon_data;
   Elm_Drag_Icon_Create_Cb icon_cb;
};

struct _Dnd_Drag_Pos
{
   void *pos_data;
   Elm_Drag_Pos pos_cb;
};

struct _Dnd_Drag_Accept
{
   void *accept_data;
   Elm_Drag_Accept accept_cb;
};

struct _Dnd_Drag_Done
{
   void *done_data;
   Elm_Drag_State done_cb;

   //for deleting
   Dnd_Drag_Pos *pos;
   Dnd_Drag_Accept *accept;
};

struct _Dnd_Drag_State
{
   void *state_data;
   Elm_Drag_State state_cb;
};

struct _Dnd_Drop
{
   Efl_Object *obj;
   Elm_Sel_Format format;
   void *drop_data;
   Elm_Drop_Cb drop_cb;

   //for deleting
   Dnd_Drag_State *enter;
   Dnd_Drag_State *leave;
   Dnd_Drag_Pos *pos;
};

struct _Dnd_Cont_Drag_Pos
{
   void *pos_data;
   Elm_Drag_Item_Container_Pos pos_cb;
   Elm_Xy_Item_Get_Cb item_get_cb;
};

struct _Dnd_Cont_Drop
{
   Efl_Object *obj;
   Elm_Sel_Format format;
   void *drop_data;
   Elm_Drop_Item_Container_Cb drop_cb;
   Elm_Xy_Item_Get_Cb item_get_cb;

   //for deleting
   Dnd_Drag_State *enter;
   Dnd_Drag_State *leave;
   Dnd_Cont_Drag_Pos *pos;
};

struct _Item_Container_Drag_Info
{
   Elm_Drag_User_Info user_info;
   Elm_Object_Item *it;
   Elm_Item_Container_Data_Get_Cb data_get_cb;
   Elm_Xy_Item_Get_Cb item_get_cb;
};

static Efl_Object *
_dnd_icon_create_cb(void *data, Efl_Object *win, Efl_Object *drag_obj EINA_UNUSED, Eina_Position2D *pos_ret)
{
   Dnd_Icon_Create *ic = data;
   Efl_Object *ret = ic->icon_cb(ic->icon_data, win, &pos_ret->x, &pos_ret->y);

   free(ic);
   return ret;
}

static void
_dnd_drag_pos_cb(void *data, const Efl_Event *event)
{
   Dnd_Drag_Pos *pos = data;
   Efl_Dnd_Drag_Pos *ddata = event->info;

   if (pos->pos_cb)
     pos->pos_cb(pos->pos_data, event->object, ddata->pos.x, ddata->pos.y,
                 (Elm_Xdnd_Action)ddata->action);
}

static void
_dnd_drag_accept_cb(void *data, const Efl_Event *event)
{
   Dnd_Drag_Accept *accept = data;

   if (accept->accept_cb)
     accept->accept_cb(accept->accept_data, event->object, *(Eina_Bool *)event->info);
}

static void
_dnd_drag_done_cb(void *data, const Efl_Event *event)
{
   Dnd_Drag_Done *done = data;

   if (done->done_cb)
     done->done_cb(done->done_data, event->object);

   efl_event_callback_del(event->object, EFL_UI_DND_EVENT_DRAG_POS,
                          _dnd_drag_pos_cb, done->pos);
   efl_event_callback_del(event->object, EFL_UI_DND_EVENT_DRAG_ACCEPT,
                          _dnd_drag_accept_cb, done->accept);
   efl_event_callback_del(event->object, EFL_UI_DND_EVENT_DRAG_DONE,
                          _dnd_drag_done_cb, done);
   free(done->pos);
   free(done->accept);
   free(done);
}

static void
_dnd_drag_enter_leave_cb(void *data, const Efl_Event *event)
{
   Dnd_Drag_State *state = data;

   if (state->state_cb)
     state->state_cb(state->state_data, event->object);
}

static void
_dnd_drop_cb(void *data, const Efl_Event *event)
{
   Dnd_Drop *drop = data;
   Efl_Ui_Selection_Data *org_ddata = event->info;
   Elm_Selection_Data ddata;

   ddata.x = org_ddata->pos.x;
   ddata.y = org_ddata->pos.y;
   ddata.format = (Elm_Sel_Format)org_ddata->format;
   ddata.action = (Elm_Xdnd_Action)org_ddata->action;
   ddata.data = calloc(1, org_ddata->content.len);
   if (!ddata.data) return;
   ddata.data = memcpy(ddata.data, org_ddata->content.mem, org_ddata->content.len);
   ddata.len = org_ddata->content.len;
   if (drop->drop_cb)
     drop->drop_cb(drop->drop_data, event->object, &ddata);
   free(ddata.data);
}

EAPI Eina_Bool
elm_drag_start(Evas_Object *obj, Elm_Sel_Format format, const char *data,
               Elm_Xdnd_Action action,
               Elm_Drag_Icon_Create_Cb icon_create_cb, void *icon_create_data,
               Elm_Drag_Pos drag_pos_cb, void *drag_pos_data,
               Elm_Drag_Accept drag_accept_cb, void *drag_accept_data,
               Elm_Drag_State drag_done_cb, void *drag_done_data)
{
   if (!data) return EINA_FALSE;
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   int seatid = 1;
   Eina_Slice sl;
   Dnd_Drag_Pos *pos = calloc(1, sizeof(Dnd_Drag_Pos));
   Dnd_Drag_Accept *accept = calloc(1, sizeof(Dnd_Drag_Accept));
   Dnd_Drag_Done *done = calloc(1, sizeof(Dnd_Drag_Done));
   Dnd_Icon_Create *ic = calloc(1, sizeof(Dnd_Icon_Create));
   if (!pos || !accept || !done || !ic) goto on_error;

   pos->pos_data = drag_pos_data;
   pos->pos_cb = drag_pos_cb;

   accept->accept_data = drag_accept_data;
   accept->accept_cb = drag_accept_cb;

   done->done_data = drag_done_data;
   done->done_cb = drag_done_cb;
   done->pos = pos;
   done->accept = accept;

   efl_event_callback_add(obj, EFL_UI_DND_EVENT_DRAG_POS, _dnd_drag_pos_cb, pos);
   efl_event_callback_add(obj, EFL_UI_DND_EVENT_DRAG_ACCEPT, _dnd_drag_accept_cb, accept);
   efl_event_callback_add(obj, EFL_UI_DND_EVENT_DRAG_DONE, _dnd_drag_done_cb, done);
   sl.mem = data;
   sl.len = strlen(data);
#ifdef HAVE_ELEMENTARY_WL2
   if (_wl_window_get(obj)) seatid = _wl_default_seat_id_get(obj);
#endif

   ic->icon_data = icon_create_data;
   ic->icon_cb = icon_create_cb;
   efl_ui_selection_manager_drag_start(sel_man, obj, (Efl_Ui_Selection_Format)format, sl,
                                    (Efl_Ui_Selection_Action)action,
                                    ic, _dnd_icon_create_cb, NULL, seatid);

   return EINA_TRUE;

on_error:
   if (pos) free(pos);
   if (accept) free(accept);
   if (done) free(done);
   if (ic) free(ic);

   return EINA_FALSE;
}

EAPI Eina_Bool
elm_drag_action_set(Evas_Object *obj, Elm_Xdnd_Action action)
{
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   int seatid = 1;

#ifdef HAVE_ELEMENTARY_WL2
   if (_wl_window_get(obj)) seatid = _wl_default_seat_id_get(obj);
#endif
   efl_ui_selection_manager_drag_action_set(sel_man, obj, (Efl_Ui_Selection_Action)action, seatid);

   return EINA_TRUE;
}

EAPI Eina_Bool
elm_drag_cancel(Evas_Object *obj)
{
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   int seatid = 1;

#ifdef HAVE_ELEMENTARY_WL2
   if (_wl_window_get(obj)) seatid = _wl_default_seat_id_get(obj);
#endif

   efl_ui_selection_manager_drag_cancel(sel_man, obj, seatid);

   return EINA_TRUE;
}

static void
_drop_obj_del_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   Eina_List *drop_list;
   Dnd_Drop *drop;

   drop_list = efl_key_data_get(obj, "__drop_list");
   EINA_LIST_FREE(drop_list, drop)
     {
        efl_event_callback_del(drop->obj, EFL_UI_DND_EVENT_DRAG_ENTER,
                               _dnd_drag_enter_leave_cb, drop->enter);
        efl_event_callback_del(drop->obj, EFL_UI_DND_EVENT_DRAG_LEAVE,
                               _dnd_drag_enter_leave_cb, drop->leave);
        efl_event_callback_del(drop->obj, EFL_UI_DND_EVENT_DRAG_POS,
                               _dnd_drag_pos_cb, drop->pos);
        efl_event_callback_del(drop->obj, EFL_UI_DND_EVENT_DRAG_DROP,
                               _dnd_drop_cb, drop);
        free(drop->enter);
        free(drop->leave);
        free(drop->pos);
        free(drop);
     }
   efl_key_data_set(obj, "__drop_list", NULL);
}

EAPI Eina_Bool
elm_drop_target_add(Evas_Object *obj, Elm_Sel_Format format,
                    Elm_Drag_State enter_cb, void *enter_data,
                    Elm_Drag_State leave_cb, void *leave_data,
                    Elm_Drag_Pos pos_cb, void *pos_data,
                    Elm_Drop_Cb drop_cb, void *drop_data)
{
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   int seatid = 1;
   Dnd_Drag_State *enter, *leave;
   Dnd_Drag_Pos *pos;
   Dnd_Drop *drop;
   Eina_List *drop_list;

   enter = calloc(1, sizeof(Dnd_Drag_State));
   leave = calloc(1, sizeof(Dnd_Drag_State));
   pos = calloc(1, sizeof(Dnd_Drag_Pos));
   drop = calloc(1, sizeof(Dnd_Drop));
   if (!enter || !leave || !pos || !drop) goto on_error;
#ifdef HAVE_ELEMENTARY_WL2
   if (_wl_window_get(obj)) seatid = _wl_default_seat_id_get(obj);
#endif
   enter->state_cb = enter_cb;
   enter->state_data = enter_data;
   leave->state_cb = leave_cb;
   leave->state_data = leave_data;
   pos->pos_cb = pos_cb;
   pos->pos_data = pos_data;
   drop->obj = obj;
   drop->format = format;
   drop->drop_cb = drop_cb;
   drop->drop_data = drop_data;
   drop->enter = enter;
   drop->leave = leave;
   drop->pos = pos;

   drop_list = efl_key_data_get(obj, "__drop_list");
   drop_list = eina_list_append(drop_list, drop);
   efl_key_data_set(obj, "__drop_list", drop_list);
   evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
                                  _drop_obj_del_cb, NULL);
   efl_event_callback_add(obj, EFL_UI_DND_EVENT_DRAG_ENTER,
                          _dnd_drag_enter_leave_cb, enter);
   efl_event_callback_add(obj, EFL_UI_DND_EVENT_DRAG_LEAVE,
                          _dnd_drag_enter_leave_cb, leave);
   efl_event_callback_add(obj, EFL_UI_DND_EVENT_DRAG_POS,
                          _dnd_drag_pos_cb, pos);
   efl_event_callback_add(obj, EFL_UI_DND_EVENT_DRAG_DROP,
                          _dnd_drop_cb, drop);
   efl_ui_selection_manager_drop_target_add(sel_man, obj, (Efl_Ui_Selection_Format)format, seatid);

   return EINA_TRUE;

on_error:
   if (enter) free(enter);
   if (leave) free(leave);
   if (pos) free(pos);
   if (drop) free(drop);

   return EINA_FALSE;
}

EAPI Eina_Bool
elm_drop_target_del(Evas_Object *obj, Elm_Sel_Format format,
                    Elm_Drag_State enter_cb, void *enter_data,
                    Elm_Drag_State leave_cb, void *leave_data,
                    Elm_Drag_Pos pos_cb, void *pos_data,
                    Elm_Drop_Cb drop_cb, void *drop_data)
{
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   int seatid = 1;
   //Eina_List *l, *l2;
   Eina_List *drop_list;
   Dnd_Drop *drop;

#ifdef HAVE_ELEMENTARY_WL2
   if (_wl_window_get(obj)) seatid = _wl_default_seat_id_get(obj);
#endif

   drop_list = efl_key_data_get(obj, "__drop_list");
   drop = eina_list_data_get(drop_list);
   if (drop &&
       (drop->format == format) &&
       (drop->enter->state_cb == enter_cb) &&
       (drop->enter->state_data == enter_data) &&
       (drop->leave->state_cb == leave_cb) &&
       (drop->leave->state_data == leave_data) &&
       (drop->pos->pos_cb == pos_cb) &&
       (drop->pos->pos_data == pos_data) &&
       (drop->drop_cb == drop_cb) &&
       (drop->drop_data == drop_data))
     {
        drop_list = eina_list_remove(drop_list, drop);
        efl_key_data_set(obj, "__drop_list", drop_list);
        evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL, _drop_obj_del_cb);
        efl_event_callback_del(drop->obj, EFL_UI_DND_EVENT_DRAG_ENTER,
                               _dnd_drag_enter_leave_cb, drop->enter);
        efl_event_callback_del(drop->obj, EFL_UI_DND_EVENT_DRAG_LEAVE,
                               _dnd_drag_enter_leave_cb, drop->leave);
        efl_event_callback_del(drop->obj, EFL_UI_DND_EVENT_DRAG_POS,
                               _dnd_drag_pos_cb, drop->pos);
        efl_event_callback_del(drop->obj, EFL_UI_DND_EVENT_DRAG_DROP,
                               _dnd_drop_cb, drop);
        free(drop->enter);
        free(drop->leave);
        free(drop->pos);
        free(drop);
     }
   efl_ui_selection_manager_drop_target_del(sel_man, obj, (Efl_Ui_Selection_Format)format, seatid);

   return EINA_TRUE;
}

static Efl_Object *
_dnd_item_func(void *data, Efl_Canvas_Object *item, Eina_Position2D pos, Eina_Position2D *pos_ret)
{
   Elm_Xy_Item_Get_Cb item_get_cb = data;
   Evas_Coord x, y;
   Efl_Object *obj = NULL;

   x = y = 0;
   if (item_get_cb)
     obj = item_get_cb(item, pos.x, pos.y, &x, &y);
   if (pos_ret)
     {
        pos_ret->x = x;
        pos_ret->y = y;
     }

   return obj;
}

static void
_dnd_cont_drag_pos_cb(void *data, const Efl_Event *event)
{
   Dnd_Cont_Drag_Pos *pos = data;
   Efl_Dnd_Drag_Pos *ddata = event->info;
   Evas_Coord xret = 0, yret = 0;

   if (pos->item_get_cb)
     {
        Evas_Coord x, y;
        evas_object_geometry_get(event->object, &x, &y, NULL, NULL);
        pos->item_get_cb(event->object, ddata->pos.x + x, ddata->pos.y + y,
                         &xret, &yret);
     }
   if (pos->pos_cb)
     pos->pos_cb(pos->pos_data, event->object, ddata->item, ddata->pos.x, ddata->pos.y,
                 xret, yret, (Elm_Xdnd_Action)ddata->action);
}

static void
_dnd_cont_drop_cb(void *data, const Efl_Event *event)
{
   Dnd_Cont_Drop *drop = data;
   Efl_Ui_Selection_Data *org_ddata = event->info;
   Elm_Selection_Data ddata;
   Evas_Coord xret = 0, yret = 0;

   ddata.x = org_ddata->pos.x;
   ddata.y = org_ddata->pos.y;
   ddata.format = (Elm_Sel_Format)org_ddata->format;
   ddata.action = (Elm_Xdnd_Action)org_ddata->action;
   ddata.data = calloc(1, org_ddata->content.len);
   if (!ddata.data) return;
   ddata.data = memcpy(ddata.data, org_ddata->content.mem, org_ddata->content.len);
   ddata.len = org_ddata->content.len;

   if (drop->item_get_cb)
     {
        Evas_Coord x, y;
        evas_object_geometry_get(event->object, &x, &y, NULL, NULL);
        drop->item_get_cb(event->object, ddata.x + x, ddata.y + y,
                          &xret, &yret);
     }

   if (drop->drop_cb)
     drop->drop_cb(drop->drop_data, event->object, org_ddata->item,
                   &ddata, xret, yret);
   free(ddata.data);
}

static void
_cont_drop_free_data(Evas_Object *obj)
{
   Eina_List *cont_drop_list;
   Dnd_Cont_Drop *drop;

   cont_drop_list = efl_key_data_get(obj, "__cont_drop_item");
   drop = eina_list_data_get(cont_drop_list);
   if (drop)
     {
        efl_event_callback_del(drop->obj, EFL_UI_DND_EVENT_DRAG_ENTER,
                               _dnd_drag_enter_leave_cb, drop->enter);
        efl_event_callback_del(drop->obj, EFL_UI_DND_EVENT_DRAG_LEAVE,
                               _dnd_drag_enter_leave_cb, drop->leave);
        efl_event_callback_del(drop->obj, EFL_UI_DND_EVENT_DRAG_POS,
                               _dnd_cont_drag_pos_cb, drop->pos);
        efl_event_callback_del(drop->obj, EFL_UI_DND_EVENT_DRAG_DROP,
                               _dnd_cont_drop_cb, drop);
        free(drop->enter);
        free(drop->leave);
        free(drop->pos);
        cont_drop_list = eina_list_remove(cont_drop_list, drop);
        efl_key_data_set(obj, "__cont_drop_item", cont_drop_list);
        free(drop);
     }
}

static void
_cont_drop_obj_del_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *info EINA_UNUSED)
{
   _cont_drop_free_data(obj);
}

EAPI Eina_Bool
elm_drop_item_container_add(Evas_Object *obj,
                            Elm_Sel_Format format,
                            Elm_Xy_Item_Get_Cb item_get_cb,
                            Elm_Drag_State enter_cb, void *enter_data,
                            Elm_Drag_State leave_cb, void *leave_data,
                            Elm_Drag_Item_Container_Pos pos_cb, void *pos_data,
                            Elm_Drop_Item_Container_Cb drop_cb, void *drop_data)
{
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   int seatid = 1;
   Dnd_Drag_State *enter = NULL, *leave = NULL;
   Dnd_Cont_Drag_Pos *pos = NULL;
   Dnd_Cont_Drop *drop = NULL;
   Eina_List *cont_drop_list;

   enter = calloc(1, sizeof(Dnd_Drag_State));
   leave = calloc(1, sizeof(Dnd_Drag_State));
   pos = calloc(1, sizeof(Dnd_Cont_Drag_Pos));
   drop = calloc(1, sizeof(Dnd_Cont_Drop));
   if (!enter || !leave || !pos || !drop) goto on_error;
#ifdef HAVE_ELEMENTARY_WL2
   if (_wl_window_get(obj)) seatid = _wl_default_seat_id_get(obj);
#endif

   enter->state_cb = enter_cb;
   enter->state_data = enter_data;
   leave->state_cb = leave_cb;
   leave->state_data = leave_data;
   pos->pos_cb = pos_cb;
   pos->pos_data = pos_data;
   pos->item_get_cb = item_get_cb;
   drop->obj = obj;
   drop->format = format;
   drop->drop_cb = drop_cb;
   drop->drop_data = drop_data;
   drop->enter = enter;
   drop->leave = leave;
   drop->pos = pos;

   cont_drop_list = efl_key_data_get(obj, "__cont_drop_item");
   cont_drop_list = eina_list_append(cont_drop_list, drop);
   efl_key_data_set(obj, "__cont_drop_item", cont_drop_list);
   evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
                                  _cont_drop_obj_del_cb, NULL);
   efl_event_callback_add(obj, EFL_UI_DND_EVENT_DRAG_ENTER,
                          _dnd_drag_enter_leave_cb, enter);
   efl_event_callback_add(obj, EFL_UI_DND_EVENT_DRAG_LEAVE,
                          _dnd_drag_enter_leave_cb, leave);
   efl_event_callback_add(obj, EFL_UI_DND_EVENT_DRAG_POS,
                          _dnd_cont_drag_pos_cb, pos);
   efl_event_callback_add(obj, EFL_UI_DND_EVENT_DRAG_DROP,
                          _dnd_cont_drop_cb, drop);
   efl_ui_selection_manager_container_drop_item_add(sel_man, obj, (Efl_Ui_Selection_Format)format,
                                                 item_get_cb, _dnd_item_func, NULL,
                                                 seatid);

   return EINA_TRUE;

on_error:
   if (enter) free(enter);
   if (leave) free(leave);
   if (pos) free(pos);
   if (drop) free(drop);

   return EINA_FALSE;
}

EAPI Eina_Bool
elm_drop_item_container_del(Evas_Object *obj)
{
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   int seatid = 1;

#ifdef HAVE_ELEMENTARY_WL2
   if (_wl_window_get(obj)) seatid = _wl_default_seat_id_get(obj);
#endif

   _cont_drop_free_data(obj);
   evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL, _cont_drop_obj_del_cb);
   efl_ui_selection_manager_container_drop_item_del(sel_man, obj, seatid);

   return EINA_TRUE;
}

static void
_cont_drag_data_func(void *data, Efl_Object *obj, Efl_Ui_Selection_Format *format,
                     Eina_Rw_Slice *drag_data, Efl_Ui_Selection_Action *action)
{
   Item_Container_Drag_Info *di;

   di = data;
   if (!di) return;
   di->data_get_cb(obj, di->it, &di->user_info);
   if (format) *format = (Efl_Ui_Selection_Format)di->user_info.format;
   if (drag_data)
     {
        if (di->user_info.data)
          {
             drag_data->mem = (void *)di->user_info.data;
             drag_data->len = strlen(di->user_info.data);
          }
     }
   if (action) *action = (Efl_Ui_Selection_Action)di->user_info.action;
}

static Eina_List *
_cont_drag_icon_list_create(void *data, Efl_Object *obj EINA_UNUSED)
{
   Item_Container_Drag_Info *di;

   di = data;
   return di->user_info.icons;
}

static Efl_Object *
_cont_drag_icon_create(void *data, Efl_Object *win, Efl_Object *drag_obj EINA_UNUSED, Eina_Position2D *pos_ret)
{
   Item_Container_Drag_Info *di;
   Elm_Object_Item *it = NULL;

   di = data;
   if (!di) return NULL;
   if (!di->user_info.createicon) return NULL;
   it = di->user_info.createicon(di->user_info.createdata, win, &pos_ret->x, &pos_ret->y);
   di->it = it;
   return it;
}

static Efl_Object *
_cont_drag_item_func(void *data, Efl_Canvas_Object *item, Eina_Position2D pos, Eina_Position2D *pos_ret)
{
   Item_Container_Drag_Info *di = data;
   Evas_Coord x, y;
   Efl_Object *obj = NULL;

   x = y = 0;
   if (di->item_get_cb)
     obj = di->item_get_cb(item, pos.x, pos.y, &x, &y);
   if (pos_ret)
     {
        pos_ret->x = x;
        pos_ret->y = y;
     }
   di->it = obj;

   return obj;
}

static void
_cont_drag_free_data(Evas_Object *obj)
{
   Eina_List *di_list;
   Item_Container_Drag_Info *di;

   di_list = efl_key_data_get(obj, "__cont_drag_item");
   di = eina_list_data_get(di_list);
   di_list = eina_list_remove(di_list, di);
   efl_key_data_set(obj, "__cont_drag_item", di_list);
   free(di);
}

static void
_cont_drag_obj_del_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *event EINA_UNUSED)
{
   _cont_drag_free_data(obj);
}

EAPI Eina_Bool
elm_drag_item_container_add(Evas_Object *obj, double anim_tm, double tm_to_drag,
                            Elm_Xy_Item_Get_Cb item_get_cb, Elm_Item_Container_Data_Get_Cb data_get_cb)
{
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   int seatid = 1;
   Eina_List *di_list;
   Item_Container_Drag_Info *di;

#ifdef HAVE_ELEMENTARY_WL2
   if (_wl_window_get(obj)) seatid = _wl_default_seat_id_get(obj);
#endif

   di = calloc(1, sizeof(Item_Container_Drag_Info));
   if (!di) return EINA_FALSE;
   di->data_get_cb = data_get_cb;
   di->item_get_cb = item_get_cb;
   di_list = efl_key_data_get(obj, "__cont_drag_item");
   di_list = eina_list_append(di_list, di);
   efl_key_data_set(obj, "__cont_drag_item", di_list);
   evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _cont_drag_obj_del_cb, NULL);
   efl_ui_selection_manager_container_drag_item_add(sel_man, obj, anim_tm, tm_to_drag,
                                                 di, _cont_drag_data_func, NULL,
                                                 di, _cont_drag_item_func, NULL,
                                                 di, _cont_drag_icon_create, NULL,
                                                 di, _cont_drag_icon_list_create, NULL,
                                                 seatid);
   return EINA_TRUE;
}

EAPI Eina_Bool
elm_drag_item_container_del(Evas_Object *obj)
{
   Eo *sel_man = _efl_ui_selection_manager_get(obj);
   int seatid = 1;

#ifdef HAVE_ELEMENTARY_WL2
   if (_wl_window_get(obj)) seatid = _wl_default_seat_id_get(obj);
#endif

   _cont_drag_free_data(obj);
   evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL, _cont_drag_obj_del_cb);
   efl_ui_selection_manager_container_drag_item_del(sel_man, obj, seatid);

   return EINA_TRUE;
}

#include "efl_ui_dnd.eo.c"
#include "efl_ui_dnd_container.eo.c"