commit cdceaf5792c82f970d38ad35f5928b1f7bcc8cf8
authorChunEon Park <chuneon.park@samsung.com>
Fri, 22 Mar 2013 07:51:23 +0000 (16:51 +0900)
committerSungho Kwak <sungho1.kwak@samsung.com>
Thu, 28 Mar 2013 02:50:51 +0000 (11:50 +0900)
Author: ChunEon Park <hermet>@hermet.pe.kr>
Date: Wed Mar 6 21:33:13 2013 +0900

elementary/widget - added elm_object_item_signal_callback_add(), elm_object_item_signal_callback_del()

Change-Id: I1b0ce007e9ffda3d161841b5f7fa6a7c727eed58

src/lib/elm_main.c
src/lib/elm_object_item.h
src/lib/elm_widget.c
src/lib/elm_widget.h

index 5b58ce4..2f9a3a3 100644 (file)
@@ -1513,6 +1513,18 @@ elm_object_item_signal_emit(Elm_Object_Item *it, const char *emission, const cha
    _elm_widget_item_signal_emit((Elm_Widget_Item *)it, emission, source);
 }
 
+EAPI void
+elm_object_item_signal_callback_add(Elm_Object_Item *it, const char *emission, const char *source, Elm_Object_Item_Signal_Cb func, void *data)
+{
+   _elm_widget_item_signal_callback_add((Elm_Widget_Item *)it, emission, source, (Elm_Widget_Item_Signal_Cb) func, data);
+}
+
+EAPI void *
+elm_object_item_signal_callback_del(Elm_Object_Item *it, const char *emission, const char *source, Elm_Object_Item_Signal_Cb func)
+{
+   return _elm_widget_item_signal_callback_del((Elm_Widget_Item *)it, emission, source, (Elm_Widget_Item_Signal_Cb) func);
+}
+
 EAPI void elm_object_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
 {
    _elm_widget_item_disabled_set((Elm_Widget_Item *)it, disabled);
index 43491d1..bad0754 100644 (file)
@@ -1,4 +1,20 @@
 /**
+ * @typedef Elm_Object_Item_Signal_Cb
+ *
+ * Elm_Object_Item Signal Callback functions' prototype definition. @c data
+ * will have the auxiliary data pointer at the time the callback registration.
+ * @c it will be a pointer the Elm_Object_Item that have the edje object where
+ * the signal comes from. @c emission will identify the exact signal's emission
+ * string and @c source the exact signal's source one.
+ *
+ * @see elm_object_item_signal_callback_add()
+ * @since 1.8
+ *
+ * @ingroup General
+ */
+typedef void                  (*Elm_Object_Item_Signal_Cb)(void *data, Elm_Object_Item *it, const char *emission, const char *source);
+
+/**
  * Get the widget object's handle which contains a given item
  *
  * @param it The Elementary object item
@@ -207,6 +223,50 @@ EAPI void                         elm_object_item_data_set(Elm_Object_Item *it,
 EAPI void                         elm_object_item_signal_emit(Elm_Object_Item *it, const char *emission, const char *source);
 
 /**
+ * Add a callback for a signal emitted by object item edje.
+ *
+ * This function connects a callback function to a signal emitted by the
+ * edje object of the object item.
+ * Globs can occur in either the emission or source name.
+ *
+ * @param it The elementary object item
+ * @param emission The signal's name.
+ * @param source The signal's source.
+ * @param func The callback function to be executed when the signal is
+ * emitted.
+ * @param data A pointer to data to pass to the callback function.
+ * @since 1.8
+ *
+ * @ingroup General
+ */
+EAPI void                         elm_object_item_signal_callback_add(Elm_Object_Item *it, const char *emission, const char *source, Elm_Object_Item_Signal_Cb func, void *data);
+
+/**
+ * Remove a signal-triggered callback from a object item edje object.
+ *
+ * @param it The elementary object item
+ * @param emission The signal's name.
+ * @param source The signal's source.
+ * @param func The callback function to be executed when the signal is
+ * emitted.
+ * @return The data pointer of the signal callback or @c NULL, on
+ * errors.
+ *
+ * This function removes the @b last callback, previously attached to
+ * a signal emitted by an underlying Edje object of @a it, whose
+ * parameters @a emission, @a source and @c func match exactly with
+ * those passed to a previous call to
+ * elm_object_item_signal_callback_add(). The data pointer that was passed
+ * to this call will be returned.
+ *
+ * @see elm_object_item_signal_callback_add()
+ * @since 1.8
+ *
+ * @ingroup General
+ */
+EAPI void                        *elm_object_item_signal_callback_del(Elm_Object_Item *it, const char *emission, const char *source, Elm_Object_Item_Signal_Cb func);
+
+/**
  * Set the disabled state of an widget item.
  *
  * @param it The Elementary object item
index 1f0ab14..8ecbc4e 100644 (file)
@@ -3977,6 +3977,8 @@ _elm_widget_item_new(Evas_Object *widget,
 EAPI void
 _elm_widget_item_free(Elm_Widget_Item *item)
 {
+   Elm_Widget_Item_Signal_Data *wisd;
+
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
 
    if (item->del_func)
@@ -3988,6 +3990,13 @@ _elm_widget_item_free(Elm_Widget_Item *item)
    if (item->access_info)
      eina_stringshare_del(item->access_info);
 
+   EINA_LIST_FREE(item->signals, wisd)
+     {
+        eina_stringshare_del(wisd->emission);
+        eina_stringshare_del(wisd->source);
+        free(wisd);
+     }
+
    EINA_MAGIC_SET(item, EINA_MAGIC_NONE);
    free(item);
 }
@@ -4690,6 +4699,88 @@ _elm_widget_item_signal_emit_hook_set(Elm_Widget_Item *item,
    item->signal_emit_func = func;
 }
 
+
+static void
+_elm_widget_item_signal_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission,
+                           const char *source)
+{
+   Elm_Widget_Item_Signal_Data *wisd = data;
+   wisd->func(wisd->data, wisd->item, emission, source);
+}
+
+EAPI void
+_elm_widget_item_signal_callback_add(Elm_Widget_Item *item,
+                                     const char *emission,
+                                     const char *source,
+                                     Elm_Widget_Item_Signal_Cb func,
+                                     void *data)
+{
+   ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
+   EINA_SAFETY_ON_NULL_RETURN(func);
+
+   Elm_Widget_Item_Signal_Data *wisd;
+
+   wisd = malloc(sizeof(Elm_Widget_Item_Signal_Data));
+   if (!wisd) return;
+
+   wisd->item = item;
+   wisd->func = func;
+   wisd->data = data;
+   wisd->emission = eina_stringshare_add(emission);
+   wisd->source = eina_stringshare_add(source);
+
+   if (_elm_widget_is(item->view))
+     elm_object_signal_callback_add(item->view, emission, source, _elm_widget_item_signal_cb, wisd);
+   else if (!strcmp(evas_object_type_get(item->view), "edje"))
+     edje_object_signal_callback_add(item->view, emission, source, _elm_widget_item_signal_cb, wisd);
+   else
+     {
+        WRN("The %s widget item doesn't support signal callback add!",
+            evas_object_type_get(item->widget));
+        free(wisd);
+        return;
+     }
+
+   item->signals = eina_list_append(item->signals, wisd);
+}
+
+EAPI void *
+_elm_widget_item_signal_callback_del(Elm_Widget_Item *item,
+                                    const char *emission,
+                                    const char *source,
+                                    Elm_Widget_Item_Signal_Cb func)
+{
+   ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
+
+   Elm_Widget_Item_Signal_Data *wisd;
+   Eina_List *l;
+   void *data = NULL;
+
+   EINA_LIST_FOREACH(item->signals, l, wisd)
+     {
+        if ((wisd->func == func) && !strcmp(wisd->emission, emission) &&
+            !strcmp(wisd->source, source))
+          {
+             item->signals = eina_list_remove_list(item->signals, l);
+             eina_stringshare_del(wisd->emission);
+             eina_stringshare_del(wisd->source);
+             data = wisd->data;
+
+             if (_elm_widget_is(item->view))
+               elm_object_signal_callback_del(item->view, emission, source,
+                                              _elm_widget_item_signal_cb);
+             else if (!strcmp(evas_object_type_get(item->view), "edje"))
+               edje_object_signal_callback_del_full(item->view, emission,
+                                                    source,
+                                                    _elm_widget_item_signal_cb,
+                                                    data);
+          }
+     }
+
+   return data;
+}
+
 EAPI void
 _elm_widget_item_access_info_set(Elm_Widget_Item *item,
                                  const char *txt)
index 1bc7677..8f3d77f 100644 (file)
@@ -534,6 +534,7 @@ typedef struct _Elm_Cursor      Elm_Cursor;
 
 /**< base structure for all widget items that are not Elm_Widget themselves */
 typedef struct _Elm_Widget_Item Elm_Widget_Item;
+typedef struct _Elm_Widget_Item_Signal_Data Elm_Widget_Item_Signal_Data;
 
 /**< accessibility information to be able to set and get from the access API */
 typedef struct _Elm_Access_Info Elm_Access_Info;
@@ -549,6 +550,7 @@ typedef Evas_Object          *(*Elm_Widget_Content_Unset_Cb)(const void *data, c
 typedef void                  (*Elm_Widget_Signal_Emit_Cb)(void *data, const char *emission, const char *source);
 typedef void                  (*Elm_Widget_Disable_Cb)(void *data);
 typedef Eina_Bool             (*Elm_Widget_Del_Pre_Cb)(void *data);
+typedef void                  (*Elm_Widget_Item_Signal_Cb)(void *data, Elm_Widget_Item *item, const char *emission, const char *source);
 
 #define ELM_ACCESS_DONE          -1   /* sentence done - send done event here */
 #define ELM_ACCESS_CANCEL        -2   /* stop reading immediately */
@@ -617,6 +619,15 @@ EAPI void             _elm_access_highlight_cycle(Evas_Object *obj, Elm_Focus_Di
 /**< put this as the first member in your widget item struct */
 #define ELM_WIDGET_ITEM       Elm_Widget_Item base
 
+struct _Elm_Widget_Item_Signal_Data
+{
+   Elm_Widget_Item *item;
+   Elm_Widget_Item_Signal_Cb func;
+   const char *emission;
+   const char *source;
+   void *data;
+};
+
 struct _Elm_Widget_Item
 {
 /* ef1 ~~ efl, el3 ~~ elm */
@@ -646,6 +657,7 @@ struct _Elm_Widget_Item
    Evas_Object                   *access_obj;
    const char                    *access_info;
    Eina_List                     *access_order;
+   Eina_List                     *signals;
 
    Eina_Bool                      disabled : 1;
    Eina_Bool                      on_deletion : 1;
@@ -824,6 +836,9 @@ EAPI Evas_Object     *_elm_widget_item_part_content_get(const Elm_Widget_Item *i
 EAPI Evas_Object     *_elm_widget_item_part_content_unset(Elm_Widget_Item *item, const char *part);
 EAPI void             _elm_widget_item_part_text_set(Elm_Widget_Item *item, const char *part, const char *label);
 EAPI const char      *_elm_widget_item_part_text_get(const Elm_Widget_Item *item, const char *part);
+
+EAPI void             _elm_widget_item_signal_callback_add(Elm_Widget_Item *item, const char *emission, const char *source, Elm_Widget_Item_Signal_Cb func, void *data);
+EAPI void            *_elm_widget_item_signal_callback_del(Elm_Widget_Item *it, const char *emission, const char *source, Elm_Widget_Item_Signal_Cb func);
 EAPI void             _elm_widget_item_signal_emit(Elm_Widget_Item *item, const char *emission, const char *source);
 EAPI void             _elm_widget_item_content_set_hook_set(Elm_Widget_Item *item, Elm_Widget_Content_Set_Cb func);
 EAPI void             _elm_widget_item_content_get_hook_set(Elm_Widget_Item *item, Elm_Widget_Content_Get_Cb func);