Group overlay's size have same size as that of default overlay.
[framework/uifw/elementary.git] / src / lib / elm_layout.c
index e8fd384..6f14484 100644 (file)
@@ -19,27 +19,32 @@ struct _Subinfo
 {
    const char *part;
    Evas_Object *obj;
-   enum {
-     SWALLOW,
-     BOX_APPEND,
-     BOX_PREPEND,
-     BOX_INSERT_BEFORE,
-     BOX_INSERT_AT,
-     TABLE_PACK,
-     TEXT
-   } type;
-   union {
-      union {
-         const Evas_Object *reference;
-         unsigned int pos;
-      } box;
-      struct {
-         unsigned short col, row, colspan, rowspan;
-      } table;
-      struct {
-         const char *text;
-      } text;
-   } p;
+   enum
+     {
+        SWALLOW,
+        BOX_APPEND,
+        BOX_PREPEND,
+        BOX_INSERT_BEFORE,
+        BOX_INSERT_AT,
+        TABLE_PACK,
+        TEXT
+     } type;
+   union
+     {
+        union
+          {
+             const Evas_Object *reference;
+             unsigned int pos;
+          } box;
+        struct
+          {
+             unsigned short col, row, colspan, rowspan;
+          } table;
+        struct
+          {
+             const char *text;
+          } text;
+     } p;
 };
 
 struct _Part_Cursor
@@ -206,7 +211,7 @@ _part_cursor_part_apply(const Part_Cursor *pc)
 {
    elm_object_cursor_set(pc->obj, pc->cursor);
    elm_object_cursor_style_set(pc->obj, pc->style);
-   elm_object_cursor_engine_only_set(pc->obj, pc->engine_only);
+   elm_object_cursor_theme_search_enabled_set(pc->obj, pc->engine_only);
 }
 
 static Part_Cursor *
@@ -303,7 +308,7 @@ _parts_text_fix(Widget_Data *wd)
    EINA_LIST_FOREACH(wd->subs, l, si)
      {
         if (si->type == TEXT)
-          edje_object_part_text_set(wd->lay, si->part, si->p.text.text);
+          edje_object_part_text_escaped_set(wd->lay, si->part, si->p.text.text);
      }
 }
 
@@ -325,7 +330,7 @@ _elm_layout_label_set(Evas_Object *obj, const char *part, const char *text)
                   eina_stringshare_del(si->part);
                   eina_stringshare_del(si->p.text.text);
                   free(si);
-                  edje_object_part_text_set(wd->lay, part, NULL);
+                  edje_object_part_text_escaped_set(wd->lay, part, NULL);
                   wd->subs = eina_list_remove_list(wd->subs, l);
                   return;
                }
@@ -345,7 +350,7 @@ _elm_layout_label_set(Evas_Object *obj, const char *part, const char *text)
      }
 
    eina_stringshare_replace(&si->p.text.text, text);
-   edje_object_part_text_set(wd->lay, part, text);
+   edje_object_part_text_escaped_set(wd->lay, part, text);
    _request_sizing_eval(wd);
 }
 
@@ -358,6 +363,83 @@ _elm_layout_label_get(const Evas_Object *obj, const char *part)
    return edje_object_part_text_get(wd->lay, part);
 }
 
+static void
+_content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   Subinfo *si;
+   const Eina_List *l;
+   if (!wd) return;
+   EINA_SAFETY_ON_NULL_RETURN(part);
+   EINA_LIST_FOREACH(wd->subs, l, si)
+     {
+        if ((si->type == SWALLOW) && (!strcmp(part, si->part)))
+          {
+             if (content == si->obj) return;
+             evas_object_del(si->obj);
+             break;
+          }
+     }
+   if (content)
+     {
+        elm_widget_sub_object_add(obj, content);
+        evas_object_event_callback_add(content,
+                                       EVAS_CALLBACK_CHANGED_SIZE_HINTS,
+                                       _changed_size_hints, wd);
+        if (!edje_object_part_swallow(wd->lay, part, content))
+          WRN("could not swallow %p into part '%s'", content, part);
+        si = ELM_NEW(Subinfo);
+        si->type = SWALLOW;
+        si->part = eina_stringshare_add(part);
+        si->obj = content;
+        wd->subs = eina_list_append(wd->subs, si);
+     }
+   _request_sizing_eval(wd);
+}
+
+static Evas_Object *
+_content_get_hook(const Evas_Object *obj, const char *part)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   const Eina_List *l;
+   Subinfo *si;
+   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+
+   EINA_LIST_FOREACH(wd->subs, l, si)
+     {
+        if ((si->type == SWALLOW) && !strcmp(part, si->part))
+          return si->obj;
+     }
+   return NULL;
+}
+
+static Evas_Object *
+_content_unset_hook(Evas_Object *obj, const char *part)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   Subinfo *si;
+   const Eina_List *l;
+   if (!wd) return NULL;
+   EINA_LIST_FOREACH(wd->subs, l, si)
+     {
+        if ((si->type == SWALLOW) && (!strcmp(part, si->part)))
+          {
+             Evas_Object *content;
+             if (!si->obj) return NULL;
+             content = si->obj; /* si will die in _sub_del due elm_widget_sub_object_del() */
+             elm_widget_sub_object_del(obj, content);
+             evas_object_event_callback_del_full(content,
+                                                 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
+                                                 _changed_size_hints, wd);
+             edje_object_part_unswallow(wd->lay, content);
+             return content;
+          }
+     }
+   return NULL;
+}
+
 EAPI Evas_Object *
 elm_layout_add(Evas_Object *parent)
 {
@@ -381,6 +463,9 @@ elm_layout_add(Evas_Object *parent)
    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
    elm_widget_text_set_hook_set(obj, _elm_layout_label_set);
    elm_widget_text_get_hook_set(obj, _elm_layout_label_get);
+   elm_widget_content_set_hook_set(obj, _content_set_hook);
+   elm_widget_content_get_hook_set(obj, _content_get_hook);
+   elm_widget_content_unset_hook_set(obj, _content_unset_hook);
 
    wd->obj = obj;
    wd->lay = edje_object_add(e);
@@ -434,98 +519,13 @@ elm_layout_theme_set(Evas_Object *obj, const char *clas, const char *group, cons
    return ret;
 }
 
-EAPI void
-elm_layout_content_set(Evas_Object *obj, const char *swallow, Evas_Object *content)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype);
-   Widget_Data *wd = elm_widget_data_get(obj);
-   Subinfo *si;
-   const Eina_List *l;
-   if (!wd) return;
-   EINA_LIST_FOREACH(wd->subs, l, si)
-     {
-        if ((si->type == SWALLOW) && (!strcmp(swallow, si->part)))
-          {
-             if (content == si->obj) return;
-             evas_object_del(si->obj);
-             break;
-          }
-     }
-   if (content)
-     {
-        elm_widget_sub_object_add(obj, content);
-        evas_object_event_callback_add(content,
-                                       EVAS_CALLBACK_CHANGED_SIZE_HINTS,
-                                       _changed_size_hints, wd);
-        if (!edje_object_part_swallow(wd->lay, swallow, content))
-          WRN("could not swallow %p into part '%s'", content, swallow);
-        si = ELM_NEW(Subinfo);
-        si->type = SWALLOW;
-        si->part = eina_stringshare_add(swallow);
-        si->obj = content;
-        wd->subs = eina_list_append(wd->subs, si);
-     }
-   _request_sizing_eval(wd);
-}
-
-EAPI Evas_Object *
-elm_layout_content_get(const Evas_Object *obj, const char *swallow)
-{
-   Widget_Data *wd = elm_widget_data_get(obj);
-   const Eina_List *l;
-   Subinfo *si;
-   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
-
-   EINA_LIST_FOREACH(wd->subs, l, si)
-     {
-        if ((si->type == SWALLOW) && !strcmp(swallow, si->part))
-          return si->obj;
-     }
-   return NULL;
-}
-
-EAPI Evas_Object *
-elm_layout_content_unset(Evas_Object *obj, const char *swallow)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
-   Widget_Data *wd = elm_widget_data_get(obj);
-   Subinfo *si;
-   const Eina_List *l;
-   if (!wd) return NULL;
-   EINA_LIST_FOREACH(wd->subs, l, si)
-     {
-        if ((si->type == SWALLOW) && (!strcmp(swallow, si->part)))
-          {
-             Evas_Object *content;
-             if (!si->obj) return NULL;
-             content = si->obj; /* si will die in _sub_del due elm_widget_sub_object_del() */
-             elm_widget_sub_object_del(obj, content);
-             edje_object_part_unswallow(wd->lay, content);
-             return content;
-          }
-     }
-   return NULL;
-}
-
-EAPI void
-elm_layout_text_set(Evas_Object *obj, const char *part, const char *text)
-{
-   _elm_layout_label_set(obj, part, text);
-}
-
-EAPI const char *
-elm_layout_text_get(const Evas_Object *obj, const char *part)
-{
-   return _elm_layout_label_get(obj, part);
-}
-
-EAPI void
+EAPI Eina_Bool
 elm_layout_box_append(Evas_Object *obj, const char *part, Evas_Object *child)
 {
-   ELM_CHECK_WIDTYPE(obj, widtype);
+   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
    Widget_Data *wd = elm_widget_data_get(obj);
    Subinfo *si;
-   if (!wd) return;
+   if (!wd) return EINA_FALSE;
 
    if (!edje_object_part_box_append(wd->lay, part, child))
      WRN("child %p could not be appended to box part '%s'", child, part);
@@ -539,15 +539,17 @@ elm_layout_box_append(Evas_Object *obj, const char *part, Evas_Object *child)
    si->obj = child;
    wd->subs = eina_list_append(wd->subs, si);
    _request_sizing_eval(wd);
+
+   return EINA_TRUE;
 }
 
-EAPI void
+EAPI Eina_Bool
 elm_layout_box_prepend(Evas_Object *obj, const char *part, Evas_Object *child)
 {
-   ELM_CHECK_WIDTYPE(obj, widtype);
+   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
    Widget_Data *wd = elm_widget_data_get(obj);
    Subinfo *si;
-   if (!wd) return;
+   if (!wd) return EINA_FALSE;
 
    if (!edje_object_part_box_prepend(wd->lay, part, child))
      WRN("child %p could not be prepended to box part '%s'", child, part);
@@ -561,6 +563,8 @@ elm_layout_box_prepend(Evas_Object *obj, const char *part, Evas_Object *child)
    si->obj = child;
    wd->subs = eina_list_prepend(wd->subs, si);
    _request_sizing_eval(wd);
+
+   return EINA_TRUE;
 }
 
 static void
@@ -570,13 +574,13 @@ _box_reference_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
    si->p.box.reference = NULL;
 }
 
-EAPI void
+EAPI Eina_Bool
 elm_layout_box_insert_before(Evas_Object *obj, const char *part, Evas_Object *child, const Evas_Object *reference)
 {
-   ELM_CHECK_WIDTYPE(obj, widtype);
+   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
    Widget_Data *wd = elm_widget_data_get(obj);
    Subinfo *si;
-   if (!wd) return;
+   if (!wd) return EINA_FALSE;
 
    if (!edje_object_part_box_insert_before(wd->lay, part, child, reference))
      WRN("child %p could not be inserted before %p inf box part '%s'",
@@ -596,15 +600,17 @@ elm_layout_box_insert_before(Evas_Object *obj, const char *part, Evas_Object *ch
 
    wd->subs = eina_list_append(wd->subs, si);
    _request_sizing_eval(wd);
+
+   return EINA_TRUE;
 }
 
-EAPI void
+EAPI Eina_Bool
 elm_layout_box_insert_at(Evas_Object *obj, const char *part, Evas_Object *child, unsigned int pos)
 {
-   ELM_CHECK_WIDTYPE(obj, widtype);
+   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
    Widget_Data *wd = elm_widget_data_get(obj);
    Subinfo *si;
-   if (!wd) return;
+   if (!wd) return EINA_FALSE;
 
    if (!edje_object_part_box_insert_at(wd->lay, part, child, pos))
      WRN("child %p could not be inserted at %u to box part '%s'",
@@ -621,6 +627,8 @@ elm_layout_box_insert_at(Evas_Object *obj, const char *part, Evas_Object *child,
    si->p.box.pos = pos;
    wd->subs = eina_list_append(wd->subs, si);
    _request_sizing_eval(wd);
+
+   return EINA_TRUE;
 }
 
 static Evas_Object *
@@ -686,16 +694,16 @@ elm_layout_box_remove(Evas_Object *obj, const char *part, Evas_Object *child)
    return NULL;
 }
 
-EAPI void
+EAPI Eina_Bool
 elm_layout_box_remove_all(Evas_Object *obj, const char *part, Eina_Bool clear)
 {
-   ELM_CHECK_WIDTYPE(obj, widtype);
+   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
    Widget_Data *wd = elm_widget_data_get(obj);
    Subinfo *si;
    Eina_List *lst;
 
-   if (!wd) return;
-   EINA_SAFETY_ON_NULL_RETURN(part);
+   if (!wd) return EINA_FALSE;
+   EINA_SAFETY_ON_NULL_RETURN_VAL(part, EINA_FALSE);
 
    lst = eina_list_clone(wd->subs);
    EINA_LIST_FREE(lst, si)
@@ -709,15 +717,17 @@ elm_layout_box_remove_all(Evas_Object *obj, const char *part, Eina_Bool clear)
      }
    /* eventually something may not be added with layout, del them as well */
    edje_object_part_box_remove_all(wd->lay, part, clear);
+
+   return EINA_TRUE;
 }
 
-EAPI void
+EAPI Eina_Bool
 elm_layout_table_pack(Evas_Object *obj, const char *part, Evas_Object *child, unsigned short col, unsigned short row, unsigned short colspan, unsigned short rowspan)
 {
-   ELM_CHECK_WIDTYPE(obj, widtype);
+   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
    Widget_Data *wd = elm_widget_data_get(obj);
    Subinfo *si;
-   if (!wd) return;
+   if (!wd) return EINA_FALSE;
 
    if (!edje_object_part_table_pack
        (wd->lay, part, child, col, row, colspan, rowspan))
@@ -738,6 +748,8 @@ elm_layout_table_pack(Evas_Object *obj, const char *part, Evas_Object *child, un
    si->p.table.rowspan = rowspan;
    wd->subs = eina_list_append(wd->subs, si);
    _request_sizing_eval(wd);
+
+   return EINA_TRUE;
 }
 
 EAPI Evas_Object *
@@ -761,16 +773,16 @@ elm_layout_table_unpack(Evas_Object *obj, const char *part, Evas_Object *child)
    return NULL;
 }
 
-EAPI void
+EAPI Eina_Bool
 elm_layout_table_clear(Evas_Object *obj, const char *part, Eina_Bool clear)
 {
-   ELM_CHECK_WIDTYPE(obj, widtype);
+   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
    Widget_Data *wd = elm_widget_data_get(obj);
    Subinfo *si;
    Eina_List *lst;
 
-   if (!wd) return;
-   EINA_SAFETY_ON_NULL_RETURN(part);
+   if (!wd) return EINA_FALSE;
+   EINA_SAFETY_ON_NULL_RETURN_VAL(part, EINA_FALSE);
 
    lst = eina_list_clone(wd->subs);
    EINA_LIST_FREE(lst, si)
@@ -784,6 +796,8 @@ elm_layout_table_clear(Evas_Object *obj, const char *part, Eina_Bool clear)
      }
    /* eventually something may not be added with layout, del them as well */
    edje_object_part_table_clear(wd->lay, part, clear);
+
+   return EINA_TRUE;
 }
 
 EAPI Evas_Object *
@@ -812,18 +826,6 @@ elm_layout_sizing_eval(Evas_Object *obj)
    _request_sizing_eval(wd);
 }
 
-/**
- * Sets a specific cursor for an edje part.
- *
- * @param obj The layout object.
- * @param part_name a part from loaded edje group.
- * @param cursor cursor name to use, see Elementary_Cursor.h
- *
- * @return EINA_TRUE on success or EINA_FALSE on failure, that may be
- *         part not exists or it has "mouse_events: 0".
- *
- * @ingroup Layout
- */
 EAPI Eina_Bool
 elm_layout_part_cursor_set(Evas_Object *obj, const char *part_name, const char *cursor)
 {
@@ -860,6 +862,8 @@ elm_layout_part_cursor_set(Evas_Object *obj, const char *part_name, const char *
         pc = calloc(1, sizeof(*pc));
         pc->part = eina_stringshare_add(part_name);
         pc->cursor = eina_stringshare_add(cursor);
+        pc->style = eina_stringshare_add("default");
+        wd->parts_cursors = eina_list_append(wd->parts_cursors, pc);
      }
 
    pc->obj = part_obj;
@@ -867,15 +871,6 @@ elm_layout_part_cursor_set(Evas_Object *obj, const char *part_name, const char *
    return EINA_TRUE;
 }
 
-/**
- * Get the cursor to be shown when mouse is over an edje part
- *
- * @param obj The layout object.
- * @param part_name a part from loaded edje group.
- * @return the cursor name.
- *
- * @ingroup Layout
- */
 EAPI const char *
 elm_layout_part_cursor_get(const Evas_Object *obj, const char *part_name)
 {
@@ -889,22 +884,13 @@ elm_layout_part_cursor_get(const Evas_Object *obj, const char *part_name)
    return elm_object_cursor_get(pc->obj);
 }
 
-/**
- * Unsets a cursor previously set with elm_layout_part_cursor_set().
- *
- * @param obj The layout object.
- * @param part_name a part from loaded edje group, that had a cursor set
- *        with elm_layout_part_cursor_set().
- *
- * @ingroup Layout
- */
-EAPI void
+EAPI Eina_Bool
 elm_layout_part_cursor_unset(Evas_Object *obj, const char *part_name)
 {
-   ELM_CHECK_WIDTYPE(obj, widtype);
-   EINA_SAFETY_ON_NULL_RETURN(part_name);
+   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
+   EINA_SAFETY_ON_NULL_RETURN_VAL(part_name, EINA_FALSE);
    Widget_Data *wd = elm_widget_data_get(obj);
-   EINA_SAFETY_ON_NULL_RETURN(wd);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
    Eina_List *l;
    Part_Cursor *pc;
 
@@ -915,23 +901,13 @@ elm_layout_part_cursor_unset(Evas_Object *obj, const char *part_name)
              if (pc->obj) elm_object_cursor_unset(pc->obj);
              _part_cursor_free(pc);
              wd->parts_cursors = eina_list_remove_list(wd->parts_cursors, l);
-             return;
+             return EINA_TRUE;
           }
      }
+
+   return EINA_FALSE;
 }
 
-/**
- * Sets a specific cursor style for an edje part.
- *
- * @param obj The layout object.
- * @param part_name a part from loaded edje group.
- * @param style the theme style to use (default, transparent, ...)
- *
- * @return EINA_TRUE on success or EINA_FALSE on failure, that may be
- *         part not exists or it did not had a cursor set.
- *
- * @ingroup Layout
- */
 EAPI Eina_Bool
 elm_layout_part_cursor_style_set(Evas_Object *obj, const char *part_name, const char *style)
 {
@@ -948,17 +924,6 @@ elm_layout_part_cursor_style_set(Evas_Object *obj, const char *part_name, const
    return EINA_TRUE;
 }
 
-/**
- * Gets a specific cursor style for an edje part.
- *
- * @param obj The layout object.
- * @param part_name a part from loaded edje group.
- *
- * @return the theme style in use, defaults to "default". If the
- *         object does not have a cursor set, then NULL is returned.
- *
- * @ingroup Layout
- */
 EAPI const char *
 elm_layout_part_cursor_style_get(const Evas_Object *obj, const char *part_name)
 {
@@ -972,24 +937,6 @@ elm_layout_part_cursor_style_get(const Evas_Object *obj, const char *part_name)
    return elm_object_cursor_style_get(pc->obj);
 }
 
-/**
- * Sets if the cursor set should be searched on the theme or should use
- * the provided by the engine, only.
- *
- * @note before you set if should look on theme you should define a
- * cursor with elm_layout_part_cursor_set(). By default it will only
- * look for cursors provided by the engine.
- *
- * @param obj The layout object.
- * @param part_name a part from loaded edje group.
- * @param engine_only if cursors should be just provided by the engine
- *        or should also search on widget's theme as well
- *
- * @return EINA_TRUE on success or EINA_FALSE on failure, that may be
- *         part not exists or it did not had a cursor set.
- *
- * @ingroup Layout
- */
 EAPI Eina_Bool
 elm_layout_part_cursor_engine_only_set(Evas_Object *obj, const char *part_name, Eina_Bool engine_only)
 {
@@ -1002,20 +949,10 @@ elm_layout_part_cursor_engine_only_set(Evas_Object *obj, const char *part_name,
    EINA_SAFETY_ON_NULL_RETURN_VAL(pc->obj, EINA_FALSE);
 
    pc->engine_only = !!engine_only;
-   elm_object_cursor_engine_only_set(pc->obj, pc->engine_only);
+   elm_object_cursor_theme_search_enabled_set(pc->obj, pc->engine_only);
    return EINA_TRUE;
 }
 
-/**
- * Gets a specific cursor engine_only for an edje part.
- *
- * @param obj The layout object.
- * @param part_name a part from loaded edje group.
- *
- * @return whenever the cursor is just provided by engine or also from theme.
- *
- * @ingroup Layout
- */
 EAPI Eina_Bool
 elm_layout_part_cursor_engine_only_get(const Evas_Object *obj, const char *part_name)
 {
@@ -1026,5 +963,5 @@ elm_layout_part_cursor_engine_only_get(const Evas_Object *obj, const char *part_
    Part_Cursor *pc = _parts_cursors_find(wd, part_name);
    EINA_SAFETY_ON_NULL_RETURN_VAL(pc, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(pc->obj, EINA_FALSE);
-   return elm_object_cursor_engine_only_get(pc->obj);
+   return elm_object_cursor_theme_search_enabled_get(pc->obj);
 }