elementary/widget - just renamed internally.
[framework/uifw/elementary.git] / src / lib / elm_widget.c
index 071b454..37a8d83 100644 (file)
@@ -5,10 +5,10 @@ static const char SMART_NAME[] = "elm_widget";
 
 #define API_ENTRY                                    \
   Smart_Data * sd = evas_object_smart_data_get(obj); \
-  if ((!obj) || (!sd) || (!_elm_widget_is(obj)))
+  if ((!sd) || (!_elm_widget_is(obj)))
 #define INTERNAL_ENTRY                               \
   Smart_Data * sd = evas_object_smart_data_get(obj); \
-  if (!sd) return;
+  if (!sd) return
 
 #undef elm_widget_text_set_hook_set
 #undef elm_widget_text_get_hook_set
@@ -79,11 +79,11 @@ struct _Smart_Data
                                       Evas_Coord        *y,
                                       Evas_Coord        *w,
                                       Evas_Coord        *h);
-   Elm_Widget_On_Text_Set_Cb on_text_set_func;
-   Elm_Widget_On_Text_Get_Cb on_text_get_func;
-   Elm_Widget_On_Content_Set_Cb on_content_set_func;
-   Elm_Widget_On_Content_Get_Cb on_content_get_func;
-   Elm_Widget_On_Content_Unset_Cb on_content_unset_func;
+   Elm_Widget_Text_Set_Cb text_set_func;
+   Elm_Widget_Text_Get_Cb text_get_func;
+   Elm_Widget_Content_Set_Cb content_set_func;
+   Elm_Widget_Content_Get_Cb content_get_func;
+   Elm_Widget_Content_Unset_Cb content_unset_func;
    void        *data;
    Evas_Coord   rx, ry, rw, rh;
    int          scroll_hold;
@@ -197,7 +197,7 @@ _unfocus_parents(Evas_Object *obj)
 {
    for (; obj; obj = elm_widget_parent_get(obj))
      {
-        INTERNAL_ENTRY
+        INTERNAL_ENTRY;
         if (!sd->focused) return;
         sd->focused = 0;
      }
@@ -208,7 +208,7 @@ _focus_parents(Evas_Object *obj)
 {
    for (; obj; obj = elm_widget_parent_get(obj))
      {
-        INTERNAL_ENTRY
+        INTERNAL_ENTRY;
         if (sd->focused) return;
         sd->focused = 1;
      }
@@ -295,7 +295,7 @@ static void
 _propagate_x_drag_lock(Evas_Object *obj,
                        int          dir)
 {
-   INTERNAL_ENTRY
+   INTERNAL_ENTRY;
    if (sd->parent_obj)
      {
         Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
@@ -311,7 +311,7 @@ static void
 _propagate_y_drag_lock(Evas_Object *obj,
                        int          dir)
 {
-   INTERNAL_ENTRY
+   INTERNAL_ENTRY;
    if (sd->parent_obj)
      {
         Smart_Data *sd2 = evas_object_smart_data_get(sd->parent_obj);
@@ -329,7 +329,7 @@ _propagate_event(void        *data,
                  Evas_Object *obj,
                  void        *event_info)
 {
-   INTERNAL_ENTRY
+   INTERNAL_ENTRY;
    Evas_Callback_Type type = (Evas_Callback_Type)(long)data;
    Evas_Event_Flags *event_flags = NULL;
 
@@ -564,42 +564,42 @@ elm_widget_event_hook_set(Evas_Object *obj,
 
 EAPI void
 elm_widget_text_set_hook_set(Evas_Object *obj,
-                             Elm_Widget_On_Text_Set_Cb func)
+                             Elm_Widget_Text_Set_Cb func)
 {
    API_ENTRY return;
-   sd->on_text_set_func = func;
+   sd->text_set_func = func;
 }
 
 EAPI void
 elm_widget_text_get_hook_set(Evas_Object *obj,
-                             Elm_Widget_On_Text_Get_Cb func)
+                             Elm_Widget_Text_Get_Cb func)
 {
    API_ENTRY return;
-   sd->on_text_get_func = func;
+   sd->text_get_func = func;
 }
 
 EAPI void
 elm_widget_content_set_hook_set(Evas_Object *obj,
-                                Elm_Widget_On_Content_Set_Cb func)
+                                Elm_Widget_Content_Set_Cb func)
 {
    API_ENTRY return;
-   sd->on_content_set_func = func;
+   sd->content_set_func = func;
 }
 
 EAPI void
 elm_widget_content_get_hook_set(Evas_Object *obj,
-                                Elm_Widget_On_Content_Get_Cb func)
+                                Elm_Widget_Content_Get_Cb func)
 {
    API_ENTRY return;
-   sd->on_content_get_func = func;
+   sd->content_get_func = func;
 }
 
 EAPI void
 elm_widget_content_unset_hook_set(Evas_Object *obj,
-                                  Elm_Widget_On_Content_Unset_Cb func)
+                                  Elm_Widget_Content_Unset_Cb func)
 {
    API_ENTRY return;
-   sd->on_content_unset_func = func;
+   sd->content_unset_func = func;
 }
 
 EAPI void
@@ -1941,7 +1941,7 @@ elm_widget_focused_object_clear(Evas_Object *obj)
 {
    API_ENTRY return;
    if (!sd->focused) return;
-   if (elm_widget_focus_get(sd->resize_obj))
+   if (sd->resize_obj && elm_widget_focus_get(sd->resize_obj))
      elm_widget_focused_object_clear(sd->resize_obj);
    else
      {
@@ -2208,10 +2208,10 @@ elm_widget_scroll_hold_pop(Evas_Object *obj)
 {
    API_ENTRY return;
    sd->scroll_hold--;
-   if (sd->scroll_hold < 0) sd->scroll_hold = 0;
    if (!sd->scroll_hold)
      evas_object_smart_callback_call(obj, "scroll-hold-off", obj);
    if (sd->parent_obj) elm_widget_scroll_hold_pop(sd->parent_obj);
+   if (sd->scroll_hold < 0) sd->scroll_hold = 0;
 }
 
 EAPI int
@@ -2237,10 +2237,10 @@ elm_widget_scroll_freeze_pop(Evas_Object *obj)
 {
    API_ENTRY return;
    sd->scroll_freeze--;
-   if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
    if (!sd->scroll_freeze)
      evas_object_smart_callback_call(obj, "scroll-freeze-off", obj);
    if (sd->parent_obj) elm_widget_scroll_freeze_pop(sd->parent_obj);
+   if (sd->scroll_freeze < 0) sd->scroll_freeze = 0;
 }
 
 EAPI int
@@ -2297,10 +2297,10 @@ elm_widget_text_part_set(Evas_Object *obj, const char *part, const char *label)
 {
    API_ENTRY return;
 
-   if (!sd->on_text_set_func)
+   if (!sd->text_set_func)
      return;
 
-   sd->on_text_set_func(obj, part, label);
+   sd->text_set_func(obj, part, label);
 }
 
 EAPI const char *
@@ -2308,10 +2308,10 @@ elm_widget_text_part_get(const Evas_Object *obj, const char *part)
 {
    API_ENTRY return NULL;
 
-   if (!sd->on_text_get_func)
+   if (!sd->text_get_func)
      return NULL;
 
-   return sd->on_text_get_func(obj, part);
+   return sd->text_get_func(obj, part);
 }
 
 EAPI void
@@ -2415,8 +2415,8 @@ elm_widget_content_part_set(Evas_Object *obj, const char *part, Evas_Object *con
 {
    API_ENTRY return;
 
-   if (!sd->on_content_set_func)  return;
-   sd->on_content_set_func(obj, part, content);
+   if (!sd->content_set_func)  return;
+   sd->content_set_func(obj, part, content);
 }
 
 EAPI Evas_Object *
@@ -2424,8 +2424,8 @@ elm_widget_content_part_get(const Evas_Object *obj, const char *part)
 {
    API_ENTRY return NULL;
 
-   if (!sd->on_content_get_func) return NULL;
-   return sd->on_content_get_func(obj, part);
+   if (!sd->content_get_func) return NULL;
+   return sd->content_get_func(obj, part);
 }
 
 EAPI Evas_Object *
@@ -2433,8 +2433,8 @@ elm_widget_content_part_unset(Evas_Object *obj, const char *part)
 {
    API_ENTRY return NULL;
 
-   if (!sd->on_content_unset_func) return NULL;
-   return sd->on_content_unset_func(obj, part);
+   if (!sd->content_unset_func) return NULL;
+   return sd->content_unset_func(obj, part);
 }
 
 EAPI void
@@ -2637,6 +2637,50 @@ elm_widget_type_check(const Evas_Object *obj,
    return EINA_FALSE;
 }
 
+static Evas_Object *
+_widget_name_find(const Evas_Object *obj, const char *name, int recurse)
+{
+   Eina_List *l;
+   Evas_Object *child;
+   const char *s;
+   INTERNAL_ENTRY NULL;
+   
+   if (!_elm_widget_is(obj)) return NULL;
+   if (sd->resize_obj)
+     {
+        s = evas_object_name_get(sd->resize_obj);
+        if ((s) && (!strcmp(s, name))) return sd->resize_obj;
+        if ((recurse != 0) && 
+            ((child = _widget_name_find(sd->resize_obj, name, recurse - 1))))
+          return child;
+     }
+   EINA_LIST_FOREACH(sd->subobjs, l, child)
+     {
+        s = evas_object_name_get(child);
+        if ((s) && (!strcmp(s, name))) return child;
+        if ((recurse != 0) && 
+            ((child = _widget_name_find(child, name, recurse - 1))))
+          return child;
+     }
+   if (sd->hover_obj)
+     {
+        s = evas_object_name_get(sd->hover_obj);
+        if ((s) && (!strcmp(s, name))) return sd->hover_obj;
+        if ((recurse != 0) && 
+            ((child = _widget_name_find(sd->hover_obj, name, recurse - 1))))
+          return child;
+     }
+   return NULL;
+}
+
+EAPI Evas_Object *
+elm_widget_name_find(const Evas_Object *obj, const char *name, int recurse)
+{
+   API_ENTRY return NULL;
+   if (!name) return NULL;
+   return _widget_name_find(obj, name, recurse);
+}
+
 /**
  * @internal
  *
@@ -2782,8 +2826,11 @@ _elm_widget_item_del(Elm_Widget_Item *item)
 {
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
 
-   if (item->del_cb)
-     item->del_cb((void *)item->data, item->widget, item);
+   if (item->del_func)
+     item->del_func((void *)item->data, item->widget, item);
+
+   if (item->del_pre_func)
+     item->del_pre_func((Elm_Object_Item *) item);
 
    if (item->view)
      evas_object_del(item->view);
@@ -2807,6 +2854,27 @@ _elm_widget_item_del(Elm_Widget_Item *item)
 /**
  * @internal
  *
+ * Set the function to notify to widgets when item is being deleted by user.
+ *
+ * This function will complain if there was a callback set already,
+ * however it will set the new one.
+ *
+ * @param item a valid #Elm_Widget_Item to be notified
+ * @see elm_widget_item_del_pre_hook_set() convenience macro.
+ * @ingroup Widget
+ */
+EAPI void
+_elm_widget_item_del_pre_hook_set(Elm_Widget_Item *item, Elm_Widget_Item_Del_Pre_Cb func)
+{
+   ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
+   if ((item->del_pre_func) && (item->del_pre_func != func))
+     WRN("You're replacing a previously set del_pre_cb %p of item %p with %p", item->del_pre_func, item, func);
+   item->del_pre_func = func;
+}
+
+/**
+ * @internal
+ *
  * Notify object will be deleted without actually deleting it.
  *
  * This function will callback Elm_Widget_Item::del_cb if it is set
@@ -2821,9 +2889,9 @@ EAPI void
 _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
 {
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
-   if (!item->del_cb) return;
-   item->del_cb((void *)item->data, item->widget, item);
-   item->del_cb = NULL;
+   if (!item->del_func) return;
+   item->del_func((void *)item->data, item->widget, item);
+   item->del_func = NULL;
 }
 
 /**
@@ -2846,15 +2914,15 @@ _elm_widget_item_pre_notify_del(Elm_Widget_Item *item)
  */
 EAPI void
 _elm_widget_item_del_cb_set(Elm_Widget_Item *item,
-                            Evas_Smart_Cb    del_cb)
+                            Evas_Smart_Cb    func)
 {
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
 
-   if ((item->del_cb) && (item->del_cb != del_cb))
+   if ((item->del_func) && (item->del_func != func))
      WRN("You're replacing a previously set del_cb %p of item %p with %p",
-         item->del_cb, item, del_cb);
+         item->del_func, item, func);
 
-   item->del_cb = del_cb;
+   item->del_func = func;
 }
 
 /**
@@ -2916,7 +2984,7 @@ _elm_widget_item_disabled_get(const Elm_Widget_Item *item)
 
 EAPI void
 _elm_widget_item_disable_set_hook_set(Elm_Widget_Item *item,
-                                      Elm_Widget_On_Disable_Set_Cb func)
+                                      Elm_Widget_Disable_Set_Cb func)
 {
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
    item->disable_func = func;
@@ -3286,8 +3354,8 @@ _elm_widget_item_content_part_set(Elm_Widget_Item *item,
                                  Evas_Object *content)
 {
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
-   if (!item->on_content_set_func) return;
-   item->on_content_set_func((Elm_Object_Item *) item, part, content);
+   if (!item->content_set_func) return;
+   item->content_set_func((Elm_Object_Item *) item, part, content);
 }
 
 EAPI Evas_Object *
@@ -3295,8 +3363,8 @@ _elm_widget_item_content_part_get(const Elm_Widget_Item *item,
                                   const char *part)
 {
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
-   if (!item->on_content_get_func) return NULL;
-   return item->on_content_get_func((Elm_Object_Item *) item, part);
+   if (!item->content_get_func) return NULL;
+   return item->content_get_func((Elm_Object_Item *) item, part);
 }
 
 EAPI Evas_Object *
@@ -3304,8 +3372,8 @@ _elm_widget_item_content_part_unset(Elm_Widget_Item *item,
                                     const char *part)
 {
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
-   if (!item->on_content_unset_func) return NULL;
-   return item->on_content_unset_func((Elm_Object_Item *) item, part);
+   if (!item->content_unset_func) return NULL;
+   return item->content_unset_func((Elm_Object_Item *) item, part);
 }
 
 EAPI void
@@ -3314,8 +3382,8 @@ _elm_widget_item_text_part_set(Elm_Widget_Item *item,
                               const char *label)
 {
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
-   if (!item->on_text_set_func) return;
-   item->on_text_set_func((Elm_Object_Item *) item, part, label);
+   if (!item->text_set_func) return;
+   item->text_set_func((Elm_Object_Item *) item, part, label);
 }
 
 EAPI void
@@ -3324,8 +3392,8 @@ _elm_widget_item_signal_emit(Elm_Widget_Item *item,
                              const char *source)
 {
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
-   if (item->on_signal_emit_func)
-     item->on_signal_emit_func((Elm_Object_Item *) item, emission, source);
+   if (item->signal_emit_func)
+     item->signal_emit_func((Elm_Object_Item *) item, emission, source);
 }
 
 EAPI const char *
@@ -3333,56 +3401,56 @@ _elm_widget_item_text_part_get(const Elm_Widget_Item *item,
                                const char *part)
 {
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL);
-   if (!item->on_text_get_func) return NULL;
-   return item->on_text_get_func((Elm_Object_Item *) item, part);
+   if (!item->text_get_func) return NULL;
+   return item->text_get_func((Elm_Object_Item *) item, part);
 }
 
 EAPI void
 _elm_widget_item_content_set_hook_set(Elm_Widget_Item *item,
-                                      Elm_Widget_On_Content_Set_Cb func)
+                                      Elm_Widget_Content_Set_Cb func)
 {
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
-   item->on_content_set_func = func;
+   item->content_set_func = func;
 }
 
 EAPI void
 _elm_widget_item_content_get_hook_set(Elm_Widget_Item *item,
-                                      Elm_Widget_On_Content_Get_Cb func)
+                                      Elm_Widget_Content_Get_Cb func)
 {
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
-   item->on_content_get_func = func;
+   item->content_get_func = func;
 }
 
 EAPI void
 _elm_widget_item_content_unset_hook_set(Elm_Widget_Item *item,
-                                        Elm_Widget_On_Content_Unset_Cb func)
+                                        Elm_Widget_Content_Unset_Cb func)
 {
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
-   item->on_content_unset_func = func;
+   item->content_unset_func = func;
 }
 
 EAPI void
 _elm_widget_item_text_set_hook_set(Elm_Widget_Item *item,
-                                   Elm_Widget_On_Text_Set_Cb func)
+                                   Elm_Widget_Text_Set_Cb func)
 {
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
-   item->on_text_set_func = func;
+   item->text_set_func = func;
 }
 
 EAPI void
 _elm_widget_item_text_get_hook_set(Elm_Widget_Item *item,
-                                   Elm_Widget_On_Text_Get_Cb func)
+                                   Elm_Widget_Text_Get_Cb func)
 {
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
-   item->on_text_get_func = func;
+   item->text_get_func = func;
 }
 
 EAPI void
 _elm_widget_item_signal_emit_hook_set(Elm_Widget_Item *item,
-                                      Elm_Widget_On_Signal_Emit_Cb func)
+                                      Elm_Widget_Signal_Emit_Cb func)
 {
    ELM_WIDGET_ITEM_CHECK_OR_RETURN(item);
-   item->on_signal_emit_func = func;
+   item->signal_emit_func = func;
 }
 
 EAPI void
@@ -3452,7 +3520,7 @@ _if_focused_revert(Evas_Object *obj,
    Evas_Object *newest = NULL;
    unsigned int newest_focus_order = 0;
 
-   INTERNAL_ENTRY
+   INTERNAL_ENTRY;
 
    if (!sd->focused) return;
    if (!sd->parent_obj) return;
@@ -3476,7 +3544,7 @@ _smart_del(Evas_Object *obj)
    Edje_Signal_Data *esd;
    Elm_Translate_String_Data *ts;
 
-   INTERNAL_ENTRY
+   INTERNAL_ENTRY;
 
    if (sd->del_pre_func) sd->del_pre_func(obj);
    if (sd->resize_obj)
@@ -3535,7 +3603,7 @@ _smart_move(Evas_Object *obj,
             Evas_Coord   x,
             Evas_Coord   y)
 {
-   INTERNAL_ENTRY
+   INTERNAL_ENTRY;
    sd->x = x;
    sd->y = y;
    _smart_reconfigure(sd);
@@ -3546,7 +3614,7 @@ _smart_resize(Evas_Object *obj,
               Evas_Coord   w,
               Evas_Coord   h)
 {
-   INTERNAL_ENTRY
+   INTERNAL_ENTRY;
    sd->w = w;
    sd->h = h;
    _smart_reconfigure(sd);
@@ -3557,7 +3625,7 @@ _smart_show(Evas_Object *obj)
 {
    Eina_List *list;
    Evas_Object *o;
-   INTERNAL_ENTRY
+   INTERNAL_ENTRY;
    if ((list = evas_object_smart_members_get(obj)))
      {
         EINA_LIST_FREE(list, o)
@@ -3573,7 +3641,7 @@ _smart_hide(Evas_Object *obj)
 {
    Eina_List *list;
    Evas_Object *o;
-   INTERNAL_ENTRY
+   INTERNAL_ENTRY;
 
    list = evas_object_smart_members_get(obj);
    EINA_LIST_FREE(list, o)
@@ -3592,7 +3660,7 @@ _smart_color_set(Evas_Object *obj,
 {
    Eina_List *list;
    Evas_Object *o;
-   INTERNAL_ENTRY
+   INTERNAL_ENTRY;
    if ((list = evas_object_smart_members_get(obj)))
      {
         EINA_LIST_FREE(list, o)
@@ -3609,7 +3677,7 @@ _smart_clip_set(Evas_Object *obj,
 {
    Eina_List *list;
    Evas_Object *o;
-   INTERNAL_ENTRY
+   INTERNAL_ENTRY;
    if ((list = evas_object_smart_members_get(obj)))
      {
         EINA_LIST_FREE(list, o)
@@ -3625,7 +3693,7 @@ _smart_clip_unset(Evas_Object *obj)
 {
    Eina_List *list;
    Evas_Object *o;
-   INTERNAL_ENTRY
+   INTERNAL_ENTRY;
    if ((list = evas_object_smart_members_get(obj)))
      {
         EINA_LIST_FREE(list, o)
@@ -3639,7 +3707,7 @@ _smart_clip_unset(Evas_Object *obj)
 static void
 _smart_calculate(Evas_Object *obj)
 {
-   INTERNAL_ENTRY
+   INTERNAL_ENTRY;
    if (sd->changed_func) sd->changed_func(obj);
 }
 
@@ -3688,7 +3756,7 @@ _sub_obj_tree_dump(const Evas_Object *obj,
    if (_elm_widget_is(obj))
      {
         Eina_List *l;
-        INTERNAL_ENTRY
+        INTERNAL_ENTRY;
         printf("+ %s(%p)\n",
                sd->type,
                obj);
@@ -3710,7 +3778,7 @@ _sub_obj_tree_dot_dump(const Evas_Object *obj,
 {
    if (!_elm_widget_is(obj))
      return;
-   INTERNAL_ENTRY
+   INTERNAL_ENTRY;
 
    Eina_Bool visible = evas_object_visible_get(obj);
    Eina_Bool disabled = elm_widget_disabled_get(obj);