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(edje_object_part_object_get(wd->lbl, "elm.text"));
624 tc2 = evas_object_textblock_cursor_new(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(edje_object_part_object_get(wd->lbl, "elm.text"));
686 tc2 = evas_object_textblock_cursor_new(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;
731 char **kvalue = NULL;
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((char*)kvalue);
752 while (_is_width_over(obj, linemode))
754 if (cur_fontsize > minfontsize)
757 if (cur_fontsize < minfontsize)
758 cur_fontsize = minfontsize;
759 _ellipsis_fontsize_set(obj, cur_fontsize);
763 if (linemode == 0) // single line
765 _ellipsis_cut_chars_to_widget(obj, cur_fontsize, linemode);
770 _ellipsis_cut_lines_to_widget(obj, cur_fontsize, linemode);
778 * setting internal state of mulitline label
779 * singleline doesn't need it
782 void _label_state_change(Evas_Object *obj)
784 Widget_Data *wd = elm_widget_data_get(obj);
790 edje_object_signal_emit(wd->lbl, "elm,state,wordwrap", "elm");
792 edje_object_signal_emit(wd->lbl, "elm,state,default", "elm");
796 void _label_sliding_change(Evas_Object *obj)
798 Widget_Data *wd = elm_widget_data_get(obj);
803 wd->slidingmode = EINA_FALSE;
804 fprintf(stderr, "ERR: elm_label dosen't support multiline sliding effect!!!\n");
805 fprintf(stderr, "ERR: elm_label dosen't support multiline sliding effect!!!\n");
806 fprintf(stderr, "ERR: elm_label dosen't support multiline sliding effect!!!\n");
813 wd->slidingellipsis = EINA_TRUE;
814 elm_label_ellipsis_set(obj, EINA_FALSE);
816 Edje_Message_Int_Set *msg = alloca(sizeof(Edje_Message_Int_Set) + (sizeof(int)));
819 msg->val[0] = (int)wd->slide_duration;
821 edje_object_message_send(wd->lbl, EDJE_MESSAGE_INT_SET, 0, msg);
822 edje_object_signal_emit(wd->lbl, "elm,state,slide,start", "elm");
826 edje_object_signal_emit(wd->lbl, "elm,state,slide,stop", "elm");
827 if (wd->slidingellipsis)
829 wd->slidingellipsis = EINA_FALSE;
830 elm_label_ellipsis_set(obj, EINA_TRUE);
836 * Add a new label to the parent
838 * @param parent The parent object
839 * @return The new object or NULL if it cannot be created
844 elm_label_add(Evas_Object *parent)
850 wd = ELM_NEW(Widget_Data);
851 e = evas_object_evas_get(parent);
852 wd->bg = evas_object_rectangle_add(e);
853 evas_object_color_set(wd->bg, 0, 0, 0, 0);
854 obj = elm_widget_add(e);
855 ELM_SET_WIDTYPE(widtype, "label");
856 elm_widget_type_set(obj, "label");
857 elm_widget_sub_object_add(parent, obj);
858 elm_widget_data_set(obj, wd);
859 elm_widget_del_hook_set(obj, _del_hook);
860 elm_widget_theme_hook_set(obj, _theme_hook);
861 elm_widget_can_focus_set(obj, 0);
863 wd->linewrap = EINA_FALSE;
864 wd->bgcolor = EINA_FALSE;
865 wd->ellipsis = EINA_FALSE;
866 wd->wrapmode = EINA_FALSE;
867 wd->slidingmode = EINA_FALSE;
868 wd->slidingellipsis = EINA_FALSE;
871 wd->slide_duration = 10;
873 wd->lbl = edje_object_add(e);
874 _elm_theme_object_set(obj, wd->lbl, "label", "base", "default");
875 wd->label = eina_stringshare_add("<br>");
876 edje_object_part_text_set(wd->lbl, "elm.text", "<br>");
877 elm_widget_resize_object_set(obj, wd->lbl);
879 evas_object_event_callback_add(wd->lbl, EVAS_CALLBACK_RESIZE, _resize, obj);
887 * Set the label on the label object
889 * @param obj The label object
890 * @param label The label will be used on the label object
895 elm_label_label_set(Evas_Object *obj, const char *label)
897 ELM_CHECK_WIDTYPE(obj, widtype);
898 Widget_Data *wd = elm_widget_data_get(obj);
900 if (!label) label = "";
901 eina_stringshare_replace(&wd->label, label);
902 edje_object_part_text_set(wd->lbl, "elm.text", label);
908 * Get the label used on the label object
910 * @param obj The label object
911 * @return The string inside the label
915 elm_label_label_get(const Evas_Object *obj)
917 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
918 Widget_Data *wd = elm_widget_data_get(obj);
919 if (!wd) return NULL;
924 * Set the wrapping behavior of the label
926 * @param obj The label object
927 * @param wrap To wrap text or not
931 elm_label_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
933 ELM_CHECK_WIDTYPE(obj, widtype);
934 Widget_Data *wd = elm_widget_data_get(obj);
937 if (wd->linewrap == wrap) return;
939 t = eina_stringshare_add(elm_label_label_get(obj));
941 elm_label_label_set(obj, t);
942 eina_stringshare_del(t);
948 * Get the wrapping behavior of the label
950 * @param obj The label object
951 * @return To wrap text or not
955 elm_label_line_wrap_get(const Evas_Object *obj)
957 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
958 Widget_Data *wd = elm_widget_data_get(obj);
959 if (!wd) return EINA_FALSE;
964 * Set wrap width of the label
966 * @param obj The label object
967 * @param w The wrap width in pixels at a minimum where words need to wrap
971 elm_label_wrap_width_set(Evas_Object *obj, Evas_Coord w)
973 ELM_CHECK_WIDTYPE(obj, widtype);
974 Widget_Data *wd = elm_widget_data_get(obj);
977 if (wd->wrap_w == w) return;
978 if (wd->ellipsis) edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
984 * get wrap width of the label
986 * @param obj The label object
987 * @return The wrap width in pixels at a minimum where words need to wrap
991 elm_label_wrap_width_get(const Evas_Object *obj)
993 ELM_CHECK_WIDTYPE(obj, widtype) 0;
994 Widget_Data *wd = elm_widget_data_get(obj);
1000 * Set wrap height of the label
1002 * @param obj The label object
1003 * @param w The wrap width in pixels at a minimum where words need to wrap
1007 elm_label_wrap_height_set(Evas_Object *obj, Evas_Coord h)
1009 ELM_CHECK_WIDTYPE(obj, widtype);
1010 Widget_Data *wd = elm_widget_data_get(obj);
1013 if (wd->wrap_h == h) return;
1014 if (wd->ellipsis) edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1020 * get wrap width of the label
1022 * @param obj The label object
1023 * @return The wrap height in pixels at a minimum where words need to wrap
1027 elm_label_wrap_height_get(const Evas_Object *obj)
1029 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1030 Widget_Data *wd = elm_widget_data_get(obj);
1036 * Set the font size on the label object
1038 * @param obj The label object
1039 * @param size font size
1044 elm_label_fontsize_set(Evas_Object *obj, int fontsize)
1046 ELM_CHECK_WIDTYPE(obj, widtype);
1047 Widget_Data *wd = elm_widget_data_get(obj);
1048 Eina_Strbuf *fontbuf = NULL;
1049 int len, removeflag = 0;
1052 len = strlen(wd->label);
1053 if (len <= 0) return;
1054 fontbuf = eina_strbuf_new();
1055 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
1057 if (fontsize == 0) removeflag = 1; // remove fontsize tag
1059 if (_stringshare_key_value_replace(&wd->label, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
1061 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1065 eina_strbuf_free(fontbuf);
1069 * Set the text align on the label object
1071 * @param obj The label object
1072 * @param align align mode ("left", "center", "right")
1077 elm_label_text_align_set(Evas_Object *obj, const char *alignmode)
1079 ELM_CHECK_WIDTYPE(obj, widtype);
1080 Widget_Data *wd = elm_widget_data_get(obj);
1084 len = strlen(wd->label);
1085 if (len <= 0) return;
1087 if (_stringshare_key_value_replace(&wd->label, "align", alignmode, 0) == 0)
1088 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1095 * Set the text color on the label object
1097 * @param obj The label object
1098 * @param r Red property background color of The label object
1099 * @param g Green property background color of The label object
1100 * @param b Blue property background color of The label object
1101 * @param a Alpha property background color of The label object
1106 elm_label_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
1108 ELM_CHECK_WIDTYPE(obj, widtype);
1109 Widget_Data *wd = elm_widget_data_get(obj);
1110 Eina_Strbuf *colorbuf = NULL;
1114 len = strlen(wd->label);
1115 if (len <= 0) return;
1116 colorbuf = eina_strbuf_new();
1117 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
1119 if (_stringshare_key_value_replace(&wd->label, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
1121 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1125 eina_strbuf_free(colorbuf);
1130 * Set background color of the label
1132 * @param obj The label object
1133 * @param r Red property background color of The label object
1134 * @param g Green property background color of The label object
1135 * @param b Blue property background color of The label object
1136 * @param a Alpha property background color of The label object
1140 elm_label_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
1142 ELM_CHECK_WIDTYPE(obj, widtype);
1143 Widget_Data *wd = elm_widget_data_get(obj);
1145 evas_object_color_set(wd->bg, r, g, b, a);
1147 if (wd->bgcolor == EINA_FALSE)
1150 edje_object_part_swallow(wd->lbl, "label.swallow.background", wd->bg);
1155 * Set the ellipsis behavior of the label
1157 * @param obj The label object
1158 * @param ellipsis To ellipsis text or not
1162 elm_label_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
1164 ELM_CHECK_WIDTYPE(obj, widtype);
1165 Widget_Data *wd = elm_widget_data_get(obj);
1167 if (wd->ellipsis == ellipsis) return;
1168 wd->ellipsis = ellipsis;
1169 if (wd->linewrap) _theme_change(obj);
1170 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1176 * Set the wrapmode of the label
1178 * @param obj The label object
1179 * @param wrapmode 0 is charwrap, 1 is wordwrap
1183 elm_label_wrap_mode_set(Evas_Object *obj, Eina_Bool wrapmode)
1185 ELM_CHECK_WIDTYPE(obj, widtype);
1186 Widget_Data *wd = elm_widget_data_get(obj);
1188 if (wd->wrapmode == wrapmode) return;
1189 wd->wrapmode = wrapmode;
1190 _label_state_change(obj);
1196 * Set the text slide of the label
1198 * @param obj The label object
1199 * @param slide To start slide or stop
1203 elm_label_slide_set(Evas_Object *obj, Eina_Bool slide)
1205 ELM_CHECK_WIDTYPE(obj, widtype);
1206 Widget_Data *wd = elm_widget_data_get(obj);
1209 if (wd->slidingmode == slide) return;
1210 wd->slidingmode = slide;
1211 _label_sliding_change(obj);
1217 * get the text slide mode of the label
1219 * @param obj The label object
1220 * @return slide slide mode value
1224 elm_label_slide_get(Evas_Object *obj)
1226 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1227 Widget_Data *wd = elm_widget_data_get(obj);
1228 if (!wd) return EINA_FALSE;
1230 return wd->slidingmode;
1234 * set the slide duration(speed) of the label
1236 * @param obj The label object
1237 * @return The duration time in moving text from slide begin position to slide end position
1241 elm_label_slide_duration_set(Evas_Object *obj, int duration)
1243 ELM_CHECK_WIDTYPE(obj, widtype);
1244 Widget_Data *wd = elm_widget_data_get(obj);
1245 Edje_Message_Int_Set *msg = alloca(sizeof(Edje_Message_Int_Set) + (sizeof(int)));
1248 wd->slide_duration = duration;
1251 msg->val[0] = (int)wd->slide_duration;
1253 edje_object_message_send(wd->lbl, EDJE_MESSAGE_INT_SET, 0, msg);
1257 * get the slide duration(speed) of the label
1259 * @param obj The label object
1260 * @return The duration time in moving text from slide begin position to slide end position
1264 elm_label_slide_duration_get(Evas_Object *obj)
1266 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1267 Widget_Data *wd = elm_widget_data_get(obj);
1269 return wd->slide_duration;