svn update: 48945 (latest:48959)
[framework/uifw/elementary.git] / src / edje_externals / elm_list.c
1 #include <assert.h>
2
3 #include "private.h"
4
5 typedef struct _Elm_Params_List
6 {
7    const char *policy_h;
8    const char *policy_v;
9    const char *horizontal_mode;
10    Eina_Bool multi : 1;
11    Eina_Bool multi_exists : 1;
12    Eina_Bool always_select : 1;
13    Eina_Bool always_select_exists : 1;
14 } Elm_Params_List;
15
16 #define CHOICE_GET(CHOICES, STR)                \
17   unsigned int i;                               \
18   for (i = 0; i < sizeof(CHOICES); i++)         \
19     if (strcmp(STR, CHOICES[i]) == 0)           \
20       return i
21
22 static const char *scroller_policy_choices[] = {"auto", "on", "off", NULL};
23 static const char *list_horizontal_mode_choices[] = {"compress", "scroll",
24                                                      "limit", NULL};
25
26 static Elm_Scroller_Policy
27 _scroller_policy_choices_setting_get(const char *policy_str)
28 {
29    assert(sizeof(scroller_policy_choices)/
30           sizeof(scroller_policy_choices[0]) == ELM_SCROLLER_POLICY_LAST + 1);
31    CHOICE_GET(scroller_policy_choices, policy_str);
32    return ELM_SCROLLER_POLICY_LAST;
33 }
34
35 static Elm_List_Mode
36 _list_horizontal_mode_setting_get(const char *horizontal_mode_str)
37 {
38    assert(sizeof(list_horizontal_mode_choices)/
39           sizeof(list_horizontal_mode_choices[0]) == ELM_LIST_LAST + 1);
40    CHOICE_GET(list_horizontal_mode_choices, horizontal_mode_str);
41    return ELM_LIST_LAST;
42 }
43
44
45 static void
46 external_list_state_set(void *data __UNUSED__, Evas_Object *obj, const void *from_params, const void *to_params, float pos __UNUSED__)
47 {
48    const Elm_Params_List *p;
49    Elm_Scroller_Policy policy_h, policy_v;
50
51    if (to_params) p = to_params;
52    else if (from_params) p = from_params;
53    else return;
54
55    if (p->horizontal_mode)
56      {
57         Elm_List_Mode set = _list_horizontal_mode_setting_get(
58                                              p->horizontal_mode);
59
60         if (set != ELM_LIST_LAST)
61            elm_list_horizontal_mode_set(obj, set);
62      }
63
64    if ((p->policy_h) && (p->policy_v))
65      {
66         policy_h = _scroller_policy_choices_setting_get(p->policy_h);
67         policy_v = _scroller_policy_choices_setting_get(p->policy_v);
68         elm_list_scroller_policy_set(obj, policy_h, policy_v);
69      }
70    else if ((p->policy_h) || (p->policy_v))
71      {
72         elm_list_scroller_policy_get(obj, &policy_h, &policy_v);
73         if (p->policy_h)
74           {
75              policy_h = _scroller_policy_choices_setting_get(p->policy_h);
76              elm_list_scroller_policy_set(obj, policy_h, policy_v);
77           }
78         else
79           {
80              policy_v = _scroller_policy_choices_setting_get(p->policy_v);
81              elm_list_scroller_policy_set(obj, policy_h, policy_v);
82           }
83      }
84
85    if (p->multi_exists)
86      elm_list_multi_select_set(obj, p->multi);
87    if (p->always_select_exists)
88      elm_list_always_select_mode_set(obj, p->always_select);
89 }
90
91 static Eina_Bool
92 external_list_param_set(void *data __UNUSED__, Evas_Object *obj, const Edje_External_Param *param)
93 {
94    if (!strcmp(param->name, "horizontal mode"))
95      {
96         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_CHOICE)
97           {
98              Elm_List_Mode set = _list_horizontal_mode_setting_get(param->s);
99              if (set == ELM_LIST_LAST) return EINA_FALSE;
100              elm_list_horizontal_mode_set(obj, set);
101              return EINA_TRUE;
102           }
103      }
104    else if (!strcmp(param->name, "scroll horizontal"))
105      {
106         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_CHOICE)
107           {
108              Elm_Scroller_Policy h, v;
109              elm_list_scroller_policy_get(obj, &h, &v);
110              h = _scroller_policy_choices_setting_get(param->s);
111              if (h == ELM_SCROLLER_POLICY_LAST) return EINA_FALSE;
112              elm_list_scroller_policy_set(obj, h, v);
113              return EINA_TRUE;
114           }
115      }
116    else if (!strcmp(param->name, "scroll vertical"))
117      {
118         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_CHOICE)
119           {
120              Elm_Scroller_Policy h, v;
121              elm_list_scroller_policy_get(obj, &h, &v);
122              v = _scroller_policy_choices_setting_get(param->s);
123              if (v == ELM_SCROLLER_POLICY_LAST) return EINA_FALSE;
124              elm_list_scroller_policy_set(obj, h, v);
125              return EINA_TRUE;
126           }
127      }
128    else  if (!strcmp(param->name, "multi"))
129      {
130         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
131           {
132              elm_list_multi_select_set(obj, param->i);
133              return EINA_TRUE;
134           }
135      }
136    else if (!strcmp(param->name, "always_select"))
137      {
138         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
139           {
140              elm_list_always_select_mode_set(obj, param->i);
141              return EINA_TRUE;
142           }
143      }
144
145    ERR("unknown parameter '%s' of type '%s'",
146        param->name, edje_external_param_type_str(param->type));
147
148    return EINA_FALSE;
149 }
150
151 static Eina_Bool
152 external_list_param_get(void *data __UNUSED__, const Evas_Object *obj, Edje_External_Param *param)
153 {
154    if (!strcmp(param->name, "multi"))
155      {
156         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
157           {
158              param->i = elm_list_multi_select_get(obj);
159              return EINA_TRUE;
160           }
161      }
162    else if (!strcmp(param->name, "always_select"))
163      {
164         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
165           {
166              param->i = elm_list_always_select_mode_get(obj);
167              return EINA_TRUE;
168           }
169      }
170    else if (!strcmp(param->name, "scroll horizontal"))
171      {
172         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_CHOICE)
173           {
174              Elm_Scroller_Policy h, v;
175              elm_list_scroller_policy_get(obj, &h, &v);
176
177              param->s = scroller_policy_choices[h];
178              return EINA_TRUE;
179           }
180      }
181    else if (!strcmp(param->name, "scroll vertical"))
182      {
183         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_CHOICE)
184           {
185              Elm_Scroller_Policy h, v;
186              elm_list_scroller_policy_get(obj, &h, &v);
187
188              param->s = scroller_policy_choices[v];
189              return EINA_TRUE;
190           }
191      }
192    else if (!strcmp(param->name, "horizontal mode"))
193      {
194         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_CHOICE)
195           {
196              Elm_List_Mode m = elm_list_horizontal_mode_get(obj);
197
198              if (m == ELM_LIST_LAST)
199                return EINA_FALSE;
200
201              param->s = list_horizontal_mode_choices[m];
202              return EINA_TRUE;
203           }
204      }
205
206    ERR("unknown parameter '%s' of type '%s'",
207        param->name, edje_external_param_type_str(param->type));
208
209    return EINA_FALSE;
210 }
211
212 static void *
213 external_list_params_parse(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const Eina_List *params)
214 {
215    Elm_Params_List *mem;
216    Edje_External_Param *param;
217    const Eina_List *l;
218
219    mem = calloc(1, sizeof(Elm_Params_List));
220    if (!mem)
221      return NULL;
222
223    EINA_LIST_FOREACH(params, l, param)
224      {
225         if (!strcmp(param->name, "multi"))
226           {
227              mem->multi = param->i;
228              mem->multi_exists = EINA_TRUE;
229           }
230         else if (!strcmp(param->name, "always_select"))
231           {
232              mem->always_select = param->i;
233              mem->always_select_exists = EINA_TRUE;
234           }
235         else if (!strcmp(param->name, "scroll horizontal"))
236           mem->policy_h = eina_stringshare_add(param->s);
237         else if (!strcmp(param->name, "scroll vertical"))
238           mem->policy_v = eina_stringshare_add(param->s);
239         else if (!strcmp(param->name, "horizontal mode"))
240           mem->horizontal_mode = eina_stringshare_add(param->s);
241      }
242    return mem;
243 }
244
245 static void
246 external_list_params_free(void *params)
247 {
248    Elm_Params_List *mem = params;
249
250    if (mem->horizontal_mode)
251      eina_stringshare_del(mem->horizontal_mode);
252    if (mem->policy_h)
253      eina_stringshare_del(mem->policy_h);
254    if (mem->policy_v)
255      eina_stringshare_del(mem->policy_v);
256
257    free(mem);
258 }
259
260 static Edje_External_Param_Info external_list_params[] = {
261   EDJE_EXTERNAL_PARAM_INFO_CHOICE_FULL("horizontal mode", "scroll",
262                                        list_horizontal_mode_choices),
263   EDJE_EXTERNAL_PARAM_INFO_CHOICE_FULL("scroll horizontal", "auto",
264                                        scroller_policy_choices),
265   EDJE_EXTERNAL_PARAM_INFO_CHOICE_FULL("scroll vertical", "auto",
266                                        scroller_policy_choices),
267   EDJE_EXTERNAL_PARAM_INFO_BOOL("multi"),
268   EDJE_EXTERNAL_PARAM_INFO_BOOL("always_select"),
269   EDJE_EXTERNAL_PARAM_INFO_SENTINEL
270 };
271
272 DEFINE_EXTERNAL_ICON_ADD(list, "list")
273 DEFINE_EXTERNAL_TYPE_SIMPLE(list, "List");