1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
8 Evas_Object *base, *rect, *img, *overlay;
9 const char *file, *group;
17 static const char *widtype = NULL;
19 static void _del_hook(Evas_Object *obj);
20 static void _theme_hook(Evas_Object *obj);
21 static void _custom_resize(void *data, Evas *a, Evas_Object *obj, void *event_info);
22 static void _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content);
23 static Evas_Object *_content_get_hook(const Evas_Object *obj, const char *part);
24 static Evas_Object *_content_unset_hook(Evas_Object *obj, const char *part);
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);
39 _elm_theme_object_set(obj, wd->base, "bg", "base",
40 elm_widget_style_get(obj));
43 edje_object_part_swallow(wd->base, "elm.swallow.rectangle", wd->rect);
45 edje_object_part_swallow(wd->base, "elm.swallow.background", wd->img);
47 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->overlay);
49 // FIXME: if i don't do this, bg doesnt calc correctly. why?
50 evas_object_geometry_get(wd->base, NULL, NULL, &w, &h);
51 evas_object_resize(wd->base, w, h);
55 _custom_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
57 Widget_Data *wd = data;
58 Evas_Coord bx = 0, by = 0, bw = 0, bh = 0;
59 Evas_Coord iw = 0, ih = 0, mw = -1, mh = -1;
60 Evas_Coord fx = 0, fy = 0, fw = 0, fh = 0;
61 Evas_Coord nx = 0, ny = 0, nw = 0, nh = 0;
64 if ((!wd->img) || (!wd->file)) return;
65 if (((p = strrchr(wd->file, '.'))) && (!strcasecmp(p, ".edj"))) return;
68 evas_object_image_size_get(wd->img, &iw, &ih);
69 if ((iw < 1) || (ih < 1)) return;
71 /* grab base object dimensions */
72 evas_object_geometry_get(wd->base, &bx, &by, &bw, &bh);
74 /* set some defaults */
82 case ELM_BG_OPTION_CENTER:
90 case ELM_BG_OPTION_SCALE:
92 fh = ((ih * fw) / iw);
96 fw = ((iw * fh) / ih);
101 case ELM_BG_OPTION_TILE:
105 case ELM_BG_OPTION_STRETCH:
112 evas_object_move(wd->img, nx, ny);
113 evas_object_resize(wd->img, nw, nh);
114 evas_object_image_fill_set(wd->img, fx, fy, fw, fh);
116 evas_object_size_hint_min_set(wd->img, mw, mh);
117 evas_object_size_hint_max_set(wd->img, mw, mh);
121 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
123 ELM_CHECK_WIDTYPE(obj, widtype);
126 if (part && strcmp(part, "overlay")) return;
128 wd = elm_widget_data_get(obj);
132 evas_object_del(wd->overlay);
137 wd->overlay = content;
138 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
139 elm_widget_sub_object_add(obj, content);
142 _custom_resize(wd, NULL, NULL, NULL);
146 _content_get_hook(const Evas_Object *obj, const char *part)
148 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
150 if (part && strcmp(part, "overlay")) return NULL;
151 wd = elm_widget_data_get(obj);
152 if (!wd) return NULL;
157 _content_unset_hook(Evas_Object *obj, const char *part)
159 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
161 Evas_Object *overlay;
162 if (part && strcmp(part, "overlay")) return NULL;
163 wd = elm_widget_data_get(obj);
164 if (!wd || !wd->overlay) return NULL;
165 overlay = wd->overlay;
166 elm_widget_sub_object_del(obj, wd->overlay);
167 edje_object_part_unswallow(wd->base, wd->overlay);
169 _custom_resize(wd, NULL, NULL, NULL);
174 elm_bg_add(Evas_Object *parent)
180 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
182 ELM_SET_WIDTYPE(widtype, "bg");
183 elm_widget_type_set(obj, "bg");
184 elm_widget_sub_object_add(parent, obj);
185 elm_widget_data_set(obj, wd);
186 elm_widget_del_hook_set(obj, _del_hook);
187 elm_widget_theme_hook_set(obj, _theme_hook);
188 elm_widget_content_set_hook_set(obj, _content_set_hook);
189 elm_widget_content_get_hook_set(obj, _content_get_hook);
190 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
192 elm_widget_can_focus_set(obj, EINA_FALSE);
194 wd->base = edje_object_add(e);
195 _elm_theme_object_set(obj, wd->base, "bg", "base", "default");
196 elm_widget_resize_object_set(obj, wd->base);
198 evas_object_event_callback_add(wd->base, EVAS_CALLBACK_RESIZE,
201 wd->option = ELM_BG_OPTION_SCALE;
206 elm_bg_file_set(Evas_Object *obj, const char *file, const char *group)
208 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
209 Widget_Data *wd = elm_widget_data_get(obj);
214 evas_object_del(wd->img);
219 eina_stringshare_del(wd->file);
221 eina_stringshare_del(wd->group);
225 eina_stringshare_replace(&wd->file, file);
226 eina_stringshare_replace(&wd->group, group);
227 if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
229 wd->img = edje_object_add(evas_object_evas_get(wd->base));
230 edje_object_file_set(wd->img, file, group);
234 wd->img = evas_object_image_add(evas_object_evas_get(wd->base));
235 if ((wd->load_opts.w > 0) && (wd->load_opts.h > 0))
236 evas_object_image_load_size_set(wd->img, wd->load_opts.w, wd->load_opts.h);
237 evas_object_image_file_set(wd->img, file, group);
239 evas_object_repeat_events_set(wd->img, EINA_TRUE);
240 edje_object_part_swallow(wd->base, "elm.swallow.background", wd->img);
241 elm_widget_sub_object_add(obj, wd->img);
242 _custom_resize(wd, NULL, NULL, NULL);
248 elm_bg_file_get(const Evas_Object *obj, const char **file, const char **group)
250 ELM_CHECK_WIDTYPE(obj, widtype);
251 Widget_Data *wd = elm_widget_data_get(obj);
252 if (file) *file = wd->file;
253 if (group) *group = wd->group;
259 elm_bg_option_set(Evas_Object *obj, Elm_Bg_Option option)
261 ELM_CHECK_WIDTYPE(obj, widtype);
264 wd = elm_widget_data_get(obj);
266 _custom_resize(wd, NULL, NULL, NULL);
272 elm_bg_option_get(const Evas_Object *obj)
274 ELM_CHECK_WIDTYPE(obj, widtype) ELM_BG_OPTION_LAST;
277 wd = elm_widget_data_get(obj);
282 elm_bg_color_set(Evas_Object *obj, int r, int g, int b)
284 ELM_CHECK_WIDTYPE(obj, widtype);
287 wd = elm_widget_data_get(obj);
290 wd->rect = evas_object_rectangle_add(evas_object_evas_get(wd->base));
291 edje_object_part_swallow(wd->base, "elm.swallow.rectangle", wd->rect);
292 elm_widget_sub_object_add(obj, wd->rect);
293 _custom_resize(wd, NULL, NULL, NULL);
295 evas_object_color_set(wd->rect, r, g, b, 255);
301 elm_bg_color_get(const Evas_Object *obj, int *r, int *g, int *b)
303 ELM_CHECK_WIDTYPE(obj, widtype);
306 wd = elm_widget_data_get(obj);
307 evas_object_color_get(wd->rect, r, g, b, NULL);
313 elm_bg_load_size_set(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
315 ELM_CHECK_WIDTYPE(obj, widtype);
316 Widget_Data *wd = elm_widget_data_get(obj);
321 if (!wd->img) return;
322 if (!(((p = strrchr(wd->file, '.'))) && (!strcasecmp(p, ".edj"))))
323 evas_object_image_load_size_set(wd->img, w, h);