1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
8 Evas_Object *base, *rect, *img, *overlay;
9 const char *file, *group;
16 static const char *widtype = NULL;
18 static void _del_hook(Evas_Object *obj);
19 static void _theme_hook(Evas_Object *obj);
20 static void _custom_resize(void *data, Evas *a, Evas_Object *obj, void *event_info);
23 _del_hook(Evas_Object *obj)
25 Widget_Data *wd = elm_widget_data_get(obj);
30 _theme_hook(Evas_Object *obj)
32 Widget_Data *wd = elm_widget_data_get(obj);
35 _elm_theme_object_set(obj, wd->base, "bg", "base",
36 elm_widget_style_get(obj));
39 edje_object_part_swallow(wd->base, "elm.swallow.rectangle", wd->rect);
41 edje_object_part_swallow(wd->base, "elm.swallow.background", wd->img);
43 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->overlay);
45 // FIXME: if i don't do this, bg doesnt calc correctly. why?
46 evas_object_geometry_get(wd->base, NULL, NULL, &w, &h);
47 evas_object_resize(wd->base, w, h);
51 _custom_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
53 Widget_Data *wd = data;
54 Evas_Coord bx = 0, by = 0, bw = 0, bh = 0;
55 Evas_Coord iw = 0, ih = 0, mw = -1, mh = -1;
56 Evas_Coord fx = 0, fy = 0, fw = 0, fh = 0;
57 Evas_Coord nx = 0, ny = 0, nw = 0, nh = 0;
60 if ((!wd->img) || (!wd->file)) return;
61 if (((p = strrchr(wd->file, '.'))) && (!strcasecmp(p, ".edj"))) return;
64 evas_object_image_size_get(wd->img, &iw, &ih);
65 if ((iw < 1) || (ih < 1)) return;
67 /* grab base object dimensions */
68 evas_object_geometry_get(wd->base, &bx, &by, &bw, &bh);
70 /* set some defaults */
78 case ELM_BG_OPTION_CENTER:
86 case ELM_BG_OPTION_SCALE:
88 fh = ((ih * fw) / iw);
92 fw = ((iw * fh) / ih);
97 case ELM_BG_OPTION_TILE:
101 case ELM_BG_OPTION_STRETCH:
108 evas_object_move(wd->img, nx, ny);
109 evas_object_resize(wd->img, nw, nh);
110 evas_object_image_fill_set(wd->img, fx, fy, fw, fh);
112 evas_object_size_hint_min_set(wd->img, mw, mh);
113 evas_object_size_hint_max_set(wd->img, mw, mh);
117 elm_bg_add(Evas_Object *parent)
123 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
125 ELM_SET_WIDTYPE(widtype, "bg");
126 elm_widget_type_set(obj, "bg");
127 elm_widget_sub_object_add(parent, obj);
128 elm_widget_data_set(obj, wd);
129 elm_widget_del_hook_set(obj, _del_hook);
130 elm_widget_theme_hook_set(obj, _theme_hook);
131 elm_widget_can_focus_set(obj, EINA_FALSE);
133 wd->base = edje_object_add(e);
134 _elm_theme_object_set(obj, wd->base, "bg", "base", "default");
135 elm_widget_resize_object_set(obj, wd->base);
137 evas_object_event_callback_add(wd->base, EVAS_CALLBACK_RESIZE,
140 wd->option = ELM_BG_OPTION_SCALE;
145 elm_bg_file_set(Evas_Object *obj, const char *file, const char *group)
147 ELM_CHECK_WIDTYPE(obj, widtype);
148 Widget_Data *wd = elm_widget_data_get(obj);
153 evas_object_del(wd->img);
158 eina_stringshare_del(wd->file);
160 eina_stringshare_del(wd->group);
164 eina_stringshare_replace(&wd->file, file);
165 eina_stringshare_replace(&wd->group, group);
166 if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
168 wd->img = edje_object_add(evas_object_evas_get(wd->base));
169 edje_object_file_set(wd->img, file, group);
173 wd->img = evas_object_image_add(evas_object_evas_get(wd->base));
174 if ((wd->load_opts.w > 0) && (wd->load_opts.h > 0))
175 evas_object_image_load_size_set(wd->img, wd->load_opts.w, wd->load_opts.h);
176 evas_object_image_file_set(wd->img, file, group);
178 evas_object_repeat_events_set(wd->img, EINA_TRUE);
179 edje_object_part_swallow(wd->base, "elm.swallow.background", wd->img);
180 elm_widget_sub_object_add(obj, wd->img);
181 _custom_resize(wd, NULL, NULL, NULL);
185 elm_bg_file_get(const Evas_Object *obj, const char **file, const char **group)
187 ELM_CHECK_WIDTYPE(obj, widtype);
188 Widget_Data *wd = elm_widget_data_get(obj);
189 if (file) *file = wd->file;
190 if (group) *group = wd->group;
194 elm_bg_option_set(Evas_Object *obj, Elm_Bg_Option option)
196 ELM_CHECK_WIDTYPE(obj, widtype);
199 wd = elm_widget_data_get(obj);
201 _custom_resize(wd, NULL, NULL, NULL);
205 elm_bg_option_get(const Evas_Object *obj)
207 ELM_CHECK_WIDTYPE(obj, widtype) 0;
210 wd = elm_widget_data_get(obj);
215 elm_bg_color_set(Evas_Object *obj, int r, int g, int b)
217 ELM_CHECK_WIDTYPE(obj, widtype);
220 wd = elm_widget_data_get(obj);
223 wd->rect = evas_object_rectangle_add(evas_object_evas_get(wd->base));
224 edje_object_part_swallow(wd->base, "elm.swallow.rectangle", wd->rect);
225 elm_widget_sub_object_add(obj, wd->rect);
226 _custom_resize(wd, NULL, NULL, NULL);
228 evas_object_color_set(wd->rect, r, g, b, 255);
232 elm_bg_color_get(const Evas_Object *obj, int *r, int *g, int *b)
234 ELM_CHECK_WIDTYPE(obj, widtype);
237 wd = elm_widget_data_get(obj);
238 evas_object_color_get(wd->rect, r, g, b, NULL);
242 elm_bg_overlay_set(Evas_Object *obj, Evas_Object *overlay)
244 ELM_CHECK_WIDTYPE(obj, widtype);
245 Widget_Data *wd = elm_widget_data_get(obj);
249 evas_object_del(wd->overlay);
254 wd->overlay = overlay;
255 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->overlay);
256 elm_widget_sub_object_add(obj, wd->overlay);
259 _custom_resize(wd, NULL, NULL, NULL);
263 elm_bg_overlay_get(const Evas_Object *obj)
265 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
266 Widget_Data *wd = elm_widget_data_get(obj);
267 if (!wd) return NULL;
272 elm_bg_overlay_unset(Evas_Object *obj)
274 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
275 Widget_Data *wd = elm_widget_data_get(obj);
276 Evas_Object *overlay;
277 if (!wd) return NULL;
278 if (!wd->overlay) return NULL;
279 overlay = wd->overlay;
280 elm_widget_sub_object_del(obj, wd->overlay);
281 edje_object_part_unswallow(wd->base, wd->overlay);
283 _custom_resize(wd, NULL, NULL, NULL);
288 elm_bg_load_size_set(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
290 ELM_CHECK_WIDTYPE(obj, widtype);
291 Widget_Data *wd = elm_widget_data_get(obj);
296 if (!wd->img) return;
297 if (!(((p = strrchr(wd->file, '.'))) && (!strcasecmp(p, ".edj"))))
298 evas_object_image_load_size_set(wd->img, w, h);