|
grep长点击实现事件的方法
- // ---- long click implementation
- static const char* _klongtimer = "_long_timer";
- static long _long_click_time = 1; // 1 sec default
- static Eina_Bool _long_press_cb(void *data)
- {
- Evas_Object *obj = data;
- if (data == NULL) return ECORE_CALLBACK_CANCEL;
- evas_object_smart_callback_call(obj, "longclick", NULL);
- return ECORE_CALLBACK_CANCEL;
- }
- static void _mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info)
- {
- Ecore_Timer *timer = evas_object_data_get(obj, _klongtimer);
- if (timer != NULL) {
- ecore_timer_del(timer);
- evas_object_data_del(obj, _klongtimer);
- }
- if (timer == NULL) {
- timer = ecore_timer_add(_long_click_time, _long_press_cb, obj);
- evas_object_data_set(obj, _klongtimer, timer);
- }
- }
- static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info)
- {
- Ecore_Timer *timer = evas_object_data_get(obj, _klongtimer);
- if (timer != NULL) {
- ecore_timer_del(timer);
- evas_object_data_del(obj, _klongtimer);
- }
- }
- static void _mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info)
- {
- Ecore_Timer *timer = evas_object_data_get(obj, _klongtimer);
- Evas_Event_Mouse_Move *ev = event_info;
- if ((ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) && timer) {
- ecore_timer_del(timer);
- evas_object_data_del(obj, _klongtimer);
- }
- }
- void pius_object_longclick_time_set(double time)
- {
- _long_click_time = time;
- }
- double pius_object_longclick_time_get()
- {
- return _long_click_time;
- }
- void pius_object_longclick_add(Evas_Object *obj, Evas_Smart_Cb func, const void *data)
- {
- evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, NULL);
- evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP, _mouse_up, NULL);
- evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, NULL);
- evas_object_smart_callback_add(obj, "longclick", func, data);
- }
- // ----
- // Usage
- static void longclick(void *data, Evas_Object *obj, void *event_info)
- {
- LOGI("long click!!");
- }
- Evas_Object *img = elm_image_add(ad->conform);
- elm_image_file_set(img, path, NULL);
- evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_object_content_set(ad->conform, img);
- evas_object_show(img);
- pius_object_longclick_add(img, longclick, NULL);
复制代码 |
|