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);
21 static void _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content);
22 static Evas_Object *_content_get_hook(const Evas_Object *obj, const char *part);
23 static Evas_Object *_content_unset_hook(Evas_Object *obj, const char *part);
26 _del_hook(Evas_Object *obj)
28 Widget_Data *wd = elm_widget_data_get(obj);
33 _theme_hook(Evas_Object *obj)
35 Widget_Data *wd = elm_widget_data_get(obj);
38 _elm_theme_object_set(obj, wd->base, "bg", "base",
39 elm_widget_style_get(obj));
42 edje_object_part_swallow(wd->base, "elm.swallow.rectangle", wd->rect);
44 edje_object_part_swallow(wd->base, "elm.swallow.background", wd->img);
46 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->overlay);
48 // FIXME: if i don't do this, bg doesnt calc correctly. why?
49 evas_object_geometry_get(wd->base, NULL, NULL, &w, &h);
50 evas_object_resize(wd->base, w, h);
54 _custom_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
56 Widget_Data *wd = data;
57 Evas_Coord bx = 0, by = 0, bw = 0, bh = 0;
58 Evas_Coord iw = 0, ih = 0, mw = -1, mh = -1;
59 Evas_Coord fx = 0, fy = 0, fw = 0, fh = 0;
60 Evas_Coord nx = 0, ny = 0, nw = 0, nh = 0;
63 if ((!wd->img) || (!wd->file)) return;
64 if (((p = strrchr(wd->file, '.'))) && (!strcasecmp(p, ".edj"))) return;
67 evas_object_image_size_get(wd->img, &iw, &ih);
68 if ((iw < 1) || (ih < 1)) return;
70 /* grab base object dimensions */
71 evas_object_geometry_get(wd->base, &bx, &by, &bw, &bh);
73 /* set some defaults */
81 case ELM_BG_OPTION_CENTER:
89 case ELM_BG_OPTION_SCALE:
91 fh = ((ih * fw) / iw);
95 fw = ((iw * fh) / ih);
100 case ELM_BG_OPTION_TILE:
104 case ELM_BG_OPTION_STRETCH:
111 evas_object_move(wd->img, nx, ny);
112 evas_object_resize(wd->img, nw, nh);
113 evas_object_image_fill_set(wd->img, fx, fy, fw, fh);
115 evas_object_size_hint_min_set(wd->img, mw, mh);
116 evas_object_size_hint_max_set(wd->img, mw, mh);
120 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
122 ELM_CHECK_WIDTYPE(obj, widtype);
125 if (!part || strcmp(part, "overlay")) return;
127 wd = elm_widget_data_get(obj);
131 evas_object_del(wd->overlay);
136 wd->overlay = content;
137 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
138 elm_widget_sub_object_add(obj, content);
141 _custom_resize(wd, NULL, NULL, NULL);
145 _content_get_hook(const Evas_Object *obj, const char *part)
147 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
149 if (!part || strcmp(part, "overlay")) return NULL;
150 wd = elm_widget_data_get(obj);
151 if (!wd) return NULL;
156 _content_unset_hook(Evas_Object *obj, const char *part)
158 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
160 Evas_Object *overlay;
161 if (!part || strcmp(part, "overlay")) return NULL;
162 wd = elm_widget_data_get(obj);
163 if (!wd || !wd->overlay) return NULL;
164 overlay = wd->overlay;
165 elm_widget_sub_object_del(obj, wd->overlay);
166 edje_object_part_unswallow(wd->base, wd->overlay);
168 _custom_resize(wd, NULL, NULL, NULL);
173 elm_bg_add(Evas_Object *parent)
179 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
181 ELM_SET_WIDTYPE(widtype, "bg");
182 elm_widget_type_set(obj, "bg");
183 elm_widget_sub_object_add(parent, obj);
184 elm_widget_data_set(obj, wd);
185 elm_widget_del_hook_set(obj, _del_hook);
186 elm_widget_theme_hook_set(obj, _theme_hook);
187 elm_widget_content_set_hook_set(obj, _content_set_hook);
188 elm_widget_content_get_hook_set(obj, _content_get_hook);
189 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
191 elm_widget_can_focus_set(obj, EINA_FALSE);
193 wd->base = edje_object_add(e);
194 _elm_theme_object_set(obj, wd->base, "bg", "base", "default");
195 elm_widget_resize_object_set(obj, wd->base);
197 evas_object_event_callback_add(wd->base, EVAS_CALLBACK_RESIZE,
200 wd->option = ELM_BG_OPTION_SCALE;
205 elm_bg_file_set(Evas_Object *obj, const char *file, const char *group)
207 ELM_CHECK_WIDTYPE(obj, widtype);
208 Widget_Data *wd = elm_widget_data_get(obj);
213 evas_object_del(wd->img);
218 eina_stringshare_del(wd->file);
220 eina_stringshare_del(wd->group);
224 eina_stringshare_replace(&wd->file, file);
225 eina_stringshare_replace(&wd->group, group);
226 if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
228 wd->img = edje_object_add(evas_object_evas_get(wd->base));
229 edje_object_file_set(wd->img, file, group);
233 wd->img = evas_object_image_add(evas_object_evas_get(wd->base));
234 if ((wd->load_opts.w > 0) && (wd->load_opts.h > 0))
235 evas_object_image_load_size_set(wd->img, wd->load_opts.w, wd->load_opts.h);
236 evas_object_image_file_set(wd->img, file, group);
238 evas_object_repeat_events_set(wd->img, EINA_TRUE);
239 edje_object_part_swallow(wd->base, "elm.swallow.background", wd->img);
240 elm_widget_sub_object_add(obj, wd->img);
241 _custom_resize(wd, NULL, NULL, NULL);
245 elm_bg_file_get(const Evas_Object *obj, const char **file, const char **group)
247 ELM_CHECK_WIDTYPE(obj, widtype);
248 Widget_Data *wd = elm_widget_data_get(obj);
249 if (file) *file = wd->file;
250 if (group) *group = wd->group;
254 elm_bg_option_set(Evas_Object *obj, Elm_Bg_Option option)
256 ELM_CHECK_WIDTYPE(obj, widtype);
259 wd = elm_widget_data_get(obj);
261 _custom_resize(wd, NULL, NULL, NULL);
265 elm_bg_option_get(const Evas_Object *obj)
267 ELM_CHECK_WIDTYPE(obj, widtype) 0;
270 wd = elm_widget_data_get(obj);
275 elm_bg_color_set(Evas_Object *obj, int r, int g, int b)
277 ELM_CHECK_WIDTYPE(obj, widtype);
280 wd = elm_widget_data_get(obj);
283 wd->rect = evas_object_rectangle_add(evas_object_evas_get(wd->base));
284 edje_object_part_swallow(wd->base, "elm.swallow.rectangle", wd->rect);
285 elm_widget_sub_object_add(obj, wd->rect);
286 _custom_resize(wd, NULL, NULL, NULL);
288 evas_object_color_set(wd->rect, r, g, b, 255);
292 elm_bg_color_get(const Evas_Object *obj, int *r, int *g, int *b)
294 ELM_CHECK_WIDTYPE(obj, widtype);
297 wd = elm_widget_data_get(obj);
298 evas_object_color_get(wd->rect, r, g, b, NULL);
302 elm_bg_overlay_set(Evas_Object *obj, Evas_Object *overlay)
304 _content_set_hook(obj, "overlay", overlay);
308 elm_bg_overlay_get(const Evas_Object *obj)
310 return _content_get_hook(obj, "overlay");
314 elm_bg_overlay_unset(Evas_Object *obj)
316 return _content_unset_hook(obj, "overlay");
320 elm_bg_load_size_set(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
322 ELM_CHECK_WIDTYPE(obj, widtype);
323 Widget_Data *wd = elm_widget_data_get(obj);
328 if (!wd->img) return;
329 if (!(((p = strrchr(wd->file, '.'))) && (!strcasecmp(p, ".edj"))))
330 evas_object_image_load_size_set(wd->img, w, h);