summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2016-09-06 11:11:51 -0400
committerMike Blumenkrantz <zmike@osg.samsung.com>2016-09-06 11:12:31 -0400
commit5da62d9adf9c2ff6672ffbe6765e53a9937e0e24 (patch)
tree09a33ac63629429f8ae7c14df502bfcb181d0b18
parent686dc747d6f6c481614fd5d0a7a1fb413da0ca5f (diff)
add drop handlers for gadgets
a simple wrapper around existing e_dnd functionality
-rw-r--r--src/bin/e_gadget.c59
-rw-r--r--src/bin/e_gadget.h10
2 files changed, 69 insertions, 0 deletions
diff --git a/src/bin/e_gadget.c b/src/bin/e_gadget.c
index d5bf1b086..ba5e41a0e 100644
--- a/src/bin/e_gadget.c
+++ b/src/bin/e_gadget.c
@@ -64,6 +64,8 @@ struct E_Gadget_Config
64 void *data; 64 void *data;
65 } allow_deny; 65 } allow_deny;
66 66
67 Eina_Hash *drop_handlers;
68
67 double x, y; //fixed % positioning 69 double x, y; //fixed % positioning
68 double w, h; //fixed % sizing 70 double w, h; //fixed % sizing
69 Evas_Point offset; //offset from mouse down 71 Evas_Point offset; //offset from mouse down
@@ -262,6 +264,7 @@ _gadget_object_free(E_Object *eobj)
262 evas_object_event_callback_del_full(zgc->display, EVAS_CALLBACK_DEL, _gadget_del, zgc); 264 evas_object_event_callback_del_full(zgc->display, EVAS_CALLBACK_DEL, _gadget_del, zgc);
263 E_FREE_FUNC(zgc->display, evas_object_del); 265 E_FREE_FUNC(zgc->display, evas_object_del);
264 } 266 }
267 E_FREE_FUNC(zgc->drop_handlers, eina_hash_free);
265 E_FREE_FUNC(zgc->gadget, evas_object_del); 268 E_FREE_FUNC(zgc->gadget, evas_object_del);
266 E_FREE_FUNC(zgc->cfg_object, evas_object_del); 269 E_FREE_FUNC(zgc->cfg_object, evas_object_del);
267 E_FREE_FUNC(zgc->style.obj, evas_object_del); 270 E_FREE_FUNC(zgc->style.obj, evas_object_del);
@@ -1389,6 +1392,62 @@ e_gadget_type_iterator_get(void)
1389 return gadget_types ? eina_hash_iterator_key_new(gadget_types) : NULL; 1392 return gadget_types ? eina_hash_iterator_key_new(gadget_types) : NULL;
1390} 1393}
1391 1394
1395static void
1396_gadget_drop_handler_moveresize(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
1397{
1398 int x, y, w, h;
1399
1400 evas_object_geometry_get(obj, &x, &y, &w, &h);
1401 e_drop_handler_geometry_set(data, x, y, w, h);
1402}
1403
1404static void
1405_gadget_drop_handler_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
1406{
1407 E_Gadget_Config *zgc = data;
1408
1409 eina_hash_del_by_key(zgc->drop_handlers, &obj);
1410 e_object_del(evas_object_data_get(obj, "gadget_drop_handler"));
1411}
1412
1413E_API Evas_Object *
1414e_gadget_drop_handler_add(Evas_Object *g, void *data,
1415 void (*enter_cb)(void *data, const char *type, void *event),
1416 void (*move_cb)(void *data, const char *type, void *event),
1417 void (*leave_cb)(void *data, const char *type, void *event),
1418 void (*drop_cb)(void *data, const char *type, void *event),
1419 const char **types, unsigned int num_types)
1420{
1421 E_Gadget_Config *zgc;
1422 int x, y, w, h;
1423 Evas_Object *drop_object;
1424 E_Drop_Handler *drop_handler;
1425
1426 EINA_SAFETY_ON_NULL_RETURN_VAL(g, NULL);
1427 zgc = evas_object_data_get(g, "__e_gadget");
1428 EINA_SAFETY_ON_NULL_RETURN_VAL(zgc, NULL);
1429
1430 if (!zgc->drop_handlers)
1431 zgc->drop_handlers = eina_hash_pointer_new((Eina_Free_Cb)evas_object_del);
1432
1433 evas_object_geometry_get(zgc->display, &x, &y, &w, &h);
1434 drop_handler = e_drop_handler_add(zgc->e_obj_inherit, NULL, data,
1435 enter_cb, move_cb, leave_cb, drop_cb,
1436 types, num_types, x, y, w, h);
1437 drop_object = evas_object_rectangle_add(e_comp->evas);
1438 evas_object_color_set(drop_object, 0, 0, 0, 0);
1439 e_object_data_set(E_OBJECT(drop_handler), drop_object);
1440 evas_object_data_set(drop_object, "gadget_drop_handler", drop_handler);
1441 evas_object_geometry_set(drop_object, x, y, w, h);
1442 evas_object_pass_events_set(drop_object, 1);
1443 evas_object_layer_set(drop_object, evas_object_layer_get(zgc->display));
1444 evas_object_event_callback_add(drop_object, EVAS_CALLBACK_MOVE, _gadget_drop_handler_moveresize, drop_handler);
1445 evas_object_event_callback_add(drop_object, EVAS_CALLBACK_RESIZE, _gadget_drop_handler_moveresize, drop_handler);
1446 evas_object_event_callback_add(drop_object, EVAS_CALLBACK_DEL, _gadget_drop_handler_del, zgc);
1447 eina_hash_add(zgc->drop_handlers, &drop_object, drop_handler);
1448 return drop_object;
1449}
1450
1392E_API Evas_Object * 1451E_API Evas_Object *
1393e_gadget_util_layout_style_init(Evas_Object *g, Evas_Object *style) 1452e_gadget_util_layout_style_init(Evas_Object *g, Evas_Object *style)
1394{ 1453{
diff --git a/src/bin/e_gadget.h b/src/bin/e_gadget.h
index 863828a09..f44f634f4 100644
--- a/src/bin/e_gadget.h
+++ b/src/bin/e_gadget.h
@@ -130,6 +130,16 @@ E_API void e_gadget_type_add(const char *type, E_Gadget_Create_Cb callback, E_Ga
130E_API void e_gadget_type_del(const char *type); 130E_API void e_gadget_type_del(const char *type);
131E_API Eina_Iterator *e_gadget_type_iterator_get(void); 131E_API Eina_Iterator *e_gadget_type_iterator_get(void);
132 132
133/* drop region initially matches gadget size, resizes to match returned object's size
134 * handler is removed when returned object is deleted
135 */
136E_API Evas_Object *e_gadget_drop_handler_add(Evas_Object *g, void *data,
137 void (*enter_cb)(void *data, const char *type, void *event),
138 void (*move_cb)(void *data, const char *type, void *event),
139 void (*leave_cb)(void *data, const char *type, void *event),
140 void (*drop_cb)(void *data, const char *type, void *event),
141 const char **types, unsigned int num_types);
142
133E_API Evas_Object *e_gadget_util_layout_style_init(Evas_Object *g, Evas_Object *style); 143E_API Evas_Object *e_gadget_util_layout_style_init(Evas_Object *g, Evas_Object *style);
134E_API void e_gadget_util_ctxpopup_place(Evas_Object *g, Evas_Object *ctx, Evas_Object *pos_obj); 144E_API void e_gadget_util_ctxpopup_place(Evas_Object *g, Evas_Object *ctx, Evas_Object *pos_obj);
135E_API void e_gadget_util_allow_deny_ctxpopup(Evas_Object *g, const char *text, Evas_Smart_Cb allow_cb, Evas_Smart_Cb deny_cb, const void *data); 145E_API void e_gadget_util_allow_deny_ctxpopup(Evas_Object *g, const char *text, Evas_Smart_Cb allow_cb, Evas_Smart_Cb deny_cb, const void *data);