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