3 #include <Elementary.h>
9 * The bg object is used for setting a solid background to a window or packing
10 * into any container object.
13 typedef struct _Widget_Data Widget_Data;
17 Evas_Object *img, *custom_img;
18 const char *file, *group;
21 static const char *widtype = NULL;
22 static void _del_hook(Evas_Object *obj);
23 static void _theme_hook(Evas_Object *obj);
24 static void _custom_resize(void *data, Evas *a, Evas_Object *obj, void *event_info);
27 _del_hook(Evas_Object *obj)
29 Widget_Data *wd = elm_widget_data_get(obj);
34 _theme_hook(Evas_Object *obj)
36 Widget_Data *wd = elm_widget_data_get(obj);
37 _elm_theme_object_set(obj, wd->img, "bg", "base", elm_widget_style_get(obj));
41 _custom_resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
44 Evas_Coord x, y, w, h, ow = 0, oh = 0;
46 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
47 evas_object_image_size_get(obj, &iw, &ih);
49 if ((iw < 1) || (ih < 1)) return;
59 evas_object_image_fill_set(obj, x, y, w, h);
63 * Add a new background to the parent
65 * @param parent The parent object
66 * @return The new object or NULL if it cannot be created
71 elm_bg_add(Evas_Object *parent)
77 wd = ELM_NEW(Widget_Data);
78 e = evas_object_evas_get(parent);
79 obj = elm_widget_add(e);
80 ELM_SET_WIDTYPE(widtype, "bg");
81 elm_widget_type_set(obj, "bg");
82 elm_widget_sub_object_add(parent, obj);
83 elm_widget_data_set(obj, wd);
84 elm_widget_del_hook_set(obj, _del_hook);
85 elm_widget_theme_hook_set(obj, _theme_hook);
86 elm_widget_can_focus_set(obj, 0);
88 wd->img = edje_object_add(e);
89 _elm_theme_object_set(obj, wd->img, "bg", "base", "default");
90 elm_widget_resize_object_set(obj, wd->img);
95 * Set the file (image or edje) used for the background
97 * @param obj The bg object
98 * @param file The file path
99 * @param group Optional key (group in Edje) within the file
101 * This sets the image file used in the background object. The image (or edje)
102 * will be stretched (retaining aspect if its an image file) to completely fill
103 * the bg object. This may mean some parts arte not visible.
108 elm_bg_file_set(Evas_Object *obj, const char *file, const char *group)
110 ELM_CHECK_WIDTYPE(obj, widtype);
111 Widget_Data *wd = elm_widget_data_get(obj);
116 evas_object_del(wd->custom_img);
117 wd->custom_img = NULL;
120 eina_stringshare_replace(&wd->file, file);
121 eina_stringshare_replace(&wd->group, group);
122 if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
124 wd->custom_img = edje_object_add(evas_object_evas_get(wd->img));
125 edje_object_file_set(wd->custom_img, file, group);
129 wd->custom_img = evas_object_image_add(evas_object_evas_get(wd->img));
130 evas_object_event_callback_add(wd->custom_img, EVAS_CALLBACK_RESIZE,
132 evas_object_image_file_set(wd->custom_img, file, group);
134 elm_widget_sub_object_add(obj, wd->custom_img);
135 evas_object_repeat_events_set(wd->custom_img, 1);
136 edje_object_part_swallow(wd->img, "elm.swallow.background", wd->custom_img);
137 evas_object_show(wd->custom_img);