multibuttonentry: Add item long pressed callback.
authorwoochan lee <wc0917.lee@samsung.com>
Sat, 28 Mar 2015 06:05:44 +0000 (15:05 +0900)
committerChunEon Park <hermet@hermet.pe.kr>
Sat, 28 Mar 2015 06:09:27 +0000 (15:09 +0900)
Summary: Add long pressed callback for application. test code changed to following this change as well.

@feature

Reviewers: seoz, woohyun, Jaehyun, Hermet

Differential Revision: https://phab.enlightenment.org/D2103

Conflicts:

src/lib/elc_multibuttonentry.c

legacy/elementary/src/bin/test_multibuttonentry.c
legacy/elementary/src/lib/elc_multibuttonentry.c
legacy/elementary/src/lib/elc_multibuttonentry.h
legacy/elementary/src/lib/elm_multibuttonentry.eo
legacy/elementary/src/lib/elm_widget_multibuttonentry.h

index 83da32e..04c6499 100644 (file)
@@ -120,6 +120,16 @@ _shrink_state_changed_cb(void *data EINA_UNUSED,
    printf("contracted state changed! \n");
 }
 
+// "longpressed" smart callback
+static void
+_longpressed_cb(void *data EINA_UNUSED,
+                         Evas_Object *obj EINA_UNUSED,
+                         void *event_info EINA_UNUSED)
+{
+   printf("longpressed! \n");
+}
+
+
 // "item verified" confirm callback
 static Eina_Bool
 _item_filter_cb(Evas_Object *obj EINA_UNUSED,
@@ -198,6 +208,7 @@ _add_multibuttonentry(Evas_Object *parent)
    evas_object_smart_callback_add(mbe, "expanded", _expanded_cb, NULL);
    evas_object_smart_callback_add(mbe, "contracted", _contracted_cb, NULL);
    evas_object_smart_callback_add(mbe, "shrink,state,changed", _shrink_state_changed_cb, NULL);
+   evas_object_smart_callback_add(mbe, "longpressed", _longpressed_cb, NULL);
 
    btn = _format_change_btn_add(mbe);
    elm_object_part_content_set(parent, "box", btn);
index f1e5e63..9e1a755 100644 (file)
@@ -28,6 +28,7 @@ static const char SIG_UNFOCUSED[] = "unfocused";
 static const char SIG_EXPANDED[] = "expanded";
 static const char SIG_CONTRACTED[] = "contracted";
 static const char SIG_EXPAND_STATE_CHANGED[] = "expand,state,changed";
+static const char SIG_LONGPRESSED[] = "longpressed";
 static const Evas_Smart_Cb_Description _smart_callbacks[] = {
    {SIG_ITEM_SELECTED, ""},
    {SIG_ITEM_ADDED, ""},
@@ -39,6 +40,7 @@ static const Evas_Smart_Cb_Description _smart_callbacks[] = {
    {SIG_EXPANDED, ""},
    {SIG_CONTRACTED, ""},
    {SIG_EXPAND_STATE_CHANGED, ""},
+   {SIG_LONGPRESSED, ""},
    {NULL, NULL}
 };
 
@@ -513,6 +515,51 @@ _on_item_deleted(void *data,
      }
 }
 
+static Eina_Bool
+_long_press_cb(void *data)
+{
+   Elm_Multibuttonentry_Item_Data *it = data;
+
+   ELM_MULTIBUTTONENTRY_DATA_GET(WIDGET(it), sd);
+
+   sd->longpress_timer = NULL;
+
+   evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, EO_OBJ(it));
+
+   return ECORE_CALLBACK_CANCEL;
+}
+
+static void
+_mouse_down_cb(void  *data,
+               Evas *evas EINA_UNUSED,
+               Evas_Object *obj EINA_UNUSED,
+               void *event_info)
+{
+   Elm_Multibuttonentry_Item_Data *it = data;
+   Evas_Event_Mouse_Down *ev = event_info;
+
+   ELM_MULTIBUTTONENTRY_DATA_GET_OR_RETURN(WIDGET(it), sd);
+
+   if (ev->button != 1) return;
+
+   ecore_timer_del(sd->longpress_timer);
+   sd->longpress_timer = ecore_timer_add
+      (_elm_config->longpress_timeout, _long_press_cb, it);
+}
+
+static void
+_mouse_up_cb(void *data,
+             Evas *evas EINA_UNUSED,
+             Evas_Object *obj EINA_UNUSED,
+             void *event_info EINA_UNUSED)
+{
+   Elm_Multibuttonentry_Item_Data *it = data;
+
+   ELM_MULTIBUTTONENTRY_DATA_GET_OR_RETURN(WIDGET(it), sd);
+
+   ELM_SAFE_FREE(sd->longpress_timer, ecore_timer_del);
+}
+
 EOLIAN static void
 _elm_multibuttonentry_item_elm_widget_item_signal_emit(Eo *eo_item EINA_UNUSED,
                                                        Elm_Multibuttonentry_Item_Data *item,
@@ -664,6 +711,13 @@ _item_new(Elm_Multibuttonentry_Data *sd,
      (VIEW(item), "mouse,clicked,1", "*", _on_item_clicked, EO_OBJ(item));
    elm_layout_signal_callback_add
      (VIEW(item), "elm,deleted", "elm", _on_item_deleted, EO_OBJ(item));
+   evas_object_event_callback_add
+      (VIEW(item),
+       EVAS_CALLBACK_MOUSE_DOWN, _mouse_down_cb, item);
+   evas_object_event_callback_add
+      (VIEW(item),
+       EVAS_CALLBACK_MOUSE_UP, _mouse_up_cb, item);
+
    evas_object_show(VIEW(item));
 
    evas_object_smart_calculate(VIEW(item));
@@ -1466,6 +1520,7 @@ _elm_multibuttonentry_evas_object_smart_del(Eo *obj, Elm_Multibuttonentry_Data *
    evas_object_del(sd->label);
    evas_object_del(sd->guide_text);
    evas_object_del(sd->end);
+   ecore_timer_del(sd->longpress_timer);
 
    eo_do_super(obj, MY_CLASS, evas_obj_smart_del());
 }
index 32b590d..d0862fc 100644 (file)
@@ -37,6 +37,7 @@
  * - @c "contracted" - when multi-button entry is contracted.
  * - @c "expand,state,changed" - when shrink mode state of
  *       multi-button entry is changed.
+ * - @c "longpressed" - when multi-button entry is pressed for a long time.
  *
  * Default text parts of the multi-button entry widget that you can use are:
  * @li "default" - A label of the multi-button entry
index 43e13a9..6149ab6 100644 (file)
@@ -280,6 +280,7 @@ class Elm_Multibuttonentry (Elm_Layout)
       expanded;
       contracted;
       expand,state,changed;
+      longpressed;
    }
 
 }
index 41d1926..607e05c 100644 (file)
@@ -105,14 +105,19 @@ struct _Elm_Multibuttonentry_Data
    Eina_Bool                           last_it_select : 1;
    Eina_Bool                           editable : 1;
    Eina_Bool                           focused : 1;
+
+   Ecore_Timer                         *longpress_timer;
 };
 
 /**
  * @}
  */
 
+#define ELM_MULTIBUTTONENTRY_DATA_GET(o, sd) \
+  Elm_Multibuttonentry_Data *sd = eo_data_scope_get(o, ELM_MULTIBUTTONENTRY_CLASS);
+
 #define ELM_MULTIBUTTONENTRY_DATA_GET_OR_RETURN(o, ptr) \
-  Elm_Multibuttonentry_Data *ptr = eo_data_scope_get(o, ELM_MULTIBUTTONENTRY_CLASS); \
+  ELM_MULTIBUTTONENTRY_DATA_GET(o, ptr);                \
   if (EINA_UNLIKELY(!ptr))                              \
     {                                                   \
        CRI("No widget data for object %p (%s)",         \