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;
19 Ecore_Job *deferred_recalc_job;
24 Eina_Bool wrapmode : 1;
25 Eina_Bool linewrap : 1;
26 Eina_Bool changed : 1;
27 Eina_Bool bgcolor : 1;
28 Eina_Bool ellipsis : 1;
29 Eina_Bool slidingmode : 1;
30 Eina_Bool slidingellipsis : 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, const char *key, char **value);
38 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, const char *key, const char *value, int deleteflag);
39 static int _stringshare_key_value_replace(const char **srcstring, const char *key, const char *value, int deleteflag);
40 static int _is_width_over(Evas_Object *obj, Eina_Bool multiline);
41 static void _ellipsis_label_to_width(Evas_Object *obj, Eina_Bool multiline);
42 static void _label_sliding_change(Evas_Object *obj);
45 _elm_win_recalc_job(void *data)
47 Widget_Data *wd = elm_widget_data_get(data);
48 Evas_Coord minw = -1, minh = -1, maxh = -1;
49 Evas_Coord resw, resh, minminw;
51 wd->deferred_recalc_job = NULL;
52 evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
54 edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, 0, 0);
56 if (wd->wrap_w >= resw)
59 edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, resw, 0);
60 evas_object_size_hint_min_set(data, minw, minh);
64 if (wd->wrap_w > minminw) minminw = wd->wrap_w;
65 edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, resw, 0);
66 evas_object_size_hint_min_set(data, minminw, minh);
69 if ((wd->ellipsis) && (wd->linewrap) && (wd->wrap_h > 0) &&
70 (_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",
98 elm_widget_style_get(obj));
100 _elm_theme_object_set(obj, wd->lbl, "label", "base_wrap",
101 elm_widget_style_get(obj));
104 _elm_theme_object_set(obj, wd->lbl, "label", "base",
105 elm_widget_style_get(obj));
109 _theme_hook(Evas_Object *obj)
111 Widget_Data *wd = elm_widget_data_get(obj);
114 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
115 edje_object_scale_set(wd->lbl, elm_widget_scale_get(obj) *
117 _label_sliding_change(obj);
122 _sizing_eval(Evas_Object *obj)
124 Widget_Data *wd = elm_widget_data_get(obj);
125 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
126 Evas_Coord resw, resh;
130 evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
131 if ((resw == wd->lastw) && (!wd->changed)) return;
132 wd->changed = EINA_FALSE;
134 _elm_win_recalc_job(obj);
135 // FIXME: works ok. but NOT for genlist. what should genlist do?
136 // if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
137 // wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
141 evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
142 edje_object_size_min_calc(wd->lbl, &minw, &minh);
143 if (wd->wrap_w > 0 && minw > wd->wrap_w) minw = wd->wrap_w;
144 evas_object_size_hint_min_set(obj, minw, minh);
146 evas_object_size_hint_max_set(obj, maxw, maxh);
147 if ((wd->ellipsis) && (_is_width_over(obj, 0) == 1))
148 _ellipsis_label_to_width(obj, 0);
153 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
155 Widget_Data *wd = elm_widget_data_get(data);
157 if (wd->linewrap) _sizing_eval(data);
161 _get_value_in_key_string(const char *oldstring, const char *key, char **value)
163 char *curlocater, *starttag, *endtag;
164 int firstindex = 0, foundflag = -1;
166 curlocater = strstr(oldstring, key);
169 int key_len = strlen(key);
170 starttag = curlocater;
171 endtag = curlocater + key_len;
172 if ((!endtag) || (*endtag != '='))
177 firstindex = abs(oldstring - curlocater);
178 firstindex += key_len + 1; // strlen("key") + strlen("=")
179 *value = (char *)oldstring + firstindex;
181 while (oldstring != starttag)
183 if (*starttag == '>')
188 if (*starttag == '<')
192 if (!starttag) break;
209 if ((foundflag) && (*starttag == '<') && (*endtag == '>'))
219 if (foundflag == 1) return 0;
226 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, const char *key, const char *value, int deleteflag)
228 const char *srcstring = NULL;
229 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
230 char *curlocater, *replocater;
231 char *starttag, *endtag;
232 int tagtxtlen = 0, insertflag = 0;
234 srcstring = eina_strbuf_string_get(srcbuf);
235 curlocater = strstr(srcstring, key);
237 if (!curlocater || !srcstring)
241 int key_len = strlen(key);
244 starttag = strchr(srcstring, '<');
245 endtag = strchr(srcstring, '>');
246 tagtxtlen = endtag - starttag;
247 if (tagtxtlen <= 0) tagtxtlen = 0;
248 if ((starttag < curlocater) && (curlocater < endtag)) break;
249 if ((endtag) && ((endtag + 1)))
250 srcstring = endtag + 1;
253 } while (strlen(srcstring) > 1);
255 if ((starttag) && (endtag) && (tagtxtlen > key_len))
257 repbuf = eina_strbuf_new();
258 diffbuf = eina_strbuf_new();
259 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
260 srcstring = eina_strbuf_string_get(repbuf);
261 curlocater = strstr(srcstring, key);
264 replocater = curlocater + key_len + 1;
266 while ((*replocater) && (*replocater != ' ') && (*replocater != '>'))
269 if (replocater - curlocater > key_len)
271 eina_strbuf_append_n(diffbuf, curlocater,
272 replocater-curlocater);
279 eina_strbuf_reset(repbuf);
285 if (!repbuf) repbuf = eina_strbuf_new();
286 if (!diffbuf) diffbuf = eina_strbuf_new();
290 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
291 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
297 eina_strbuf_prepend(diffbuf, "<");
298 eina_strbuf_append(diffbuf, ">");
299 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
303 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
304 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
308 if (repbuf) eina_strbuf_free(repbuf);
309 if (diffbuf) eina_strbuf_free(diffbuf);
315 _stringshare_key_value_replace(const char **srcstring, const char *key, const char *value, int deleteflag)
317 Eina_Strbuf *sharebuf = NULL;
319 sharebuf = eina_strbuf_new();
320 eina_strbuf_append(sharebuf, *srcstring);
321 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
322 eina_stringshare_del(*srcstring);
323 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
324 eina_strbuf_free(sharebuf);
330 _is_width_over(Evas_Object *obj, Eina_Bool multiline)
332 Evas_Coord x, y, w, h;
333 Evas_Coord vx, vy, vw, vh;
334 Widget_Data *wd = elm_widget_data_get(obj);
336 const char *ellipsis_string = "...";
337 int mincount = sizeof(ellipsis_string) - 1;
341 plaintxt = _elm_util_mkup_to_text(edje_object_part_text_get(wd->lbl, "elm.text"));
344 plainlen = strlen(plaintxt);
347 // too short to ellipsis
348 if (plainlen <= mincount) return 0;
350 edje_object_part_geometry_get(wd->lbl, "elm.text", &x, &y, &w, &h);
351 evas_object_geometry_get(obj, &vx, &vy, &vw, &vh);
354 fprintf(stderr, "## _is_width_over\n");
355 fprintf(stderr, "## x = %d, y = %d, w = %d, h = %d\n", x, y, w, h);
356 fprintf(stderr, "## vx = %d, vy = %d, vw = %d, vh = %d\n", vx, vy, vw, vh);
358 fprintf(stderr, "## wd->wrap_w = %d, wd->wrap_h = %d\n", wd->wrap_w, wd->wrap_h);
360 fprintf(stderr, "## wd->wrap_w = %d\n", wd->wrap_w);
361 fprintf(stderr, "## check str = %s\n", edje_object_part_text_get(wd->lbl, "elm.text"));
364 if (!multiline) // single line
366 // skip if too early to check widget size
367 if ((w < 0) && (h < 0)) return 0;
368 // if string fits at widget
369 if ((x >= 0) && (y >= 0))
371 if ((wd->wrap_w > 0) && (wd->wrap_w < w))
373 Evas_Coord minw, minh;
375 edje_object_size_min_calc(wd->lbl, &minw, &minh);
376 if (minw < wd->wrap_w) return 0; // min insufficient
381 if ((0 < wd->wrap_w) && (w > wd->wrap_w)) return 1;
385 if (((x >= 0) || (y >= 0)) && (h > wd->wrap_h)) return 1;
392 _ellipsis_fontsize_set(Evas_Object *obj, int fontsize)
394 Widget_Data *wd = elm_widget_data_get(obj);
397 Eina_Strbuf *fontbuf = NULL;
398 Eina_Strbuf *txtbuf = NULL;
399 txtbuf = eina_strbuf_new();
400 fontbuf = eina_strbuf_new();
401 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->lbl, "elm.text"));
402 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
403 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
404 edje_object_part_text_set(wd->lbl, "elm.text", eina_strbuf_string_get(txtbuf));
405 eina_strbuf_free(fontbuf);
406 eina_strbuf_free(txtbuf);
410 _ellipsis_cut_chars_to_widget(Evas_Object *obj)
412 Widget_Data *wd = elm_widget_data_get(obj);
413 if (!wd) return EINA_FALSE;
414 const char *ellipsis_string = "...";
415 int mincount = sizeof(ellipsis_string) - 1;
417 Evas_Textblock_Cursor *tc1, *tc2;
418 char *cutstr, *elstr;
423 edje_object_part_geometry_get(wd->lbl, "elm.text", NULL, NULL, &w, &h);
424 if (w <= 0) return EINA_FALSE;
425 tc1 = evas_object_textblock_cursor_new((Evas_Object *)edje_object_part_object_get(wd->lbl, "elm.text"));
426 tc2 = evas_object_textblock_cursor_new((Evas_Object *)edje_object_part_object_get(wd->lbl, "elm.text"));
428 if ((wd->wrap_w > 0) && (wd->wrap_w < w)) limitw = wd->wrap_w;
430 evas_textblock_cursor_pos_set(tc1, 0);
431 evas_textblock_cursor_char_coord_set(tc2, limitw, 0);
433 // if too small to cut,(is it bug? or any other reasons?)
434 // then fallback to one step mode
435 if (evas_textblock_cursor_pos_get(tc2) < mincount)
437 Evas_Coord cx, cy, cw, ch;
438 int eolpos = evas_textblock_cursor_paragraph_text_length_get(tc1);
440 for (i = eolpos; i > mincount; i--)
442 evas_textblock_cursor_pos_set(tc2, i);
443 evas_textblock_cursor_char_geometry_get(tc2, &cx, &cy, &cw, &ch);
444 if (cx <= limitw) break;
447 if (evas_textblock_cursor_pos_get(tc2) < mincount)
449 evas_textblock_cursor_free(tc1);
450 evas_textblock_cursor_free(tc2);
455 for (i = 0; i <= mincount; i++) evas_textblock_cursor_char_prev(tc2);
456 cutstr = evas_textblock_cursor_range_text_get(tc1, tc2, EVAS_TEXTBLOCK_TEXT_PLAIN);
457 if (!cutstr) return EINA_FALSE;
459 lencutstr = strlen(cutstr);
460 elstr = alloca(sizeof(char) * (lencutstr + mincount + 1));
461 strcpy(elstr, cutstr);
463 strcat(elstr, ellipsis_string);
464 edje_object_part_text_set(wd->lbl, "elm.text", elstr);
466 evas_textblock_cursor_free(tc1);
467 evas_textblock_cursor_free(tc2);
473 _ellipsis_cut_lines_to_widget(Evas_Object *obj)
475 Widget_Data *wd = elm_widget_data_get(obj);
476 if (!wd) return EINA_FALSE;
477 const char *ellipsis_string = "...";
478 int mincount = sizeof(ellipsis_string) - 1;
480 Evas_Textblock_Cursor *tc1, *tc2;
481 int linenum = 0, cutline = 0;
482 double lineheight = 0.0;
483 char *cutstr, *elstr;
488 edje_object_part_geometry_get(wd->lbl, "elm.text", NULL, NULL, &w, &h);
490 tc1 = evas_object_textblock_cursor_new((Evas_Object *)edje_object_part_object_get(wd->lbl, "elm.text"));
491 tc2 = evas_object_textblock_cursor_new((Evas_Object *)edje_object_part_object_get(wd->lbl, "elm.text"));
492 // goto last paragraph
493 while (evas_textblock_cursor_paragraph_next(tc2) == EINA_TRUE);
495 evas_textblock_cursor_paragraph_last(tc2);
496 // get total linenumber
497 linenum = evas_textblock_cursor_line_geometry_get(tc2, NULL, NULL, NULL, NULL);
498 lineheight = (double)h / (double)linenum;
499 if ((wd->wrap_h > 0) && (wd->wrap_h < h)) limith = wd->wrap_h;
501 cutline = limith / lineheight;
502 if (cutline < 1) cutline = 1;
504 evas_textblock_cursor_pos_set(tc1, 0);
505 evas_textblock_cursor_line_set(tc2, cutline - 1);
506 evas_textblock_cursor_line_char_last(tc2);
507 for (i = 0; i <= mincount; i++) evas_textblock_cursor_char_prev(tc2);
508 cutstr = evas_textblock_cursor_range_text_get(tc1, tc2, EVAS_TEXTBLOCK_TEXT_PLAIN);
509 if (!cutstr) return EINA_FALSE;
511 lencutstr = strlen(cutstr);
512 elstr = alloca(sizeof(char) * (lencutstr + mincount + 1));
513 strcpy(elstr, cutstr);
515 strcat(elstr, ellipsis_string);
516 edje_object_part_text_set(wd->lbl, "elm.text", elstr);
518 evas_textblock_cursor_free(tc1);
519 evas_textblock_cursor_free(tc2);
525 _ellipsis_label_to_width(Evas_Object *obj, Eina_Bool multiline)
527 Widget_Data *wd = elm_widget_data_get(obj);
529 int cur_fontsize = 0;
531 const char *minfont, *deffont, *maxfont;
532 int minfontsize, maxfontsize;
534 minfont = edje_object_data_get(wd->lbl, "min_font_size");
535 if (minfont) minfontsize = atoi(minfont);
536 else minfontsize = 1;
537 maxfont = edje_object_data_get(wd->lbl, "max_font_size");
538 if (maxfont) maxfontsize = atoi(maxfont);
539 else maxfontsize = 1;
540 deffont = edje_object_data_get(wd->lbl, "default_font_size");
541 if (deffont) cur_fontsize = atoi(deffont);
542 else cur_fontsize = 1;
543 if (minfontsize > maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
544 if (eina_stringshare_strlen(wd->label) <= 0) return;
546 if (_get_value_in_key_string(wd->label, "font_size", &kvalue) == 0)
548 if (kvalue != NULL) cur_fontsize = atoi(kvalue);
551 while (_is_width_over(obj, multiline))
553 if (cur_fontsize > minfontsize)
556 if (cur_fontsize < minfontsize) cur_fontsize = minfontsize;
557 _ellipsis_fontsize_set(obj, cur_fontsize);
561 if (!multiline) // single line
563 _ellipsis_cut_chars_to_widget(obj);
568 _ellipsis_cut_lines_to_widget(obj);
576 * setting internal state of mulitline label.
577 * singleline doesn't need it
581 _label_state_change(Evas_Object *obj)
583 Widget_Data *wd = elm_widget_data_get(obj);
589 edje_object_signal_emit(wd->lbl, "elm,state,wordwrap", "elm");
591 edje_object_signal_emit(wd->lbl, "elm,state,default", "elm");
596 _label_sliding_change(Evas_Object *obj)
598 Widget_Data *wd = elm_widget_data_get(obj);
603 // dosen't support multiline sliding effect
606 wd->slidingmode = EINA_FALSE;
610 plaintxt = _elm_util_mkup_to_text(edje_object_part_text_get(wd->lbl, "elm.text"));
611 if (plaintxt != NULL)
613 plainlen = strlen(plaintxt);
616 // too short to slide label
619 wd->slidingmode = EINA_TRUE;
625 Edje_Message_Int_Set *msg = alloca(sizeof(Edje_Message_Int_Set) + (sizeof(int)));
629 wd->slidingellipsis = EINA_TRUE;
630 elm_label_ellipsis_set(obj, EINA_FALSE);
634 msg->val[0] = (int)wd->slide_duration;
636 edje_object_message_send(wd->lbl, EDJE_MESSAGE_INT_SET, 0, msg);
637 edje_object_signal_emit(wd->lbl, "elm,state,slide,start", "elm");
641 edje_object_signal_emit(wd->lbl, "elm,state,slide,stop", "elm");
642 if (wd->slidingellipsis)
644 wd->slidingellipsis = EINA_FALSE;
645 elm_label_ellipsis_set(obj, EINA_TRUE);
651 * Add a new label to the parent
653 * @param parent The parent object
654 * @return The new object or NULL if it cannot be created
659 elm_label_add(Evas_Object *parent)
665 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
667 wd = ELM_NEW(Widget_Data);
668 e = evas_object_evas_get(parent);
670 wd->bgcolor = EINA_FALSE;
671 wd->bg = evas_object_rectangle_add(e);
672 evas_object_color_set(wd->bg, 0, 0, 0, 0);
673 obj = elm_widget_add(e);
674 ELM_SET_WIDTYPE(widtype, "label");
675 elm_widget_type_set(obj, "label");
676 elm_widget_sub_object_add(parent, obj);
677 elm_widget_data_set(obj, wd);
678 elm_widget_del_hook_set(obj, _del_hook);
679 elm_widget_theme_hook_set(obj, _theme_hook);
680 elm_widget_can_focus_set(obj, EINA_FALSE);
682 wd->linewrap = EINA_FALSE;
683 wd->ellipsis = EINA_FALSE;
684 wd->wrapmode = EINA_FALSE;
685 wd->slidingmode = EINA_FALSE;
686 wd->slidingellipsis = EINA_FALSE;
689 wd->slide_duration = 10;
691 wd->lbl = edje_object_add(e);
692 _elm_theme_object_set(obj, wd->lbl, "label", "base", "default");
693 wd->label = eina_stringshare_add("<br>");
694 edje_object_part_text_set(wd->lbl, "elm.text", "<br>");
695 elm_widget_resize_object_set(obj, wd->lbl);
697 evas_object_event_callback_add(wd->lbl, EVAS_CALLBACK_RESIZE, _resize, obj);
705 * Set the label on the label object
707 * @param obj The label object
708 * @param label The label will be used on the label object
713 elm_label_label_set(Evas_Object *obj, const char *label)
715 ELM_CHECK_WIDTYPE(obj, widtype);
716 Widget_Data *wd = elm_widget_data_get(obj);
718 if (!label) label = "";
719 eina_stringshare_replace(&wd->label, label);
720 edje_object_part_text_set(wd->lbl, "elm.text", label);
726 * Get the label used on the label object
728 * @param obj The label object
729 * @return The string inside the label
733 elm_label_label_get(const Evas_Object *obj)
735 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
736 Widget_Data *wd = elm_widget_data_get(obj);
737 if (!wd) return NULL;
742 * Set the wrapping behavior of the label
744 * @param obj The label object
745 * @param wrap To wrap text or not
749 elm_label_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
751 ELM_CHECK_WIDTYPE(obj, widtype);
752 Widget_Data *wd = elm_widget_data_get(obj);
755 if (wd->linewrap == wrap) return;
757 t = eina_stringshare_add(elm_label_label_get(obj));
759 elm_label_label_set(obj, t);
760 eina_stringshare_del(t);
766 * Get the wrapping behavior of the label
768 * @param obj The label object
769 * @return To wrap text or not
773 elm_label_line_wrap_get(const Evas_Object *obj)
775 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
776 Widget_Data *wd = elm_widget_data_get(obj);
777 if (!wd) return EINA_FALSE;
782 * Set wrap width of the label
784 * @param obj The label object
785 * @param w The wrap width in pixels at a minimum where words need to wrap
789 elm_label_wrap_width_set(Evas_Object *obj, Evas_Coord w)
791 ELM_CHECK_WIDTYPE(obj, widtype);
792 Widget_Data *wd = elm_widget_data_get(obj);
795 if (wd->wrap_w == w) return;
796 if (wd->ellipsis) edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
802 * get wrap width of the label
804 * @param obj The label object
805 * @return The wrap width in pixels at a minimum where words need to wrap
809 elm_label_wrap_width_get(const Evas_Object *obj)
811 ELM_CHECK_WIDTYPE(obj, widtype) 0;
812 Widget_Data *wd = elm_widget_data_get(obj);
818 * Set wrap height of the label
820 * @param obj The label object
821 * @param w The wrap width in pixels at a minimum where words need to wrap
825 elm_label_wrap_height_set(Evas_Object *obj,
828 ELM_CHECK_WIDTYPE(obj, widtype);
829 Widget_Data *wd = elm_widget_data_get(obj);
832 if (wd->wrap_h == h) return;
833 if (wd->ellipsis) edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
839 * get wrap width of the label
841 * @param obj The label object
842 * @return The wrap height in pixels at a minimum where words need to wrap
846 elm_label_wrap_height_get(const Evas_Object *obj)
848 ELM_CHECK_WIDTYPE(obj, widtype) 0;
849 Widget_Data *wd = elm_widget_data_get(obj);
855 * Set the font size on the label object.
857 * NEVER use this. It is for hyper-special cases only. use styles instead. e.g.
858 * "big", "medium", "small" - or better name them by use:
859 * "title", "footnote", "quote" etc.
861 * @param obj The label object
862 * @param size font size
867 elm_label_fontsize_set(Evas_Object *obj, int fontsize)
869 ELM_CHECK_WIDTYPE(obj, widtype);
870 Widget_Data *wd = elm_widget_data_get(obj);
871 Eina_Strbuf *fontbuf = NULL;
872 int len, removeflag = 0;
875 _elm_dangerous_call_check(__FUNCTION__);
876 len = strlen(wd->label);
877 if (len <= 0) return;
878 fontbuf = eina_strbuf_new();
879 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
881 if (fontsize == 0) removeflag = 1; // remove fontsize tag
883 if (_stringshare_key_value_replace(&wd->label, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
885 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
889 eina_strbuf_free(fontbuf);
893 * Set the text align on the label object
895 * NEVER use this. It is for hyper-special cases only. use styles instead. e.g.
896 * "big", "medium", "small" - or better name them by use:
897 * "title", "footnote", "quote" etc.
899 * @param obj The label object
900 * @param align align mode ("left", "center", "right")
905 elm_label_text_align_set(Evas_Object *obj, const char *alignmode)
907 ELM_CHECK_WIDTYPE(obj, widtype);
908 Widget_Data *wd = elm_widget_data_get(obj);
912 _elm_dangerous_call_check(__FUNCTION__);
913 len = strlen(wd->label);
914 if (len <= 0) return;
916 if (_stringshare_key_value_replace(&wd->label, "align", alignmode, 0) == 0)
917 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
924 * Set the text color on the label object
926 * @param obj The label object
927 * @param r Red property background color of The label object
928 * @param g Green property background color of The label object
929 * @param b Blue property background color of The label object
930 * @param a Alpha property background color of The label object
935 elm_label_text_color_set(Evas_Object *obj,
941 ELM_CHECK_WIDTYPE(obj, widtype);
942 Widget_Data *wd = elm_widget_data_get(obj);
943 Eina_Strbuf *colorbuf = NULL;
947 _elm_dangerous_call_check(__FUNCTION__);
948 len = strlen(wd->label);
949 if (len <= 0) return;
950 colorbuf = eina_strbuf_new();
951 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
953 if (_stringshare_key_value_replace(&wd->label, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
955 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
959 eina_strbuf_free(colorbuf);
963 * Set background color of the label
965 * NEVER use this. It is for hyper-special cases only. use styles instead. e.g.
966 * "big", "medium", "small" - or better name them by use:
967 * "title", "footnote", "quote" etc.
969 * @param obj The label object
970 * @param r Red property background color of The label object
971 * @param g Green property background color of The label object
972 * @param b Blue property background color of The label object
973 * @param a Alpha property background alpha of The label object
978 elm_label_background_color_set(Evas_Object *obj,
984 ELM_CHECK_WIDTYPE(obj, widtype);
985 Widget_Data *wd = elm_widget_data_get(obj);
987 evas_object_color_set(wd->bg, r, g, b, a);
990 _elm_dangerous_call_check(__FUNCTION__);
991 if (wd->bgcolor == EINA_FALSE)
994 edje_object_part_swallow(wd->lbl, "label.swallow.background", wd->bg);
999 * Set the ellipsis behavior of the label
1001 * @param obj The label object
1002 * @param ellipsis To ellipsis text or not
1006 elm_label_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
1008 ELM_CHECK_WIDTYPE(obj, widtype);
1009 Widget_Data *wd = elm_widget_data_get(obj);
1011 if (wd->ellipsis == ellipsis) return;
1012 wd->ellipsis = ellipsis;
1013 if (wd->linewrap) _theme_change(obj);
1014 edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
1020 * Set the wrapmode of the label
1022 * @param obj The label object
1023 * @param wrapmode 0 is charwrap, 1 is wordwrap
1027 elm_label_wrap_mode_set(Evas_Object *obj,
1030 ELM_CHECK_WIDTYPE(obj, widtype);
1031 Widget_Data *wd = elm_widget_data_get(obj);
1033 if (wd->wrapmode == wrapmode) return;
1034 wd->wrapmode = wrapmode;
1035 _label_state_change(obj);
1041 * Set the text slide of the label
1043 * @param obj The label object
1044 * @param slide To start slide or stop
1048 elm_label_slide_set(Evas_Object *obj,
1051 ELM_CHECK_WIDTYPE(obj, widtype);
1052 Widget_Data *wd = elm_widget_data_get(obj);
1055 if (wd->slidingmode == slide) return;
1056 wd->slidingmode = slide;
1057 _label_sliding_change(obj);
1063 * get the text slide mode of the label
1065 * @param obj The label object
1066 * @return slide slide mode value
1070 elm_label_slide_get(Evas_Object *obj)
1072 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1073 Widget_Data *wd = elm_widget_data_get(obj);
1074 if (!wd) return EINA_FALSE;
1075 return wd->slidingmode;
1079 * set the slide duration(speed) of the label
1081 * @param obj The label object
1082 * @return The duration time in moving text from slide begin position to slide end position
1086 elm_label_slide_duration_set(Evas_Object *obj, int duration)
1088 ELM_CHECK_WIDTYPE(obj, widtype);
1089 Widget_Data *wd = elm_widget_data_get(obj);
1090 Edje_Message_Int_Set *msg = alloca(sizeof(Edje_Message_Int_Set) + (sizeof(int)));
1093 wd->slide_duration = duration;
1095 msg->val[0] = (int)wd->slide_duration;
1096 edje_object_message_send(wd->lbl, EDJE_MESSAGE_INT_SET, 0, msg);
1100 * get the slide duration(speed) of the label
1102 * @param obj The label object
1103 * @return The duration time in moving text from slide begin position to slide end position
1107 elm_label_slide_duration_get(Evas_Object *obj)
1109 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1110 Widget_Data *wd = elm_widget_data_get(obj);
1112 return wd->slide_duration;