2013-04-25 22:13:00 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "elementary_config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-10-17 08:56:11 -07:00
|
|
|
#define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED
|
2016-04-20 05:07:38 -07:00
|
|
|
#define ELM_LAYOUT_PROTECTED
|
2014-10-17 08:56:11 -07:00
|
|
|
|
2008-09-29 23:58:56 -07:00
|
|
|
#include <Elementary.h>
|
|
|
|
#include "elm_priv.h"
|
2012-07-31 15:07:28 -07:00
|
|
|
#include "elm_widget_bg.h"
|
2012-11-25 22:32:53 -08:00
|
|
|
#include "elm_widget_layout.h"
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2014-06-03 03:35:28 -07:00
|
|
|
#define MY_CLASS ELM_BG_CLASS
|
2017-07-27 23:35:10 -07:00
|
|
|
#define MY_CLASS_PFX elm_bg
|
2012-11-25 22:32:53 -08:00
|
|
|
|
2013-11-07 03:44:22 -08:00
|
|
|
#define MY_CLASS_NAME "Elm_Bg"
|
|
|
|
#define MY_CLASS_NAME_LEGACY "elm_bg"
|
2012-05-03 15:41:32 -07:00
|
|
|
|
|
|
|
static const Elm_Layout_Part_Alias_Description _content_aliases[] =
|
2008-10-06 18:23:49 -07:00
|
|
|
{
|
2012-05-03 15:41:32 -07:00
|
|
|
{"overlay", "elm.swallow.content"},
|
|
|
|
{NULL, NULL}
|
|
|
|
};
|
2008-10-06 18:23:49 -07:00
|
|
|
|
2014-03-19 06:27:27 -07:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_bg_elm_layout_sizing_eval(Eo *obj, Elm_Bg_Data *sd)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2012-05-02 18:19:05 -07:00
|
|
|
Evas_Coord iw = 0, ih = 0, mw = -1, mh = -1;
|
2012-05-03 15:41:32 -07:00
|
|
|
Evas_Coord bx = 0, by = 0, bw = 0, bh = 0;
|
2010-10-12 07:38:46 -07:00
|
|
|
Evas_Coord fx = 0, fy = 0, fw = 0, fh = 0;
|
|
|
|
const char *p;
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2013-10-05 01:13:27 -07:00
|
|
|
ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
|
2012-05-03 15:41:32 -07:00
|
|
|
|
|
|
|
if ((!sd->img) || (!sd->file)) return;
|
|
|
|
if (((p = strrchr(sd->file, '.'))) && (!strcasecmp(p, ".edj"))) return;
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2010-10-12 07:38:46 -07:00
|
|
|
/* grab image size */
|
2012-05-03 15:41:32 -07:00
|
|
|
evas_object_image_size_get(sd->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 */
|
2012-05-03 15:41:32 -07:00
|
|
|
evas_object_geometry_get
|
2012-11-25 22:32:53 -08:00
|
|
|
(wd->resize_obj, &bx, &by, &bw, &bh);
|
2010-10-12 07:38:46 -07:00
|
|
|
|
2012-05-03 15:41:32 -07:00
|
|
|
switch (sd->option)
|
2010-10-11 21:12:48 -07:00
|
|
|
{
|
2010-10-12 07:38:46 -07:00
|
|
|
case ELM_BG_OPTION_CENTER:
|
2014-10-10 08:17:21 -07:00
|
|
|
fw = mw = iw;
|
|
|
|
fh = mh = ih;
|
2012-05-03 15:41:32 -07:00
|
|
|
break;
|
|
|
|
|
2010-10-12 07:38:46 -07:00
|
|
|
case ELM_BG_OPTION_SCALE:
|
2012-05-03 15:41:32 -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:
|
2012-05-03 15:41:32 -07:00
|
|
|
fw = iw;
|
|
|
|
fh = ih;
|
|
|
|
break;
|
|
|
|
|
2010-10-12 07:38:46 -07:00
|
|
|
case ELM_BG_OPTION_STRETCH:
|
|
|
|
default:
|
2012-05-03 15:41:32 -07:00
|
|
|
fw = bw;
|
|
|
|
fh = bh;
|
|
|
|
break;
|
2010-10-11 21:12:48 -07:00
|
|
|
}
|
2010-10-12 07:38:46 -07:00
|
|
|
|
2012-05-03 15:41:32 -07:00
|
|
|
evas_object_image_fill_set(sd->img, fx, fy, fw, fh);
|
2010-10-15 16:03:56 -07:00
|
|
|
|
2012-05-03 15:41:32 -07:00
|
|
|
evas_object_size_hint_min_set(sd->img, mw, mh);
|
|
|
|
evas_object_size_hint_max_set(sd->img, mw, mh);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
|
|
|
|
2011-10-28 01:31:42 -07:00
|
|
|
static void
|
2012-05-03 15:41:32 -07:00
|
|
|
_on_resize(void *data,
|
2014-01-06 06:30:02 -08:00
|
|
|
Evas *e EINA_UNUSED,
|
|
|
|
Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info EINA_UNUSED)
|
2011-10-28 01:31:42 -07:00
|
|
|
{
|
2012-05-03 15:41:32 -07:00
|
|
|
elm_layout_sizing_eval(data);
|
|
|
|
}
|
2012-03-29 04:09:40 -07:00
|
|
|
|
2014-03-19 06:27:27 -07:00
|
|
|
EOLIAN static void
|
2016-06-17 01:26:08 -07:00
|
|
|
_elm_bg_efl_canvas_group_group_add(Eo *obj, Elm_Bg_Data *priv)
|
2012-05-03 15:41:32 -07:00
|
|
|
{
|
2011-10-28 01:31:42 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_canvas_group_add(efl_super(obj, MY_CLASS));
|
2013-09-24 21:33:39 -07:00
|
|
|
elm_widget_sub_object_parent_add(obj);
|
2012-05-03 15:41:32 -07:00
|
|
|
elm_widget_can_focus_set(obj, EINA_FALSE);
|
2011-10-28 01:31:42 -07:00
|
|
|
|
2012-05-03 15:41:32 -07:00
|
|
|
priv->option = ELM_BG_OPTION_SCALE;
|
|
|
|
|
|
|
|
evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _on_resize, obj);
|
|
|
|
|
2013-03-01 18:04:31 -08:00
|
|
|
if (!elm_layout_theme_set(obj, "bg", "base", elm_widget_style_get(obj)))
|
2013-12-25 20:03:55 -08:00
|
|
|
CRI("Failed to set layout!");
|
2012-05-02 18:19:05 -07:00
|
|
|
}
|
2012-05-02 09:58:16 -07:00
|
|
|
|
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
|
|
|
{
|
2012-05-03 15:41:32 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
|
2017-07-06 00:47:41 -07:00
|
|
|
return efl_add(MY_CLASS, parent, efl_canvas_object_legacy_ctor(efl_added));
|
2012-11-25 22:32:53 -08:00
|
|
|
}
|
2012-05-02 18:19:05 -07:00
|
|
|
|
2015-05-19 05:34:07 -07:00
|
|
|
EOLIAN static Eo *
|
2016-08-10 07:23:04 -07:00
|
|
|
_elm_bg_efl_object_constructor(Eo *obj, Elm_Bg_Data *_pd EINA_UNUSED)
|
2012-11-25 22:32:53 -08:00
|
|
|
{
|
2016-03-02 04:10:48 -08:00
|
|
|
elm_interface_atspi_accessible_type_set(obj, ELM_ATSPI_TYPE_DISABLED);
|
2016-08-15 06:44:41 -07:00
|
|
|
obj = efl_constructor(efl_super(obj, MY_CLASS));
|
2016-06-20 21:26:15 -07:00
|
|
|
efl_canvas_object_type_set(obj, MY_CLASS_NAME_LEGACY);
|
2015-05-19 05:34:07 -07:00
|
|
|
|
|
|
|
return obj;
|
2008-10-06 18:23:49 -07:00
|
|
|
}
|
|
|
|
|
2014-03-19 06:27:27 -07:00
|
|
|
EOLIAN static Eina_Bool
|
2014-07-22 07:44:52 -07:00
|
|
|
_elm_bg_efl_file_file_set(Eo *obj, Elm_Bg_Data *sd, const char *file, const char *group)
|
2008-10-06 18:23:49 -07:00
|
|
|
{
|
2014-03-19 06:27:27 -07:00
|
|
|
ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EINA_FALSE);
|
2012-05-03 15:41:32 -07:00
|
|
|
|
2008-09-29 23:58:56 -07:00
|
|
|
const char *p;
|
2012-11-25 22:32:53 -08:00
|
|
|
Eina_Bool int_ret;
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2014-01-21 17:38:55 -08:00
|
|
|
ELM_SAFE_FREE(sd->img, evas_object_del);
|
2010-11-25 07:16:48 -08:00
|
|
|
if (!file)
|
|
|
|
{
|
2013-05-29 04:22:54 -07:00
|
|
|
ELM_SAFE_FREE(sd->file, eina_stringshare_del);
|
|
|
|
ELM_SAFE_FREE(sd->group, eina_stringshare_del);
|
2014-03-19 06:27:27 -07:00
|
|
|
return EINA_TRUE;
|
2010-11-25 07:16:48 -08:00
|
|
|
}
|
2012-05-03 15:41:32 -07:00
|
|
|
eina_stringshare_replace(&sd->file, file);
|
|
|
|
eina_stringshare_replace(&sd->group, group);
|
2008-09-29 23:58:56 -07:00
|
|
|
if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
|
|
|
|
{
|
2012-05-03 15:41:32 -07:00
|
|
|
sd->img = edje_object_add
|
2012-11-25 22:32:53 -08:00
|
|
|
(evas_object_evas_get(wd->resize_obj));
|
|
|
|
int_ret = edje_object_file_set(sd->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
|
|
|
{
|
2012-05-03 15:41:32 -07:00
|
|
|
int err;
|
|
|
|
|
|
|
|
sd->img = evas_object_image_add
|
2012-11-25 22:32:53 -08:00
|
|
|
(evas_object_evas_get(wd->resize_obj));
|
2017-01-13 03:23:54 -08:00
|
|
|
evas_object_image_load_orientation_set(sd->img, EINA_TRUE);
|
2012-05-03 15:41:32 -07:00
|
|
|
if ((sd->load_opts.w > 0) && (sd->load_opts.h > 0))
|
|
|
|
evas_object_image_load_size_set
|
|
|
|
(sd->img, sd->load_opts.w, sd->load_opts.h);
|
|
|
|
evas_object_image_file_set(sd->img, file, group);
|
|
|
|
|
|
|
|
err = evas_object_image_load_error_get(sd->img);
|
|
|
|
if (err != EVAS_LOAD_ERROR_NONE)
|
|
|
|
{
|
|
|
|
ERR("Could not load image '%s': %s\n",
|
|
|
|
file, evas_load_error_str(err));
|
2012-11-25 22:32:53 -08:00
|
|
|
int_ret = EINA_FALSE;
|
2012-05-03 15:41:32 -07:00
|
|
|
}
|
|
|
|
else
|
2012-11-25 22:32:53 -08:00
|
|
|
int_ret = EINA_TRUE;
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2012-03-06 14:12:42 -08:00
|
|
|
|
2012-05-03 15:41:32 -07:00
|
|
|
evas_object_repeat_events_set(sd->img, EINA_TRUE);
|
|
|
|
|
2012-11-25 22:32:53 -08:00
|
|
|
int_ret &= elm_layout_content_set(obj, "elm.swallow.background", sd->img);
|
2012-05-03 15:41:32 -07:00
|
|
|
|
|
|
|
elm_layout_sizing_eval(obj);
|
|
|
|
|
2014-03-19 06:27:27 -07:00
|
|
|
return int_ret;
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2010-10-11 21:12:48 -07:00
|
|
|
|
2014-03-19 06:27:27 -07:00
|
|
|
EOLIAN static void
|
2014-07-22 07:44:52 -07:00
|
|
|
_elm_bg_efl_file_file_get(Eo *obj EINA_UNUSED, Elm_Bg_Data *sd, const char **file, const char **group)
|
2012-11-25 22:32:53 -08:00
|
|
|
{
|
2012-05-03 15:41:32 -07:00
|
|
|
if (file) *file = sd->file;
|
|
|
|
if (group) *group = sd->group;
|
2010-10-27 07:38:37 -07:00
|
|
|
}
|
|
|
|
|
2014-03-19 06:27:27 -07:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_bg_option_set(Eo *obj, Elm_Bg_Data *sd, Elm_Bg_Option option)
|
2010-10-11 21:12:48 -07:00
|
|
|
{
|
2012-05-03 15:41:32 -07:00
|
|
|
sd->option = option;
|
2012-03-06 14:12:42 -08:00
|
|
|
|
2012-05-03 15:41:32 -07:00
|
|
|
elm_layout_sizing_eval(obj);
|
2010-10-11 21:12:48 -07:00
|
|
|
}
|
2010-10-12 01:46:17 -07:00
|
|
|
|
2014-03-19 06:27:27 -07:00
|
|
|
EOLIAN static Elm_Bg_Option
|
|
|
|
_elm_bg_option_get(Eo *obj EINA_UNUSED, Elm_Bg_Data *sd)
|
2010-10-27 07:38:37 -07:00
|
|
|
{
|
2014-03-19 06:27:27 -07:00
|
|
|
return sd->option;
|
2010-10-27 07:38:37 -07:00
|
|
|
}
|
|
|
|
|
2012-03-06 14:35:27 -08:00
|
|
|
EAPI void
|
2012-05-03 15:41:32 -07:00
|
|
|
elm_bg_color_set(Evas_Object *obj,
|
|
|
|
int r,
|
|
|
|
int g,
|
|
|
|
int b)
|
2010-10-12 01:46:17 -07:00
|
|
|
{
|
2012-05-03 15:41:32 -07:00
|
|
|
ELM_BG_CHECK(obj);
|
2016-03-02 04:10:48 -08:00
|
|
|
elm_obj_bg_color_set(obj, r, g, b, 255);
|
2012-11-25 22:32:53 -08:00
|
|
|
}
|
|
|
|
|
2014-03-19 06:27:27 -07:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_bg_color_set(Eo *obj, Elm_Bg_Data *sd, int r, int g, int b, int a)
|
2012-11-25 22:32:53 -08:00
|
|
|
{
|
2013-10-05 01:13:27 -07:00
|
|
|
ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
|
2010-10-12 01:46:17 -07:00
|
|
|
|
2013-08-28 03:31:40 -07:00
|
|
|
// reset color
|
|
|
|
if ((r == -1) && (g == -1) && (b == -1))
|
|
|
|
{
|
|
|
|
ELM_SAFE_FREE(sd->rect, evas_object_del);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-03 15:41:32 -07:00
|
|
|
if (!sd->rect)
|
2010-10-12 01:46:17 -07:00
|
|
|
{
|
2012-05-03 15:41:32 -07:00
|
|
|
sd->rect = evas_object_rectangle_add
|
2012-11-25 22:32:53 -08:00
|
|
|
(evas_object_evas_get(wd->resize_obj));
|
2012-05-03 15:41:32 -07:00
|
|
|
|
|
|
|
elm_layout_content_set(obj, "elm.swallow.rectangle", sd->rect);
|
|
|
|
|
|
|
|
elm_layout_sizing_eval(obj);
|
2010-10-12 01:46:17 -07:00
|
|
|
}
|
2012-03-06 14:12:42 -08:00
|
|
|
|
2013-08-28 20:35:13 -07:00
|
|
|
evas_object_color_set(sd->rect, r, g, b, a);
|
2010-10-12 01:46:17 -07:00
|
|
|
}
|
|
|
|
|
2012-03-06 14:35:27 -08:00
|
|
|
EAPI void
|
2012-05-03 15:41:32 -07:00
|
|
|
elm_bg_color_get(const Evas_Object *obj,
|
|
|
|
int *r,
|
|
|
|
int *g,
|
|
|
|
int *b)
|
2010-10-27 07:38:37 -07:00
|
|
|
{
|
2012-05-03 15:41:32 -07:00
|
|
|
ELM_BG_CHECK(obj);
|
2016-03-02 04:10:48 -08:00
|
|
|
elm_obj_bg_color_get((Eo *) obj, r, g, b, NULL);
|
2012-11-25 22:32:53 -08:00
|
|
|
}
|
|
|
|
|
2014-03-19 06:27:27 -07:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_bg_color_get(Eo *obj EINA_UNUSED, Elm_Bg_Data *sd, int *r, int *g, int *b, int *a)
|
2012-11-25 22:32:53 -08:00
|
|
|
{
|
2013-08-28 20:35:13 -07:00
|
|
|
evas_object_color_get(sd->rect, r, g, b, a);
|
2010-10-27 07:38:37 -07:00
|
|
|
}
|
|
|
|
|
2014-03-19 06:27:27 -07:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_bg_load_size_set(Eo *obj EINA_UNUSED, Elm_Bg_Data *sd, Evas_Coord w, Evas_Coord h)
|
2012-11-25 22:32:53 -08:00
|
|
|
{
|
2011-02-14 08:38:18 -08:00
|
|
|
const char *p;
|
2012-05-02 18:19:05 -07:00
|
|
|
|
2012-05-03 15:41:32 -07:00
|
|
|
sd->load_opts.w = w;
|
|
|
|
sd->load_opts.h = h;
|
|
|
|
if (!sd->img) return;
|
|
|
|
|
|
|
|
if (!(((p = strrchr(sd->file, '.'))) && (!strcasecmp(p, ".edj"))))
|
|
|
|
evas_object_image_load_size_set(sd->img, w, h);
|
|
|
|
}
|
2012-11-25 22:32:53 -08:00
|
|
|
|
|
|
|
static void
|
2016-08-10 07:23:04 -07:00
|
|
|
_elm_bg_class_constructor(Efl_Class *klass)
|
2012-11-25 22:32:53 -08:00
|
|
|
{
|
2013-11-07 03:44:22 -08:00
|
|
|
evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
|
2012-11-25 22:32:53 -08:00
|
|
|
}
|
|
|
|
|
2014-07-22 07:44:52 -07:00
|
|
|
EAPI Eina_Bool
|
|
|
|
elm_bg_file_set(Eo *obj, const char *file, const char *group)
|
|
|
|
{
|
2016-03-02 04:10:48 -08:00
|
|
|
return efl_file_set((Eo *) obj, file, group);
|
2014-07-22 07:44:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_bg_file_get(const Eo *obj, const char **file, const char **group)
|
|
|
|
{
|
2016-03-02 04:10:48 -08:00
|
|
|
efl_file_get((Eo *) obj, file, group);
|
2014-07-22 07:44:52 -07:00
|
|
|
}
|
|
|
|
|
2017-05-18 01:52:17 -07:00
|
|
|
/* Internal EO APIs and hidden overrides */
|
|
|
|
|
2017-08-07 19:48:31 -07:00
|
|
|
ELM_LAYOUT_CONTENT_ALIASES_IMPLEMENT(MY_CLASS_PFX)
|
2017-07-27 23:35:10 -07:00
|
|
|
|
2017-05-18 01:52:17 -07:00
|
|
|
#define ELM_BG_EXTRA_OPS \
|
2017-08-07 19:48:31 -07:00
|
|
|
ELM_LAYOUT_CONTENT_ALIASES_OPS(MY_CLASS_PFX), \
|
2017-08-07 00:13:38 -07:00
|
|
|
ELM_LAYOUT_SIZING_EVAL_OPS(elm_bg), \
|
2017-05-18 01:52:17 -07:00
|
|
|
EFL_CANVAS_GROUP_ADD_OPS(elm_bg)
|
|
|
|
|
2014-03-19 06:27:27 -07:00
|
|
|
#include "elm_bg.eo.c"
|