From 79ad6418928fe5ba3e1f3365d85198375b651332 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Wed, 23 Sep 2009 03:22:07 +0000 Subject: [PATCH] genlist - get item at xy. handy for dnd. skips blocks that dont intersect SVN revision: 42635 --- src/bin/test_genlist.c | 25 ++++++++++++++++++- src/bin/test_photocam.c | 2 +- src/lib/Elementary.h.in | 1 + src/lib/elm_genlist.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 2 deletions(-) diff --git a/src/bin/test_genlist.c b/src/bin/test_genlist.c index b52b3f5..c9c30d1 100644 --- a/src/bin/test_genlist.c +++ b/src/bin/test_genlist.c @@ -39,10 +39,25 @@ gl_sel(void *data, Evas_Object *obj, void *event_info) printf("sel item data [%p] on genlist obj [%p], item pointer [%p]\n", data, obj, event_info); } +static void +_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) +{ + Evas_Object *gl = data; + Evas_Event_Mouse_Move *ev = event_info; + int where = 0; + Elm_Genlist_Item *gli; + gli = elm_genlist_at_xy_item_get(gl, ev->cur.canvas.x, ev->cur.canvas.y, &where); + if (gli) + printf("over %p, where %i\n", elm_genlist_item_data_get(gli), where); + else + printf("over none, where %i\n", where); +} + void test_genlist(void *data, Evas_Object *obj, void *event_info) { Evas_Object *win, *bg, *gl; + Evas_Object *over; Elm_Genlist_Item *gli; int i; @@ -60,7 +75,15 @@ test_genlist(void *data, Evas_Object *obj, void *event_info) elm_win_resize_object_add(win, gl); evas_object_size_hint_weight_set(gl, 1.0, 1.0); evas_object_show(gl); - + + over = evas_object_rectangle_add(evas_object_evas_get(win)); + evas_object_color_set(over, 0, 0, 0, 0); + evas_object_event_callback_add(over, EVAS_CALLBACK_MOUSE_MOVE, _move, gl); + evas_object_repeat_events_set(over, 1); + evas_object_show(over); + evas_object_size_hint_weight_set(over, 1.0, 1.0); + elm_win_resize_object_add(win, over); + itc1.item_style = "default"; itc1.func.label_get = gl_label_get; itc1.func.icon_get = gl_icon_get; diff --git a/src/bin/test_photocam.c b/src/bin/test_photocam.c index e9cea78..811a77a 100644 --- a/src/bin/test_photocam.c +++ b/src/bin/test_photocam.c @@ -26,7 +26,7 @@ test_photocam(void *data, Evas_Object *obj, void *event_info) evas_object_size_hint_weight_set(ph, 1.0, 1.0); elm_win_resize_object_add(win, ph); - elm_photocam_file_set(ph, img[3]); + elm_photocam_file_set(ph, img[1]); evas_object_show(ph); diff --git a/src/lib/Elementary.h.in b/src/lib/Elementary.h.in index 172fa1c..67ff1ba 100644 --- a/src/lib/Elementary.h.in +++ b/src/lib/Elementary.h.in @@ -694,6 +694,7 @@ extern "C" { EAPI void elm_genlist_multi_select_set(Evas_Object *obj, Eina_Bool multi); EAPI Elm_Genlist_Item *elm_genlist_selected_item_get(const Evas_Object *obj); EAPI const Eina_List *elm_genlist_selected_items_get(const Evas_Object *obj); + EAPI Elm_Genlist_Item *elm_genlist_at_xy_item_get(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, int *posret); EAPI Elm_Genlist_Item *elm_genlist_first_item_get(const Evas_Object *obj); EAPI Elm_Genlist_Item *elm_genlist_last_item_get(const Evas_Object *obj); EAPI Elm_Genlist_Item *elm_genlist_item_next_get(const Elm_Genlist_Item *item); diff --git a/src/lib/elm_genlist.c b/src/lib/elm_genlist.c index c4e609b..7f4da1f 100644 --- a/src/lib/elm_genlist.c +++ b/src/lib/elm_genlist.c @@ -1853,6 +1853,72 @@ elm_genlist_selected_items_get(const Evas_Object *obj) } /** + * Get the item that is at the x, y canvas coords + * + * This returns the item at the given coordinates (which are canvas relative + * not object-relative). If an item is at that coordinate, that item handle + * is returned, and if @p posret is not NULL, the integer pointed to is set + * to a value of -1, 0 or 1, depending if the coordinate is on the upper + * portion of that item (-1), on the middle section (0) or on the lower part + * (1). If NULL is returned as an item (no item found there), then posret + * may indicate -1 or 1 based if the coordinate is above or below all items + * respectively in the genlist. + * + * @param it The item + * @param x The input x coordinate + * @param y The input y coordinate + * @param posret The position relative to the item returned here + * @return The item at the coordinates or NULL if none + * + * @ingroup Genlist + */ +EAPI Elm_Genlist_Item * +elm_genlist_at_xy_item_get(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, int *posret) +{ + Widget_Data *wd = elm_widget_data_get(obj); + Evas_Coord ox, oy, ow, oh; + Item_Block *itb; + Evas_Coord lasty; + + evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh); + lasty = oy; + EINA_INLIST_FOREACH(wd->blocks, itb) + { + Eina_List *l; + Elm_Genlist_Item *it; + + if (!ELM_RECTS_INTERSECT(ox + itb->x - itb->wd->pan_x, + oy + itb->y - itb->wd->pan_y, + itb->w, itb->h, x, y, 1, 1)) + continue; + EINA_LIST_FOREACH(itb->items, l, it) + { + Evas_Coord itx, ity; + + itx = ox + itb->x + it->x - itb->wd->pan_x; + ity = oy + itb->y + it->y - itb->wd->pan_y; + if (ELM_RECTS_INTERSECT(itx, ity, it->w, it->h, x, y, 1, 1)) + { + if (posret) + { + if (y <= (ity + (it->h / 4))) *posret = -1; + else if (y >= (ity + it->h - (it->h / 4))) *posret = 1; + else *posret = 0; + } + return it; + } + lasty = ity + it->h; + } + } + if (posret) + { + if (y > lasty) *posret = 1; + else *posret = -1; + } + return NULL; +} + +/** * Get the first item in the genlist * * This returns the first item in the list. -- 2.7.4