a8b2405f30e46f2a4703a77f63115fdaaf0d6848
[framework/uifw/elementary.git] / src / edje_externals / elm_genlist.c
1 #include <assert.h>
2
3 #include "private.h"
4
5 typedef struct _Elm_Params_Genlist
6 {
7    const char *horizontal_mode;
8    Eina_Bool multi:1;
9    Eina_Bool multi_exists:1;
10    Eina_Bool always_select:1;
11    Eina_Bool always_select_exists:1;
12    Eina_Bool no_select:1;
13    Eina_Bool no_select_exists:1;
14    Eina_Bool compress:1;
15    Eina_Bool compress_exists:1;
16    Eina_Bool homogeneous:1;
17    Eina_Bool homogeneous_exists:1;
18    Eina_Bool h_bounce:1;
19    Eina_Bool h_bounce_exists:1;
20    Eina_Bool v_bounce:1;
21    Eina_Bool v_bounce_exists:1;
22 } Elm_Params_Genlist;
23
24 static const char* list_horizontal_mode_choices[] = {"compress", "scroll", "limit", NULL};
25
26 static Elm_List_Mode
27 _list_horizontal_mode_setting_get(const char *horizontal_mode_str)
28 {
29    unsigned int i;
30
31    assert(sizeof(list_horizontal_mode_choices)/sizeof(list_horizontal_mode_choices[0]) == ELM_LIST_LAST + 1);
32
33    for (i = 0; i < sizeof(list_horizontal_mode_choices); i++)
34      {
35         if (!strcmp(horizontal_mode_str, list_horizontal_mode_choices[i]))
36           return i;
37      }
38    return ELM_LIST_LAST;
39 }
40
41 static void
42 external_genlist_state_set(void *data __UNUSED__, Evas_Object *obj, const void *from_params, const void *to_params, float pos __UNUSED__)
43 {
44    const Elm_Params_Genlist *p;
45
46    if (to_params) p = to_params;
47    else if (from_params) p = from_params;
48    else return;
49
50    if (p->horizontal_mode)
51      {
52         Elm_List_Mode set = _list_horizontal_mode_setting_get(p->horizontal_mode);
53
54         if (set != ELM_LIST_LAST)
55            elm_genlist_horizontal_mode_set(obj, set);
56      }
57    if (p->multi_exists)
58      elm_genlist_multi_select_set(obj, p->multi);
59    if (p->always_select_exists)
60      elm_genlist_always_select_mode_set(obj, p->always_select);
61    if (p->no_select_exists)
62      elm_genlist_no_select_mode_set(obj, p->no_select);
63    if (p->compress_exists)
64      elm_genlist_compress_mode_set(obj, p->compress);
65    if (p->homogeneous_exists)
66      elm_genlist_homogeneous_set(obj, p->homogeneous);
67    if ((p->h_bounce_exists) && (p->v_bounce_exists))
68      elm_genlist_bounce_set(obj, p->h_bounce, p->v_bounce);
69    else if ((p->h_bounce_exists) || (p->v_bounce_exists))
70      {
71         Eina_Bool h_bounce, v_bounce;
72
73         elm_genlist_bounce_get(obj, &h_bounce, &v_bounce);
74         if (p->h_bounce_exists)
75           elm_genlist_bounce_set(obj, p->h_bounce, v_bounce);
76         else
77           elm_genlist_bounce_set(obj, h_bounce, p->v_bounce);
78      }
79 }
80
81 static Eina_Bool
82 external_genlist_param_set(void *data __UNUSED__, Evas_Object *obj, const Edje_External_Param *param)
83 {
84    if (!strcmp(param->name, "horizontal mode"))
85      {
86         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_CHOICE)
87           {
88              Elm_List_Mode set = _list_horizontal_mode_setting_get(param->s);
89
90              if (set == ELM_LIST_LAST) return EINA_FALSE;
91              elm_genlist_horizontal_mode_set(obj, set);
92              return EINA_TRUE;
93           }
94      }
95    else if (!strcmp(param->name, "multi select"))
96      {
97         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
98           {
99              elm_genlist_multi_select_set(obj, param->i);
100              return EINA_TRUE;
101           }
102      }
103    else if (!strcmp(param->name, "always select"))
104      {
105         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
106           {
107              elm_genlist_always_select_mode_set(obj, param->i);
108              return EINA_TRUE;
109           }
110      }
111    else if (!strcmp(param->name, "no select"))
112      {
113         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
114           {
115              elm_genlist_no_select_mode_set(obj, param->i);
116              return EINA_TRUE;
117           }
118      }
119    else if (!strcmp(param->name, "compress"))
120      {
121         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
122           {
123              elm_genlist_compress_mode_set(obj, param->i);
124              return EINA_TRUE;
125           }
126      }
127    else if (!strcmp(param->name, "homogeneous"))
128      {
129         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
130           {
131              elm_genlist_homogeneous_set(obj, param->i);
132              return EINA_TRUE;
133           }
134      }
135    else if (!strcmp(param->name, "height bounce"))
136      {
137         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
138           {
139              Eina_Bool h_bounce, v_bounce;
140              elm_genlist_bounce_get(obj, &h_bounce, &v_bounce);
141              elm_genlist_bounce_set(obj, param->i, v_bounce);
142              return EINA_TRUE;
143           }
144      }
145    else if (!strcmp(param->name, "width bounce"))
146      {
147         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
148           {
149              Eina_Bool h_bounce, v_bounce;
150              elm_genlist_bounce_get(obj, &h_bounce, &v_bounce);
151              elm_genlist_bounce_set(obj, h_bounce, param->i);
152              return EINA_TRUE;
153           }
154      }
155
156    ERR("unknown parameter '%s' of type '%s'",
157        param->name, edje_external_param_type_str(param->type));
158
159    return EINA_FALSE;
160 }
161
162 static Eina_Bool
163 external_genlist_param_get(void *data __UNUSED__, const Evas_Object *obj, Edje_External_Param *param)
164 {
165    if (!strcmp(param->name, "horizontal mode"))
166      {
167         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_CHOICE)
168           {
169              Elm_List_Mode list_horizontal_mode_set = elm_genlist_horizontal_mode_get(obj);
170
171              if (list_horizontal_mode_set == ELM_LIST_LAST)
172                return EINA_FALSE;
173
174              param->s = list_horizontal_mode_choices[list_horizontal_mode_set];
175              return EINA_TRUE;
176           }
177      }
178    else if (!strcmp(param->name, "multi select"))
179      {
180         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
181           {
182              param->i = elm_genlist_multi_select_get(obj);
183              return EINA_TRUE;
184           }
185      }
186    else if (!strcmp(param->name, "always select"))
187      {
188         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
189           {
190              param->i = elm_genlist_always_select_mode_get(obj);
191              return EINA_TRUE;
192           }
193      }
194    else if (!strcmp(param->name, "no select"))
195      {
196         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
197           {
198              param->i = elm_genlist_no_select_mode_get(obj);
199              return EINA_TRUE;
200           }
201      }
202    else if (!strcmp(param->name, "compress"))
203      {
204         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
205           {
206              param->i = elm_genlist_compress_mode_get(obj);
207              return EINA_TRUE;
208           }
209      }
210    else if (!strcmp(param->name, "homogeneous"))
211      {
212         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
213           {
214              param->i = elm_genlist_homogeneous_get(obj);
215              return EINA_TRUE;
216           }
217      }
218    else if (!strcmp(param->name, "height bounce"))
219      {
220         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
221           {
222              Eina_Bool h_bounce, v_bounce;
223              elm_genlist_bounce_get(obj, &h_bounce, &v_bounce);
224              param->i = h_bounce;
225              return EINA_TRUE;
226           }
227      }
228    else if (!strcmp(param->name, "width bounce"))
229      {
230         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
231           {
232              Eina_Bool h_bounce, v_bounce;
233              elm_genlist_bounce_get(obj, &h_bounce, &v_bounce);
234              param->i = v_bounce;
235              return EINA_TRUE;
236           }
237      }
238
239    ERR("unknown parameter '%s' of type '%s'",
240        param->name, edje_external_param_type_str(param->type));
241
242    return EINA_FALSE;
243 }
244
245 static void *
246 external_genlist_params_parse(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const Eina_List *params)
247 {
248    Elm_Params_Genlist *mem;
249    Edje_External_Param *param;
250    const Eina_List *l;
251
252    mem = calloc(1, sizeof(Elm_Params_Genlist));
253    if (!mem)
254      return NULL;
255
256    EINA_LIST_FOREACH(params, l, param)
257      {
258         if (!strcmp(param->name, "horizontal mode"))
259              mem->horizontal_mode = eina_stringshare_add(param->s);
260         else if (!strcmp(param->name, "multi select"))
261           {
262              mem->multi = !!param->i;
263              mem->multi_exists = EINA_TRUE;
264           }
265         else if (!strcmp(param->name, "always select"))
266           {
267              mem->always_select = !!param->i;
268              mem->always_select_exists = EINA_TRUE;
269           }
270         else if (!strcmp(param->name, "no select"))
271           {
272              mem->no_select = !!param->i;
273              mem->no_select_exists = EINA_TRUE;
274           }
275         else if (!strcmp(param->name, "compress"))
276           {
277              mem->compress = !!param->i;
278              mem->compress_exists = EINA_TRUE;
279           }
280         else if (!strcmp(param->name, "homogeneous"))
281           {
282              mem->homogeneous = !!param->i;
283              mem->homogeneous_exists = EINA_TRUE;
284           }
285         else if (!strcmp(param->name, "height bounce"))
286           {
287              mem->h_bounce = !!param->i;
288              mem->h_bounce_exists = EINA_TRUE;
289           }
290         else if (!strcmp(param->name, "width bounce"))
291           {
292              mem->v_bounce = !!param->i;
293              mem->v_bounce_exists = EINA_TRUE;
294           }
295      }
296
297    return mem;
298 }
299
300 static Evas_Object *external_genlist_content_get(void *data __UNUSED__,
301                 const Evas_Object *obj, const char *content)
302 {
303         ERR("so content");
304         return NULL;
305 }
306
307 static void
308 external_genlist_params_free(void *params)
309 {
310    Elm_Params_Genlist *mem = params;
311
312    if (mem->horizontal_mode)
313      eina_stringshare_del(mem->horizontal_mode);
314
315    free(mem);
316 }
317
318 static Edje_External_Param_Info external_genlist_params[] = {
319    EDJE_EXTERNAL_PARAM_INFO_CHOICE_FULL("horizontal mode", "scroll", list_horizontal_mode_choices),
320    EDJE_EXTERNAL_PARAM_INFO_BOOL("multi select"),
321    EDJE_EXTERNAL_PARAM_INFO_BOOL("always select"),
322    EDJE_EXTERNAL_PARAM_INFO_BOOL("no select"),
323    EDJE_EXTERNAL_PARAM_INFO_BOOL("compress"),
324    EDJE_EXTERNAL_PARAM_INFO_BOOL("homogeneous"),
325    EDJE_EXTERNAL_PARAM_INFO_BOOL("height bounce"),
326    EDJE_EXTERNAL_PARAM_INFO_BOOL("width bounce"),
327    EDJE_EXTERNAL_PARAM_INFO_SENTINEL
328 };
329
330 DEFINE_EXTERNAL_ICON_ADD(genlist, "genlist");
331 DEFINE_EXTERNAL_TYPE_SIMPLE(genlist, "Generic List");