fixed plugin image size problem
[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_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_choices[] = {"compress", "scroll", "limit", "expand", NULL};
25
26 static Elm_List_Mode
27 _list_horizontal_setting_get(const char *horizontal_str)
28 {
29    unsigned int i;
30
31    assert(sizeof(list_horizontal_choices)/sizeof(list_horizontal_choices[0]) == ELM_LIST_LAST + 1);
32
33    for (i = 0; i < ELM_LIST_LAST; i++)
34      {
35         if (!strcmp(horizontal_str, list_horizontal_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)
51      {
52         Elm_List_Mode set = _list_horizontal_setting_get(p->horizontal);
53
54         if (set != ELM_LIST_LAST)
55            elm_genlist_mode_set(obj, set);
56      }
57    if (p->multi_exists)
58      elm_genlist_multi_select_set(obj, p->multi);
59    if (p->no_select_exists)
60      {
61         if (p->no_select)
62           elm_genlist_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_NONE);
63         else
64           elm_genlist_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_DEFAULT);
65      }
66    if (p->always_select_exists)
67      {
68         if (p->always_select)
69           elm_genlist_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_ALWAYS);
70         else
71           elm_genlist_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_DEFAULT);
72      }
73    if (p->homogeneous_exists)
74      elm_genlist_homogeneous_set(obj, p->homogeneous);
75    if ((p->h_bounce_exists) && (p->v_bounce_exists))
76      elm_genlist_bounce_set(obj, p->h_bounce, p->v_bounce);
77    else if ((p->h_bounce_exists) || (p->v_bounce_exists))
78      {
79         Eina_Bool h_bounce, v_bounce;
80
81         elm_genlist_bounce_get(obj, &h_bounce, &v_bounce);
82         if (p->h_bounce_exists)
83           elm_genlist_bounce_set(obj, p->h_bounce, v_bounce);
84         else
85           elm_genlist_bounce_set(obj, h_bounce, p->v_bounce);
86      }
87 }
88
89 static Eina_Bool
90 external_genlist_param_set(void *data __UNUSED__, Evas_Object *obj, const Edje_External_Param *param)
91 {
92    if (!strcmp(param->name, "horizontal mode"))
93      {
94         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_CHOICE)
95           {
96              Elm_List_Mode set = _list_horizontal_setting_get(param->s);
97
98              if (set == ELM_LIST_LAST) return EINA_FALSE;
99              elm_genlist_mode_set(obj, set);
100              return EINA_TRUE;
101           }
102      }
103    else if (!strcmp(param->name, "multi select"))
104      {
105         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
106           {
107              elm_genlist_multi_select_set(obj, param->i);
108              return EINA_TRUE;
109           }
110      }
111    else if (!strcmp(param->name, "always select"))
112      {
113         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
114           {
115              if (param->i)
116                elm_genlist_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_ALWAYS);
117              else
118                elm_genlist_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_DEFAULT);
119              return EINA_TRUE;
120           }
121      }
122    else if (!strcmp(param->name, "no select"))
123      {
124         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
125           {
126              if (param->i)
127                elm_genlist_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_NONE);
128              else
129                elm_genlist_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_DEFAULT);
130              return EINA_TRUE;
131           }
132      }
133    else if (!strcmp(param->name, "homogeneous"))
134      {
135         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
136           {
137              elm_genlist_homogeneous_set(obj, param->i);
138              return EINA_TRUE;
139           }
140      }
141    else if (!strcmp(param->name, "height bounce"))
142      {
143         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
144           {
145              Eina_Bool h_bounce, v_bounce;
146              elm_genlist_bounce_get(obj, &h_bounce, &v_bounce);
147              elm_genlist_bounce_set(obj, param->i, v_bounce);
148              return EINA_TRUE;
149           }
150      }
151    else if (!strcmp(param->name, "width bounce"))
152      {
153         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
154           {
155              Eina_Bool h_bounce, v_bounce;
156              elm_genlist_bounce_get(obj, &h_bounce, &v_bounce);
157              elm_genlist_bounce_set(obj, h_bounce, param->i);
158              return EINA_TRUE;
159           }
160      }
161
162    ERR("unknown parameter '%s' of type '%s'",
163        param->name, edje_external_param_type_str(param->type));
164
165    return EINA_FALSE;
166 }
167
168 static Eina_Bool
169 external_genlist_param_get(void *data __UNUSED__, const Evas_Object *obj, Edje_External_Param *param)
170 {
171    if (!strcmp(param->name, "horizontal mode"))
172      {
173         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_CHOICE)
174           {
175              Elm_List_Mode list_horizontal_set = elm_genlist_mode_get(obj);
176
177              if (list_horizontal_set == ELM_LIST_LAST)
178                return EINA_FALSE;
179
180              param->s = list_horizontal_choices[list_horizontal_set];
181              return EINA_TRUE;
182           }
183      }
184    else if (!strcmp(param->name, "multi select"))
185      {
186         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
187           {
188              param->i = elm_genlist_multi_select_get(obj);
189              return EINA_TRUE;
190           }
191      }
192    else if (!strcmp(param->name, "always select"))
193      {
194         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
195           {
196              if (elm_genlist_select_mode_get (obj) ==
197                  ELM_OBJECT_SELECT_MODE_ALWAYS)
198                param->i = EINA_TRUE;
199              else
200                param->i = EINA_FALSE;
201              return EINA_TRUE;
202           }
203      }
204    else if (!strcmp(param->name, "no select"))
205      {
206         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
207           {
208              if (elm_genlist_select_mode_get (obj) ==
209                  ELM_OBJECT_SELECT_MODE_NONE)
210                param->i = EINA_TRUE;
211              else
212                param->i = EINA_FALSE;
213              return EINA_TRUE;
214           }
215      }
216    else if (!strcmp(param->name, "homogeneous"))
217      {
218         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
219           {
220              param->i = elm_genlist_homogeneous_get(obj);
221              return EINA_TRUE;
222           }
223      }
224    else if (!strcmp(param->name, "height bounce"))
225      {
226         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
227           {
228              Eina_Bool h_bounce, v_bounce;
229              elm_genlist_bounce_get(obj, &h_bounce, &v_bounce);
230              param->i = h_bounce;
231              return EINA_TRUE;
232           }
233      }
234    else if (!strcmp(param->name, "width bounce"))
235      {
236         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
237           {
238              Eina_Bool h_bounce, v_bounce;
239              elm_genlist_bounce_get(obj, &h_bounce, &v_bounce);
240              param->i = v_bounce;
241              return EINA_TRUE;
242           }
243      }
244
245    ERR("unknown parameter '%s' of type '%s'",
246        param->name, edje_external_param_type_str(param->type));
247
248    return EINA_FALSE;
249 }
250
251 static void *
252 external_genlist_params_parse(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const Eina_List *params)
253 {
254    Elm_Params_Genlist *mem;
255    Edje_External_Param *param;
256    const Eina_List *l;
257
258    mem = ELM_NEW(Elm_Params_Genlist);
259    if (!mem)
260      return NULL;
261
262    EINA_LIST_FOREACH(params, l, param)
263      {
264         if (!strcmp(param->name, "horizontal mode"))
265              mem->horizontal = eina_stringshare_add(param->s);
266         else if (!strcmp(param->name, "multi select"))
267           {
268              mem->multi = !!param->i;
269              mem->multi_exists = EINA_TRUE;
270           }
271         else if (!strcmp(param->name, "always select"))
272           {
273              mem->always_select = !!param->i;
274              mem->always_select_exists = EINA_TRUE;
275           }
276         else if (!strcmp(param->name, "no select"))
277           {
278              mem->no_select = !!param->i;
279              mem->no_select_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("homogeneous"),
326    EDJE_EXTERNAL_PARAM_INFO_BOOL("height bounce"),
327    EDJE_EXTERNAL_PARAM_INFO_BOOL("width bounce"),
328    EDJE_EXTERNAL_PARAM_INFO_SENTINEL
329 };
330
331 DEFINE_EXTERNAL_ICON_ADD(genlist, "genlist");
332 DEFINE_EXTERNAL_TYPE_SIMPLE(genlist, "Generic List");