tizen 2.4 release
[framework/uifw/elementary.git] / src / edje_externals / elm_bg.c
1 #include <assert.h>
2 #include "private.h"
3
4 typedef struct _Elm_Params_Bg
5 {
6    Elm_Params base;
7    const char *file;
8    const char *option;
9 } Elm_Params_Bg;
10
11 #define OPTION_GET(CHOICES, STR)                                \
12    unsigned int i;                                              \
13    for (i = 0; i < (sizeof(CHOICES) / sizeof(CHOICES[0])); ++i) \
14      if (!strcmp(STR, CHOICES[i]))                              \
15        return i;
16
17 static const char *_bg_options[] =
18 {
19    "center", "scale", "stretch", "tile", NULL
20 };
21
22 static Elm_Bg_Option
23 _bg_option_get(const char *option)
24 {
25    assert(sizeof(_bg_options) / sizeof(_bg_options[0])
26           == ELM_BG_OPTION_TILE + 2);
27    OPTION_GET(_bg_options, option);
28    return -1;
29 }
30
31 static void
32 external_bg_state_set(void *data EINA_UNUSED, Evas_Object *obj,
33                       const void *from_params, const void *to_params,
34                       float pos EINA_UNUSED)
35 {
36    const Elm_Params_Bg *p;
37    Elm_Bg_Option option;
38
39    if (to_params) p = to_params;
40    else if (from_params) p = from_params;
41    else return;
42
43    if (p->option)
44      {
45         option = _bg_option_get(p->option);
46         elm_bg_option_set(obj, option);
47      }
48    if (p->file)
49      {
50         elm_bg_file_set(obj, p->file, NULL);
51      }
52 }
53
54 static Eina_Bool
55 external_bg_param_set(void *data EINA_UNUSED, Evas_Object *obj,
56                       const Edje_External_Param *param)
57 {
58    if ((!strcmp(param->name, "file"))
59        && (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING))
60      {
61         return elm_bg_file_set(obj, param->s, NULL);
62      }
63    else if ((!strcmp(param->name, "select_mode"))
64             && (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING))
65      {
66         Elm_Bg_Option option;
67         option = _bg_option_get(param->s);
68         elm_bg_option_set(obj, option);
69         return EINA_TRUE;
70      }
71
72    ERR("unknown parameter '%s' of type '%s'",
73        param->name, edje_external_param_type_str(param->type));
74
75    return EINA_FALSE;
76 }
77
78 static Eina_Bool
79 external_bg_param_get(void *data EINA_UNUSED,
80                       const Evas_Object *obj EINA_UNUSED,
81                       Edje_External_Param *param)
82 {
83    if ((!strcmp(param->name, "file"))
84        && (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING))
85      {
86         elm_bg_file_get(obj, &(param->s), NULL);
87         return EINA_TRUE;
88      }
89    else if ((!strcmp(param->name, "option"))
90             && (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING))
91      {
92         Elm_Bg_Option option;
93         option = elm_bg_option_get(obj);
94         param->s = _bg_options[option];
95         return EINA_TRUE;
96      }
97
98    ERR("unknown parameter '%s' of type '%s'",
99        param->name, edje_external_param_type_str(param->type));
100
101    return EINA_FALSE;
102 }
103
104 static void *
105 external_bg_params_parse(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
106                          const Eina_List *params)
107 {
108    Elm_Params_Bg *mem;
109    Edje_External_Param *param;
110    const Eina_List *l;
111
112    mem = calloc(1, sizeof(Elm_Params_Bg));
113    if (!mem)
114      return NULL;
115
116    EINA_LIST_FOREACH(params, l, param)
117      {
118         if (!strcmp(param->name, "file"))
119           mem->file = eina_stringshare_add(param->s);
120         else if (!strcmp(param->name, "option"))
121           mem->option = eina_stringshare_add(param->s);
122      }
123
124    return mem;
125 }
126
127 static Evas_Object *
128 external_bg_content_get(void *data EINA_UNUSED,
129                         const Evas_Object *obj EINA_UNUSED,
130                         const char *content EINA_UNUSED)
131 {
132    ERR("no content");
133    return NULL;
134 }
135
136 static void
137 external_bg_params_free(void *params)
138 {
139    Elm_Params_Bg *mem = params;
140
141    if (mem->file)
142      eina_stringshare_del(mem->file);
143
144    if (mem->option)
145      eina_stringshare_del(mem->option);
146
147    free(mem);
148 }
149
150 static Edje_External_Param_Info external_bg_params[] =
151 {
152    DEFINE_EXTERNAL_COMMON_PARAMS,
153    EDJE_EXTERNAL_PARAM_INFO_STRING("file"),
154    EDJE_EXTERNAL_PARAM_INFO_STRING("option"),
155    EDJE_EXTERNAL_PARAM_INFO_SENTINEL
156 };
157
158 DEFINE_EXTERNAL_ICON_ADD(bg, "bg");
159 DEFINE_EXTERNAL_TYPE_SIMPLE(bg, "Bg");