Merge branch 'master' of 165.213.180.234:/git/slp/pkgs/elementary
[framework/uifw/elementary.git] / src / lib / elm_label.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup Label Label
6  * @ingroup Elementary
7  *
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
10  */
11
12 typedef struct _Widget_Data Widget_Data;
13
14 struct _Widget_Data
15 {
16    Evas_Object *lbl;
17    Evas_Object *bg;
18    const char *label;
19    Evas_Coord lastw;
20    Ecore_Job *deferred_recalc_job;
21    Evas_Coord wrap_w;
22    Evas_Coord wrap_h;
23    Eina_Bool linewrap : 1;
24    Eina_Bool changed : 1;
25    Eina_Bool bgcolor : 1;
26    Eina_Bool ellipsis : 1;
27 };
28
29 static const char *widtype = NULL;
30 static void _del_hook(Evas_Object *obj);
31 static void _theme_hook(Evas_Object *obj);
32 static void _sizing_eval(Evas_Object *obj);
33 static int _get_value_in_key_string(const char *oldstring, char *key, char **value);
34 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag);
35 static int _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag);
36 static int _is_width_over(Evas_Object *obj, int linemode);
37 static void _ellipsis_label_to_width(Evas_Object *obj, int linemode);
38
39 static void
40 _elm_win_recalc_job(void *data)
41 {
42    Widget_Data *wd = elm_widget_data_get(data);
43    Evas_Coord minw = -1, minh = -1, maxh = -1;
44    Evas_Coord resw, resh, minminw, minminh;
45    if (!wd) return;
46    wd->deferred_recalc_job = NULL;
47    evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
48    resh = 0;
49    minminw = 0;
50    edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, 0, 0);
51    minminw = minw;
52    minminh = minh;
53    if (wd->wrap_w >= resw) 
54      {
55         resw = wd->wrap_w;
56         edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, resw, 0);
57         evas_object_size_hint_min_set(data, minw, minh);
58      }
59    else
60      {
61         if (wd->wrap_w > minminw) minminw = wd->wrap_w;
62         edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, resw, 0);
63         evas_object_size_hint_min_set(data, minminw, minh);
64      }
65
66    if (wd->ellipsis && wd->wrap_h > 0 && _is_width_over(data, 1) == 1) 
67      _ellipsis_label_to_width(data, 1);
68
69    maxh = minh;
70    evas_object_size_hint_max_set(data, -1, maxh);
71 }
72
73 static void
74 _del_hook(Evas_Object *obj)
75 {
76    Widget_Data *wd = elm_widget_data_get(obj);
77    if (!wd) return;
78    if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
79    if (wd->label) eina_stringshare_del(wd->label);
80    if (wd->bg) evas_object_del(wd->bg);
81    free(wd);
82 }
83
84 static void
85 _theme_hook(Evas_Object *obj)
86 {
87    Widget_Data *wd = elm_widget_data_get(obj);
88    if (!wd) return;
89    if (wd->linewrap)
90      _elm_theme_object_set(obj, wd->lbl, "label", "base_wrap", elm_widget_style_get(obj));
91    else
92      _elm_theme_object_set(obj, wd->lbl, "label", "base", elm_widget_style_get(obj));
93    edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
94    edje_object_scale_set(wd->lbl, elm_widget_scale_get(obj) * 
95                          _elm_config->scale);
96    _sizing_eval(obj);
97 }
98
99 static void
100 _sizing_eval(Evas_Object *obj)
101 {
102    Widget_Data *wd = elm_widget_data_get(obj);
103    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
104    Evas_Coord resw, resh;
105    if (!wd) return;
106    if (wd->linewrap)
107      {
108         evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
109         if ((resw == wd->lastw) && (!wd->changed)) return;
110         wd->changed = EINA_FALSE;
111         wd->lastw = resw;
112         _elm_win_recalc_job(obj);
113 // FIXME: works ok. but NOT for genlist. what should genlist do?        
114 //        if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
115 //        wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
116      }
117    else
118      {
119         evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
120         edje_object_size_min_calc(wd->lbl, &minw, &minh);
121         evas_object_size_hint_min_set(obj, minw, minh);
122         maxh = minh;
123         evas_object_size_hint_max_set(obj, maxw, maxh);
124
125         if (wd->ellipsis && _is_width_over(obj, 0) == 1) 
126           _ellipsis_label_to_width(obj, 0);
127      }
128 }
129
130 static void 
131 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
132 {
133    Widget_Data *wd = elm_widget_data_get(data);
134    if (!wd) return;
135    if (wd->linewrap) _sizing_eval(data);
136 }
137
138 static int
139 _get_value_in_key_string(const char *oldstring, char *key, char **value)
140 {
141    char *curlocater, *starttag, *endtag;
142    int firstindex = 0, foundflag = -1;
143
144    curlocater = strstr(oldstring, key);
145    if (curlocater)
146      {
147         starttag = curlocater;
148         endtag = curlocater + strlen(key);
149         if (endtag == NULL || *endtag != '=') 
150           {
151             foundflag = 0;
152             return -1;
153           }
154
155         firstindex = abs(oldstring - curlocater);
156         firstindex += strlen(key)+1; // strlen("key") + strlen("=")
157         *value = (char*)oldstring + firstindex;
158
159         while (oldstring != starttag)
160           {
161             if (*starttag == '>')
162               {
163                 foundflag = 0;
164                 break;
165               }
166             if (*starttag == '<') 
167               break;
168             else 
169               starttag--;
170             if (starttag == NULL) break;
171           }
172
173         while (NULL != endtag)
174           {
175             if (*endtag == '<')
176               {
177                 foundflag = 0;
178                 break;
179               }
180             if (*endtag == '>') 
181               break;
182             else 
183               endtag++;
184             if (endtag == NULL) break;
185           }
186
187         if (foundflag != 0 && *starttag == '<' && *endtag == '>') 
188           foundflag = 1;
189         else 
190           foundflag = 0;
191      }
192    else
193      {
194        foundflag = 0;
195      }
196
197    if (foundflag == 1) return 0;
198
199    return -1;
200 }
201
202 static int
203 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
204 {
205    const char *srcstring = NULL;
206    Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
207    char *curlocater, *replocater;
208    char *starttag, *endtag;
209    int tagtxtlen = 0, insertflag = 0;
210
211    srcstring = eina_strbuf_string_get(srcbuf);
212    curlocater = strstr(srcstring, key);
213
214    if (curlocater == NULL)
215      {
216        insertflag = 1;
217      }
218    else
219      {
220        do 
221          {
222            starttag = strchr(srcstring, '<');
223            endtag = strchr(srcstring, '>');
224            tagtxtlen = endtag - starttag;
225            if (tagtxtlen <= 0) tagtxtlen = 0;
226            if (starttag < curlocater && curlocater < endtag) break;
227            if (endtag != NULL && endtag+1 != NULL)
228              srcstring = endtag+1;
229            else
230              break;
231          } while (strlen(srcstring) > 1);
232
233        if (starttag && endtag && tagtxtlen > strlen(key))
234          {
235            repbuf = eina_strbuf_new();
236            diffbuf = eina_strbuf_new();
237            eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
238            srcstring = eina_strbuf_string_get(repbuf);
239            curlocater = strstr(srcstring, key);
240
241            if (curlocater != NULL)
242              {
243                replocater = curlocater + strlen(key) + 1;
244
245                while (*replocater == ' ' || *replocater == '=')
246                            {
247                  replocater++;
248                            }
249
250                 while (*replocater != NULL && *replocater != ' ' && *replocater != '>')
251                   replocater++;
252
253                if (replocater-curlocater > strlen(key)+1)
254                  {
255                    replocater--;
256                    eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
257                  }
258                else
259                  insertflag = 1;
260              }
261            else
262              {
263                insertflag = 1;
264              }
265            eina_strbuf_reset(repbuf);
266          }
267        else
268          {
269            insertflag = 1; 
270          }
271      }
272
273    if (repbuf == NULL) repbuf = eina_strbuf_new();
274    if (diffbuf == NULL) diffbuf = eina_strbuf_new();
275
276    if (insertflag)
277      {
278        eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
279        eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
280      }
281    else
282      {
283         if (deleteflag)
284           {
285             eina_strbuf_prepend(diffbuf, "<");
286             eina_strbuf_append(diffbuf, ">");
287             eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
288           }
289         else
290           {
291             eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
292             eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
293           }
294      }
295
296    if (repbuf) eina_strbuf_free(repbuf);
297    if (diffbuf) eina_strbuf_free(diffbuf);
298   
299    return 0;           
300 }
301
302 static int
303 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
304 {
305    Eina_Strbuf *sharebuf = NULL;   
306    
307    sharebuf = eina_strbuf_new();
308    eina_strbuf_append(sharebuf, *srcstring);
309    _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
310    eina_stringshare_del(*srcstring);
311    *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
312    eina_strbuf_free(sharebuf);
313
314    return 0;
315 }
316
317 static int
318 _is_width_over(Evas_Object *obj, int linemode)
319 {
320    Evas_Coord x, y, w, h;
321    Evas_Coord vx, vy, vw, vh;
322    Widget_Data *wd = elm_widget_data_get(obj);
323    const char *ellipsis_string = "...";
324    size_t ellen = strlen(ellipsis_string)+1;
325
326    if (!wd) return 0;
327
328    edje_object_part_geometry_get(wd->lbl,"elm.text",&x,&y,&w,&h);
329
330    evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
331
332    if (linemode == 0) // single line
333      {
334        if (x >= 0 && y >= 0) return 0;
335
336        if (ellen < wd->wrap_w && w > wd->wrap_w) return 1;
337      }
338    else // multiline
339      {
340        if (vy > h && h > wd->wrap_h) return 1;
341      }
342
343    return 0;
344 }
345
346 static void
347 _ellipsis_label_to_width(Evas_Object *obj, int linemode)
348 {
349    Widget_Data *wd = elm_widget_data_get(obj);
350    int cur_fontsize = 0, len, showcount;
351    Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
352    char **kvalue = NULL;
353    const char *minfont, *deffont, *maxfont;
354    const char *ellipsis_string = "...";
355    int minfontsize, maxfontsize, minshowcount;
356
357    minshowcount = strlen(ellipsis_string) + 1;
358    minfont = edje_object_data_get(wd->lbl, "min_font_size");
359    if (minfont) minfontsize = atoi(minfont);
360    else minfontsize = 1;
361    maxfont = edje_object_data_get(wd->lbl, "max_font_size");
362    if (maxfont) maxfontsize = atoi(maxfont);
363    else maxfontsize = 1;
364    deffont = edje_object_data_get(wd->lbl, "default_font_size");
365    if (deffont) cur_fontsize = atoi(deffont);
366    else cur_fontsize = 1;
367    if (minfontsize > maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
368    if (eina_stringshare_strlen(wd->label) <= 0) return;
369
370    if (_get_value_in_key_string(wd->label, "font_size", &kvalue) == 0)
371      {
372        if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
373      }
374
375    txtbuf = eina_strbuf_new();
376    eina_strbuf_append(txtbuf, wd->label);
377
378    while (_is_width_over(obj, linemode))
379      {
380        if (cur_fontsize > minfontsize)
381          {
382            cur_fontsize--;
383            if (fontbuf != NULL)
384              {
385                eina_strbuf_free(fontbuf);
386                fontbuf = NULL;
387              }
388            fontbuf = eina_strbuf_new();
389            eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
390            _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
391            edje_object_part_text_set(wd->lbl, "elm.text", eina_strbuf_string_get(txtbuf));
392            eina_strbuf_free(fontbuf);
393            fontbuf = NULL;
394          }
395        else
396          {
397            if (txtbuf != NULL)
398              {
399                eina_strbuf_free(txtbuf);
400                txtbuf = NULL;
401              }
402            txtbuf = eina_strbuf_new();
403            eina_strbuf_append_printf(txtbuf, "%s", edje_object_part_text_get(wd->lbl, "elm.text"));
404            len = eina_strbuf_length_get(txtbuf);
405            showcount = len - 1;
406            while (showcount > minshowcount)
407              {
408                unsigned char *ltxt = eina_strbuf_string_get(txtbuf);
409                len = eina_strbuf_length_get(txtbuf);
410                // FIXME : more reliable truncate routine is needed
411                //         it works on only EUC-KR
412                int delta = 0;
413                            if (ltxt[len-minshowcount-delta] >= 0x80)
414                  {
415                    delta = 2;
416                    showcount--;
417                  }
418                eina_strbuf_remove(txtbuf, len-minshowcount-delta, len);
419                eina_strbuf_append(txtbuf, ellipsis_string);
420                edje_object_part_text_set(wd->lbl, "elm.text", eina_strbuf_string_get(txtbuf));
421
422                if (_is_width_over(obj, linemode))
423                  showcount--;
424                else 
425                  break;
426              }
427          }
428      }
429
430    if (txtbuf) eina_strbuf_free(txtbuf);
431    wd->changed = 1;
432    _sizing_eval(obj);
433 }
434
435 /**
436  * Add a new label to the parent
437  *
438  * @param parent The parent object
439  * @return The new object or NULL if it cannot be created
440  *
441  * @ingroup Label
442  */
443 EAPI Evas_Object *
444 elm_label_add(Evas_Object *parent)
445 {
446    Evas_Object *obj;
447    Evas *e;
448    Widget_Data *wd;
449
450    wd = ELM_NEW(Widget_Data);
451    e = evas_object_evas_get(parent);
452    wd->bg = evas_object_rectangle_add(e);
453    evas_object_color_set(wd->bg, 0, 0, 0, 0);
454    obj = elm_widget_add(e);
455    ELM_SET_WIDTYPE(widtype, "label");
456    elm_widget_type_set(obj, "label");
457    elm_widget_sub_object_add(parent, obj);
458    elm_widget_data_set(obj, wd);
459    elm_widget_del_hook_set(obj, _del_hook);
460    elm_widget_theme_hook_set(obj, _theme_hook);
461    elm_widget_can_focus_set(obj, 0);
462
463    wd->linewrap = EINA_FALSE;
464    wd->bgcolor = EINA_FALSE;
465    wd->ellipsis = EINA_FALSE;
466    wd->wrap_w = 0;
467    wd->wrap_h = 0;
468
469    wd->lbl = edje_object_add(e);
470    _elm_theme_object_set(obj, wd->lbl, "label", "base", "default");
471    wd->label = eina_stringshare_add("<br>");
472    edje_object_part_text_set(wd->lbl, "elm.text", "<br>");
473    elm_widget_resize_object_set(obj, wd->lbl);
474    
475    evas_object_event_callback_add(wd->lbl, EVAS_CALLBACK_RESIZE, _resize, obj);
476    
477    wd->changed = 1;
478    _sizing_eval(obj);
479    return obj;
480 }
481
482 /**
483  * Set the label on the label object
484  *
485  * @param obj The label object
486  * @param label The label will be used on the label object
487  *
488  * @ingroup Label
489  */
490 EAPI void
491 elm_label_label_set(Evas_Object *obj, const char *label)
492 {
493    ELM_CHECK_WIDTYPE(obj, widtype);
494    Widget_Data *wd = elm_widget_data_get(obj);
495    if (!wd) return;
496    if (!label) label = "";
497    eina_stringshare_replace(&wd->label, label);
498    edje_object_part_text_set(wd->lbl, "elm.text", label);
499    wd->changed = 1;
500    _sizing_eval(obj);
501 }
502
503 /**
504  * Get the label used on the label object
505  *
506  * @param obj The label object
507  * @return The string inside the label
508  * @ingroup Label
509  */
510 EAPI const char *
511 elm_label_label_get(const Evas_Object *obj)
512 {
513    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
514    Widget_Data *wd = elm_widget_data_get(obj);
515    if (!wd) return NULL;
516    return wd->label;
517 }
518
519 /**
520  * Set the wrapping behavior of the label
521  *
522  * @param obj The label object
523  * @param wrap To wrap text or not
524  * @ingroup Label
525  */
526 EAPI void
527 elm_label_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
528 {
529    ELM_CHECK_WIDTYPE(obj, widtype);
530    Widget_Data *wd = elm_widget_data_get(obj);
531    if (!wd) return;
532    const char *t;
533    if (wd->linewrap == wrap) return;
534    wd->linewrap = wrap;
535    t = eina_stringshare_add(elm_label_label_get(obj));
536    if (wd->linewrap)
537      _elm_theme_object_set(obj, wd->lbl, "label", "base_wrap", elm_widget_style_get(obj));
538    else
539      _elm_theme_object_set(obj, wd->lbl, "label", "base", elm_widget_style_get(obj));
540    elm_label_label_set(obj, t);
541    eina_stringshare_del(t);
542    wd->changed = 1;
543    _sizing_eval(obj);
544 }
545
546 /**
547  * Get the wrapping behavior of the label
548  *
549  * @param obj The label object
550  * @return To wrap text or not
551  * @ingroup Label
552  */
553 EAPI Eina_Bool
554 elm_label_line_wrap_get(const Evas_Object *obj)
555 {
556    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
557    Widget_Data *wd = elm_widget_data_get(obj);
558    if (!wd) return EINA_FALSE;
559    return wd->linewrap;
560 }
561
562 /**
563  * Set wrap width of the label
564  *
565  * @param obj The label object
566  * @param w The wrap width in pixels at a minimum where words need to wrap
567  * @ingroup Label
568  */
569 EAPI void
570 elm_label_wrap_width_set(Evas_Object *obj, Evas_Coord w)
571 {
572    ELM_CHECK_WIDTYPE(obj, widtype);
573    Widget_Data *wd = elm_widget_data_get(obj);
574    if (!wd) return;
575    if (wd->wrap_w == w) return;
576    wd->wrap_w = w;
577    _sizing_eval(obj);
578 }
579
580 /**
581  * get wrap width of the label
582  *
583  * @param obj The label object
584  * @return The wrap width in pixels at a minimum where words need to wrap
585  * @ingroup Label
586  */
587 EAPI Evas_Coord
588 elm_label_wrap_width_get(const Evas_Object *obj)
589 {
590    ELM_CHECK_WIDTYPE(obj, widtype) 0;
591    Widget_Data *wd = elm_widget_data_get(obj);
592    if (!wd) return 0;
593    return wd->wrap_w;
594 }
595
596 /**
597  * Set wrap height of the label
598  *
599  * @param obj The label object
600  * @param w The wrap width in pixels at a minimum where words need to wrap
601  * @ingroup Label
602  */
603 EAPI void
604 elm_label_wrap_height_set(Evas_Object *obj, Evas_Coord h)
605 {
606    ELM_CHECK_WIDTYPE(obj, widtype);
607    Widget_Data *wd = elm_widget_data_get(obj);
608    if (!wd) return;
609    if (wd->wrap_h == h) return;
610    wd->wrap_h = h;
611    _sizing_eval(obj);
612 }
613
614 /**
615  * get wrap width of the label
616  *
617  * @param obj The label object
618  * @return The wrap height in pixels at a minimum where words need to wrap
619  * @ingroup Label
620  */
621 EAPI Evas_Coord
622 elm_label_wrap_height_get(const Evas_Object *obj)
623 {
624    ELM_CHECK_WIDTYPE(obj, widtype) 0;
625    Widget_Data *wd = elm_widget_data_get(obj);
626    if (!wd) return 0;
627    return wd->wrap_h;
628 }
629
630 /**
631  * Set the font size on the label object
632  *
633  * @param obj The label object
634  * @param size font size
635  *
636  * @ingroup Label
637  */
638 EAPI void
639 elm_label_fontsize_set(Evas_Object *obj, int fontsize)
640 {
641    ELM_CHECK_WIDTYPE(obj, widtype);
642    Widget_Data *wd = elm_widget_data_get(obj);
643    Eina_Strbuf *fontbuf = NULL;
644    int len, removeflag = 0;
645
646    if (!wd) return;
647    len = strlen(wd->label);
648    if (len <= 0) return;
649    fontbuf = eina_strbuf_new();
650    eina_strbuf_append_printf(fontbuf, "%d", fontsize);
651
652    if (fontsize == 0) removeflag = 1; // remove fontsize tag
653
654    if (_stringshare_key_value_replace(&wd->label, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
655      {
656        edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
657        wd->changed = 1;
658        _sizing_eval(obj);
659      }
660    eina_strbuf_free(fontbuf);
661 }
662
663 /**
664  * Set the text align on the label object
665  *
666  * @param obj The label object
667  * @param align align mode ("left", "center", "right")
668  *
669  * @ingroup Label
670  */
671 EAPI void
672 elm_label_text_align_set(Evas_Object *obj, const char *alignmode)
673 {
674    ELM_CHECK_WIDTYPE(obj, widtype);
675    Widget_Data *wd = elm_widget_data_get(obj);
676    int len;
677
678    if (!wd) return;
679    len = strlen(wd->label);
680    if (len <= 0) return;
681
682    if (_stringshare_key_value_replace(&wd->label, "align", alignmode, 0) == 0)
683      edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
684
685    wd->changed = 1;
686    _sizing_eval(obj);
687 }
688
689 /**
690  * Set the text color on the label object
691  *
692  * @param obj The label object
693  * @param r Red property background color of The label object 
694  * @param g Green property background color of The label object 
695  * @param b Blue property background color of The label object 
696  * @param a Alpha property background alpha of The label object 
697  *
698  * @ingroup Label
699  */
700 EAPI void
701 elm_label_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
702 {
703    ELM_CHECK_WIDTYPE(obj, widtype);
704    Widget_Data *wd = elm_widget_data_get(obj);
705    Eina_Strbuf *colorbuf = NULL;
706    int len;
707
708    if (!wd) return;
709    len = strlen(wd->label);
710    if (len <= 0) return;
711    colorbuf = eina_strbuf_new();
712    eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
713
714    if (_stringshare_key_value_replace(&wd->label, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
715      {
716        edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
717        wd->changed = 1;
718        _sizing_eval(obj);
719      }
720    eina_strbuf_free(colorbuf);
721 }
722
723
724 /**
725  * Set background color of the label
726  *
727  * @param obj The label object
728  * @param r Red property background color of The label object 
729  * @param g Green property background color of The label object 
730  * @param b Blue property background color of The label object 
731  * @param a Alpha property background alpha of The label object 
732  * @ingroup Label
733  */
734 EAPI void
735 elm_label_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
736 {
737    ELM_CHECK_WIDTYPE(obj, widtype);
738    Widget_Data *wd = elm_widget_data_get(obj);
739    evas_object_color_set(wd->bg, r, g, b, a);
740
741    if (wd->bgcolor == EINA_FALSE)
742      {
743         wd->bgcolor = 1;
744         edje_object_part_swallow(wd->lbl, "label.swallow.background", wd->bg);
745      }
746 }
747
748 /**
749  * Set the ellipsis behavior of the label
750  *
751  * @param obj The label object
752  * @param ellipsis To ellipsis text or not
753  * @ingroup Label
754  */
755 EAPI void
756 elm_label_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
757 {
758    ELM_CHECK_WIDTYPE(obj, widtype);
759    Widget_Data *wd = elm_widget_data_get(obj);
760    if (wd->ellipsis == ellipsis) return;
761    wd->ellipsis = ellipsis;
762    wd->changed = 1;
763    _sizing_eval(obj);
764 }