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