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