2008-09-29 23:58:56 -07:00
|
|
|
#include <Elementary.h>
|
|
|
|
#include "elm_priv.h"
|
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
typedef struct _Widget_Data Widget_Data;
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
struct _Widget_Data
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2010-10-12 01:46:17 -07:00
|
|
|
Evas_Object *base, *rect, *img, *overlay;
|
2008-10-06 18:23:49 -07:00
|
|
|
const char *file, *group;
|
2010-10-11 21:12:48 -07:00
|
|
|
Elm_Bg_Option option;
|
2011-02-14 08:38:18 -08:00
|
|
|
struct {
|
2011-02-14 09:13:40 -08:00
|
|
|
Evas_Coord w, h;
|
2011-02-14 08:38:18 -08:00
|
|
|
} load_opts;
|
2008-09-29 23:58:56 -07:00
|
|
|
};
|
|
|
|
|
2010-03-08 22:15:39 -08:00
|
|
|
static const char *widtype = NULL;
|
2010-10-12 01:46:17 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
static void _del_hook(Evas_Object *obj);
|
2009-10-15 12:33:28 -07:00
|
|
|
static void _theme_hook(Evas_Object *obj);
|
2008-10-06 18:23:49 -07:00
|
|
|
static void _custom_resize(void *data, Evas *a, Evas_Object *obj, void *event_info);
|
2011-10-28 01:31:42 -07:00
|
|
|
static void _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content);
|
|
|
|
static Evas_Object *_content_get_hook(const Evas_Object *obj, const char *part);
|
|
|
|
static Evas_Object *_content_unset_hook(Evas_Object *obj, const char *part);
|
2008-10-06 18:23:49 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
_del_hook(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
free(wd);
|
|
|
|
}
|
|
|
|
|
2008-11-15 05:58:50 -08:00
|
|
|
static void
|
|
|
|
_theme_hook(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-09-14 16:42:50 -07:00
|
|
|
Evas_Coord w, h;
|
2010-10-11 21:12:48 -07:00
|
|
|
|
elementary / entry, list, scroller, fileselector_button, config, photocam, map, pan, bg, store, priv, pager, conform, box, clock, flipselector
fixed indentation, removed white spaces.
SVN revision: 58267
2011-04-01 12:08:56 -07:00
|
|
|
_elm_theme_object_set(obj, wd->base, "bg", "base",
|
2010-10-12 01:46:17 -07:00
|
|
|
elm_widget_style_get(obj));
|
|
|
|
|
|
|
|
if (wd->rect)
|
|
|
|
edje_object_part_swallow(wd->base, "elm.swallow.rectangle", wd->rect);
|
|
|
|
if (wd->img)
|
|
|
|
edje_object_part_swallow(wd->base, "elm.swallow.background", wd->img);
|
|
|
|
if (wd->overlay)
|
|
|
|
edje_object_part_swallow(wd->base, "elm.swallow.content", wd->overlay);
|
|
|
|
|
2011-04-08 07:36:29 -07:00
|
|
|
// FIXME: if i don't do this, bg doesnt calc correctly. why?
|
2010-10-12 01:46:17 -07:00
|
|
|
evas_object_geometry_get(wd->base, NULL, NULL, &w, &h);
|
|
|
|
evas_object_resize(wd->base, w, h);
|
2008-11-15 05:58:50 -08:00
|
|
|
}
|
|
|
|
|
2008-09-29 23:58:56 -07:00
|
|
|
static void
|
2010-10-12 07:38:46 -07:00
|
|
|
_custom_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2010-10-11 21:21:50 -07:00
|
|
|
Widget_Data *wd = data;
|
2010-10-12 07:38:46 -07:00
|
|
|
Evas_Coord bx = 0, by = 0, bw = 0, bh = 0;
|
2010-10-15 16:03:56 -07:00
|
|
|
Evas_Coord iw = 0, ih = 0, mw = -1, mh = -1;
|
2010-10-12 07:38:46 -07:00
|
|
|
Evas_Coord fx = 0, fy = 0, fw = 0, fh = 0;
|
|
|
|
Evas_Coord nx = 0, ny = 0, nw = 0, nh = 0;
|
|
|
|
const char *p;
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2010-10-12 07:38:46 -07:00
|
|
|
if ((!wd->img) || (!wd->file)) return;
|
|
|
|
if (((p = strrchr(wd->file, '.'))) && (!strcasecmp(p, ".edj"))) return;
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2010-10-12 07:38:46 -07:00
|
|
|
/* grab image size */
|
|
|
|
evas_object_image_size_get(wd->img, &iw, &ih);
|
2008-09-29 23:58:56 -07:00
|
|
|
if ((iw < 1) || (ih < 1)) return;
|
2010-10-12 07:38:46 -07:00
|
|
|
|
|
|
|
/* grab base object dimensions */
|
|
|
|
evas_object_geometry_get(wd->base, &bx, &by, &bw, &bh);
|
|
|
|
|
|
|
|
/* set some defaults */
|
|
|
|
nx = bx;
|
|
|
|
ny = by;
|
|
|
|
nw = bw;
|
|
|
|
nh = bh;
|
|
|
|
|
elementary / entry, list, scroller, fileselector_button, config, photocam, map, pan, bg, store, priv, pager, conform, box, clock, flipselector
fixed indentation, removed white spaces.
SVN revision: 58267
2011-04-01 12:08:56 -07:00
|
|
|
switch (wd->option)
|
2010-10-11 21:12:48 -07:00
|
|
|
{
|
2010-10-12 07:38:46 -07:00
|
|
|
case ELM_BG_OPTION_CENTER:
|
2011-04-01 04:35:07 -07:00
|
|
|
fw = nw = iw;
|
|
|
|
fh = nh = ih;
|
|
|
|
nx = ((bw - fw) / 2);
|
|
|
|
ny = ((bh - fh) / 2);
|
|
|
|
mw = iw;
|
|
|
|
mh = ih;
|
|
|
|
break;
|
2010-10-12 07:38:46 -07:00
|
|
|
case ELM_BG_OPTION_SCALE:
|
2011-04-01 04:35:07 -07:00
|
|
|
fw = bw;
|
|
|
|
fh = ((ih * fw) / iw);
|
|
|
|
if (fh < bh)
|
|
|
|
{
|
|
|
|
fh = bh;
|
|
|
|
fw = ((iw * fh) / ih);
|
|
|
|
}
|
|
|
|
fx = ((bw - fw) / 2);
|
|
|
|
fy = ((bh - fh) / 2);
|
|
|
|
break;
|
2010-10-12 07:38:46 -07:00
|
|
|
case ELM_BG_OPTION_TILE:
|
2011-04-01 04:35:07 -07:00
|
|
|
fw = iw;
|
|
|
|
fh = ih;
|
|
|
|
break;
|
2010-10-12 07:38:46 -07:00
|
|
|
case ELM_BG_OPTION_STRETCH:
|
|
|
|
default:
|
2011-04-01 04:35:07 -07:00
|
|
|
fw = bw;
|
|
|
|
fh = bh;
|
|
|
|
break;
|
2010-10-11 21:12:48 -07:00
|
|
|
}
|
2010-10-12 07:38:46 -07:00
|
|
|
|
|
|
|
evas_object_move(wd->img, nx, ny);
|
|
|
|
evas_object_resize(wd->img, nw, nh);
|
2010-10-15 16:03:56 -07:00
|
|
|
evas_object_image_fill_set(wd->img, fx, fy, fw, fh);
|
|
|
|
|
|
|
|
evas_object_size_hint_min_set(wd->img, mw, mh);
|
|
|
|
evas_object_size_hint_max_set(wd->img, mw, mh);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
|
|
|
|
2011-10-28 01:31:42 -07:00
|
|
|
static void
|
2011-11-16 04:51:53 -08:00
|
|
|
_content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
|
2011-10-28 01:31:42 -07:00
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
2011-11-16 04:51:53 -08:00
|
|
|
Widget_Data *wd;
|
|
|
|
|
2011-11-16 16:42:14 -08:00
|
|
|
if (part && strcmp(part, "overlay")) return;
|
2011-11-16 04:51:53 -08:00
|
|
|
|
|
|
|
wd = elm_widget_data_get(obj);
|
2011-10-28 01:31:42 -07:00
|
|
|
if (!wd) return;
|
|
|
|
if (wd->overlay)
|
|
|
|
{
|
|
|
|
evas_object_del(wd->overlay);
|
|
|
|
wd->overlay = NULL;
|
|
|
|
}
|
|
|
|
if (content)
|
|
|
|
{
|
|
|
|
wd->overlay = content;
|
|
|
|
edje_object_part_swallow(wd->base, "elm.swallow.content", content);
|
|
|
|
elm_widget_sub_object_add(obj, content);
|
|
|
|
}
|
|
|
|
|
|
|
|
_custom_resize(wd, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Evas_Object *
|
2011-11-16 04:51:53 -08:00
|
|
|
_content_get_hook(const Evas_Object *obj, const char *part)
|
2011-10-28 01:31:42 -07:00
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
|
2011-11-16 04:51:53 -08:00
|
|
|
Widget_Data *wd;
|
2011-11-16 16:42:14 -08:00
|
|
|
if (part && strcmp(part, "overlay")) return NULL;
|
2011-11-16 04:51:53 -08:00
|
|
|
wd = elm_widget_data_get(obj);
|
2011-10-28 01:31:42 -07:00
|
|
|
if (!wd) return NULL;
|
|
|
|
return wd->overlay;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Evas_Object *
|
2011-11-16 04:51:53 -08:00
|
|
|
_content_unset_hook(Evas_Object *obj, const char *part)
|
2011-10-28 01:31:42 -07:00
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
|
2011-11-16 04:51:53 -08:00
|
|
|
Widget_Data *wd;
|
2011-10-28 01:31:42 -07:00
|
|
|
Evas_Object *overlay;
|
2011-11-16 16:42:14 -08:00
|
|
|
if (part && strcmp(part, "overlay")) return NULL;
|
2011-11-16 04:51:53 -08:00
|
|
|
wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd || !wd->overlay) return NULL;
|
2011-10-28 01:31:42 -07:00
|
|
|
overlay = wd->overlay;
|
|
|
|
elm_widget_sub_object_del(obj, wd->overlay);
|
|
|
|
edje_object_part_unswallow(wd->base, wd->overlay);
|
|
|
|
wd->overlay = NULL;
|
|
|
|
_custom_resize(wd, NULL, NULL, NULL);
|
|
|
|
return overlay;
|
|
|
|
}
|
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI Evas_Object *
|
|
|
|
elm_bg_add(Evas_Object *parent)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
Evas_Object *obj;
|
|
|
|
Evas *e;
|
|
|
|
Widget_Data *wd;
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2011-03-31 23:08:02 -07:00
|
|
|
ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_SET_WIDTYPE(widtype, "bg");
|
2009-05-13 05:21:52 -07:00
|
|
|
elm_widget_type_set(obj, "bg");
|
|
|
|
elm_widget_sub_object_add(parent, obj);
|
2008-10-06 18:23:49 -07:00
|
|
|
elm_widget_data_set(obj, wd);
|
|
|
|
elm_widget_del_hook_set(obj, _del_hook);
|
2008-11-15 05:58:50 -08:00
|
|
|
elm_widget_theme_hook_set(obj, _theme_hook);
|
2011-10-28 01:31:42 -07:00
|
|
|
elm_widget_content_set_hook_set(obj, _content_set_hook);
|
|
|
|
elm_widget_content_get_hook_set(obj, _content_get_hook);
|
|
|
|
elm_widget_content_unset_hook_set(obj, _content_unset_hook);
|
|
|
|
|
2010-09-27 21:28:14 -07:00
|
|
|
elm_widget_can_focus_set(obj, EINA_FALSE);
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2010-10-12 01:46:17 -07:00
|
|
|
wd->base = edje_object_add(e);
|
|
|
|
_elm_theme_object_set(obj, wd->base, "bg", "base", "default");
|
|
|
|
elm_widget_resize_object_set(obj, wd->base);
|
2010-10-11 21:12:48 -07:00
|
|
|
|
elementary / entry, list, scroller, fileselector_button, config, photocam, map, pan, bg, store, priv, pager, conform, box, clock, flipselector
fixed indentation, removed white spaces.
SVN revision: 58267
2011-04-01 12:08:56 -07:00
|
|
|
evas_object_event_callback_add(wd->base, EVAS_CALLBACK_RESIZE,
|
2010-10-12 07:38:46 -07:00
|
|
|
_custom_resize, wd);
|
|
|
|
|
2010-10-12 03:30:32 -07:00
|
|
|
wd->option = ELM_BG_OPTION_SCALE;
|
2008-10-06 18:23:49 -07:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_bg_file_set(Evas_Object *obj, const char *file, const char *group)
|
|
|
|
{
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
2008-10-06 18:23:49 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2008-09-29 23:58:56 -07:00
|
|
|
const char *p;
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2010-10-12 01:46:17 -07:00
|
|
|
if (wd->img)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2011-02-14 08:38:18 -08:00
|
|
|
evas_object_del(wd->img);
|
|
|
|
wd->img = NULL;
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2010-11-25 07:16:48 -08:00
|
|
|
if (!file)
|
|
|
|
{
|
|
|
|
eina_stringshare_del(wd->file);
|
|
|
|
wd->file = NULL;
|
|
|
|
eina_stringshare_del(wd->group);
|
|
|
|
wd->group = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2010-03-13 13:01:26 -08:00
|
|
|
eina_stringshare_replace(&wd->file, file);
|
|
|
|
eina_stringshare_replace(&wd->group, group);
|
2008-09-29 23:58:56 -07:00
|
|
|
if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
|
|
|
|
{
|
2011-02-14 08:38:18 -08:00
|
|
|
wd->img = edje_object_add(evas_object_evas_get(wd->base));
|
|
|
|
edje_object_file_set(wd->img, file, group);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2009-07-06 23:46:51 -07:00
|
|
|
else
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2011-02-14 08:38:18 -08:00
|
|
|
wd->img = evas_object_image_add(evas_object_evas_get(wd->base));
|
|
|
|
if ((wd->load_opts.w > 0) && (wd->load_opts.h > 0))
|
2011-04-01 04:35:07 -07:00
|
|
|
evas_object_image_load_size_set(wd->img, wd->load_opts.w, wd->load_opts.h);
|
2011-02-14 08:38:18 -08:00
|
|
|
evas_object_image_file_set(wd->img, file, group);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2010-10-12 01:46:17 -07:00
|
|
|
evas_object_repeat_events_set(wd->img, EINA_TRUE);
|
|
|
|
edje_object_part_swallow(wd->base, "elm.swallow.background", wd->img);
|
2010-10-12 07:38:46 -07:00
|
|
|
elm_widget_sub_object_add(obj, wd->img);
|
|
|
|
_custom_resize(wd, NULL, NULL, NULL);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2010-10-11 21:12:48 -07:00
|
|
|
|
2010-10-27 07:38:37 -07:00
|
|
|
EAPI void
|
|
|
|
elm_bg_file_get(const Evas_Object *obj, const char **file, const char **group)
|
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (file) *file = wd->file;
|
|
|
|
if (group) *group = wd->group;
|
|
|
|
}
|
|
|
|
|
elementary / entry, list, scroller, fileselector_button, config, photocam, map, pan, bg, store, priv, pager, conform, box, clock, flipselector
fixed indentation, removed white spaces.
SVN revision: 58267
2011-04-01 12:08:56 -07:00
|
|
|
EAPI void
|
|
|
|
elm_bg_option_set(Evas_Object *obj, Elm_Bg_Option option)
|
2010-10-11 21:12:48 -07:00
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
|
|
|
Widget_Data *wd;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(obj);
|
|
|
|
wd->option = option;
|
2010-10-12 07:38:46 -07:00
|
|
|
_custom_resize(wd, NULL, NULL, NULL);
|
2010-10-11 21:12:48 -07:00
|
|
|
}
|
2010-10-12 01:46:17 -07:00
|
|
|
|
2010-10-27 07:38:37 -07:00
|
|
|
EAPI Elm_Bg_Option
|
|
|
|
elm_bg_option_get(const Evas_Object *obj)
|
|
|
|
{
|
2010-10-27 10:01:58 -07:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) 0;
|
2010-10-27 07:38:37 -07:00
|
|
|
Widget_Data *wd;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(obj);
|
|
|
|
return wd->option;
|
|
|
|
}
|
|
|
|
|
elementary / entry, list, scroller, fileselector_button, config, photocam, map, pan, bg, store, priv, pager, conform, box, clock, flipselector
fixed indentation, removed white spaces.
SVN revision: 58267
2011-04-01 12:08:56 -07:00
|
|
|
EAPI void
|
|
|
|
elm_bg_color_set(Evas_Object *obj, int r, int g, int b)
|
2010-10-12 01:46:17 -07:00
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
|
|
|
Widget_Data *wd;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd->rect)
|
|
|
|
{
|
|
|
|
wd->rect = evas_object_rectangle_add(evas_object_evas_get(wd->base));
|
|
|
|
edje_object_part_swallow(wd->base, "elm.swallow.rectangle", wd->rect);
|
2010-10-12 07:38:46 -07:00
|
|
|
elm_widget_sub_object_add(obj, wd->rect);
|
|
|
|
_custom_resize(wd, NULL, NULL, NULL);
|
2010-10-12 01:46:17 -07:00
|
|
|
}
|
|
|
|
evas_object_color_set(wd->rect, r, g, b, 255);
|
|
|
|
}
|
|
|
|
|
2010-10-27 07:38:37 -07:00
|
|
|
EAPI void
|
|
|
|
elm_bg_color_get(const Evas_Object *obj, int *r, int *g, int *b)
|
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
|
|
|
Widget_Data *wd;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(obj);
|
|
|
|
evas_object_color_get(wd->rect, r, g, b, NULL);
|
|
|
|
}
|
|
|
|
|
2010-10-14 11:54:42 -07:00
|
|
|
EAPI void
|
2010-10-12 01:46:17 -07:00
|
|
|
elm_bg_overlay_set(Evas_Object *obj, Evas_Object *overlay)
|
|
|
|
{
|
2011-11-16 04:51:53 -08:00
|
|
|
_content_set_hook(obj, "overlay", overlay);
|
2010-10-12 01:46:17 -07:00
|
|
|
}
|
2010-10-14 11:54:42 -07:00
|
|
|
|
|
|
|
EAPI Evas_Object *
|
|
|
|
elm_bg_overlay_get(const Evas_Object *obj)
|
|
|
|
{
|
2011-11-16 04:51:53 -08:00
|
|
|
return _content_get_hook(obj, "overlay");
|
2010-10-14 11:54:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Evas_Object *
|
|
|
|
elm_bg_overlay_unset(Evas_Object *obj)
|
|
|
|
{
|
2011-11-16 04:51:53 -08:00
|
|
|
return _content_unset_hook(obj, "overlay");
|
2010-10-14 11:54:42 -07:00
|
|
|
}
|
2011-02-14 08:38:18 -08:00
|
|
|
|
|
|
|
EAPI void
|
2011-02-14 09:13:40 -08:00
|
|
|
elm_bg_load_size_set(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
|
2011-02-14 08:38:18 -08:00
|
|
|
{
|
2011-03-22 00:51:17 -07:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
2011-02-14 08:38:18 -08:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
const char *p;
|
|
|
|
if (!wd) return;
|
|
|
|
wd->load_opts.w = w;
|
|
|
|
wd->load_opts.h = h;
|
|
|
|
if (!wd->img) return;
|
|
|
|
if (!(((p = strrchr(wd->file, '.'))) && (!strcasecmp(p, ".edj"))))
|
2011-04-01 04:35:07 -07:00
|
|
|
evas_object_image_load_size_set(wd->img, w, h);
|
2011-02-14 08:38:18 -08:00
|
|
|
}
|
|
|
|
|