elementary: bg - keep file path and key string for legacy bg widget

Summary:
If a file path and key string was passed to elm_bg, we could get
the same file path and key string. Even if it failed to load the image file.
And the file path also remained its original form.
ex) Setting file path "~/image.png" => Getting file path "~/image.png"
                                       (Not "/home/user_name/image.png")

@fix

Test Plan: Included in elementary test suite.

Reviewers: jpeg, cedric, raster

Reviewed By: cedric

Subscribers: woohyun

Differential Revision: https://phab.enlightenment.org/D5823

Signed-off-by: Cedric Bail <cedric@osg.samsung.com>
This commit is contained in:
Youngbok Shin 2018-03-06 17:56:56 -08:00 committed by Cedric Bail
parent b63cdb6497
commit b147b5062f
4 changed files with 53 additions and 1 deletions

View File

@ -45,6 +45,8 @@ _efl_ui_bg_widget_efl_object_constructor(Eo *obj, Efl_Ui_Bg_Widget_Data *pd)
pd->img = efl_add(EFL_UI_IMAGE_CLASS, obj,
efl_image_scale_type_set(efl_added, EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE),
efl_content_set(efl_part(obj, "elm.swallow.background"), efl_added));
pd->file = NULL;
pd->key = NULL;
efl_access_type_set(obj, EFL_ACCESS_TYPE_DISABLED);
@ -53,6 +55,15 @@ _efl_ui_bg_widget_efl_object_constructor(Eo *obj, Efl_Ui_Bg_Widget_Data *pd)
return obj;
}
EOLIAN static void
_efl_ui_bg_widget_efl_object_destructor(Eo *obj, Efl_Ui_Bg_Widget_Data *sd)
{
ELM_SAFE_FREE(sd->file, eina_stringshare_del);
ELM_SAFE_FREE(sd->key, eina_stringshare_del);
efl_destructor(efl_super(obj, MY_CLASS));
}
EAPI void
elm_bg_option_set(Evas_Object *obj, Elm_Bg_Option option)
{
@ -191,6 +202,9 @@ elm_bg_file_set(Eo *obj, const char *file, const char *group)
EOLIAN static Eina_Bool
_efl_ui_bg_widget_efl_file_file_set(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd, const char *file, const char *key)
{
eina_stringshare_replace(&sd->file, file);
eina_stringshare_replace(&sd->key, key);
return efl_file_set(sd->img, file, key);
}
EAPI void
@ -200,8 +214,15 @@ elm_bg_file_get(const Eo *obj, const char **file, const char **group)
}
EOLIAN static void
_efl_ui_bg_widget_efl_file_file_get(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd, const char **file, const char **key)
_efl_ui_bg_widget_efl_file_file_get(Eo *obj, Efl_Ui_Bg_Widget_Data *sd, const char **file, const char **key)
{
if (elm_widget_is_legacy(obj))
{
*file = sd->file;
*key = sd->key;
return;
}
efl_file_get(sd->img, file, key);
}

View File

@ -9,6 +9,7 @@ class Efl.Ui.Bg_Widget (Efl.Ui.Layout, Efl.Ui.Bg, Efl.Image.Load)
legacy_prefix: elm_bg;
implements {
Efl.Object.constructor;
Efl.Object.destructor;
Efl.File.file { get; set; }
Efl.File.mmap { get; set; }
Efl.Gfx.Color.color { get; set; }

View File

@ -28,6 +28,8 @@ struct _Efl_Ui_Bg_Widget_Data
{
Evas_Object *rect; /*<< Used for elm_bg_color_set(): elm.swallow.rectangle */
Evas_Object *img; /*<< Used for elm_bg_file_set(): elm.swallow.content */
const char *file; /*<< Used for elm_bg_file_set() with legacy widget */
const char *key; /*<< Used for elm_bg_file_set() with legacy widget */
};
/**

View File

@ -28,7 +28,35 @@ START_TEST (elm_bg_legacy_type_check)
}
END_TEST
START_TEST (elm_bg_legacy_file_set_get_check)
{
Evas_Object *win, *bg;
const char *file = NULL, *key = NULL;
elm_init(1, NULL);
win = elm_win_add(NULL, "bg", ELM_WIN_BASIC);
bg = elm_bg_add(win);
/* This test case will check the following things for legacy widget.
* It is all about backward compatibility.
* 1. Set and Get file path, key even if there is no proper image file for the given file path.
* 2. Even if there is a proper image file and the given file path is interpreted to full file path,
* the Get function should give original file path. NOT interpreted. */
elm_bg_file_set(bg, "~/test.png", "test_key");
elm_bg_file_get(bg, &file, &key);
ck_assert(file != NULL);
ck_assert(!strcmp(file, "~/test.png"));
ck_assert(key != NULL);
ck_assert(!strcmp(key, "test_key"));
elm_shutdown();
}
END_TEST
void elm_test_bg(TCase *tc EINA_UNUSED)
{
tcase_add_test(tc, elm_bg_legacy_type_check);
tcase_add_test(tc, elm_bg_legacy_file_set_get_check);
}