summaryrefslogtreecommitdiff
path: root/src/lib/efl/interfaces/efl_ui_format.c
blob: 6cb64f39136e4674de83f31d1570edf5efb2623b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "config.h"
#include "Efl.h"

typedef struct
{
   const char *template;
} Efl_Ui_Format_Data;

static void
_default_format_cb(void *data, Eina_Strbuf *str, const Eina_Value value)
{
   const Eina_Value_Type *type = eina_value_type_get(&value);
   Efl_Ui_Format_Data *sd = data;

   if (type == EINA_VALUE_TYPE_DOUBLE)
     {
        double v;
        eina_value_get(&value, &v);
        eina_strbuf_append_printf(str, sd->template, v);
     }
   else if (type == EINA_VALUE_TYPE_INT)
     {
        int v;
        eina_value_get(&value, &v);
        eina_strbuf_append_printf(str, sd->template, v);
     }
   //XXX: handle other types e.g. struct tm
   else
     {
        char *v = eina_value_to_string(&value);
        eina_strbuf_append_printf(str, "%s", v);
        free(v);
     }
}

static void
_default_format_free_cb(void *data)
{
   Efl_Ui_Format_Data *sd = data;

   if (sd->template)
     {
        eina_stringshare_del(sd->template);
        sd->template = NULL;
     }
}

EOLIAN static void
_efl_ui_format_format_string_set(Eo *obj, Efl_Ui_Format_Data *sd, const char *template)
{
   if (!template) return;
   eina_stringshare_replace(&sd->template, template);
   efl_ui_format_cb_set(obj, sd, _default_format_cb, _default_format_free_cb);
}

EOLIAN static const char *
_efl_ui_format_format_string_get(Eo *obj EINA_UNUSED, Efl_Ui_Format_Data *sd)
{
   return sd->template;
}

#include "interfaces/efl_ui_format.eo.c"