找回密码
 立即注册
查看: 2761|回复: 0

grep长点击实现事件的方法

[复制链接]
发表于 2015-8-8 21:42:02 | 显示全部楼层 |阅读模式
grep长点击实现事件的方法
  1. // ---- long click implementation
  2. static const char* _klongtimer = "_long_timer";
  3. static long _long_click_time = 1; // 1 sec default
  4. static Eina_Bool _long_press_cb(void *data)
  5. {
  6.     Evas_Object *obj = data;
  7.         if (data == NULL) return ECORE_CALLBACK_CANCEL;
  8.         evas_object_smart_callback_call(obj, "longclick", NULL);

  9.         return ECORE_CALLBACK_CANCEL;
  10. }
  11. static void _mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info)
  12. {
  13.         Ecore_Timer *timer = evas_object_data_get(obj, _klongtimer);
  14.         if (timer != NULL) {
  15.                 ecore_timer_del(timer);
  16.                 evas_object_data_del(obj, _klongtimer);
  17.         }
  18.         if (timer == NULL) {
  19.                 timer = ecore_timer_add(_long_click_time, _long_press_cb, obj);
  20.                 evas_object_data_set(obj, _klongtimer, timer);
  21.         }
  22. }
  23. static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info)
  24. {
  25.         Ecore_Timer *timer = evas_object_data_get(obj, _klongtimer);
  26.         if (timer != NULL) {
  27.                 ecore_timer_del(timer);
  28.                 evas_object_data_del(obj, _klongtimer);
  29.         }
  30. }
  31. static void _mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info)
  32. {
  33.         Ecore_Timer *timer = evas_object_data_get(obj, _klongtimer);
  34.         Evas_Event_Mouse_Move *ev = event_info;
  35.         if ((ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) && timer) {
  36.                 ecore_timer_del(timer);
  37.                 evas_object_data_del(obj, _klongtimer);
  38.         }
  39. }
  40. void pius_object_longclick_time_set(double time)
  41. {
  42.         _long_click_time = time;
  43. }
  44. double pius_object_longclick_time_get()
  45. {
  46.         return _long_click_time;
  47. }
  48. void pius_object_longclick_add(Evas_Object *obj, Evas_Smart_Cb func, const void *data)
  49. {
  50.         evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, NULL);
  51.         evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP, _mouse_up, NULL);
  52.         evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, NULL);
  53.         evas_object_smart_callback_add(obj, "longclick", func, data);
  54. }
  55. // ----





  56. // Usage
  57. static void longclick(void *data, Evas_Object *obj, void *event_info)
  58. {
  59.     LOGI("long click!!");
  60. }

  61. Evas_Object *img = elm_image_add(ad->conform);
  62. elm_image_file_set(img, path, NULL);
  63. evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  64. elm_object_content_set(ad->conform, img);
  65. evas_object_show(img);

  66. pius_object_longclick_add(img, longclick, NULL);
复制代码
欢迎来到泰泽网:http://www.tizennet.com/ 泰泽论坛:http://bbs.tizennet.com/ 好没有内涵哦,快到设置中更改这个无聊的签名吧!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|泰泽应用|泰泽论坛|泰泽网|小黑屋|Archiver|手机版|泰泽邮箱|泰泽网 ( 蜀ICP备13024062号-1 )

GMT+8, 2024-11-24 02:38 , Processed in 0.089097 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表