[genlist] apply r71140 with local enhancement
[framework/uifw/elementary.git] / src / lib / elm_bg.c
index 9c2bef8..df29d5b 100644 (file)
@@ -1,13 +1,6 @@
 #include <Elementary.h>
 #include "elm_priv.h"
 
-/**
- * @defgroup Bg Bg
- *
- * The bg object is used for setting a solid background to a window or packing
- * into any container object.
- */
-
 typedef struct _Widget_Data Widget_Data;
 
 struct _Widget_Data
@@ -15,9 +8,10 @@ struct _Widget_Data
    Evas_Object *base, *rect, *img, *overlay;
    const char  *file, *group;
    Elm_Bg_Option option;
-   struct {
-      Evas_Coord w, h;
-   } load_opts;
+   struct
+     {
+        Evas_Coord w, h;
+     } load_opts;
 };
 
 static const char *widtype = NULL;
@@ -25,6 +19,9 @@ static const char *widtype = NULL;
 static void _del_hook(Evas_Object *obj);
 static void _theme_hook(Evas_Object *obj);
 static void _custom_resize(void *data, Evas *a, Evas_Object *obj, void *event_info);
+static void _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content);
+static Evas_Object *_content_get_hook(const Evas_Object *obj, const char *part);
+static Evas_Object *_content_unset_hook(Evas_Object *obj, const char *part);
 
 static void
 _del_hook(Evas_Object *obj)
@@ -39,7 +36,7 @@ _theme_hook(Evas_Object *obj)
    Widget_Data *wd = elm_widget_data_get(obj);
    Evas_Coord w, h;
 
-   _elm_theme_object_set(obj, wd->base, "bg", "base", 
+   _elm_theme_object_set(obj, wd->base, "bg", "base",
                          elm_widget_style_get(obj));
 
    if (wd->rect)
@@ -49,7 +46,7 @@ _theme_hook(Evas_Object *obj)
    if (wd->overlay)
      edje_object_part_swallow(wd->base, "elm.swallow.content", wd->overlay);
 
-   // FIXME: if i don't do this, bg doesnt calc correctly. why?   
+   // FIXME: if i don't do this, bg doesnt calc correctly. why?
    evas_object_geometry_get(wd->base, NULL, NULL, &w, &h);
    evas_object_resize(wd->base, w, h);
 }
@@ -80,7 +77,7 @@ _custom_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void
    nw = bw;
    nh = bh;
 
-   switch (wd->option) 
+   switch (wd->option)
      {
       case ELM_BG_OPTION_CENTER:
          fw = nw = iw;
@@ -120,14 +117,56 @@ _custom_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void
    evas_object_size_hint_max_set(wd->img, mw, mh);
 }
 
-/**
- * Add a new background to the parent
- *
- * @param parent The parent object
- * @return The new object or NULL if it cannot be created
- *
- * @ingroup Bg
- */
+static void
+_content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd;
+   if (part && strcmp(part, "overlay")) return;
+   wd = elm_widget_data_get(obj);
+   if (!wd) return;
+
+   if (content == wd->overlay) return;
+   if (wd->overlay) evas_object_del(wd->overlay);
+
+   wd->overlay = content;
+   if (content)
+     {
+        edje_object_part_swallow(wd->base, "elm.swallow.content", content);
+        elm_widget_sub_object_add(obj, content);
+     }
+
+   _custom_resize(wd, NULL, NULL, NULL);
+}
+
+static Evas_Object *
+_content_get_hook(const Evas_Object *obj, const char *part)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+   Widget_Data *wd;
+   if (part && strcmp(part, "overlay")) return NULL;
+   wd = elm_widget_data_get(obj);
+   if (!wd) return NULL;
+   return wd->overlay;
+}
+
+static Evas_Object *
+_content_unset_hook(Evas_Object *obj, const char *part)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+   Widget_Data *wd;
+   Evas_Object *overlay;
+   if (part && strcmp(part, "overlay")) return NULL;
+   wd = elm_widget_data_get(obj);
+   if (!wd || !wd->overlay) return NULL;
+   overlay = wd->overlay;
+   elm_widget_sub_object_del(obj, wd->overlay);
+   edje_object_part_unswallow(wd->base, wd->overlay);
+   wd->overlay = NULL;
+   _custom_resize(wd, NULL, NULL, NULL);
+   return overlay;
+}
+
 EAPI Evas_Object *
 elm_bg_add(Evas_Object *parent)
 {
@@ -143,39 +182,27 @@ elm_bg_add(Evas_Object *parent)
    elm_widget_data_set(obj, wd);
    elm_widget_del_hook_set(obj, _del_hook);
    elm_widget_theme_hook_set(obj, _theme_hook);
+   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);
+
    elm_widget_can_focus_set(obj, EINA_FALSE);
 
    wd->base = edje_object_add(e);
    _elm_theme_object_set(obj, wd->base, "bg", "base", "default");
    elm_widget_resize_object_set(obj, wd->base);
 
-   evas_object_event_callback_add(wd->base, EVAS_CALLBACK_RESIZE, 
+   evas_object_event_callback_add(wd->base, EVAS_CALLBACK_RESIZE,
                                   _custom_resize, wd);
 
    wd->option = ELM_BG_OPTION_SCALE;
    return obj;
 }
 
-/**
- * Set the file (image or edje) used for the background
- *
- * @param obj The bg object
- * @param file The file path
- * @param group Optional key (group in Edje) within the file
- *
- * This sets the image file used in the background object. The image (or edje)
- * will be stretched (retaining aspect if its an image file) to completely fill
- * the bg object. This may mean some parts are not visible.
- *
- * @note  Once the image of @p obj is set, a previously set one will be deleted,
- * even if @p file is NULL.
- *
- * @ingroup Bg
- */
-EAPI void
+EAPI Eina_Bool
 elm_bg_file_set(Evas_Object *obj, const char *file, const char *group)
 {
-   ELM_CHECK_WIDTYPE(obj, widtype);
+   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
    Widget_Data *wd = elm_widget_data_get(obj);
    const char *p;
 
@@ -190,7 +217,7 @@ elm_bg_file_set(Evas_Object *obj, const char *file, const char *group)
         wd->file = NULL;
         eina_stringshare_del(wd->group);
         wd->group = NULL;
-        return;
+        return EINA_TRUE;
      }
    eina_stringshare_replace(&wd->file, file);
    eina_stringshare_replace(&wd->group, group);
@@ -210,17 +237,10 @@ elm_bg_file_set(Evas_Object *obj, const char *file, const char *group)
    edje_object_part_swallow(wd->base, "elm.swallow.background", wd->img);
    elm_widget_sub_object_add(obj, wd->img);
    _custom_resize(wd, NULL, NULL, NULL);
+
+   return EINA_TRUE;
 }
 
-/**
- * Get the file (image or edje) used for the background
- *
- * @param obj The bg object
- * @param file The file path
- * @param group Optional key (group in Edje) within the file
- *
- * @ingroup Bg
- */
 EAPI void
 elm_bg_file_get(const Evas_Object *obj, const char **file, const char **group)
 {
@@ -228,21 +248,12 @@ elm_bg_file_get(const Evas_Object *obj, const char **file, const char **group)
    Widget_Data *wd = elm_widget_data_get(obj);
    if (file) *file = wd->file;
    if (group) *group = wd->group;
+
+   return;
 }
 
-/**
- * Set the option used for the background image
- *
- * @param obj The bg object
- * @param option The desired background option (TILE, SCALE)
- *
- * This sets the option used for manipulating the display of the background 
- * image. The image can be tiled or scaled.
- *
- * @ingroup Bg
- */
-EAPI void 
-elm_bg_option_set(Evas_Object *obj, Elm_Bg_Option option) 
+EAPI void
+elm_bg_option_set(Evas_Object *obj, Elm_Bg_Option option)
 {
    ELM_CHECK_WIDTYPE(obj, widtype);
    Widget_Data *wd;
@@ -250,40 +261,22 @@ elm_bg_option_set(Evas_Object *obj, Elm_Bg_Option option)
    wd = elm_widget_data_get(obj);
    wd->option = option;
    _custom_resize(wd, NULL, NULL, NULL);
+
+   return;
 }
 
-/**
- * Get the option used for the background image
- *
- * @param obj The bg object
- * @return The desired background option (TILE, SCALE)
- *
- * @ingroup Bg
- */
 EAPI Elm_Bg_Option
 elm_bg_option_get(const Evas_Object *obj)
 {
-   ELM_CHECK_WIDTYPE(obj, widtype) 0;
+   ELM_CHECK_WIDTYPE(obj, widtype) ELM_BG_OPTION_LAST;
    Widget_Data *wd;
 
    wd = elm_widget_data_get(obj);
    return wd->option;
 }
 
-/**
- * Set the option used for the background color
- *
- * @param obj The bg object
- * @param r
- * @param g
- * @param b
- *
- * This sets the color used for the background rectangle.
- *
- * @ingroup Bg
- */
-EAPI void 
-elm_bg_color_set(Evas_Object *obj, int r, int g, int b) 
+EAPI void
+elm_bg_color_set(Evas_Object *obj, int r, int g, int b)
 {
    ELM_CHECK_WIDTYPE(obj, widtype);
    Widget_Data *wd;
@@ -297,18 +290,10 @@ elm_bg_color_set(Evas_Object *obj, int r, int g, int b)
         _custom_resize(wd, NULL, NULL, NULL);
      }
    evas_object_color_set(wd->rect, r, g, b, 255);
+
+   return;
 }
 
-/**
- * Get the option used for the background color
- *
- * @param obj The bg object
- * @param r
- * @param g
- * @param b
- *
- * @ingroup Bg
- */
 EAPI void
 elm_bg_color_get(const Evas_Object *obj, int *r, int *g, int *b)
 {
@@ -317,97 +302,10 @@ elm_bg_color_get(const Evas_Object *obj, int *r, int *g, int *b)
 
    wd = elm_widget_data_get(obj);
    evas_object_color_get(wd->rect, r, g, b, NULL);
-}
 
-/**
- * Set the overlay object used for the background object.
- *
- * @param obj The bg object
- * @param overlay The overlay object
- *
- * This provides a way for elm_bg to have an 'overlay' (such as animated fog)
- * Once the over object is set, a previously set one will be deleted.
- * If you want to keep that old content object, use the
- * elm_bg_overlay_unset() function.
- *
- * @ingroup Bg
- */
-EAPI void
-elm_bg_overlay_set(Evas_Object *obj, Evas_Object *overlay)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype);
-   Widget_Data *wd = elm_widget_data_get(obj);
-   if (!wd) return;
-   if (wd->overlay)
-     {
-        evas_object_del(wd->overlay);
-        wd->overlay = NULL;
-     }
-   if (overlay)
-     {
-        wd->overlay = overlay;
-        edje_object_part_swallow(wd->base, "elm.swallow.content", wd->overlay);
-        elm_widget_sub_object_add(obj, wd->overlay);
-     }
-
-   _custom_resize(wd, NULL, NULL, NULL);
+   return;
 }
 
-/**
- * Set the overlay object used for the background object.
- *
- * @param obj The bg object
- * @return The content that is being used
- *
- * Return the content object which is set for this widget
- *
- * @ingroup Bg
- */
-EAPI Evas_Object *
-elm_bg_overlay_get(const Evas_Object *obj)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
-   Widget_Data *wd = elm_widget_data_get(obj);
-   if (!wd) return NULL;
-   return wd->overlay;
-}
-
-/**
- * Get the overlay object used for the background object.
- *
- * @param obj The bg object
- * @return The content that was being used
- *
- * Unparent and return the overlay object which was set for this widget
- *
- * @ingroup Bg
- */
-EAPI Evas_Object *
-elm_bg_overlay_unset(Evas_Object *obj)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
-   Widget_Data *wd = elm_widget_data_get(obj);
-   Evas_Object *overlay;
-   if (!wd) return NULL;
-   if (!wd->overlay) return NULL;
-   overlay = wd->overlay;
-   elm_widget_sub_object_del(obj, wd->overlay);
-   edje_object_part_unswallow(wd->base, wd->overlay);
-   wd->overlay = NULL;
-   _custom_resize(wd, NULL, NULL, NULL);
-   return overlay;
-}
-
-/**
- * Set the size of a loaded image of the canvas of the bg.
- *
- * @param obj The bg object
- * @param w The new width of the canvas image given.
- * @param h The new height of the canvas image given.
- *
- * This function sets a new size for the canvas image of the given the bg.
- *
- */
 EAPI void
 elm_bg_load_size_set(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
 {
@@ -420,5 +318,7 @@ elm_bg_load_size_set(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
    if (!wd->img) return;
    if (!(((p = strrchr(wd->file, '.'))) && (!strcasecmp(p, ".edj"))))
      evas_object_image_load_size_set(wd->img, w, h);
+
+   return;
 }