summaryrefslogtreecommitdiff
path: root/src/edje_external/elementary/elm_gengrid.c
blob: 73739422343c4dd1ce03f01c3cf199de14b1fb89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
#include <assert.h>
#include "private.h"

typedef struct _Elm_Params_Gengrid
{
   Elm_Params base;
   Eina_Bool multi : 1;
   Eina_Bool multi_exists : 1;
   Eina_Bool no_select : 1;
   Eina_Bool no_select_exists : 1;
   Eina_Bool always_select : 1;
   Eina_Bool always_select_exists : 1;
   Eina_Bool h_bounce:1;
   Eina_Bool h_bounce_exists:1;
   Eina_Bool v_bounce:1;
   Eina_Bool v_bounce_exists:1;
   double    h_pagerel;
   Eina_Bool h_pagerel_exists : 1;
   double    v_pagerel;
   Eina_Bool v_pagerel_exists : 1;
   int       h_itemsize;
   Eina_Bool h_itemsize_exists : 1;
   int       v_itemsize;
   Eina_Bool v_itemsize_exists : 1;
   Eina_Bool horizontal : 1;
   Eina_Bool horizontal_exists : 1;
   Eina_Bool align_x_exists;
   double align_x;
   Eina_Bool align_y_exists;
   double align_y;
} Elm_Params_Gengrid;

static void
external_gengrid_state_set(void *data EINA_UNUSED, Evas_Object *obj,
                           const void *from_params, const void *to_params,
                           float pos EINA_UNUSED)
{
   const Elm_Params_Gengrid *p;

   if (to_params) p = to_params;
   else if (from_params) p = from_params;
   else return;

   if (p->multi_exists)
     elm_gengrid_multi_select_set(obj, p->multi);
   if (p->no_select_exists)
     {
        if (p->no_select)
          elm_gengrid_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_NONE);
        else
          elm_gengrid_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_DEFAULT);
     }
   if (p->always_select_exists)
     {
        if (p->always_select)
          elm_gengrid_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_ALWAYS);
        else
          elm_gengrid_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_DEFAULT);
     }
   if (p->h_bounce_exists)
     {
        Eina_Bool h_bounce, v_bounce;
        elm_scroller_bounce_get(obj, &h_bounce, &v_bounce);
        elm_scroller_bounce_set(obj, p->h_bounce, v_bounce);
     }
   if (p->v_bounce_exists)
     {
        Eina_Bool h_bounce, v_bounce;
        elm_scroller_bounce_get(obj, &h_bounce, &v_bounce);
        elm_scroller_bounce_set(obj, h_bounce, p->v_bounce);
     }
   if (p->h_pagerel_exists)
     {
        double h_pagerel, v_pagerel;
        elm_scroller_page_relative_get(obj, &h_pagerel, &v_pagerel);
        elm_scroller_page_relative_set(obj, h_pagerel, p->v_pagerel);
     }
   if (p->v_pagerel_exists)
     {
        double h_pagerel, v_pagerel;
        elm_scroller_page_relative_get(obj, &h_pagerel, &v_pagerel);
        elm_scroller_page_relative_set(obj, p->h_pagerel, v_pagerel);
     }
   if (p->h_itemsize_exists)
     {
        int h_itemsize, v_itemsize;
        elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
        elm_gengrid_item_size_set(obj, h_itemsize, p->v_itemsize);
     }
   if (p->v_itemsize_exists)
     {
        int h_itemsize, v_itemsize;
        elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
        elm_gengrid_item_size_set(obj, p->h_itemsize, v_itemsize);
     }
   else if (p->align_x_exists || p->align_y_exists)
     {
        double x, y;
        elm_gengrid_align_get(obj, &x, &y);
        if (p->align_x_exists)
          elm_gengrid_align_set(obj, p->align_x, y);
        else
          elm_gengrid_align_set(obj, x, p->align_y);
     }
   if (p->horizontal_exists)
     {
        elm_gengrid_horizontal_set(obj, p->horizontal);
     }
}

static Eina_Bool
external_gengrid_param_set(void *data EINA_UNUSED, Evas_Object *obj,
                           const Edje_External_Param *param)
{
   if (!strcmp(param->name, "multi select"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             elm_gengrid_multi_select_set(obj, param->i);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "no selected"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             if (param->i)
               elm_gengrid_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_NONE);
             else
               elm_gengrid_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_DEFAULT);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "always select"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             if (param->i)
               elm_gengrid_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_ALWAYS);
             else
               elm_gengrid_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_DEFAULT);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "height bounce"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             Eina_Bool h_bounce, v_bounce;
             elm_scroller_bounce_get(obj, &h_bounce, &v_bounce);
             elm_scroller_bounce_set(obj, param->i, v_bounce);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "width bounce"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             Eina_Bool h_bounce, v_bounce;
             elm_scroller_bounce_get(obj, &h_bounce, &v_bounce);
             elm_scroller_bounce_set(obj, h_bounce, param->i);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "horizontal page relative"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
          {
             double h_pagerel, v_pagerel;
             elm_scroller_page_relative_get(obj, &h_pagerel, &v_pagerel);
             elm_scroller_page_relative_set(obj, param->d, v_pagerel);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "vertical page relative"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
          {
             double h_pagerel, v_pagerel;
             elm_scroller_page_relative_get(obj, &h_pagerel, &v_pagerel);
             elm_scroller_page_relative_set(obj, h_pagerel, param->d);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "horizontal item size"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
          {
             int h_itemsize, v_itemsize;
             elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
             elm_gengrid_item_size_set(obj, param->i, v_itemsize);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "vertical item size"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
          {
             int h_itemsize, v_itemsize;
             elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
             elm_gengrid_item_size_set(obj, h_itemsize, param->i);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "horizontal"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             elm_gengrid_horizontal_set(obj, param->i);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "align x")
            && param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
     {
        double x, y;
        elm_gengrid_align_get(obj, &x, &y);
        elm_gengrid_align_set(obj, param->d, y);
        return EINA_TRUE;
     }
   else if (!strcmp(param->name, "align y")
            && param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
     {
        double x, y;
        elm_gengrid_align_get(obj, &x, &y);
        elm_gengrid_align_set(obj, x, param->d);
        return EINA_TRUE;
     }
   ERR("unknown parameter '%s' of type '%s'",
       param->name, edje_external_param_type_str(param->type));

   return EINA_FALSE;
}

static Eina_Bool
external_gengrid_param_get(void *data EINA_UNUSED, const Evas_Object *obj,
                           Edje_External_Param *param)
{
   if (!strcmp(param->name, "multi select"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             param->i = elm_gengrid_multi_select_get(obj);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "no selected"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             if (elm_gengrid_select_mode_get (obj) ==
                 ELM_OBJECT_SELECT_MODE_NONE)
               param->i = EINA_TRUE;
             else
               param->i = EINA_FALSE;
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "always select"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             if (elm_gengrid_select_mode_get (obj) ==
                 ELM_OBJECT_SELECT_MODE_ALWAYS)
               param->i = EINA_TRUE;
             else
               param->i = EINA_FALSE;
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "height bounce"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             Eina_Bool h_bounce, v_bounce;
             elm_scroller_bounce_get(obj, &h_bounce, &v_bounce);
             param->i = h_bounce;
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "width bounce"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             Eina_Bool h_bounce, v_bounce;
             elm_scroller_bounce_get(obj, &h_bounce, &v_bounce);
             param->i = v_bounce;
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "horizontal page relative"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
          {
             double h_pagerel, v_pagerel;
             elm_scroller_page_relative_get(obj, &h_pagerel, &v_pagerel);
             param->d = h_pagerel;
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "vertical page relative"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
          {
             double h_pagerel, v_pagerel;
             elm_scroller_page_relative_get(obj, &h_pagerel, &v_pagerel);
             param->d = v_pagerel;
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "horizontal item size"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
          {
             int h_itemsize, v_itemsize;
             elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
             param->i = h_itemsize;
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "vertical item size"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
          {
             int h_itemsize, v_itemsize;
             elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
             param->i = v_itemsize;
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "horizontal"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             param->i = elm_gengrid_horizontal_get(obj);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "align x")
            && param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
     {
        double x, y;
        elm_gengrid_align_get(obj, &x, &y);
        param->d = x;
        return EINA_TRUE;
     }
   else if (!strcmp(param->name, "align y")
            && param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
     {
        double x, y;
        elm_gengrid_align_get(obj, &x, &y);
        param->d = y;
        return EINA_TRUE;
     }
   ERR("unknown parameter '%s' of type '%s'",
       param->name, edje_external_param_type_str(param->type));

   return EINA_FALSE;
}

static void *
external_gengrid_params_parse(void *data EINA_UNUSED,
                              Evas_Object *obj EINA_UNUSED,
                              const Eina_List *params)
{
   Elm_Params_Gengrid *mem;
   Edje_External_Param *param;
   const Eina_List *l;

   mem = ELM_NEW(Elm_Params_Gengrid);
   if (!mem)
     return NULL;

   EINA_LIST_FOREACH(params, l, param)
     {
        if (!strcmp(param->name, "multi select"))
          {
             mem->multi = !!param->i;
             mem->multi_exists = EINA_TRUE;
          }
        else if (!strcmp(param->name, "no selected"))
          {
             mem->no_select = !!param->i;
             mem->no_select_exists = EINA_TRUE;
          }
        else if (!strcmp(param->name, "always select"))
          {
             mem->always_select = !!param->i;
             mem->always_select_exists = EINA_TRUE;
          }
        else if (!strcmp(param->name, "height bounce"))
          {
             mem->h_bounce = !!param->i;
             mem->h_bounce_exists = EINA_TRUE;
          }
        else if (!strcmp(param->name, "width bounce"))
          {
             mem->v_bounce = !!param->i;
             mem->v_bounce_exists = EINA_TRUE;
          }
        else if (!strcmp(param->name, "horizontal page relative"))
          {
             mem->h_pagerel = param->d;
             mem->h_pagerel_exists = EINA_TRUE;
          }
        else if (!strcmp(param->name, "vertical page relative"))
          {
             mem->v_pagerel = param->d;
             mem->v_pagerel_exists = EINA_TRUE;
          }
        else if (!strcmp(param->name, "horizontal item size"))
          {
             mem->h_itemsize = param->i;
             mem->h_itemsize_exists = EINA_TRUE;
          }
        else if (!strcmp(param->name, "vertical item size"))
          {
             mem->v_itemsize = param->i;
             mem->v_itemsize_exists = EINA_TRUE;
          }
        else if (!strcmp(param->name, "horizontal"))
          {
             mem->horizontal = !!param->i;
             mem->horizontal_exists = EINA_TRUE;
          }
        else if (!strcmp(param->name, "align x"))
          {
             mem->align_x = param->d;
             mem->align_x_exists = EINA_TRUE;
          }
        else if (!strcmp(param->name, "align y"))
          {
             mem->align_y = param->d;
             mem->align_y_exists = EINA_TRUE;
          }
     }

   return mem;
}

static Evas_Object *
external_gengrid_content_get(void *data EINA_UNUSED,
                             const Evas_Object *obj EINA_UNUSED,
                             const char *content EINA_UNUSED)
{
   ERR("No content.");
   return NULL;
}

static void
external_gengrid_params_free(void *params)
{
   Elm_Params_Gengrid *mem = params;
   free(mem);
}

static Edje_External_Param_Info external_gengrid_params[] = {
   DEFINE_EXTERNAL_COMMON_PARAMS,
   EDJE_EXTERNAL_PARAM_INFO_BOOL("multi select"),
   EDJE_EXTERNAL_PARAM_INFO_BOOL("no select"),
   EDJE_EXTERNAL_PARAM_INFO_BOOL("always select"),
   EDJE_EXTERNAL_PARAM_INFO_BOOL("height bounce"),
   EDJE_EXTERNAL_PARAM_INFO_BOOL("width bounce"),
   EDJE_EXTERNAL_PARAM_INFO_DOUBLE("horizontal page relative"),
   EDJE_EXTERNAL_PARAM_INFO_DOUBLE("vertical page relative"),
   EDJE_EXTERNAL_PARAM_INFO_INT("horizontal item size"),
   EDJE_EXTERNAL_PARAM_INFO_INT("vertical item size"),
   EDJE_EXTERNAL_PARAM_INFO_BOOL("horizontal"),
   EDJE_EXTERNAL_PARAM_INFO_DOUBLE("align x"),
   EDJE_EXTERNAL_PARAM_INFO_DOUBLE("align y"),
   EDJE_EXTERNAL_PARAM_INFO_SENTINEL
};

DEFINE_EXTERNAL_ICON_ADD(gengrid, "gengrid");
DEFINE_EXTERNAL_TYPE_SIMPLE(gengrid, "Generic Grid");