1 #include <Elementary.h>
5 * @defgroup Label Label
8 * Display text, with simple html-like markup. The theme of course
9 * can invent new markup tags and style them any way it likes
12 typedef struct _Widget_Data Widget_Data;
20 Ecore_Job *deferred_recalc_job;
23 Eina_Bool linewrap : 1;
24 Eina_Bool wrapmode : 1;
25 Eina_Bool slidingmode : 1;
26 Eina_Bool slidingellipsis : 1;
27 Eina_Bool changed : 1;
28 Eina_Bool bgcolor : 1;
29 Eina_Bool ellipsis : 1;
33 static const char *widtype = NULL;
34 static void _del_hook(Evas_Object *obj);
35 static void _theme_hook(Evas_Object *obj);
36 static void _sizing_eval(Evas_Object *obj);
37 static int _get_value_in_key_string(const char *oldstring, char *key, char **value);
38 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag);
39 static int _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag);
40 static int _is_width_over(Evas_Object *obj, int linemode);
41 static void _ellipsis_label_to_width(Evas_Object *obj, int linemode);
44 _elm_win_recalc_job(void *data)
46 Widget_Data *wd = elm_widget_data_get(data);
47 Evas_Coord minw = -1, minh = -1, maxh = -1;
48 Evas_Coord resw, resh, minminw, minminh;
50 wd->deferred_recalc_job = NULL;
51 evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
54 edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, 0, 0);
57 if (wd->wrap_w >= resw)
60 edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, resw, 0);
61 evas_object_size_hint_min_set(data, minw, minh);
65 if (wd->wrap_w > minminw) minminw = wd->wrap_w;
66 edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, resw, 0);
67 evas_object_size_hint_min_set(data, minminw, minh);
70 if (wd->ellipsis && wd->linewrap && wd->wrap_h > 0 && _is_width_over(data, 1) == 1)
71 _ellipsis_label_to_width(data, 1);
74 evas_object_size_hint_max_set(data, -1, maxh);
78 _del_hook(Evas_Object *obj)
80 Widget_Data *wd = elm_widget_data_get(obj);
82 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
83 if (wd->label) eina_stringshare_del(wd->label);
84 if (wd->bg) evas_object_del(wd->bg);
89 _theme_change(Evas_Object *obj)
91 Widget_Data *wd = elm_widget_data_get(obj);
97 _elm_theme_object_set(obj, wd->lbl, "label", "base_wrap_ellipsis", elm_widget_style_get(obj));
99 _elm_theme_object_set(obj, wd->lbl, "label", "base_wrap", elm_widget_style_get(obj));
102 _elm_theme_object_set(obj, wd->lbl, "label", "base", elm_widget_style_get(obj));
107 _theme_hook(Evas_Object *obj)
109 Widget_Data *wd = elm_widget_data_get(obj);
112 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
113 edje_object_scale_set(wd->lbl, elm_widget_scale_get(obj) *
119 _sizing_eval(Evas_Object *obj)
121 Widget_Data *wd = elm_widget_data_get(obj);
122 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
123 Evas_Coord resw, resh;
127 evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
128 if ((resw == wd->lastw) && (!wd->changed)) return;
129 wd->changed = EINA_FALSE;
131 _elm_win_recalc_job(obj);
132 // FIXME: works ok. but NOT for genlist. what should genlist do?
133 // if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
134 // wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
138 evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
139 edje_object_size_min_calc(wd->lbl, &minw, &minh);
140 if (wd->wrap_w > 0 && minw > wd->wrap_w)
142 evas_object_size_hint_min_set(obj, minw, minh);
144 evas_object_size_hint_max_set(obj, maxw, maxh);
146 if (wd->ellipsis && _is_width_over(obj, 0) == 1)
147 _ellipsis_label_to_width(obj, 0);
152 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
154 Widget_Data *wd = elm_widget_data_get(data);
156 if (wd->linewrap) _sizing_eval(data);
160 _get_value_in_key_string(const char *oldstring, char *key, char **value)
162 char *curlocater, *starttag, *endtag;
163 int firstindex = 0, foundflag = -1;
165 curlocater = strstr(oldstring, key);
168 starttag = curlocater;
169 endtag = curlocater + strlen(key);
170 if (endtag == NULL || *endtag != '=')
176 firstindex = abs(oldstring - curlocater);
177 firstindex += strlen(key)+1; // strlen("key") + strlen("=")
178 *value = (char*)(oldstring + firstindex);
180 while (oldstring != starttag)
182 if (*starttag == '>')
187 if (*starttag == '<')
191 if (starttag == NULL) break;
194 while (NULL != endtag)
205 if (endtag == NULL) break;
208 if (foundflag != 0 && *starttag == '<' && *endtag == '>')
218 if (foundflag == 1) return 0;
224 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
226 const char *srcstring = NULL;
227 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
228 char *curlocater, *replocater;
229 char *starttag, *endtag;
230 int tagtxtlen = 0, insertflag = 0;
232 srcstring = eina_strbuf_string_get(srcbuf);
233 curlocater = strstr(srcstring, key);
235 if (curlocater == NULL)
243 starttag = strchr(srcstring, '<');
244 endtag = strchr(srcstring, '>');
245 tagtxtlen = endtag - starttag;
246 if (tagtxtlen <= 0) tagtxtlen = 0;
247 if (starttag < curlocater && curlocater < endtag) break;
248 if (endtag != NULL && endtag+1 != NULL)
249 srcstring = endtag+1;
252 } while (strlen(srcstring) > 1);
254 if (starttag && endtag && tagtxtlen > strlen(key))
256 repbuf = eina_strbuf_new();
257 diffbuf = eina_strbuf_new();
258 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
259 srcstring = eina_strbuf_string_get(repbuf);
260 curlocater = strstr(srcstring, key);
262 if (curlocater != NULL)
264 replocater = curlocater + strlen(key) + 1;
266 while (*replocater == ' ' || *replocater == '=')
271 while (replocater != NULL && *replocater != ' ' && *replocater != '>')
274 if (replocater-curlocater > strlen(key)+1)
277 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
286 eina_strbuf_reset(repbuf);
294 if (repbuf == NULL) repbuf = eina_strbuf_new();
295 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
299 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
300 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
306 eina_strbuf_prepend(diffbuf, "<");
307 eina_strbuf_append(diffbuf, ">");
308 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
312 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
313 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
317 if (repbuf) eina_strbuf_free(repbuf);
318 if (diffbuf) eina_strbuf_free(diffbuf);
324 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
326 Eina_Strbuf *sharebuf = NULL;
328 sharebuf = eina_strbuf_new();
329 eina_strbuf_append(sharebuf, *srcstring);
330 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
331 eina_stringshare_del(*srcstring);
332 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
333 eina_strbuf_free(sharebuf);
339 // FIXME: move to some where(such as elm_util??).
340 // copied from elm_entry for check pure text length w/o tags.
342 _str_append(char *str, const char *txt, int *len, int *alloc)
344 int txt_len = strlen(txt);
346 if (txt_len <= 0) return str;
347 if ((*len + txt_len) >= *alloc)
352 alloc2 = *alloc + txt_len + 128;
353 str2 = realloc(str, alloc2);
354 if (!str2) return str;
358 strcpy(str + *len, txt);
363 // FIXME: move to some where(such as elm_util??).
364 // copied from elm_entry for check pure text length w/o tags.
366 _strncpy(char* dest, const char* src, size_t count)
370 ERR( "dest is NULL" );
375 ERR( "src is NULL" );
380 ERR( "count is smaller than 0" );
384 return strncpy( dest, src, count );
387 // FIXME: move to some where(such as elm_util??).
388 // copied from elm_entry for check pure text length w/o tags.
390 _mkup_to_text(const char *mkup)
393 int str_len = 0, str_alloc = 0;
395 char *tag_start, *tag_end, *esc_start, *esc_end, *ts;
397 if (!mkup) return NULL;
399 tag_start = tag_end = esc_start = esc_end = NULL;
404 if (((p!=NULL)&&(*p == 0)) ||
405 (tag_end) || (esc_end) ||
406 (tag_start) || (esc_start))
412 ttag = malloc(tag_end - tag_start);
415 _strncpy(ttag, tag_start + 1, tag_end - tag_start - 1);
416 ttag[tag_end - tag_start - 1] = 0;
417 if (!strcmp(ttag, "br"))
418 str = _str_append(str, "\n", &str_len, &str_alloc);
419 else if (!strcmp(ttag, "\n"))
420 str = _str_append(str, "\n", &str_len, &str_alloc);
421 else if (!strcmp(ttag, "\\n"))
422 str = _str_append(str, "\n", &str_len, &str_alloc);
423 else if (!strcmp(ttag, "\t"))
424 str = _str_append(str, "\t", &str_len, &str_alloc);
425 else if (!strcmp(ttag, "\\t"))
426 str = _str_append(str, "\t", &str_len, &str_alloc);
427 else if (!strcmp(ttag, "ps")) /* Unicode paragraph separator */
428 str = _str_append(str, "\xE2\x80\xA9", &str_len, &str_alloc);
431 tag_start = tag_end = NULL;
435 ts = malloc(esc_end - esc_start + 1);
439 _strncpy(ts, esc_start, esc_end - esc_start);
440 ts[esc_end - esc_start] = 0;
441 esc = evas_textblock_escape_string_get(ts);
443 str = _str_append(str, esc, &str_len, &str_alloc);
446 esc_start = esc_end = NULL;
448 else if ((p!=NULL)&&(*p == 0))
450 ts = malloc(p - s + 1);
453 _strncpy(ts, s, p - s);
455 str = _str_append(str, ts, &str_len, &str_alloc);
461 if ((p!=NULL)&&(*p == '<'))
467 ts = malloc(p - s + 1);
470 _strncpy(ts, s, p - s);
472 str = _str_append(str, ts, &str_len, &str_alloc);
478 else if ((p!=NULL)&&(*p == '>'))
486 else if ((p!=NULL)&&(*p == '&'))
492 ts = malloc(p - s + 1);
495 _strncpy(ts, s, p - s);
497 str = _str_append(str, ts, &str_len, &str_alloc);
503 else if ((p!=NULL)&&(*p == ';'))
517 _is_width_over(Evas_Object *obj, int linemode)
519 Evas_Coord x, y, w, h;
520 Evas_Coord vx, vy, vw, vh;
521 Widget_Data *wd = elm_widget_data_get(obj);
522 const char *ellipsis_string = "...";
523 size_t ellen = strlen(ellipsis_string)+1;
527 // too short to ellipsis
528 char *plaintxt = _mkup_to_text(edje_object_part_text_get(wd->lbl, "elm.text"));
530 if (plaintxt != NULL)
532 plainlen = strlen(plaintxt);
535 if (plainlen <= ellen) return 0;
537 edje_object_part_geometry_get(wd->lbl, "elm.text", &x, &y, &w, &h);
539 evas_object_geometry_get(obj, &vx, &vy, &vw, &vh);
542 fprintf(stderr, "## _is_width_over\n");
543 fprintf(stderr, "## x = %d, y = %d, w = %d, h = %d\n", x, y, w, h);
544 fprintf(stderr, "## vx = %d, vy = %d, vw = %d, vh = %d\n", vx, vy, vw, vh);
546 fprintf(stderr, "## wd->wrap_w = %d, wd->wrap_h = %d\n", wd->wrap_w, wd->wrap_h);
548 fprintf(stderr, "## wd->wrap_w = %d\n", wd->wrap_w);
549 fprintf(stderr, "## check str = %s\n", edje_object_part_text_get(wd->lbl, "elm.text"));
552 if (linemode == 0) // single line
554 // skip if too early to check widget size
557 // if string fits at widget
558 if ((x >= 0) && (y >= 0))
560 if ((wd->wrap_w > 0) && (wd->wrap_w < w))
562 Evas_Coord minw, minh;
563 edje_object_size_min_calc(wd->lbl, &minw, &minh);
565 if (minw < wd->wrap_w)
566 { // min insufficient
576 if (0 < wd->wrap_w && w > wd->wrap_w) return 1;
580 // if (vy > h && h > wd->wrap_h) return 1;
581 if ((x >= 0 || y >= 0) && h > wd->wrap_h) return 1;
588 _ellipsis_fontsize_set(Evas_Object *obj, int fontsize)
590 Widget_Data *wd = elm_widget_data_get(obj);
593 Eina_Strbuf *fontbuf = NULL;
594 Eina_Strbuf *txtbuf = NULL;
595 txtbuf = eina_strbuf_new();
596 fontbuf = eina_strbuf_new();
597 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->lbl, "elm.text"));
598 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
599 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
600 edje_object_part_text_set(wd->lbl, "elm.text", eina_strbuf_string_get(txtbuf));
601 eina_strbuf_free(fontbuf);
602 eina_strbuf_free(txtbuf);
606 _ellipsis_cut_chars_to_widget(Evas_Object *obj, int fontsize, int linemode)
608 Widget_Data *wd = elm_widget_data_get(obj);
609 if (!wd) return EINA_FALSE;
611 const char *ellipsis_string = "...";
612 int minshowcount = strlen(ellipsis_string);
614 Evas_Textblock_Cursor *tc1, *tc2;
615 char *cutstr, *elstr;
620 edje_object_part_geometry_get(wd->lbl,"elm.text", NULL, NULL, &w, &h);
623 tc1 = evas_object_textblock_cursor_new((Evas_Object*)edje_object_part_object_get(wd->lbl, "elm.text"));
624 tc2 = evas_object_textblock_cursor_new((Evas_Object*)edje_object_part_object_get(wd->lbl, "elm.text"));
626 if (wd->wrap_w > 0 && wd->wrap_w < w)
630 evas_textblock_cursor_pos_set(tc1, 0);
631 evas_textblock_cursor_char_coord_set(tc2, limitw, 0);
632 for (i = 0; i <= minshowcount; i++)
633 evas_textblock_cursor_char_prev(tc2);
634 cutstr = evas_textblock_cursor_range_text_get(tc1, tc2, EVAS_TEXTBLOCK_TEXT_PLAIN);
637 int eolpos = evas_textblock_cursor_paragraph_text_length_get(tc1);
638 Evas_Coord cx, cy, cw, ch;
639 for (i = eolpos; i > minshowcount; i--)
641 evas_textblock_cursor_pos_set(tc2, i);
642 fprintf(stderr, "## tc2 = %d\n", evas_textblock_cursor_pos_get(tc2));
643 evas_textblock_cursor_char_geometry_get(tc2, &cx, &cy, &cw, &ch);
644 fprintf(stderr, "## limitw = %d\n", limitw);
645 fprintf(stderr, "## cx = %d, cy = %d, cw = %d, ch = %d\n", cx, cy, cw, ch);
651 // FIXME: consider other unicode encoding, currently only care about utf-8
652 lencutstr = strlen(cutstr);
653 elstr = malloc(sizeof(char)*(lencutstr+minshowcount+1));
654 strcpy(elstr, cutstr);
655 strcat(elstr, ellipsis_string);
657 edje_object_part_text_set(wd->lbl, "elm.text", elstr);
660 evas_textblock_cursor_free(tc1);
661 evas_textblock_cursor_free(tc2);
667 _ellipsis_cut_lines_to_widget(Evas_Object *obj, int fontsize, int linemode)
669 Widget_Data *wd = elm_widget_data_get(obj);
670 if (!wd) return EINA_FALSE;
672 const char *ellipsis_string = "...";
673 int minshowcount = strlen(ellipsis_string);
675 Evas_Textblock_Cursor *tc1, *tc2;
676 int linenum = 0, cutline = 0;
677 double lineheight = 0.0;
678 char *cutstr, *elstr;
683 edje_object_part_geometry_get(wd->lbl,"elm.text", NULL, NULL, &w, &h);
685 tc1 = evas_object_textblock_cursor_new((Evas_Object*)edje_object_part_object_get(wd->lbl, "elm.text"));
686 tc2 = evas_object_textblock_cursor_new((Evas_Object*)edje_object_part_object_get(wd->lbl, "elm.text"));
687 // goto last paragraph
688 while (evas_textblock_cursor_paragraph_next(tc2) == EINA_TRUE)
690 evas_textblock_cursor_paragraph_last(tc2);
691 // get total linenumber
692 linenum = evas_textblock_cursor_line_geometry_get(tc2, NULL, NULL, NULL, NULL);
693 lineheight = h/linenum * 1.0;
694 if (wd->wrap_h > 0 && wd->wrap_h < h)
698 cutline = limith / lineheight;
702 evas_textblock_cursor_pos_set(tc1, 0);
703 evas_textblock_cursor_line_set(tc2, cutline-1);
704 evas_textblock_cursor_line_char_last(tc2);
705 for (i = 0; i <= minshowcount; i++)
706 evas_textblock_cursor_char_prev(tc2);
707 cutstr = evas_textblock_cursor_range_text_get(tc1, tc2, EVAS_TEXTBLOCK_TEXT_PLAIN);
709 // FIXME: consider other unicode encoding, currently only care about utf-8
710 lencutstr = strlen(cutstr);
711 elstr = malloc(sizeof(char)*(lencutstr+minshowcount+1));
712 strcpy(elstr, cutstr);
713 strcat(elstr, ellipsis_string);
715 edje_object_part_text_set(wd->lbl, "elm.text", elstr);
718 evas_textblock_cursor_free(tc1);
719 evas_textblock_cursor_free(tc2);
725 _ellipsis_label_to_width(Evas_Object *obj, int linemode)
727 Widget_Data *wd = elm_widget_data_get(obj);
730 int cur_fontsize = 0;
732 const char *minfont, *deffont, *maxfont;
733 int minfontsize, maxfontsize;
735 minfont = edje_object_data_get(wd->lbl, "min_font_size");
736 if (minfont) minfontsize = atoi(minfont);
737 else minfontsize = 1;
738 maxfont = edje_object_data_get(wd->lbl, "max_font_size");
739 if (maxfont) maxfontsize = atoi(maxfont);
740 else maxfontsize = 1;
741 deffont = edje_object_data_get(wd->lbl, "default_font_size");
742 if (deffont) cur_fontsize = atoi(deffont);
743 else cur_fontsize = 1;
744 if (minfontsize > maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
745 if (eina_stringshare_strlen(wd->label) <= 0) return;
747 if (_get_value_in_key_string(wd->label, "font_size", &kvalue) == 0)
749 if (kvalue != NULL) cur_fontsize = atoi(kvalue);
750 fprintf(stderr, "## cur_fontsize = %d\n", cur_fontsize);
754 while (_is_width_over(obj, linemode))
756 if (cur_fontsize > minfontsize)
759 if (cur_fontsize < minfontsize)
760 cur_fontsize = minfontsize;
761 _ellipsis_fontsize_set(obj, cur_fontsize);
765 if (linemode == 0) // single line
767 _ellipsis_cut_chars_to_widget(obj, cur_fontsize, linemode);
772 _ellipsis_cut_lines_to_widget(obj, cur_fontsize, linemode);
780 * setting internal state of mulitline label.
781 * singleline doesn't need it
784 void _label_state_change(Evas_Object *obj)
786 Widget_Data *wd = elm_widget_data_get(obj);
792 edje_object_signal_emit(wd->lbl, "elm,state,wordwrap", "elm");
794 edje_object_signal_emit(wd->lbl, "elm,state,default", "elm");
798 void _label_sliding_change(Evas_Object *obj)
800 Widget_Data *wd = elm_widget_data_get(obj);
805 wd->slidingmode = EINA_FALSE;
806 fprintf(stderr, "ERR: elm_label dosen't support multiline sliding effect!!!\n");
807 fprintf(stderr, "ERR: elm_label dosen't support multiline sliding effect!!!\n");
808 fprintf(stderr, "ERR: elm_label dosen't support multiline sliding effect!!!\n");
812 char *plaintxt = _mkup_to_text(edje_object_part_text_get(wd->lbl, "elm.text"));
814 if (plaintxt != NULL)
816 plainlen = strlen(plaintxt);
821 wd->slidingmode = EINA_TRUE;
822 fprintf(stderr, "ERR: too short to slide label!!!\n");
830 wd->slidingellipsis = EINA_TRUE;
831 elm_label_ellipsis_set(obj, EINA_FALSE);
833 Edje_Message_Int_Set *msg = alloca(sizeof(Edje_Message_Int_Set) + (sizeof(int)));
836 msg->val[0] = (int)wd->slide_duration;
838 edje_object_message_send(wd->lbl, EDJE_MESSAGE_INT_SET, 0, msg);
839 edje_object_signal_emit(wd->lbl, "elm,state,slide,start", "elm");
843 edje_object_signal_emit(wd->lbl, "elm,state,slide,stop", "elm");
844 if (wd->slidingellipsis)
846 wd->slidingellipsis = EINA_FALSE;
847 elm_label_ellipsis_set(obj, EINA_TRUE);
853 * Add a new label to the parent
855 * @param parent The parent object
856 * @return The new object or NULL if it cannot be created
861 elm_label_add(Evas_Object *parent)
867 wd = ELM_NEW(Widget_Data);
868 e = evas_object_evas_get(parent);
869 wd->bg = evas_object_rectangle_add(e);
870 evas_object_color_set(wd->bg, 0, 0, 0, 0);
871 obj = elm_widget_add(e);
872 ELM_SET_WIDTYPE(widtype, "label");
873 elm_widget_type_set(obj, "label");
874 elm_widget_sub_object_add(parent, obj);
875 elm_widget_data_set(obj, wd);
876 elm_widget_del_hook_set(obj, _del_hook);
877 elm_widget_theme_hook_set(obj, _theme_hook);
878 elm_widget_can_focus_set(obj, 0);
880 wd->linewrap = EINA_FALSE;
881 wd->bgcolor = EINA_FALSE;
882 wd->ellipsis = EINA_FALSE;
883 wd->wrapmode = EINA_FALSE;
884 wd->slidingmode = EINA_FALSE;
885 wd->slidingellipsis = EINA_FALSE;
888 wd->slide_duration = 10;
890 wd->lbl = edje_object_add(e);
891 _elm_theme_object_set(obj, wd->lbl, "label", "base", "default");
892 wd->label = eina_stringshare_add("<br>");
893 edje_object_part_text_set(wd->lbl, "elm.text", "<br>");
894 elm_widget_resize_object_set(obj, wd->lbl);
896 evas_object_event_callback_add(wd->lbl, EVAS_CALLBACK_RESIZE, _resize, obj);
904 * Set the label on the label object
906 * @param obj The label object
907 * @param label The label will be used on the label object
912 elm_label_label_set(Evas_Object *obj, const char *label)
914 ELM_CHECK_WIDTYPE(obj, widtype);
915 Widget_Data *wd = elm_widget_data_get(obj);
917 if (!label) label = "";
918 eina_stringshare_replace(&wd->label, label);
919 edje_object_part_text_set(wd->lbl, "elm.text", label);
925 * Get the label used on the label object
927 * @param obj The label object
928 * @return The string inside the label
932 elm_label_label_get(const Evas_Object *obj)
934 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
935 Widget_Data *wd = elm_widget_data_get(obj);
936 if (!wd) return NULL;
941 * Set the wrapping behavior of the label
943 * @param obj The label object
944 * @param wrap To wrap text or not
948 elm_label_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
950 ELM_CHECK_WIDTYPE(obj, widtype);
951 Widget_Data *wd = elm_widget_data_get(obj);
954 if (wd->linewrap == wrap) return;
956 t = eina_stringshare_add(elm_label_label_get(obj));
958 elm_label_label_set(obj, t);
959 eina_stringshare_del(t);
965 * Get the wrapping behavior of the label
967 * @param obj The label object
968 * @return To wrap text or not
972 elm_label_line_wrap_get(const Evas_Object *obj)
974 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
975 Widget_Data *wd = elm_widget_data_get(obj);
976 if (!wd) return EINA_FALSE;
981 * Set wrap width of the label
983 * @param obj The label object
984 * @param w The wrap width in pixels at a minimum where words need to wrap
988 elm_label_wrap_width_set(Evas_Object *obj, Evas_Coord w)
990 ELM_CHECK_WIDTYPE(obj, widtype);
991 Widget_Data *wd = elm_widget_data_get(obj);
994 if (wd->wrap_w == w) return;
995 if (wd->ellipsis) edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1001 * get wrap width of the label
1003 * @param obj The label object
1004 * @return The wrap width in pixels at a minimum where words need to wrap
1008 elm_label_wrap_width_get(const Evas_Object *obj)
1010 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1011 Widget_Data *wd = elm_widget_data_get(obj);
1017 * Set wrap height of the label
1019 * @param obj The label object
1020 * @param w The wrap width in pixels at a minimum where words need to wrap
1024 elm_label_wrap_height_set(Evas_Object *obj, Evas_Coord h)
1026 ELM_CHECK_WIDTYPE(obj, widtype);
1027 Widget_Data *wd = elm_widget_data_get(obj);
1030 if (wd->wrap_h == h) return;
1031 if (wd->ellipsis) edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1037 * get wrap width of the label
1039 * @param obj The label object
1040 * @return The wrap height in pixels at a minimum where words need to wrap
1044 elm_label_wrap_height_get(const Evas_Object *obj)
1046 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1047 Widget_Data *wd = elm_widget_data_get(obj);
1053 * Set the font size on the label object
1055 * @param obj The label object
1056 * @param size font size
1061 elm_label_fontsize_set(Evas_Object *obj, int fontsize)
1063 ELM_CHECK_WIDTYPE(obj, widtype);
1064 Widget_Data *wd = elm_widget_data_get(obj);
1065 Eina_Strbuf *fontbuf = NULL;
1066 int len, removeflag = 0;
1069 len = strlen(wd->label);
1070 if (len <= 0) return;
1071 fontbuf = eina_strbuf_new();
1072 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
1074 if (fontsize == 0) removeflag = 1; // remove fontsize tag
1076 if (_stringshare_key_value_replace(&wd->label, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
1078 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1082 eina_strbuf_free(fontbuf);
1086 * Set the text align on the label object
1088 * @param obj The label object
1089 * @param align align mode ("left", "center", "right")
1094 elm_label_text_align_set(Evas_Object *obj, const char *alignmode)
1096 ELM_CHECK_WIDTYPE(obj, widtype);
1097 Widget_Data *wd = elm_widget_data_get(obj);
1101 len = strlen(wd->label);
1102 if (len <= 0) return;
1104 if (_stringshare_key_value_replace(&wd->label, "align", alignmode, 0) == 0)
1105 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1112 * Set the text color on the label object
1114 * @param obj The label object
1115 * @param r Red property background color of The label object
1116 * @param g Green property background color of The label object
1117 * @param b Blue property background color of The label object
1118 * @param a Alpha property background color of The label object
1123 elm_label_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
1125 ELM_CHECK_WIDTYPE(obj, widtype);
1126 Widget_Data *wd = elm_widget_data_get(obj);
1127 Eina_Strbuf *colorbuf = NULL;
1131 len = strlen(wd->label);
1132 if (len <= 0) return;
1133 colorbuf = eina_strbuf_new();
1134 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
1136 if (_stringshare_key_value_replace(&wd->label, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
1138 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1142 eina_strbuf_free(colorbuf);
1147 * Set background color of the label
1149 * @param obj The label object
1150 * @param r Red property background color of The label object
1151 * @param g Green property background color of The label object
1152 * @param b Blue property background color of The label object
1153 * @param a Alpha property background color of The label object
1157 elm_label_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
1159 ELM_CHECK_WIDTYPE(obj, widtype);
1160 Widget_Data *wd = elm_widget_data_get(obj);
1162 evas_object_color_set(wd->bg, r, g, b, a);
1164 if (wd->bgcolor == EINA_FALSE)
1167 edje_object_part_swallow(wd->lbl, "label.swallow.background", wd->bg);
1172 * Set the ellipsis behavior of the label
1174 * @param obj The label object
1175 * @param ellipsis To ellipsis text or not
1179 elm_label_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
1181 ELM_CHECK_WIDTYPE(obj, widtype);
1182 Widget_Data *wd = elm_widget_data_get(obj);
1184 if (wd->ellipsis == ellipsis) return;
1185 wd->ellipsis = ellipsis;
1186 if (wd->linewrap) _theme_change(obj);
1187 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1193 * Set the wrapmode of the label
1195 * @param obj The label object
1196 * @param wrapmode 0 is charwrap, 1 is wordwrap
1200 elm_label_wrap_mode_set(Evas_Object *obj, Eina_Bool wrapmode)
1202 ELM_CHECK_WIDTYPE(obj, widtype);
1203 Widget_Data *wd = elm_widget_data_get(obj);
1205 if (wd->wrapmode == wrapmode) return;
1206 wd->wrapmode = wrapmode;
1207 _label_state_change(obj);
1213 * Set the text slide of the label
1215 * @param obj The label object
1216 * @param slide To start slide or stop
1220 elm_label_slide_set(Evas_Object *obj, Eina_Bool slide)
1222 ELM_CHECK_WIDTYPE(obj, widtype);
1223 Widget_Data *wd = elm_widget_data_get(obj);
1226 if (wd->slidingmode == slide) return;
1227 wd->slidingmode = slide;
1228 _label_sliding_change(obj);
1234 * get the text slide mode of the label
1236 * @param obj The label object
1237 * @return slide slide mode value
1241 elm_label_slide_get(Evas_Object *obj)
1243 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1244 Widget_Data *wd = elm_widget_data_get(obj);
1245 if (!wd) return EINA_FALSE;
1247 return wd->slidingmode;
1251 * set the slide duration(speed) of the label
1253 * @param obj The label object
1254 * @return The duration time in moving text from slide begin position to slide end position
1258 elm_label_slide_duration_set(Evas_Object *obj, int duration)
1260 ELM_CHECK_WIDTYPE(obj, widtype);
1261 Widget_Data *wd = elm_widget_data_get(obj);
1262 Edje_Message_Int_Set *msg = alloca(sizeof(Edje_Message_Int_Set) + (sizeof(int)));
1265 wd->slide_duration = duration;
1268 msg->val[0] = (int)wd->slide_duration;
1270 edje_object_message_send(wd->lbl, EDJE_MESSAGE_INT_SET, 0, msg);
1274 * get the slide duration(speed) of the label
1276 * @param obj The label object
1277 * @return The duration time in moving text from slide begin position to slide end position
1281 elm_label_slide_duration_get(Evas_Object *obj)
1283 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1284 Widget_Data *wd = elm_widget_data_get(obj);
1286 return wd->slide_duration;