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