Immediatly change the cursor if changed from inside the widget
authorDave Andreoli <dave@gurumeditation.it>
Wed, 20 May 2015 19:31:53 +0000 (21:31 +0200)
committerDave Andreoli <dave@gurumeditation.it>
Wed, 20 May 2015 19:32:08 +0000 (21:32 +0200)
@fix elm_object_cursor_set() to work also when used with the mouse pointer
yet inside the widget, otherwise you need to mouseout/mousein to actually see
the new setted cursor.

Please give a short review on this one, maybe there is a simpler way to check
if the pointer is inside the widget...

Also added a button in the cursor test for this use case

src/bin/test_cursor.c
src/lib/elm_priv.h
src/lib/els_cursor.c

index 04f3b87..1e6401a 100644 (file)
@@ -15,6 +15,7 @@ typedef struct _Testitem
 } Testitem;
 
 static Elm_Gengrid_Item_Class gic;
+static Eina_Bool cursor_setted = EINA_FALSE;
 
 char *
 grd_lbl_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
@@ -94,6 +95,23 @@ glt_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNU
    return strdup(buf);
 }
 
+static void
+bt_clicked(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
+{
+   if (cursor_setted)
+     {
+        elm_object_cursor_unset(obj);
+        cursor_setted = EINA_FALSE;
+        elm_object_text_set(obj, "Cursor set on click");
+     }
+   else
+     {
+        elm_object_cursor_set(obj, ELM_CURSOR_HAND1);
+        cursor_setted = EINA_TRUE;
+        elm_object_text_set(obj, "Cursor unset on click");
+     }
+}
+
 void
 test_cursor(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
 {
@@ -133,6 +151,12 @@ test_cursor(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_in
    elm_box_pack_end(bx, bt);
    evas_object_show(bt);
 
+   bt = elm_button_add(win);
+   elm_object_text_set(bt, "Cursor set on click");
+   evas_object_smart_callback_add(bt, "clicked", bt_clicked, NULL);
+   elm_box_pack_end(bx, bt);
+   evas_object_show(bt);
+
    list = elm_list_add(win);
    elm_box_pack_end(bx, list);
    evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
index 1378d9b..9e7bc42 100644 (file)
@@ -164,6 +164,10 @@ extern const char *_elm_engines[];
 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
 #undef CEIL
 #define CEIL(a)   (((a) % 2 != 0) ? ((a) / 2 + 1) : ((a) / 2))
+#undef IS_INSIDE
+#define IS_INSIDE(x, y, xx, yy, ww, hh) \
+  (((x) < ((xx) + (ww))) && ((y) < ((yy) + (hh))) && \
+  ((x) >= (xx)) && ((y) >= (yy)))
 
 
 #define ELM_SAFE_FREE(_h, _fn) do { _fn((void*)_h); _h = NULL; } while (0)
index c4eae47..c28994b 100644 (file)
@@ -406,6 +406,12 @@ _elm_cursor_cur_set(Elm_Cursor *cur)
 #endif
           }
      }
+
+   Evas_Coord x, y, w, h, px, py;
+   evas_object_geometry_get(cur->eventarea, &x, &y, &w, &h);
+   evas_pointer_canvas_xy_get(cur->evas, &px, &py);
+   if (IS_INSIDE(px, py, x, y, w, h))
+     _elm_cursor_set(cur);
 }
 
 /**