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,
40 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf,
44 static int _stringshare_key_value_replace(const char **srcstring,
48 static int _is_width_over(Evas_Object *obj,
50 static void _ellipsis_label_to_width(Evas_Object *obj,
54 _elm_win_recalc_job(void *data)
56 Widget_Data *wd = elm_widget_data_get(data);
57 Evas_Coord minw = -1, minh = -1, maxh = -1;
58 Evas_Coord resw, resh, minminw, minminh;
60 wd->deferred_recalc_job = NULL;
61 evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
64 edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, 0, 0);
67 if (wd->wrap_w >= resw)
70 edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, resw, 0);
71 evas_object_size_hint_min_set(data, minw, minh);
75 if (wd->wrap_w > minminw) minminw = wd->wrap_w;
76 edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, resw, 0);
77 evas_object_size_hint_min_set(data, minminw, minh);
80 if (wd->ellipsis && wd->linewrap && wd->wrap_h > 0 && _is_width_over(data, 1) == 1)
81 _ellipsis_label_to_width(data, 1);
84 evas_object_size_hint_max_set(data, -1, maxh);
88 _del_hook(Evas_Object *obj)
90 Widget_Data *wd = elm_widget_data_get(obj);
92 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
93 if (wd->label) eina_stringshare_del(wd->label);
94 if (wd->bg) evas_object_del(wd->bg);
99 _theme_change(Evas_Object *obj)
101 Widget_Data *wd = elm_widget_data_get(obj);
107 _elm_theme_object_set(obj, wd->lbl, "label", "base_wrap_ellipsis", elm_widget_style_get(obj));
109 _elm_theme_object_set(obj, wd->lbl, "label", "base_wrap", elm_widget_style_get(obj));
112 _elm_theme_object_set(obj, wd->lbl, "label", "base", elm_widget_style_get(obj));
116 _theme_hook(Evas_Object *obj)
118 Widget_Data *wd = elm_widget_data_get(obj);
121 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
122 edje_object_scale_set(wd->lbl, elm_widget_scale_get(obj) *
128 _sizing_eval(Evas_Object *obj)
130 Widget_Data *wd = elm_widget_data_get(obj);
131 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
132 Evas_Coord resw, resh;
136 evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
137 if ((resw == wd->lastw) && (!wd->changed)) return;
138 wd->changed = EINA_FALSE;
140 _elm_win_recalc_job(obj);
141 // FIXME: works ok. but NOT for genlist. what should genlist do?
142 // if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
143 // wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
147 evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
148 edje_object_size_min_calc(wd->lbl, &minw, &minh);
149 if (wd->wrap_w > 0 && minw > wd->wrap_w)
151 evas_object_size_hint_min_set(obj, minw, minh);
153 evas_object_size_hint_max_set(obj, maxw, maxh);
155 if (wd->ellipsis && _is_width_over(obj, 0) == 1)
156 _ellipsis_label_to_width(obj, 0);
163 Evas_Object *obj __UNUSED__,
164 void *event_info __UNUSED__)
166 Widget_Data *wd = elm_widget_data_get(data);
168 if (wd->linewrap) _sizing_eval(data);
172 _get_value_in_key_string(const char *oldstring,
176 char *curlocater, *starttag, *endtag;
177 int firstindex = 0, foundflag = -1;
179 curlocater = strstr(oldstring, key);
182 starttag = curlocater;
183 endtag = curlocater + strlen(key);
184 if (endtag == NULL || *endtag != '=')
190 firstindex = abs(oldstring - curlocater);
191 firstindex += strlen(key) + 1; // strlen("key") + strlen("=")
192 *value = (char *)(oldstring + firstindex);
194 while (oldstring != starttag)
196 if (*starttag == '>')
201 if (*starttag == '<')
205 if (starttag == NULL) break;
208 while (NULL != endtag)
219 if (endtag == NULL) break;
222 if (foundflag != 0 && *starttag == '<' && *endtag == '>')
232 if (foundflag == 1) return 0;
238 _strbuf_key_value_replace(Eina_Strbuf *srcbuf,
243 const char *srcstring = NULL;
244 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
245 char *curlocater, *replocater;
246 char *starttag, *endtag;
247 int tagtxtlen = 0, insertflag = 0;
249 srcstring = eina_strbuf_string_get(srcbuf);
250 curlocater = strstr(srcstring, key);
252 if (curlocater == NULL)
260 starttag = strchr(srcstring, '<');
261 endtag = strchr(srcstring, '>');
262 tagtxtlen = endtag - starttag;
263 if (tagtxtlen <= 0) tagtxtlen = 0;
264 if (starttag < curlocater && curlocater < endtag) break;
265 if (endtag != NULL && endtag + 1 != NULL)
266 srcstring = endtag + 1;
269 } while (strlen(srcstring) > 1);
271 if (starttag && endtag && tagtxtlen > strlen(key))
273 repbuf = eina_strbuf_new();
274 diffbuf = eina_strbuf_new();
275 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
276 srcstring = eina_strbuf_string_get(repbuf);
277 curlocater = strstr(srcstring, key);
279 if (curlocater != NULL)
281 replocater = curlocater + strlen(key) + 1;
283 while (*replocater == ' ' || *replocater == '=')
288 while (replocater != NULL && *replocater != ' ' && *replocater != '>')
291 if (replocater - curlocater > strlen(key) + 1)
294 eina_strbuf_append_n(diffbuf, curlocater, replocater - curlocater + 1);
303 eina_strbuf_reset(repbuf);
311 if (repbuf == NULL) repbuf = eina_strbuf_new();
312 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
316 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
317 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
323 eina_strbuf_prepend(diffbuf, "<");
324 eina_strbuf_append(diffbuf, ">");
325 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
329 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
330 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
334 if (repbuf) eina_strbuf_free(repbuf);
335 if (diffbuf) eina_strbuf_free(diffbuf);
341 _stringshare_key_value_replace(const char **srcstring,
346 Eina_Strbuf *sharebuf = NULL;
348 sharebuf = eina_strbuf_new();
349 eina_strbuf_append(sharebuf, *srcstring);
350 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
351 eina_stringshare_del(*srcstring);
352 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
353 eina_strbuf_free(sharebuf);
358 // FIXME: move to some where(such as elm_util??).
359 // copied from elm_entry for check pure text length w/o tags.
361 _str_append(char *str,
366 int txt_len = strlen(txt);
368 if (txt_len <= 0) return str;
369 if ((*len + txt_len) >= *alloc)
374 alloc2 = *alloc + txt_len + 128;
375 str2 = realloc(str, alloc2);
376 if (!str2) return str;
380 strcpy(str + *len, txt);
385 // FIXME: move to some where(such as elm_util??).
386 // copied from elm_entry for check pure text length w/o tags.
404 ERR("count is smaller than 0");
408 return strncpy(dest, src, count);
411 // FIXME: move to some where(such as elm_util??).
412 // copied from elm_entry for check pure text length w/o tags.
414 _mkup_to_text(const char *mkup)
417 int str_len = 0, str_alloc = 0;
419 char *tag_start, *tag_end, *esc_start, *esc_end, *ts;
421 if (!mkup) return NULL;
423 tag_start = tag_end = esc_start = esc_end = NULL;
428 if (((p != NULL) && (*p == 0)) ||
429 (tag_end) || (esc_end) ||
430 (tag_start) || (esc_start))
436 ttag = malloc(tag_end - tag_start);
439 _strncpy(ttag, tag_start + 1, tag_end - tag_start - 1);
440 ttag[tag_end - tag_start - 1] = 0;
441 if (!strcmp(ttag, "br"))
442 str = _str_append(str, "\n", &str_len, &str_alloc);
443 else if (!strcmp(ttag, "\n"))
444 str = _str_append(str, "\n", &str_len, &str_alloc);
445 else if (!strcmp(ttag, "\\n"))
446 str = _str_append(str, "\n", &str_len, &str_alloc);
447 else if (!strcmp(ttag, "\t"))
448 str = _str_append(str, "\t", &str_len, &str_alloc);
449 else if (!strcmp(ttag, "\\t"))
450 str = _str_append(str, "\t", &str_len, &str_alloc);
451 else if (!strcmp(ttag, "ps")) /* Unicode paragraph separator */
452 str = _str_append(str, "\xE2\x80\xA9", &str_len, &str_alloc);
455 tag_start = tag_end = NULL;
459 ts = malloc(esc_end - esc_start + 1);
463 _strncpy(ts, esc_start, esc_end - esc_start);
464 ts[esc_end - esc_start] = 0;
465 esc = evas_textblock_escape_string_get(ts);
467 str = _str_append(str, esc, &str_len, &str_alloc);
470 esc_start = esc_end = NULL;
472 else if ((p != NULL) && (*p == 0))
474 ts = malloc(p - s + 1);
477 _strncpy(ts, s, p - s);
479 str = _str_append(str, ts, &str_len, &str_alloc);
485 if ((p != NULL) && (*p == '<'))
491 ts = malloc(p - s + 1);
494 _strncpy(ts, s, p - s);
496 str = _str_append(str, ts, &str_len, &str_alloc);
502 else if ((p != NULL) && (*p == '>'))
510 else if ((p != NULL) && (*p == '&'))
516 ts = malloc(p - s + 1);
519 _strncpy(ts, s, p - s);
521 str = _str_append(str, ts, &str_len, &str_alloc);
527 else if ((p != NULL) && (*p == ';'))
541 _is_width_over(Evas_Object *obj,
544 Evas_Coord x, y, w, h;
545 Evas_Coord vx, vy, vw, vh;
546 Widget_Data *wd = elm_widget_data_get(obj);
547 const char *ellipsis_string = "...";
548 size_t ellen = strlen(ellipsis_string) + 1;
552 // too short to ellipsis
553 char *plaintxt = _mkup_to_text(edje_object_part_text_get(wd->lbl, "elm.text"));
555 if (plaintxt != NULL)
557 plainlen = strlen(plaintxt);
560 if (plainlen <= ellen) return 0;
562 edje_object_part_geometry_get(wd->lbl, "elm.text", &x, &y, &w, &h);
564 evas_object_geometry_get(obj, &vx, &vy, &vw, &vh);
567 fprintf(stderr, "## _is_width_over\n");
568 fprintf(stderr, "## x = %d, y = %d, w = %d, h = %d\n", x, y, w, h);
569 fprintf(stderr, "## vx = %d, vy = %d, vw = %d, vh = %d\n", vx, vy, vw, vh);
571 fprintf(stderr, "## wd->wrap_w = %d, wd->wrap_h = %d\n", wd->wrap_w, wd->wrap_h);
573 fprintf(stderr, "## wd->wrap_w = %d\n", wd->wrap_w);
574 fprintf(stderr, "## check str = %s\n", edje_object_part_text_get(wd->lbl, "elm.text"));
577 if (linemode == 0) // single line
579 // skip if too early to check widget size
582 // if string fits at widget
583 if ((x >= 0) && (y >= 0))
585 if ((wd->wrap_w > 0) && (wd->wrap_w < w))
587 Evas_Coord minw, minh;
588 edje_object_size_min_calc(wd->lbl, &minw, &minh);
590 if (minw < wd->wrap_w) // min insufficient
601 if (0 < wd->wrap_w && w > wd->wrap_w) return 1;
605 // if (vy > h && h > wd->wrap_h) return 1;
606 if ((x >= 0 || y >= 0) && h > wd->wrap_h) return 1;
613 _ellipsis_fontsize_set(Evas_Object *obj,
616 Widget_Data *wd = elm_widget_data_get(obj);
619 Eina_Strbuf *fontbuf = NULL;
620 Eina_Strbuf *txtbuf = NULL;
621 txtbuf = eina_strbuf_new();
622 fontbuf = eina_strbuf_new();
623 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->lbl, "elm.text"));
624 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
625 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
626 edje_object_part_text_set(wd->lbl, "elm.text", eina_strbuf_string_get(txtbuf));
627 eina_strbuf_free(fontbuf);
628 eina_strbuf_free(txtbuf);
632 _ellipsis_cut_chars_to_widget(Evas_Object *obj,
636 Widget_Data *wd = elm_widget_data_get(obj);
637 if (!wd) return EINA_FALSE;
639 const char *ellipsis_string = "...";
640 int minshowcount = strlen(ellipsis_string);
642 Evas_Textblock_Cursor *tc1, *tc2;
643 char *cutstr, *elstr;
648 edje_object_part_geometry_get(wd->lbl, "elm.text", NULL, NULL, &w, &h);
651 tc1 = evas_object_textblock_cursor_new((Evas_Object *)edje_object_part_object_get(wd->lbl, "elm.text"));
652 tc2 = evas_object_textblock_cursor_new((Evas_Object *)edje_object_part_object_get(wd->lbl, "elm.text"));
654 if (wd->wrap_w > 0 && wd->wrap_w < w)
658 evas_textblock_cursor_pos_set(tc1, 0);
659 evas_textblock_cursor_char_coord_set(tc2, limitw, 0);
661 // if too small to cut,(is it bug? or any other reasons?)
662 // then fallback to one step mode
663 if (evas_textblock_cursor_pos_get(tc2) < minshowcount)
665 int eolpos = evas_textblock_cursor_paragraph_text_length_get(tc1);
666 Evas_Coord cx, cy, cw, ch;
667 for (i = eolpos; i > minshowcount; i--)
669 evas_textblock_cursor_pos_set(tc2, i);
670 evas_textblock_cursor_char_geometry_get(tc2, &cx, &cy, &cw, &ch);
675 if (evas_textblock_cursor_pos_get(tc2) < minshowcount)
677 evas_textblock_cursor_free(tc1);
678 evas_textblock_cursor_free(tc2);
684 for (i = 0; i <= minshowcount; i++)
685 evas_textblock_cursor_char_prev(tc2);
686 cutstr = evas_textblock_cursor_range_text_get(tc1, tc2, EVAS_TEXTBLOCK_TEXT_PLAIN);
688 // FIXME: consider other unicode encoding, currently only care about utf-8
689 lencutstr = strlen(cutstr);
690 elstr = malloc(sizeof(char) * (lencutstr + minshowcount + 1));
691 strcpy(elstr, cutstr);
692 strcat(elstr, ellipsis_string);
694 edje_object_part_text_set(wd->lbl, "elm.text", elstr);
697 evas_textblock_cursor_free(tc1);
698 evas_textblock_cursor_free(tc2);
704 _ellipsis_cut_lines_to_widget(Evas_Object *obj,
708 Widget_Data *wd = elm_widget_data_get(obj);
709 if (!wd) return EINA_FALSE;
711 const char *ellipsis_string = "...";
712 int minshowcount = strlen(ellipsis_string);
714 Evas_Textblock_Cursor *tc1, *tc2;
715 int linenum = 0, cutline = 0;
716 double lineheight = 0.0;
717 char *cutstr, *elstr;
722 edje_object_part_geometry_get(wd->lbl, "elm.text", NULL, NULL, &w, &h);
724 tc1 = evas_object_textblock_cursor_new((Evas_Object *)edje_object_part_object_get(wd->lbl, "elm.text"));
725 tc2 = evas_object_textblock_cursor_new((Evas_Object *)edje_object_part_object_get(wd->lbl, "elm.text"));
726 // goto last paragraph
727 while (evas_textblock_cursor_paragraph_next(tc2) == EINA_TRUE)
729 evas_textblock_cursor_paragraph_last(tc2);
730 // get total linenumber
731 linenum = evas_textblock_cursor_line_geometry_get(tc2, NULL, NULL, NULL, NULL);
732 lineheight = h / linenum * 1.0;
733 if (wd->wrap_h > 0 && wd->wrap_h < h)
737 cutline = limith / lineheight;
741 evas_textblock_cursor_pos_set(tc1, 0);
742 evas_textblock_cursor_line_set(tc2, cutline - 1);
743 evas_textblock_cursor_line_char_last(tc2);
744 for (i = 0; i <= minshowcount; i++)
745 evas_textblock_cursor_char_prev(tc2);
746 cutstr = evas_textblock_cursor_range_text_get(tc1, tc2, EVAS_TEXTBLOCK_TEXT_PLAIN);
748 // FIXME: consider other unicode encoding, currently only care about utf-8
749 lencutstr = strlen(cutstr);
750 elstr = malloc(sizeof(char) * (lencutstr + minshowcount + 1));
751 strcpy(elstr, cutstr);
752 strcat(elstr, ellipsis_string);
754 edje_object_part_text_set(wd->lbl, "elm.text", elstr);
757 evas_textblock_cursor_free(tc1);
758 evas_textblock_cursor_free(tc2);
764 _ellipsis_label_to_width(Evas_Object *obj,
767 Widget_Data *wd = elm_widget_data_get(obj);
770 int cur_fontsize = 0;
772 const char *minfont, *deffont, *maxfont;
773 int minfontsize, maxfontsize;
775 minfont = edje_object_data_get(wd->lbl, "min_font_size");
776 if (minfont) minfontsize = atoi(minfont);
777 else minfontsize = 1;
778 maxfont = edje_object_data_get(wd->lbl, "max_font_size");
779 if (maxfont) maxfontsize = atoi(maxfont);
780 else maxfontsize = 1;
781 deffont = edje_object_data_get(wd->lbl, "default_font_size");
782 if (deffont) cur_fontsize = atoi(deffont);
783 else cur_fontsize = 1;
784 if (minfontsize > maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
785 if (eina_stringshare_strlen(wd->label) <= 0) return;
787 if (_get_value_in_key_string(wd->label, "font_size", &kvalue) == 0)
789 if (kvalue != NULL) cur_fontsize = atoi(kvalue);
792 while (_is_width_over(obj, linemode))
794 if (cur_fontsize > minfontsize)
797 if (cur_fontsize < minfontsize)
798 cur_fontsize = minfontsize;
799 _ellipsis_fontsize_set(obj, cur_fontsize);
803 if (linemode == 0) // single line
805 _ellipsis_cut_chars_to_widget(obj, cur_fontsize, linemode);
810 _ellipsis_cut_lines_to_widget(obj, cur_fontsize, linemode);
818 * setting internal state of mulitline label.
819 * singleline doesn't need it
823 _label_state_change(Evas_Object *obj)
825 Widget_Data *wd = elm_widget_data_get(obj);
831 edje_object_signal_emit(wd->lbl, "elm,state,wordwrap", "elm");
833 edje_object_signal_emit(wd->lbl, "elm,state,default", "elm");
838 _label_sliding_change(Evas_Object *obj)
840 Widget_Data *wd = elm_widget_data_get(obj);
845 wd->slidingmode = EINA_FALSE;
846 fprintf(stderr, "ERR: elm_label dosen't support multiline sliding effect!!!\n");
847 fprintf(stderr, "ERR: elm_label dosen't support multiline sliding effect!!!\n");
848 fprintf(stderr, "ERR: elm_label dosen't support multiline sliding effect!!!\n");
852 char *plaintxt = _mkup_to_text(edje_object_part_text_get(wd->lbl, "elm.text"));
854 if (plaintxt != NULL)
856 plainlen = strlen(plaintxt);
861 wd->slidingmode = EINA_TRUE;
862 fprintf(stderr, "ERR: too short to slide label!!!\n");
870 wd->slidingellipsis = EINA_TRUE;
871 elm_label_ellipsis_set(obj, EINA_FALSE);
873 Edje_Message_Int_Set *msg = alloca(sizeof(Edje_Message_Int_Set) + (sizeof(int)));
876 msg->val[0] = (int)wd->slide_duration;
878 edje_object_message_send(wd->lbl, EDJE_MESSAGE_INT_SET, 0, msg);
879 edje_object_signal_emit(wd->lbl, "elm,state,slide,start", "elm");
883 edje_object_signal_emit(wd->lbl, "elm,state,slide,stop", "elm");
884 if (wd->slidingellipsis)
886 wd->slidingellipsis = EINA_FALSE;
887 elm_label_ellipsis_set(obj, EINA_TRUE);
893 * Add a new label to the parent
895 * @param parent The parent object
896 * @return The new object or NULL if it cannot be created
901 elm_label_add(Evas_Object *parent)
907 wd = ELM_NEW(Widget_Data);
908 e = evas_object_evas_get(parent);
909 wd->bg = evas_object_rectangle_add(e);
910 evas_object_color_set(wd->bg, 0, 0, 0, 0);
911 obj = elm_widget_add(e);
912 ELM_SET_WIDTYPE(widtype, "label");
913 elm_widget_type_set(obj, "label");
914 elm_widget_sub_object_add(parent, obj);
915 elm_widget_data_set(obj, wd);
916 elm_widget_del_hook_set(obj, _del_hook);
917 elm_widget_theme_hook_set(obj, _theme_hook);
918 elm_widget_can_focus_set(obj, 0);
920 wd->linewrap = EINA_FALSE;
921 wd->bgcolor = EINA_FALSE;
922 wd->ellipsis = EINA_FALSE;
923 wd->wrapmode = EINA_FALSE;
924 wd->slidingmode = EINA_FALSE;
925 wd->slidingellipsis = EINA_FALSE;
928 wd->slide_duration = 10;
930 wd->lbl = edje_object_add(e);
931 _elm_theme_object_set(obj, wd->lbl, "label", "base", "default");
932 wd->label = eina_stringshare_add("<br>");
933 edje_object_part_text_set(wd->lbl, "elm.text", "<br>");
934 elm_widget_resize_object_set(obj, wd->lbl);
936 evas_object_event_callback_add(wd->lbl, EVAS_CALLBACK_RESIZE, _resize, obj);
944 * Set the label on the label object
946 * @param obj The label object
947 * @param label The label will be used on the label object
952 elm_label_label_set(Evas_Object *obj,
955 ELM_CHECK_WIDTYPE(obj, widtype);
956 Widget_Data *wd = elm_widget_data_get(obj);
958 if (!label) label = "";
959 eina_stringshare_replace(&wd->label, label);
960 edje_object_part_text_set(wd->lbl, "elm.text", label);
966 * Get the label used on the label object
968 * @param obj The label object
969 * @return The string inside the label
973 elm_label_label_get(const Evas_Object *obj)
975 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
976 Widget_Data *wd = elm_widget_data_get(obj);
977 if (!wd) return NULL;
982 * Set the wrapping behavior of the label
984 * @param obj The label object
985 * @param wrap To wrap text or not
989 elm_label_line_wrap_set(Evas_Object *obj,
992 ELM_CHECK_WIDTYPE(obj, widtype);
993 Widget_Data *wd = elm_widget_data_get(obj);
996 if (wd->linewrap == wrap) return;
998 t = eina_stringshare_add(elm_label_label_get(obj));
1000 elm_label_label_set(obj, t);
1001 eina_stringshare_del(t);
1007 * Get the wrapping behavior of the label
1009 * @param obj The label object
1010 * @return To wrap text or not
1014 elm_label_line_wrap_get(const Evas_Object *obj)
1016 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1017 Widget_Data *wd = elm_widget_data_get(obj);
1018 if (!wd) return EINA_FALSE;
1019 return wd->linewrap;
1023 * Set wrap width of the label
1025 * @param obj The label object
1026 * @param w The wrap width in pixels at a minimum where words need to wrap
1030 elm_label_wrap_width_set(Evas_Object *obj,
1033 ELM_CHECK_WIDTYPE(obj, widtype);
1034 Widget_Data *wd = elm_widget_data_get(obj);
1037 if (wd->wrap_w == w) return;
1038 if (wd->ellipsis) edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1044 * get wrap width of the label
1046 * @param obj The label object
1047 * @return The wrap width in pixels at a minimum where words need to wrap
1051 elm_label_wrap_width_get(const Evas_Object *obj)
1053 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1054 Widget_Data *wd = elm_widget_data_get(obj);
1060 * Set wrap height of the label
1062 * @param obj The label object
1063 * @param w The wrap width in pixels at a minimum where words need to wrap
1067 elm_label_wrap_height_set(Evas_Object *obj,
1070 ELM_CHECK_WIDTYPE(obj, widtype);
1071 Widget_Data *wd = elm_widget_data_get(obj);
1074 if (wd->wrap_h == h) return;
1075 if (wd->ellipsis) edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1081 * get wrap width of the label
1083 * @param obj The label object
1084 * @return The wrap height in pixels at a minimum where words need to wrap
1088 elm_label_wrap_height_get(const Evas_Object *obj)
1090 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1091 Widget_Data *wd = elm_widget_data_get(obj);
1097 * Set the font size on the label object
1099 * @param obj The label object
1100 * @param size font size
1105 elm_label_fontsize_set(Evas_Object *obj,
1108 ELM_CHECK_WIDTYPE(obj, widtype);
1109 Widget_Data *wd = elm_widget_data_get(obj);
1110 Eina_Strbuf *fontbuf = NULL;
1111 int len, removeflag = 0;
1114 len = strlen(wd->label);
1115 if (len <= 0) return;
1116 fontbuf = eina_strbuf_new();
1117 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
1119 if (fontsize == 0) removeflag = 1; // remove fontsize tag
1121 if (_stringshare_key_value_replace(&wd->label, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
1123 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1127 eina_strbuf_free(fontbuf);
1131 * Set the text align on the label object
1133 * @param obj The label object
1134 * @param align align mode ("left", "center", "right")
1139 elm_label_text_align_set(Evas_Object *obj,
1140 const char *alignmode)
1142 ELM_CHECK_WIDTYPE(obj, widtype);
1143 Widget_Data *wd = elm_widget_data_get(obj);
1147 len = strlen(wd->label);
1148 if (len <= 0) return;
1150 if (_stringshare_key_value_replace(&wd->label, "align", alignmode, 0) == 0)
1151 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1158 * Set the text color on the label object
1160 * @param obj The label object
1161 * @param r Red property background color of The label object
1162 * @param g Green property background color of The label object
1163 * @param b Blue property background color of The label object
1164 * @param a Alpha property background color of The label object
1169 elm_label_text_color_set(Evas_Object *obj,
1175 ELM_CHECK_WIDTYPE(obj, widtype);
1176 Widget_Data *wd = elm_widget_data_get(obj);
1177 Eina_Strbuf *colorbuf = NULL;
1181 len = strlen(wd->label);
1182 if (len <= 0) return;
1183 colorbuf = eina_strbuf_new();
1184 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
1186 if (_stringshare_key_value_replace(&wd->label, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
1188 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1192 eina_strbuf_free(colorbuf);
1196 * Set background color of the label
1198 * @param obj The label object
1199 * @param r Red property background color of The label object
1200 * @param g Green property background color of The label object
1201 * @param b Blue property background color of The label object
1202 * @param a Alpha property background color of The label object
1206 elm_label_background_color_set(Evas_Object *obj,
1212 ELM_CHECK_WIDTYPE(obj, widtype);
1213 Widget_Data *wd = elm_widget_data_get(obj);
1215 evas_object_color_set(wd->bg, r, g, b, a);
1217 if (wd->bgcolor == EINA_FALSE)
1220 edje_object_part_swallow(wd->lbl, "label.swallow.background", wd->bg);
1225 * Set the ellipsis behavior of the label
1227 * @param obj The label object
1228 * @param ellipsis To ellipsis text or not
1232 elm_label_ellipsis_set(Evas_Object *obj,
1235 ELM_CHECK_WIDTYPE(obj, widtype);
1236 Widget_Data *wd = elm_widget_data_get(obj);
1238 if (wd->ellipsis == ellipsis) return;
1239 wd->ellipsis = ellipsis;
1240 if (wd->linewrap) _theme_change(obj);
1241 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1247 * Set the wrapmode of the label
1249 * @param obj The label object
1250 * @param wrapmode 0 is charwrap, 1 is wordwrap
1254 elm_label_wrap_mode_set(Evas_Object *obj,
1257 ELM_CHECK_WIDTYPE(obj, widtype);
1258 Widget_Data *wd = elm_widget_data_get(obj);
1260 if (wd->wrapmode == wrapmode) return;
1261 wd->wrapmode = wrapmode;
1262 _label_state_change(obj);
1268 * Set the text slide of the label
1270 * @param obj The label object
1271 * @param slide To start slide or stop
1275 elm_label_slide_set(Evas_Object *obj,
1278 ELM_CHECK_WIDTYPE(obj, widtype);
1279 Widget_Data *wd = elm_widget_data_get(obj);
1282 if (wd->slidingmode == slide) return;
1283 wd->slidingmode = slide;
1284 _label_sliding_change(obj);
1290 * get the text slide mode of the label
1292 * @param obj The label object
1293 * @return slide slide mode value
1297 elm_label_slide_get(Evas_Object *obj)
1299 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1300 Widget_Data *wd = elm_widget_data_get(obj);
1301 if (!wd) return EINA_FALSE;
1303 return wd->slidingmode;
1307 * set the slide duration(speed) of the label
1309 * @param obj The label object
1310 * @return The duration time in moving text from slide begin position to slide end position
1314 elm_label_slide_duration_set(Evas_Object *obj,
1317 ELM_CHECK_WIDTYPE(obj, widtype);
1318 Widget_Data *wd = elm_widget_data_get(obj);
1319 Edje_Message_Int_Set *msg = alloca(sizeof(Edje_Message_Int_Set) + (sizeof(int)));
1322 wd->slide_duration = duration;
1325 msg->val[0] = (int)wd->slide_duration;
1327 edje_object_message_send(wd->lbl, EDJE_MESSAGE_INT_SET, 0, msg);
1331 * get the slide duration(speed) of the label
1333 * @param obj The label object
1334 * @return The duration time in moving text from slide begin position to slide end position
1338 elm_label_slide_duration_get(Evas_Object *obj)
1340 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1341 Widget_Data *wd = elm_widget_data_get(obj);
1343 return wd->slide_duration;