yakov pushed a commit to branch master. http://git.enlightenment.org/tools/erigo.git/commit/?id=b6be9b68c979d85319c1fd75ffa4fe79b759fa02
commit b6be9b68c979d85319c1fd75ffa4fe79b759fa02 Author: Yakov Goldberg <yako...@samsung.com> Date: Wed Nov 11 13:42:46 2015 +0200 Refactoring drag data --- src/bin/gui/dnd.c | 180 ++++++++++++++++++++++----------------------------- src/bin/gui/editor.c | 4 +- 2 files changed, 81 insertions(+), 103 deletions(-) diff --git a/src/bin/gui/dnd.c b/src/bin/gui/dnd.c index 7061c23..4b816f5 100644 --- a/src/bin/gui/dnd.c +++ b/src/bin/gui/dnd.c @@ -31,11 +31,9 @@ typedef struct Eid *wdg_id; /*Widget id*/ char *image_path; /* image for DnD icon. */ Eo *obj; /*object, where drag starts. Used to call cb on delete. */ - Eo *drag_window_obj; +} Factory_Drag_Info; - Eina_Bool drag_accept; - void (*dragdone_post_cb)(Eina_Bool accept, const Eo *wdg_eo, const Gui_Widget * drag_start_wdg); -} Drag_Info; +Factory_Drag_Info _wdg_drag = {NULL, NULL, NULL}; /* Information about Drop Target*/ typedef struct @@ -67,16 +65,35 @@ static _Drop_Info_Global _drop_info_global = {0, NULL, EINA_FALSE}; /* Structure to keed data about current Drag event. */ typedef struct { - Drag_Info *drag_info; Eina_Bool canvas_is_source; + Eina_Bool drag_accept; char *_drag_data; /*Allocated on drag_start and deleted in dragdone*/ const Gui_Widget *drag_start_wdg; + void (*_wdg_dragdone_post_cb)(Eina_Bool accept, const Eo *wdg_eo, const Gui_Widget * drag_start_wdg); + Eo *drag_window_obj; + + Eid *wdg_id; /*Widget id*/ + Eo *obj; /*object, where drag starts. Used to call cb on delete. */ } _Drag_Info_Global; -static _Drag_Info_Global _drag_info_global = {NULL, EINA_FALSE, NULL, NULL}; +static _Drag_Info_Global _drag_info_global = {EINA_FALSE, EINA_FALSE, NULL, NULL, NULL, NULL, NULL, NULL}; static Ecore_Timer *_drag_factory_timer = NULL; +static inline void +_drag_info_global_null() +{ + if (_drag_info_global._drag_data) free(_drag_info_global._drag_data); + _drag_info_global.canvas_is_source = EINA_FALSE; + _drag_info_global.drag_accept = EINA_FALSE; + _drag_info_global._drag_data = NULL; + _drag_info_global.drag_start_wdg = NULL; + _drag_info_global._wdg_dragdone_post_cb = NULL; + _drag_info_global.drag_window_obj = NULL; + _drag_info_global.wdg_id = NULL; + _drag_info_global.obj = NULL; +} + static void _drop_data_free() { @@ -119,8 +136,8 @@ dnd_drop_data_get() void dnd_drag_window_object_visibility_set(Eina_Bool visibility) { - if (_drag_info_global.drag_info) - eo_do(_drag_info_global.drag_info->drag_window_obj, efl_gfx_visible_set(visibility)); + if (_drag_info_global.drag_window_obj) + eo_do(_drag_info_global.drag_window_obj, efl_gfx_visible_set(visibility)); } Eina_Bool @@ -139,7 +156,7 @@ const Gui_Widget * dnd_drag_wdg_get() { if (_drag_info_global.canvas_is_source) - return wdg_get(_drag_info_global.drag_info->wdg_id); + return wdg_get(_drag_info_global.wdg_id); return NULL; } @@ -150,45 +167,26 @@ _dragpos(void *data EINA_UNUSED, Eo * obj EINA_UNUSED, Evas_Coord x EINA_UNUSED, } static void -_dragaccept(void *data, Evas_Object *obj EINA_UNUSED, Eina_Bool doaccept) +_dragaccept(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, Eina_Bool doaccept) { -// ERR("accept: %d; %s", doaccept, (char *) data); - Drag_Info *di = data; - if (di) - { - if (di->drag_accept != doaccept) dnd_debug("In %d", doaccept); - di->drag_accept = doaccept; - } + if (_drag_info_global.drag_accept != doaccept) dnd_debug("In %d", doaccept); + _drag_info_global.drag_accept = doaccept; } -static Eina_Bool -_drag_data_free(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED); - static void -_dragdone(void *data, Evas_Object *obj EINA_UNUSED) +_dragdone(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED) { dnd_debug("In"); - if (_drag_info_global._drag_data) free(_drag_info_global._drag_data); - _drag_info_global._drag_data = NULL; - Drag_Info *di = data; - if (di) + if (_drag_info_global.canvas_is_source) { - if (di->dragdone_post_cb) - { - di->dragdone_post_cb(di->drag_accept, di->obj, _drag_info_global.drag_start_wdg); - } + _drag_info_global._wdg_dragdone_post_cb(_drag_info_global.drag_accept, _drag_info_global.obj, _drag_info_global.drag_start_wdg); } - /* if dropping outside, NULL this pointer*/ - if (_drag_info_global.canvas_is_source) - _drag_data_free(_drag_info_global.drag_info, NULL, NULL, NULL); - if (!dnd_is_destination()) { - _drag_info_global.canvas_is_source = EINA_FALSE; + _drag_info_global_null(); } - _drag_info_global.drag_start_wdg = NULL; } /* This callback is called only for a window object. @@ -261,10 +259,10 @@ _dropcb(void *data, Evas_Object *obj, Elm_Selection_Data *ev) if (ti->drop_target_drop) ti->drop_target_drop(ti->dropdata, obj, ev); - _drag_info_global.canvas_is_source = EINA_FALSE; + + _drag_info_global_null(); _drop_info_global._enter_leave_counter = 0; - _drag_info_global.drag_start_wdg = NULL; _drop_data_free(); return EINA_TRUE; } @@ -405,16 +403,16 @@ _droppos(void *data, Eo *obj, Evas_Coord x, Evas_Coord y, Elm_Xdnd_Action action static Evas_Object * _drag_factory_image_icon_create(void *data, Evas_Object *parent, Evas_Coord *xoff, Evas_Coord *yoff) { - Drag_Info *di = data; + Factory_Drag_Info *fdi = data; Evas_Object *ic = NULL; Evas_Coord xm, ym; ic = elm_image_add(parent); - elm_image_file_set(ic, di->image_path, NULL); + elm_image_file_set(ic, fdi->image_path, NULL); evas_object_resize(ic, 40, 40); evas_object_show(ic); - evas_pointer_canvas_xy_get(evas_object_evas_get(di->obj), &xm, &ym); + evas_pointer_canvas_xy_get(evas_object_evas_get(fdi->obj), &xm, &ym); if (xoff) *xoff = xm - 30; if (yoff) *yoff = ym - 30; @@ -425,16 +423,16 @@ _drag_factory_image_icon_create(void *data, Evas_Object *parent, Evas_Coord *xof static Evas_Object * _drag_factory_real_object_create(void *data, Evas_Object *parent, Evas_Coord *xoff, Evas_Coord *yoff) { - Drag_Info *di = data; + Factory_Drag_Info *fdi = data; Evas_Coord xc, yc; - evas_pointer_canvas_xy_get(evas_object_evas_get(di->obj), &xc, &yc); + evas_pointer_canvas_xy_get(evas_object_evas_get(fdi->obj), &xc, &yc); if (xoff) *xoff = xc; if (yoff) *yoff = yc; Gui_Session *tmp_session = session_new(MODE_SIMULATOR, EINA_TRUE); - Eo *o = simulator_widget_create(tmp_session, wdg_get(di->wdg_id), parent); - di->drag_window_obj = o; + Eo *o = simulator_widget_create(tmp_session, wdg_get(fdi->wdg_id), parent); + _drag_info_global.drag_window_obj = o; return o; } @@ -468,9 +466,8 @@ dnd_drag_obj_create(const Gui_Widget *dragged_wdg, Eo *parent) } static Evas_Object * -_drag_widget_object_create(void *data, Evas_Object *parent, Evas_Coord *xoff, Evas_Coord *yoff) +_drag_widget_object_create(void *data EINA_UNUSED, Evas_Object *parent, Evas_Coord *xoff, Evas_Coord *yoff) { - Drag_Info *di = data; Evas_Object *ic = NULL; Evas_Coord cur_x_global, cur_y_global; /* Cursor coords in global Evas (editor) */ @@ -482,8 +479,8 @@ _drag_widget_object_create(void *data, Evas_Object *parent, Evas_Coord *xoff, Ev if (xoff) *xoff = cur_x_global; if (yoff) *yoff = cur_y_global; - ic = dnd_drag_obj_create(wdg_get(di->wdg_id), parent); - di->drag_window_obj = ic; + ic = dnd_drag_obj_create(wdg_get(_drag_info_global.wdg_id), parent); + _drag_info_global.drag_window_obj = ic; return ic; } @@ -491,22 +488,20 @@ static Eina_Bool _drag_start_from_factory(void *data) { dnd_debug("In"); - Drag_Info *di = data; + Factory_Drag_Info *fdi = data; Evas_Object *(*image_create_icon_f)(void *data, Evas_Object *parent, Evas_Coord *xoff, Evas_Coord *yoff) = NULL; - image_create_icon_f = (di->image_path) ? _drag_factory_image_icon_create : _drag_factory_real_object_create; + image_create_icon_f = (fdi->image_path) ? _drag_factory_image_icon_create : _drag_factory_real_object_create; _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; + _drag_info_global_null(); - char *wdg_data = json_widget_generate(di->wdg_id); + char *wdg_data = json_widget_generate(fdi->wdg_id); dnd_debug("Data %s", wdg_data); _drag_info_global._drag_data = wdg_data; - elm_drag_start(di->obj, ELM_SEL_FORMAT_TEXT, + elm_drag_start(fdi->obj, ELM_SEL_FORMAT_TEXT, wdg_data, ELM_XDND_ACTION_COPY, - image_create_icon_f, di, + image_create_icon_f, fdi, _dragpos, NULL, _dragaccept, NULL, _dragdone, NULL); @@ -528,22 +523,22 @@ _factory_drag_mouse_up(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Descripti static Eina_Bool _factory_drag_mouse_down(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) { - Drag_Info *di = data; + Factory_Drag_Info *fdi = data; eo_do(obj, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_UP, _factory_drag_mouse_up, NULL)); ecore_timer_del(_drag_factory_timer); - _drag_factory_timer = ecore_timer_add(TIME_TO_DRAG, _drag_start_from_factory, di); + _drag_factory_timer = ecore_timer_add(TIME_TO_DRAG, _drag_start_from_factory, fdi); return EO_CALLBACK_CONTINUE; } static Eina_Bool -_drag_data_free(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) +_factory_drag_info_free(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) { dnd_debug("In"); - Drag_Info *di = data; - if (di->image_path) free(di->image_path); - free(di); - _drag_info_global.drag_info = NULL; + Factory_Drag_Info *fdi = data; + if (fdi->image_path) free(fdi->image_path); + free(fdi); + _drag_info_global_null(); return EO_CALLBACK_CONTINUE; } @@ -552,38 +547,35 @@ _drag_data_free(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *des void drag_add(Eo *obj, const char *image_path, Eid *wdg_id) { - Drag_Info *di = calloc(1, sizeof(Drag_Info)); + Factory_Drag_Info *fdi = calloc(1, sizeof(Factory_Drag_Info)); if (image_path) - di->image_path = strdup(image_path); - di->wdg_id = wdg_id; - di->obj = obj; - eo_do(obj, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_DOWN, _factory_drag_mouse_down, di)); - eo_do(obj, eo_event_callback_add(EVAS_OBJECT_EVENT_DEL, _drag_data_free, di)); + fdi->image_path = strdup(image_path); + fdi->wdg_id = wdg_id; + fdi->obj = obj; + eo_do(obj, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_DOWN, _factory_drag_mouse_down, fdi)); + eo_do(obj, eo_event_callback_add(EVAS_OBJECT_EVENT_DEL, _factory_drag_info_free, fdi)); } /* Function to start dragging, when mouse down/up are handled outside. * Dragging widgets on canvas */ void -drag_start(Eo *obj, Eid *wdg_id, void (*_dragdone_post_cb)(Eina_Bool accept, const Eo *, const Gui_Widget *)) +drag_start(Eo *obj, Eid *wdg_id, void (*_wdg_dragdone_post_cb)(Eina_Bool accept, const Eo *, const Gui_Widget *)) { - Drag_Info *di = calloc(1, sizeof(Drag_Info)); - di->image_path = NULL; - di->wdg_id = wdg_id; - di->obj = obj; - di->dragdone_post_cb = _dragdone_post_cb; - - _drag_info_global.drag_info = di; _drag_info_global.canvas_is_source = EINA_TRUE; + _drag_info_global._wdg_dragdone_post_cb = _wdg_dragdone_post_cb; _drag_info_global.drag_start_wdg = wdg_main_wdg_get(wdg_get(wdg_id)); + _drag_info_global.wdg_id = wdg_id; + _drag_info_global.obj = obj; + Eo *drag_object = obj; /* We want to provide inline image as a drag object * in order to properly calculate coords of evas. */ Eo *main_wdg_eo; - const Gui_Widget *main_wdg = wdg_main_wdg_get(wdg_get(di->wdg_id)); + const Gui_Widget *main_wdg = wdg_main_wdg_get(wdg_get(wdg_id)); - Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(wdg_context_get(wdg_get(di->wdg_id))); + Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(wdg_context_get(wdg_get(wdg_id))); main_wdg_eo = session_eo_get(session, main_wdg); /* Usually main_wdg is win. * But when it is not, need to get image of Editor win */ @@ -597,13 +589,13 @@ drag_start(Eo *obj, Eid *wdg_id, void (*_dragdone_post_cb)(Eina_Bool accept, con drag_object = elm_win_inlined_image_object_get(main_obj_inlined_win_img); } - char *wdg_data = json_widget_generate(di->wdg_id); + char *wdg_data = json_widget_generate(wdg_id); elm_drag_start(drag_object, ELM_SEL_FORMAT_TEXT, wdg_data, ELM_XDND_ACTION_COPY, - _drag_widget_object_create, di, + _drag_widget_object_create, NULL, _dragpos, NULL, - _dragaccept, di, - _dragdone, di); + _dragaccept, NULL, + _dragdone, NULL); free(wdg_data); } @@ -712,20 +704,8 @@ _gl_createicon(void *data, Evas_Object *win, Evas_Coord *xoff, Evas_Coord *yoff) /* Structo to hold info when dragging from item container */ typedef struct { - //Elm_Sel_Format format; - //const char *data; - //Eina_List *icons; - //Elm_Xdnd_Action action; -// Elm_Drag_Icon_Create_Cb createicon; - // void *createdata; Elm_Drag_Start dragstart; -// void *startcbdata; - //Elm_Drag_Pos dragpos; - //void *dragdata; - //Elm_Drag_Accept acceptcb; - //void *acceptdata; Elm_Drag_Done dragdone; - // void *donecbdata; } _Drag_Item_Container_Info; static void @@ -736,12 +716,9 @@ _drag_item_container_dragstart_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_ Gui_Widget *wdg = data; - Drag_Info *di = calloc(1, sizeof(Drag_Info)); - di->image_path = NULL; - 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); + _drag_info_global.wdg_id = wdg_eid_get(wdg); if (_dici && _dici->dragstart) { @@ -756,12 +733,11 @@ _drag_item_container_dragdone_cb(void *data EINA_UNUSED, Evas_Object *obj, Eina_ eo_do(obj, _dici = eo_key_data_get(DRAG_ITEM_CONTAINER_INFO)); if (_dici && _dici->dragdone) { - _dici->dragdone((void *)_drag_info_global.drag_start_wdg, obj, accepted); + _dici->dragdone((void *)_drag_info_global.drag_start_wdg, NULL, 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; + _drag_info_global_null(); } static Eina_Bool diff --git a/src/bin/gui/editor.c b/src/bin/gui/editor.c index 45d89b5..41119e3 100644 --- a/src/bin/gui/editor.c +++ b/src/bin/gui/editor.c @@ -1918,7 +1918,9 @@ _objtree_drag_start_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED) static void _objtree_dragdone_cb(void *data, Evas_Object *obj EINA_UNUSED, Eina_Bool accepted) { - _dragdone_post_cb(accepted, NULL, data); + Gui_Widget *wdg = data; + const Gui_Session *session = gui_context_editor_session_get(wdg_context_get(wdg)); + _dragdone_post_cb(accepted, session_eo_get(session, wdg), wdg); } static void --