[elementary/elm_label] Deprecated some APIs, and refactored

elm_label.c and label.edc files.


SVN revision: 68563
This commit is contained in:
WooHyun Jung 2012-03-01 04:49:23 +00:00
parent d7a8ea0da6
commit 78ae3dc90b
4 changed files with 50 additions and 327 deletions

View File

@ -12,17 +12,9 @@ group { name: "elm/label/base/default";
}
}
parts {
part { name: "label.swallow.background";
type: SWALLOW;
description { state: "default" 0.0;
visible: 1;
}
}
part { name: "label.text.clip";
type: RECT;
description { state: "default" 0.0;
rel1 { relative: 0 0; to: "label.swallow.background"; }
rel2 { relative: 1 1; to: "label.swallow.background"; }
}
}
part { name: "elm.text";
@ -53,14 +45,6 @@ group { name: "elm/label/base/marker";
}
}
parts {
part { name: "label.swallow.background";
type: SWALLOW;
description { state: "default" 0.0;
visible: 1;
rel1 { relative: 0 0; to: "elm.text"; }
rel2 { relative: 1 1; to: "elm.text"; }
}
}
part { name: "elm.text";
type: TEXTBLOCK;
scale: 1;
@ -136,19 +120,10 @@ group { name: "elm/label/base/slide_long";
}
parts {
part { name: "label.swallow.background";
type: SWALLOW;
description { state: "default" 0.0;
visible: 1;
}
}
part { name: "label.text.clip";
type: RECT;
description { state: "default" 0.0;
visible: 1;
color: 255 255 255 255;
rel1 { relative: 0 0; to: "label.swallow.background"; }
rel2 { relative: 1 1; to: "label.swallow.background"; }
}
}
part { name: "elm.text";
@ -261,19 +236,10 @@ group { name: "elm/label/base/slide_short";
}
parts {
part { name: "label.swallow.background";
type: SWALLOW;
description { state: "default" 0.0;
visible: 1;
}
}
part { name: "label.text.clip";
type: RECT;
description { state: "default" 0.0;
visible: 1;
color: 255 255 255 255;
rel1 { relative: 0 0; to: "label.swallow.background"; }
rel2 { relative: 1 1; to: "label.swallow.background"; }
}
}
part { name: "elm.text";
@ -397,19 +363,10 @@ group { name: "elm/label/base/slide_bounce";
}
parts {
part { name: "label.swallow.background";
type: SWALLOW;
description { state: "default" 0.0;
visible: 1;
}
}
part { name: "label.text.clip";
type: RECT;
description { state: "default" 0.0;
visible: 1;
color: 255 255 255 255;
rel1 { relative: 0 0; to: "label.swallow.background"; }
rel2 { relative: 1 1; to: "label.swallow.background"; }
}
}
part { name: "elm.text";

View File

@ -4229,7 +4229,7 @@ EINA_DEPRECATED EAPI const char *elm_pager_item_style_default_get(const Eva
*
* @warning NEVER use this. It is for hyper-special cases only. use styles
* instead. e.g. "default", "marker", "slide_long" etc.
* @deprecated Use tag instead
* @deprecated Use <font_size> tag instead. eg) <font_size=40>abc</font_size>
*/
EINA_DEPRECATED EAPI void elm_label_fontsize_set(Evas_Object *obj, int fontsize);
@ -4244,7 +4244,7 @@ EINA_DEPRECATED EAPI void elm_label_fontsize_set(Evas_Obj
*
* @warning NEVER use this. It is for hyper-special cases only. use styles
* instead. e.g. "default", "marker", "slide_long" etc.
* @deprecated Use tag instead
* @deprecated Use <color> tag instead. about <color> tag - Text color in one of the following formats: "#RRGGBB", "#RRGGBBAA", "#RGB", and "#RGBA"
*/
EINA_DEPRECATED EAPI void elm_label_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a);
@ -4256,7 +4256,7 @@ EINA_DEPRECATED EAPI void elm_label_text_color_set(Evas_O
*
* @warning NEVER use this. It is for hyper-special cases only. use styles
* instead. e.g. "default", "marker", "slide_long" etc.
* @deprecated Use tag instead
* @deprecated Use <align> tag instead. about <align> tag - Either "auto" (meaning according to text direction), "left", "right", "center", "middle", a value between 0.0 and 1.0, or a value between 0% to 100%.
*/
EINA_DEPRECATED EAPI void elm_label_text_align_set(Evas_Object *obj, const char *alignmode);
@ -4275,6 +4275,28 @@ EINA_DEPRECATED EAPI void elm_label_text_align_set(Evas_O
*/
EINA_DEPRECATED EAPI void elm_label_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a);
/**
* @brief Set wrap height of the label
*
* @param obj The label object
* @param h The wrap height in pixels at a minimum where words need to wrap
*
* This function sets the maximum height size hint of the label.
*
* @warning This is only relevant if the label is inside a container.
* @deprecated This function should not be used because of wrong concept.
*/
EAPI void elm_label_wrap_height_set(Evas_Object *obj, Evas_Coord h);
/**
* @brief get wrap width of the label
*
* @param obj The label object
* @return The wrap height in pixels at a minimum where words need to wrap
* @deprecated This function should not be used because of wrong concept.
*/
EAPI Evas_Coord elm_label_wrap_height_get(const Evas_Object *obj);
/**
* @brief Flush all caches.
*

View File

@ -6,17 +6,14 @@ typedef struct _Widget_Data Widget_Data;
struct _Widget_Data
{
Evas_Object *lbl;
Evas_Object *bg;
const char *label;
const char *format;
Ecore_Job *deferred_recalc_job;
double slide_duration;
Evas_Coord lastw;
Evas_Coord wrap_w;
Evas_Coord wrap_h;
Elm_Wrap_Type linewrap;
Eina_Bool changed : 1;
Eina_Bool bgcolor : 1;
Eina_Bool ellipsis : 1;
Eina_Bool slidingmode : 1;
Eina_Bool slidingellipsis : 1;
@ -30,8 +27,6 @@ static void _sizing_eval(Evas_Object *obj);
static int _get_value_in_key_string(const char *oldstring, const char *key, char **value);
static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, const char *key, const char *value, int deleteflag);
static int _stringshare_key_value_replace(const char **srcstring, const char *key, const char *value, int deleteflag);
static int _is_width_over(Evas_Object *obj);
static void _ellipsis_label_to_width(Evas_Object *obj);
static void _label_sliding_change(Evas_Object *obj);
static void
@ -58,11 +53,6 @@ _elm_recalc_job(void *data)
minw = ominw;
}
evas_object_size_hint_min_set(data, minw, minh);
evas_object_size_hint_max_set(data, wd->wrap_w, wd->wrap_h);
if ((wd->ellipsis) && (wd->linewrap) && (wd->wrap_h > 0) &&
(_is_width_over(data) == 1))
_ellipsis_label_to_width(data);
evas_event_thaw(evas_object_evas_get(data));
evas_event_thaw_eval(evas_object_evas_get(data));
}
@ -75,7 +65,6 @@ _del_hook(Evas_Object *obj)
evas_event_freeze(evas_object_evas_get(obj));
if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
if (wd->label) eina_stringshare_del(wd->label);
if (wd->bg) evas_object_del(wd->bg);
free(wd);
evas_event_thaw(evas_object_evas_get(obj));
evas_event_thaw_eval(evas_object_evas_get(obj));
@ -143,11 +132,7 @@ _sizing_eval(Evas_Object *obj)
evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
edje_object_size_min_calc(wd->lbl, &minw, &minh);
if (wd->wrap_w > 0 && minw > wd->wrap_w) minw = wd->wrap_w;
if (wd->wrap_h > 0 && minh > wd->wrap_h) minh = wd->wrap_h;
evas_object_size_hint_min_set(obj, minw, minh);
evas_object_size_hint_max_set(obj, wd->wrap_w, wd->wrap_h);
if ((wd->ellipsis) && (_is_width_over(obj) == 1))
_ellipsis_label_to_width(obj);
evas_event_thaw(evas_object_evas_get(obj));
evas_event_thaw_eval(evas_object_evas_get(obj));
}
@ -254,137 +239,6 @@ _stringshare_key_value_replace(const char **srcstring, const char *key, const ch
return 0;
}
static int
_is_width_over(Evas_Object *obj)
{
Evas_Coord x, y, w, h;
Evas_Coord vx, vy, vw, vh;
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return 0;
evas_event_freeze(evas_object_evas_get(obj));
edje_object_part_geometry_get(wd->lbl, "elm.text", &x, &y, NULL, NULL);
/* Calc the formatted size with ellipsis turned off */
if (wd->ellipsis)
{
const Evas_Object *tb;
char *_kvalue;
double ellipsis = 0.0;
Eina_Bool found_key = EINA_FALSE;
if (_get_value_in_key_string(wd->format, "ellipsis", &_kvalue) == 0)
{
ellipsis = atof(_kvalue);
found_key = EINA_TRUE;
}
if (_stringshare_key_value_replace(&wd->format,
"ellipsis", NULL, 1) == 0)
{
edje_object_part_text_style_user_set(wd->lbl, "elm.text",
wd->format);
edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
}
tb = edje_object_part_object_get(wd->lbl, "elm.text");
evas_object_textblock_size_formatted_get(tb, &w, &h);
if (found_key)
{
Eina_Strbuf *elpbuf;
elpbuf = eina_strbuf_new();
eina_strbuf_append_printf(elpbuf, "%f", ellipsis);
if (_stringshare_key_value_replace(&wd->format, "ellipsis",
eina_strbuf_string_get(elpbuf), 0) == 0)
{
edje_object_part_text_style_user_set(wd->lbl, "elm.text",
wd->format);
edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
}
eina_strbuf_free(elpbuf);
}
}
else
{
const Evas_Object *tb;
tb = edje_object_part_object_get(wd->lbl, "elm.text");
evas_object_textblock_size_formatted_get(tb, &w, &h);
}
evas_object_geometry_get(obj, &vx, &vy, &vw, &vh);
evas_event_thaw(evas_object_evas_get(obj));
evas_event_thaw_eval(evas_object_evas_get(obj));
if (w > wd->wrap_w || h > wd->wrap_h)
return 1;
return 0;
}
static void
_ellipsis_fontsize_set(Evas_Object *obj, int fontsize)
{
Widget_Data *wd = elm_widget_data_get(obj);
Eina_Strbuf *fontbuf = NULL;
int removeflag = 0;
if (!wd) return;
fontbuf = eina_strbuf_new();
eina_strbuf_append_printf(fontbuf, "%d", fontsize);
if (fontsize == 0) removeflag = 1; // remove fontsize tag
if (_stringshare_key_value_replace(&wd->format, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
{
edje_object_part_text_style_user_set(wd->lbl, "elm.text",
wd->format);
edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
}
eina_strbuf_free(fontbuf);
}
static void
_ellipsis_label_to_width(Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
int cur_fontsize = 0;
char *kvalue;
const char *minfont, *deffont, *maxfont;
int minfontsize, maxfontsize;
evas_event_freeze(evas_object_evas_get(obj));
minfont = edje_object_data_get(wd->lbl, "min_font_size");
if (minfont) minfontsize = atoi(minfont);
else minfontsize = 1;
maxfont = edje_object_data_get(wd->lbl, "max_font_size");
if (maxfont) maxfontsize = atoi(maxfont);
else maxfontsize = 1;
deffont = edje_object_data_get(wd->lbl, "default_font_size");
if (deffont) cur_fontsize = atoi(deffont);
else cur_fontsize = 1;
if (minfontsize > maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
if (eina_stringshare_strlen(wd->label) <= 0) return;
if (_get_value_in_key_string(wd->format, "font_size", &kvalue) == 0)
{
if (kvalue != NULL) cur_fontsize = atoi(kvalue);
}
while (_is_width_over(obj))
{
if (cur_fontsize > minfontsize)
{
cur_fontsize -= 3;
if (cur_fontsize < minfontsize) cur_fontsize = minfontsize;
_ellipsis_fontsize_set(obj, cur_fontsize);
}
else
{
break;
}
}
evas_event_thaw(evas_object_evas_get(obj));
evas_event_thaw_eval(evas_object_evas_get(obj));
}
static void
_label_sliding_change(Evas_Object *obj)
{
@ -492,16 +346,11 @@ elm_label_add(Evas_Object *parent)
elm_widget_text_get_hook_set(obj, _elm_label_label_get);
elm_widget_translate_hook_set(obj, _translate_hook);
wd->bgcolor = EINA_FALSE;
wd->bg = evas_object_rectangle_add(e);
evas_object_color_set(wd->bg, 0, 0, 0, 0);
wd->linewrap = ELM_WRAP_NONE;
wd->ellipsis = EINA_FALSE;
wd->slidingmode = EINA_FALSE;
wd->slidingellipsis = EINA_FALSE;
wd->wrap_w = -1;
wd->wrap_h = -1;
wd->slide_duration = 10;
wd->lbl = edje_object_add(e);
@ -611,134 +460,51 @@ elm_label_wrap_width_get(const Evas_Object *obj)
return wd->wrap_w;
}
EAPI void
elm_label_wrap_height_set(Evas_Object *obj,
Evas_Coord h)
EINA_DEPRECATED EAPI void
elm_label_wrap_height_set(Evas_Object *obj __UNUSED__,
Evas_Coord h __UNUSED__)
{
ELM_CHECK_WIDTYPE(obj, widtype);
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
if (h < 0) h = 0;
if (wd->wrap_h == h) return;
if (wd->ellipsis)
{
edje_object_part_text_style_user_set(wd->lbl, "elm.text",
wd->format);
edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
}
wd->wrap_h = h;
_sizing_eval(obj);
return;
}
EAPI Evas_Coord
elm_label_wrap_height_get(const Evas_Object *obj)
EINA_DEPRECATED EAPI Evas_Coord
elm_label_wrap_height_get(const Evas_Object *obj __UNUSED__)
{
ELM_CHECK_WIDTYPE(obj, widtype) 0;
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return 0;
return wd->wrap_h;
return 0;
}
EINA_DEPRECATED EAPI void
elm_label_fontsize_set(Evas_Object *obj, int fontsize)
elm_label_fontsize_set(Evas_Object *obj __UNUSED__,
int fontsize __UNUSED__)
{
ELM_CHECK_WIDTYPE(obj, widtype);
Widget_Data *wd = elm_widget_data_get(obj);
Eina_Strbuf *fontbuf = NULL;
int len, removeflag = 0;
if (!wd) return;
_elm_dangerous_call_check(__FUNCTION__);
len = strlen(wd->label);
if (len <= 0) return;
fontbuf = eina_strbuf_new();
eina_strbuf_append_printf(fontbuf, "%d", fontsize);
if (fontsize == 0) removeflag = 1; // remove fontsize tag
if (_stringshare_key_value_replace(&wd->format, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
{
edje_object_part_text_style_user_set(wd->lbl, "elm.text",
wd->format);
edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
wd->changed = 1;
_sizing_eval(obj);
}
eina_strbuf_free(fontbuf);
return;
}
EINA_DEPRECATED EAPI void
elm_label_text_align_set(Evas_Object *obj, const char *alignmode)
elm_label_text_align_set(Evas_Object *obj __UNUSED__,
const char *alignmode __UNUSED__)
{
ELM_CHECK_WIDTYPE(obj, widtype);
Widget_Data *wd = elm_widget_data_get(obj);
int len;
if (!wd) return;
_elm_dangerous_call_check(__FUNCTION__);
len = strlen(wd->label);
if (len <= 0) return;
if (_stringshare_key_value_replace(&wd->format, "align", alignmode, 0) == 0)
{
edje_object_part_text_style_user_set(wd->lbl, "elm.text",
wd->format);
edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
}
wd->changed = 1;
_sizing_eval(obj);
return;
}
EINA_DEPRECATED EAPI void
elm_label_text_color_set(Evas_Object *obj,
unsigned int r,
unsigned int g,
unsigned int b,
unsigned int a)
elm_label_text_color_set(Evas_Object *obj __UNUSED__,
unsigned int r __UNUSED__,
unsigned int g __UNUSED__,
unsigned int b __UNUSED__,
unsigned int a __UNUSED__)
{
ELM_CHECK_WIDTYPE(obj, widtype);
Widget_Data *wd = elm_widget_data_get(obj);
Eina_Strbuf *colorbuf = NULL;
int len;
if (!wd) return;
_elm_dangerous_call_check(__FUNCTION__);
len = strlen(wd->label);
if (len <= 0) return;
colorbuf = eina_strbuf_new();
eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
if (_stringshare_key_value_replace(&wd->format, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
{
edje_object_part_text_style_user_set(wd->lbl, "elm.text",
wd->format);
edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
wd->changed = 1;
_sizing_eval(obj);
}
eina_strbuf_free(colorbuf);
return;
}
EINA_DEPRECATED EAPI void
elm_label_background_color_set(Evas_Object *obj,
unsigned int r,
unsigned int g,
unsigned int b,
unsigned int a)
elm_label_background_color_set(Evas_Object *obj __UNUSED__,
unsigned int r __UNUSED__,
unsigned int g __UNUSED__,
unsigned int b __UNUSED__,
unsigned int a __UNUSED__)
{
ELM_CHECK_WIDTYPE(obj, widtype);
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
evas_object_color_set(wd->bg, r, g, b, a);
if (!wd) return;
_elm_dangerous_call_check(__FUNCTION__);
if (wd->bgcolor == EINA_FALSE)
{
wd->bgcolor = 1;
edje_object_part_swallow(wd->lbl, "label.swallow.background", wd->bg);
}
return;
}
EAPI void

View File

@ -85,28 +85,6 @@ EAPI void elm_label_wrap_width_set(Evas_Object *obj, Evas
*/
EAPI Evas_Coord elm_label_wrap_width_get(const Evas_Object *obj);
/**
* @brief Set wrap height of the label
*
* @param obj The label object
* @param h The wrap height in pixels at a minimum where words need to wrap
*
* This function sets the maximum height size hint of the label.
*
* @warning This is only relevant if the label is inside a container.
*/
//XXX: Maybe added for supporting multi-line ellipsis. Evas textblock supports multi-line ellipsis by itself, no more needs for this API.
EAPI void elm_label_wrap_height_set(Evas_Object *obj, Evas_Coord h);
/**
* @brief get wrap width of the label
*
* @param obj The label object
* @return The wrap height in pixels at a minimum where words need to wrap
*/
//XXX: Maybe added for supporting multi-line ellipsis. Evas textblock supports multi-line ellipsis by itself, no more needs for this API.
EAPI Evas_Coord elm_label_wrap_height_get(const Evas_Object *obj);
/**
* @brief Set the ellipsis behavior of the label
*