3 #include <Elementary.h>
10 * The bg object is used for setting a solid background to a window or packing
11 * into any container object.
14 typedef struct _Widget_Data Widget_Data;
18 Evas_Object *img, *custom_img;
19 const char *file, *group;
22 static const char *widtype = NULL;
23 static void _del_hook(Evas_Object *obj);
24 static void _theme_hook(Evas_Object *obj);
25 static void _custom_resize(void *data, Evas *a, Evas_Object *obj, void *event_info);
28 _del_hook(Evas_Object *obj)
30 Widget_Data *wd = elm_widget_data_get(obj);
35 _theme_hook(Evas_Object *obj)
37 Widget_Data *wd = elm_widget_data_get(obj);
38 _elm_theme_object_set(obj, wd->img, "bg", "base", elm_widget_style_get(obj));
42 _custom_resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
45 Evas_Coord x, y, w, h, ow = 0, oh = 0;
47 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
48 evas_object_image_size_get(obj, &iw, &ih);
50 if ((iw < 1) || (ih < 1)) return;
60 evas_object_image_fill_set(obj, x, y, w, h);
64 * Add a new background to the parent
66 * @param parent The parent object
67 * @return The new object or NULL if it cannot be created
72 elm_bg_add(Evas_Object *parent)
78 wd = ELM_NEW(Widget_Data);
79 e = evas_object_evas_get(parent);
80 obj = elm_widget_add(e);
81 ELM_SET_WIDTYPE(widtype, "bg");
82 elm_widget_type_set(obj, "bg");
83 elm_widget_sub_object_add(parent, obj);
84 elm_widget_data_set(obj, wd);
85 elm_widget_del_hook_set(obj, _del_hook);
86 elm_widget_theme_hook_set(obj, _theme_hook);
87 elm_widget_can_focus_set(obj, 0);
89 wd->img = edje_object_add(e);
90 _elm_theme_object_set(obj, wd->img, "bg", "base", "default");
91 elm_widget_resize_object_set(obj, wd->img);
96 * Set the file (image or edje) used for the background
98 * @param obj The bg object
99 * @param file The file path
100 * @param group Optional key (group in Edje) within the file
102 * This sets the image file used in the background object. The image (or edje)
103 * will be stretched (retaining aspect if its an image file) to completely fill
104 * the bg object. This may mean some parts arte not visible.
109 elm_bg_file_set(Evas_Object *obj, const char *file, const char *group)
111 ELM_CHECK_WIDTYPE(obj, widtype);
112 Widget_Data *wd = elm_widget_data_get(obj);
117 evas_object_del(wd->custom_img);
118 wd->custom_img = NULL;
121 eina_stringshare_replace(&wd->file, file);
122 eina_stringshare_replace(&wd->group, group);
123 if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
125 wd->custom_img = edje_object_add(evas_object_evas_get(wd->img));
126 edje_object_file_set(wd->custom_img, file, group);
130 wd->custom_img = evas_object_image_add(evas_object_evas_get(wd->img));
131 evas_object_event_callback_add(wd->custom_img, EVAS_CALLBACK_RESIZE,
133 evas_object_image_file_set(wd->custom_img, file, group);
135 elm_widget_sub_object_add(obj, wd->custom_img);
136 evas_object_repeat_events_set(wd->custom_img, 1);
137 edje_object_part_swallow(wd->img, "elm.swallow.background", wd->custom_img);
138 evas_object_show(wd->custom_img);