yakov pushed a commit to branch master. http://git.enlightenment.org/tools/erigo.git/commit/?id=bd92ca28bcf2bfc981b41193949334ef254fbb55
commit bd92ca28bcf2bfc981b41193949334ef254fbb55 Author: Yakov Goldberg <[email protected]> Date: Thu Nov 5 19:06:10 2015 +0200 Properly handle object dragging inside its parent --- src/bin/gui/dnd.c | 19 +++++++++++++------ src/bin/gui/dnd.h | 2 +- src/bin/gui/editor.c | 24 +++++++++++++++--------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/bin/gui/dnd.c b/src/bin/gui/dnd.c index 8943fee..92479ee 100644 --- a/src/bin/gui/dnd.c +++ b/src/bin/gui/dnd.c @@ -27,7 +27,7 @@ typedef struct Eo *drag_window_obj_wref; Eina_Bool drag_accept; - void (*dragdone_post_cb)(Eina_Bool accept, const Eo *wdg_eo); + void (*dragdone_post_cb)(Eina_Bool accept, const Eo *wdg_eo, const Gui_Widget * drag_start_wdg); } Drag_Info; /* Information about Drop Target*/ @@ -63,9 +63,10 @@ typedef struct Drag_Info *drag_info; Eina_Bool canvas_is_source; char *_drag_data; /*Allocated on drag_start and deleted in dragdone*/ + const Gui_Widget *drag_start_wdg; } _Drag_Info_Global; -static _Drag_Info_Global _drag_info_global = {NULL, EINA_FALSE, NULL}; +static _Drag_Info_Global _drag_info_global = {NULL, EINA_FALSE, NULL, NULL}; static Ecore_Timer *_drag_factory_timer = NULL; @@ -163,7 +164,7 @@ _dragdone(void *data, Evas_Object *obj EINA_UNUSED) { if (di->dragdone_post_cb) { - di->dragdone_post_cb(di->drag_accept, di->obj); + di->dragdone_post_cb(di->drag_accept, di->obj, _drag_info_global.drag_start_wdg); } } @@ -175,6 +176,7 @@ _dragdone(void *data, Evas_Object *obj EINA_UNUSED) { _drag_info_global.canvas_is_source = EINA_FALSE; } + _drag_info_global.drag_start_wdg = NULL; } /* This callback is called only for a window object. @@ -247,6 +249,7 @@ _dropcb(void *data, Evas_Object *obj, Elm_Selection_Data *ev) _drag_info_global.canvas_is_source = EINA_FALSE; _drop_info_global._enter_leave_counter = 0; + _drag_info_global.drag_start_wdg = NULL; _drop_data_free(); return EINA_TRUE; } @@ -484,6 +487,7 @@ _drag_start_from_factory(void *data) _drag_factory_timer = NULL; _drag_info_global.drag_info = di; _drag_info_global.canvas_is_source = EINA_FALSE; + _drag_info_global.drag_start_wdg = NULL; char *wdg_data = json_widget_generate(di->wdg_id); _drag_info_global._drag_data = wdg_data; @@ -546,7 +550,7 @@ drag_add(Eo *obj, const char *image_path, Eid *wdg_id) /* Function to start dragging, when mouse down/up are handled outside. * Dragging widgets on canvas */ void -drag_start(Eo *obj, Eid *wdg_id, void (*_drag_start_post_cb)(const Gui_Widget *, const Eo *), void (*_dragdone_post_cb)(Eina_Bool accept, const Eo *)) +drag_start(Eo *obj, Eid *wdg_id, void (*_drag_start_post_cb)(const Gui_Widget *, const Eo *), void (*_dragdone_post_cb)(Eina_Bool accept, const Eo *, const Gui_Widget *)) { Drag_Info *di = calloc(1, sizeof(Drag_Info)); di->image_path = NULL; @@ -556,6 +560,7 @@ drag_start(Eo *obj, Eid *wdg_id, void (*_drag_start_post_cb)(const Gui_Widget *, _drag_info_global.drag_info = di; _drag_info_global.canvas_is_source = EINA_TRUE; + _drag_info_global.drag_start_wdg = wdg_main_wdg_get(wdg_get(wdg_id)); Eo *drag_object = obj; @@ -727,6 +732,7 @@ _drag_item_container_dragstart_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_ di->wdg_id = wdg_eid_get(wdg); _drag_info_global.drag_info = di; _drag_info_global.canvas_is_source = EINA_TRUE; + _drag_info_global.drag_start_wdg = wdg_main_wdg_get(wdg); if (_dici && _dici->dragstart) { @@ -735,17 +741,18 @@ _drag_item_container_dragstart_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_ } static void -_drag_item_container_dragdone_cb(void *data, Evas_Object *obj, Eina_Bool accepted) +_drag_item_container_dragdone_cb(void *data EINA_UNUSED, Evas_Object *obj, Eina_Bool accepted) { _Drag_Item_Container_Info *_dici = NULL; eo_do(obj, _dici = eo_key_data_get(DRAG_ITEM_CONTAINER_INFO)); if (_dici && _dici->dragdone) { - _dici->dragdone(data, obj, accepted); + _dici->dragdone((void *)_drag_info_global.drag_start_wdg, obj, accepted); } /* if dropping outside, NULL this pointer*/ if (!dnd_is_destination()) _drag_info_global.canvas_is_source = EINA_FALSE; + _drag_info_global.drag_start_wdg = NULL; } static Eina_Bool diff --git a/src/bin/gui/dnd.h b/src/bin/gui/dnd.h index d618368..3ff5fe1 100644 --- a/src/bin/gui/dnd.h +++ b/src/bin/gui/dnd.h @@ -5,7 +5,7 @@ void drag_add(Eo *obj, const char *image_path, Eid *wdg_id); void -drag_start(Eo *obj, Eid *wdg_id, void (*_post_cb)(const Gui_Widget *, const Eo *), void (*_dragdone_post_cb)(Eina_Bool accept, const Eo *wdg_eo)); +drag_start(Eo *obj, Eid *wdg_id, void (*_post_cb)(const Gui_Widget *, const Eo *), void (*_dragdone_post_cb)(Eina_Bool accept, const Eo *wdg_eo, const Gui_Widget *drag_start_wdg)); void drop_target_wdg_set(Gui_Widget *wdg, Eo *obj, diff --git a/src/bin/gui/editor.c b/src/bin/gui/editor.c index 88a7e68..897a9bd 100644 --- a/src/bin/gui/editor.c +++ b/src/bin/gui/editor.c @@ -522,11 +522,11 @@ _drag_widget_iterate(Gui_Widget **drag_candidate, const Gui_Session *session, Ev _drag_widget_iterate(drag_candidate, session, x, y); } -void +static void _drag_start_post_cb(const Gui_Widget *wdg, const Eo *_wdg_eo); static void -_dragdone_post_cb(Eina_Bool accept, const Eo *wdg_eo); +_dragdone_post_cb(Eina_Bool accept, const Eo *wdg_eo, const Gui_Widget *drag_start_wdg); static Ecore_Timer *_drag_timer_start = NULL; static Eina_Bool drag_started = EINA_FALSE; @@ -1986,13 +1986,14 @@ static void _objtree_drag_start_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED) { Gui_Widget *wdg = data; - _drag_start_post_cb(wdg, NULL); + const Gui_Session *session = gui_context_editor_session_get(wdg_context_get(wdg)); + _drag_start_post_cb(wdg, session_eo_get(session, wdg)); } static void -_objtree_dragdone_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, Eina_Bool accepted) +_objtree_dragdone_cb(void *data, Evas_Object *obj EINA_UNUSED, Eina_Bool accepted) { - _dragdone_post_cb(accepted, NULL); + _dragdone_post_cb(accepted, NULL, data); } static void @@ -2327,10 +2328,10 @@ _drag_start_post_cb(const Gui_Widget *wdg, const Eo *_wdg_eo) } else { + /* If we dragging around window where drag started, use original Eo object, + * t.e. not create eo_cur in _drop_target_pos() func. */ DnD_Main_Obj_Info *di = wdg_data_get(wdg_main_wdg_get(wdg), EDITOR_DND_DATA); - /* If we dragging around window where drag started, use real object. - * Use weak ref, to automatically NULL this pointer if object dropped into other place. */ - eo_do(wdg_eo, eo_wref_add(&(di->eo_cur))); + di->eo_cur = wdg_eo; } /* Unpack Eo object if dragging from container. */ @@ -2376,7 +2377,7 @@ __undo_no_update(const Gui_Context *ctx); /* This callback is added only for dragging of objects on canvas. */ static void -_dragdone_post_cb(Eina_Bool accept, const Eo *wdg_eo) +_dragdone_post_cb(Eina_Bool accept, const Eo *wdg_eo, const Gui_Widget *drag_start_wdg) { const Gui_Widget *drag_wdg = dnd_drag_wdg_get(); if (!drag_wdg) return; @@ -2442,6 +2443,11 @@ _dragdone_post_cb(Eina_Bool accept, const Eo *wdg_eo) Eo *fr = main_wdg_info_frame_get(wi); eo_do(fr, efl_gfx_visible_set(EINA_TRUE)); } + if (drag_start_wdg) + { + DnD_Main_Obj_Info *di = wdg_data_get(wdg_main_wdg_get(drag_start_wdg), EDITOR_DND_DATA); + di->eo_cur = NULL; + } } static Eina_Bool --
