summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2015-05-20 21:31:53 +0200
committerDave Andreoli <dave@gurumeditation.it>2015-05-20 21:32:08 +0200
commitb8afe3f03dbbca5c5382d8c2946d0480f8c41917 (patch)
treeac1cdea5e5189d05601e9cd2b7bce7eb971fc04e
parent6b6ba6d2a00d11fb04c31734e0c8520c4764b90d (diff)
Immediatly change the cursor if changed from inside the widget
@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
-rw-r--r--src/bin/test_cursor.c24
-rw-r--r--src/lib/elm_priv.h4
-rw-r--r--src/lib/els_cursor.c6
3 files changed, 34 insertions, 0 deletions
diff --git a/src/bin/test_cursor.c b/src/bin/test_cursor.c
index 04f3b87fa..1e6401abb 100644
--- a/src/bin/test_cursor.c
+++ b/src/bin/test_cursor.c
@@ -15,6 +15,7 @@ typedef struct _Testitem
15} Testitem; 15} Testitem;
16 16
17static Elm_Gengrid_Item_Class gic; 17static Elm_Gengrid_Item_Class gic;
18static Eina_Bool cursor_setted = EINA_FALSE;
18 19
19char * 20char *
20grd_lbl_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED) 21grd_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
94 return strdup(buf); 95 return strdup(buf);
95} 96}
96 97
98static void
99bt_clicked(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
100{
101 if (cursor_setted)
102 {
103 elm_object_cursor_unset(obj);
104 cursor_setted = EINA_FALSE;
105 elm_object_text_set(obj, "Cursor set on click");
106 }
107 else
108 {
109 elm_object_cursor_set(obj, ELM_CURSOR_HAND1);
110 cursor_setted = EINA_TRUE;
111 elm_object_text_set(obj, "Cursor unset on click");
112 }
113}
114
97void 115void
98test_cursor(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) 116test_cursor(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
99{ 117{
@@ -133,6 +151,12 @@ test_cursor(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_in
133 elm_box_pack_end(bx, bt); 151 elm_box_pack_end(bx, bt);
134 evas_object_show(bt); 152 evas_object_show(bt);
135 153
154 bt = elm_button_add(win);
155 elm_object_text_set(bt, "Cursor set on click");
156 evas_object_smart_callback_add(bt, "clicked", bt_clicked, NULL);
157 elm_box_pack_end(bx, bt);
158 evas_object_show(bt);
159
136 list = elm_list_add(win); 160 list = elm_list_add(win);
137 elm_box_pack_end(bx, list); 161 elm_box_pack_end(bx, list);
138 evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 162 evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
diff --git a/src/lib/elm_priv.h b/src/lib/elm_priv.h
index 1378d9bae..9e7bc42ba 100644
--- a/src/lib/elm_priv.h
+++ b/src/lib/elm_priv.h
@@ -164,6 +164,10 @@ extern const char *_elm_engines[];
164#define MAX(x, y) (((x) > (y)) ? (x) : (y)) 164#define MAX(x, y) (((x) > (y)) ? (x) : (y))
165#undef CEIL 165#undef CEIL
166#define CEIL(a) (((a) % 2 != 0) ? ((a) / 2 + 1) : ((a) / 2)) 166#define CEIL(a) (((a) % 2 != 0) ? ((a) / 2 + 1) : ((a) / 2))
167#undef IS_INSIDE
168#define IS_INSIDE(x, y, xx, yy, ww, hh) \
169 (((x) < ((xx) + (ww))) && ((y) < ((yy) + (hh))) && \
170 ((x) >= (xx)) && ((y) >= (yy)))
167 171
168 172
169#define ELM_SAFE_FREE(_h, _fn) do { _fn((void*)_h); _h = NULL; } while (0) 173#define ELM_SAFE_FREE(_h, _fn) do { _fn((void*)_h); _h = NULL; } while (0)
diff --git a/src/lib/els_cursor.c b/src/lib/els_cursor.c
index c4eae4733..c28994b1f 100644
--- a/src/lib/els_cursor.c
+++ b/src/lib/els_cursor.c
@@ -406,6 +406,12 @@ _elm_cursor_cur_set(Elm_Cursor *cur)
406#endif 406#endif
407 } 407 }
408 } 408 }
409
410 Evas_Coord x, y, w, h, px, py;
411 evas_object_geometry_get(cur->eventarea, &x, &y, &w, &h);
412 evas_pointer_canvas_xy_get(cur->evas, &px, &py);
413 if (IS_INSIDE(px, py, x, y, w, h))
414 _elm_cursor_set(cur);
409} 415}
410 416
411/** 417/**